Shaders: lower ds_add{_rtn}_f32 and ds_cmpst{_rtn}_f32 LDS atomics #1488

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

@⁠AscilCH on GitHub · 2026-11-24 18:22 UTC · original
AscilCH:fix/ds-float-atomics → main · +334 −18 · 2 files · 1 commits · open

Summary

Lower GFX10 floating-point LDS atomics ds_add_f32 (0x015), ds_add_rtn_f32 (0x055), ds_cmpst_f32 (0x011), and ds_cmpst_rtn_f32 (0x031) in Lower::ds() (crates/victory-shader/src/emit/lower.rs).

(Complementary to #164 which covers integer LDS atomics and leaves out float atomics, and disjoint from #628 which covers ds_min_f32/ds_max_f32.)

Reproduction (Before Fix)

Lowering a synthetic compute shader containing ds_add_f32, ds_add_rtn_f32, ds_cmpst_f32, or ds_cmpst_rtn_f32 failed with:

lower: Unsupported { offset: 40, what: "an LDS operation" }

Implementation

  • ds_add_f32 / ds_add_rtn_f32: Emits a guarded cmpxchg CAS loop on the LDS dword: reads cur, computes next = bitcast(bitcast(cur, f32) + bitcast(src, f32), i32), and retries cmpxchg cur -> next until the previous word equals cur (handling both normal updates and NaN/no-op termination cleanly).
  • ds_cmpst_f32 / ds_cmpst_rtn_f32: Emits a guarded cmpxchg loop using IEEE-754 ordered float equality (fcmp oeq) against the loaded word — matching RDNA2's floating-point compare-and-swap semantics where +0.0 == -0.0 succeeds and NaN == NaN fails (leaving LDS untouched and returning the old bits for _rtn).

Test

Added synthetic end-to-end test emit::valu_tests::ds_add_f32_and_ds_cmpst_f32_match_rdna2 (64-thread two-wave compute shaders, validated by dxil.dll and executed on hardware GPU + WARP):

  • Single-lane (v_cmpx_eq_u32 EXEC-guarded) ds_add_rtn_f32 and ds_add_f32 old/new values and NaN add termination.
  • ds_cmpst_rtn_f32 and ds_cmpst_f32 covering matching values, mismatching values, +0.0 == -0.0, -0.0 == +0.0, and NaN != NaN.
  • 64-lane contended ds_add_f32 accumulation across two waves verifying the exact sum 1 + 2 + ... + 64 = 2080.0.

Verification

  • rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rs and modified lines of lower.rs: clean
  • cargo test -p victory-shader --locked ds_add_f32_and_ds_cmpst_f32_match_rdna2 (hardware + WARP + dxil.dll): passed
  • VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failed
  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
**@⁠AscilCH** on GitHub · 2026-11-24 18:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/1488) `AscilCH:fix/ds-float-atomics` → `main` · +334 −18 · 2 files · 1 commits · open ## Summary Lower GFX10 floating-point LDS atomics `ds_add_f32` (`0x015`), `ds_add_rtn_f32` (`0x055`), `ds_cmpst_f32` (`0x011`), and `ds_cmpst_rtn_f32` (`0x031`) in `Lower::ds()` (`crates/victory-shader/src/emit/lower.rs`). *(Complementary to #164 which covers integer LDS atomics and leaves out float atomics, and disjoint from #628 which covers `ds_min_f32`/`ds_max_f32`.)* ## Reproduction (Before Fix) Lowering a synthetic compute shader containing `ds_add_f32`, `ds_add_rtn_f32`, `ds_cmpst_f32`, or `ds_cmpst_rtn_f32` failed with: ```text lower: Unsupported { offset: 40, what: "an LDS operation" } ``` ## Implementation - **`ds_add_f32` / `ds_add_rtn_f32`**: Emits a guarded `cmpxchg` CAS loop on the LDS dword: reads `cur`, computes `next = bitcast(bitcast(cur, f32) + bitcast(src, f32), i32)`, and retries `cmpxchg cur -> next` until the previous word equals `cur` (handling both normal updates and NaN/no-op termination cleanly). - **`ds_cmpst_f32` / `ds_cmpst_rtn_f32`**: Emits a guarded `cmpxchg` loop using IEEE-754 ordered float equality (`fcmp oeq`) against the loaded word — matching RDNA2's floating-point compare-and-swap semantics where `+0.0 == -0.0` succeeds and `NaN == NaN` fails (leaving LDS untouched and returning the old bits for `_rtn`). ## Test Added synthetic end-to-end test `emit::valu_tests::ds_add_f32_and_ds_cmpst_f32_match_rdna2` (64-thread two-wave compute shaders, validated by `dxil.dll` and executed on hardware GPU + WARP): - Single-lane (`v_cmpx_eq_u32` EXEC-guarded) `ds_add_rtn_f32` and `ds_add_f32` old/new values and NaN add termination. - `ds_cmpst_rtn_f32` and `ds_cmpst_f32` covering matching values, mismatching values, `+0.0 == -0.0`, `-0.0 == +0.0`, and `NaN != NaN`. - 64-lane contended `ds_add_f32` accumulation across two waves verifying the exact sum `1 + 2 + ... + 64 = 2080.0`. ## Verification - `rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rs` and modified lines of `lower.rs`: clean - `cargo test -p victory-shader --locked ds_add_f32_and_ds_cmpst_f32_match_rdna2` (hardware + WARP + `dxil.dll`): passed - `VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1`: 121 passed, 0 failed - `cargo xtask policy`: 154 files ok - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean
Lower the floating-point 32-bit LDS atomic instructions in Lower::ds()
using structured compare-exchange (cmpxchg) loops inside begin_guarded /
end_guarded:
- ds_add_f32 (0x015) and ds_add_rtn_f32 (0x055): load current dword,
  bitcast to f32, add src0.f32, bitcast back to i32, and retry cmpxchg
  until the expected bit pattern matches.
