From e4490a0272e4409af0442935e72f35dd00c00a8c Mon Sep 17 00:00:00 2001 From: boykopovar Date: Tue, 15 Sep 2026 11:44:42 +0300 Subject: [PATCH] feat(shader): arithmetic + ext regs + logic impl for ir builder --- .../src/IrBuilder/IrBuilderArithmetic.cpp | 21 ++++--- .../IrBuilder/IrBuilderExtendedRegisters.cpp | 39 ++++++------ .../src/IrBuilder/IrBuilderLogic.cpp | 60 +++++++++++-------- 3 files changed, 66 insertions(+), 54 deletions(-) diff --git a/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderArithmetic.cpp b/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderArithmetic.cpp index 250ed9b53..7d23b2b5f 100644 --- a/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderArithmetic.cpp +++ b/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderArithmetic.cpp @@ -1,46 +1,45 @@ #include "IntermediateRepresentation/IrBuilder.hpp" -#include namespace ShaderRecompiler { IrValue& IrBuilder::IAdd(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::IAdd not implemented"); + return Emit(IrOpcode::IAdd32, IrType::U32, {&lhs, &rhs}); } IrValue& IrBuilder::ISub(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::ISub not implemented"); + return Emit(IrOpcode::ISub32, IrType::U32, {&lhs, &rhs}); } IrValue& IrBuilder::IMul(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::IMul not implemented"); + return Emit(IrOpcode::IMul32, IrType::U32, {&lhs, &rhs}); } IrValue& IrBuilder::ShiftLeftLogical(IrValue& value, IrValue& shift) { - throw std::runtime_error("IrBuilder::ShiftLeftLogical not implemented"); + return Emit(IrOpcode::ShiftLeftLogical32, IrType::U32, {&value, &shift}); } IrValue& IrBuilder::ShiftRightLogical(IrValue& value, IrValue& shift) { - throw std::runtime_error("IrBuilder::ShiftRightLogical not implemented"); + return Emit(IrOpcode::ShiftRightLogical32, IrType::U32, {&value, &shift}); } IrValue& IrBuilder::ShiftRightArithmetic(IrValue& value, IrValue& shift) { - throw std::runtime_error("IrBuilder::ShiftRightArithmetic not implemented"); + return Emit(IrOpcode::ShiftRightArithmetic32, IrType::U32, {&value, &shift}); } IrValue& IrBuilder::BitwiseAnd(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::BitwiseAnd not implemented"); + return Emit(IrOpcode::BitwiseAnd32, IrType::U32, {&lhs, &rhs}); } IrValue& IrBuilder::BitwiseOr(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::BitwiseOr not implemented"); + return Emit(IrOpcode::BitwiseOr32, IrType::U32, {&lhs, &rhs}); } IrValue& IrBuilder::BitwiseXor(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::BitwiseXor not implemented"); + return Emit(IrOpcode::BitwiseXor32, IrType::U32, {&lhs, &rhs}); } IrValue& IrBuilder::BitwiseNot(IrValue& value) { - throw std::runtime_error("IrBuilder::BitwiseNot not implemented"); + return Emit(IrOpcode::BitwiseNot32, IrType::U32, {&value}); } } diff --git a/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderExtendedRegisters.cpp b/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderExtendedRegisters.cpp index 1e6113ed2..ab447c8d8 100644 --- a/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderExtendedRegisters.cpp +++ b/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderExtendedRegisters.cpp @@ -1,78 +1,79 @@ #include "IntermediateRepresentation/IrBuilder.hpp" -#include namespace ShaderRecompiler { IrValue& IrBuilder::GetGotoVariable(std::uint32_t id) { - throw std::runtime_error("IrBuilder::GetGotoVariable not implemented"); + IrValue& idValue = Constant(id); + return Emit(IrOpcode::GetGotoVariable, IrType::Bool, {&idValue}); } void IrBuilder::SetGotoVariable(std::uint32_t id, IrValue& value) { - throw std::runtime_error("IrBuilder::SetGotoVariable not implemented"); + IrValue& idValue = Constant(id); + (void)Emit(IrOpcode::SetGotoVariable, IrType::Void, {&idValue, &value}); } IrValue& IrBuilder::GetScc() { - throw std::runtime_error("IrBuilder::GetScc not implemented"); + return Emit(IrOpcode::GetScc, IrType::Bool, {}); } void IrBuilder::SetScc(IrValue& value) { - throw std::runtime_error("IrBuilder::SetScc not implemented"); + (void)Emit(IrOpcode::SetScc, IrType::Void, {&value}); } IrValue& IrBuilder::GetExec() { - throw std::runtime_error("IrBuilder::GetExec not implemented"); + return Emit(IrOpcode::GetExec, IrType::Bool, {}); } void IrBuilder::SetExec(IrValue& value) { - throw std::runtime_error("IrBuilder::SetExec not implemented"); + (void)Emit(IrOpcode::SetExec, IrType::Void, {&value}); } IrValue& IrBuilder::GetExecLo() { - throw std::runtime_error("IrBuilder::GetExecLo not implemented"); + return Emit(IrOpcode::GetExecLo, IrType::U32, {}); } void IrBuilder::SetExecLo(IrValue& value) { - throw std::runtime_error("IrBuilder::SetExecLo not implemented"); + (void)Emit(IrOpcode::SetExecLo, IrType::Void, {&value}); } IrValue& IrBuilder::GetExecHi() { - throw std::runtime_error("IrBuilder::GetExecHi not implemented"); + return Emit(IrOpcode::GetExecHi, IrType::U32, {}); } void IrBuilder::SetExecHi(IrValue& value) { - throw std::runtime_error("IrBuilder::SetExecHi not implemented"); + (void)Emit(IrOpcode::SetExecHi, IrType::Void, {&value}); } IrValue& IrBuilder::GetVcc() { - throw std::runtime_error("IrBuilder::GetVcc not implemented"); + return Emit(IrOpcode::GetVcc, IrType::Bool, {}); } void IrBuilder::SetVcc(IrValue& value) { - throw std::runtime_error("IrBuilder::SetVcc not implemented"); + (void)Emit(IrOpcode::SetVcc, IrType::Void, {&value}); } IrValue& IrBuilder::GetVccLo() { - throw std::runtime_error("IrBuilder::GetVccLo not implemented"); + return Emit(IrOpcode::GetVccLo, IrType::U32, {}); } void IrBuilder::SetVccLo(IrValue& value) { - throw std::runtime_error("IrBuilder::SetVccLo not implemented"); + (void)Emit(IrOpcode::SetVccLo, IrType::Void, {&value}); } IrValue& IrBuilder::GetVccHi() { - throw std::runtime_error("IrBuilder::GetVccHi not implemented"); + return Emit(IrOpcode::GetVccHi, IrType::U32, {}); } void IrBuilder::SetVccHi(IrValue& value) { - throw std::runtime_error("IrBuilder::SetVccHi not implemented"); + (void)Emit(IrOpcode::SetVccHi, IrType::Void, {&value}); } IrValue& IrBuilder::GetM0() { - throw std::runtime_error("IrBuilder::GetM0 not implemented"); + return Emit(IrOpcode::GetM0, IrType::U32, {}); } void IrBuilder::SetM0(IrValue& value) { - throw std::runtime_error("IrBuilder::SetM0 not implemented"); + (void)Emit(IrOpcode::SetM0, IrType::Void, {&value}); } } diff --git a/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderLogic.cpp b/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderLogic.cpp index 7b6e5fc4b..5bac16e36 100644 --- a/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderLogic.cpp +++ b/core/shader/recompiler/IntermediateRepresentation/src/IrBuilder/IrBuilderLogic.cpp @@ -3,36 +3,48 @@ namespace ShaderRecompiler { -IrValue& IrBuilder::Select(IrValue& condition, IrValue& trueValue, IrValue& falseValue) { - throw std::runtime_error("IrBuilder::Select not implemented"); -} + IrValue& IrBuilder::Select(IrValue& condition, IrValue& trueValue, IrValue& falseValue) { + if (trueValue.Type() != falseValue.Type()) { + throw std::invalid_argument("IrBuilder::Select trueValue and falseValue type mismatch"); + } + switch (trueValue.Type()) { + case IrType::Bool: + return Emit(IrOpcode::SelectU1, IrType::Bool, {&condition, &trueValue, &falseValue}); + case IrType::U32: + return Emit(IrOpcode::SelectU32, IrType::U32, {&condition, &trueValue, &falseValue}); + case IrType::F32: + return Emit(IrOpcode::SelectF32, IrType::F32, {&condition, &trueValue, &falseValue}); + default: + throw std::invalid_argument("IrBuilder::Select unsupported value type"); + } + } -IrValue& IrBuilder::IEqual(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::IEqual not implemented"); -} + IrValue& IrBuilder::IEqual(IrValue& lhs, IrValue& rhs) { + return Emit(IrOpcode::IEqual32, IrType::Bool, {&lhs, &rhs}); + } -IrValue& IrBuilder::INotEqual(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::INotEqual not implemented"); -} + IrValue& IrBuilder::INotEqual(IrValue& lhs, IrValue& rhs) { + return Emit(IrOpcode::INotEqual32, IrType::Bool, {&lhs, &rhs}); + } -IrValue& IrBuilder::ULessThan(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::ULessThan not implemented"); -} + IrValue& IrBuilder::ULessThan(IrValue& lhs, IrValue& rhs) { + return Emit(IrOpcode::ULessThan32, IrType::Bool, {&lhs, &rhs}); + } -IrValue& IrBuilder::UGreaterThan(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::UGreaterThan not implemented"); -} + IrValue& IrBuilder::UGreaterThan(IrValue& lhs, IrValue& rhs) { + return Emit(IrOpcode::UGreaterThan32, IrType::Bool, {&lhs, &rhs}); + } -IrValue& IrBuilder::LogicalAnd(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::LogicalAnd not implemented"); -} + IrValue& IrBuilder::LogicalAnd(IrValue& lhs, IrValue& rhs) { + return Emit(IrOpcode::LogicalAnd, IrType::Bool, {&lhs, &rhs}); + } -IrValue& IrBuilder::LogicalOr(IrValue& lhs, IrValue& rhs) { - throw std::runtime_error("IrBuilder::LogicalOr not implemented"); -} + IrValue& IrBuilder::LogicalOr(IrValue& lhs, IrValue& rhs) { + return Emit(IrOpcode::LogicalOr, IrType::Bool, {&lhs, &rhs}); + } -IrValue& IrBuilder::LogicalNot(IrValue& value) { - throw std::runtime_error("IrBuilder::LogicalNot not implemented"); -} + IrValue& IrBuilder::LogicalNot(IrValue& value) { + return Emit(IrOpcode::LogicalNot, IrType::Bool, {&value}); + } }