startup: lower v_swap_b32 in gfx2hlsl #1988
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1995"
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 JB2WIN on 2026-11-24T22:50:56Z.
Refs #1723
Change
tools/startup/gfx2hlsl.pynow lowersv_swap_b32. It is one of the refusals in the #1723 census (2 pairs).op_v_swap_b32emits{ uint t = vA; vA = vB; vB = t; }, so both sources are read before either one is written. Whenexecis unknown, the swap is guarded withif (exec & 1), as the neighbouring lane ops are.used_vis updated. A uniform flag moves with its value and is dropped whenexecis unknown.V_SWAP_B32among the instructions that cannot use DPP or SDWA. The edge cases follow thepixel_aotlowering from #771.v_swap_b32 v1, v2as02 cb 02 7e, the self-swapv3, v3andv255, v0for gfx1013. It rejects_e64,_dpp,_sdwa,clamp, negation, SGPR and constant sources, and pairs.omod,op_seland the VOP3A form, which the decoder already marks unsupported.Test
New device-free check
tests/startup_gfx2hlsl_swap_check.py, registered asstartup_gfx2hlsl_swapand listed in the pure-Python job andAGENTS.md. A short note is added todocs/experiments.md.v255, v0. The emitted text is evaluated and compared with a reference list swap.Unsupportedcases.main'sgfx2hlsl.pyit fails withUnsupported: v_swap_b32.Results:
e63721f9, alltests/startup_gfx2hlsl_*_check.py,tests/startup_translator_check.pyandtests/docs_links_check.pypass.verify.pyon the base1d825c18:form_coverage,rdna2_tools,pso_readiness,docs_linksand the LLVM 15 binary round trip passed;startup_view_heap_hardware(shortcut logged -1 times, expected 1). It fails the same way onmainat1d825c18without this change and passed at387bdaf5, on an RTX 3080 (32.0.16.2124, Windows 11 build 26200). I'm narrowing it down separately.The check evaluates the emitted HLSL in Python. It does not compile it or draw with it.
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T22:53:13Z.
Ran it and broke the swap four ways — all caught
Windows 11 build 26300.9974, device-free:
op_v_swap_b32{ vA = vB; vB = vA; }(write before read, no temporary){ vA = vB; })if (exec & 1)guard dropped whenexecis unknownexecThe first two are the same mistakes the fixture already names as its own controls, which is a good sign: your controls and my mutations agree on what
can go wrong, and both fail the suite. The fourth is the subtler one — a swap under an unknown mask no longer proves either register uniform, and
dropping that makes a later
v_readfirstlane_b32accept a source it should not.On the uniformity rule
uniform = (dst in self.uniform_v and self.exec_known, src in self.uniform_v and self.exec_known)— theexec_knownterm is what keeps the propertyhonest when the mask is unknown, and it is the line a copy of this handler into another lane op would most likely lose. Worth a comment of its own if
the pattern spreads.
What the guard costs
if (exec & 1)around the whole body is the same shape as the neighbouring lane ops, so a reader recognises it; the alternative (guarding each write)would be wrong, because a half-swap is worse than none. That reasoning is not in the code comment — it says "guarded with
if (exec & 1), as theneighbouring lane ops are" — and a one-clause addition would stop someone "optimising" it into two guarded writes later.
Scope
v_swap_b32only;v_swaprel_b32and the DPP/SDWA spellings stay refused per the comment. The fixture's 7 cases and the two controls above cover theaccepted and refused forms; no draw was run, which matches the description.
Verdict
Reviewed. Four independent breakages, four failures, and the uniformity rule travels with the values as intended.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:07:40Z.
Your commit
f018831bis already the code inmain; this PR page still shows openChecked while reviewing a duplicate:
tools/startup/gfx2hlsl.pyonmaintoday contains your handler verbatim, including theuniformity-preserving line and the
if (exec & 1)guard:and
tests/startup_gfx2hlsl_swap_check.pyis onmainand green (exit 0). So either this was merged through another PR that carried thesame commit, or it was pushed directly — worth knowing only because #2012 is a duplicate of it and I have pointed that out there.
Nothing needed from you if the content is in; just flagging so the open state does not look like unlanded work.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:10:02Z.
Correction: my previous comment was wrong — your commit is not already in
mainI wrote that
f018831bis the code inmainand that your PR page merely still showed open. That was wrong. Verified against the commit object,not a working tree:
origin/mainat66423e45has 75op_*methods onStage, none of themop_v_swap_b32, andtests/startup_gfx2hlsl_swap_check.pyis not inthe tree. So this PR is genuine unlanded work, and I am sorry for suggesting otherwise.
What I did wrong: I had a branch checked out earlier in the session to run a test, and my later greps read that working tree instead of
origin/main. The line numbers I quoted were real, in that branch; the claim I built on them was not.For what it is worth, the substance of my review of your handler stands: four mutations (temp removed, one destination,
execguard dropped,uniform flag kept under an unknown
exec) all fail your fixture, and the uniformity rule travelling with the value is the precise behaviour.Notes
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:14:11Z.
Merge matrix for the 16 open PRs that touch
tools/startup/gfx2hlsl.pyI computed each PR's changed line ranges against its own merge base (not against
main, which makes stale branches look like they delete otherpeople's work), then looked for pairs whose ranges overlap.
Only 2 of 120 pairs overlap:
op_s_bfm_b64FETCH_FORMATS(10-10-10-2 UNORM vs 16-16 SNORM)But line overlap is only half the story
I merged the overlapping pairs, and then a pair that does not overlap:
#2012and#1995add the same method at lines 1272 and 1304 — far apart, so nothing overlaps, yet they are the same feature. In one merge ordergit silently keeps a single definition (one author's behaviour is lost with no marker); in the other it keeps both. Neither outcome is a rebase of
the other, and the reviewer would have to notice by reading the file.
So: line-overlap predicts textual conflicts, not duplicate additions. For a file where 16 people are each adding one handler, the dangerous
case is the one this matrix does not flag, and the two duplicate pairs above (#1995/#2012 on
v_swap_b32, #2003/#2007 ons_bfm_b64) areexactly that.
What I would do with this
the same way, so both are safe choices).
#2006/#2005, whichever goes second needs a one-line rebase of two adjacent dict entries — trivial, but it will be a conflict ratherthan a merge.
The script is 40 lines (merge-base,
git diff -U0, range intersection) if you want it as a CI job — but a cheaper version is just "search theopen PR titles for the mnemonic", which would have caught both duplicates before either branch existed.
Notes
main7f149ac9.