shader: keep an accumulated lane mask live at a compute execz exit #3109
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#3109
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@SimSalabimse on GitHub · 2026-11-27 15:44 UTC · original
Change
A straight compute lane-exhaustion exit can keep one accumulated lane mask live in the staying span. The pair is
s_and_b32 sA, sA, exec_lothens_or_b32 sB, sB, sA. The exit branch jumps over it, so a lane that leaves keeps its own bit ofsB.sAmust be dead at the exit, and every later read ofsBmust be per lane. Refs #2645 (T4). This builds on #2900: the scalar run before the EXEC restore, the single-wave32 bound (x * y * z <= 32), the 32-thread edge, and the pre-guard ANDN2 save proof stay as merged.The counted loop with a backward latch and a second saved mask stays refused.
An AND that rewrites an already tracked carried mask ends that word's old definition and starts a new tracked definition at the same destination. A repeated carry (
ACCUM_REPEAT_*) and a longer chain that rewrites the tracked word (ACCUM_REWRITE_*) stay refused.Verification
All results below are for commit
ede53dce485b1028f78287026eb8a89a258bdd5a, rebased onto main77d1ba4d63ba31abaf4ca3635d4159189a423201.Windows test PC (MSVC,
--preset dev,-j 1). The command was:It passed 71 of 71 with ctest exit 0.
Linux, agent-reported at this head:
python3 -B tests/startup_gfx2hlsl_compute_check.py: exit 0.ACCUM_REPEAT_*andACCUM_REWRITE_*staybranch out of the block. Restoring the old carry rule accepts both and makes the check fail.python3 -B tests/startup_tools_lint_check.py tools/startup: exit 0.CI on this commit succeeded for
Build and test on Windows,Assemble and translate gfx1013 fixtures, andRun platform-independent Python checks on Linux.Evidence and follow-up
ACCUM_SOURCEintests/startup_gfx2hlsl_compute_check.pyis a hand-written gfx1013 program.ACCUM_WORDSis the recorded encoding;binary llvm-mc-15reassembles it. The host check compares a wave trace with one-lane traces.ACCUM_REPEAT_*andACCUM_REWRITE_*are recorded the same way. The fixture does not cover the #2645 counted loop.docs/experiments.mdhas the T4 section after the #2900 T3 section.Checklist
AI-assisted (Cursor)
Pull request details or commits were not available from GitHub; kept as an issue.
github-bot referenced this issue2026-11-27 21:30:21 +00:00
@SimSalabimse on GitHub · 2026-11-27 22:49 UTC · original
The AND of the accumulated mask with exec is a per-lane read only when nothing reads the SCC it sets. That SCC is the whole word, so a later s_cselect of it stays refused. Added a source program that kills the SCC with a compare and then uses the AND result in v_cndmask, plus the s_cselect program as a negative control. Dropping the dead-SCC check makes that refusal fail.
Linux: the python-linux list exited 0 (245 checks), startup tools lint exited 0, and the compute gfx2hlsl check exited 0. Windows test PC: startup_gfx2hlsl_compute_controls passed twice, startup_gfx2hlsl_compute_ 69/69 passed, exit 0.
AI-Assisted
@JohnConnorNPC on GitHub · 2026-11-28 07:34 UTC · original
Thanks for the update on
4f53dc60. R0Y00's SCC request is met:ACCUM_SCC_WORDScarries their exact replacement (1a7e1b8781801c851c020a7e) and the test asserts it is refused. Their review is still CHANGES_REQUESTED on85e96f29, so it needs a re-review from R0Y00. Before that, could you add a control for each of the two new refusals that has none? Mutant runs were on copies oftools/startup/gfx2hlsl.py, restored by hash.if kept in live_in[target] or accum not in live_in[target]:withif accum not in live_in[target]:leavespython3 -B tests/startup_gfx2hlsl_compute_check.pygreen (rc=0). Under that mutant, words050001d5050d6a00+80039abe+050001d5050d6600(v_cndmask … s26; s_mov_b32 s26, 0; v_cndmask_b32 v5, v5, v6, s25) in the ACCUM fixture are accepted asaccum=[('s25', 's26')]; unmutated they are refused (accum=[False]). That would make a good ACCUM refusal control.accum_scc_deadtos_and_b32only also leaves the suite green, and the tests never use the direct form (git show 4f53dc60:tests/startup_gfx2hlsl_compute_check.py | grep -c 1a3c9cbe→ 0).1a3c9cbe1c03febe81801d851d020a7e(s_and_saveexec_b32 s28, s26; s_mov_b32 exec_lo, s28; s_cselect_b32 s29, 1, 0; v_mov_b32 v5, s29) is refused on the head today, so it can go in as a second ACCUM_SCC control.Smaller points:
mainc3204a9cin one file (git merge-tree --write-tree --name-only c3204a9c 4f53dc60→tests/startup_gfx2hlsl_compute_check.py). Main'scheck_execz_mask_subsetand yourcheck_execz_accumulated_maskwere added at the same spot. Keeping both resolves it, and the compute check passes on that merge.85e96f29, not4f53dc60.ctest -R '^startup_gfx2hlsl_compute_', but no dispatch case uses ACCUM (grep -cE "CASES\[[^]]*\] *=.*(ACCUM|EXIT_RUN)"→ 0). That run doesn't exercise this fixture, so please say so in the docs or add ACCUM as a case.This comment was AI-assisted.
@SimSalabimse on GitHub · 2026-11-28 10:52 UTC · original
Retested fc2341e2af022efb926e59239109cdd9c7457a8f on the Windows test PC (NVIDIA, 32-lane waves).
ctest --preset dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_compute_controls$' -E "startup_audio_output|startup_audio_pacing|startup_audio_provider"
That passed twice, 1/1 each time, exit 0.
ctest --preset dev --no-tests=error -j 1 -R startup_gfx2hlsl_ -E "startup_audio_output|startup_audio_pacing|startup_audio_provider"
387/387 passed, exit 0.
Both of JohnConnorNPC's described mutants fail the new ACCUM_KEPT_* and ACCUM_SAVEEXEC_* controls on the Linux run.
AI-Assisted
@SimSalabimse on GitHub · 2026-11-28 20:34 UTC · original
@R0Y00 Both of your requests are in, and the branch is rebased onto current main (head
2c6dd7a1).accum_scc_deadin3d205071only treatss_and_b32 sX, sB, exec_loas a per-lane read when no later instruction still has SCC live. Yours_cselectreplacement stays refused.ACCUM_SCC_WORDSis your replacement (1a7e1b8781801c851c020a7e), and the compute check asserts that it is refused. Forcing the dead-SCC check to pass makes that assertion fail.Linux: tools lint exited 0, and python-linux passed 258/258.
Windows test PC:
startup_gfx2hlsl_compute_71/71 passed at2c6dd7a1, ctest exit 0.AI-Assisted
@Leyukaka on GitHub · 2026-11-29 00:16 UTC · original
Review of
2c6dd7a1, diff only, againstmain51472392. The three touched files are unchanged onmainsince0614f68c(git diff --stat 0614f68c 51472392on them is empty), andgit merge-tree --write-treemerges cleanly.The sA/sB proof holds for one pair: a leaving lane skips the pair, so its bit of sB matches, and its bit of sA differs, which
kept in live_in[target]refuses. SCC of the pair is dead at the exit because main already requires that.A second pair is not caught by any test.
tools/startup/gfx2hlsl.py:3446: changingif (pair is None and base == 's_and_b32'toif (base == 's_and_b32'leaves the suite green, because no fixture has two pairs. Under that change the second pair overwritespair, and the first pair's sA liveness and sB reads are never checked. A control: start s27 as an entry EXEC copy and s28 as 0, adds_and_b32 s27, s27, exec_lo; s_or_b32 s28, s28, s27after the first pair, and after the restore read s28 withv_cndmask_b32 v5, v5, v6, s28, thenv_cndmask_b32 v5, v5, v6, s25. Under the change the s25 read is not checked and the words are accepted; lane 0 stores 9 in the wave and 1 in the model. It must staybranch out of the block.The walk does not follow the AND's destination. At
:3471-3476only reads of sA and sB are checked. A copy of sB throughs_and_b32 sX, sB, exec_locan carry the whole word to an SCC thataccum_scc_deadnever sees. Please add this control: inACCUM_WORDSreplace050001d5050d6a00withs_and_b32 s27, s26, exec_lo; s_and_b32 s28, s27, exec_lo; s_cselect_b32 s29, 1, 0; v_mov_b32 v5, s29(1a7e1b87 1b7e1c87 81801d85 1d020a7e, written from the fixture's encodings, not assembled). The first AND's SCC is dead, since the second AND overwrites it. The second AND reads s27, not s26, so its SCC is not checked. The wave's SCC is true, so all 8 lanes store 1, while the singletons give[0, 0, 0, 1, 1, 1, 1, 1]. The PR's own test showsACCUM_SCC_WORDStranslates onceaccum_scc_deadis forced toTrue, so nothing after the walk is shown to refuse the s_cselect path. If it translates, follow sX in the walk as sB is followed.Verdict on
2c6dd7a1: comment. Items 1 and 2 need a control each, and item 2 may need a code change.@SimSalabimse on GitHub · 2026-11-29 00:37 UTC · original
@Leyukaka Both controls are in (head
6e0bdf25, rebased onto main51472392).branch out of the block. The new program (ACCUM_SECOND_*) starts s27 as an entry EXEC copy and s28 as 0, putss_and_b32 s27, s27, exec_lo; s_or_b32 s28, s28, s27after the first pair, then selects with s28 and s25. Lane 0 is 9 in the wave and 1 in the model. Droppingpair is Noneaccepts those words, and the compute check exits 1 there.accum_carried). Your words decode ass_and_b32 s27, s26, exec_lo; s_and_b32 s28, s27, exec_lo; s_cselect_b32 s29, 1, 0; v_mov_b32 v5, s29(ACCUM_CARRY_*), and that program stays refused. Turning the follow off accepts it, and the check fails on that assertion.Linux: tools lint exited 0, and python-linux passed 259/259.
Windows test PC:
startup_gfx2hlsl_compute_71/71 passed at6e0bdf25, ctest exit 0.AI-Assisted
@SimSalabimse on GitHub · 2026-11-29 12:54 UTC · original
Fixed at
ede53dce485b1028f78287026eb8a89a258bdd5a. An AND that rewrites an already tracked lane mask now ends the old definition and starts a new tracked definition at that destination, so a later AND's SCC stays inside the refusal. That covers the repeated carry into s27 (ACCUM_REPEAT_*, the first dword ofACCUM_CARRY_WORDSrepeated) and the longer chain that rewrites s27 from s28 then carries it into s29 (ACCUM_REWRITE_*). Restoring the old rule that returnsNonewhen the destination is already tracked accepts both, and the check then fails. The earlier accumulated-mask controls are unchanged. The branch is rebased onto main77d1ba4d.Windows test PC (MSVC,
--preset dev,-j 1), at that head:ctest --preset dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_compute_' -E 'startup_audio_(output|pacing|provider)': 71/71 passed, exit 0.startup_gfx2hlsl_compute_controlsran the execz refusals, including the two new programs. The other 70 are the warp, hardware, spill and mask-spill cases, including the expected-fail controls.Not done in this head: the trace asserts for the new controls still repeat the earlier model calls. The in-place
s_and_b32 sX, sX, exec_loprograms from the review are not added as named controls.AI-Assisted
@JohnConnorNPC on GitHub · 2026-11-29 12:55 UTC · original
Review of
ede53dce(merge-base = main77d1ba4d). Verdict: no MUST from me. Merging is blocked only by the recorded change requests: pigalot and Leyukaka on6e0bdf25, and R0Y00 on85e96f29. Each needs its author's re-review.pigalot's blocking finding (a repeated AND drops a carried mask) is fixed the way pigalot suggested.
accum_carriedno longer returnsNonefor an already tracked destination, and the walk buildsnxt = set(tracked) - writesbefore adding the carry. What I ran, Linux, Python 3.13:python -B tests/startup_gfx2hlsl_compute_check.py→ exit 0.tools/startup/gfx2hlsl.pyfromede53dce~1→ exit 1 atAssertionError: accepted, expected a refusal naming 's_cbranch_scc0 inside a block s_cbranch_execz skips per lane: branch out of the block'. So the newACCUM_REPEAT/ACCUM_REWRITEcontrols pin the fix, and the in-testno_recarrystub covers the same ground.050001d5050d6a00inACCUM_WORDSwith each of these, and all are refused with that reason:s_mov_b32 s27, s26, thens_and_b32 s28, s27, exec_lo; s_cselect_b32 s29, 1, 0; v_mov_b32 v5, s29;s_and_b32 s27, s27, exec_loof a carried word, thens_cselect;assemble(llvm_mc, ACCUM_REPEAT_SOURCE) == ACCUM_REPEAT_WORDS, and the same forREWRITE), and CI's fixture job passes on this head.The change is gfx2hlsl-only. With
X2W_NATIVE_SHADERS_ONLY=1(the launcher default since #3451), its compute manifests aren't loaded, so it affects-Translateruns only.AI-assisted.