Shaders: wave64 LDS regions that need no order between the halves (VICTORY_LDS_EXACT=1, off by default) #733

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

@⁠OtavMacedo on GitHub · 2026-11-28 04:38 UTC · original
OtavMacedo:vn/wave64-lds-exact → main · +1294 −103 · 6 files · 3 commits · open

What and why

On a host whose waves have 32 lanes (NVIDIA), a console wave64 compute program runs as two host waves per console wave. When the group holds several console waves and has LDS, the two halves only meet (group barrier) on the edges of each lane-branch region. A region that both reads and writes LDS is refused ("an LDS read and write in one lane-branch region"), and the program stays at 64 lanes, which the host refuses.

One such program is 6b82bc7d22016cb5: groups of 1,024 threads, all 32 KiB of LDS. No current form takes it. It fails on three things:

  • LDS read and written inside lane-branch regions;
  • a wave reservation done with ds_add_rtn_u32 on an LDS counter, which the allocation idiom of with_local_waves does not recognise (it only knows buffer_atomic_*);
  • one LDS dword too many: the wave_base counter would put it past D3D12's 32 KiB.

Two kinds of region need no order between the halves, and the new emit::lds_exact module proves them:

  • One thread runs the region. Every way in is an edge of a branch on v_cmp_eq(thread id, k) in a 1-D group, or comes from a block that thread alone runs. Loop masks joined by a phi are followed.
  • Its reads cannot see its writes. The byte range of each LDS access is bounded from how its address is made (constant, masked/shifted value, plus offsets). Read and written ranges do not meet, and atomics that meet are the same operation. An atomic that returns the old value is allowed only in the allocation idiom's local waves.

Also:

  • wave_local takes an LDS atomic (ds_add_u32 and the others, with or without _rtn) as the first lane's reservation, in those forms only.
  • A 1-D group whose LDS fills all 8,192 dwords takes its console threads from the flat id, so it needs no counter dword. As local waves it gets no exchange dwords, which are never touched there.
  • In those forms, a program past 32 KiB is refused instead of being emitted.

Off by default. Even with VICTORY_LDS_EXACT=1, these forms are tried after every other form, so a program that translates today keeps its form. With VICTORY_WAVE_WHY=1, a WAVE64-LDS-REGION line gives each refused region's code offsets and the reason.

Files

  • crates/victory-shader/src/emit/lds_exact.rs (new): the region proofs. It also takes over the meeting analysis, which was lower.rs's lds_meetings. It still leaves out the accesses that LdsOrder finds unordered, and pair meetings are unchanged. Moving it also rejoins its doc comment, which an earlier insertion had split around LdsOrder.
  • crates/victory-shader/src/emit/lower.rs: the idiom's LDS reservation, NO_COUNTER for a full 32 KiB, and the 32 KiB refusal in the last forms.
  • crates/victory-shader/src/emit/mod.rs: the last forms in emit, each whole and as local waves (idiom). Also emit::lds_exact().
  • crates/victory-gpu/src/shader_cache.rs: the cache key includes the switch while it is on, the same way as VICTORY_EARLY_DEPTH.
  • crates/victory-shader/src/emit/lds_exact_tests.rs (new), plus whole_uav in wave64_tests.rs: hand-written 128-thread fixtures with no game data.

Results (offline, translate --list --jobs 1, VICTORY_HOST_WAVE=32)

program before after, switch off after, VICTORY_LDS_EXACT=1
6b82bc7d22016cb5 (1,024 threads, 32 KiB LDS) no wave32 lowering no wave32 lowering (unchanged) emitted, wave 32 ("exact LDS regions, local waves (idiom), without early-outs")
02384a60fda6f2d0 (128 threads) no wave32 lowering unchanged unchanged (an LDS access whose reach is not known)

The emitted DXIL was not checked by dxil.dll here (no validator in this environment), and no pipeline was created.

Tests

  • Native cargo test -p victory-shader -p xtask: 213 + 6 pass.
  • Windows test build (cargo-xwin) run under Wine: the 6 lds_exact tests pass. They did not run on a GPU because no SM 6.6 device was available there.
  • cargo clippy --workspace --all-targets (with and without --all-features, Windows target): no warnings in the changed files. Warnings elsewhere were already on main.
  • Asset policy: ok.

