Shaders: lower image_atomic_inc, _dec, _fcmpswap, _fmin and _fmax #1148

Closed
VermaakLabs wants to merge 1 commit from upstream-pr/1148 into main
VermaakLabs commented 2026-11-24 16:14:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by VermaakLabs on 2026-11-24T16:14:33Z.


DXIL has no operation for image_atomic_inc, _dec, _fcmpswap, _fmin and _fmax, so a program using one of them stopped. Each is now a compare-and-swap loop on the dword: the new value is made from the old one by RDNA2's definition, starting from a guess of 0, until the exchange finds the value it was made from. A null view reads 0, so the loop leaves at once there.

  • inc and dec wrap at the data as the ISA says.
  • fcmpswap compares as floats: -0 matches +0, NaN matches nothing.
  • fmin and fmax follow v_min_f32 and v_max_f32.

64-bit and 16-bit image atomics still stop the program, as before.

Tests: emit/image_atomic_tests.rs builds a synthetic GFX10 compute shader for each (the same way as valu_tests.rs), validated by dxil.dll, and runs it on the host GPU and WARP, checking the returned old value and the texel left behind. Passes on an Intel Arc 140T, an NVIDIA RTX 5070 Ti Laptop GPU and WARP. Clippy is clean and cargo xtask policy passes.

Side note, not part of this change: valu_tests::v_med3_f32_matches_rdna2_with_nan fails on main too when the default adapter is the Intel Arc (v_med3_f32(1.0, 2.0, NaN) gives 2.0, want 1.0). It passes on the NVIDIA card.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6586245659 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1148). Originally posted by [VermaakLabs](https://github.com/VermaakLabs) on 2026-11-24T16:14:33Z. --- DXIL has no operation for `image_atomic_inc`, `_dec`, `_fcmpswap`, `_fmin` and `_fmax`, so a program using one of them stopped. Each is now a compare-and-swap loop on the dword: the new value is made from the old one by RDNA2's definition, starting from a guess of 0, until the exchange finds the value it was made from. A null view reads 0, so the loop leaves at once there. - `inc` and `dec` wrap at the data as the ISA says. - `fcmpswap` compares as floats: -0 matches +0, NaN matches nothing. - `fmin` and `fmax` follow `v_min_f32` and `v_max_f32`. 64-bit and 16-bit image atomics still stop the program, as before. **Tests:** `emit/image_atomic_tests.rs` builds a synthetic GFX10 compute shader for each (the same way as `valu_tests.rs`), validated by `dxil.dll`, and runs it on the host GPU and WARP, checking the returned old value and the texel left behind. Passes on an Intel Arc 140T, an NVIDIA RTX 5070 Ti Laptop GPU and WARP. Clippy is clean and `cargo xtask policy` passes. Side note, not part of this change: `valu_tests::v_med3_f32_matches_rdna2_with_nan` fails on `main` too when the default adapter is the Intel Arc (`v_med3_f32(1.0, 2.0, NaN)` gives 2.0, want 1.0). It passes on the NVIDIA card.
shortselow-byte commented 2026-11-24 18:05:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-24T17:23:28Z.


This PR has no CI run yet, so I ran the CI's checks at head 1661a3e on Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2).

On its own base (8e79c80) everything passes: workspace 315 passed, 0 failed; both clippy runs clean; policy ok.

Merged onto current main (ffe310e) it does not compile, the #801 pattern: resource::track takes a fourth argument there.

error[E0061]: this function takes 4 arguments but 3 arguments were supplied
   --> crates\victory-shader\src\emit\image_atomic_tests.rs:114:15

With the call written as valu_tests.rs does on main (structure first, then resource::track(&p, &native.layout, native.stage, Some(&st)); local only, not pushed):

  • all four new tests pass on the AMD device and on WARP, with dxil.dll validation (inc wrap, dec reload, fcmpswap as floats, fmin/fmax);
  • workspace 346 passed, 0 failed; both clippy runs (default and --all-features) clean.

So the lowering itself looks good on AMD; the branch only needs a rebase with that one-line test change.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139121654 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1148#issuecomment-7139121654). Originally posted by [shortselow-byte](https://github.com/shortselow-byte) on 2026-11-24T17:23:28Z. --- This PR has no CI run yet, so I ran the CI's checks at head `1661a3e` on Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2). **On its own base (`8e79c80`)** everything passes: workspace 315 passed, 0 failed; both clippy runs clean; policy ok. **Merged onto current `main` (`ffe310e`) it does not compile**, the #801 pattern: `resource::track` takes a fourth argument there. ``` error[E0061]: this function takes 4 arguments but 3 arguments were supplied --> crates\victory-shader\src\emit\image_atomic_tests.rs:114:15 ``` With the call written as `valu_tests.rs` does on `main` (structure first, then `resource::track(&p, &native.layout, native.stage, Some(&st))`; local only, not pushed): - all four new tests pass on the AMD device and on WARP, with `dxil.dll` validation (`inc` wrap, `dec` reload, `fcmpswap` as floats, `fmin`/`fmax`); - workspace 346 passed, 0 failed; both clippy runs (default and `--all-features`) clean. So the lowering itself looks good on AMD; the branch only needs a rebase with that one-line test change.
Zipettte commented 2026-11-24 18:06:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T18:01:16Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 1661a3e: cargo test -p victory-shader passes, 93 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140041207 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1148#issuecomment-7140041207). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T18:01:16Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 1661a3e: `cargo test -p victory-shader` passes, 93 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Marvisak commented 2026-11-25 01:08:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:37:44Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148711480 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1148#issuecomment-7148711480). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:37:44Z. --- <!-- victory-triage v1 head=1661a3e0cfb31380ea71faad2f98c3c983d5cea6 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 10:05:53 +00:00

Pull request closed

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!1148
No description provided.