shader: accept purely commutative non-returning 32-bit integer LDS atomics in Wave32 regions #2358

Open
nidea1 wants to merge 1 commit from upstream-pr/2358 into main
nidea1 commented 2026-11-29 12:21:22 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-11-29T12:21:22Z.


What it changes

Adds Refinement C to the static LDS hazard analysis in crates/victory-shader/src/emit/lds.rs (region_commutative_atomics):

  • Accepts !all (lane-branch) LDS regions where every LDS access is a non-returning, commutative and associative 32-bit integer atomic (ds_add_u32, ds_sub_u32, ds_and_b32, ds_or_b32, ds_xor_b32, ds_min_i32, ds_max_i32, ds_min_u32, ds_max_u32), with zero plain reads, zero plain writes, and zero returning (_rtn) or order-sensitive atomics (ds_inc_u32, ds_cmpst_*, ds_add_f32, etc.).
  • When a region mixes multiple distinct algebraic families (e.g., ds_add_u32 and ds_or_b32), requires provably disjoint constant byte offsets on a shared group-uniform base; same-offset mixes are refused.
  • Because lds::analyze inserts host-wave meet barriers around !all region entries and exits and 32-bit LDS atomics operate on single aligned dwords (addr >> 2), any Wave32 interleaving produces the exact same final LDS bits as Wave64 — complementing LdsOrder::looped for acyclic !all branches and for loops preceded by all-block writes without an explicit s_barrier.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 3060 Ti 8 GB, Series S profile, 1440p, FSR 3 2x FG, RT off (plus direct RTX 3060 Ti compute dispatch readback in commutative_atomic_reduction_runs_on_wave32_gpu)
  • Before: !all regions with non-returning commutative integer atomics (e.g., if (tid.x < N) { ds_add_u32(LDS[0], ...); }) failed lds::analyze with Refusal::AtomicWithoutPlainRead and fell back to Wave64 (or required VICTORY_LDS_WRITE_ONLY_OK=1)
  • After: such regions lower soundly to Wave32 by default with entry/exit host-wave barriers; non-commutative, returning, float, and overlapping mixed-family atomics stay refused
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): 32 and 64 lanes (emit::lds::tests:: verifies both Wave32 acceptance/GPU execution and Wave64 refusal cases)
  • cargo test passed for the crates it touches: yes (cargo test -p victory-shader --lib --locked emit::lds::tests:: — 23 passed, 0 failed)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1773, #2261 (separate strided loop counter proof in lds.rs; this PR only adds commutative non-returning 32-bit integer atomic analysis and does not overlap #1773)
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5550650770 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2358). Originally posted by [nidea1](https://github.com/nidea1) on 2026-11-29T12:21:22Z. --- ## What it changes Adds **Refinement C** to the static LDS hazard analysis in `crates/victory-shader/src/emit/lds.rs` (`region_commutative_atomics`): - Accepts `!all` (lane-branch) LDS regions where every LDS access is a non-returning, commutative and associative 32-bit integer atomic (`ds_add_u32`, `ds_sub_u32`, `ds_and_b32`, `ds_or_b32`, `ds_xor_b32`, `ds_min_i32`, `ds_max_i32`, `ds_min_u32`, `ds_max_u32`), with zero plain reads, zero plain writes, and zero returning (`_rtn`) or order-sensitive atomics (`ds_inc_u32`, `ds_cmpst_*`, `ds_add_f32`, etc.). - When a region mixes multiple distinct algebraic families (e.g., `ds_add_u32` and `ds_or_b32`), requires provably disjoint constant byte offsets on a shared group-uniform base; same-offset mixes are refused. - Because `lds::analyze` inserts host-wave `meet` barriers around `!all` region entries and exits and 32-bit LDS atomics operate on single aligned dwords (`addr >> 2`), any Wave32 interleaving produces the exact same final LDS bits as Wave64 — complementing `LdsOrder::looped` for acyclic `!all` branches and for loops preceded by `all`-block writes without an explicit `s_barrier`. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 3060 Ti 8 GB, Series S profile, 1440p, FSR 3 2x FG, RT off (plus direct RTX 3060 Ti compute dispatch readback in `commutative_atomic_reduction_runs_on_wave32_gpu`) - Before: `!all` regions with non-returning commutative integer atomics (e.g., `if (tid.x < N) { ds_add_u32(LDS[0], ...); }`) failed `lds::analyze` with `Refusal::AtomicWithoutPlainRead` and fell back to Wave64 (or required `VICTORY_LDS_WRITE_ONLY_OK=1`) - After: such regions lower soundly to Wave32 by default with entry/exit host-wave barriers; non-commutative, returning, float, and overlapping mixed-family atomics stay refused - For shader changes, the wave sizes tested (32 and/or 64 lanes): 32 and 64 lanes (`emit::lds::tests::` verifies both Wave32 acceptance/GPU execution and Wave64 refusal cases) - `cargo test` passed for the crates it touches: yes (`cargo test -p victory-shader --lib --locked emit::lds::tests::` — 23 passed, 0 failed) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1773, #2261 (separate strided loop counter proof in `lds.rs`; this PR only adds commutative non-returning 32-bit integer atomic analysis and does not overlap #1773)
Lyrnc commented 2026-11-29 23:23:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-29T23:23:18Z.


Hardware check of this PR's pattern on a gfx1036 oracle (native wave64), against the 32-lane result on an RTX 5080 and a Radeon 680M. Hand-written wave64 cases matched in every case. On main those cases only translated through the folded form; with this PR they go to the plain split. Rebased onto current main together with the other LDS proof PR, the lds tests pass (51), and so does the full victory-shader lib apart from 3 failures that main has too.

#3441 is built on this PR and #2358/#1773 (the two conflict with each other; the resolution is in #3441). It adds two more proofs and takes the refused/folded count from 181 (main) via 162 (this pair) to 139.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7264422196 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2358#issuecomment-7264422196). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-29T23:23:18Z. --- Hardware check of this PR's pattern on a gfx1036 oracle (native wave64), against the 32-lane result on an RTX 5080 and a Radeon 680M. Hand-written wave64 cases matched in every case. On main those cases only translated through the folded form; with this PR they go to the plain split. Rebased onto current main together with the other LDS proof PR, the `lds` tests pass (51), and so does the full victory-shader lib apart from 3 failures that main has too. #3441 is built on this PR and #2358/#1773 (the two conflict with each other; the resolution is in #3441). It adds two more proofs and takes the refused/folded count from 181 (main) via 162 (this pair) to 139. AI use: Claude Code (Claude Opus 5.5).
nidea1 commented 2026-11-30 00:15:43 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-11-30T00:15:43Z.


Thanks @Lyrnc for the native Wave64 gfx1036 oracle verification against RTX 5080 and Radeon 680M, and for keeping the commit/authorship intact in #3441!

I'll leave #2358 open and untouched so #3441 stays cleanly stacked on top; if #1773 lands on main first, I'm happy to rebase #2358 right away.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7265110629 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2358#issuecomment-7265110629). Originally posted by [nidea1](https://github.com/nidea1) on 2026-11-30T00:15:43Z. --- Thanks @Lyrnc for the native Wave64 gfx1036 oracle verification against RTX 5080 and Radeon 680M, and for keeping the commit/authorship intact in #3441! I'll leave #2358 open and untouched so #3441 stays cleanly stacked on top; if #1773 lands on `main` first, I'm happy to rebase #2358 right away.
dyshay commented 2026-11-30 03:12:10 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-30T03:12:10Z.


Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7267678101 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2358#issuecomment-7267678101). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-30T03:12:10Z. --- Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.
nidea1 commented 2026-11-30 16:08:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-11-30T16:08:39Z.


Rebased onto \main\ (\c71899d9, now including #1773) at \242623c2; \cargo test -p victory-shader --locked --lib emit::lds::\ passes 26/26.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7284184901 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2358#issuecomment-7284184901). Originally posted by [nidea1](https://github.com/nidea1) on 2026-11-30T16:08:39Z. --- Rebased onto \main\ (\c71899d9\, now including #1773) at \242623c2\; \cargo test -p victory-shader --locked --lib emit::lds::\ passes 26/26.
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/2358:upstream-pr/2358'
git switch 'upstream-pr/2358'

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