shader: static Wave32 LDS alias & lane-private analysis for native Wave32 compute #1140

Open
github-bot wants to merge 3 commits from github-bot/gh-1140 into main AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 21:26 UTC · original
Vladimir-Human:shader/wave32-lds-disjoint → main · +3490 −142 · 4 files · 3 commits · open

Summary

AI-assisted port of static Wave32 LDS alias/hazard proof analysis (crates/victory-shader/src/emit/lds.rs) onto fxceless/victory-fork main, unlocking native Wave32 execution on NVIDIA/32-wide GPUs for compute shaders whose LDS (ds_*) operations live inside control flow or use disjoint/lane-private addressing, while preserving wave64 fallback whenever safety cannot be statically proven.

Key Details & Soundness Guarantees

  • Refinement A (Disjoint constant byte ranges): Verifies shared group-uniform bases with disjoint byte footprints within non-wrapping MAX_OFFSET = 1 MiB 32-bit bounds (<4-byte unaligned vs >=4-byte dword collision guard, zero RMWs, acyclic !all regions, symmetric RAW/WAR/WAW).
  • Refinement B (Injective per-lane private slots): Proves lane-private slots are injective across active workgroup dimensions and paired v_mbcnt console_lane (group <= 64), aligned, sub-array split, non-wrapping, and cross-cluster disjoint.
  • Safety checks:
    • Primary 1-dword dst verification (is_primary_sop_dst/is_primary_valu_dst) prevents VOP3B v.carry / Reg::Scc misidentification as group-uniform values.
    • Tightened SGPR uniformity (c < cs.user_sgprs() + Input::GroupId, refusing scratch_wave_offset and uninitialized SGPRs).
    • Refuses refinement when !all regions contain s_barrier or non-inline special SOP constants (c != 253).
    • Existing Wave32/Wave64 lowering and wave64_tests preserved intact.

Verification (86e93bb1c)

  • Clean git merge-tree --write-tree origin/main HEAD against latest main (c36971b2).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: exit 0, 0 warnings.
  • VICTORY_REQUIRE_HW_GPU=1 cargo test -p victory-shader --lib emit::wave64_tests::lds_ -- --nocapture: 4 passed; 0 failed on hardware D3D12 (no skip).
  • cargo test -p victory-shader --all-targets: 233 passed; 0 failed; 3 ignored (14/14 emit::lds::tests::*).

Co-Authored-By: AI Assistant

