diff --git a/src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp b/src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp index 0c38286f3..5878a5873 100644 --- a/src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp +++ b/src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp @@ -503,6 +503,17 @@ void FoldInstruction(Block& block, Block::iterator instruction, } return; } + case ValueOpcode::BitReverse32: { + const auto value = Arg(inst, 0); + if (IsImmediate(value, Type::U32)) { + uint32_t source = value.U32(), reversed = 0; + for (uint32_t bit = 0; bit < 32u; ++bit, source >>= 1u) { + reversed = (reversed << 1u) | (source & 1u); + } + Replace(inst, Value(reversed)); + } + return; + } case ValueOpcode::BitCount32: { const auto value = Arg(inst, 0); if (IsImmediate(value, Type::U32)) { diff --git a/tests/ShaderRayTracingGpuTests.inc b/tests/ShaderRayTracingGpuTests.inc index bae25ca3c..6ba16f1a7 100644 --- a/tests/ShaderRayTracingGpuTests.inc +++ b/tests/ShaderRayTracingGpuTests.inc @@ -3,7 +3,7 @@ TestCase FlatStackApertures(u32 wave_size) { test.name = wave_size == 32 ? "FlatStackApertures32" : "FlatStackApertures64"; auto &code = test.code; code = {EncodeSop1(0x04, 8, 237), // private base - EncodeSop1(0x04, 10, 235), // shared base + EncodeSop1(0x0b, 11, InlineU32(1)), // S_BREV_B32 shared aperture, as in GTA. EncodeVop2(0x1a, 20, InlineU32(2), 0), EncodeVop2(0x1b, 22, InlineU32(1), 0), EncodeVop2(0x1a, 22, InlineU32(31), 22)}; @@ -77,6 +77,8 @@ TestCase FlatStackApertures(u32 wave_size) { test.compute_info.scratch_size_dwords = wave_size; test.compute_info.lds_size_dwords = wave_size; test.has_compute_info = true; + test.decoded_counts = {{"S_BREV_B32", 1}}; + test.ir_counts = {{" = BitReverse32 ", 0}}; test.forbidden_spirv = {"get_bda_pointer"}; return test; }