shader: add BVH stack operations

This commit is contained in:
nmzik committed 2026-10-29 18:37:29 +01:00
1 parent 6ff6e7551d
commit bfd4c34b88
18 files changed
+419 -3

No files matched your search

+41
View File
@@ -1,4 +1,45 @@
void TestTrinityStackInstruction() {
namespace D = ShaderRecompiler::Decoder;
const std::array code{0xdb840008u, 0x01010a09u,
0xdb840010u, 0x02010a09u, EncodeSopp(0x01)};
D::Program decoded;
D::DecodeProgram(code, decoded);
const auto& first = decoded.instructions.front();
Check(first.opcode == D::Opcode::DS_BVH_STACK_PUSH8_POP1_RTN_B32 &&
first.src_count == 3 && first.offset == 8 && first.dst.reg == 1 &&
first.src0.reg == 9 && first.src1.reg == 10 && first.src2.reg == 1,
"Trinity stack operands or capacity were not decoded");
ShaderComputeInputInfo compute{};
compute.lds_size_dwords = 1024;
auto options = MakeCompileOptions(ShaderType::Compute);
options.input_info.compute = &compute;
const auto result = RecompileForTest(code, options);
Check(CountSourceOccurrences(result.ir_dump, " = BvhStack ") == 2 &&
result.program.info.uses_lds && result.program.info.bvh_stack &&
!result.program.info.shared_int64_atomics,
"unused stack results discarded LDS writes or selected 64-bit atomics");
Check(SpirvInstructionOpcodeCount(result.spirv, 54u) == 2 &&
SpirvInstructionOpcodeCount(result.spirv, 246u) == 1,
"Trinity stack calls duplicated the function or unrolled its eight pushes");
CheckSpirvBinaryValidates(result.spirv);
compute.lds_storage = true;
CheckSpirvBinaryValidates(RecompileForTest(code, options).spirv);
options = MakeCompileOptions(ShaderType::Pixel);
CheckSpirvBinaryValidates(RecompileForTest(code, options).spirv);
for (const auto words : {std::array{0xdb860008u, 0x01010a09u},
std::array{0xdb840007u, 0x01010a09u},
std::array{0xdb840020u, 0x01010a09u},
std::array{0xdb840008u, 0x01f90a09u},
std::array{0xdb840008u, 0x09010a09u}}) {
const std::array invalid{words[0], words[1], EncodeSopp(0x01)};
D::DecodeProgram(invalid, decoded);
Check(decoded.instructions[0].opcode == D::Opcode::UNSUPPORTED,
"unsupported stack encoding was silently accepted");
}
}
void TestRayTracingInstructions() {
TestTrinityStackInstruction();
namespace D = ShaderRecompiler::Decoder;
const std::array code{
0xf1989f01u, 0x00081014u,