shader: order cross-half UAV write-then-read in wave64 compute without lane reads #2421

Manually merged
github merged 1 commit from github-bot/gh-2421 into main 2026-11-30 14:16:48 +00:00 AGit
Owner

@⁠steven-seagull27 on GitHub · 2026-11-29 12:53 UTC · original
steven-seagull27:fix/wave64-uav-order → main · +890 −3 · 3 files · 1 commits · merged 2026-11-30 14:12 UTC

Fixes Marvisak/VIctory#3766

What it changes

Console wave64 compute shaders (group > 32) with no lane reads (!console_lanes) and no LDS (lds == 0) can still rely on implicit intra-wave ordering when one half of a 64-lane wave stores to a UAV and the other half subsequently loads from it without an intervening s_barrier. Previously, lowering neither requested WaveSize(64) on 64-lane hosts (allowing drivers to compile them as Wave32) nor synchronized the two 32-lane host halves on 32-lane hosts like NVIDIA.

  • Added uav_order forward dataflow analysis in crates/victory-shader/src/emit/lower/analysis.rs to detect wave64 compute shaders (x.native.wave64 && group > 32) where a UAV load is reachable after a UAV store/atomic (or a UAV atomic after a plain UAV store) without an intervening convergent s_barrier. Read-only, write-only, straight-line read-then-write, and wave32 compute shaders are unaffected (zero added barriers, zero metadata change).
  • On 64-lane hosts (host_max_wave() >= 64): sets s.wave_size = Some(64) so the console wave remains intact at zero barrier cost.
  • On 32-lane hosts (host_max_wave() == 32): emits minimal dx.op.barrier(1 | 2) (thread-group sync + global UAV fence) before convergent UAV loads or before exiting convergent blocks into divergent UAV loads (using all_lane_blocks for group <= 64 and every_thread_blocks for group > 64, skipping syncs under cut_short). Inside divergent-only regions with no intervening convergent block, emits fence-only dx.op.barrier(2) so divergent branches can never deadlock.
  • Added synthetic regression and negative-control tests in crates/victory-shader/src/emit/wave64_tests.rs covering 5 -> 40 and 40 -> 5 cross-half UAV ordering (both branched and masked forms), WaveSize(64) emission on 64-lane hosts, dxil.dll validation, hardware D3D12 execution (including a negative control without the barrier), zero-barrier negative controls, and divergent-branch deadlock safety.

