From 9886eb8e61fab589e743b83e6367b43dce404423 Mon Sep 17 00:00:00 2001 From: Luuk Motz Date: Tue, 1 Dec 2026 08:55:23 +0100 Subject: [PATCH 1/2] shader: lower s_not_b32, s_brev_b32 and s_bfe_i32 in the mesh frontend The shared scalar ALU already lowers all three, SCC included. The mesh frontend refused them with "unsupported mesh instruction or EXEC state". They now join s_bfe_u32 and s_min_u32 on the shared path, with the same EXEC and VCC destination refusals. On a native Mesh86 capture (1,569 distinct slot 86 programs), these were the first refusal for 555 of them, and 122 more now translate fully. Co-Authored-By: Claude Opus 5.5 --- src/gfx1013_direct_mesh.inl | 4 +++- tests/native_direct_mesh_check.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/gfx1013_direct_mesh.inl b/src/gfx1013_direct_mesh.inl index ee48a603b7..1f16a69a02 100644 --- a/src/gfx1013_direct_mesh.inl +++ b/src/gfx1013_direct_mesh.inl @@ -1827,7 +1827,9 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout const auto sum=ir.binary("add",lo,hi); alu.write(i.dst,sum); alu.write(128,ir.value("zext i1 "+alu.cmp("ne",sum,"0")+" to i32")); - } else if (i.name=="s_bfe_u32" || i.name=="s_min_u32") { + } else if (i.name=="s_bfe_u32" || i.name=="s_min_u32" || i.name=="s_bfe_i32" || + i.name=="s_not_b32" || i.name=="s_brev_b32") { + // The shared scalar ALU lowers each one, SCC included (s_brev_b32 leaves it unchanged). if (i.dst==126 || i.dst==127) refuse(pc,"mesh scalar write to EXEC"); if (i.dst==106 || i.dst==107) refuse(pc,"mesh scalar write to VCC"); alu.arithmetic(i,state); diff --git a/tests/native_direct_mesh_check.py b/tests/native_direct_mesh_check.py index 03b310a893..c5e46a2e88 100644 --- a/tests/native_direct_mesh_check.py +++ b/tests/native_direct_mesh_check.py @@ -398,7 +398,27 @@ def run(name, words, expected=None): xor = re.search(r'(%[\w.]+) = xor i32 -2, -1\n', text) assert xor, text assert_position_x(text, r'and i32 ' + re.escape(xor[1]) + ',') + # s_not_b32, s_brev_b32 and s_bfe_i32 on the same s20 = -2 go through the shared scalar ALU. + movk = 0xb014fffe # s_movk_i32 s20, 0xfffe + use = 0x36020015 # v_and_b32 v1, s21, v0 + text = run('scalar-not', program[:5] + [movk, 0xbe950714, use] + program[6:]) # s_not_b32 s21, s20 + inverted = re.search(r'(%[\w.]+) = xor i32 -2, -1\n', text) + assert inverted, text + assert_position_x(text, r'and i32 ' + re.escape(inverted[1]) + ',') + text = run('scalar-brev', program[:5] + [movk, 0xbe950b14, use] + program[6:]) # s_brev_b32 s21, s20 + reversed_bits = re.search(r'(%[\w.]+) = call i32 @dx\.op\.unary\.i32\(i32 30, i32 -2\)', text) + assert reversed_bits, text + assert_position_x(text, r'and i32 ' + re.escape(reversed_bits[1]) + ',') + # s_bfe_i32 s21, s20, 0x80004: 8 bits from bit 4, sign-extended (an arithmetic shift, not a logical one). + text = run('scalar-bfe-i32', program[:5] + [movk, 0x9415ff14, 0x00080004, use] + program[6:]) + signed = re.search(r'(?P%[\w.]+) = ashr i32 -2, %[\w.]+\n.*?' + r'(?P%[\w.]+) = shl i32 (?P=shifted), (?P%[\w.]+)\n' + r'\s*%[\w.]+ = ashr i32 (?P=up), (?P=pad)\n', text, re.S) + assert signed and not re.search(r'= lshr i32 -2,', text), text for scalar_k_case, scalar_k_word, scalar_k_reason in ( + ('scalar-not-exec', 0xbefe0714, 'mesh scalar write to EXEC'), # s_not_b32 exec_lo, s20 + ('scalar-brev-vcc', 0xbeea0b14, 'mesh scalar write to VCC'), # s_brev_b32 vcc_lo, s20 + ('scalar-not-vcc-hi', 0xbeeb0714, 'mesh scalar write to VCC'), # s_not_b32 vcc_hi, s20 ('scalar-movk-vcc', 0xb06afffe, 'unsupported mesh instruction or EXEC state: s_movk_i32'), ('scalar-movk-exec', 0xb07efffe, 'unsupported mesh instruction or EXEC state: s_movk_i32'), ('scalar-movk-m0', 0xb07cfffe, 'unsupported mesh instruction or EXEC state: s_movk_i32'), From a6602c755b1274cf24f14500491fbbb9a1f223d8 Mon Sep 17 00:00:00 2001 From: Luuk Motz Date: Tue, 1 Dec 2026 09:33:01 +0100 Subject: [PATCH 2/2] tests: pin SCC for s_brev_b32 and s_not_b32 in the mesh frontend Review follow-up on #3708. After s_cmp_eq_u32 s20, 0, an s_cselect_b32 behind s_brev_b32 still selects on the compare's SCC, and behind s_not_b32 on (result != 0). Both selects reach the exported X. Co-Authored-By: Claude Opus 5.5 --- tests/native_direct_mesh_check.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/native_direct_mesh_check.py b/tests/native_direct_mesh_check.py index c5e46a2e88..68b4bb360a 100644 --- a/tests/native_direct_mesh_check.py +++ b/tests/native_direct_mesh_check.py @@ -415,6 +415,24 @@ def run(name, words, expected=None): r'(?P%[\w.]+) = shl i32 (?P=shifted), (?P%[\w.]+)\n' r'\s*%[\w.]+ = ashr i32 (?P=up), (?P=pad)\n', text, re.S) assert signed and not re.search(r'= lshr i32 -2,', text), text + # SCC: s_cmp_eq_u32 s20, 0 sets it, then s_cselect_b32 s21, 1, 0 reads it after the op. + # s_brev_b32 leaves the compare's SCC; s_not_b32 replaces it with (result != 0). + compare, cselect = 0xbf068014, 0x85158081 + text = run('scalar-brev-keeps-scc', program[:5] + [movk, compare, 0xbe960b14, # s_brev_b32 s22, s20 + cselect, use] + program[6:]) + kept_scc = re.search(r'(?P%[\w.]+) = icmp eq i32 -2, 0\n\s*(?P%[\w.]+) = zext i1 (?P=cmp) to i32\n.*?' + r'(?P%[\w.]+) = icmp ne i32 (?P=scc), 0\n\s*' + r'(?P%[\w.]+) = select i1 (?P=test), i32 1, i32 0\n', text, re.S) + assert kept_scc, text + assert_position_x(text, r'and i32 ' + re.escape(kept_scc['pick']) + ',') + text = run('scalar-not-sets-scc', program[:5] + [movk, compare, 0xbe960714, # s_not_b32 s22, s20 + cselect, use] + program[6:]) + not_scc = re.search(r'(?P%[\w.]+) = xor i32 -2, -1\n.*?' + r'(?P%[\w.]+) = icmp ne i32 (?P=not), 0\n\s*(?P%[\w.]+) = zext i1 (?P=nz) to i32\n.*?' + r'(?P%[\w.]+) = icmp ne i32 (?P=scc), 0\n\s*' + r'(?P%[\w.]+) = select i1 (?P=test), i32 1, i32 0\n', text, re.S) + assert not_scc, text + assert_position_x(text, r'and i32 ' + re.escape(not_scc['pick']) + ',') for scalar_k_case, scalar_k_word, scalar_k_reason in ( ('scalar-not-exec', 0xbefe0714, 'mesh scalar write to EXEC'), # s_not_b32 exec_lo, s20 ('scalar-brev-vcc', 0xbeea0b14, 'mesh scalar write to VCC'), # s_brev_b32 vcc_lo, s20