Shaders: lower buffer_atomic_{sub,csub,inc,dec,fcmpswap,fmin,fmax} #1342

Open
github-bot wants to merge 1 commit from github-bot/gh-1342 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-24 17:33 UTC · original
AscilCH:fix/buffer-atomic-sub-inc-dec → main · +278 −23 · 2 files · 1 commits · open

Gap

Lower::buffer() in crates/victory-shader/src/emit/lower.rs was missing lowering for seven 32-bit MUBUF atomic instructions, failing shader translation with:

lower: Unsupported { offset: 36, what: "buffer_atomic_sub" }

Missing ops: buffer_atomic_sub (0x33), buffer_atomic_csub (0x34), buffer_atomic_inc (0x3c), buffer_atomic_dec (0x3d), buffer_atomic_fcmpswap (0x3e), buffer_atomic_fmin (0x3f), and buffer_atomic_fmax (0x40).

Fix

Added a BufferAtomic lowering dispatch in Lower::buffer():

  • buffer_atomic_sub (0x33): negates vals[0] (0 - val) and emits atomicBinOp.i32(Add) (matching image_atomic_sub).
  • buffer_atomic_csub (0x34): structured atomicCompareExchange.i32 CAS loop computing (old >= val) ? old - val : 0.
  • buffer_atomic_inc (0x3c) and buffer_atomic_dec (0x3d): structured CAS loops with RDNA2 unsigned wrap semantics ((old >= val) ? 0 : old + 1 and (old == 0 || old > val) ? val : old - 1).
  • buffer_atomic_fmin (0x3f) and buffer_atomic_fmax (0x40): structured CAS loops using RDNA2 self.max_min (-0.0 < +0.0, non-NaN wins).
  • buffer_atomic_fcmpswap (0x3e): structured CAS loop comparing with IEEE ordered equality (pred::OEQ, so +0.0 == -0.0 and NaN != NaN) and exiting without writing on mismatch.

Added hardware + WARP + dxil.dll test emit::valu_tests::buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2 verifying both updated buffer memory and returned pre-op values (glc = 1) for all seven instructions across normal, clamp, wrap, -0.0/+0.0, and NaN cases.

Verification

Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK dxil.dll:

  • rustfmt --edition 2024 --check on valu_tests.rs: clean
  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test -p victory-shader --locked -- buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2 --nocapture --test-threads=1: passed (hardware + WARP + dxil.dll)
  • VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failed, 1 ignored
**@⁠AscilCH** on GitHub · 2026-11-24 17:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1342) `AscilCH:fix/buffer-atomic-sub-inc-dec` → `main` · +278 −23 · 2 files · 1 commits · open ### Gap `Lower::buffer()` in `crates/victory-shader/src/emit/lower.rs` was missing lowering for seven 32-bit MUBUF atomic instructions, failing shader translation with: ```text lower: Unsupported { offset: 36, what: "buffer_atomic_sub" } ``` Missing ops: `buffer_atomic_sub` (`0x33`), `buffer_atomic_csub` (`0x34`), `buffer_atomic_inc` (`0x3c`), `buffer_atomic_dec` (`0x3d`), `buffer_atomic_fcmpswap` (`0x3e`), `buffer_atomic_fmin` (`0x3f`), and `buffer_atomic_fmax` (`0x40`). ### Fix Added a `BufferAtomic` lowering dispatch in `Lower::buffer()`: - **`buffer_atomic_sub` (`0x33`)**: negates `vals[0]` (`0 - val`) and emits `atomicBinOp.i32(Add)` (matching `image_atomic_sub`). - **`buffer_atomic_csub` (`0x34`)**: structured `atomicCompareExchange.i32` CAS loop computing `(old >= val) ? old - val : 0`. - **`buffer_atomic_inc` (`0x3c`)** and **`buffer_atomic_dec` (`0x3d`)**: structured CAS loops with RDNA2 unsigned wrap semantics (`(old >= val) ? 0 : old + 1` and `(old == 0 || old > val) ? val : old - 1`). - **`buffer_atomic_fmin` (`0x3f`)** and **`buffer_atomic_fmax` (`0x40`)**: structured CAS loops using RDNA2 `self.max_min` (`-0.0 < +0.0`, non-NaN wins). - **`buffer_atomic_fcmpswap` (`0x3e`)**: structured CAS loop comparing with IEEE ordered equality (`pred::OEQ`, so `+0.0 == -0.0` and `NaN != NaN`) and exiting without writing on mismatch. Added hardware + WARP + `dxil.dll` test `emit::valu_tests::buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2` verifying both updated buffer memory and returned pre-op values (`glc = 1`) for all seven instructions across normal, clamp, wrap, `-0.0`/`+0.0`, and `NaN` cases. ### Verification Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK `dxil.dll`: - `rustfmt --edition 2024 --check` on `valu_tests.rs`: clean - `cargo xtask policy`: `154 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test -p victory-shader --locked -- buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2 --nocapture --test-threads=1`: passed (hardware + WARP + `dxil.dll`) - `VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1`: `121 passed, 0 failed, 1 ignored`
Lower the remaining 32-bit MUBUF atomic instructions in Lower::buffer:
- buffer_atomic_sub (0x33): negate src and emit atomicBinOp.i32(Add).
- buffer_atomic_csub (0x34): atomic CAS loop computing
  (old >= val) ? old - val : 0.
