Repository navigation
shader: accept scalar work between a mesh diamond join and its EXEC restore (Part of #3416) - #3633
Conversation
…estore A compiler may schedule EXEC-independent scalar instructions (SMEM loads, SALU, s_waitcnt, s_clause) between the join of a signed-CMPX if/else and the s_mov_b64 exec restore that closes it. The frontend accepted the restore only at the join and refused the rest as an EXEC write inside a lane-skip block. Those instructions run once per wave whatever EXEC holds, so the restore still closes the diamond. Each must leave EXEC, VCC and control flow alone, no other path may arrive in the gap, and the restore must still name the open skip's guard. Tests to follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The positive case places a table load, its wait and a scalar add between the join of a signed-CMPX diamond and the restore. Controls put a VCC write, a branch, a saved-mask overwrite or an EXEC read in the same gap, and each keeps the restore refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lukaslw-lab
left a comment
There was a problem hiding this comment.
Reviewed ebaf1817 by reading the diff; not built or run. I checked the two target sites offline on our side (see the table).
Verdict: approve. The acceptance stays on the existing closed-nested-skip terms: the restored mask must be the open skip's own guard (gfx1013_direct_mesh.inl:1074). So whatever the gap holds, a restore cannot enable lanes outside the skip. The gap allowlist is extra caution on top of that. No MUST.
Target sites, using compile_dxil built from main 35a3f6d + #3619 (inert without heap_tokens; the rest of the mesh frontend is unchanged up to bee9c64), with the #3416 layout, offline on Windows 10 19045:
| Request | Main | Join → restore |
|---|---|---|
| f2b3d808 | +0x70c EXEC write inside a lane-skip block |
join +0x6fc: s_load_dwordx4, s_buffer_load_dword, then s_mov_b64 exec, s[20:21] |
| 2319d05e | same | same shape; s[20:21] saved at +0x4e0, inside the skip opened at +0x1ac, so the mask is the guard |
- SHOULD The fixture's gap (
native_direct_mesh_check.py,scalar_gap) hass_load_dwordx4,s_waitcntands_add_u32, but nos_buffer_load_dword. That is the second instruction at both real sites, and the only path through the SMEM op 8–12 branch (:424). Adding one toscalar_gapcovers that branch. - NIT
diamond_joinedis set at the join (:409) before it is read (:416). So a restore placed at the join of a diamond whose restore names another mask (restores_exec == false) is now accepted too, when that mask is the guard. This is sound on the same terms, but neither the comment nor a fixture describes it. - NIT The SALU test is a name denylist (
:429).s_call_b64,s_setreg_b32,s_subvector_loop_*ands_rfe_b64pass it, and they stay safe only because the frontend refuses them later (:1274). An allowlist of the SALU forms the frontend lowers would keep the gap rule tight as SOPK support grows (thes_movk_i32claim on #2413).
Tests: the four negative controls prove that a VCC write, a branch, a saved-mask overwrite or an EXEC read in the gap keeps the refusal. CI did not run them: native_direct_mesh is not in the pr preset filter. The author ran it locally (192/192).
|
Thanks for the review. All three points are in
Mutation checks, each caught by
|
|
This merged before my review follow-up landed. The follow-up is now #3646, on top of main. |
shader: review follow-up for the mesh diamond restore gap (#3633)
Part of #3416 (claim in #2413). Target
main.Problem
mesh EXEC write inside a lane-skip blockis the second-largest C++ refusal among the top slot 57 variants in the #3416 call-weighted table (0.78 M refusedDispatchMeshcalls in a 360 s run). In those programs a signed-CMPX if/else closes withs_mov_b64 exec, <saved>, but the compiler places EXEC-independent scalar work between the diamond's join and that restore:s_waitcntands_clause.The frontend accepted the restore only exactly at the join. With anything in between, the restore counted as an EXEC write inside the enclosing lane skip.
Change
src/gfx1013_direct_mesh.inl,lower_mesh:diamond_joinedflag for as long as each following instruction is EXEC-independent scalar work:s_load_dword*,s_buffer_load_dword*) that write below VCC;s_waitcnt,s_clauseands_nop;movrelforms.s_mov_b64 exec, <saved>reached while the flag holds is accepted on the same terms as the existing closed-nested-skip restore: the saved mask must still be valid and must name the open skip's guard. An instruction in the gap that overwrites the saved mask therefore still leaves the restore refused.These instructions run once per wave whatever EXEC holds, so their effect is the same as if they followed the restore. #2900 made the same argument for the compute path.
Tests
tests/native_direct_mesh_check.py, next to the existingsigned-cmpx-exec-restorecase. Programs are source-built gfx1013 words:signed-cmpx-scalar-gap: the same diamond with a tables_load_dwordx4, itss_waitcntand ans_add_u32between the join and the restore. It translates, and the join produces aphi.mesh EXEC write inside a lane-skip block:gap-vcc-write:s_mov_b64 vcc, -1in the gap;gap-branch: ans_branchin the gap;gap-saved-mask: the saved mask register overwritten in the gap;gap-exec-read:s_mov_b64 s[28:29], execin the gap.signed-cmpx-scalar-gapfails at+0x5c;gap-vcc-writecompile.Windows 11 build 26300, MSVC 19.44, Release, RTX 3090.
ctest --preset release -R "mesh|compile_dxil" -j4: 192 of 192 passed (twomesh_two_exitscapability skips).Census
compile_dxil --refusalsover 454 slot 57 requests in a local start-up cache, with the #3416 layout (packed_parameters,validate_uint_heap_reads,guest_root):mesh EXEC write inside a lane-skip blockThe 55 requests that move on stop at later refusals, mostly instructions the mesh frontend does not cover yet:
v_fma_mixlo_f16v_sqrt_f32v_fmamk_f32v_cvt_f16_f32s_movk_i32v_cmpx_eq_i32v_fma_mixhi_f16No request translates fully yet, so this does not change a title draw on its own.
Not covered: the 8 left with this refusal include an else arm (
s_andn2_b64 exec, <older saved mask>, exec) that merges lanes after a large then-arm with scalar branches. That needs lane-merge support, which is not part of this change.🤖 Generated with Claude Code