refactor(shader): refactor ir builder to separated module + som getters impl

This commit is contained in:
boykopovar 2026-09-15 11:36:41 +03:00
parent 5c8af9032b
commit 039b88b08e
12 changed files with 471 additions and 264 deletions

View File

@ -21,7 +21,15 @@ function(add_shader_recompiler target runtimeTarget)
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrValue.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBlock.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrProgram.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBuilder.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBuilder/IrBuilderInternal.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBuilder/IrBuilderCore.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBuilder/IrBuilderConstants.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBuilder/IrBuilderRegisters.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBuilder/IrBuilderControlFlow.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBuilder/IrBuilderExtendedRegisters.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBuilder/IrBuilderConversions.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBuilder/IrBuilderArithmetic.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/IntermediateRepresentation/src/IrBuilder/IrBuilderLogic.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Translation/src/EmbeddedVertexFetch.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Translation/src/InstructionTranslator.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Translation/src/ScalarInstructions.cpp

View File

@ -0,0 +1,14 @@
#ifndef CORE_SHADER_RECOMPILIER_INTERMEDIATEREPRESENTATION_INCLUDE_INTERMEDIATEREPRESENTATION_IRBUILDERINTERNAL_HPP
#define CORE_SHADER_RECOMPILIER_INTERMEDIATEREPRESENTATION_INCLUDE_INTERMEDIATEREPRESENTATION_IRBUILDERINTERNAL_HPP
#include "IntermediateRepresentation/IrProgram.hpp"
#include "IntermediateRepresentation/GuestRegister.hpp"
namespace ShaderRecompiler {
[[nodiscard]] IrValue& createLeafValue(IrProgram& program, IrType type);
[[nodiscard]] IrValue& createRegisterOperand(IrProgram& program, RegisterBank bank, std::uint32_t index, IrType type);
}
#endif

View File

@ -1,263 +0,0 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include <stdexcept>
namespace ShaderRecompiler {
IrBuilder::IrBuilder(IrProgram& program) : program(program), insertionPoint(nullptr) {
throw std::runtime_error("IrBuilder::IrBuilder not implemented");
}
void IrBuilder::SetInsertionPoint(IrBlock& block) {
throw std::runtime_error("IrBuilder::SetInsertionPoint not implemented");
}
IrValue& IrBuilder::Constant(std::uint32_t value) {
throw std::runtime_error("IrBuilder::Constant not implemented");
}
IrValue& IrBuilder::ReadRegister(const GuestRegister& reg) {
throw std::runtime_error("IrBuilder::ReadRegister not implemented");
}
void IrBuilder::WriteRegister(const GuestRegister& reg, IrValue& value) {
throw std::runtime_error("IrBuilder::WriteRegister not implemented");
}
IrValue& IrBuilder::Emit(IrOpcode opcode, IrType type, std::initializer_list<IrValue*> arguments) {
throw std::runtime_error("IrBuilder::Emit not implemented");
}
void IrBuilder::Branch(IrBlock& target) {
throw std::runtime_error("IrBuilder::Branch not implemented");
}
void IrBuilder::BranchConditional(IrValue& condition, IrBlock& trueTarget, IrBlock& falseTarget) {
throw std::runtime_error("IrBuilder::BranchConditional not implemented");
}
IrValue& IrBuilder::ConstantU64(std::uint64_t value) {
throw std::runtime_error("IrBuilder::ConstantU64 not implemented");
}
IrValue& IrBuilder::ConstantF16(std::uint16_t bits) {
throw std::runtime_error("IrBuilder::ConstantF16 not implemented");
}
IrValue& IrBuilder::ConstantF32(float value) {
throw std::runtime_error("IrBuilder::ConstantF32 not implemented");
}
IrValue& IrBuilder::ConstantBool(bool value) {
throw std::runtime_error("IrBuilder::ConstantBool not implemented");
}
IrValue& IrBuilder::ConstantU8(std::uint8_t value) {
throw std::runtime_error("IrBuilder::ConstantU8 not implemented");
}
IrValue& IrBuilder::ConstantU16(std::uint16_t value) {
throw std::runtime_error("IrBuilder::ConstantU16 not implemented");
}
IrValue& IrBuilder::Emit(IrOpcode opcode, IrType type, std::initializer_list<IrValue*> arguments, std::uint64_t flags) {
throw std::runtime_error("IrBuilder::Emit not implemented");
}
IrValue& IrBuilder::GetUserData(ScalarReg reg) {
throw std::runtime_error("IrBuilder::GetUserData not implemented");
}
IrValue& IrBuilder::GetScalarReg(ScalarReg reg) {
throw std::runtime_error("IrBuilder::GetScalarReg not implemented");
}
void IrBuilder::SetScalarReg(ScalarReg reg, IrValue& value) {
throw std::runtime_error("IrBuilder::SetScalarReg not implemented");
}
IrValue& IrBuilder::GetThreadBitScalarReg(ScalarReg reg) {
throw std::runtime_error("IrBuilder::GetThreadBitScalarReg not implemented");
}
void IrBuilder::SetThreadBitScalarReg(ScalarReg reg, IrValue& value) {
throw std::runtime_error("IrBuilder::SetThreadBitScalarReg not implemented");
}
IrValue& IrBuilder::GetScalarMaskTag(ScalarReg reg) {
throw std::runtime_error("IrBuilder::GetScalarMaskTag not implemented");
}
void IrBuilder::SetScalarMaskTag(ScalarReg reg, IrValue& value) {
throw std::runtime_error("IrBuilder::SetScalarMaskTag not implemented");
}
IrValue& IrBuilder::GetVectorReg(VectorReg reg) {
throw std::runtime_error("IrBuilder::GetVectorReg not implemented");
}
void IrBuilder::SetVectorReg(VectorReg reg, IrValue& value) {
throw std::runtime_error("IrBuilder::SetVectorReg not implemented");
}
IrValue& IrBuilder::GetGotoVariable(std::uint32_t id) {
throw std::runtime_error("IrBuilder::GetGotoVariable not implemented");
}
void IrBuilder::SetGotoVariable(std::uint32_t id, IrValue& value) {
throw std::runtime_error("IrBuilder::SetGotoVariable not implemented");
}
IrValue& IrBuilder::GetScc() {
throw std::runtime_error("IrBuilder::GetScc not implemented");
}
void IrBuilder::SetScc(IrValue& value) {
throw std::runtime_error("IrBuilder::SetScc not implemented");
}
IrValue& IrBuilder::GetExec() {
throw std::runtime_error("IrBuilder::GetExec not implemented");
}
void IrBuilder::SetExec(IrValue& value) {
throw std::runtime_error("IrBuilder::SetExec not implemented");
}
IrValue& IrBuilder::GetExecLo() {
throw std::runtime_error("IrBuilder::GetExecLo not implemented");
}
void IrBuilder::SetExecLo(IrValue& value) {
throw std::runtime_error("IrBuilder::SetExecLo not implemented");
}
IrValue& IrBuilder::GetExecHi() {
throw std::runtime_error("IrBuilder::GetExecHi not implemented");
}
void IrBuilder::SetExecHi(IrValue& value) {
throw std::runtime_error("IrBuilder::SetExecHi not implemented");
}
IrValue& IrBuilder::GetVcc() {
throw std::runtime_error("IrBuilder::GetVcc not implemented");
}
void IrBuilder::SetVcc(IrValue& value) {
throw std::runtime_error("IrBuilder::SetVcc not implemented");
}
IrValue& IrBuilder::GetVccLo() {
throw std::runtime_error("IrBuilder::GetVccLo not implemented");
}
void IrBuilder::SetVccLo(IrValue& value) {
throw std::runtime_error("IrBuilder::SetVccLo not implemented");
}
IrValue& IrBuilder::GetVccHi() {
throw std::runtime_error("IrBuilder::GetVccHi not implemented");
}
void IrBuilder::SetVccHi(IrValue& value) {
throw std::runtime_error("IrBuilder::SetVccHi not implemented");
}
IrValue& IrBuilder::GetM0() {
throw std::runtime_error("IrBuilder::GetM0 not implemented");
}
void IrBuilder::SetM0(IrValue& value) {
throw std::runtime_error("IrBuilder::SetM0 not implemented");
}
IrValue& IrBuilder::BitCastF32(IrValue& value) {
throw std::runtime_error("IrBuilder::BitCastF32 not implemented");
}
IrValue& IrBuilder::BitCastU32(IrValue& value) {
throw std::runtime_error("IrBuilder::BitCastU32 not implemented");
}
IrValue& IrBuilder::BitCastF16(IrValue& value) {
throw std::runtime_error("IrBuilder::BitCastF16 not implemented");
}
IrValue& IrBuilder::BitCastU32FromF16(IrValue& value) {
throw std::runtime_error("IrBuilder::BitCastU32FromF16 not implemented");
}
IrValue& IrBuilder::ConstructU64(IrValue& low, IrValue& high) {
throw std::runtime_error("IrBuilder::ConstructU64 not implemented");
}
IrValue& IrBuilder::CompositeExtract(IrValue& composite, std::uint32_t index) {
throw std::runtime_error("IrBuilder::CompositeExtract not implemented");
}
IrValue& IrBuilder::IAdd(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::IAdd not implemented");
}
IrValue& IrBuilder::ISub(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::ISub not implemented");
}
IrValue& IrBuilder::IMul(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::IMul not implemented");
}
IrValue& IrBuilder::ShiftLeftLogical(IrValue& value, IrValue& shift) {
throw std::runtime_error("IrBuilder::ShiftLeftLogical not implemented");
}
IrValue& IrBuilder::ShiftRightLogical(IrValue& value, IrValue& shift) {
throw std::runtime_error("IrBuilder::ShiftRightLogical not implemented");
}
IrValue& IrBuilder::ShiftRightArithmetic(IrValue& value, IrValue& shift) {
throw std::runtime_error("IrBuilder::ShiftRightArithmetic not implemented");
}
IrValue& IrBuilder::BitwiseAnd(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::BitwiseAnd not implemented");
}
IrValue& IrBuilder::BitwiseOr(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::BitwiseOr not implemented");
}
IrValue& IrBuilder::BitwiseXor(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::BitwiseXor not implemented");
}
IrValue& IrBuilder::BitwiseNot(IrValue& value) {
throw std::runtime_error("IrBuilder::BitwiseNot not implemented");
}
IrValue& IrBuilder::Select(IrValue& condition, IrValue& trueValue, IrValue& falseValue) {
throw std::runtime_error("IrBuilder::Select not implemented");
}
IrValue& IrBuilder::IEqual(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::IEqual not implemented");
}
IrValue& IrBuilder::INotEqual(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::INotEqual not implemented");
}
IrValue& IrBuilder::ULessThan(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::ULessThan not implemented");
}
IrValue& IrBuilder::UGreaterThan(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::UGreaterThan not implemented");
}
IrValue& IrBuilder::LogicalAnd(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::LogicalAnd not implemented");
}
IrValue& IrBuilder::LogicalOr(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::LogicalOr not implemented");
}
IrValue& IrBuilder::LogicalNot(IrValue& value) {
throw std::runtime_error("IrBuilder::LogicalNot not implemented");
}
}

