feat(shader): arithmetic + ext regs + logic impl for ir builder

This commit is contained in:
boykopovar 2026-09-15 11:44:42 +03:00
parent 039b88b08e
commit e4490a0272
3 changed files with 66 additions and 54 deletions

View File

@ -1,46 +1,45 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include <stdexcept>
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});
}
}

View File

@ -1,78 +1,79 @@
#include "IntermediateRepresentation/IrBuilder.hpp"
#include <stdexcept>
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});
}
}

View File

@ -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});
}
}