shader: lower s_and_saveexec_b64 if/else diamonds inside a mesh lane skip (Part of #2413) #3645
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3645"
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-30T20:37:33Z.
Part of #2413 (claim: https://github.com/R0Y00/Xbox2Windows/issues/2413#issuecomment-7289341190).
The
s_and_saveexec_b64handler from #3638 covers the instruction outside a lane skip. Inside one, the C++ mesh frontend still refused it asunsupported mesh instruction or EXEC state: s_and_saveexec_b64. On main that is the first refusal for 47 of the 454 cached slot 57 requests in my local census.All 47 are a compiler if/else:
s_and_saveexec_b64 sD, sS,s_cbranch_execzover the then arm, thens_andn2_b64 exec, sD, execfor the else arm. The else arm takes one of two shapes:s_cbranch_execz, and its target restoress_mov_b64 exec, sD. This is the same join the existings_and_b64gather diamond uses.s_mov_b64 exec, -1restores full EXEC.Change (
src/gfx1013_direct_mesh.inl)s_and_saveexec_b64case for an open lane skip. It lowers the if/else as a per-lane branch onsSwith the existingDiamond/lane_elsemachinery.sDgets the parent EXEC, recorded as a saved mask, so the inverse and the paired restore resolve to it.Diamond::joins_skip_endflag reorders the two. That flag is only set here, so the order for every existing diamond is unchanged. Such a join also does not open the #3633 restore gap.mesh SAVEEXEC then arm depends on EXECmesh SAVEEXEC then arm has a wave or memory side effects_sendmsg,s_endpgm, PC ops, buffer/image store or atomicmesh SAVEEXEC then arm branches out of the armmesh SAVEEXEC then arm overwrites the saved EXECsDmesh SAVEEXEC else arm is not vector-onlymesh SAVEEXEC else arm reads a scalar the then arm writesTests (
tests/native_direct_mesh_check.py)saveexec-skip-endandsaveexec-paired:v1is 2 in the then arm and 3 in the else arm. The test asserts the join phi[2, then] [3, else]and that the mask branch goes to the then arm.saveexec-then-scalar: an SGPR written and used only in the then arm is accepted.v_cndmask;Mutation checks, each caught by
native_direct_mesh:I ran these on the branch before I merged main with #3633; the only change since then is where the skip close sits after the join.
Verification
ctest --preset release -R "mesh|compile_dxil" -j 4on top of maind5970858: 204 passed (the twomesh_two_exitscases skip, as on main).s_xor_b32(#3635).then arm depends on EXEC(a nested CMPX/EXECZ in the then arm).graphics register undefined on an incoming path(v10–v13). Those are VGPRs written in both arms and read by the position export after the vertex-count exchange, under a different guard. That is the existing refusal class, already the most common one on main; it is not part of this PR.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T20:57:34Z.
Review: APPROVED
Reviewed
29404d76by reading the diff; not built or run.Verdict: approve. The shape match and the per-lane if/else lowering are right for the census shapes, and the change fails closed as described. No MUST. Two SHOULDs extend the then-arm filter the same way the else arm is already filtered. Both are cheap refusals that can follow.
src/gfx1013_direct_mesh.inl,for (auto r : then_writes) if (r<106)). A VOPC e32, or a VOP3 compare intovcc, puts 106/107 intothen_writes, but onlyr < 106reacheslane_scalar_clobbers. On hardware the compare runs with the then-arm EXEC and writes 0 into the else lanes' bits whenever any lane took the then arm. If the per-lane model carries VCC across the join as a per-lane value, else lanes keep their pre-diamond bit. A per-lane VCC read after the join (v_cndmask,_co_ci) would then differ for else lanes. Either clobber 106/107 too, or refuse VCC destinations in the then arm.name.find("lane")).v_readlane_b32orv_permlane16/x16in the then arm read lanes that are inactive there. On hardware that is defined: the register holds whatever the else lanes held. In a divergent per-lane branch a lane read of an inactive lane is undefined.v_readfirstlanehappens to agree, because both sides take the first active then-lane. Refusing*lane*exceptreadfirstlanein the then arm would keep the fail-closed promise.0xbefe04c1iss_mov_b64 exec, -1at the skip end. The inverse must bes_andn2_b64 exec, sD, exec, the paired restore must come fromsD, and both EXECZ targets must stay inside the skip.sDoverwrites are refused.joins_skip_endis set only here. Merging the diamond beforeclose_skip()leaves every other diamond's order unchanged, anddiamond_joined = !join_at_skip_endavoids opening the #3633 gap.Tests: two positive shapes check the join phi
[2, then] [3, else]and the branch direction, plus 10 refusal controls and five mutations. Neither SHOULD case has a control.native_direct_meshis outside the Windowsprpreset filter, so it has only your run ond5970858.Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-30T21:29:05Z.
Thanks. Both SHOULDs are in
b0ee8b5b:vcc,vcccarry-outs (throughcarry_destination) andv_div_scale. A VOP3B carry into an ordinary SGPR goes intothen_writes, so it is clobbered at the join and the else arm may not read it.*lane*name exceptv_readfirstlane_b32.New controls, each at +0x34:
saveexec-then-vopc,saveexec-then-vop3-vcc,saveexec-then-carry,saveexec-then-readlane. I removed each refusal in turn (VCC, carry/div_scale only, lane) and every mutation failsnative_direct_mesh. Mesh andcompile_dxiltests: 204/204.The slot 57 census (454 requests) gives the same result line for every request before and after, so no real then arm hit either refusal.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T01:10:18Z.
Review: APPROVED
Reviewed
b0ee8b5bby reading the diff; not built or run.Verdict: approve.
b0ee8b5bfixes both points from our review at29404d76, and the PR still merges cleanly with maina3bfd019. No MUST.if (carry) { then_writes.insert(...) }(the then-arm loop insrc/gfx1013_direct_mesh.inl) is the only place that keeps the else arm from reading it, and no test fails if that line goes. Asaveexec-else-reads-thenvariant withv_add_co_u32_e64 v1, s[30:31], ...in the then arm andv_mov_b32 v2, s30in the else arm would cover it.carry_destination≥ 106 andv_div_scale*.carry_destinationdoes not listv_mad_i64_i32, but the mesh frontend does not lower it, so it is refused anyway.*lane*exceptv_readfirstlane_b32. readfirstlane writes an SGPR, so it lands inthen_writesand is clobbered at the join.diamond_joinedis set. A join at the skip end sets it false and closes the skip right after, so the #3633 gap is not opened. A join at aforwardtarget still resets it.s_movk_i32ands_xor_b32in the then arm go through the SOPK/SOP2then_writespath.v_bfm_b32is VOP3, which the else arm allows.Tests: four new refusal controls at +0x34 reach the two new refusals (VOPC, VOP3 compare, VOP2 carry, readlane). Your mutation run shows each clause is needed. CI at this head ran before #3644 put
native_direct_meshinto theprfilter, so these controls have not run on CI yet. A rerun or a merge of main would cover them.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-01T01:16:18Z.
Review: APPROVED
Reviewed the paired-EXECZ and enclosing-skip-end shapes, including the saved-mask, cross-lane and side-effect guards.
ctest --test-dir <build> --no-tests=error -j1 -R '^native_direct_mesh$' --output-on-failurepassed. Two extra source-builtv_mov_b32cases readingexec_loorexec_hiin the else arm were refused as unproven entry registers 126 and 127.