Skip to content

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

Open
Mdemets wants to merge 1 commit into
Marvisak:mainfrom
Mdemets:contrib/atomic-sub
Open

Mdemets wants to merge 1 commit into
Marvisak:mainfrom
Mdemets:contrib/atomic-sub

Conversation

@Mdemets

@Mdemets Mdemets commented Nov 26, 2026

Copy link
Copy Markdown

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

@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown

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

Coordinated under #1633 (claim: #1633 (comment)).

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 Shaders: lower V_SAT_PK_U8_I16 #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.

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants