victory-shader: support multi-wave and LDS Wave64 compute shaders on … #221

Open
github-bot wants to merge 1 commit from github-bot/gh-221 into main AGit
Owner

@⁠spook40 on GitHub · 2026-11-26 02:57 UTC · original
spook40:fix/wave64-lds-multiwave-149 → main · +94 −21 · 3 files · 1 commits · open

Closes #149

Summary

Enables Wave64 compute shaders that use LDS (s.lds_dwords > 0) and/or span multiple console waves per threadgroup (> 64 threads) to translate and run on 32-lane NVIDIA hardware via console_cf.

Root Cause

On 32-lane targets (!target.runs(64)), victory-shader previously restricted console_cf to single-wave threadgroups (<= 64 threads) with zero LDS (s.lds_dwords == 0). Any Wave64 compute shader combining cross-lane operations with LDS—or dispatching 128+ threads per group—fell back to s.wave_size = Some(64) and failed pipeline creation with Unsupported, dropping ~17 compute dispatches per frame in the prison prologue.

Changes

  • crates/victory-shader/src/emit/lower.rs:
    • Generalized exchange() to allocate threads.div_ceil(64) * 2 shared-memory dwords and index each console wave's exchange pair via (flat_tid >> 6) * 2 + half, allowing multi-wave threadgroups (> 64 threads) to exchange half-wave values without colliding.
    • Updated wants_console_flow to route Wave64 compute shaders with LDS (s.lds_dwords > 0) and multi-wave threadgroups through console_cf on 32-lane targets, emitting group memory barriers around LDS reads/writes to preserve intra-wave memory ordering across split 32-lane warps.
  • crates/victory-shader/src/emit/split_tests.rs & mod.rs:
    • Updated adapter matrix tests to verify 128-thread Wave64 compute pipeline creation on 32-lane hosts.
    • Added hardware D3D12 execution tests covering 128-thread multi-wave console_cf isolation and combined cross-lane exchange + LDS (ds_write_b32/ds_read_b32).

Testing

  • cargo test -p victory-shader split_tests -- --test-threads=1 (12/12 passed on NVIDIA GeForce RTX 3060 Ti)
  • cargo test -p victory-shader each_adapter_gets_what_it_runs (passed on NVIDIA GeForce RTX 3060 Ti)
**@⁠spook40** on GitHub · 2026-11-26 02:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/221) `spook40:fix/wave64-lds-multiwave-149` → `main` · +94 −21 · 3 files · 1 commits · open Closes #149 ### Summary Enables Wave64 compute shaders that use LDS (`s.lds_dwords > 0`) and/or span multiple console waves per threadgroup (`> 64` threads) to translate and run on 32-lane NVIDIA hardware via `console_cf`. ### Root Cause On 32-lane targets (`!target.runs(64)`), `victory-shader` previously restricted `console_cf` to single-wave threadgroups (`<= 64` threads) with zero LDS (`s.lds_dwords == 0`). Any Wave64 compute shader combining cross-lane operations with LDS—or dispatching 128+ threads per group—fell back to `s.wave_size = Some(64)` and failed pipeline creation with `Unsupported`, dropping ~17 compute dispatches per frame in the prison prologue. ### Changes - **`crates/victory-shader/src/emit/lower.rs`**: - Generalized `exchange()` to allocate `threads.div_ceil(64) * 2` shared-memory dwords and index each console wave's exchange pair via `(flat_tid >> 6) * 2 + half`, allowing multi-wave threadgroups (`> 64` threads) to exchange half-wave values without colliding. - Updated `wants_console_flow` to route Wave64 compute shaders with LDS (`s.lds_dwords > 0`) and multi-wave threadgroups through `console_cf` on 32-lane targets, emitting group memory barriers around LDS reads/writes to preserve intra-wave memory ordering across split 32-lane warps. - **`crates/victory-shader/src/emit/split_tests.rs` & `mod.rs`**: - Updated adapter matrix tests to verify 128-thread Wave64 compute pipeline creation on 32-lane hosts. - Added hardware D3D12 execution tests covering 128-thread multi-wave `console_cf` isolation and combined cross-lane exchange + LDS (`ds_write_b32`/`ds_read_b32`). ### Testing - `cargo test -p victory-shader split_tests -- --test-threads=1` (12/12 passed on NVIDIA GeForce RTX 3060 Ti) - `cargo test -p victory-shader each_adapter_gets_what_it_runs` (passed on NVIDIA GeForce RTX 3060 Ti)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:38:11 +00:00
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:54 UTC · original