How it was tested

  • GPU and profile: NVIDIA GeForce RTX 5080 (32-lane hardware D3D12 host), 100% synthetic unit & GPU dispatch tests in victory-shader
  • Before: synthetic 64-thread wave64 compute shader without lane reads or LDS (5 -> 40 and 40 -> 5 branched) emitted 0 barriers on 32-lane hosts (no WaveSize(64) on 64-lane hosts) and reproduced 8,192 / 8,192 stale reads across hardware dispatches on RTX 5080 (negative control).
  • After:
    • 64-lane host (TEST_HOST_WAVE = Some(64)): emits WaveSize(64) metadata with 0 barriers and validates cleanly with dxil.dll.
    • 32-lane host (TEST_HOST_WAVE = Some(32)): emits dx.op.barrier(3) (mode 1 | 2), validates cleanly with dxil.dll, and passes 0 / 256 stale dispatches (4,096 hardware waves per variant) on RTX 5080 across all four variants (5->40 branched, 40->5 branched, 5->40 masked, 40->5 masked).
    • Negative controls: write-only, read-only, straight-line read-modify-write wave64 compute shaders and wave32 store->load compute shaders emit 0 barriers; divergent same-region UAV write->read emits fence-only dx.op.barrier(2) and runs on RTX 5080 without deadlock when half 1 skips the branch.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): both 32-lane (hardware D3D12 + dxil.dll) and 64-lane (DXIL lowering + WaveSize(64) metadata + dxil.dll)
  • cargo test passed for the crates it touches: yes
    • cargo test --locked -j 3 -p victory-shader --lib -- wave64_tests --test-threads=1: 46 passed; 0 failed
    • cargo test --locked -j 3 -p victory-shader --lib -- --test-threads=1: 464 passed; 0 failed; 9 ignored
    • cargo clippy --locked -j 3 -p victory-shader --lib --tests: 0 warnings in touched code
    • git diff --check: clean

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: none (no open PR addresses Marvisak/VIctory#3766)
**@⁠steven-seagull27** on GitHub · 2026-11-29 12:53 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2421) `steven-seagull27:fix/wave64-uav-order` → `main` · +890 −3 · 3 files · 1 commits · merged 2026-11-30 14:12 UTC Fixes Marvisak/VIctory#3766 ## What it changes Console wave64 compute shaders (`group > 32`) with no lane reads (`!console_lanes`) and no LDS (`lds == 0`) can still rely on implicit intra-wave ordering when one half of a 64-lane wave stores to a UAV and the other half subsequently loads from it without an intervening `s_barrier`. Previously, lowering neither requested `WaveSize(64)` on 64-lane hosts (allowing drivers to compile them as Wave32) nor synchronized the two 32-lane host halves on 32-lane hosts like NVIDIA. - Added `uav_order` forward dataflow analysis in `crates/victory-shader/src/emit/lower/analysis.rs` to detect wave64 compute shaders (`x.native.wave64 && group > 32`) where a UAV load is reachable after a UAV store/atomic (or a UAV atomic after a plain UAV store) without an intervening convergent `s_barrier`. Read-only, write-only, straight-line read-then-write, and wave32 compute shaders are unaffected (zero added barriers, zero metadata change). - On 64-lane hosts (`host_max_wave() >= 64`): sets `s.wave_size = Some(64)` so the console wave remains intact at zero barrier cost. - On 32-lane hosts (`host_max_wave() == 32`): emits minimal `dx.op.barrier(1 | 2)` (thread-group sync + global UAV fence) before convergent UAV loads or before exiting convergent blocks into divergent UAV loads (using `all_lane_blocks` for `group <= 64` and `every_thread_blocks` for `group > 64`, skipping syncs under `cut_short`). Inside divergent-only regions with no intervening convergent block, emits fence-only `dx.op.barrier(2)` so divergent branches can never deadlock. - Added synthetic regression and negative-control tests in `crates/victory-shader/src/emit/wave64_tests.rs` covering `5 -> 40` and `40 -> 5` cross-half UAV ordering (both branched and masked forms), `WaveSize(64)` emission on 64-lane hosts, `dxil.dll` validation, hardware D3D12 execution (including a negative control without the barrier), zero-barrier negative controls, and divergent-branch deadlock safety. ## How it was tested - GPU and profile: NVIDIA GeForce RTX 5080 (32-lane hardware D3D12 host), 100% synthetic unit & GPU dispatch tests in `victory-shader` - Before: synthetic 64-thread wave64 compute shader without lane reads or LDS (`5 -> 40` and `40 -> 5` branched) emitted 0 barriers on 32-lane hosts (no `WaveSize(64)` on 64-lane hosts) and reproduced **8,192 / 8,192 stale reads** across hardware dispatches on RTX 5080 (negative control). - After: - 64-lane host (`TEST_HOST_WAVE = Some(64)`): emits `WaveSize(64)` metadata with 0 barriers and validates cleanly with `dxil.dll`. - 32-lane host (`TEST_HOST_WAVE = Some(32)`): emits `dx.op.barrier(3)` (mode `1 | 2`), validates cleanly with `dxil.dll`, and passes **0 / 256 stale dispatches** (4,096 hardware waves per variant) on RTX 5080 across all four variants (`5->40` branched, `40->5` branched, `5->40` masked, `40->5` masked). - Negative controls: write-only, read-only, straight-line read-modify-write wave64 compute shaders and wave32 store->load compute shaders emit **0** barriers; divergent same-region UAV write->read emits fence-only `dx.op.barrier(2)` and runs on RTX 5080 without deadlock when half 1 skips the branch. - For shader changes, the wave sizes tested (32 and/or 64 lanes): both 32-lane (hardware D3D12 + `dxil.dll`) and 64-lane (DXIL lowering + `WaveSize(64)` metadata + `dxil.dll`) - `cargo test` passed for the crates it touches: yes - `cargo test --locked -j 3 -p victory-shader --lib -- wave64_tests --test-threads=1`: **46 passed; 0 failed** - `cargo test --locked -j 3 -p victory-shader --lib -- --test-threads=1`: **464 passed; 0 failed; 9 ignored** - `cargo clippy --locked -j 3 -p victory-shader --lib --tests`: 0 warnings in touched code - `git diff --check`: clean ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: none (no open PR addresses Marvisak/VIctory#3766)
Fixes Marvisak/VIctory#3766.

Wave64 compute shaders with group size > 32, no lane reads, and no LDS
can still rely on implicit intra-wave ordering when one half writes a
UAV and the other half subsequently loads it without an intervening
s_barrier. Previously, these shaders neither requested WaveSize(64) on
64-lane hosts nor synchronized halves on 32-lane hosts.

- Detect wave64 compute programs (group > 32) where a UAV load is
  reachable after a UAV store/atomic (or a UAV atomic after a plain UAV
  store) without an intervening convergent s_barrier, leaving read-only,
  write-only, straight-line read-then-write, and wave32 shaders untouched.
- On 64-lane hosts (host_max_wave() >= 64): set s.wave_size = Some(64)
  so the console wave stays intact at zero barrier cost.
- On 32-lane hosts (host_max_wave() == 32): emit a minimal group+UAV
  barrier (dx.op.barrier mode 1 | 2) before convergent loads or before
  exiting convergent blocks into divergent loads; inside divergent-only
  regions emit fence-only dx.op.barrier(2) so branches can never deadlock.
- Add synthetic regression and negative-control tests in wave64_tests.rs
  covering both 5->40 and 40->5 directions, branched and masked forms,
  WaveSize(64) emission, DXIL validation, hardware GPU execution, and
  divergent safety.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 12:54:59 +00:00
github manually merged commit 46e7ee988a into main 2026-11-30 14:16:48 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2421
No description provided.