fix(shader): prove scalar runs before compute EXEC restores #2900
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2900"
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 brainbudt on 2026-11-26T17:29:04Z.
Problem
A compute lane-exhaustion exit is refused when its destination starts with a scalar descriptor load and wait before restoring EXEC. Refs #2645 (T3).
Change
Prove that exiting lanes cannot observe work on the staying path, verify that both paths reach a safe scalar run (rejecting divergent EXEC, live SCC reads, scalar clobbers, and wave effects such as
s_setprio,s_barrier, ands_sendmsg) and restore an unchanged saved EXEC mask. Add a source-built gfx1013 fixture and refusal controls for wrong remasks, scalar clobbers, unsafe effects, and invalid targets.Scope
Covers straight exits in compute groups of up to 32 threads (the two-mask counted loop remains refused).
Verification
python3 -B tests/startup_gfx2hlsl_compute_check.pypassed (including after rebasing onto latestorigin/main). Wave and singleton traces agreed for both exit outcomes; the original translator refused the accepted fixture withbranch out of the block.python-linux(210/210) and LLVM 15.0.7pixel-binary(136/136) suites passed;python3 -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-15reassembled the fixture byte-for-byte.Reviewed & refined by GPT-6.2 Sol in Codex (APPROVE); implemented with Mistral Large 4 in Mistral Vibe (orchestrated with Gemini 4 Neon in T3 Code).
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-26T18:14:13Z.
Independent Linux host-only result on
088d0d11: the new exit is accepted, the base refuses it, and 8 of the 14 conditions of the new guard are not separated by any controlNot a code change; measurements only.
Environment
088d0d11(base6ee878d8). Blob sha256tools/startup/gfx2hlsl.py382be0e422fd1fba65df93c71d368db8aacacafecbe03f07b9d911b48a748060at the head,0eb758407558cd2997e850712adbda1b0d01a49514976a5b2faa89fe60a8fd38at the base;tests/startup_gfx2hlsl_compute_check.py6e82de0a3b847e9b422cf663f16d4f4d20ed38ef9564045e075acb6363d23616. The translator sha256 is printed before and after every run andgit status --porcelain --untracked-files=nois empty at the end of each pass.Commands
Observed
Head: exit 0, last line
compute entry, numthreads, masked bit counts, manifest, offen store forms and the store, descriptor, execz and sample refusals pass.Base translator with your fixture: exit 1,
so the acceptance is new behaviour and this fixture is what names it — the same A/B you describe, on a machine outside your two.
Which conditions the added controls separate
Stage.execz_scalar_exit(lines 2992-3060 at088d0d11) has 13return Falsesites plus the run's ownsaved_exec(...) and all(...)return. Two measurements: one condition deleted at a time, the motif required to be unique, the tree restored and re-checked by sha256 after each run.Deleting one of these turns the fixture red: M5
live_in[target] & {mask, 'scc'}, M8 the restore right after the branch, M9 the body between that restore and the exit target, M11 the run's scalar-only content, M12 the saved-mask reuse in the run's EXEC write and its guard-range scan, M13 the shape of that EXEC write. Two of them fail through an adjacent refusal rather than through the near-miss that names them: M11 is refused later byLDS exchange needs a 1D group and a nonzero allocation of at most 32 KiB, M13 refuses the accepted fixture itself.Deleting one of these changes no verdict, in this fixture and in the 14 other files of
tests/that build ans_cbranch_scc0inside ans_cbranch_execz-skipped block: M1x * y * z > 32, M2into.get(join) != [guard], M3 no other entry into[guard+1, target), M4 thes_andn2_b32 d, s, exec_loshape, M6saved_execbefore the guard, M7 the body between the guard and the branch, M10 no other entry into the run after its target, M14 the trailingreturn False. (19 files carry both mnemonics, 4 need arguments oriced_x86and were left out, leaving 15 that run bare — this fixture included.)A counter print placed in front of each
return False— behaviour unchanged, exit 0 — shows which refusals the suite actually takes:live_in1,saved_execbefore the guard 1, the restore-after-branch 1, the post-restore body 1, the run's EXEC-write shape 1, the run's saved-register range 1, the run's scalar content 7. Six sites are never taken at all.Putting the two together: seven of the eight green deletions remove a refusal the suite never takes, and three of those (M1, M2, M3) are disjuncts of the single site at 3001-3003. The eighth,
saved_exec(3024-3025), is taken once and removing it still leaves the whole suite green, so no control attributes that program's refusal to this line.Nothing here says the eight are wrong. It says no control in the suite translates a program whose verdict would change if the condition vanished: an exit run entered from a second site, a restored mask that was never saved, an
s_andn2_b32whose destination is not its source.The fixture is already enforced on pull requests:
python-linux(.github/workflows/windows.yml:181, list entry at:340) andpixel-binary(:18,:143) carry noif:guard. So the six deletions that turn it red are caught by CI and the eight above are outside what CI can see.The scope boundary is the one with a measured consequence
Your body scopes the change to "compute groups of up to 32 threads". Same words, group size varied through the fixture's own
translate('O', code=EXIT_RUN_WORDS, group=...):Every head refusal is the same
branch out of the block, and the whole fixture stays green on M1. The text accepted for(64,1,1)declares[numthreads(64, 1, 1)]and is otherwise the same translation as(32,1,1): oneuint execword for a group of two waves. With the line neutralised the same words translate at every size above, so this condition is the only refusal standing between the shape and a group bigger than one wave — and no test in the suite distinguishes the two sides of it. One control that translatesEXIT_RUN_WORDSatgroup=(64,1,1)and asserts the refusal would pin the boundary your body already claims.Limits
(33,1,1)and(64,1,1), it is simply never given such a group by the suite.088d0d11.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-26T20:24:42Z.
Review: COMMENTED
fix(shader): prove scalar runs before compute EXEC restores
Interesting shader correctness fix. Testing scalar register liveness across compute EXEC restores is important for correctness — scalar pipelines have different scheduling characteristics than vector units.
Observations
Questions
Verdict: Needs domain-expert review of the scalar register tracking logic and any potential regression impact on other shader types.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T05:48:51Z.
Review: COMMENTED
What works
EXIT_RUN_SOURCEfixture is well-structured:s_and_saveexec_b32/s_cbranch_execz/s_andn2_b32/s_cbranch_scc0chain followed by a shared scalar run ending ins_mov_b32 exec_lo, s21. Tight and reproducible.trace()/singletons()) is excellent — shows wave vs. singleton parity, including near-miss edge cases (remask from s21, scalar_on_stay=True).MESH_WAVE_BLOCK_LOADStoSCALAR_LOADSis a clean unification that reduces duplication across mesh and executor paths.EXECZ_EXIT_WAITS(s_nop, s_waitcnt, s_waitcnt_depctr) correctly limit what can appear in the shared scalar run.Issues
Group size bound: The proof restricts to
x*y*z <= 32. While this is correctly noted, many compute shaders use 256-thread groups. The comment indocs/experiments.mdshould explicitly state this is a "up to 32 threads" proof, not a general solution. Consider adding a follow-up item for larger groups in the experiment doc.saved_exec()backward scan: The function scans fromguard-1down to 0 looking for the EXEC save. This O(n) backward scan is fine for small blocks but could miss cases where a scalar effect between the save and guard interferes. Thewords & effects[k][2]check catches writes to the scalar register, but doesn't verify the save path is unbroken by otherexeczentry points. This is likely fine in practice.SCC after the scalar run: The test at the end (
check_execz_exit_run) verifies that SCC after the run still distinguishes wave vs. singleton, which triggers refusal. However, the mainexecz_scalar_exit()method checkslive_in[target] & {mask, "scc"}— if SCC is live at the target, it rejects. This is correct but the comment in the function docstring should explicitly mention SCC liveness as a rejection criterion.EXECZ_EXIT_WAITSscope: The tuple includess_nop, which means a run consisting entirely of nops and waitcnts is accepted. This is safe but the boundary — whens_cbranch_scc0is removed and replaced bys_cbranch_execzinside a skipped block — could merge the two test cases (LOOP_BREAK and EXIT_RUN) differently. The current separation intocheck_execz_loop_break()andcheck_execz_exit_run()with adjusted assertions in between is correct.quiet(j)change: The logic shift fromreason = 'branch out of the block'followed by conditional override to anelifwithexecz_scalar_exit()is cleaner but could be confusing during maintenance. The new structure means the original reason string is never assigned when the exit path is valid — consider adding a comment at the top of the block explaining the new control flow.Recommendations
# TODO:orRefs #XXXX:in the code pointing to the next phase (handling groups > 32 or the two-mask counted loop from #2645 T2). This helps future contributors know what's explicitly out of scope vs. deferred bugs.swap()function is a clever near-miss generator. Consider making it a standalone helper at module level since it's used across multiple test functions.Overall
This is a solid, well-tested change. The trace-level verification model (wave vs. singletons with KEY^lane) is a strong foundation for proving the scalar exit pattern. The
execz_scalar_exit()method adds clear, structured proof conditions. The refactoring toSCALAR_LOADSis a nice cleanup. The group-size limitation to 32 threads is correctly bounded and clearly documented.Recommendation: APPROVE (with the documentation note in #1 above addressed as a minor comment).
Imported from R0Y00/Xbox2Windows. Originally posted by brainbudt on 2026-11-27T09:36:46Z.
Thanks @thepatrickworld and @KelboLive! Updated in
022212a:check_execz_exit_runfor workgroups > 32 threads (group=(33,1,1)and(64,1,1)), an unsaved restore mask (s_mov_b32 s21, 0), ands_andn2_b32withdest != src.x * y * z <= 32) scope bound (with larger workgroups noted as follow-up work) and the SCC-liveness rejection criterion indocs/experiments.mdandStage.execz_scalar_exit.python3 -B tests/startup_gfx2hlsl_compute_check.pypasses cleanly.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-27T10:10:43Z.
Independent Linux host-only result on
022212aa: what the three refusal controls added in the second commit pinEnvironment and scope
Linux host, no GPU: no D3D12 dispatch and no
_hardwareentry ran. Everything below is Python-only translator measurement oftests/startup_gfx2hlsl_compute_check.pyat022212aa(clean worktree).python3 -B tests/startup_gfx2hlsl_compute_check.pypasses (… execz and sample refusals pass).022212aachanges no behaviour:tools/startup/gfx2hlsl.py+3/−2 (docstring only), fixture +6/−1. The accepted program and the proof come from088d0d11, where I reported the base/head delta (6ee878d8refuses it,088d0d11accepts).Method
32 hand-written single edits of
Stage.execz_scalar_exit; 25 applied through the harness (mutatedgfx2hlsl.pyloaded oversys.modules['gfx2hlsl'], thencheck_execz_exit_run()andcheck_controls()re-run; baseline green before and after, and a sanity edit ofs_andn2_b32tos_andn2_b64is killed). Four scope edits needed a qualified anchor and re-ran outside the harness; three (operand count, pair-aligned mask, run-operand shape) were not measured. Result: 12 killed, 13 survive. Line numbers are the head's, read from asys.settracepass over the module.What the three added controls pin
(33,1,1)/(64,1,1):> 33,> 64and a deleted bound all turn the check red, so the refusal edge is pinned at 33. The accepted edge is not: the head acceptsgroup=(32,1,1)(9989 chars of HLSL), the fixture never passes a 32-thread group, andx*y*z >= 32keeps the whole suite green. Onetranslate(..., group=(32,1,1))line pins it.s_mov_b32 s21, 0(byte 28): removing the pre-guard save proof for the ANDN2 source alone stays green; removing the restore re-proof (3053-3054) alone is caught. The control pins the restore side, not the pre-guard site.s_andn2_b32 s22, s0, exec_lo(byte 52) is refused at head by the shape test (3006-3008), by the save proof (3025-3026) once the equality term is removed, and by the remask install (3033) once both are removed (measured: refused, refused, accepted). The entry crosses three catchers and pins none of them on its own.Survivors
s_mov_b32 exec_hi, s21dies at the destination test 3048 and never reaches the width test 3050).ops[2] != 'exec_lo'. My own entry for the last one,s_andn2_b32 s0, s0, vcc_lo, is refused by the join-liveness rule instead, so it separates nothing._dppandv_permlane/v_movrelin the exit run.Stage.vector_only_instructionacceptsv_mov_b32_dppandv_permlane16_b32, so those terms are the rejection and not that helper; a compute DPP op is refused earlier anyway (4513-4516).branch <= guard + 1can only bebranch == guard + 1, andins[branch - 1]is then thes_cbranch_execzitself, which the shape test rejects at 3006.Limits
No HLSL was compiled or executed: these are refusal-gate measurements only. The oracle is the fixture of the same commit, so a killed edit shows the fixture sees a change, not that its expectation is right, and every internal refusal shares one message, so a refusal can pass for the wrong reason (the
s22entry is the demonstration). The edit set is mine.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by brainbudt on 2026-11-27T11:14:32Z.
Updated in
491d0fdto address @thepatrickworld's mutation findings:translate('O', code=EXIT_RUN_WORDS, group=(32, 1, 1)).hlsl_cs()incheck_execz_exit_runsox * y * z <= 32is pinned on both sides (32 accepted, 33/64 refused).s_and_saveexec_b32 s0, vcc_loat byte 36 withs_mov_b32 s0, 0(800380be), pinningsaved_exec(mask, 's_mov_b32', 'exec_lo')independently of the restore-sides21check.branch <= guard + 1check inStage.execz_scalar_exit(whenbranch == guard + 1,ins[branch - 1]iss_cbranch_execzand already rejected by thes_andn2_b32check).Verified locally:
python3 -B tests/startup_gfx2hlsl_compute_check.pypasses, and single-edit mutation checks confirm bothx * y * z >= 32and removing the pre-guardsaved_execcheck are now caught.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T11:48:08Z.
Review: APPROVED
Reviewed
491d0fd0in the plannedmainintegration after #3041, #3043 and #3044 (tree1fd75c1b). The translator, modified-descriptor, cselect-descnum, readfirstlane-uniform, join-symbols, same-register saveexec, mesh dynamic and mesh clip/cull Python checks passed. The original emitted shader compiled with SDK DXC (-Ges -WX -T cs_6_0 -E main) at 3, 8 and 32 threads. For GPU readback I substituted the two fixed entry constants for the cbuffer so the existingoffscreen_check --raw-uav-dumpcould bind only the UAV. With both Debug and Release /O2 renderers, WARP and RTX matched 9 in lanes 0–2 and0x13579bdf ^ lanein later lanes, at all three workgroup sizes. Mutating the final EXEC restore to zero broke all four adapter/configuration combinations for every size. The integration tree emits identical HLSL for the three sources I used. Windows 11 26200.9974, SDK DXC 10.0.26100, WARP 10.0.26100.9818, RTX 4060 Laptop driver 32.0.16.1656, debug layer enabled with no errors or warnings. Hosted Windows, Linux Python and gfx1013 checks passed.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-27T12:10:23Z.
Independent Linux host-only result on the merged tree
298a2034: the three review points are pinned, not only appliedEnvironment and scope
#2900was squashed ontomainas298a2034(11:49Z) while this measurement was running, so this is a post-merge receipt: everything below was re-run on that merged tree, in a clean worktree (git status --porcelain --untracked-files=noempty). Line numbers are the merged tree's.Stage.execz_scalar_exitis byte-identical between the last PR head491d0fd0and298a2034(71 lines, sha256c6419b4a2ac392e4118af1b87ab005ce9766ae7bee89dbe583a81f0d4e8874ba, lines 2992-3062 and 3184-3254, LF-normalised), and so ischeck_execz_exit_run(84 lines, sha25604f1597fa53cc4168c8ca3aa454cb09b0e30fb00e283363783abebbac67cbe56, lines 1168-1251 in both), so the numbers are the merged code's own.Linux host, no GPU: no D3D12 dispatch and no
_hardwareentry ran; this is Python-only, translator and fixture.python3 -B tests/startup_gfx2hlsl_compute_check.pypasses on the merged tree. The 210-scriptpython-linuxstep of.github/workflows/windows.ymlgives at491d0fd0196 ok, 13 failing and 1 skipped, and the same 13 fail identically on this PR's base6ee878d8, all of them on a missing module in this host's interpreter (11pefile, 2iced_x86); none of the 13 mentionsgfx2hlsl.Method
One fixture (
check_execz_exit_run), one edit ofStage.execz_scalar_exitat a time. For each edit,chk.refusedis replaced by a recorder that runs everybuild()and classifies it instead of stopping at the first failure, which yields a verdict for each of the 20 refusal entries (2 group bounds, 16 byte edits, 2 closures over an outer program); the accepted calls report the fixture line where they die. The two edits this follow-up turns on also run against the pre-fix pair (022212aatranslator and fixture), so "green before" is about the state a reader would check out and not about a hybrid tree; the others run against the merged pair and against that pair with only the fixture swapped for022212aa's.Results
x * y * z > 32→>= 32) is green on the pre-fix pair and red at fixture line 1202 on the merged tree. With line 1202 removed at491d0fd0, the same edit leaves the whole 210-scriptpython-linuxlist at its result (196 ok, the same 13 environment failures), so that line is the only catcher in it. On the merged tree, 32 is accepted (11 331 characters of HLSL emitted), while 33, 64 and (32, 2, 1) are refused.check_execz_exit_run, and on the merged tree turns exactly one of the 20 entries from refused to accepted — the new byte-36s_mov_b32 s0, 0. The byte-28 entry stays refused under that edit, and deleting the restore re-proof (3245) instead flips only byte 28 and is red on both fixtures: the two sites are pinned separately. Asys.settracepass shows the byte-36 entry reaching the pre-guard call at 3217, the last frames ofsaved_execat 3212-3214, thenreturn Falseat 3218, while the unmutated program continues past 3217 into 3219-3251 and the restore proof at 3245-3246, so that entry is refused by the pre-guard proof and not by another catcher that shares the message.branch <= guard + 1at 3194 changes nothing: all 20 entries keep their verdict and every accepted call still translates, on both fixtures. It can only bebranch == guard + 1, and thenins[branch - 1]is thes_cbranch_execzthat the caller's loop (3117) selected asguard, whose shape test (3198) returns the sameFalse; the removal cannot change a refusal.Limits
Host translation only: nothing compiled or executed. The oracle is the fixture of the same commit, so a killed edit shows the fixture sees the change, not that its expectation is right. Every internal refusal shares one message, so a refused entry can pass for a reason other than the one its comment names; the per-entry table is what separates them here. Under the accepted-edge edit the run aborts at line 1202, so the 20 refusal entries are not measured under that edit. The program's pre-guard save is the
s_and_saveexec_b32form; a pre-guard save written ass_mov_b32 sX, exec_lois accepted by the same proof and no fixture program uses it (that branch ofsaved_execis pinned at the restore site, by the byte-28 entry). The edits are mine.AI-assisted.