- ds_cmpst_f32 (0x011) and ds_cmpst_rtn_f32 (0x031): compare current
  f32 against data0.f32 with IEEE ordered equality (+0.0 == -0.0,
  NaN != NaN), exiting without writing on mismatch, and attempting
  cmpxchg(ptr, cur, data1) on match.

Adds synthetic compute shader test
emit::valu_tests::ds_add_f32_and_ds_cmpst_f32_match_rdna2 covering all
four instructions (EXEC-guarded single-lane old/new value checks, signed
zero equality, NaN termination/non-equality, and 64-lane contention) on
hardware GPU, WARP, and dxil.dll.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:33:43 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 18:48 UTC · original

Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 62c4ded. cargo test -p victory-shader --lib -- --test-threads=1 --nocapture gives 121 passed, 0 failed, 1 ignored, with the new LDS float atomic test passing on the hardware adapter and WARP. Running the compare-exchange loop on the raw bits (prev == cur as integers) means a NaN already stored can't make the ds_add_f32 loop spin, which was the part I wanted to see. On this hardware the loop also completes when the lanes of a wave contend for one address.

**@⁠marquezinii** on GitHub · 2026-11-24 18:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1488#issuecomment-7141172059) Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `62c4ded`. `cargo test -p victory-shader --lib -- --test-threads=1 --nocapture` gives 121 passed, 0 failed, 1 ignored, with the new LDS float atomic test passing on the hardware adapter and WARP. Running the compare-exchange loop on the raw bits (`prev == cur` as integers) means a NaN already stored can't make the `ds_add_f32` loop spin, which was the part I wanted to see. On this hardware the loop also completes when the lanes of a wave contend for one address.
Author
Owner

@⁠wwwwwwww3333333 on GitHub · 2026-11-24 19:15 UTC · original

Native Windows run on AMD RDNA2: RX 6750 XT (RDNA2, gfx1031), AMD driver 32.0.21045.29003, i5-13400F, Windows 11, Rust 1.98.1 MSVC. Head 62c4ded on main ffe310e (clean merge).

cargo test -p victory-shader --lib -- --test-threads=1: 121 passed, 0 failed, 1 ignored (main alone: 120 passed). ds_add_f32_and_ds_cmpst_f32_match_rdna2 ran on the hardware adapter and then on WARP, and passed on both. This adds an AMD result to the NVIDIA runs already posted.

Synthetic tests only, no game files. AI-assisted (Claude picked the PRs and wrote the batch script; I ran it on my machine).

**@⁠wwwwwwww3333333** on GitHub · 2026-11-24 19:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1488#issuecomment-7141829249) Native Windows run on AMD RDNA2: RX 6750 XT (RDNA2, gfx1031), AMD driver 32.0.21045.29003, i5-13400F, Windows 11, Rust 1.98.1 MSVC. Head 62c4ded on main ffe310e (clean merge). `cargo test -p victory-shader --lib -- --test-threads=1`: **121 passed, 0 failed**, 1 ignored (main alone: 120 passed). `ds_add_f32_and_ds_cmpst_f32_match_rdna2` ran on the hardware adapter and then on WARP, and passed on both. This adds an AMD result to the NVIDIA runs already posted. Synthetic tests only, no game files. AI-assisted (Claude picked the PRs and wrote the batch script; I ran it on my machine).
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:13 UTC · original

Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 62c4ded onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1488#issuecomment-7143209540) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 62c4ded onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:29 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1488#issuecomment-7149610304) <!-- victory-triage v1 head=62c4ded0ffbac3cb42f73aa7ddf66f4d49d43bad verdict=needs-rebase at=2026-11-25T01:29:43Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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