**@⁠Vladimir-Human** on GitHub · 2026-11-25 21:26 UTC · [original](https://github.com/fxceless/victory-fork/pull/1140) `Vladimir-Human:shader/wave32-lds-disjoint` → `main` · +3490 −142 · 4 files · 3 commits · open ## Summary AI-assisted port of static Wave32 LDS alias/hazard proof analysis (`crates/victory-shader/src/emit/lds.rs`) onto `fxceless/victory-fork` `main`, unlocking native Wave32 execution on NVIDIA/32-wide GPUs for compute shaders whose LDS (`ds_*`) operations live inside control flow or use disjoint/lane-private addressing, while preserving `wave64` fallback whenever safety cannot be statically proven. ### Key Details & Soundness Guarantees - **Refinement A (Disjoint constant byte ranges)**: Verifies shared group-uniform bases with disjoint byte footprints within non-wrapping `MAX_OFFSET = 1 MiB` 32-bit bounds (`<4`-byte unaligned vs `>=4`-byte dword collision guard, zero RMWs, acyclic `!all` regions, symmetric RAW/WAR/WAW). - **Refinement B (Injective per-lane private slots)**: Proves lane-private slots are injective across active workgroup dimensions and paired `v_mbcnt` `console_lane` (`group <= 64`), aligned, sub-array split, non-wrapping, and cross-cluster disjoint. - **Safety checks**: - Primary 1-dword `dst` verification (`is_primary_sop_dst`/`is_primary_valu_dst`) prevents VOP3B `v.carry` / `Reg::Scc` misidentification as group-uniform values. - Tightened SGPR uniformity (`c < cs.user_sgprs()` + `Input::GroupId`, refusing `scratch_wave_offset` and uninitialized SGPRs). - Refuses refinement when `!all` regions contain `s_barrier` or non-inline special SOP constants (`c != 253`). - Existing Wave32/Wave64 lowering and `wave64_tests` preserved intact. ### Verification (`86e93bb1c`) - Clean `git merge-tree --write-tree origin/main HEAD` against latest `main` (`c36971b2`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: exit 0, 0 warnings. - `VICTORY_REQUIRE_HW_GPU=1 cargo test -p victory-shader --lib emit::wave64_tests::lds_ -- --nocapture`: **4 passed; 0 failed** on hardware D3D12 (no skip). - `cargo test -p victory-shader --all-targets`: **233 passed; 0 failed; 3 ignored** (14/14 `emit::lds::tests::*`). Co-Authored-By: AI Assistant
Port static Wave32 LDS alias and hazard analysis for !all lane-branch
regions in console WaveSize(64) compute shaders lowered to 32-lane waves:

- Add crates/victory-shader/src/emit/lds.rs implementing Refinement A
  (disjoint constant byte ranges on a shared group-uniform base with
  non-wrapping 32-bit bounds, zero RMWs, acyclic regions, and symmetric
  RAW/WAR/WAW checks) and Refinement B (injective lane-private per-thread
  slots across all active workgroup dimensions with alignment,
  non-wrapping footprints, and cross-cluster disjointness).
- Tighten input SGPR uniformity to user SGPRs (< cs.user_sgprs()) plus
  GroupId so per-wave scratch_wave_offset SGPRs are never treated as
  group-uniform.
- Hook emit/lower.rs lds_meetings to super::lds::meetings (and register
  mod lds in emit/mod.rs) while preserving all existing Wave32 lowering
  improvements; build.rs hashes src/**/*.rs automatically so lib.rs stays
  unchanged.
- Add hardware D3D12 Wave32 execution tests and negative shared-atomic
  Wave64 refusal test to emit/wave64_tests.rs.
Address two soundness issues in emit/lds.rs:
- Verify the SSA value being evaluated is written to the primary 32-bit
  destination (valu.dst Reg::V for VALU, scalar dst Reg::S for SOP) in
  eval_inst, uniform_result_tz, and is_group_uniform_val (VALU), preventing
  VOP3B carry-out lane masks (v_add_co_u32 / v_sub_co_u32 / v_subrev_co_u32)
  from being confused with arithmetic results or treated as group-uniform.
- Refuse (!all -> None) whenever any !all block contains s_barrier so a
  divergent barrier is never lowered across two 32-lane host waves.
- Add regression tests covering VOP3B carry Refinement A/B bypasses,
  non-64-multiple [96, 1, 1] carry ballot uniformity, positive primary-dst
  control, and divergent s_barrier refusal under both Refinements A and B.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:17 +00:00
Author
Owner

@⁠GDKAYKY on GitHub · 2026-11-25 21:28 UTC · original

does this have improvement on frametime,fps or VRAM usage?

**@⁠GDKAYKY** on GitHub · 2026-11-25 21:28 UTC · [original](https://github.com/fxceless/victory-fork/pull/1140#issuecomment-7175130859) does this have improvement on frametime,fps or VRAM usage?
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 23:10 UTC · original

@⁠GDKAYKY Target and effect summary:

  • Target hardware: Wave32-only GPUs (such as NVIDIA) running console Wave64 compute shaders whose LDS (ds_*) operations sit inside control flow or per-lane offsets.
  • Frametime / FPS: Removes the Wave64 two-wave software emulation path (extra LDS ballot/shuffle traffic and doubled workgroup barriers) whenever static alias/injectivity analysis (emit/lds.rs) proves native Wave32 execution produces identical results. The exact full-frame FPS delta depends on how many active compute shaders in a given scene hit that Wave64 LDS fallback path, and hasn't been measured in a live title run yet.
  • VRAM: Neutral (no persistent GPU buffer or heap allocation changes; slightly lower register/groupshared pressure on qualifying compute shaders).
**@⁠Vladimir-Human** on GitHub · 2026-11-25 23:10 UTC · [original](https://github.com/fxceless/victory-fork/pull/1140#issuecomment-7177221082) @⁠GDKAYKY Target and effect summary: - **Target hardware**: Wave32-only GPUs (such as NVIDIA) running console Wave64 compute shaders whose LDS (`ds_*`) operations sit inside control flow or per-lane offsets. - **Frametime / FPS**: Removes the Wave64 two-wave software emulation path (extra LDS ballot/shuffle traffic and doubled workgroup barriers) whenever static alias/injectivity analysis (`emit/lds.rs`) proves native Wave32 execution produces identical results. The exact full-frame FPS delta depends on how many active compute shaders in a given scene hit that Wave64 LDS fallback path, and hasn't been measured in a live title run yet. - **VRAM**: Neutral (no persistent GPU buffer or heap allocation changes; slightly lower register/groupshared pressure on qualifying compute shaders).
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-26 09:29 UTC · original

RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2, 86e93bb on main 32b31f7 + #402 (Agility, WARP skips here).

  • With the PR: victory-shader 234 passed, 0 failed; the 18 new tests pass, including the three *_execute_wave32_on_hardware runs on the card.
  • PR tests on the base without the fix: 4 fail, all at the wave-size checks before execution (lds_*_execute_wave32_on_hardware get 64 instead of 32, lds_shared_returning_atomic_stays_wave64 gets 32 instead of 64).

AI-assisted (Claude Code): tests run on my machine, text drafted with Claude.

**@⁠HAL9000RELOADED** on GitHub · 2026-11-26 09:29 UTC · [original](https://github.com/fxceless/victory-fork/pull/1140#issuecomment-7188061492) RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2, `86e93bb` on main `32b31f7` + #402 (Agility, WARP skips here). - With the PR: `victory-shader` 234 passed, 0 failed; the 18 new tests pass, including the three `*_execute_wave32_on_hardware` runs on the card. - PR tests on the base without the fix: 4 fail, all at the wave-size checks before execution (`lds_*_execute_wave32_on_hardware` get 64 instead of 32, `lds_shared_returning_atomic_stays_wave64` gets 32 instead of 64). _AI-assisted (Claude Code): tests run on my machine, text drafted with Claude._
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 09:46 UTC · original

Pushed follow-up commit d12852c incorporating live 32-lane NVIDIA review findings and diagnostic improvements:

  1. 32-lane opt-in VICTORY_LDS_WRITE_ONLY_OK=1 + has_plain_read (emit/lds.rs):

    • Tracks has_plain_read strictly on Kind::Read (ds_read*), distinct from Kind::Rmw (LDS atomics).
    • Strictly gated on host_max_wave() == 32 and VICTORY_LDS_WRITE_ONLY_OK=1 (off by default, always disabled on 64-lane hosts). When enabled on 32-lane hosts, !all write-only regions and !all LDS atomic regions with no plain ds_read* are accepted for native Wave32, while divergent s_barrier, unhandled DS instructions, and mixed regions with an explicit plain ds_read* remain refused.
  2. Specific VICTORY_WAVE_WHY=1 refusal diagnostics (emit/lds.rs, emit/lower.rs):

    • Added typed lds::Refusal variants via lds::analyze(...) so VICTORY_WAVE_WHY=1 accurately distinguishes overlapping plain writes, atomics with no plain LDS read, mixed regions with an explicit plain ds_read*, divergent barriers, unhandled DS ops, and cyclic shared writes.
  3. Note on @⁠GDKAYKY's question (frame pacing / NVIDIA skinning shaders):

    • On Wave32-only GPUs (NVIDIA), any compute shader that falls back to WaveSize(64) is rejected by D3D12 CreateComputePipelineState (E_INVALIDARG), which drops those dispatches (including skinning compute passes) or forces slower fallback paths. Proving more branched-LDS compute shaders safe for native Wave32 keeps those pipelines compiling and executing cleanly on 32-lane hardware without Wave64 software emulation overhead, directly helping frame pacing and rendering completeness on NVIDIA.
  4. Verification:

    • Added unit tests covering shared atomics with/without plain ds_read*, 32-lane vs 64-lane host gating, the 4-kernel lowering matrix (same-dword write-only, separate writes, overlapping read+write, disjoint read + writes), negative s_barrier/ds_nop checks, and VICTORY_WAVE_WHY reason strings.
    • cargo test -p victory-shader -- --test-threads=4: 235 passed; 0 failed; 3 ignored (including the 3 hardware D3D12 Wave32 LDS execution tests).
    • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
**@⁠Vladimir-Human** on GitHub · 2026-11-26 09:46 UTC · [original](https://github.com/fxceless/victory-fork/pull/1140#issuecomment-7188463505) Pushed follow-up commit `d12852c` incorporating live 32-lane NVIDIA review findings and diagnostic improvements: 1. **32-lane opt-in `VICTORY_LDS_WRITE_ONLY_OK=1` + `has_plain_read` (`emit/lds.rs`):** - Tracks `has_plain_read` strictly on `Kind::Read` (`ds_read*`), distinct from `Kind::Rmw` (LDS atomics). - Strictly gated on `host_max_wave() == 32` **and** `VICTORY_LDS_WRITE_ONLY_OK=1` (off by default, always disabled on 64-lane hosts). When enabled on 32-lane hosts, `!all` write-only regions and `!all` LDS atomic regions with no plain `ds_read*` are accepted for native Wave32, while divergent `s_barrier`, unhandled DS instructions, and mixed regions with an explicit plain `ds_read*` remain refused. 2. **Specific `VICTORY_WAVE_WHY=1` refusal diagnostics (`emit/lds.rs`, `emit/lower.rs`):** - Added typed `lds::Refusal` variants via `lds::analyze(...)` so `VICTORY_WAVE_WHY=1` accurately distinguishes overlapping plain writes, atomics with no plain LDS read, mixed regions with an explicit plain `ds_read*`, divergent barriers, unhandled DS ops, and cyclic shared writes. 3. **Note on @⁠GDKAYKY's question (frame pacing / NVIDIA skinning shaders):** - On Wave32-only GPUs (NVIDIA), any compute shader that falls back to `WaveSize(64)` is rejected by D3D12 `CreateComputePipelineState` (`E_INVALIDARG`), which drops those dispatches (including skinning compute passes) or forces slower fallback paths. Proving more branched-LDS compute shaders safe for native Wave32 keeps those pipelines compiling and executing cleanly on 32-lane hardware without Wave64 software emulation overhead, directly helping frame pacing and rendering completeness on NVIDIA. 4. **Verification:** - Added unit tests covering shared atomics with/without plain `ds_read*`, 32-lane vs 64-lane host gating, the 4-kernel lowering matrix (same-dword write-only, separate writes, overlapping read+write, disjoint read + writes), negative `s_barrier`/`ds_nop` checks, and `VICTORY_WAVE_WHY` reason strings. - `cargo test -p victory-shader -- --test-threads=4`: **235 passed; 0 failed; 3 ignored** (including the 3 hardware D3D12 Wave32 LDS execution tests). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: **0 warnings**.
github-bot force-pushed github-bot/gh-1140 from d12852c206 to c629faf815 2026-11-26 16:58:38 +00:00 Compare
Author
Owner

@⁠Dathinel on GitHub · 2026-11-26 20:16 UTC · original · edited 2026-11-26 20:17 UTC

At c629faf, the CPU-side LDS analysis accepts a cross-lane byte alias in a partial workgroup. I compiled the PR's region_lane_private, injective_lane_disp and ranges_may_overlap functions in isolation with Rust and supplied two synthetic Access records. No GPU or game input is needed.

Use threads = [n, 1, 1], no uniforms, uniform_tz = 32, console_lane = 0. The write has width 1, tid = [1,0,0], off = 0. The read has width 1, tid = [0,0,0], off = n-1. Thread n-1 writes the byte that every thread reads. The two accesses therefore cannot be proven lane-private.

n region_lane_private
32 false
33 true
63 true
64 false

For n=33 the aggregate write footprint is [0,33). The cross-cluster check passes 33 as an instruction width to ranges_may_overlap, which rounds the upper bound down to 32 on the aligned path. The final byte disappears. Compare the already-computed half-open footprint bounds directly at this call site, retaining the existing alignment guard, and add the 33-thread case as a regression. This reproduces the analyzer decision only. AI-assisted review.

CPU check of the proposed change: I compiled both versions of region_lane_private and enumerated byte writes at initial + stride * tid.x and a uniform byte read at offset r. Parameters were n=32..65 inclusive, stride in {1,2,4}, initial=0..3, and r=0..n*stride+4 inclusive. The oracle enumerated all n write addresses and checked whether any equaled r. Every thread reads r, so a match is cross-thread sharing.

Across 48,212 inputs the original accepted 442 sharing cases as private. Replacing only the cross-cluster ranges_may_overlap call with (a.min_lo < b.max_hi && b.min_lo < a.max_hi) reduced that count to zero. Conservative rejections of genuinely disjoint cases changed from 26,282 to 25,840, including 170 safe cases newly rejected. Bounding intervals can include holes between strided writes. These results cover byte accesses in this family only.

**@⁠Dathinel** on GitHub · 2026-11-26 20:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/1140#issuecomment-7202476824) · edited 2026-11-26 20:17 UTC At c629faf, the CPU-side LDS analysis accepts a cross-lane byte alias in a partial workgroup. I compiled the PR's region_lane_private, injective_lane_disp and ranges_may_overlap functions in isolation with Rust and supplied two synthetic Access records. No GPU or game input is needed. Use threads = [n, 1, 1], no uniforms, uniform_tz = 32, console_lane = 0. The write has width 1, tid = [1,0,0], off = 0. The read has width 1, tid = [0,0,0], off = n-1. Thread n-1 writes the byte that every thread reads. The two accesses therefore cannot be proven lane-private. | n | region_lane_private | |---|---| | 32 | false | | 33 | true | | 63 | true | | 64 | false | For n=33 the aggregate write footprint is [0,33). The cross-cluster check passes 33 as an instruction width to ranges_may_overlap, which rounds the upper bound down to 32 on the aligned path. The final byte disappears. Compare the already-computed half-open footprint bounds directly at this call site, retaining the existing alignment guard, and add the 33-thread case as a regression. This reproduces the analyzer decision only. AI-assisted review. CPU check of the proposed change: I compiled both versions of region_lane_private and enumerated byte writes at initial + stride * tid.x and a uniform byte read at offset r. Parameters were n=32..65 inclusive, stride in {1,2,4}, initial=0..3, and r=0..n*stride+4 inclusive. The oracle enumerated all n write addresses and checked whether any equaled r. Every thread reads r, so a match is cross-thread sharing. Across 48,212 inputs the original accepted 442 sharing cases as private. Replacing only the cross-cluster ranges_may_overlap call with (a.min_lo < b.max_hi && b.min_lo < a.max_hi) reduced that count to zero. Conservative rejections of genuinely disjoint cases changed from 26,282 to 25,840, including 170 safe cases newly rejected. Bounding intervals can include holes between strided writes. These results cover byte accesses in this family only.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/1140/head:github-bot/gh-1140'
git switch 'github-bot/gh-1140'

Merge

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