View File

@ -0,0 +1,46 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include <stdexcept>
namespace ShaderRecompiler {
IrValue& IrBuilder::IAdd(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::IAdd not implemented");
}
IrValue& IrBuilder::ISub(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::ISub not implemented");
}
IrValue& IrBuilder::IMul(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::IMul not implemented");
}
IrValue& IrBuilder::ShiftLeftLogical(IrValue& value, IrValue& shift) {
throw std::runtime_error("IrBuilder::ShiftLeftLogical not implemented");
}
IrValue& IrBuilder::ShiftRightLogical(IrValue& value, IrValue& shift) {
throw std::runtime_error("IrBuilder::ShiftRightLogical not implemented");
}
IrValue& IrBuilder::ShiftRightArithmetic(IrValue& value, IrValue& shift) {
throw std::runtime_error("IrBuilder::ShiftRightArithmetic not implemented");
}
IrValue& IrBuilder::BitwiseAnd(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::BitwiseAnd not implemented");
}
IrValue& IrBuilder::BitwiseOr(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::BitwiseOr not implemented");
}
IrValue& IrBuilder::BitwiseXor(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::BitwiseXor not implemented");
}
IrValue& IrBuilder::BitwiseNot(IrValue& value) {
throw std::runtime_error("IrBuilder::BitwiseNot not implemented");
}
}