Validated on hardware (RTX 3070 8 GB, driver 32.0.16.2124, Windows 11). The same change, in VItoria Spark's tree (its PR #71), was run on that PC:

  • Offline reproduction of the saved programs with the driver's compiler: with VICTORY_LDS_EXACT=1, 6b82bc7d22016cb5 gets a pipeline ("pipeline created"). With it plus VICTORY_WAVE_PAIR=1 and 02384a60fda6f2d0 in VICTORY_WAVE_WIDE_ONLY, both programs that the card used to refuse are made.
  • In the game: six runs of 5 to 15 minutes at 1440p with those switches, 0 pipelines refused in all six (before: 1 to 2 refused per run), no crash, no device loss, and no new warnings.
  • This VIctory-NVIDIA branch itself was checked offline only (victory translate and the tests below). It is a hand port of the same code, so a run here with and without the switch is still worth doing.

What to watch in the game. Run with VICTORY_LDS_EXACT=1 on an NVIDIA card. The program above should get a pipeline instead of being dropped. Look for wrong or missing geometry where its output is used, and compare against a run with the switch off.

Credits. Port of the mandy project's commit 1855daf98 by NotRexed (and its tests, a7557be81), by way of VItoria Spark PR #71, adapted by hand to VIctory-NVIDIA's lowering.

🤖 Generated with Claude Code

**@⁠OtavMacedo** on GitHub · 2026-11-28 04:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/733) `OtavMacedo:vn/wave64-lds-exact` → `main` · +1294 −103 · 6 files · 3 commits · open **What and why** On a host whose waves have 32 lanes (NVIDIA), a console wave64 compute program runs as two host waves per console wave. When the group holds several console waves and has LDS, the two halves only meet (group barrier) on the edges of each lane-branch region. A region that both reads and writes LDS is refused ("an LDS read and write in one lane-branch region"), and the program stays at 64 lanes, which the host refuses. One such program is `6b82bc7d22016cb5`: groups of 1,024 threads, all 32 KiB of LDS. No current form takes it. It fails on three things: - LDS read and written inside lane-branch regions; - a wave reservation done with `ds_add_rtn_u32` on an LDS counter, which the allocation idiom of `with_local_waves` does not recognise (it only knows `buffer_atomic_*`); - one LDS dword too many: the `wave_base` counter would put it past D3D12's 32 KiB. Two kinds of region need no order between the halves, and the new `emit::lds_exact` module proves them: - **One thread runs the region.** Every way in is an edge of a branch on `v_cmp_eq(thread id, k)` in a 1-D group, or comes from a block that thread alone runs. Loop masks joined by a phi are followed. - **Its reads cannot see its writes.** The byte range of each LDS access is bounded from how its address is made (constant, masked/shifted value, plus offsets). Read and written ranges do not meet, and atomics that meet are the same operation. An atomic that returns the old value is allowed only in the allocation idiom's local waves. Also: - `wave_local` takes an LDS atomic (`ds_add_u32` and the others, with or without `_rtn`) as the first lane's reservation, in those forms only. - A 1-D group whose LDS fills all 8,192 dwords takes its console threads from the flat id, so it needs no counter dword. As local waves it gets no exchange dwords, which are never touched there. - In those forms, a program past 32 KiB is refused instead of being emitted. **Off by default.** Even with `VICTORY_LDS_EXACT=1`, these forms are tried after every other form, so a program that translates today keeps its form. With `VICTORY_WAVE_WHY=1`, a `WAVE64-LDS-REGION` line gives each refused region's code offsets and the reason. **Files** - `crates/victory-shader/src/emit/lds_exact.rs` (new): the region proofs. It also takes over the meeting analysis, which was `lower.rs`'s `lds_meetings`. It still leaves out the accesses that `LdsOrder` finds unordered, and pair meetings are unchanged. Moving it also rejoins its doc comment, which an earlier insertion had split around `LdsOrder`. - `crates/victory-shader/src/emit/lower.rs`: the idiom's LDS reservation, `NO_COUNTER` for a full 32 KiB, and the 32 KiB refusal in the last forms. - `crates/victory-shader/src/emit/mod.rs`: the last forms in `emit`, each whole and as local waves (idiom). Also `emit::lds_exact()`. - `crates/victory-gpu/src/shader_cache.rs`: the cache key includes the switch while it is on, the same way as `VICTORY_EARLY_DEPTH`. - `crates/victory-shader/src/emit/lds_exact_tests.rs` (new), plus `whole_uav` in `wave64_tests.rs`: hand-written 128-thread fixtures with no game data. **Results (offline, `translate --list --jobs 1`, `VICTORY_HOST_WAVE=32`)** | program | before | after, switch off | after, `VICTORY_LDS_EXACT=1` | |---|---|---|---| | `6b82bc7d22016cb5` (1,024 threads, 32 KiB LDS) | no wave32 lowering | no wave32 lowering (unchanged) | **emitted, wave 32** ("exact LDS regions, local waves (idiom), without early-outs") | | `02384a60fda6f2d0` (128 threads) | no wave32 lowering | unchanged | unchanged (an LDS access whose reach is not known) | The emitted DXIL was not checked by `dxil.dll` here (no validator in this environment), and no pipeline was created. **Tests** - Native `cargo test -p victory-shader -p xtask`: 213 + 6 pass. - Windows test build (cargo-xwin) run under Wine: the 6 `lds_exact` tests pass. They did not run on a GPU because no SM 6.6 device was available there. - `cargo clippy --workspace --all-targets` (with and without `--all-features`, Windows target): no warnings in the changed files. Warnings elsewhere were already on `main`. - Asset policy: ok. **Validated on hardware (RTX 3070 8 GB, driver 32.0.16.2124, Windows 11).** The same change, in VItoria Spark's tree (its PR #71), was run on that PC: - Offline reproduction of the saved programs with the driver's compiler: with `VICTORY_LDS_EXACT=1`, `6b82bc7d22016cb5` gets a pipeline ("pipeline created"). With it plus `VICTORY_WAVE_PAIR=1` and `02384a60fda6f2d0` in `VICTORY_WAVE_WIDE_ONLY`, both programs that the card used to refuse are made. - In the game: six runs of 5 to 15 minutes at 1440p with those switches, **0 pipelines refused** in all six (before: 1 to 2 refused per run), no crash, no device loss, and no new warnings. - This VIctory-NVIDIA branch itself was checked offline only (`victory translate` and the tests below). It is a hand port of the same code, so a run here with and without the switch is still worth doing. **What to watch in the game.** Run with `VICTORY_LDS_EXACT=1` on an NVIDIA card. The program above should get a pipeline instead of being dropped. Look for wrong or missing geometry where its output is used, and compare against a run with the switch off. **Credits.** Port of the mandy project's commit 1855daf98 by NotRexed (and its tests, a7557be81), by way of VItoria Spark PR #71, adapted by hand to VIctory-NVIDIA's lowering. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A console wave64 compute program of several console waves with LDS read and
written inside one lane-branch region stays at 64 lanes, which a host of
32-lane waves refuses: its two host waves meet only on the edges of such a
region, so a read inside it may miss the other half's write. Two kinds of
region need no order between the halves, and emit::lds_exact proves them:

