Shaders: skip cross-half exchange in active_f64_sum for local waves and groups <= 32 #461

Open
Fimpos wants to merge 1 commit from upstream-pr/461 into main
Fimpos commented 2026-11-25 01:13:21 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Fimpos on 2026-11-25T01:13:21Z.


## Problem

Lower::active_f64_sum (added in 3bff182 for v_add_f64 whole-wave sums) checked if self.exchange.is_some() directly instead of matching wave_reduction's guard right above it (if !self.local && self.exchange.as_ref().is_some_and(|e| !e.1)).

On 32-lane hosts (NVIDIA), that had two consequences for wave64 compute shaders containing Shape::ActiveF64:

  1. Under with_local_waves / with_local_waves_any (self.local == true), divergent f64 sums still returned Err("a wave reduction where not every lane runs") instead of taking the host wave's own sum, causing shaders such as 5dc3b25986622949 and 6f225b641c5b0708 to fail the local-wave retry (together with #190 / LOCAL_ANY they now lower at WaveSize(32) and pass CreateComputePipelineState instead of falling back to WaveSize(64) -> E_INVALIDARG).
  2. For a wave64 shader with group <= 32 (e.1 == true), one host wave already holds the whole group, so no cross-half exchange should be emitted.

Change

  • crates/victory-shader/src/emit/lower.rs: guard the cross-half exchange in Lower::active_f64_sum with if !self.local && self.exchange.as_ref().is_some_and(|e| !e.1), matching Lower::wave_reduction.
  • crates/victory-shader/src/emit/wave64_tests.rs: add wave64_f64_sum_on_wave32_host_respects_small_groups_and_local_waves, covering both the 64-thread divergent with_local_waves_any path and a 32-thread wave64 group executed on the host GPU.

Verification

  • cargo xtask policy: ok (169 files)
  • cargo clippy -p victory-shader --tests -- -D warnings: clean
  • cargo test -p victory-shader --lib wave64_f64_sum_on_wave32_host_respects_small_groups_and_local_waves: passed on Windows 11 + NVIDIA RTX 5070 (dxil.dll validation + hardware GPU dispatch)
  • Verified with VICTORY_HOST_MAX_WAVE=32 that 5dc3b25986622949 and 6f225b641c5b0708 get past the 0x7e8/0x7f8 a wave reduction where not every lane runs stop (and together with the scc_some / LOCAL_ANY wave32 fixes, both validate with dxil.dll and create D3D12 pipelines on RTX 5070).

Related: #394