View File

@ -0,0 +1,48 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include "IntermediateRepresentation/IrBuilderInternal.hpp"
namespace ShaderRecompiler {
IrValue& IrBuilder::Constant(std::uint32_t value) {
IrValue& constant = createLeafValue(program, IrType::U32);
constant.SetImmediateU32(value);
return constant;
}
IrValue& IrBuilder::ConstantU64(std::uint64_t value) {
IrValue& constant = createLeafValue(program, IrType::U64);
constant.SetImmediateU64(value);
return constant;
}
IrValue& IrBuilder::ConstantF16(std::uint16_t bits) {
IrValue& constant = createLeafValue(program, IrType::F16);
constant.SetImmediateF16Bits(bits);
return constant;
}
IrValue& IrBuilder::ConstantF32(float value) {
IrValue& constant = createLeafValue(program, IrType::F32);
constant.SetImmediateF32(value);
return constant;
}
IrValue& IrBuilder::ConstantBool(bool value) {
IrValue& constant = createLeafValue(program, IrType::Bool);
constant.SetImmediateBool(value);
return constant;
}
IrValue& IrBuilder::ConstantU8(std::uint8_t value) {
IrValue& constant = createLeafValue(program, IrType::U8);
constant.SetImmediateU8(value);
return constant;
}
IrValue& IrBuilder::ConstantU16(std::uint16_t value) {
IrValue& constant = createLeafValue(program, IrType::U16);
constant.SetImmediateU16(value);
return constant;
}
}

View File

@ -0,0 +1,14 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include <stdexcept>
namespace ShaderRecompiler {
void IrBuilder::Branch(IrBlock& target) {
throw std::runtime_error("IrBuilder::Branch not implemented");
}
void IrBuilder::BranchConditional(IrValue& condition, IrBlock& trueTarget, IrBlock& falseTarget) {
throw std::runtime_error("IrBuilder::BranchConditional not implemented");
}
}

View File

@ -0,0 +1,30 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include <stdexcept>
namespace ShaderRecompiler {
IrValue& IrBuilder::BitCastF32(IrValue& value) {
throw std::runtime_error("IrBuilder::BitCastF32 not implemented");
}
IrValue& IrBuilder::BitCastU32(IrValue& value) {
throw std::runtime_error("IrBuilder::BitCastU32 not implemented");
}
IrValue& IrBuilder::BitCastF16(IrValue& value) {
throw std::runtime_error("IrBuilder::BitCastF16 not implemented");
}
IrValue& IrBuilder::BitCastU32FromF16(IrValue& value) {
throw std::runtime_error("IrBuilder::BitCastU32FromF16 not implemented");
}
IrValue& IrBuilder::ConstructU64(IrValue& low, IrValue& high) {
throw std::runtime_error("IrBuilder::ConstructU64 not implemented");
}
IrValue& IrBuilder::CompositeExtract(IrValue& composite, std::uint32_t index) {
throw std::runtime_error("IrBuilder::CompositeExtract not implemented");
}
}

View File

