startup: lower wave32 reductions around uniform pixel branches #3193

Manually merged
github merged 2 commits from github-bot/gh-3191 into gh-pr/3191/base 2026-11-27 21:57:15 +00:00 AGit
Owner

@⁠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 UTC

Change

tools/startup/gfx2hlsl.py now 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_b32 has 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 02ec0b1439eab2dffd4cb37761c7877ae43af999 on a5dad84328f0824586018b7bdef975852f6e6f23.

  • ./out/pe-env/bin/python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux with the python-linux list 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 binary with llvm-mc 15.0.7: all fixtures pass, exit 0.

Windows test PC (RTX 4070 Ti, MSVC 19.44):

ctest --preset dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_wave_reduce' -E 'startup_audio_output|startup_audio_pacing|startup_audio_provider'

3/3 passed, exit 0, twice (startup_gfx2hlsl_wave_reduce_controls, startup_gfx2hlsl_wave_reduce_warp and startup_gfx2hlsl_wave_reduce_hardware).

The full ^startup_gfx2hlsl_ suite at the previous commit 488255066d48e8cb74c405df8dd33a22e0f2fa47 was 377 of 379 passed. The two failures were startup_gfx2hlsl_wave_reduce_warp and startup_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.md and docs/startup-runtime.md describe the allowance and the refusals.

The fixtures are hand-assembled gfx1013 words. No game files or captured programs.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Cursor)

**@⁠SimSalabimse** on GitHub · 2026-11-27 21:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3191) `SimSalabimse:cursor/ps-wave-reduction-branched` → `main` · +280 −31 · 4 files · 2 commits · merged 2026-11-27 21:56 UTC ## Change `tools/startup/gfx2hlsl.py` now 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_b32` has 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 `02ec0b1439eab2dffd4cb37761c7877ae43af999` on `a5dad84328f0824586018b7bdef975852f6e6f23`. - `./out/pe-env/bin/python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux` with the `python-linux` list 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 binary` with llvm-mc 15.0.7: all fixtures pass, exit 0. Windows test PC (RTX 4070 Ti, MSVC 19.44): ```powershell ctest --preset dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_wave_reduce' -E 'startup_audio_output|startup_audio_pacing|startup_audio_provider' ``` 3/3 passed, exit 0, twice (`startup_gfx2hlsl_wave_reduce_controls`, `startup_gfx2hlsl_wave_reduce_warp` and `startup_gfx2hlsl_wave_reduce_hardware`). The full `^startup_gfx2hlsl_` suite at the previous commit `488255066d48e8cb74c405df8dd33a22e0f2fa47` was 377 of 379 passed. The two failures were `startup_gfx2hlsl_wave_reduce_warp` and `startup_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.md` and `docs/startup-runtime.md` describe the allowance and the refusals. The fixtures are hand-assembled gfx1013 words. No game files or captured programs. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Cursor)
Accept a wave32 OR, MIN, or MAX reduction in a pixel stage that also has
branches when the chain itself is straight, EXEC is saved and restored as in
the existing shapes, and every branch outside the chain is uniform. Wave64
and a non-uniform or in-chain branch stay refused.

Refs #2125

Co-authored-by: SimSalabimse <[email protected]>
The signed-for-unsigned mutation does not change a v_or_b32 lowering.
Apply it only where it changes the program, including the
uniform-branch-after or draw, the same way the straight-line or draw
already skipped it.

Refs #2125

Co-authored-by: SimSalabimse <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:05:00 +00:00
github-bot changed target branch from main to gh-pr/3191/base 2026-11-27 21:57:12 +00:00
github manually merged commit 02ec0b1439 into gh-pr/3191/base 2026-11-27 21:57:15 +00:00
Author
Owner

@⁠pigalot on GitHub · 2026-11-27 21:56 UTC · original · approved these changes

Independently reviewed 02ec0b14 integrated over main c15a73a5 (tree bc1dfbba). The merge is clean (tools/startup/gfx2hlsl.py auto-merged) and git diff --cached --check origin/main is clean.

What I traced. The old guard in wave_reduction refused any chain in a program with has_branches or blocks. wave_reduce_branch_reason(pc, end) replaces it. A branched program is now accepted only when:

  • no s_cbranch* or s_branch lies in (pc, end];
  • the uniformity map exists (a probe that never ran translate() is still refused);
  • no branch at or before end is in divergent_branches.

The other checks run after it, unchanged: pixel stage, exec_known, no s_wqm. A divergent branch after the chain is only classified once translate() reaches it, so wave_reduce_spans records each accepted span. wave_reduce_branch_refusals then refuses it at the chain start, through the same refusals / Unsupported path as the other deferred refusals. The spans are reset with reduce_plan / reduce_pending on each pass.

"Uniform" here is the existing classification: scc_uniform, wave-limit and wave-load branches, covered VCC compares, and quad-voted execz branches. A quad vote needs not exec_known, so it cannot sit before an accepted chain. Each accepted case leaves the desktop wave converged at the WaveActive*, which is what the lowering needs.

I also checked a shape the fixtures do not build: a uniform s_cbranch_scc0 that is taken and skips the whole chain. It translates to if (pc == 1) { … v2 = WaveActiveMax(v1); … } with pc set from constants only. That is still a wave-uniform condition.

What I ran.

