From a529827753f659b331db3930dbf94e8fe84fc245 Mon Sep 17 00:00:00 2001 From: boykopovar Date: Thu, 17 Sep 2026 12:16:04 +0300 Subject: [PATCH] feat(shader): ir typed value method impl --- .../IntermediateRepresentation/IrBuilder.hpp | 5 +++- .../IntermediateRepresentation/IrValue.hpp | 28 ++++++++++++------- .../src/GuestRegister.cpp | 6 ++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrBuilder.hpp b/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrBuilder.hpp index d0b1589fa..99b5ef6fa 100644 --- a/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrBuilder.hpp +++ b/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrBuilder.hpp @@ -3,6 +3,7 @@ #include "IntermediateRepresentation/IrProgram.hpp" #include "IntermediateRepresentation/GuestRegister.hpp" +#include #include namespace ShaderRecompiler { @@ -81,7 +82,9 @@ public: template requires(sizeof(TFlags) <= sizeof(std::uint64_t) && std::is_trivially_copyable_v) [[nodiscard]] IrValue& Emit(IrOpcode opcode, IrType type, std::initializer_list 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: diff --git a/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrValue.hpp b/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrValue.hpp index 5b9365122..22d6d8f27 100644 --- a/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrValue.hpp +++ b/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrValue.hpp @@ -6,6 +6,7 @@ #include "IntermediateRepresentation/GuestRegister.hpp" #include #include +#include #include #include #include @@ -47,12 +48,15 @@ public: template requires(sizeof(TValue) <= sizeof(std::uint64_t) && std::is_trivially_copyable_v) [[nodiscard]] TValue Flags() const { - throw std::runtime_error("IrValue::Flags not implemented"); + TValue result{}; + std::memcpy(&result, &flags, sizeof(result)); + return result; } template requires(sizeof(TValue) <= sizeof(std::uint64_t) && std::is_trivially_copyable_v) 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 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 requires((static_cast(TValueType) & static_cast(TOtherType)) != 0u) - IrTypedValue(const IrTypedValue& value) { - throw std::runtime_error("IrTypedValue not implemented"); + IrTypedValue(const IrTypedValue& 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 friend class IrTypedValue; + IrValue* value = nullptr; }; diff --git a/core/shader/recompiler/IntermediateRepresentation/src/GuestRegister.cpp b/core/shader/recompiler/IntermediateRepresentation/src/GuestRegister.cpp index dd703fe21..da5a3d3d3 100644 --- a/core/shader/recompiler/IntermediateRepresentation/src/GuestRegister.cpp +++ b/core/shader/recompiler/IntermediateRepresentation/src/GuestRegister.cpp @@ -16,9 +16,9 @@ bool operator<(const GuestRegister& lhs, const GuestRegister& rhs) { std::uint32_t RegIndex(ScalarReg reg) { const auto index = static_cast(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; }