@ -0,0 +1,60 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include <stdexcept>
#include <string>
namespace ShaderRecompiler {
IrBuilder::IrBuilder(IrProgram& program) : program(program), insertionPoint(nullptr) {
}
void IrBuilder::SetInsertionPoint(IrBlock& block) {
insertionPoint = &block;
}
IrValue& IrBuilder::Emit(IrOpcode opcode, IrType type, std::initializer_list<IrValue*> arguments) {
if (insertionPoint == nullptr) {
throw std::runtime_error("IrBuilder::Emit no insertion point set");
}
if (arguments.size() != IrOpcodeOperandCount(opcode)) {
throw std::invalid_argument("IrBuilder::Emit argument count mismatch for " + std::string(IrOpcodeName(opcode)));
}
IrValue& value = program.CreateValue(opcode, type);
std::size_t index = 0;
for (IrValue* argument : arguments) {
if (argument == nullptr) {
throw std::invalid_argument("IrBuilder::Emit argument cannot be null");
}
if (argument->Type() != IrOpcodeArgumentType(opcode, index)) {
throw std::invalid_argument("IrBuilder::Emit argument type mismatch at index " + std::to_string(index));
}
value.AddArgument(argument);
++index;
}
insertionPoint->AppendInstruction(&value);
return value;
}
IrValue& IrBuilder::Emit(IrOpcode opcode, IrType type, std::initializer_list<IrValue*> arguments, std::uint64_t flags) {
if (insertionPoint == nullptr) {
throw std::runtime_error("IrBuilder::Emit no insertion point set");
}
if (arguments.size() != IrOpcodeOperandCount(opcode)) {
throw std::invalid_argument("IrBuilder::Emit argument count mismatch for " + std::string(IrOpcodeName(opcode)));
}
IrValue& value = program.CreateValue(opcode, type, flags);
std::size_t index = 0;
for (IrValue* argument : arguments) {
if (argument == nullptr) {
throw std::invalid_argument("IrBuilder::Emit argument cannot be null");
}
if (argument->Type() != IrOpcodeArgumentType(opcode, index)) {
throw std::invalid_argument("IrBuilder::Emit argument type mismatch at index " + std::to_string(index));
}
value.AddArgument(argument);
++index;
}
insertionPoint->AppendInstruction(&value);
return value;
}
}

View File

@ -0,0 +1,78 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include <stdexcept>
namespace ShaderRecompiler {
IrValue& IrBuilder::GetGotoVariable(std::uint32_t id) {
throw std::runtime_error("IrBuilder::GetGotoVariable not implemented");
}
void IrBuilder::SetGotoVariable(std::uint32_t id, IrValue& value) {
throw std::runtime_error("IrBuilder::SetGotoVariable not implemented");
}
IrValue& IrBuilder::GetScc() {
throw std::runtime_error("IrBuilder::GetScc not implemented");
}
void IrBuilder::SetScc(IrValue& value) {
throw std::runtime_error("IrBuilder::SetScc not implemented");
}
IrValue& IrBuilder::GetExec() {
throw std::runtime_error("IrBuilder::GetExec not implemented");
}
void IrBuilder::SetExec(IrValue& value) {
throw std::runtime_error("IrBuilder::SetExec not implemented");
}
IrValue& IrBuilder::GetExecLo() {
throw std::runtime_error("IrBuilder::GetExecLo not implemented");
}
void IrBuilder::SetExecLo(IrValue& value) {
throw std::runtime_error("IrBuilder::SetExecLo not implemented");
}
IrValue& IrBuilder::GetExecHi() {
throw std::runtime_error("IrBuilder::GetExecHi not implemented");
}
void IrBuilder::SetExecHi(IrValue& value) {
throw std::runtime_error("IrBuilder::SetExecHi not implemented");
}
IrValue& IrBuilder::GetVcc() {
throw std::runtime_error("IrBuilder::GetVcc not implemented");
}
void IrBuilder::SetVcc(IrValue& value) {
throw std::runtime_error("IrBuilder::SetVcc not implemented");
}
IrValue& IrBuilder::GetVccLo() {
throw std::runtime_error("IrBuilder::GetVccLo not implemented");
}
void IrBuilder::SetVccLo(IrValue& value) {
throw std::runtime_error("IrBuilder::SetVccLo not implemented");
}
IrValue& IrBuilder::GetVccHi() {
throw std::runtime_error("IrBuilder::GetVccHi not implemented");
}
void IrBuilder::SetVccHi(IrValue& value) {
throw std::runtime_error("IrBuilder::SetVccHi not implemented");
}
IrValue& IrBuilder::GetM0() {
throw std::runtime_error("IrBuilder::GetM0 not implemented");
}
void IrBuilder::SetM0(IrValue& value) {
throw std::runtime_error("IrBuilder::SetM0 not implemented");
}
}

