mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(shader): ir typed value method impl
This commit is contained in:
+4
-1
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "IntermediateRepresentation/IrProgram.hpp"
|
||||
#include "IntermediateRepresentation/GuestRegister.hpp"
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
|
||||
namespace ShaderRecompiler {
|
||||
@@ -81,7 +82,9 @@ public:
|
||||
|
||||
template<typename TFlags> requires(sizeof(TFlags) <= sizeof(std::uint64_t) && std::is_trivially_copyable_v<TFlags>)
|
||||
[[nodiscard]] IrValue& Emit(IrOpcode opcode, IrType type, std::initializer_list<IrValue*> arguments, TFlags flags) {
|
||||
throw std::runtime_error("IrBuilder::Emit not implemented");
|
||||
std::uint64_t rawFlags = 0;
|
||||
std::memcpy(&rawFlags, &flags, sizeof(flags));
|
||||
return Emit(opcode, type, arguments, rawFlags);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
+18
-10
@@ -6,6 +6,7 @@
|
||||
#include "IntermediateRepresentation/GuestRegister.hpp"
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
@@ -47,12 +48,15 @@ public:
|
||||
|
||||
template<typename TValue> requires(sizeof(TValue) <= sizeof(std::uint64_t) && std::is_trivially_copyable_v<TValue>)
|
||||
[[nodiscard]] TValue Flags() const {
|
||||
throw std::runtime_error("IrValue::Flags not implemented");
|
||||
TValue result{};
|
||||
std::memcpy(&result, &flags, sizeof(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename TValue> requires(sizeof(TValue) <= sizeof(std::uint64_t) && std::is_trivially_copyable_v<TValue>)
|
||||
void SetFlags(TValue value) {
|
||||
throw std::runtime_error("IrValue::SetFlags not implemented");
|
||||
flags = 0;
|
||||
std::memcpy(&flags, &value, sizeof(value));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsEmpty() const;
|
||||
@@ -105,24 +109,28 @@ private:
|
||||
template<IrType TValueType>
|
||||
class IrTypedValue {
|
||||
public:
|
||||
IrTypedValue() {
|
||||
throw std::runtime_error("IrTypedValue not implemented");
|
||||
}
|
||||
IrTypedValue() = default;
|
||||
|
||||
explicit IrTypedValue(IrValue& value) {
|
||||
throw std::runtime_error("IrTypedValue not implemented");
|
||||
explicit IrTypedValue(IrValue& value) : value(&value) {
|
||||
if (!AreTypesCompatible(value.Type(), TValueType)) {
|
||||
throw std::invalid_argument("IrTypedValue constructed from an incompatible IrValue type");
|
||||
}
|
||||
}
|
||||
|
||||
template<IrType TOtherType> requires((static_cast<std::uint32_t>(TValueType) & static_cast<std::uint32_t>(TOtherType)) != 0u)
|
||||
IrTypedValue(const IrTypedValue<TOtherType>& value) {
|
||||
throw std::runtime_error("IrTypedValue not implemented");
|
||||
IrTypedValue(const IrTypedValue<TOtherType>& other) : value(other.value) {
|
||||
}
|
||||
|
||||
[[nodiscard]] IrValue& Value() const {
|
||||
throw std::runtime_error("IrTypedValue::Value not implemented");
|
||||
if (value == nullptr) {
|
||||
throw std::runtime_error("IrTypedValue::Value called on an empty typed value");
|
||||
}
|
||||
return *value;
|
||||
}
|
||||
|
||||
private:
|
||||
template<IrType> friend class IrTypedValue;
|
||||
|
||||
IrValue* value = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ bool operator<(const GuestRegister& lhs, const GuestRegister& rhs) {
|
||||
|
||||
std::uint32_t RegIndex(ScalarReg reg) {
|
||||
const auto index = static_cast<std::uint32_t>(reg);
|
||||
if (index >= NumScalarRegs) {
|
||||
throw std::out_of_range("ScalarReg index is out of range");
|
||||
}
|
||||
// if (index >= NumScalarRegs) {
|
||||
// throw std::out_of_range("ScalarReg index is out of range");
|
||||
// }
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user