(AI-assisted fix & test; built and verified on real RTX 5070 hardware.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:5483185425 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/461). Originally posted by [Fimpos](https://github.com/Fimpos) on 2026-11-25T01:13:21Z. --- ## Problem `Lower::active_f64_sum` (added in `3bff182` for `v_add_f64` whole-wave sums) checked `if self.exchange.is_some()` directly instead of matching `wave_reduction`'s guard right above it (`if !self.local && self.exchange.as_ref().is_some_and(|e| !e.1)`). On 32-lane hosts (NVIDIA), that had two consequences for wave64 compute shaders containing `Shape::ActiveF64`: 1. Under `with_local_waves` / `with_local_waves_any` (`self.local == true`), divergent f64 sums still returned `Err("a wave reduction where not every lane runs")` instead of taking the host wave's own sum, causing shaders such as `5dc3b25986622949` and `6f225b641c5b0708` to fail the local-wave retry (together with #190 / `LOCAL_ANY` they now lower at `WaveSize(32)` and pass `CreateComputePipelineState` instead of falling back to `WaveSize(64)` -> `E_INVALIDARG`). 2. For a wave64 shader with `group <= 32` (`e.1 == true`), one host wave already holds the whole group, so no cross-half exchange should be emitted. ## Change - `crates/victory-shader/src/emit/lower.rs`: guard the cross-half exchange in `Lower::active_f64_sum` with `if !self.local && self.exchange.as_ref().is_some_and(|e| !e.1)`, matching `Lower::wave_reduction`. - `crates/victory-shader/src/emit/wave64_tests.rs`: add `wave64_f64_sum_on_wave32_host_respects_small_groups_and_local_waves`, covering both the 64-thread divergent `with_local_waves_any` path and a 32-thread wave64 group executed on the host GPU. ## Verification - `cargo xtask policy`: ok (169 files) - `cargo clippy -p victory-shader --tests -- -D warnings`: clean - `cargo test -p victory-shader --lib wave64_f64_sum_on_wave32_host_respects_small_groups_and_local_waves`: passed on Windows 11 + NVIDIA RTX 5070 (`dxil.dll` validation + hardware GPU dispatch) - Verified with `VICTORY_HOST_MAX_WAVE=32` that `5dc3b25986622949` and `6f225b641c5b0708` get past the `0x7e8`/`0x7f8` `a wave reduction where not every lane runs` stop (and together with the `scc_some` / `LOCAL_ANY` wave32 fixes, both validate with `dxil.dll` and create D3D12 pipelines on RTX 5070). Related: #394 *(AI-assisted fix & test; built and verified on real RTX 5070 hardware.)*
Yorivel commented 2026-11-25 02:10:11 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Yorivel on 2026-11-25T01:47:33Z.


Tested together with #190 and #156 on an RTX 4090 (32-lane, driver 621.40), on a803c87:

  • 5dc3b25986622949 and 6f225b641c5b0708 now lower at WaveSize(32) and create pipelines. Offline (VICTORY_HOST_MAX_WAVE=32 victory translate --validate --pipelines) and in game, both had been E_INVALIDARG on every run before.
  • With #156 the ray-tracing builder also gets all 53 host pipelines (the crash after that is #16).
  • Runs reach the first gameplay room without errors or device faults, at the same frame time as before.

Of the seven wave64 refusals of this scene, four remain: 2da4beb386509b77, 2cc4c197ee29e291, 02384a60fda6f2d0, 6b82bc7d22016cb5. A fifth, 369cbe906ea72764, is handled in #500.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149961467 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/461#issuecomment-7149961467). Originally posted by [Yorivel](https://github.com/Yorivel) on 2026-11-25T01:47:33Z. --- Tested together with #190 and #156 on an RTX 4090 (32-lane, driver 621.40), on `a803c87`: - `5dc3b25986622949` and `6f225b641c5b0708` now lower at `WaveSize(32)` and create pipelines. Offline (`VICTORY_HOST_MAX_WAVE=32 victory translate --validate --pipelines`) and in game, both had been `E_INVALIDARG` on every run before. - With #156 the ray-tracing builder also gets all 53 host pipelines (the crash after that is #16). - Runs reach the first gameplay room without errors or device faults, at the same frame time as before. Of the seven wave64 refusals of this scene, four remain: `2da4beb386509b77`, `2cc4c197ee29e291`, `02384a60fda6f2d0`, `6b82bc7d22016cb5`. A fifth, `369cbe906ea72764`, is handled in #500.
HAL9000RELOADED commented 2026-11-25 20:09:27 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T19:29:44Z.


RX 7900 XTX (RDNA3), Windows 10 + #402 for SM 6.6, main d510ee4: the new test wave64_f64_sum_on_wave32_host_respects_small_groups_and_local_waves passes on the card with this PR, and fails with the test alone on the base. No other test changed. Run table: #129 (https://github.com/fxceless/victory-fork/pull/129#issuecomment-7172358511).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7172375828 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/461#issuecomment-7172375828). Originally posted by [HAL9000RELOADED](https://github.com/HAL9000RELOADED) on 2026-11-25T19:29:44Z. --- RX 7900 XTX (RDNA3), Windows 10 + #402 for SM 6.6, main `d510ee4`: the new test `wave64_f64_sum_on_wave32_host_respects_small_groups_and_local_waves` passes on the card with this PR, and fails with the test alone on the base. No other test changed. Run table: #129 (https://github.com/fxceless/victory-fork/pull/129#issuecomment-7172358511).
Dathinel commented 2026-11-25 23:09:55 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Dathinel on 2026-11-25T22:19:11Z.


Independent synthetic readback on an RTX 3050 Laptop (Windows D3D12). I applied the active_f64_sum guard to our local Series S branch and adapted the PR fixture to require DXIL validation, successful PSO creation, and actual dispatch. Before the guard, lowering stopped at offset 220 with “a wave reduction where not every lane runs”. Afterward both variants validated and created pipelines. In the 32-thread variant, 1, 4, 16, 31 and 32 active lanes each contributing 1.25 produced exactly 1.25, 5, 20, 38.75 and 40. The 64-thread local variant was checked through pipeline creation only. On this PC WARP reports a maximum wave size of 4 and refuses the required WaveSize(32) PSO. No water rendering or performance comparison in this test. AI-assisted.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7176214300 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/461#issuecomment-7176214300). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T22:19:11Z. --- Independent synthetic readback on an RTX 3050 Laptop (Windows D3D12). I applied the active_f64_sum guard to our local Series S branch and adapted the PR fixture to require DXIL validation, successful PSO creation, and actual dispatch. Before the guard, lowering stopped at offset 220 with “a wave reduction where not every lane runs”. Afterward both variants validated and created pipelines. In the 32-thread variant, 1, 4, 16, 31 and 32 active lanes each contributing 1.25 produced exactly 1.25, 5, 20, 38.75 and 40. The 64-thread local variant was checked through pipeline creation only. On this PC WARP reports a maximum wave size of 4 and refuses the required WaveSize(32) PSO. No water rendering or performance comparison in this test. AI-assisted.
Lyrnc commented 2026-11-27 00:46:22 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Lyrnc on 2026-11-27T00:46:22Z.


Setup. #461 (d3c96c3) merged onto fork main 52ac4ec (the only conflict: both sides add tests at the end of wave64_tests.rs, kept both). Each case is a hand-written console wave64 compute program: one 64-thread group, lowered for a host of 32-lane waves (TEST_HOST_WAVE=32), validated by dxil.dll, then run through D3D12 on an RTX 5080. The reference is the same instructions run natively in wave64 on the gfx1036 iGPU (RDNA2) of the same PC. A Python model of the console's order agrees with that hardware on 54 of 54 cases. The cases are 54 whole-wave f32 and f64 sums in the compiler's WaveActiveSum shape: DPP8 [1,0,3,2,5,4,7,6] / [2,2,0,0,6,6,4,4] / [4,4,4,4,0,0,0,0], row_mirror bound_ctrl:1, v_permlanex16_b32 0, 0, v_readlane_b32 32 and 0. The f64 form uses v_mov_b32 DPP pairs and v_add_f64. The sums sit inside per-lane branches or after an early-out. 20 of the 54 are f64 sums.

F4 cases (54), RTX 5080 exact differ refused
main, wave-wide on 29 25 0
main + #461, wave-wide on 29 25 0 (the same per case)
main, wave-wide off (default local-wave forms) 5 34 15
main + #461, wave-wide off 5 49 0

The fork's 151 wave64 cases (wave-wide on, RTX 5080) give the same result on every case with and without #461: 120 exact, 31 differ.

Meaning. With the wave-wide form, #461 changes nothing: exchange is set and the group is 64 threads, so the guard it edits is true before and after. Under local waves it works as described: the 15 f64 sums that main refuses (a wave reduction where not every lane runs) are now lowered. Each host wave gives its own half's sum, though, so all 15 differ from the hardware. Example: f64/hash64/all, lane 0, hardware 0x40a0137b25a67b46 (2057.74), with #461 0x408f48beb6361ce8 (1001.09, the sum of lanes 0..31 only). That is the local form's known approximation, not a new bug. The PR's own test (wave64_f64_sum_on_wave32_host_respects_small_groups_and_local_waves) passes on the 5080, both on main + #461 and on the local tree-order branch (mentioned below) + #461.

Neither form fixes the order of the sum. Every one of the 25 differences, with or without #461, matches lanes 16 apart being added first in each 32-lane half: waveActiveOp on the 5080. Example: f64/cancel64/all hardware 62.0 (0x404f000000000000), 5080 60.3752 (0x404e30073d8bb1c1). A local branch that adds in the console's tree makes all 54 exact (and 5 more in uniform control flow).

AI use: Claude Code (Claude Opus 5.5) wrote the cases, the harness and the merge, and ran them on this PC. The numbers come from those runs.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7206740072 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/461#issuecomment-7206740072). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-27T00:46:22Z. --- **Setup.** #461 (d3c96c3) merged onto fork main 52ac4ec (the only conflict: both sides add tests at the end of `wave64_tests.rs`, kept both). Each case is a hand-written console wave64 compute program: one 64-thread group, lowered for a host of 32-lane waves (`TEST_HOST_WAVE=32`), validated by dxil.dll, then run through D3D12 on an RTX 5080. The reference is the same instructions run natively in wave64 on the gfx1036 iGPU (RDNA2) of the same PC. A Python model of the console's order agrees with that hardware on 54 of 54 cases. The cases are 54 whole-wave f32 and f64 sums in the compiler's `WaveActiveSum` shape: DPP8 `[1,0,3,2,5,4,7,6]` / `[2,2,0,0,6,6,4,4]` / `[4,4,4,4,0,0,0,0]`, `row_mirror bound_ctrl:1`, `v_permlanex16_b32 0, 0`, `v_readlane_b32` 32 and 0. The f64 form uses `v_mov_b32` DPP pairs and `v_add_f64`. The sums sit inside per-lane branches or after an early-out. 20 of the 54 are f64 sums. | F4 cases (54), RTX 5080 | exact | differ | refused | |---|---|---|---| | main, wave-wide on | 29 | 25 | 0 | | main + #461, wave-wide on | 29 | 25 | 0 (the same per case) | | main, wave-wide off (default local-wave forms) | 5 | 34 | 15 | | main + #461, wave-wide off | 5 | 49 | 0 | The fork's 151 wave64 cases (wave-wide on, RTX 5080) give the same result on every case with and without #461: 120 exact, 31 differ. **Meaning.** With the wave-wide form, #461 changes nothing: `exchange` is set and the group is 64 threads, so the guard it edits is true before and after. Under local waves it works as described: the 15 f64 sums that main refuses (`a wave reduction where not every lane runs`) are now lowered. Each host wave gives its own half's sum, though, so all 15 differ from the hardware. Example: `f64/hash64/all`, lane 0, hardware 0x40a0137b25a67b46 (2057.74), with #461 0x408f48beb6361ce8 (1001.09, the sum of lanes 0..31 only). That is the local form's known approximation, not a new bug. The PR's own test (`wave64_f64_sum_on_wave32_host_respects_small_groups_and_local_waves`) passes on the 5080, both on main + #461 and on the local tree-order branch (mentioned below) + #461. Neither form fixes the order of the sum. Every one of the 25 differences, with or without #461, matches lanes 16 apart being added first in each 32-lane half: `waveActiveOp` on the 5080. Example: `f64/cancel64/all` hardware 62.0 (0x404f000000000000), 5080 60.3752 (0x404e30073d8bb1c1). A local branch that adds in the console's tree makes all 54 exact (and 5 more in uniform control flow). AI use: Claude Code (Claude Opus 5.5) wrote the cases, the harness and the merge, and ran them on this PC. The numbers come from those runs.
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/461:upstream-pr/461'
git switch 'upstream-pr/461'

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/461'
git switch 'upstream-pr/461'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/461'
git switch 'upstream-pr/461'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/461'
git switch 'main'
git merge --squash 'upstream-pr/461'
git switch 'main'
git merge --ff-only 'upstream-pr/461'
git switch 'main'
git merge 'upstream-pr/461'
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
fxceless/victory-fork!461
No description provided.