View File

@ -0,0 +1,15 @@
#include "IntermediateRepresentation/IrBuilderInternal.hpp"
namespace ShaderRecompiler {
IrValue& createLeafValue(IrProgram& program, IrType type) {
return program.CreateValue(IrOpcode::Void, type);
}
IrValue& createRegisterOperand(IrProgram& program, RegisterBank bank, std::uint32_t index, IrType type) {
IrValue& operand = createLeafValue(program, type);
operand.SetRegister(GuestRegister{bank, index});
return operand;
}
}

View File

@ -0,0 +1,38 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include <stdexcept>
namespace ShaderRecompiler {
IrValue& IrBuilder::Select(IrValue& condition, IrValue& trueValue, IrValue& falseValue) {
throw std::runtime_error("IrBuilder::Select not implemented");
}
IrValue& IrBuilder::IEqual(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::IEqual not implemented");
}
IrValue& IrBuilder::INotEqual(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::INotEqual not implemented");
}
IrValue& IrBuilder::ULessThan(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::ULessThan not implemented");
}
IrValue& IrBuilder::UGreaterThan(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::UGreaterThan not implemented");
}
IrValue& IrBuilder::LogicalAnd(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::LogicalAnd not implemented");
}
IrValue& IrBuilder::LogicalOr(IrValue& lhs, IrValue& rhs) {
throw std::runtime_error("IrBuilder::LogicalOr not implemented");
}
IrValue& IrBuilder::LogicalNot(IrValue& value) {
throw std::runtime_error("IrBuilder::LogicalNot not implemented");
}
}

View File

