Shaders: lower ds_add{_rtn}_f32 and ds_cmpst{_rtn}_f32 LDS atomics #1487
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1488"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by AscilCH on 2026-11-24T18:22:24Z.
Summary
Lower GFX10 floating-point LDS atomics
ds_add_f32(0x015),ds_add_rtn_f32(0x055),ds_cmpst_f32(0x011), andds_cmpst_rtn_f32(0x031) inLower::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, ords_cmpst_rtn_f32failed with:Implementation
ds_add_f32/ds_add_rtn_f32: Emits a guardedcmpxchgCAS loop on the LDS dword: readscur, computesnext = bitcast(bitcast(cur, f32) + bitcast(src, f32), i32), and retriescmpxchg cur -> nextuntil the previous word equalscur(handling both normal updates and NaN/no-op termination cleanly).ds_cmpst_f32/ds_cmpst_rtn_f32: Emits a guardedcmpxchgloop 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.0succeeds andNaN == NaNfails (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 bydxil.dlland executed on hardware GPU + WARP):v_cmpx_eq_u32EXEC-guarded)ds_add_rtn_f32andds_add_f32old/new values and NaN add termination.ds_cmpst_rtn_f32andds_cmpst_f32covering matching values, mismatching values,+0.0 == -0.0,-0.0 == +0.0, andNaN != NaN.ds_add_f32accumulation across two waves verifying the exact sum1 + 2 + ... + 64 = 2080.0.Verification
rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rsand modified lines oflower.rs: cleancargo test -p victory-shader --locked ds_add_f32_and_ds_cmpst_f32_match_rdna2(hardware + WARP +dxil.dll): passedVICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failedcargo xtask policy: 154 files okcargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleanImported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T18:28:02Z.
Review: APPROVED
Verified locally merged onto
origin/main(Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):cargo test -p victory-shader --lib ds_add_f32_and_ds_cmpst_f32_match_rdna2— passed on RTX 5090 hardware and underVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— okClean CAS-loop lowering for
ds_add{_rtn}_f32andds_cmpst{_rtn}_f32with end-to-end GPU+WARP verification. Looks good.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T18:42:10Z.
Review: APPROVED
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e),cargo test -p victory-shader --locked→ 96 passed, 0 failed. Execution/valu tests are#[cfg(all(test, windows))]and were not run here; lowering/structure coverage only.ds_add_f32/ds_cmpst_f32(+_rtn) as CAS loops is the right lowering since DXIL has no float LDS atomic:_rtnhandled by the existing name normalization.The valu tests are strong: per-case memory/result checks, NaN no-spin cases, and a 64-lane contended
ds_add_f32expecting exactly 2080.0 on hardware and WARP. Windows-only here — please run before merge.Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T18:48:10Z.
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 --nocapturegives 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 == curas integers) means a NaN already stored can't make theds_add_f32loop 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.Imported from Marvisak/VIctory. Originally posted by wwwwwwww3333333 on 2026-11-24T19:15:19Z.
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
62c4dedon mainffe310e(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_rdna2ran 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).
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:13:16Z.
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head
62c4dedontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 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 --libpassed 121, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:29:44Z.
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 currentmain.Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.