Shaders: lower a subtract atomic as an add of the wrapping negation #3140

Open
Mdemets wants to merge 1 commit from upstream-pr/3142 into main
Mdemets commented 2026-11-26 10:06:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Mdemets on 2026-11-26T10:06:34Z.


atomicrmw sub removes the WARP device when the LDS subtract atomic is used; lowering it as an add of the wrapping negation is bit-identical and does not.

What changes

  • bitcode.rs: Rmw::Sub keeps its index for LLVM table alignment but is no longer constructed; the comment records why.
  • lower.rs: sub_u32 maps to Rmw::Add, and the operand is pre-negated with the existing Bin::Sub against i32(0).

Why not fix WARP instead

The shader validates and hardware is exact. The device removal is in the D3D12 WARP path for atomicrmw sub — not something this tree controls.

Verification

cargo check -p victory-shader --lib clean on 63bcca4. I also have a hardware test (a subtract atomic over a per-thread 16-byte slice, readback compared against the wrapping negation) on my test branch; it is not in this PR because lds_tests.rs no longer exists on main. Happy to re-home it into memory_tests.rs if you want it here.

Ported from my test branch (commit cf99d62).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6624250461 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3142). Originally posted by [Mdemets](https://github.com/Mdemets) on 2026-11-26T10:06:34Z. --- `atomicrmw sub` removes the WARP device when the LDS subtract atomic is used; lowering it as an add of the wrapping negation is bit-identical and does not. ## What changes - `bitcode.rs`: `Rmw::Sub` keeps its index for LLVM table alignment but is no longer constructed; the comment records why. - `lower.rs`: `sub_u32` maps to `Rmw::Add`, and the operand is pre-negated with the existing `Bin::Sub` against `i32(0)`. ## Why not fix WARP instead The shader validates and hardware is exact. The device removal is in the D3D12 WARP path for `atomicrmw sub` — not something this tree controls. ## Verification `cargo check -p victory-shader --lib` clean on `63bcca4`. I also have a hardware test (a subtract atomic over a per-thread 16-byte slice, readback compared against the wrapping negation) on my test branch; it is not in this PR because `lds_tests.rs` no longer exists on `main`. Happy to re-home it into `memory_tests.rs` if you want it here. Ported from my test branch (commit `cf99d62`).
Dukestar69 commented 2026-11-26 11:03:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T10:30:03Z.

Review: APPROVED


Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-shader --lib atomic -- --test-threads=1: passed on RTX 5090 and WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Bit-identical two's-complement lowering (atomicrmw add (0 - v0)) that avoids WARP device removal on atomicrmw sub.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6072459861 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3142#pullrequestreview-6072459861). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:30:03Z. **Review:** APPROVED --- Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib atomic -- --test-threads=1`: passed on RTX 5090 and WARP. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Bit-identical two's-complement lowering (`atomicrmw add (0 - v0)`) that avoids WARP device removal on `atomicrmw sub`. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-26 11:04:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T10:28:35Z.


WARP test report: head e9b92c8a (parent / main 63bcca43)

Coordinated under #1633 (claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7189210099).

Environment (software adapter only, no physical GPU used): Windows 11 Pro 10.0.26200 (UBR 9974); d3d10warp.dll 10.0.26100.9818; SDK dxil.dll 1.8.2502.11 (Windows SDK 10.0.26100.0, VICTORY_DXIL); dxc.exe/dxcompiler.dll 1.8.2502.11; rustc/cargo 1.98.1. VICTORY_D3D12_WARP=1 VICTORY_WARP=1 (the second forces the victory-shader test host onto WARP, which otherwise also opens the default hardware adapter). A temporary local probe confirmed DXGI reports the adapter as Microsoft Basic Render Driver (flags 0x2 software, vendor 0x1414, 0 dedicated VRAM). Every hardware label in the output below therefore also ran on WARP. Shared env for all commands: CARGO_TARGET_DIR=D:\victory-3146-3142-warp-target, -j 4.

The PR adds no test, so I wrote a temporary local oracle (not pushed) in semantics_tests.rs using the existing probe/check harness, against the ISA model MEM[a] = MEM[a] - DATA (wrapping, old value returned by _rtn). 340 inputs per probe (every pair of U32_EDGES x the first 10), three probes: (1) write [own]=a, ds_sub_rtn_u32 v5, [own], b, read back, ds_sub_u32 (no return), read back; (2) the same at offset:512 (out of the LDS allocation: returns 0, write dropped); (3) EXEC-masked lanes (masked-out lanes keep their old register).

Parent control (63bcca4 + the local test):
cargo test -p victory-shader --lib -j 4 -- zz_local_lds_sub --nocapture --test-threads 1 -> every probe fails with The GPU device instance has been suspended. Use GetDeviceRemovedReason ... (the WARP device is removed), test FAILED. Reproduces the PR's claim.

Head e9b92c8a: same command -> test ... ok; all three probes report model mismatches [hardware 0, warp 0] over 340 inputs each (both labels WARP), and DXIL passes the validator.

  • Full cargo test -p victory-shader --lib -j 4: 300 passed, 4 failed, 3 ignored; the 4 failures are the same hardware-only synthetic_tests that fail on the parent with WARP forced (see the #3146 report), unrelated to this PR.
  • cargo test -p victory-gpu --lib --features diagnostics -j 4: 246 passed, 0 failed, 1 ignored.

Observations (not blockers): the lowering maps both sub_u32 and sub_rtn_u32 to Rmw::Add with the data negated, so the returned old value is unchanged, as the oracle confirms. ds_rsub_* is not touched by this PR and I did not test it.

Not run: Clippy, cargo xtask policy, any real-GPU run (on real hardware atomicrmw sub is reportedly fine, so this was not checked there), and anything using game files.

Result: on WARP the parent removes the device and the head computes the ISA result for all 3 probes; no defect found.

AI use: tested by Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). No game files, dumps, shader names or hashes were used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189415776 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3142#issuecomment-7189415776). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T10:28:35Z. --- ## WARP test report: head `e9b92c8a` (parent / main `63bcca43`) Coordinated under #1633 (claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7189210099). **Environment (software adapter only, no physical GPU used):** Windows 11 Pro 10.0.26200 (UBR 9974); `d3d10warp.dll` 10.0.26100.9818; SDK `dxil.dll` 1.8.2502.11 (Windows SDK 10.0.26100.0, `VICTORY_DXIL`); `dxc.exe`/`dxcompiler.dll` 1.8.2502.11; rustc/cargo 1.98.1. `VICTORY_D3D12_WARP=1 VICTORY_WARP=1` (the second forces the victory-shader test host onto WARP, which otherwise also opens the default hardware adapter). A temporary local probe confirmed DXGI reports the adapter as `Microsoft Basic Render Driver` (flags 0x2 software, vendor 0x1414, 0 dedicated VRAM). Every `hardware` label in the output below therefore also ran on WARP. Shared env for all commands: `CARGO_TARGET_DIR=D:\victory-3146-3142-warp-target`, `-j 4`. The PR adds no test, so I wrote a temporary local oracle (not pushed) in `semantics_tests.rs` using the existing `probe`/`check` harness, against the ISA model `MEM[a] = MEM[a] - DATA` (wrapping, old value returned by `_rtn`). 340 inputs per probe (every pair of `U32_EDGES` x the first 10), three probes: (1) write `[own]=a`, `ds_sub_rtn_u32 v5, [own], b`, read back, `ds_sub_u32` (no return), read back; (2) the same at `offset:512` (out of the LDS allocation: returns 0, write dropped); (3) EXEC-masked lanes (masked-out lanes keep their old register). **Parent control (`63bcca4` + the local test):** `cargo test -p victory-shader --lib -j 4 -- zz_local_lds_sub --nocapture --test-threads 1` -> every probe fails with `The GPU device instance has been suspended. Use GetDeviceRemovedReason ...` (the WARP device is removed), test FAILED. Reproduces the PR's claim. **Head `e9b92c8a`:** same command -> `test ... ok`; all three probes report `model mismatches [hardware 0, warp 0]` over 340 inputs each (both labels WARP), and DXIL passes the validator. - Full `cargo test -p victory-shader --lib -j 4`: 300 passed, 4 failed, 3 ignored; the 4 failures are the same hardware-only `synthetic_tests` that fail on the parent with WARP forced (see the #3146 report), unrelated to this PR. - `cargo test -p victory-gpu --lib --features diagnostics -j 4`: 246 passed, 0 failed, 1 ignored. **Observations (not blockers):** the lowering maps both `sub_u32` and `sub_rtn_u32` to `Rmw::Add` with the data negated, so the returned old value is unchanged, as the oracle confirms. `ds_rsub_*` is not touched by this PR and I did not test it. **Not run:** Clippy, `cargo xtask policy`, any real-GPU run (on real hardware `atomicrmw sub` is reportedly fine, so this was not checked there), and anything using game files. **Result:** on WARP the parent removes the device and the head computes the ISA result for all 3 probes; no defect found. AI use: tested by Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). No game files, dumps, shader names or hashes were 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/3142:upstream-pr/3142'
git switch 'upstream-pr/3142'

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