shader: accept scalar work between a mesh diamond join and its EXEC restore (Part of #3416) #3633
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3633"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-30T18:21:20Z.
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
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T18:54:33Z.
Review: APPROVED
Reviewed
ebaf1817by 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_dxilbuilt from main35a3f6d6+ #3619 (inert withoutheap_tokens; the rest of the mesh frontend is unchanged up tobee9c64d), with the #3416 layout, offline on Windows 10 19045:+0x70cEXEC write inside a lane-skip block+0x6fc:s_load_dwordx4,s_buffer_load_dword, thens_mov_b64 exec, s[20:21]s[20:21]saved at+0x4e0, inside the skip opened at+0x1ac, so the mask is the guardnative_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.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.: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_meshis not in theprpreset filter. The author ran it locally (192/192).Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-30T19:50:18Z.
Thanks for the review. All three points are in
dbf725ef, on top of a merge of maina0e126c2:scalar_gapnow includess_buffer_load_dword s30, s[24:27], 0and its wait, so the positive case goes through the SMEM op 8–12 path.s_cmp*/s_bitcmp*for SOPC.s_call_b64,s_setreg_b32,s_subvector_loop_*,s_rfe_b64and every 64-bit form now end the gap. New controlgap-salu-b64(s_mov_b64 s[30:31], 0in the gap) keeps the restore refused.diamond_joined=true. A restore at the join of a diamond whose own restore names another mask is accepted only when the mask it names is the open skip's guard.Mutation checks, each caught by
native_direct_mesh:s_mov_b64;diamond_joinedunconditionally.ctest -R "mesh|compile_dxil" -j 4: 202 passed (the twomesh_two_exitsskips, as on main). Census on the 454 cached requests is unchanged: 8mesh EXEC write inside a lane-skip blockleft.Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-30T20:43:59Z.
This merged before my review follow-up landed. The follow-up is now #3646, on top of main.