Tested natively on Windows 11 with an RX 7900 XT (RDNA3, driver 32.0.32029.2010), head b81546b against base 4f62c2a. Other jobs were running on the machine at the same time. I have no NVIDIA card, so I could not test the RTX 3050 from #149. This GPU runs both wave sizes, so to test the 32-lane path I translated for a forced 32-32 target and ran the WaveSize(32) output here.

Archive (shaders.rpf, translate --validate --list)

  • Host lanes 32-64: no program changes.
  • Host lanes 32-32, compute: 2389 -> 2574 emitted, 2389 -> 2570 validated.
    • All 127 "a wave64 group sharing LDS without barriers" refusals now translate and validate.
    • 58 of the 166 "console wave64 lanes" refusals now translate. 108 remain.
    • 11 of the 12 hashes in #149 now translate:
      • lens_flares: CS_GeneratePowerOfTwoMips, CS_GenerateNonPowerOfTwoAlongYMips, CS_ScanMip0-3
      • TAA_Utilities: CS_Disocclusion, CS_SceneColorTemporalResolveDualOutputWithLuma
      • BilateralGrid: CS_ComputeLuminanceBilateralGrid
      • vfx_triangleClip: CS_DefragHeap_ComputeRelocations, CS_RelocateVfxStartIndexLocation
      • lens_flares CS_MergeQuads is still refused.
    • 4 programs fail validation with "Total Thread Group Shared Memory storage is 32896, exceeded 32768". Their LDS already uses all 32 KiB, and xchg is added on top.
      • Two of them validated on base: vfx_proj_decal_hit_detection CS_ComputeHitDetectionResults and CS_ComputeHitDetectionSkinnedResults.
      • The other two are new: vfx_triangleClip CS_CollectTriangles and CS_CollectTriangles_Meshlets.
    • 231 programs that already translated have changed DXIL:
      • 142 are groups of more than 64 threads with LDS. Base emitted them in the per-lane form with no wave size. lds_wave64 has no group-size limit, so they now take the console flow as WaveSize(32). The barrier calls in their DXIL go from 407 to 11143 in total (median +56.5 per program, max +295).
      • The other 89 are one-wave console-flow programs. Only the exchange slot index changes; the barrier count is the same.
  • --pipelines at 32-32 on the 7900 XT: all 2574 compute pipelines are created, including the 4 that fail validation.

Tests

  • victory-shader --lib, single-threaded: 277 passed on base. On head 278 passed and 1 failed: emit::tests::console_lanes_translate_only_for_hosts_with_that_wave_size (mod.rs:1129). It still expects a 128-thread wave64 program to be refused for a 32-32 target. It does not use the GPU, so it should fail on any machine. It is not in the test commands listed in the PR description.
  • With only the new tests applied to base, just console_flow_supports_multiple_console_waves_per_group fails.
  • multi_wave_console_flow_isolates_per_wave_exchange and console_flow_with_lds_preserves_shared_memory also pass on base here. They use host.target(), which is 32-64 on this GPU, so they run as wave64 and never reach the new path. They only exercise it on an adapter without 64-lane waves.

Hand-written wave64 programs at a forced 32-32 target, run as WaveSize(32)