- buffer_atomic_inc (0x3c) and buffer_atomic_dec (0x3d): atomic CAS
  loops with RDNA2 unsigned wrap semantics.
- buffer_atomic_fmin (0x3f) and buffer_atomic_fmax (0x40): atomic CAS
  loops using RDNA2 float min/max (-0.0 < +0.0, non-NaN wins).
- buffer_atomic_fcmpswap (0x3e): atomic CAS loop comparing with IEEE
  ordered equality (+0.0 == -0.0, NaN != NaN) and exiting without
  writing on mismatch.

Adds a synthetic compute shader test executing on hardware GPU, WARP,
and dxil.dll covering both updated memory and glc old-value return for
all seven instructions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:13 +00:00
Author
Owner

@⁠ghost on GitHub · 2026-11-24 18:01 UTC · original

Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head 8448e91 on main ffe310e.

  • buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2 passes: buffer_atomic_sub, csub, inc, dec, fcmpswap (-0 == +0, NaN != NaN), fmin and fmax, checking both the new memory value and the returned old value.
  • victory-shader lib tests: 120 passed, 1 failed, 1 ignored (main on the same host: 119/1/1). The one failure, stub_pipeline_is_created, fails on main too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR).
  • No hangs. A pass means the translated DXIL gives these values on RDNA2 through vkd3d-proton/RADV; it isn't a console measurement.

Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the test fails without the fix on this host.

AI-assisted (Claude Code, Claude Opus 5.5); no game data.

**@⁠ghost** on GitHub · 2026-11-24 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1342#issuecomment-7140036903) Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head `8448e91` on main `ffe310e`. - `buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2` passes: buffer_atomic_sub, csub, inc, dec, fcmpswap (-0 == +0, NaN != NaN), fmin and fmax, checking both the new memory value and the returned old value. - victory-shader lib tests: 120 passed, 1 failed, 1 ignored (main on the same host: 119/1/1). The one failure, `stub_pipeline_is_created`, fails on main too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR). - No hangs. A pass means the translated DXIL gives these values on RDNA2 through vkd3d-proton/RADV; it isn't a console measurement. Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the test fails without the fix on this host. AI-assisted (Claude Code, Claude Opus 5.5); no game data.
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 18:10 UTC · original

Ran natively on Windows (not through vkd3d) on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 8448e91. cargo test -p victory-shader --lib -- --test-threads=1 gives 121 passed, 0 failed, 1 ignored. buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2 passes on the hardware adapter and WARP. Together with nullmarsh's Steam Deck run, that covers RADV and a native NVIDIA driver.

I checked the compare-exchange loop bodies against the RDNA2 definitions:

  • csub: cur >= data ? cur - data : 0
  • inc: cur >= data ? 0 : cur + 1
  • dec: cur == 0 || cur > data ? data : cur - 1

All three match.

**@⁠marquezinii** on GitHub · 2026-11-24 18:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1342#issuecomment-7140273489) Ran natively on Windows (not through vkd3d) on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `8448e91`. `cargo test -p victory-shader --lib -- --test-threads=1` gives 121 passed, 0 failed, 1 ignored. `buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2` passes on the hardware adapter and WARP. Together with nullmarsh's Steam Deck run, that covers RADV and a native NVIDIA driver. I checked the compare-exchange loop bodies against the RDNA2 definitions: - `csub`: `cur >= data ? cur - data : 0` - `inc`: `cur >= data ? 0 : cur + 1` - `dec`: `cur == 0 || cur > data ? data : cur - 1` All three match.
Author
Owner

@⁠shortselow-byte on GitHub · 2026-11-24 19:06 UTC · original

For triage: #164 (older, open, already reviewed) lowers the same seven buffer atomics in its buffer_atomic_ path: sub, csub, inc, dec, fcmpswap, fmin and fmax. git merge-tree against the current heads (8448e91 here, 825dbd9 there) shows the two conflict in emit/lower.rs, so they need reconciling rather than both landing.

For the record, this PR on its own also passes on a native AMD driver: isolated target directory, Windows 11, Rust 1.98.1 MSVC, RX 6900 XT, workspace 343 passed, 0 failed, both clippy runs clean.

**@⁠shortselow-byte** on GitHub · 2026-11-24 19:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1342#issuecomment-7141613412) For triage: #164 (older, open, already reviewed) lowers the same seven buffer atomics in its `buffer_atomic_` path: `sub`, `csub`, `inc`, `dec`, `fcmpswap`, `fmin` and `fmax`. `git merge-tree` against the current heads (`8448e91` here, `825dbd9` there) shows the two conflict in `emit/lower.rs`, so they need reconciling rather than both landing. For the record, this PR on its own also passes on a native AMD driver: isolated target directory, Windows 11, Rust 1.98.1 MSVC, RX 6900 XT, workspace 343 passed, 0 failed, both clippy runs clean.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:23 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1342#issuecomment-7149497387) <!-- victory-triage v1 head=8448e91f535f531265c763258b47c0781b81223d verdict=needs-rebase at=2026-11-25T01:23:31Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 01:48 UTC · original

Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 8448e91 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 01:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1342#issuecomment-7149983362) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 8448e91 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/valu_tests.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/1342/head:github-bot/gh-1342'
git switch 'github-bot/gh-1342'

Merge

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