@ -0,0 +1,119 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include "IntermediateRepresentation/IrBuilderInternal.hpp"
#include <stdexcept>
namespace ShaderRecompiler {
IrValue& IrBuilder::ReadRegister(const GuestRegister& reg) {
switch (reg.bank) {
case RegisterBank::Scalar:
return GetScalarReg(static_cast<ScalarReg>(reg.index));
case RegisterBank::Vector:
return GetVectorReg(static_cast<VectorReg>(reg.index));
case RegisterBank::VectorConditionCode:
return GetVcc();
case RegisterBank::ScalarConditionCode:
return GetScc();
case RegisterBank::ExecutionMask:
return GetExec();
case RegisterBank::Memory:
throw std::invalid_argument("IrBuilder::ReadRegister memory bank has no register representation");
case RegisterBank::ThreadBitScalar:
return GetThreadBitScalarReg(static_cast<ScalarReg>(reg.index));
case RegisterBank::ScalarMaskTag:
return GetScalarMaskTag(static_cast<ScalarReg>(reg.index));
case RegisterBank::GotoVariable:
return GetGotoVariable(reg.index);
case RegisterBank::M0:
return GetM0();
case RegisterBank::UserData:
return GetUserData(static_cast<ScalarReg>(reg.index));
default:
throw std::invalid_argument("IrBuilder::ReadRegister unknown register bank");
}
}
void IrBuilder::WriteRegister(const GuestRegister& reg, IrValue& value) {
switch (reg.bank) {
case RegisterBank::Scalar:
SetScalarReg(static_cast<ScalarReg>(reg.index), value);
return;
case RegisterBank::Vector:
SetVectorReg(static_cast<VectorReg>(reg.index), value);
return;
case RegisterBank::VectorConditionCode:
SetVcc(value);
return;
case RegisterBank::ScalarConditionCode:
SetScc(value);
return;
case RegisterBank::ExecutionMask:
SetExec(value);
return;
case RegisterBank::Memory:
throw std::invalid_argument("IrBuilder::WriteRegister memory bank has no register representation");
case RegisterBank::ThreadBitScalar:
SetThreadBitScalarReg(static_cast<ScalarReg>(reg.index), value);
return;
case RegisterBank::ScalarMaskTag:
SetScalarMaskTag(static_cast<ScalarReg>(reg.index), value);
return;
case RegisterBank::GotoVariable:
SetGotoVariable(reg.index, value);
return;
case RegisterBank::M0:
SetM0(value);
return;
case RegisterBank::UserData:
throw std::invalid_argument("IrBuilder::WriteRegister user data has no setter");
default:
throw std::invalid_argument("IrBuilder::WriteRegister unknown register bank");
}
}
IrValue& IrBuilder::GetUserData(ScalarReg reg) {
IrValue& operand = createRegisterOperand(program, RegisterBank::UserData, RegIndex(reg), IrType::ScalarReg);
return Emit(IrOpcode::GetUserData, IrType::U32, {&operand});
}
IrValue& IrBuilder::GetScalarReg(ScalarReg reg) {
IrValue& operand = createRegisterOperand(program, RegisterBank::Scalar, RegIndex(reg), IrType::ScalarReg);
return Emit(IrOpcode::GetScalarRegister, IrType::U32, {&operand});
}
void IrBuilder::SetScalarReg(ScalarReg reg, IrValue& value) {
IrValue& operand = createRegisterOperand(program, RegisterBank::Scalar, RegIndex(reg), IrType::ScalarReg);
(void)Emit(IrOpcode::SetScalarRegister, IrType::Void, {&operand, &value});
}
IrValue& IrBuilder::GetThreadBitScalarReg(ScalarReg reg) {
IrValue& operand = createRegisterOperand(program, RegisterBank::ThreadBitScalar, RegIndex(reg), IrType::ScalarReg);
return Emit(IrOpcode::GetThreadBitScalarRegister, IrType::Bool, {&operand});
}
void IrBuilder::SetThreadBitScalarReg(ScalarReg reg, IrValue& value) {
IrValue& operand = createRegisterOperand(program, RegisterBank::ThreadBitScalar, RegIndex(reg), IrType::ScalarReg);
(void)Emit(IrOpcode::SetThreadBitScalarRegister, IrType::Void, {&operand, &value});
}
IrValue& IrBuilder::GetScalarMaskTag(ScalarReg reg) {
IrValue& operand = createRegisterOperand(program, RegisterBank::ScalarMaskTag, RegIndex(reg), IrType::ScalarReg);
return Emit(IrOpcode::GetScalarMaskTag, IrType::Bool, {&operand});
}
void IrBuilder::SetScalarMaskTag(ScalarReg reg, IrValue& value) {
IrValue& operand = createRegisterOperand(program, RegisterBank::ScalarMaskTag, RegIndex(reg), IrType::ScalarReg);
(void)Emit(IrOpcode::SetScalarMaskTag, IrType::Void, {&operand, &value});
}
IrValue& IrBuilder::GetVectorReg(VectorReg reg) {
IrValue& operand = createRegisterOperand(program, RegisterBank::Vector, RegIndex(reg), IrType::VectorReg);
return Emit(IrOpcode::GetVectorRegister, IrType::U32, {&operand});
}
void IrBuilder::SetVectorReg(VectorReg reg, IrValue& value) {
IrValue& operand = createRegisterOperand(program, RegisterBank::Vector, RegIndex(reg), IrType::VectorReg);
(void)Emit(IrOpcode::SetVectorRegister, IrType::Void, {&operand, &value});
}
}