Skip to content

feat(shader): implement the float and 64-bit inc/dec flat and global atomics - #506

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
adriadam10:feat/global-atomics-float
Oct 5, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
adriadam10:feat/global-atomics-float

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

What

This implements the eight FLAT/GLOBAL atomics that #491 left throwing (16 with both segments): {flat,global}_atomic_fcmpswap, fmin, fmax, fcmpswap_x2, fmin_x2, fmax_x2, inc_x2, dec_x2. Before this, the decoder threw FLAT opcode is not supported for each of them.

They run through the same BDA atomic path as the integer ones (EmitBdaAtomic). The value is computed in a compare-exchange loop (AtomicUpdateTyped, on u32 or u64) with the rules #332 measured for the buffer forms (AtomicFloatBits). The float compare and minNum/maxNum work on the raw bits, so the driver's denormal and NaN float controls don't matter:

  • fcmpswap(_x2): mem = (mem == cmp) ? src : mem, compared as floats: −0 equals +0, NaN equals nothing, denormals compare exactly. src is in vdata[0] ([0:1] for x2) and cmp in vdata[1] ([2:3]), the same as the integer cmpswap.
  • fmin/fmax(_x2): IEEE minNum/maxNum, with −0 < +0. A signalling NaN operand gives that NaN quieted (src first). A quiet NaN loses to a number. Two quiet NaNs give src.
  • inc_x2/dec_x2: the 32-bit inc/dec wrap rule on u64.

AtomicFloatBits gets compareSwap, increment and decrement, and the buffer forms from #332 now call them, so each rule is written once.

Opcodes from llvm-mc -mcpu=gfx1013 -show-encoding: fcmpswap 0x3e, fmin 0x3f, fmax 0x40, inc_x2 0x5c, dec_x2 0x5d, fcmpswap_x2 0x5e, fmin_x2 0x5f, fmax_x2 0x60.

Depends on #491 (integer flat/global atomics, which includes #390) and #332 (float buffer atomics, which includes #321). Their commits are included here. Only the last commit is this PR.

Behaviour measured on HW

