Skip to content

rdna2spirv: ds_cmpst_f32 and the global/buffer fcmpswap atomics - #3153

Merged
shayderrr merged 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:float-cmpswap
Nov 23, 2026
Merged

shayderrr merged 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:float-cmpswap

Conversation

@LouisRiverstone

@LouisRiverstone LouisRiverstone commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

ds_cmpst_f32/ds_cmpst_rtn_f32, global_atomic_fcmpswap and buffer_atomic_fcmpswap raised Unsupported. #2495 has the LDS f32 min/max but not cmpst_f32, and #2653 covers only the image form.

Semantics (RDNA2 ISA): tmp = M; M = (tmp == CMP) ? DATA : tmp, with the returning forms giving tmp. The compare is a float compare: −0 == +0 matches, and a NaN never matches, even with identical bits.

Implementation: OpAtomicCompareExchange compares bits, which differs exactly in those cases. So Gen.float_cmpswap_loop runs a compare-and-swap loop:

  • read M
  • pick DATA or M by OpFOrdEqual
  • swap that in if M still holds what was read; otherwise retry

This is exact under contention.

  • Operands: ds_cmpst_f32 takes CMP then DATA, as ds_cmpst_b32. The global and buffer forms take vdata as {DATA, CMP}, as cmpswap.
  • Inactive lanes, buffer bounds, glc: as for the integer siblings.
  • OpPhi fix: the result OpPhi in global_atomic and buffer_atomic now names the block that actually branches to the merge. For the existing ops that's the same _do block as before, so their code is unchanged. For fcmpswap it's the loop's exit block.
  • Not measured: subnormal inputs; the interpreter compares them exactly. _x2 forms stay Unsupported.

Tests: tests/semantic/test_float_cmpswap.py, for all four ops:

  • equal, unequal, −0/+0 both ways, NaN against the same NaN, NaN CMP, ∞, and a subnormal
  • no glc
  • buffer out-of-range
  • 32 lanes on one dword: every lane tries 0.0 → 1.0 with CMP −0; one wins and the rest keep 1.0
  • non-pair vdata and _x2 rejected

Without the change the file fails (30 errors); with it, 6/6 pass. test_global_atomics.py and test_lds_atomics_values.py still pass. python -I -m unittest discover -s tests/semantic: 4148 tests OK (4 skipped).

docs/design.md: new row after ds_cmpst_b32.

GPU test (added after the first review): runtime/test/shaders/cs_w32_fcmpswap.asm. Lane 0 of a wave32 group runs ds_cmpst_rtn_f32, ds_cmpst_f32 and buffer_atomic_fcmpswap (with and without glc): −0 against +0, a NaN against its own bits, and a value one ulp off. It is registered in check.py, run_gpu_tests.py and regen_fixtures.py. tests/semantic/test_fcmpswap_fixture.py runs it on the CPU and checks that both runners expect the same eight words. The global form isn't in the fixture, because it needs the heap setup from #1760.

The new GPU fixture hasn't been run on hardware by me; CI's llvmpipe job will run it. No game files. Claimed on #2891 before starting.

AI-assisted (Claude Code): I reviewed and ran the change and the tests.

@CharlyRien

Copy link
Copy Markdown

