startup: read S0 before writing D in gfx2hlsl s_*_saveexec #2300
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2308"
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 denn0x on 2026-11-25T11:37:37Z.
What
RDNA 2 ISA, SOP1
S_AND_SAVEEXEC_B64:D = EXEC; EXEC = S0 & EXEC; SCC = EXEC != 0, where S0 is the value read at issue.S_OR_SAVEEXECandS_ANDN2_SAVEEXECwork the same way, with|andS0 & ~EXEC.Compiled code uses the form where the destination is the source, for example
s_and_saveexec_b64 s[6:7], s[6:7]after a compare intos[6:7].tools/startup/gfx2hlsl.pyemitted:So the new exec was
exec & exec, and every lane entered the branch whatever the compare gave.With D == S0, S0 is now copied to the scratch word
wbefore D is written.wis already declared in every stage. All other forms emit the same lines as before.Test
tests/startup_gfx2hlsl_saveexec_same_reg_check.py(new). It is registered in CMake asstartup_gfx2hlsl_saveexec_same_reg_controls, in the Python CI job and in AGENTS.md.s_and/or/andn2_saveexec_b64ands_and_saveexec_b32with D == S0.startup_gfx2hlsl_bit_alu_check.s[20:21]/s20), no scratch copy is made and the result is the same. The old line order is evaluated too and must admit the lane for S0 = 0.The same check on
mainwithout the change fails 6 checks. Two are the exec result:s_and_saveexec_b64and_b32admit the lane for S0 = 0. The other four are the missing scratch copy in each D == S0 form. Or and andn2 give the same exec either way, becauseexec | execandexec & ~execdo not depend on S0 with exec = 1.tests/startup_gfx2hlsl_*_check.py,tests/startup_image_*_check.py,startup_translator_check.pyandstartup_flat_param_check.pypasses on this branch.allbuilds (Ninja Release, MSVC Build Tools 18, Windows 11). Device-free, so there were no GPU runs and no capability skips.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:41:02Z.
Review: COMMENTED
Review of head
60f8276a97(Linux only, no Windows run needed: the change is a text-emission order fix covered by the restricted evaluator).Verdict: logic is correct. One blocker: the PR is CONFLICTING and needs a rebase.
P1 (rebase)
tools/startup/gfx2hlsl.py,op_s_and_saveexec_b64conflicts with main (#2305 and earlier refactors). Main now ends the op withself.set_exec_scc(text.format(self.u(src)))(main line ~1794) instead of the inlineexec = (...) & 1; scc = exec != 0;plusscc_uniformreset that this PR edits. After the rebase, keep the neww = S0;copy and passvaluetoset_exec_scc. Main still has the original bug, so the fix is still needed.set_exec_sccoutput.What I checked
S_AND_SAVEEXEC_B64). Copying S0 towwhen D == S0 is right.wis declared in every stage prologue (uint ... w = 0), so no new declaration is needed. Other forms emit unchanged lines.Nits (P2)
Commands run locally
git diff --stat origin/main...HEAD: 5 files, +116 -2git merge-tree --write-tree origin/main HEAD: CONFLICT in tools/startup/gfx2hlsl.pypython3 -B tests/startup_gfx2hlsl_saveexec_same_reg_check.py:saveexec same-register checks: 0 failedpython3 -B tests/startup_gfx2hlsl_bit_alu_check.py: passpython3 tests/docs_links_check.py: 18 files, 446 links okpython3 tests/bidi_controls_check.py: no bidirectional controlsgit diff --check origin/main...HEAD: cleansrc_reg[1] == dtod + 99) so the copy is skipped; the new check reported6 failed. Reverted withgit checkout -- ..AI-assisted; commands listed were executed locally.
upstream-sync referenced this pull request2026-11-25 12:01:50 +00:00
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T11:40:34Z.
I'll take an independent compute readback for the overlapping SAVEEXEC forms. With one active hardware lane per source-built workgroup, four groups can cover both input EXEC bits and both source bits. In particular, an incoming EXEC of zero and S0 of one can distinguish OR and ANDN2 from reading D after it was overwritten. I'll run the same cases and the previous instruction order on WARP and RTX 4060, and share the evidence here. The source fix remains in this PR.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T11:46:31Z.
I ran the LLVM 15.0.7 source-built SAVEEXEC cases on WARP and a desktop RTX 4060 (32.0.15.9579, Windows 26100.9711; local debug layer unavailable). Each of four single-thread groups covers one (old EXEC, S0) pair: (0,0), (0,1), (1,0), (1,1). The stored word contains saved EXEC, SCC and new EXEC in bits 2, 1 and 0. This makes an inactive initial lane observable after re-enabling it for the output store.
At
60f8276a, all five forms matched on both adapters with both overlapping and distinct operands. I also combined them in a test-only commit for the existing compute CTest. With your translator, both devices matched all 320 words of this 648-byte fixture. On main209938b0, each device returned exactly five mismatches, one per alias case. The distinct-register cases and all 280 guard words stayed correct.The test-only branch is ready for a follow-up once the lowering lands. The reference for the flag and source order is AMD RDNA 2 ISA, section 12.3.
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T11:51:22Z.
Rebased onto
5074371f.op_s_and_saveexec_b64now keeps thew = S0;copy and passesvaluetoset_exec_scc. Every other line is unchanged.After the rebase:
python -B tests/startup_gfx2hlsl_saveexec_same_reg_check.pygivessaveexec same-register checks: 0 failed. It still evaluates the linesset_exec_sccemits.tests/startup_gfx2hlsl_*_check.py,tests/startup_image_*_check.py,startup_translator_check.pyandstartup_flat_param_check.pypasses.allbuilds (Ninja Release, MSVC Build Tools 18).Thanks for the WARP and hardware readback. It matches the cases the check covers, and the test-only compute fixture makes sense as a follow-up once this lands.
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T11:58:41Z.
Rebased again onto current main after #2310 merged. The only conflict was the adjacent test registration lines in CMake, CI and AGENTS.md, and both entries are kept. The saveexec and compare-destination checks both report 0 failed, and
allbuilds.Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T11:59:38Z.
Correction to my last comment: my push was refused because you had already updated the branch (
36019ef9). I have reset to your head and not pushed anything over it. Your version is what I would have pushed, with the same conflict resolution, plus the cache revision bump to x2w-startup-shader-12, which I had missed. Thanks.