Radeon 660M (gfx1035, same FLAT encoding as gfx1013), with the memory in the coarse-grained pool (float atomics aren't performed on fine-grained system memory, see #332). Every pair of 16 f32 or f64 values was used: ±0, ±1, 1.5, −2.5, ±inf, quiet NaNs with and without payload, signalling NaNs, denormals, the largest finite value and the smallest normal. The fcmpswap comparator was the memory value, the memory with its sign flipped, another value, or the data. inc/dec_x2 used 16 integer edge values (0, 1, 2³²−1, 2³², 2⁶³, 2⁶⁴−1…) plus random rows with limit = mem or mem + 1. Each op ran through global_* and through flat_* with a 64-bit VGPR address: 4160/4160 rows match the model above, for both the returned pre-op value and the stored value. Global and flat gave the same results.

Tested

Arch Linux, RADV (Radeon 660M) plus lavapipe (local Mesa and the CI version, Ubuntu Mesa 25.2.8).

  • New execution test GlobalAtomicsFloat: 8 atomics with 64 HW rows each (512 rows), picked to cover every class pair. fcmpswap, fmax, fcmpswap_x2, fmin_x2 and inc_x2 go through global_*, while fmin, fmax_x2 and dec_x2 go through flat_*. It runs as wave32 and wave64 and checks the returned value, the stored value, and that nothing else in the 64 KiB guest block changes. It takes 6 s on CI's lavapipe.
  • GlobalAtomics, BufferAtomicsFloat and BufferAtomicsIncDec64 still pass (the buffer forms now use the shared helpers).
  • Negative checks: the test fails if fcmpswap compares bits (memory 0x0 … comparator 0x80000000), if fmin and fmax are swapped, if fmax picks by order without the NaN rules, if inc_x2/dec_x2 don't wrap, or if the flat fcmpswap drops its comparator.
  • Full Release build plus ctest: 188/189. The one failure, agc_driver_pixel_helper_lanes, also fails on main on local RADV since fix(recompiler): start pixel waves without their helper invocations in EXEC #305.

Checklist

@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Progress report (00407df → c67634a)

📈 GPU shader instructions: 93.65% (+5.49%, +64 implemented instructions)

✅ 64 implemented
Encoding Name
FLAT FLAT_ATOMIC_ADD
FLAT FLAT_ATOMIC_ADD_X2
FLAT FLAT_ATOMIC_AND
FLAT FLAT_ATOMIC_AND_X2
FLAT FLAT_ATOMIC_CMPSWAP
FLAT FLAT_ATOMIC_CMPSWAP_X2
FLAT FLAT_ATOMIC_DEC
FLAT FLAT_ATOMIC_DEC_X2
FLAT FLAT_ATOMIC_FCMPSWAP
FLAT FLAT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MAX_X2
GLOBAL GLOBAL_ATOMIC_SMIN
GLOBAL GLOBAL_ATOMIC_SMIN_X2
GLOBAL GLOBAL_ATOMIC_SUB
GLOBAL GLOBAL_ATOMIC_SUB_X2
GLOBAL GLOBAL_ATOMIC_SWAP
GLOBAL GLOBAL_ATOMIC_SWAP_X2
GLOBAL GLOBAL_ATOMIC_UMAX
GLOBAL GLOBAL_ATOMIC_UMAX_X2
GLOBAL GLOBAL_ATOMIC_UMIN
GLOBAL GLOBAL_ATOMIC_UMIN_X2
GLOBAL GLOBAL_ATOMIC_XOR
GLOBAL GLOBAL_ATOMIC_XOR_X2

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks. I looked at the last commit only, as asked. The opcodes match LLVM's gfx1013 encodings (fcmpswap/fmin/fmax 0x3e to 0x40, the _x2 forms 0x5e to 0x60, inc/dec _x2 0x5c/0x5d), the 64-bit inc/dec wrap rules match the ISA, and the float ops reuse the NaN and signed-zero handling from #332, so the result doesn't depend on the host's NaN behaviour. It passes here together with the rest of the stack.

Since it carries #390, #491, #321 and #332, which are still open, I'll come back to it once those are in. A rebase down to this commit then would make it quick to merge; it touches #332's buffer atomic emitters, so I'll also run it through my PPSA21564 check at that point.

@adriadam10

Copy link
Copy Markdown
Collaborator Author

Rebased on current main: #321 and #332 are merged and dropped from the branch; the #390 and #491 commits are patch-identical to those PRs' heads and the last commit applied unchanged. agc_driver_global_atomics_float_tests passes on RADV and lavapipe, full ctest green on RADV apart from the known agc_driver_pixel_helper_lanes.

@adriadam10
adriadam10 force-pushed the feat/global-atomics-float branch from c8dada7 to 6c95d6c Compare October 5, 2026 01:39
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for the rebase, and you're right that the #390 and #491 commits here are patch-identical to those PRs, and your last commit applied unchanged. agc_driver_global_atomics_float passes here on the merged branch.

One merge-order detail, though: patch-identical isn't quite enough for GitHub. #390's branch is at 673401b, #491 carries an older copy of that commit (6a58101), #495 another one (6ce4b28), and this branch a third (357bb14). Merged as they stand, #390 and then #491, #495 or this one conflict in ResourceTracker.cpp, SpirvBda.hpp and SpirvBdaRead.cpp. If the chain shared one set of commits, each PR would merge cleanly after the one before it. The simplest way I can see: rebase #491 onto #390's head, then this one and #495 onto #491's new head. I checked that main plus 357bb14 (your copy of #390) and then #569 merges cleanly, so #569 doesn't need to change for this.

#390 and #491 are still waiting on my PPSA21564 check (PPSA21564 has a few global_load_dword* shaders), so there's no rush; the float and 64-bit atomics here aren't in any PPSA21564 shader.

DotDebian and others added 3 commits October 5, 2026 05:05
flat_store_* and global_store_* decoded and translated, but a store whose
segment is not scratch was refused when the SPIR-V was emitted ("writable
FLAT/GLOBAL addresses require GPU ownership tracking").

Such a store now goes through the BDA page table like a store through a
GPU-selected V#: the write lookup needs Write permission, which only a
writable registered range imported in place has, and the written page is
noted for the host to mark GPU-written. Byte and short stores, and dword
stores to an address that is not dword aligned, are stored byte by byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…atomics

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the feat/global-atomics-float branch from 6c95d6c to c67634a Compare October 5, 2026 03:06
@adriadam10

Copy link
Copy Markdown
Collaborator Author

Thanks, done: #491, #495 and this PR now share the same commits. #491 was rebased onto current main (be866e4 = #390's patch, then 038ded6), and #495 and this branch sit directly on 038ded6, each with only its own commit on top. A rebase onto #390's head itself didn't work: 673401b is based on 313de1c, and main has since added the FLAT D16 rows and the float64 analysis next to the lines #491 changes, and this commit needs main's newer atomic helpers. I simulated the merges with git merge-tree: #390 → #491 → #495 → this one merges cleanly at every step (also #491 before #390, and #569 after #390). agc_driver_global_atomics, agc_driver_flat_store, agc_driver_flat_cache_bits and agc_driver_global_atomics_float pass on RADV and lavapipe on their branches.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Gated on PPSA21564 on top of #491: no visual or FPS change.

@oneandonlydean
oneandonlydean merged commit 3655c2a into boykopovar:main Oct 5, 2026
3 checks passed
@adriadam10
adriadam10 deleted the feat/global-atomics-float branch October 5, 2026 06:47
thuanquang added a commit to thuanquang/AnyPS5 that referenced this pull request Oct 21, 2026
…mics

On RDNA2 the image, buffer and global float atomics (fmin, fmax,
fcmpswap and the _x2 forms) flush both operands to a signed zero when
bit 0 of the shader's denormal field is clear, as the LDS forms do: the
f32 field for the 32-bit forms, the f16/f64 field for _x2. Only the
LDS forms flushed here. floatAtomicFlush (was sharedFloatFlush) now
sets MemoryInfo::flushDenormals for every float atomic, and
AtomicFloatBits applies it in minMax and compareSwap.

The float atomic tests from boykopovar#332, boykopovar#506 and boykopovar#562 were measured with
denormals kept, so they now set FLOAT_MODE 0xf0.

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

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants