startup: lower wave32 reductions around uniform pixel branches #3193
No reviewers
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!3193
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3191"
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 21:01 UTC · original
SimSalabimse:cursor/ps-wave-reduction-branched→main· +280 −31 · 4 files · 2 commits · merged 2026-11-27 21:56 UTCChange
tools/startup/gfx2hlsl.pynow lowers a wave32 OR, MIN, or MAX reduction in a pixel stage that also has branches. The chain itself stays straight: no branch instruction and no branch target inside it, and EXEC is saved and restored as in the shapes already accepted. A uniform branch may sit before the chain, after it, or both, because every lane reaches the chain together. A branch that is not proven uniform stays refused, including a non-uniform branch that changes EXEC inside the chain. Wave64 stays refused. The existing chain matcher is unchanged.The draw check plants a signed-for-unsigned rewrite only on draws where that rewrite changes the program.
v_or_b32has no signed form, so the plant is skipped for the straight-line or draw and for the uniform-branch-after or draw. Min and max draws, including the uniform-branch-before max draw, still require the plant to change the text and to fail the desktop wave reference.Refs #2125. Builds on #2835.
Verification
Commit
02ec0b1439eab2dffd4cb37761c7877ae43af999ona5dad84328f0824586018b7bdef975852f6e6f23../out/pe-env/bin/python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linuxwith thepython-linuxlist in.github/workflows/windows.yml: exit 0, 237 checks passed../out/pe-env/bin/python -B tests/startup_gfx2hlsl_wave_reduce_check.py: exit 0../out/pe-env/bin/python -B tests/startup_tools_lint_check.py tools/startup: exit 0.python -B tests/startup_gfx2hlsl_wave_reduce_check.py binarywith llvm-mc 15.0.7: all fixtures pass, exit 0.Windows test PC (RTX 4070 Ti, MSVC 19.44):
3/3 passed, exit 0, twice (
startup_gfx2hlsl_wave_reduce_controls,startup_gfx2hlsl_wave_reduce_warpandstartup_gfx2hlsl_wave_reduce_hardware).The full
^startup_gfx2hlsl_suite at the previous commit488255066d48e8cb74c405df8dd33a22e0f2fa47was 377 of 379 passed. The two failures werestartup_gfx2hlsl_wave_reduce_warpandstartup_gfx2hlsl_wave_reduce_hardware, both the planted-error test bug this commit fixes.Evidence and follow-up
The fixtures are source-built gfx1013 pixel programs in
tests/startup_gfx2hlsl_wave_reduce_check.py. Accepted cases: a uniform branch before OR, MIN and MAX chains, after a chain, and on both sides. Refused controls: a branch target inside the chain, saveexec plus execz before the fill, a non-uniform branch after the chain, and wave64. There is also a mutant check and a reverted straight-line guard check. The WARP and hardware draws include a max chain with a uniform branch before it and an OR chain with a uniform branch after it.docs/experiments/startup-gfx2hlsl-wave-reduce.mdanddocs/startup-runtime.mddescribe the allowance and the refusals.The fixtures are hand-assembled gfx1013 words. No game files or captured programs.
Checklist
AI-assisted (Cursor)
github-bot referenced this pull request2026-11-27 21:30:21 +00:00
@pigalot on GitHub · 2026-11-27 21:56 UTC · original · approved these changes
Independently reviewed
02ec0b14integrated overmainc15a73a5(treebc1dfbba). The merge is clean (tools/startup/gfx2hlsl.pyauto-merged) andgit diff --cached --check origin/mainis clean.What I traced. The old guard in
wave_reductionrefused any chain in a program withhas_branchesorblocks.wave_reduce_branch_reason(pc, end)replaces it. A branched program is now accepted only when:s_cbranch*ors_branchlies in(pc, end];translate()is still refused);endis indivergent_branches.The other checks run after it, unchanged: pixel stage,
exec_known, nos_wqm. A divergent branch after the chain is only classified oncetranslate()reaches it, sowave_reduce_spansrecords each accepted span.wave_reduce_branch_refusalsthen refuses it at the chain start, through the samerefusals/Unsupportedpath as the other deferred refusals. The spans are reset withreduce_plan/reduce_pendingon each pass."Uniform" here is the existing classification:
scc_uniform, wave-limit and wave-load branches, covered VCC compares, and quad-votedexeczbranches. A quad vote needsnot exec_known, so it cannot sit before an accepted chain. Each accepted case leaves the desktop wave converged at theWaveActive*, which is what the lowering needs.I also checked a shape the fixtures do not build: a uniform
s_cbranch_scc0that is taken and skips the whole chain. It translates toif (pc == 1) { … v2 = WaveActiveMax(v1); … }withpcset from constants only. That is still a wave-uniform condition.What I ran.
controls,warpandhardwarepass in Debug and Release/O2(offscreen_checkrebuilt in each preset). On hardware, the newuniform branch before(max) anduniform branch after(or) draws match the reference. Each of their planted errors fails against it, for exampleuniform branch after the lane's own value … pixel (0,0): 00000001 …, reference 0000000fover 25 pixels of a 482-pixel wave. That run haddebug_errors=0 debug_warnings=0with the debug layer enabled.^startup_gfx2hlsl_without_hardware: 267/267 pass indev. (A first run overlapped one of my mutant edits and had one failure,startup_gfx2hlsl_compute_m-else-unswitched_warp. It passes alone on the restored tree, and the clean rerun is 267/267.)main'sgfx2hlsl.pyfrom a scratch copy. All are refused withwave reduction in a program with branches: only straight-line pixel stages are lowered.mainfor thev_or_b32label. The PR keys it on the input operation instead, and adds a control that the plant changes every other draw and leaves only the or draws unchanged.Mutants (each applied alone to
tools/startup/gfx2hlsl.py,startup_gfx2hlsl_wave_reduce_check.pyrerun, file restored from its raw bytes,git diff --quietclean afterwards):To test the surviving loop, I put a uniform
s_cmp_eq_u32 1, 1/s_cbranch_scc0to past the chain in three places: after the saveexec, between DPP steps, and between the restore and the readlane. The shape matcher refuses each before the new loop runs:identity fill … is not a known form,missing step quad_perm:[2,3,0,1], ands_cmp_eq_u32 1, 1 in place of v_readlane_b32. So the loop is a second line of defence for these shapes. I did not build the later-readlane forms with a branch between the restore and the readlane, where it may be the only one.Verdict: approve on
02ec0b14.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32, debug layer enabled for the hardware draw.
binarymode not run locally (no llvm-mc); CI'sAssemble and translate gfx1013 fixturescovers it.CI:
Build and test on Windows,Assemble and translate gfx1013 fixturesandRun platform-independent Python checks on Linuxpass on02ec0b14.This reply was AI-assisted.