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

Open
OtavMacedo wants to merge 3 commits from upstream-pr/733 into main
OtavMacedo commented 2026-11-28 04:38:45 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by OtavMacedo on 2026-11-28T04:38:45Z.


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5536716779 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/733). Originally posted by [OtavMacedo](https://github.com/OtavMacedo) on 2026-11-28T04:38:45Z. --- **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)
OtavMacedo commented 2026-11-28 04:38:54 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by OtavMacedo on 2026-11-28T04:38:54Z.


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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7234171485 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/733#issuecomment-7234171485). Originally posted by [OtavMacedo](https://github.com/OtavMacedo) on 2026-11-28T04:38:54Z. --- 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).
Dukestar69 commented 2026-11-28 04:45:46 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T04:45:46Z.

Review: APPROVED


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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6095865024 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/733#pullrequestreview-6095865024). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-28T04:45:46Z. **Review:** APPROVED --- 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).
Aniseto commented 2026-11-28 07:08:13 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Aniseto on 2026-11-28T07:08:13Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7235739345 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/733#issuecomment-7235739345). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-28T07:08:13Z. --- 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 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/733:upstream-pr/733'
git switch 'upstream-pr/733'

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/733'
git switch 'upstream-pr/733'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/733'
git switch 'upstream-pr/733'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/733'
git switch 'main'
git merge --squash 'upstream-pr/733'
git switch 'main'
git merge --ff-only 'upstream-pr/733'
git switch 'main'
git merge 'upstream-pr/733'
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
trustno1-coder/VIctory-NVIDIA!733
No description provided.