Tested 9c70c02 (merged on current main) on RTX 3090, driver 616.56, Windows 11 23H2: pass. With this translator change, run_gpu_tests.py gives 143/189 passed, 46 skipped (wave64 on a 32-wide GPU), the same as main on this GPU. ctest matches main here (3 known failures on this machine: d3d12_shader_cache, see #2167; and d3d12_vulkan_device / d3d12_typeless_rtv, see #2498).

AI-assisted test run.

@hidrogenone

Copy link
Copy Markdown
Contributor

Tested fbe9cc11 on NVIDIA GeForce RTX 5080 (Blackwell), driver 32.0.16.2124, Windows 11, Vulkan SDK 1.4.357.0. llvm-mc LLVM 21.1.8 (WSL Ubuntu).

scripts/run_gpu_tests.py --filter fcmpswap:

cs_w32_fcmpswap   1/1 passed

Translator: 1 shader translated, spirv-val clean — the ds_cmpst_f32 / global/buffer float compare-swap path is exact on this adapter. NVIDIA Blackwell (RTX 50-series) coverage. AI-assisted.

@emirduran707

Copy link
Copy Markdown
Contributor

Tested fbe9cc1 on AMD Radeon RX 9060 XT (RDNA4), AMD driver 26.10.44 (LLPC, Vulkan driver 2.0.395), Windows 11 Pro 10.0.26300, subgroup 32..64: pass. The checks above have no AMD run from outside the author; this adds an AMD card with native 64-wide subgroups.

  • python -I scripts/run_gpu_tests.py --build <build> --filter <fixture>, one run per new fixture:
    • cs_w32_fcmpswap: PASS, 0 1065353216 2143289344 1065353216 2147483648 1077936128 1065353216 2143289344; same with LEONIDA_W64_EMULATE=1
  • Whole suite (native wave64): 195 shaders translated, 195 pass spirv-val; 176/190 passed, 14 skipped, 0 failed. The skips are the 14 fixtures the d3d12_* tests run.
  • build.py + check.py: 215 shaders: 215 translated, 215 pass spirv-val; 165 of 168 pass, 3 skipped; ok for cs_w32_fcmpswap.
  • CPU: python -I -m unittest discover -s tests/semantic -p test_fcmpswap_fixture.py 4 OK, python -I -m unittest discover -s tests/semantic -p test_float_cmpswap.py 6 OK, tests/test_shader_checks.py 69 OK, tests/test_run_gpu_tests.py 34 OK, tests/semantic/regen_fixtures.py --check clean. I did not run the whole tests/semantic suite.

Test programs: an MSVC 14.44 build of main ec8ec4c; this PR's runtime C++ and CMake are identical to that commit, and the translator, runner and check.py are this PR's. llvm-mc 21.1.8 (native), Vulkan SDK 1.4.363.0. No negative control run here. No game files. AI-assisted (Claude Code).

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Rebased onto main (ff21d156), which now has #2448's inc/dec and #3120's ds_add_f32. Changes:

  • Code structure: fcmpswap now uses main's structure in global_atomic/buffer_atomic (is_inc_dec, done_lbl).
  • Initial read: float_cmpswap_loop now reads the dword with an OpAtomicLoad at the op's scope, as main's inc/dec and LDS CAS loops do. It used a plain load before.
  • LDS pointer: ds_cmpst_f32 uses lds_ptr, as main's other CAS-loop LDS atomics do. lds_access's merge assumes a single-block access, so it can't wrap a loop.
  • Fixture registration: cs_w32_fcmpswap stays in WAVE32_DUMPS only, not in the lane-mask list that llvmpipe skips.

test_float_cmpswap.py, test_fcmpswap_fixture.py, test_global_atomics.py, test_atomic_inc_dec.py and test_lds_add_f32.py pass. The full semantic suite has only main's 10 known failures. The GPU passes above (RTX 5080, RX 9060 XT) were on fbe9cc11, before these changes.

@Kev-Ball

Copy link
Copy Markdown

Tested aa174bab on an NVIDIA GeForce RTX 3080 Ti (32-lane subgroups), driver 620.73.04, CachyOS Linux 7.3.5-2-cachyos. I rebuilt the Vulkan harnesses from this revision and selected the NVIDIA device explicitly.

Ran the PR’s synthetic fixture through scripts/run_gpu_tests.py --build runtime/build/linux --filter <fixture> --require-pass. The shader translated and passed Vulkan SPIR-V validation. GPU readback passed:

  • cs_w32_fcmpswap — 0 1065353216 2143289344 1065353216 2147483648 1077936128 1065353216 2143289344.

AI-assisted verification with synthetic inputs.

ds_cmpst_f32 / ds_cmpst_rtn_f32, global_atomic_fcmpswap and
buffer_atomic_fcmpswap raised Unsupported. They store DATA when M equals
CMP as binary32 (-0 == +0, NaN never matches), which is not the bit compare
OpAtomicCompareExchange does, so float_cmpswap_loop runs a CAS loop (initial
read an OpAtomicLoad): read M, pick DATA or M by the float compare, swap that
in if M is unchanged. Operands follow ds_cmpst_b32 / cmpswap; bounds,
alignment, glc and inactive lanes follow their integer siblings.

tests/semantic/test_float_cmpswap.py covers all four, incl. 32 lanes on one
dword. GPU fixture runtime/test/shaders/cs_w32_fcmpswap.asm (with its CPU
test). docs/design.md row added.
@Etr0p

Etr0p commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 052333d (the current head, newer than the runs above) on AMD Radeon 610M (RDNA2 iGPU, AMD 26.11.2 / 32.0.21045.29003, subgroup 32..64) and NVIDIA GeForce RTX 5070 Ti Laptop GPU (Blackwell, 621.24, subgroup 32..32), Windows 11 Home 26200: pass.

Same laptop, one GPU at a time through LEONIDA_VK_DEVICE. Test programs rebuilt from this head with llvm-mingw 23.1.6; llvm-mc 23.1.6 (conda-forge), SPIRV-Tools v2026.4 (Vulkan SDK 1.4.363.0), Python 3.13.14.

scripts/run_gpu_tests.py (full) Result cs_w32_fcmpswap
Radeon 610M, native 196/218 passed, 22 skipped, 0 failed PASS 0 1065353216 2143289344 1065353216 2147483648 1077936128 1065353216 2143289344
RTX 5070 Ti Laptop, native 171/218 passed, 47 skipped, 0 failed PASS, the same words
RTX 5070 Ti Laptop, LEONIDA_W64_EMULATE=1 202/218 passed, 16 skipped, 0 failed PASS, the same words

So the fixture gives the same eight words on RDNA2 with AMD's Windows driver and on Blackwell, natively and under wave64 emulation. I did not run the CPU tests of this PR. One run of each. No game files. AI-assisted (Claude Code).

@bobcatchris

Copy link
Copy Markdown
Contributor

Tested 052333da2b8f48092c19108f0abcdd39b47b053c on AMD Radeon Pro V540 (Navi 12; tools/hw_oracle reports gfx1011), RADV Mesa 25.2.8-0ubuntu0.24.04.4, Ubuntu 24.04.4, Linux 7.0.0-31-generic, Vulkan 1.4.318. Cards pinned with DRI_PRIME=pci-0000_1c:00.0! and pci-0000_1f:00.0! (one process each).

  • Command: python3 -I scripts/run_gpu_tests.py --filter cs_w32_fcmpswap --build runtime/build/linux: 1/1 passed (8 words exact) on both cards.
  • Command: python3 -I scripts/run_gpu_tests.py --build runtime/build/linux: 189/218 passed, 27 skipped, 2 failed on both cards (222 shaders translated, 222 pass spirv-val). PR base 98fa503f in a separate worktree with the same toolchain: 188/217 passed, 27 skipped, 2 failed — one extra passing test, no regression.
  • The two failures (cs_signed_zero_nan, cs_w32_salu64) are pre-existing with identical words on base.
  • Command: pytest -q tests/semantic/test_fcmpswap_fixture.py tests/semantic/test_float_cmpswap.py: 10 passed. Built with Khronos Vulkan-Headers 1.4.335 locally (-DVulkan_INCLUDE_DIR=...), GCC 13.3.0, llvm-mc 21.1.8, SPIRV-Tools 2026.1.

Counts and pass/fail only; no game data. No code changes.

AI-assisted.

@junaydirfan

Copy link
Copy Markdown

Tested 052333da merged into main 98fa503f on Linux (CachyOS, kernel 7.3.5), llvm-mc 23.1.5, LEONIDA_W64_EMULATE=1, test programs built from main (this PR changes no C++): pass.

GPU driver run_gpu_tests.py main
Intel Raptor Lake-S iGPU (Xe-LP), subgroup 8..32 Mesa ANV 26.3.1 187/218 passed, 31 skipped, 0 failed 186/217
RTX 4080 Laptop GPU (Ada), subgroup 32 NVIDIA 620.73.04 202/218 passed, 16 skipped, 0 failed 201/217

New in this PR:

  • cs_w32_fcmpswap: Intel PASS, 0 1065353216 2143289344 1065353216 2147483648 1077936128 1065353216 2143289344; RTX 4080 PASS, 0 1065353216 2143289344 1065353216 2147483648 1077936128 1065353216 2143289344

Every other test has the same result as on main on both GPUs.

@jimokulou2-ops

Copy link
Copy Markdown

Tested 052333d merged onto main 98fa503 (clean merge) on AMD Radeon RX 9070 XT (RDNA4), AMD 26.11.2 (32.0.32029.2010, LLPC, Vulkan 1.4.359), Windows 11 Pro 26300: pass. A Windows AMD-driver (RDNA4, native wave64) data point next to the runs above.

  • Test programs built from main with llvm-mingw (the PR doesn't touch the runtime C++), llvm-mc 23.1.6 (conda-forge), Vulkan SDK 1.4.363.0, LEONIDA_VK_DEVICE=9070.
  • scripts/run_gpu_tests.py, full suite: 203/218 passed, 15 skipped, 0 failed; 222 shaders translated, 222 pass spirv-val. main 98fa503 on the same machine: 202/217, the same 15 skipped. The only difference is the new test:
    • cs_w32_fcmpswap: PASS 0 1065353216 2143289344 1065353216 2147483648 1077936128 1065353216 2143289344
  • tests/semantic/test_fcmpswap_fixture.py: 4 OK; tests/semantic/test_float_cmpswap.py: 6 OK.
  • tests/semantic/regen_fixtures.py --check: clean.

No game files. AI-assisted (Claude Code).

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @Kev-Ball, @Etr0p (Radeon 610M, RTX 5070 Ti native and emulated), @bobcatchris, @junaydirfan (Raptor Lake ANV, RTX 4080 Laptop) and @jimokulou2-ops. cs_w32_fcmpswap gives the same eight words everywhere, on the current head 052333da; nothing is pending.

@lunarminus

Copy link
Copy Markdown

Tested 052333da merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • What was tested: the merge was a fast-forward, because this PR is rebased on main 98fa503f, a descendant of d0835dd9. So the tree tested is 052333da itself.
  • Build: test programs rebuilt from that tree (CMake RelWithDebInfo). The PR's commit changes no runtime C++ or CMake against 98fa503f.
  • CPU tests, all OK:
    • tests/semantic: test_float_cmpswap.py 6, test_fcmpswap_fixture.py 4, test_global_atomics.py 12, test_lds_atomics_values.py 7, test_atomic_inc_dec.py 11, test_lds_add_f32.py 5.
    • tests/test_shader_checks.py 79, tests/test_run_gpu_tests.py 41.
    • tests/semantic/regen_fixtures.py --check: clean.
  • Negative control: this PR's test_float_cmpswap.py against 98fa503f's translator gives FAILED (errors=30), as the description says.
  • scripts/run_gpu_tests.py, full suite: 203/218 passed, 15 skipped, 0 failed, both natively and with LEONIDA_W64_EMULATE=1. 222 shaders translated, 222 pass spirv-val.
  • Per-test comparison with d0835dd9 without the PR (196/210, 14 skipped, in each mode):
    • Every test in that baseline has the same result.
    • 8 names are new: cs_smem_sconst_off, ps_far_branch, ps_sample_c, ps_sample_c_b, ps_texture_cl and ps_texture_b_cl PASS; ps_m2_literal SKIP; cs_w32_fcmpswap PASS.
    • A control run on main 98fa503f with the same test programs gives 202/217 passed, 15 skipped, in both modes. The only difference from this PR is cs_w32_fcmpswap, so the other 7 names come from main.
  • New fixture alone: run_gpu_tests.py --filter cs_w32_fcmpswap --require-pass gives 1/1 passed in both modes, with 0 1065353216 2143289344 1065353216 2147483648 1077936128 1065353216 2143289344. These are the same words as the runs above.

One run of each. No game files.

AI-assisted (Claude Code).

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @lunarminus (Radeon 760M, RDNA3, RADV 26.3.1), on the current head 052333da. Nothing is pending.

# Conflicts:
#	runtime/test/shaders/check.py
#	scripts/run_gpu_tests.py
#	tests/semantic/regen_fixtures.py

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review

Reviewed change in PR #3153: rdna2spirv: ds_cmpst_f32 and the global/buffer fcmpswap atomics.

Scope: docs/design.md, runtime/test/shaders/check.py, runtime/test/shaders/cs_w32_fcmpswap.asm, +6 more
Diff: +396 / -10 across 9 file(s).

The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.

Reviewed by shayderrr via automated batch review.

@shayderrr

Copy link
Copy Markdown
Collaborator

Thanks @LouisRiverstone - I went through rdna2spirv: ds_cmpst_f32 and the global/buffer fcmpswap atomics and the diff around docs/design.md. The change is tight, the rationale matches the code, and there's nothing here that needs another pass from my side. Approved and squash-merging it into main now. Nice work.

@shayderrr
shayderrr merged commit 0f2b802 into ItsNotRexed:main Nov 23, 2026
0 of 5 checks passed
@javdc

javdc commented Nov 23, 2026

Copy link
Copy Markdown

Tested b8440e8 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass.

  • pytest tests/semantic/test_fcmpswap_fixture.py tests/semantic/test_float_cmpswap.py -q: 10 passed, 38 subtests passed.
  • Targeted GPU filter cs_w32_fcmpswap: 1/1 pass.
  • Full GPU suite (python3 -I scripts/run_gpu_tests.py --build /home/deck/opencode/Leonida/runtime/build): 213/233 passed, 16 skipped, 0 failed (expected skips; total includes the new fixture).

No runtime C++ changes in this PR; tested from the PR worktree against the existing main runtime build.

AI-assisted (OpenCode).

@byPreaZy

Copy link
Copy Markdown

Corpus check on a second copy of the same package (26,503 disasm listings, counts only): ds_cmpst_f32 has 0 occurrences (the only ds_cmpst in the corpus is 2x ds_cmpst_rtn_b32), and fcmpswap has 0 occurrences (the 46 buffer_atomic_cmpswap and 1 image_atomic_cmpswap are the integer forms, which print without the f). The new f32 compare paths are latent on the game corpus, consistent with GPU-fixture-only coverage here. Counted with grep -o on Windows, AI-assisted.

@DavidM1911

Copy link
Copy Markdown

Tested b8440e8 on two Vulkan devices, Windows 11, Vulkan SDK 1.4.363, MSVC 14.50, llvm-mc 23.1.6 (AMDGPU, LLVM-MinGW build):

  • tests/semantic/test_fcmpswap_fixture.py: 4/4 OK, test_float_cmpswap.py: 6/6 OK: OK.
  • runtime/test/shaders/build.py: 262/262 translated, all pass spirv-val.
  • check.py, NVIDIA GeForce RTX 3060 Ti (driver 610.88): cs_w32_fcmpswap ok; 169/204 pass, 35 skipped, 0 failed.
  • check.py, AMD Radeon(TM) Graphics iGPU (Ryzen 9 7900X, gfx1036, driver 24.10.24, 128-byte push constants): cs_w32_fcmpswap ok; 104/204 pass, 97 skipped, 0 failed.

AI-assisted. No game files.

@bobcatchris

Copy link
Copy Markdown
Contributor

Re-ran the independent RDNA1/RADV check at the current head b8440e82963082e60095685084867c4cd40e5b74 (my earlier result was at 052333da, so the head changed). AMD Radeon Pro V540 (Navi 12; tools/hw_oracle reports gfx1011), RADV Mesa 25.2.8-0ubuntu0.24.04.4, Ubuntu 24.04.4, kernel 7.0.0-31-generic, Vulkan 1.4.318, subgroup 32..64. Cards pinned with DRI_PRIME=pci-0000_1c:00.0! and pci-0000_1f:00.0!, one process each.

  • python3 -I scripts/run_gpu_tests.py --filter cs_w32_fcmpswap --build runtime/build/linux: 1/1 passed on both cards.
  • Full python3 -I scripts/run_gpu_tests.py --build runtime/build/linux: 203/233 passed, 29 skipped, 1 failed on both cards (239 shaders translated, 239 pass spirv-val). The main side of this merge, 561b65a8, gives 202/232, 29 skipped, 1 failed with the same toolchain — one extra passing test, no regression.
  • pytest -q tests/semantic/test_fcmpswap_fixture.py tests/semantic/test_float_cmpswap.py: 10 passed.
  • The single failure (cs_w32_salu64, with the words main currently produces) is unchanged from the control worktree.
  • Toolchain: Khronos Vulkan-Headers 1.4.335 locally (-DVulkan_INCLUDE_DIR=...), GCC 13.3.0, llvm-mc 21.1.8, SPIRV-Tools 2026.1.

Counts and pass/fail only; no game data. No code changes.

AI-assisted.

benthomashull-commits added a commit to benthomashull-commits/Leonida that referenced this pull request Nov 23, 2026
…r fcmpswap atomics

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.