.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_wave_reduce_check.py          # PASS
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_gfx2hlsl_wave_reduce_(controls|warp)$'
python with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^startup_gfx2hlsl_wave_reduce_hardware$'
ctest --test-dir out/build/dev --no-tests=error -j 6 -R '^startup_gfx2hlsl_' -E '_hardware$|startup_audio'
  • New draws. controls, warp and hardware pass in Debug and Release /O2 (offscreen_check rebuilt in each preset). On hardware, the new uniform branch before (max) and uniform branch after (or) draws match the reference. Each of their planted errors fails against it, for example uniform branch after the lane's own value … pixel (0,0): 00000001 …, reference 0000000f over 25 pixels of a 482-pixel wave. That run had debug_errors=0 debug_warnings=0 with the debug layer enabled.
  • Software neighbours. ^startup_gfx2hlsl_ without _hardware: 267/267 pass in dev. (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.)
  • Before. I translated the five new uniform-branch fixtures with main's gfx2hlsl.py from a scratch copy. All are refused with wave reduction in a program with branches: only straight-line pixel stages are lowered.
  • Not a weakened test. The draw check's signed-for-unsigned skip already existed on main for the v_or_b32 label. 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.py rerun, file restored from its raw bytes, git diff --quiet clean afterwards):

Mutant Result
earlier divergent branch ignored killed
later divergent-branch refusals dropped killed
EXEC-changing branch inside the chain allowed killed
span never recorded killed
old straight-line guard restored killed
"branch inside the chain" loop removed survives; equivalent for the shapes I probed
spans not reset per pass survives; only a retry pass can reach it

To test the surviving loop, I put a uniform s_cmp_eq_u32 1, 1 / s_cbranch_scc0 to 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], and s_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. binary mode not run locally (no llvm-mc); CI's Assemble and translate gfx1013 fixtures covers it.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 02ec0b14.

This reply was AI-assisted.

**@⁠pigalot** on GitHub · 2026-11-27 21:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3191#pullrequestreview-6093711588) · **approved these changes** Independently reviewed `02ec0b14` integrated over `main` `c15a73a5` (tree `bc1dfbba`). The merge is clean (`tools/startup/gfx2hlsl.py` auto-merged) and `git diff --cached --check origin/main` is clean. **What I traced.** The old guard in `wave_reduction` refused any chain in a program with `has_branches` or `blocks`. `wave_reduce_branch_reason(pc, end)` replaces it. A branched program is now accepted only when: - no `s_cbranch*` or `s_branch` lies in `(pc, end]`; - the uniformity map exists (a probe that never ran `translate()` is still refused); - no branch at or before `end` is in `divergent_branches`. The other checks run after it, unchanged: pixel stage, `exec_known`, no `s_wqm`. A divergent branch after the chain is only classified once `translate()` reaches it, so `wave_reduce_spans` records each accepted span. `wave_reduce_branch_refusals` then refuses it at the chain start, through the same `refusals` / `Unsupported` path as the other deferred refusals. The spans are reset with `reduce_plan` / `reduce_pending` on each pass. "Uniform" here is the existing classification: `scc_uniform`, wave-limit and wave-load branches, covered VCC compares, and quad-voted `execz` branches. A quad vote needs `not exec_known`, so it cannot sit before an accepted chain. Each accepted case leaves the desktop wave converged at the `WaveActive*`, which is what the lowering needs. I also checked a shape the fixtures do not build: a uniform `s_cbranch_scc0` that is taken and skips the whole chain. It translates to `if (pc == 1) { … v2 = WaveActiveMax(v1); … }` with `pc` set from constants only. That is still a wave-uniform condition. **What I ran.** ```powershell .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_wave_reduce_check.py # PASS ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_gfx2hlsl_wave_reduce_(controls|warp)$' python with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^startup_gfx2hlsl_wave_reduce_hardware$' ctest --test-dir out/build/dev --no-tests=error -j 6 -R '^startup_gfx2hlsl_' -E '_hardware$|startup_audio' ``` - **New draws.** `controls`, `warp` and `hardware` pass in Debug and Release `/O2` (`offscreen_check` rebuilt in each preset). On hardware, the new `uniform branch before` (max) and `uniform branch after` (or) draws match the reference. Each of their planted errors fails against it, for example `uniform branch after the lane's own value … pixel (0,0): 00000001 …, reference 0000000f` over 25 pixels of a 482-pixel wave. That run had `debug_errors=0 debug_warnings=0` with the debug layer enabled. - **Software neighbours.** `^startup_gfx2hlsl_` without `_hardware`: 267/267 pass in `dev`. (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.) - **Before.** I translated the five new uniform-branch fixtures with `main`'s `gfx2hlsl.py` from a scratch copy. All are refused with `wave reduction in a program with branches: only straight-line pixel stages are lowered`. - **Not a weakened test.** The draw check's signed-for-unsigned skip already existed on `main` for the `v_or_b32` label. 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.py` rerun, file restored from its raw bytes, `git diff --quiet` clean afterwards): | Mutant | Result | |---|---| | earlier divergent branch ignored | killed | | later divergent-branch refusals dropped | killed | | EXEC-changing branch inside the chain allowed | killed | | span never recorded | killed | | old straight-line guard restored | killed | | "branch inside the chain" loop removed | survives; equivalent for the shapes I probed | | spans not reset per pass | survives; only a retry pass can reach it | To test the surviving loop, I put a uniform `s_cmp_eq_u32 1, 1` / `s_cbranch_scc0` to 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]`, and `s_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. `binary` mode not run locally (no llvm-mc); CI's `Assemble and translate gfx1013 fixtures` covers it. CI: `Build and test on Windows`, `Assemble and translate gfx1013 fixtures` and `Run platform-independent Python checks on Linux` pass on `02ec0b14`. This reply was AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.