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

Closed
github-bot wants to merge 1 commit from gh-pr/1148/head into gh-pr/1148/base
Owner

@⁠VermaakLabs on GitHub · 2026-11-24 16:14 UTC · original
shaders/image-atomic-loops → main · +344 −4 · 3 files · 1 commits · closed without merging

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.

**@⁠VermaakLabs** on GitHub · 2026-11-24 16:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1148) `shaders/image-atomic-loops` → `main` · +344 −4 · 3 files · 1 commits · closed without merging 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.
DXIL has no operation for these five, so they stopped the program. 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.

Tests: synthetic GFX10 compute shaders for each, validated by dxil.dll
and run on the host GPU and WARP, checking the returned old value and
the texel left behind.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:21:09 +00:00
github-bot closed this pull request 2026-11-26 04:21:09 +00:00
Author
Owner

@⁠shortselow-byte on GitHub · 2026-11-24 17:23 UTC · original

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.

**@⁠shortselow-byte** on GitHub · 2026-11-24 17:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1148#issuecomment-7139121654) 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.
Author
Owner

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

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

**@⁠Zipettte** on GitHub · 2026-11-24 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1148#issuecomment-7140041207) 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)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:37 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 00:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1148#issuecomment-7148711480) <!-- 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)_

Pull request closed

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