From 9965a0c9b443f25d60264d3c2afeb76806ce5891 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Sun, 29 Nov 2026 04:34:27 +0100 Subject: [PATCH 1/2] mesh: accept the group exchange without the EXEC save The native mesh frontend matched the group-id exchange only when it starts with s_mov_b64 exec, 1 followed by s_mov_b64 s[saved], exec. The same sequence also appears without that save (60 bytes instead of 64, every other word identical), and was refused as an unsupported s_mov_b64. The matcher now accepts both forms: without the save it writes no saved pair, takes the temporary from the first word after the opener and keeps every other guard. A later EXEC restore from a pair that was never saved is still refused. Tests: the no-save form is accepted with the same group-id result; the no-save form followed by s_mov_b64 exec, s[22:23] is refused with the restore error. --- src/gfx1013_direct_mesh.inl | 28 +++++++++++++++++++--------- tests/native_direct_mesh_check.py | 5 +++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/gfx1013_direct_mesh.inl b/src/gfx1013_direct_mesh.inl index 260d0762f5..6dfe08b0c4 100644 --- a/src/gfx1013_direct_mesh.inl +++ b/src/gfx1013_direct_mesh.inl @@ -378,18 +378,28 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout // writes its first lane's mesh-group identifier before the rendezvous, // the other waves read the same LDS word after it. Only v_readfirstlane // may use the result; v0 and the inactive lanes of v5 are not uniform. - if (raw == 0xbefe0481 && code.size()-pc >= 64) { - const Word save = word(code,pc+4), mask = word(code,pc+8); + if (raw == 0xbefe0481 && code.size()-pc >= 60) { + const Word save = word(code,pc+4); + const bool has_save = (save & 0xff80ffff) == 0xbe80047e; + const unsigned mask_offset = has_save ? 8 : 4; constexpr Word tail[]{0x0f000000,0xbf850007,0x2c0a0a87,0x7e000280,0xd8340008,0x500, 0xbfa3ffe3,0xbf8a0000,0xbf820004,0xbf8a0000,0x7e000280,0xd8d80008,0x05000000}; - bool exchange = (save & 0xff80ffff) == 0xbe80047e && (mask & 0xff80ffff) == 0x8700ff03; - for (unsigned k=0;k= exchange_size && (mask & 0xff80ffff) == 0x8700ff03; + for (unsigned k=0;exchange && k>16)&127, temp = (mask>>16)&127; if (exchange && !branch && !exec_skip && full_exec && !layout.wave32 && layout.group_stride && !alu.graphics_registers.count(3) && - !alu.graphics_registers.count(261) && saved<=104 && !(saved&1) && temp<106 && - temp!=saved && temp!=saved+1) { - alu.write(saved,"1"); - alu.write(saved+1,"0"); + !alu.graphics_registers.count(261) && temp<106 && + (!has_save || (saved<=104 && !(saved&1) && temp!=saved && temp!=saved+1))) { + if (has_save) { + alu.write(saved,"1"); + alu.write(saved+1,"0"); + } else { + // The scalar AND overwrites any reaching mask word in temp. + state[temp]={}; + } const auto merged = ir.binary("shl",wave_number,"24"); alu.write(temp,merged); alu.write(128,ir.value("zext i1 "+alu.cmp("ne",merged,"0")+" to i32")); @@ -398,7 +408,7 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout alu.write(256,{}); alu.write(261,{}); full_exec=false; - pc+=64; + pc+=exchange_size; continue; } } diff --git a/tests/native_direct_mesh_check.py b/tests/native_direct_mesh_check.py index baa0fdd947..7dbe5ea2a4 100644 --- a/tests/native_direct_mesh_check.py +++ b/tests/native_direct_mesh_check.py @@ -278,6 +278,11 @@ def movv(v,s): return 0x7e000200|(v<<17)|s reads_group = program.copy() reads_group[7] = 0x7e020c12 # v_cvt_f32_u32 v1,s18 uses the readfirstlane result assert 'call i32 @dx.op.groupId.i32' in run('group',exchange+reads_group) + no_save = exchange[:1] + exchange[2:] + assert 'call i32 @dx.op.groupId.i32' in run('group-no-save',no_save+reads_group) + invalid_restore = no_save.copy() + invalid_restore[-2] = 0xbefe0416 # s_mov_b64 exec, s[22:23] + run('group-no-save-restore',invalid_restore+reads_group,'mesh EXEC restore lacks a still-valid reaching mask') broken = exchange.copy() broken[12] = 0xbf800000 # missing rendezvous on the reading wave run('mismatched-barriers',broken+reads_group,'mesh group-index exchange shape or entry state is not covered') From 08cf44c842bc43c3c5b74b1a5b4600f29b544e5d Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Sun, 29 Nov 2026 08:15:40 +0100 Subject: [PATCH 2/2] tests: refuse near-miss 60-byte mesh exchange windows Flip one bit of the AND mask or of the first fixed tail word inside the no-save exchange window; the matcher must not accept either, and the opener is then refused as an unsupported EXEC state. --- tests/native_direct_mesh_check.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/native_direct_mesh_check.py b/tests/native_direct_mesh_check.py index 7dbe5ea2a4..67fa093787 100644 --- a/tests/native_direct_mesh_check.py +++ b/tests/native_direct_mesh_check.py @@ -283,6 +283,13 @@ def movv(v,s): return 0x7e000200|(v<<17)|s invalid_restore = no_save.copy() invalid_restore[-2] = 0xbefe0416 # s_mov_b64 exec, s[22:23] run('group-no-save-restore',invalid_restore+reads_group,'mesh EXEC restore lacks a still-valid reaching mask') + # src/gfx1013_direct_mesh.inl:1133 refuses an unmatched group-index exchange opener. + near_tail = no_save.copy() + near_tail[2] ^= 1 # 0x0f000000 is the first fixed tail word, directly after the AND mask. + run('group-no-save-near-tail',near_tail+reads_group,'mesh group-index exchange shape or entry state is not covered') + near_mask = no_save.copy() + near_mask[1] ^= 1 # Flip a compared bit outside the destination field. + run('group-no-save-near-mask',near_mask+reads_group,'mesh group-index exchange shape or entry state is not covered') broken = exchange.copy() broken[12] = 0xbf800000 # missing rendezvous on the reading wave run('mismatched-barriers',broken+reads_group,'mesh group-index exchange shape or entry state is not covered')