shader: fold constant bit reversal before flat stack classification

Co-authored-by: TheCruZ <thecruzwtf@gmail.com>
Co-authored-by: Ali Almohaya <AliAlmohaya@gmail.com>
This commit is contained in:
nmzik
2026-10-04 05:40:54 +04:00
parent a55a28380d
commit 139b564c01
2 changed files with 14 additions and 1 deletions
@@ -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)) {
+3 -1
View File
@@ -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;
}