shader: remove recompiler error-string propagation

This commit is contained in:
nmzik
2026-08-31 05:30:18 +04:00
parent 13533bd053
commit af8aecfdde
47 changed files with 2040 additions and 3253 deletions
@@ -1,5 +1,6 @@
#include "graphics/shader/recompiler/frontend/decode/ShaderDecoder.h"
#include "common/assert.h"
#include "graphics/shader/recompiler/frontend/decode/ExportOps.h"
#include "graphics/shader/recompiler/frontend/decode/ImageOps.h"
#include "graphics/shader/recompiler/frontend/decode/MemoryOps.h"
@@ -17,12 +18,6 @@ uint32_t FloatBits(float value) {
return std::bit_cast<uint32_t>(value);
}
void SetError(std::string* error, const char* message) {
if (error != nullptr) {
*error = message;
}
}
bool HasLiteral(const Instruction& inst) {
return inst.src0.kind == OperandKind::LiteralConstant ||
inst.src1.kind == OperandKind::LiteralConstant ||
@@ -216,86 +211,76 @@ const char* ImageDimensionToString(ImageDimension dimension) {
}
}
bool DecodeScalarSource(uint32_t code, uint32_t pc, Operand& operand, std::string* error) {
void DecodeScalarSource(uint32_t code, uint32_t pc, Operand& operand) {
operand = {};
if (code <= 105u) {
operand.kind = OperandKind::Sgpr;
operand.reg = code;
return true;
return;
}
if (code >= 128u && code <= 192u) {
operand.kind = OperandKind::IntegerInlineConstant;
operand.signed_val = static_cast<int32_t>(code - 128u);
operand.value = static_cast<uint32_t>(operand.signed_val);
return true;
return;
}
if (code >= 193u && code <= 208u) {
operand.kind = OperandKind::IntegerInlineConstant;
operand.signed_val = 192 - static_cast<int32_t>(code);
operand.value = static_cast<uint32_t>(operand.signed_val);
return true;
return;
}
if (code >= 240u && code <= 247u) {
constexpr float values[] = {0.5f, -0.5f, 1.0f, -1.0f, 2.0f, -2.0f, 4.0f, -4.0f};
operand.kind = OperandKind::FloatInlineConstant;
operand.float_val = values[code - 240u];
operand.value = FloatBits(operand.float_val);
return true;
return;
}
if (code >= 256u && code <= 511u) {
DecodeVectorGpr(code - 256u, operand);
return true;
return;
}
switch (code) {
case 106u: operand.kind = OperandKind::VccLo; return true;
case 107u: operand.kind = OperandKind::VccHi; return true;
case 124u: operand.kind = OperandKind::M0; return true;
case 125u: operand.kind = OperandKind::Null; return true;
case 126u: operand.kind = OperandKind::ExecLo; return true;
case 127u: operand.kind = OperandKind::ExecHi; return true;
case 239u: operand.kind = OperandKind::PopsExitingWaveId; return true;
case 106u: operand.kind = OperandKind::VccLo; return;
case 107u: operand.kind = OperandKind::VccHi; return;
case 124u: operand.kind = OperandKind::M0; return;
case 125u: operand.kind = OperandKind::Null; return;
case 126u: operand.kind = OperandKind::ExecLo; return;
case 127u: operand.kind = OperandKind::ExecHi; return;
case 239u: operand.kind = OperandKind::PopsExitingWaveId; return;
case 248u:
operand.kind = OperandKind::FloatInlineConstant;
operand.float_val = 0.15915494309189535f;
operand.value = FloatBits(operand.float_val);
return true;
case 251u: operand.kind = OperandKind::VccZ; return true;
case 252u: operand.kind = OperandKind::ExecZ; return true;
case 253u: operand.kind = OperandKind::Scc; return true;
case 255u: operand.kind = OperandKind::LiteralConstant; return true;
default:
if (error != nullptr) {
*error = fmt::format("unsupported scalar source operand 0x{:08x} at pc 0x{:08x}",
code, pc);
}
return false;
return;
case 251u: operand.kind = OperandKind::VccZ; return;
case 252u: operand.kind = OperandKind::ExecZ; return;
case 253u: operand.kind = OperandKind::Scc; return;
case 255u: operand.kind = OperandKind::LiteralConstant; return;
default: EXIT("unsupported scalar source operand 0x%08x at pc 0x%08x", code, pc);
}
}
bool DecodeScalarDestination(uint32_t code, uint32_t pc, Operand& operand, std::string* error) {
void DecodeScalarDestination(uint32_t code, uint32_t pc, Operand& operand) {
operand = {};
if (code <= 105u) {
operand.kind = OperandKind::Sgpr;
operand.reg = code;
return true;
return;
}
switch (code) {
case 106u: operand.kind = OperandKind::VccLo; return true;
case 107u: operand.kind = OperandKind::VccHi; return true;
case 124u: operand.kind = OperandKind::M0; return true;
case 125u: operand.kind = OperandKind::Null; return true;
case 126u: operand.kind = OperandKind::ExecLo; return true;
case 127u: operand.kind = OperandKind::ExecHi; return true;
default:
if (error != nullptr) {
*error = fmt::format(
"unsupported scalar destination operand 0x{:08x} at pc 0x{:08x}", code, pc);
}
return false;
case 106u: operand.kind = OperandKind::VccLo; return;
case 107u: operand.kind = OperandKind::VccHi; return;
case 124u: operand.kind = OperandKind::M0; return;
case 125u: operand.kind = OperandKind::Null; return;
case 126u: operand.kind = OperandKind::ExecLo; return;
case 127u: operand.kind = OperandKind::ExecHi; return;
default: EXIT("unsupported scalar destination operand 0x%08x at pc 0x%08x", code, pc);
}
}
@@ -368,39 +353,33 @@ Family GetInstructionFamily(uint32_t word) {
}
}
bool DecodeInstruction(std::span<const uint32_t> code, uint32_t word_index, Instruction& inst,
std::string* error) {
void DecodeInstruction(std::span<const uint32_t> code, uint32_t word_index, Instruction& inst) {
const uint32_t pc = word_index * sizeof(uint32_t);
switch (GetInstructionFamily(code[word_index])) {
case Family::SOP1: return DecodeSop1(pc, code, word_index, inst, error);
case Family::SOP2: return DecodeSop2(pc, code, word_index, inst, error);
case Family::SOPK: return DecodeSopk(pc, code, word_index, inst, error);
case Family::SOPC: return DecodeSopc(pc, code, word_index, inst, error);
case Family::SOPP: DecodeSopp(pc, code, word_index, inst); return true;
case Family::VOP1: return DecodeVop1(pc, code, word_index, inst, error);
case Family::VOP2: return DecodeVop2(pc, code, word_index, inst, error);
case Family::VOP3: return DecodeVop3(pc, code, word_index, inst, error);
case Family::VOP3P: return DecodeVop3p(pc, code, word_index, inst, error);
case Family::VOPC: return DecodeVopc(pc, code, word_index, inst, error);
case Family::VINTRP: DecodeVintrp(pc, code, word_index, inst); return true;
case Family::SMEM: DecodeSmem(pc, code, word_index, inst); return true;
case Family::MUBUF: DecodeMubuf(pc, code, word_index, inst); return true;
case Family::MTBUF: DecodeMtbuf(pc, code, word_index, inst); return true;
case Family::FLAT: DecodeFlat(pc, code, word_index, inst); return true;
case Family::DS: DecodeDs(pc, code, word_index, inst); return true;
case Family::MIMG: DecodeMimg(pc, code, word_index, inst); return true;
case Family::EXP: DecodeExp(pc, code, word_index, inst); return true;
case Family::SOP1: DecodeSop1(pc, code, word_index, inst); return;
case Family::SOP2: DecodeSop2(pc, code, word_index, inst); return;
case Family::SOPK: DecodeSopk(pc, code, word_index, inst); return;
case Family::SOPC: DecodeSopc(pc, code, word_index, inst); return;
case Family::SOPP: DecodeSopp(pc, code, word_index, inst); return;
case Family::VOP1: DecodeVop1(pc, code, word_index, inst); return;
case Family::VOP2: DecodeVop2(pc, code, word_index, inst); return;
case Family::VOP3: DecodeVop3(pc, code, word_index, inst); return;
case Family::VOP3P: DecodeVop3p(pc, code, word_index, inst); return;
case Family::VOPC: DecodeVopc(pc, code, word_index, inst); return;
case Family::VINTRP: DecodeVintrp(pc, code, word_index, inst); return;
case Family::SMEM: DecodeSmem(pc, code, word_index, inst); return;
case Family::MUBUF: DecodeMubuf(pc, code, word_index, inst); return;
case Family::MTBUF: DecodeMtbuf(pc, code, word_index, inst); return;
case Family::FLAT: DecodeFlat(pc, code, word_index, inst); return;
case Family::DS: DecodeDs(pc, code, word_index, inst); return;
case Family::MIMG: DecodeMimg(pc, code, word_index, inst); return;
case Family::EXP: DecodeExp(pc, code, word_index, inst); return;
default:
if (error != nullptr) {
*error =
fmt::format("unknown RDNA2 instruction family at pc 0x{:08x}, raw=0x{:08x}", pc,
code[word_index]);
}
return false;
EXIT("unknown RDNA2 instruction family at pc 0x%08x, raw=0x%08x", pc, code[word_index]);
}
}
bool DecodeProgram(std::span<const uint32_t> code, Program& program, std::string* error) {
void DecodeProgram(std::span<const uint32_t> code, Program& program) {
program.instructions.clear();
program.instructions.reserve(code.size());
program.code = code;
@@ -408,10 +387,7 @@ bool DecodeProgram(std::span<const uint32_t> code, Program& program, std::string
std::vector<bool> branch_targets;
for (uint32_t word_index = 0; word_index < code.size();) {
program.instructions.emplace_back();
if (!DecodeInstruction(code, word_index, program.instructions.back(), error)) {
program.instructions.pop_back();
return false;
}
DecodeInstruction(code, word_index, program.instructions.back());
const auto& inst = program.instructions.back();
word_index += inst.word_count;
@@ -425,12 +401,11 @@ bool DecodeProgram(std::span<const uint32_t> code, Program& program, std::string
}
if (inst.opcode == Opcode::S_ENDPGM &&
(word_index >= code.size() || branch_targets.empty() || !branch_targets[word_index])) {
return true;
return;
}
}
SetError(error, "shader decode reached the code boundary before S_ENDPGM");
return false;
EXIT("shader decode reached the code boundary before S_ENDPGM");
}
std::string OperandToString(const Operand& operand) {