This is a local test, not for merge. The reference is the same program at 32-64 on the same GPU, which was right in every case.

  • Right:
    • your LDS test body
    • v_readlane of lane 40 in 1-D groups of 128 and 256, and in 16x8, 8x16 and 8x8 groups
    • a v_readlane inside a branch that only one console wave of a 128-thread group takes
  • Wrong: write-after-read in LDS within one console wave (64 threads).
    • The program writes lds[t], reads lds[t ^ 32], then writes lds[t] again.
    • The barrier goes before the read and after the write, so one half can overwrite a value before the other half reads it.
    • One half read the new value in every group: 2048 of 4096 lanes.
    • With a barrier before ds_write as well, this case was right.
  • Wrong: console waves that reach a different number of barriers (128 threads).
    • Each console wave runs a scalar loop a different number of times (4 and 1) with an LDS write inside. Then it writes its data, runs s_barrier, and reads the other wave's data.
    • The added barriers pair up wrongly, and the second wave reads before the first one has written. All 64 lanes of the second wave are wrong in every group.
    • The result is the same with a v_readlane in the loop instead of the LDS write.
    • On base, the LDS version translates at 32-32 in the per-lane form (no WaveSize, so the driver picks the wave size) and was right here. So this breaks a program that base already ran correctly on this GPU.
    • A branch that only the first console wave takes, with three LDS writes inside, is right at head. It becomes wrong once a barrier is also added before each write. So the result depends on how many barriers each wave adds.
  • Wrong: 32x2 and 32x4 groups with a v_readlane, every lane.
    • The console ids come from the rounded first-lane id in console_flat (#216). In these two shapes at WaveSize(32) on this GPU, two host waves get the same rounded id, so the halves meet in the wrong xchg slots.
    • 32x2 also fails on base, which already accepts groups of one console wave.
    • In the archive, 97 of the 185 new programs are 2-D or 3-D groups of more than 32 threads. Their shapes include 32x2 (the three ambient_map CS_AmbientMapSky*32 programs) and 32x32 (GpuParticleEmit CS_Emit_WaterSim and CS_EmitCounts_WaterSim).

With other branches

  • #206 (7eaaadf): merges cleanly. The 32-32 counts are the same. 23 programs differ from this PR alone, all from #206's own changes. CS_MergeQuads is still refused.
  • My local branch for #216, which gives each host wave its console ids from a group-shared counter:
    • Merging it conflicts only in split_tests.rs, where both add tests at the end.
    • With it, the 32x2 and 32x4 cases are right. The LDS and loop cases above still fail.
    • At 32-32 it changes the DXIL of 241 of the 416 programs this PR adds or changes. I can share it.

Possible changes (only checked with the cases above)

  • Add the group barrier before LDS writes too. Sub-dword LDS reads and writes, and LDS atomics, get no barrier at all right now.
  • Keep the console flow to groups of one console wave, where both halves always run the same blocks. For groups of several console waves, every added barrier has to sit in control flow that is the same across the whole group.
  • Leave programs that already use all 32 KiB of LDS out, or make room for xchg, so the two hit_detection programs keep validating.

For comparison, from reading only: rx9070xt (81ebb7b) also runs these programs in host waves of 32 (lower.rs:1428-1477). It puts a group barrier before every LDS access, writes included (lower.rs:5305-5315), so the write-after-read case should not happen there. But it also counts blocks behind scalar branches as run by every lane (lower.rs:490-491), and it has no group-size limit (lower.rs:1473). So console waves that reach different numbers of barriers look possible there too. I did not test that branch.

Not tested: NVIDIA, the game, and the GPU time of the extra barriers.

**@⁠adrianmjim** on GitHub · 2026-11-26 19:54 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/221#issuecomment-7202078151) Tested natively on Windows 11 with an RX 7900 XT (RDNA3, driver 32.0.32029.2010), head b81546b against base 4f62c2a. Other jobs were running on the machine at the same time. I have no NVIDIA card, so I could not test the RTX 3050 from #149. This GPU runs both wave sizes, so to test the 32-lane path I translated for a forced 32-32 target and ran the WaveSize(32) output here. **Archive (shaders.rpf, `translate --validate --list`)** - Host lanes 32-64: no program changes. - Host lanes 32-32, compute: 2389 -> 2574 emitted, 2389 -> 2570 validated. - All 127 "a wave64 group sharing LDS without barriers" refusals now translate and validate. - 58 of the 166 "console wave64 lanes" refusals now translate. 108 remain. - 11 of the 12 hashes in #149 now translate: - lens_flares: CS_GeneratePowerOfTwoMips, CS_GenerateNonPowerOfTwoAlongYMips, CS_ScanMip0-3 - TAA_Utilities: CS_Disocclusion, CS_SceneColorTemporalResolveDualOutputWithLuma - BilateralGrid: CS_ComputeLuminanceBilateralGrid - vfx_triangleClip: CS_DefragHeap_ComputeRelocations, CS_RelocateVfxStartIndexLocation - lens_flares CS_MergeQuads is still refused. - 4 programs fail validation with "Total Thread Group Shared Memory storage is 32896, exceeded 32768". Their LDS already uses all 32 KiB, and `xchg` is added on top. - Two of them validated on base: vfx_proj_decal_hit_detection CS_ComputeHitDetectionResults and CS_ComputeHitDetectionSkinnedResults. - The other two are new: vfx_triangleClip CS_CollectTriangles and CS_CollectTriangles_Meshlets. - 231 programs that already translated have changed DXIL: - 142 are groups of more than 64 threads with LDS. Base emitted them in the per-lane form with no wave size. `lds_wave64` has no group-size limit, so they now take the console flow as WaveSize(32). The barrier calls in their DXIL go from 407 to 11143 in total (median +56.5 per program, max +295). - The other 89 are one-wave console-flow programs. Only the exchange slot index changes; the barrier count is the same. - `--pipelines` at 32-32 on the 7900 XT: all 2574 compute pipelines are created, including the 4 that fail validation. **Tests** - victory-shader `--lib`, single-threaded: 277 passed on base. On head 278 passed and 1 failed: `emit::tests::console_lanes_translate_only_for_hosts_with_that_wave_size` (mod.rs:1129). It still expects a 128-thread wave64 program to be refused for a 32-32 target. It does not use the GPU, so it should fail on any machine. It is not in the test commands listed in the PR description. - With only the new tests applied to base, just `console_flow_supports_multiple_console_waves_per_group` fails. - `multi_wave_console_flow_isolates_per_wave_exchange` and `console_flow_with_lds_preserves_shared_memory` also pass on base here. They use `host.target()`, which is 32-64 on this GPU, so they run as wave64 and never reach the new path. They only exercise it on an adapter without 64-lane waves. **Hand-written wave64 programs at a forced 32-32 target, run as WaveSize(32)** This is a local test, not for merge. The reference is the same program at 32-64 on the same GPU, which was right in every case. - Right: - your LDS test body - `v_readlane` of lane 40 in 1-D groups of 128 and 256, and in 16x8, 8x16 and 8x8 groups - a `v_readlane` inside a branch that only one console wave of a 128-thread group takes - Wrong: write-after-read in LDS within one console wave (64 threads). - The program writes lds[t], reads lds[t ^ 32], then writes lds[t] again. - The barrier goes before the read and after the write, so one half can overwrite a value before the other half reads it. - One half read the new value in every group: 2048 of 4096 lanes. - With a barrier before `ds_write` as well, this case was right. - Wrong: console waves that reach a different number of barriers (128 threads). - Each console wave runs a scalar loop a different number of times (4 and 1) with an LDS write inside. Then it writes its data, runs `s_barrier`, and reads the other wave's data. - The added barriers pair up wrongly, and the second wave reads before the first one has written. All 64 lanes of the second wave are wrong in every group. - The result is the same with a `v_readlane` in the loop instead of the LDS write. - On base, the LDS version translates at 32-32 in the per-lane form (no WaveSize, so the driver picks the wave size) and was right here. So this breaks a program that base already ran correctly on this GPU. - A branch that only the first console wave takes, with three LDS writes inside, is right at head. It becomes wrong once a barrier is also added before each write. So the result depends on how many barriers each wave adds. - Wrong: 32x2 and 32x4 groups with a `v_readlane`, every lane. - The console ids come from the rounded first-lane id in `console_flat` (#216). In these two shapes at WaveSize(32) on this GPU, two host waves get the same rounded id, so the halves meet in the wrong `xchg` slots. - 32x2 also fails on base, which already accepts groups of one console wave. - In the archive, 97 of the 185 new programs are 2-D or 3-D groups of more than 32 threads. Their shapes include 32x2 (the three ambient_map CS_AmbientMapSky*32 programs) and 32x32 (GpuParticleEmit CS_Emit_WaterSim and CS_EmitCounts_WaterSim). **With other branches** - #206 (7eaaadf): merges cleanly. The 32-32 counts are the same. 23 programs differ from this PR alone, all from #206's own changes. CS_MergeQuads is still refused. - My local branch for #216, which gives each host wave its console ids from a group-shared counter: - Merging it conflicts only in split_tests.rs, where both add tests at the end. - With it, the 32x2 and 32x4 cases are right. The LDS and loop cases above still fail. - At 32-32 it changes the DXIL of 241 of the 416 programs this PR adds or changes. I can share it. **Possible changes** (only checked with the cases above) - Add the group barrier before LDS writes too. Sub-dword LDS reads and writes, and LDS atomics, get no barrier at all right now. - Keep the console flow to groups of one console wave, where both halves always run the same blocks. For groups of several console waves, every added barrier has to sit in control flow that is the same across the whole group. - Leave programs that already use all 32 KiB of LDS out, or make room for `xchg`, so the two hit_detection programs keep validating. For comparison, from reading only: `rx9070xt` (81ebb7b) also runs these programs in host waves of 32 (lower.rs:1428-1477). It puts a group barrier before every LDS access, writes included (lower.rs:5305-5315), so the write-after-read case should not happen there. But it also counts blocks behind scalar branches as run by every lane (lower.rs:490-491), and it has no group-size limit (lower.rs:1473). So console waves that reach different numbers of barriers look possible there too. I did not test that branch. Not tested: NVIDIA, the game, and the GPU time of the extra barriers.
Author
Owner

@⁠Aniseto on GitHub · 2026-11-26 20:46 UTC · original

Ran the Wave64-on-32-lane tests at b81546b on a physical NVIDIA Blackwell desktop part:

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB), driver 32.0.16.2124
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env)
  • Build: debug; VICTORY_D3D12_ADAPTER=NVIDIA

