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

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

@⁠Mdemets on GitHub · 2026-11-26 10:06 UTC · original
Mdemets:contrib/atomic-sub → main · +15 −1 · 2 files · 1 commits · open

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

**@⁠Mdemets** on GitHub · 2026-11-26 10:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/3142) `Mdemets:contrib/atomic-sub` → `main` · +15 −1 · 2 files · 1 commits · open `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`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:08:26 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 10:28 UTC · original

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

Coordinated under #1633 (claim: #1633).

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.

**@⁠oni-swr** on GitHub · 2026-11-26 10:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3142#issuecomment-7189415776) ## WARP test report: head `e9b92c8a` (parent / main `63bcca43`) Coordinated under #1633 (claim: https://git.gtahub.st/github/Marvisak--VIctory/issues/1633). **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.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 10:30 UTC · original · approved these changes

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

**@⁠Dukestar69** on GitHub · 2026-11-26 10:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/3142#pullrequestreview-6072459861) · **approved these changes** 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).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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