Recompiler: take a wave64 reduction whose seed selects with the saved EXEC #3803

Open
BBareth wants to merge 1 commit from upstream-pr/3803 into main
BBareth commented 2026-12-03 17:53:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-03T17:53:03Z.


graphics_reductions rebuilds the console compiler's whole-wave reductions in vertex and pixel shaders as wave operations. For wave64 it requires the seed v_cndmask to select with the saved EXEC narrowed by an s_and_b64. A retail title's lighting pixel shader selects with the saved EXEC itself:

s_or_saveexec_b64 s[0:1], -1
v_cndmask_b32 v5, -1, v38, s[0:1]
(DPP8 ×3, row_mirror, v_permlanex16, v_min, v_readlane 32, v_min)
v_readlane_b32 s69, v5, 0

That form was left to the step-by-step translation. Lanes of a 32-lane hardware wave that were never launched do not run the seed, and the DPP steps read 0 from them. So in a partly covered wave the minimum light index came out 0: the same failure afpruivo found for the wave32 form with BOUND_CTRL (https://github.com/xcl-dev/xcl/pull/3089#issuecomment-7363243132). The saved EXEC holds no never-launched lane, so its seed already gives them the identity: the proof the narrowed form makes. This change takes that form too, when nothing between the save and the seed writes the saved pair.

What is in it

  • crates/xcl/src/gpu/recomp/mod.rs: graphics_reductions accepts a wave64 seed whose mask is the saved EXEC, unwritten since the save, as well as the narrowed one.
  • crates/xcl/src/gpu/recomp/tests.rs: whole_reduction can build that form (clobber 204) and the same with the saved EXEC overwritten before the seed (205). graphics_whole_reductions_use_wave_ops checks the first becomes xcl_red64_min and the second does not.

Tested

  • RTX 5070 Ti (driver 32.0.16.2124), i7-12700K, Windows 11 Pro 26200, rustc 1.95.0.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 on 430d5f5b: 3019 passed, 0 failed, 57 ignored. 28 SKIPPED: 22 no wave64, 2 no d3d12SDKLayers.dll, 2 no heap windows, 1 no D3D12 debug layer, 1 driver cache (Developer Mode).
  • cargo test -p xcl --lib graphics_whole_reductions_use_wave_ops with this test and main's mod.rs: fails (the unnarrowed form is not taken); with this change: passes.
  • Retail title, world run (1300 s, NVIDIA wave32, a tree of main 395405e4 + #3094 + #3282 + #3625 + afpruivo's BOUND_CTRL commit e8b24228, without and with this change): the lighting pixel shader that has this form is now built with xcl_red64_min. The gold speckles it left on a door frame and beside it in the HDR target are gone, apart from a few spots. Presents per minute at 600–1200 s: 82–90 with it, on the same tree without it 93–98 in one run and 84–92 in another with #3089 added, so no cost I can measure. No device removal and no crash.

Regression run
main 078358a0:

xcl-smoke v1
commit: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3046 (PresentX 3046)
presents per 2 s (last 3): 15 27 19
device removals: 0
crashes: 0
peak commit: 32465 MB

This PR (430d5f5b):

xcl-smoke v1
commit: 430d5f5b5ddf22c1b0af3862836b98abc5e5009b
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3031 (PresentX 3031)
presents per 2 s (last 3): 24 31 10
device removals: 0
crashes: 0
peak commit: 30544 MB

Not tested

  • AMD (wave64 hardware), where the 64-lane form runs with v_readlane 32 read for real.
  • A GPU run of this exact form: gpu_wave64_ps_whole_wave_reductions runs the narrowed form through the same emitter (xcl_red64_*). This change only widens the match.
  • Helper lanes are still left out of the rebuilt reduction, as before.

AI use

  • Claude Code (Claude Opus 5.5) found the unmatched form in a dumped shader, wrote the change, the test and this description, and ran the tests and runs listed above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5631970309 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3803). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-03T17:53:03Z. --- `graphics_reductions` rebuilds the console compiler's whole-wave reductions in vertex and pixel shaders as wave operations. For wave64 it requires the seed `v_cndmask` to select with the saved EXEC narrowed by an `s_and_b64`. A retail title's lighting pixel shader selects with the saved EXEC itself: ``` s_or_saveexec_b64 s[0:1], -1 v_cndmask_b32 v5, -1, v38, s[0:1] (DPP8 ×3, row_mirror, v_permlanex16, v_min, v_readlane 32, v_min) v_readlane_b32 s69, v5, 0 ``` That form was left to the step-by-step translation. Lanes of a 32-lane hardware wave that were never launched do not run the seed, and the DPP steps read 0 from them. So in a partly covered wave the minimum light index came out 0: the same failure afpruivo found for the wave32 form with `BOUND_CTRL` (https://github.com/xcl-dev/xcl/pull/3089#issuecomment-7363243132). The saved EXEC holds no never-launched lane, so its seed already gives them the identity: the proof the narrowed form makes. This change takes that form too, when nothing between the save and the seed writes the saved pair. **What is in it** - `crates/xcl/src/gpu/recomp/mod.rs`: `graphics_reductions` accepts a wave64 seed whose mask is the saved EXEC, unwritten since the save, as well as the narrowed one. - `crates/xcl/src/gpu/recomp/tests.rs`: `whole_reduction` can build that form (`clobber` 204) and the same with the saved EXEC overwritten before the seed (205). `graphics_whole_reductions_use_wave_ops` checks the first becomes `xcl_red64_min` and the second does not. **Tested** - RTX 5070 Ti (driver 32.0.16.2124), i7-12700K, Windows 11 Pro 26200, rustc 1.95.0. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4` on 430d5f5b: 3019 passed, 0 failed, 57 ignored. 28 SKIPPED: 22 no wave64, 2 no `d3d12SDKLayers.dll`, 2 no heap windows, 1 no D3D12 debug layer, 1 driver cache (Developer Mode). - `cargo test -p xcl --lib graphics_whole_reductions_use_wave_ops` with this test and `main`'s `mod.rs`: fails (the unnarrowed form is not taken); with this change: passes. - Retail title, world run (1300 s, NVIDIA wave32, a tree of `main` `395405e4` + #3094 + #3282 + #3625 + afpruivo's `BOUND_CTRL` commit `e8b24228`, without and with this change): the lighting pixel shader that has this form is now built with `xcl_red64_min`. The gold speckles it left on a door frame and beside it in the HDR target are gone, apart from a few spots. Presents per minute at 600–1200 s: 82–90 with it, on the same tree without it 93–98 in one run and 84–92 in another with #3089 added, so no cost I can measure. No device removal and no crash. **Regression run** main `078358a0`: ``` xcl-smoke v1 commit: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 120 exit: 0x0 frames shown: 3046 (PresentX 3046) presents per 2 s (last 3): 15 27 19 device removals: 0 crashes: 0 peak commit: 32465 MB ``` This PR (430d5f5b): ``` xcl-smoke v1 commit: 430d5f5b5ddf22c1b0af3862836b98abc5e5009b gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 120 exit: 0x0 frames shown: 3031 (PresentX 3031) presents per 2 s (last 3): 24 31 10 device removals: 0 crashes: 0 peak commit: 30544 MB ``` **Not tested** - AMD (wave64 hardware), where the 64-lane form runs with `v_readlane 32` read for real. - A GPU run of this exact form: `gpu_wave64_ps_whole_wave_reductions` runs the narrowed form through the same emitter (`xcl_red64_*`). This change only widens the match. - Helper lanes are still left out of the rebuilt reduction, as before. **AI use** - Claude Code (Claude Opus 5.5) found the unmatched form in a dumped shader, wrote the change, the test and this description, and ran the tests and runs listed above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Foniass commented 2026-12-03 17:55:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T17:55:26Z.


Review of 430d5f5b (code reading only, not a merge-check) · no findings

In short: graphics_reductions now also takes a wave64 whole-wave reduction whose seed v_cndmask selects with the saved EXEC itself, not only with the saved EXEC narrowed by an s_and_b64, provided nothing overwrites the saved pair before the seed. The proof the narrowed form needs, that no never-launched lane is in the mask, holds just the same for the saved EXEC. The change is small and right, and the tests cover the accepted form and the refused one. Nothing blocks it.

Checked and fine
  • unnarrowed requires mask == saved (the seed's SRC2 is the s_or_saveexec_b64 destination) and no write to either half of that pair between the save and the seed (overwrites over open + 1..i). Never-launched lanes are not in the old EXEC, so their seed is the identity, exactly as with saved & x.
  • The narrowed form keeps the same conditions as before. They have moved into one is_some_and closure, and the two "not overwritten" checks are still on their ranges.
  • The rest is unchanged: the opener within 6 instructions, the 9 wave64 steps, the step shapes and the v_readlane of lane 32. A seed that only looks like this still has to pass the whole sequence check.
  • In the tests, whole_reduction(…, Some(204)) builds the seed with the saved EXEC and no s_and, and checks it becomes xcl_red64_min. Some(205) overwrites the saved pair with s_mov_b64 s[30:31], -1 before the seed, and is in the refused list. Tested shows the first failing with main's mod.rs.
  • Tested gives the whole suite on 430d5f5b (3019 passed, 0 failed, 57 ignored, 28 SKIPPED) and a 120 s smoke pair on a retail title (3046 against 3031 frames, less peak commit). A world run shows the lighting shader built with xcl_red64_min and the speckles mostly gone.
  • Not tested names AMD and a GPU run of this exact form. The emitter it now reaches (xcl_red64_*) is already covered by gpu_wave64_ps_whole_wave_reductions.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7387291861 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3803#issuecomment-7387291861). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T17:55:26Z. --- **Review** of `430d5f5b` (code reading only, not a merge-check) · no findings **In short:** `graphics_reductions` now also takes a wave64 whole-wave reduction whose seed `v_cndmask` selects with the saved EXEC itself, not only with the saved EXEC narrowed by an `s_and_b64`, provided nothing overwrites the saved pair before the seed. The proof the narrowed form needs, that no never-launched lane is in the mask, holds just the same for the saved EXEC. The change is small and right, and the tests cover the accepted form and the refused one. Nothing blocks it. <details><summary>Checked and fine</summary> - `unnarrowed` requires `mask == saved` (the seed's `SRC2` is the `s_or_saveexec_b64` destination) and no write to either half of that pair between the save and the seed (`overwrites` over `open + 1..i`). Never-launched lanes are not in the old EXEC, so their seed is the identity, exactly as with `saved & x`. - The narrowed form keeps the same conditions as before. They have moved into one `is_some_and` closure, and the two "not overwritten" checks are still on their ranges. - The rest is unchanged: the opener within 6 instructions, the 9 wave64 steps, the step shapes and the `v_readlane` of lane 32. A seed that only looks like this still has to pass the whole sequence check. - In the tests, `whole_reduction(…, Some(204))` builds the seed with the saved EXEC and no `s_and`, and checks it becomes `xcl_red64_min`. `Some(205)` overwrites the saved pair with `s_mov_b64 s[30:31], -1` before the seed, and is in the refused list. **Tested** shows the first failing with `main`'s `mod.rs`. - **Tested** gives the whole suite on `430d5f5b` (3019 passed, 0 failed, 57 ignored, 28 SKIPPED) and a 120 s smoke pair on a retail title (3046 against 3031 frames, less peak commit). A world run shows the lighting shader built with `xcl_red64_min` and the speckles mostly gone. - **Not tested** names AMD and a GPU run of this exact form. The emitter it now reaches (`xcl_red64_*`) is already covered by `gpu_wave64_ps_whole_wave_reductions`. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3803:upstream-pr/3803'
git switch 'upstream-pr/3803'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3803'
git switch 'upstream-pr/3803'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3803'
git switch 'upstream-pr/3803'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3803'
git switch 'main'
git merge --squash 'upstream-pr/3803'
git switch 'main'
git merge --ff-only 'upstream-pr/3803'
git switch 'main'
git merge 'upstream-pr/3803'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3803
No description provided.