feat(shader): implement the float and 64-bit inc/dec flat and global atomics #506
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/506"
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 boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T10:52:12Z.
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 threwFLAT opcode is not supportedfor 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.srcis invdata[0]([0:1]for x2) andcmpinvdata[1]([2:3]), the same as the integercmpswap.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-bitinc/decwrap rule on u64.AtomicFloatBitsgetscompareSwap,incrementanddecrement, 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 throughflat_*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).
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 throughglobal_*, while fmin, fmax_x2 and dec_x2 go throughflat_*. 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,BufferAtomicsFloatandBufferAtomicsIncDec64still pass (the buffer forms now use the shared helpers).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.ctest: 188/189. The one failure,agc_driver_pixel_helper_lanes, also fails onmainon local RADV since #305.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T10:52:33Z.
Progress report (
00407df→c67634a)📈 GPU shader instructions: 93.65% (+5.49%, +64 implemented instructions)
✅ 64 implemented
FLAT_ATOMIC_ADDFLAT_ATOMIC_ADD_X2FLAT_ATOMIC_ANDFLAT_ATOMIC_AND_X2FLAT_ATOMIC_CMPSWAPFLAT_ATOMIC_CMPSWAP_X2FLAT_ATOMIC_DECFLAT_ATOMIC_DEC_X2FLAT_ATOMIC_FCMPSWAPFLAT_ATOMIC_FCMPSWAP_X2FLAT_ATOMIC_FMAXFLAT_ATOMIC_FMAX_X2FLAT_ATOMIC_FMINFLAT_ATOMIC_FMIN_X2FLAT_ATOMIC_INCFLAT_ATOMIC_INC_X2FLAT_ATOMIC_ORFLAT_ATOMIC_OR_X2FLAT_ATOMIC_SMAXFLAT_ATOMIC_SMAX_X2FLAT_ATOMIC_SMINFLAT_ATOMIC_SMIN_X2FLAT_ATOMIC_SUBFLAT_ATOMIC_SUB_X2FLAT_ATOMIC_SWAPFLAT_ATOMIC_SWAP_X2FLAT_ATOMIC_UMAXFLAT_ATOMIC_UMAX_X2FLAT_ATOMIC_UMINFLAT_ATOMIC_UMIN_X2FLAT_ATOMIC_XORFLAT_ATOMIC_XOR_X2GLOBAL_ATOMIC_ADDGLOBAL_ATOMIC_ADD_X2GLOBAL_ATOMIC_ANDGLOBAL_ATOMIC_AND_X2GLOBAL_ATOMIC_CMPSWAPGLOBAL_ATOMIC_CMPSWAP_X2GLOBAL_ATOMIC_DECGLOBAL_ATOMIC_DEC_X2GLOBAL_ATOMIC_FCMPSWAPGLOBAL_ATOMIC_FCMPSWAP_X2GLOBAL_ATOMIC_FMAXGLOBAL_ATOMIC_FMAX_X2GLOBAL_ATOMIC_FMINGLOBAL_ATOMIC_FMIN_X2GLOBAL_ATOMIC_INCGLOBAL_ATOMIC_INC_X2GLOBAL_ATOMIC_ORGLOBAL_ATOMIC_OR_X2GLOBAL_ATOMIC_SMAXGLOBAL_ATOMIC_SMAX_X2GLOBAL_ATOMIC_SMINGLOBAL_ATOMIC_SMIN_X2GLOBAL_ATOMIC_SUBGLOBAL_ATOMIC_SUB_X2GLOBAL_ATOMIC_SWAPGLOBAL_ATOMIC_SWAP_X2GLOBAL_ATOMIC_UMAXGLOBAL_ATOMIC_UMAX_X2GLOBAL_ATOMIC_UMINGLOBAL_ATOMIC_UMIN_X2GLOBAL_ATOMIC_XORGLOBAL_ATOMIC_XOR_X2Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:08:00Z.
Thanks. I looked at the last commit only, as asked. The opcodes match LLVM's gfx1013 encodings (fcmpswap/fmin/fmax 0x3e to 0x40, the
_x2forms 0x5e to 0x60, inc/dec_x20x5c/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.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T01:39:36Z.
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_testspasses on RADV and lavapipe, full ctest green on RADV apart from the knownagc_driver_pixel_helper_lanes.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T02:47:07Z.
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_floatpasses 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 inResourceTracker.cpp,SpirvBda.hppandSpirvBdaRead.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.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T03:06:43Z.
Thanks, done: #491, #495 and this PR now share the same commits. #491 was rebased onto current main (
be866e42= #390's patch, then038ded63), and #495 and this branch sit directly on038ded63, each with only its own commit on top. A rebase onto #390's head itself didn't work:673401b3is based on313de1c5, 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 withgit 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_bitsandagc_driver_global_atomics_floatpass on RADV and lavapipe on their branches.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:04:02Z.
Gated on PPSA21564 on top of #491: no visual or FPS change.