Results

  • cargo test -p victory-shader split_tests -- --test-threads=1: 12 passed, 0 failed, 0 ignored (273 filtered out, exit 0)
  • cargo test -p victory-shader each_adapter_gets_what_it_runs -- --test-threads=1: 1 passed, 0 failed, 0 ignored (284 filtered out, exit 0)
  • cargo test -p victory-shader --lib emit::tests::console_lanes_translate_only_for_hosts_with_that_wave_size -- --exact --test-threads=1: 0 passed, 1 failed, 0 ignored (284 filtered out, exit 101). The assertion now gets Ok(HostShader) where it expects Err(Unsupported { what: "console wave64 lanes on a host without 64-lane waves" }).

What this adds
The only report in the thread is on an RX 7900 XT, where the 32-lane path had to be forced; this adapter genuinely has no 64-lane waves, so the new console_cf path is taken without forcing. The twelve split_tests and the adapter test pass here. The last test fails on this host as well: adrianmjim saw the same failure on a forced 32-32 target on RDNA3 and noted it is not in the commands listed in the PR description. This is a measured result, not a review verdict.

Not tested
The hand-written wave64 shaders from that comment (write-after-read LDS, differing barrier counts, 32x2/32x4 groups), the title's shaders and GPU time, the full workspace suite, a paired smoke run, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-11-26 20:46 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/221#issuecomment-7203064022) Ran the Wave64-on-32-lane tests at `b81546b` on a physical NVIDIA Blackwell desktop part: **System** - GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB), driver 32.0.16.2124 - CPU: Intel Core i5-12400F, 64 GB RAM - OS: Windows 11 Pro build 26200 x64 - Toolchain: Rust 1.98.1 (pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env) - Build: debug; `VICTORY_D3D12_ADAPTER=NVIDIA` **Results** - `cargo test -p victory-shader split_tests -- --test-threads=1`: 12 passed, 0 failed, 0 ignored (273 filtered out, exit 0) - `cargo test -p victory-shader each_adapter_gets_what_it_runs -- --test-threads=1`: 1 passed, 0 failed, 0 ignored (284 filtered out, exit 0) - `cargo test -p victory-shader --lib emit::tests::console_lanes_translate_only_for_hosts_with_that_wave_size -- --exact --test-threads=1`: 0 passed, 1 failed, 0 ignored (284 filtered out, exit 101). The assertion now gets `Ok(HostShader)` where it expects `Err(Unsupported { what: "console wave64 lanes on a host without 64-lane waves" })`. **What this adds** The only report in the thread is on an RX 7900 XT, where the 32-lane path had to be forced; this adapter genuinely has no 64-lane waves, so the new `console_cf` path is taken without forcing. The twelve `split_tests` and the adapter test pass here. The last test fails on this host as well: adrianmjim saw the same failure on a forced 32-32 target on RDNA3 and noted it is not in the commands listed in the PR description. This is a measured result, not a review verdict. **Not tested** The hand-written wave64 shaders from that comment (write-after-read LDS, differing barrier counts, 32x2/32x4 groups), the title's shaders and GPU time, the full workspace suite, a paired smoke run, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/221/head:github-bot/gh-221'
git switch 'github-bot/gh-221'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-221'
git switch 'github-bot/gh-221'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-221'
git switch 'github-bot/gh-221'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-221'
git switch 'main'
git merge --squash 'github-bot/gh-221'
git switch 'main'
git merge --ff-only 'github-bot/gh-221'
git switch 'main'
git merge 'github-bot/gh-221'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.