- one thread runs it: every way in is the edge of a branch on
  v_cmp_eq(thread id, k) in a group of one dimension, or from a block that
  thread alone runs (loop masks joined by a phi are followed);
- its reads cannot see its writes: byte ranges bounded from how each address
  is made do not meet, atomics that meet are the same operation, and one that
  returns the old value only in the allocation idiom's local waves.

wave_local also takes an LDS atomic (ds_add_u32 and the others, with or
without _rtn) as the first lane's reservation in those forms. A group of one
dimension whose LDS fills all 8,192 dwords takes its console threads from the
flat id (no counter dword) and, as local waves, gets no exchange dwords (never
touched there); the last forms refuse a program past D3D12's 32 KiB.

The meeting analysis (lower.rs's lds_meetings) moves into the module as
lds_exact::meetings, still leaving out the accesses LdsOrder finds unordered;
the pair meetings are as they were.

Off unless VICTORY_LDS_EXACT=1, and tried after every other form even then,
so a program that translates without it keeps its form. WAVE64-LDS-REGION
lines of VICTORY_WAVE_WHY give each refused region's code offsets and reason.

Offline (translate, host waves of 32): a 1,024-thread compute program with
all 32 KiB of LDS that no form took is emitted in waves of 32 with the switch
(exact regions, local waves of the idiom); without it nothing changes.

Port of the mandy project's commit 1855daf98, by way of VItoria Spark
PR #71, adapted by hand to this lowering.
Hand-written 128-thread fixtures (two console waves, no game data): thread
0's three read-modify-writes of an LDS dword; the same by threads 0 and 1,
which the module refuses; the odd threads' allocation of slots through
ds_add_rtn_u32 on an LDS counter (the wave's first lane reserves the count,
the lanes take base plus rank), alone, with all of D3D12's 32 KiB of LDS, and
in a loop of 2 or 4 rounds the lanes leave one by one. Each region also sets a
scalar the code after it reads, so no other form flattens it: with the switch
off emit refuses them (64-lane waves only), with it on they take 32 and the
full one declares no dword past 8,192. On Windows the DXIL is validated and
run on the card when it takes waves of 32 (every slot once, 8 runs). Plus the
region classifiers and the idiom on the IR.

Port of the mandy project's commit a7557be81, by way of VItoria Spark
PR #71.
The switch picks the form of a wave64 program, so a run with it must not be
served what a run without it cached, nor the other way round. Only while it
is on, as VICTORY_EARLY_DEPTH, so that the translations cached without it are
still served without it (emit::lds_exact).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 04:44:32 +00:00
Author
Owner

@⁠OtavMacedo on GitHub · 2026-11-28 04:38 UTC · original

Heads-up on CI: the Clippy step is already red on main (63b902fe) from older code: let_and_return in a test helper near the end of emit/mod.rs and manual_is_multiple_of in victory-gpu/src/shadow.rs. If this PR shows the same failure, that is where it comes from; the changed code adds no new clippy warnings (checked with and without --all-features, Windows target).

**@⁠OtavMacedo** on GitHub · 2026-11-28 04:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/733#issuecomment-7234171485) Heads-up on CI: the Clippy step is already red on `main` (63b902fe) from older code: `let_and_return` in a test helper near the end of `emit/mod.rs` and `manual_is_multiple_of` in `victory-gpu/src/shadow.rs`. If this PR shows the same failure, that is where it comes from; the changed code adds no new clippy warnings (checked with and without `--all-features`, Windows target).
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-28 04:45 UTC · original · approved these changes

LGTM — verified on Windows (RTX 5090):

  • cargo test -p victory-shader --lib lds_exact -- --nocapture passed (6/6, including all 4 hardware execution tests on RTX 5090)
  • cargo test -p victory-gpu --lib shader_cache:: passed (2/2)
  • 0 new compiler warnings in touched files
  • cargo xtask policy passed (296 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-28 04:45 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/733#pullrequestreview-6095865024) · **approved these changes** LGTM — verified on Windows (RTX 5090): - `cargo test -p victory-shader --lib lds_exact -- --nocapture` passed (6/6, including all 4 hardware execution tests on RTX 5090) - `cargo test -p victory-gpu --lib shader_cache::` passed (2/2) - 0 new compiler warnings in touched files - `cargo xtask policy` passed (`296 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Aniseto on GitHub · 2026-11-28 07:08 UTC · original

Ran the exact-LDS-region tests at e0a4f4d on an NVIDIA Blackwell desktop part:

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

. D:\VICTORY-NVIDIA-OPS\env-victory-nvidia.ps1
$env:VICTORY_D3D12_ADAPTER = 'NVIDIA'
cargo test -p victory-shader --lib lds_exact_tests -- --test-threads=1
6 passed; 0 failed; 0 ignored; 0 measured; 298 filtered out      (exit 0)

All six tests pass on a host with no 64-lane waves. They cover the region proof, the LDS-atomic allocation idiom, a single thread reading/writing its own LDS, the 32 KiB limit and the loop-allocation case. The thread's only new comment is about CI Clippy on main, not a hardware run. I did not run the title's 6b82bc7d22016cb5 program or enable VICTORY_LDS_EXACT=1 in a real session.

Not tested: the title's shaders, a paired smoke run, the full workspace suite, release profile, AMD and Intel GPUs, native wave64 hosts, Wine, 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-28 07:08 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/733#issuecomment-7235739345) Ran the exact-LDS-region tests at `e0a4f4d` on an NVIDIA Blackwell desktop part: Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build. ``` . D:\VICTORY-NVIDIA-OPS\env-victory-nvidia.ps1 $env:VICTORY_D3D12_ADAPTER = 'NVIDIA' cargo test -p victory-shader --lib lds_exact_tests -- --test-threads=1 6 passed; 0 failed; 0 ignored; 0 measured; 298 filtered out (exit 0) ``` All six tests pass on a host with no 64-lane waves. They cover the region proof, the LDS-atomic allocation idiom, a single thread reading/writing its own LDS, the 32 KiB limit and the loop-allocation case. The thread's only new comment is about CI Clippy on `main`, not a hardware run. I did not run the title's `6b82bc7d22016cb5` program or enable `VICTORY_LDS_EXACT=1` in a real session. Not tested: the title's shaders, a paired smoke run, the full workspace suite, release profile, AMD and Intel GPUs, native wave64 hosts, Wine, 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 has changes conflicting with the target branch.
  • crates/victory-gpu/src/shader_cache.rs
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/mod.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-733'
git switch 'github-bot/gh-733'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-733'
git switch 'github-bot/gh-733'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-733'
git switch 'main'
git merge --squash 'github-bot/gh-733'
git switch 'main'
git merge --ff-only 'github-bot/gh-733'
git switch 'main'
git merge 'github-bot/gh-733'
git push origin 'main'
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!733
No description provided.