feat(shader): implement the float and 64-bit inc/dec buffer atomics #332
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/332"
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-02T06:47:05Z.
What
This implements the six buffer atomics still missing. It also fixes the existing 32-bit
buffer_atomic_fmin/fmax.buffer_atomic_fcmpswap(0x3e) /_x2(0x5e)mem = (mem == cmp) ? src : mem, compared as floats: −0 equals +0, NaN equals nothing, denormals compare exactlybuffer_atomic_fmin_x2(0x5f) /fmax_x2(0x60)buffer_atomic_inc_x2(0x5c) /dec_x2(0x5d)inc/decfrom #321, on u64Bug: the existing 32-bit
buffer_atomic_fmin/fmax(EmitFloatAtomicReplacement) kept the old value whenever either operand was a NaN or both were zeros. The hardware follows the same rule as the f64 forms above:fmin(qNaN, 1.0)= 1.0fmin(+0, −0)= −0fmin(1.0, sNaN 0x7fa00000)=0x7fe000002048/2048 vectors on hardware. The helper is now unused and is removed.
Implementation:
AtomicUpdate's compare-exchange loop is generalized to a type (AtomicUpdateTyped), andBufferAtomic64Updateruns it on the u64 storage-buffer view that #321 added.AtomicFloatBitsdoes the float compare and minNum/maxNum on the raw bits, for 32 and 64 bits, so the driver's denormal/NaN float controls don't matter.Measuring: float atomics are not performed on fine-grained system memory. The first capture returned zeros, while the integer atomics were fine. The vectors were captured with the buffers in the GPU's coarse-grained pool.
Tests, all values captured on the RDNA2 GPU (ROCm HSA, raw kernels):
agc_driver_buffer_atomics_float: fcmpswap (32/64) returned and stored values, fmin/fmax 32 and 64 across ±0, ±inf, quiet and signalling NaNs with payloads, and denormals.agc_driver_buffer_atomics_inc_dec64: the wrap edges (0, limit, limit ± 1, 2^32, 2^64−1).Tested
Linux, full ctest (101) passes.
fmin_mem0 is 0x7fa00000, expected 0x7fe00000. Without the sNaN quieting:fmin_x2_mem0 is 0xbf800000, expected 0x00000001.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-02T06:47:29Z.
Progress report (
2cf901b→7f291b7)📈 GPU shader instructions: 81.73% (+1.46%, +17 implemented instructions)
✅ 17 implemented
BUFFER_ATOMIC_ADD_X2BUFFER_ATOMIC_AND_X2BUFFER_ATOMIC_CMPSWAP_X2BUFFER_ATOMIC_DECBUFFER_ATOMIC_DEC_X2BUFFER_ATOMIC_FCMPSWAPBUFFER_ATOMIC_FCMPSWAP_X2BUFFER_ATOMIC_FMAX_X2BUFFER_ATOMIC_FMIN_X2BUFFER_ATOMIC_INCBUFFER_ATOMIC_INC_X2BUFFER_ATOMIC_SMAX_X2BUFFER_ATOMIC_SMIN_X2BUFFER_ATOMIC_SUB_X2BUFFER_ATOMIC_UMAX_X2BUFFER_ATOMIC_UMIN_X2BUFFER_ATOMIC_XOR_X2Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-03T09:44:40Z.
Rebased on main. main now has
SharedAtomicUpdatefor the LDS atomics, so this PR no longer carries its ownSharedFloatAtomic: the shared min/max path is main's, unchanged. The buffer side (AtomicFloatBits,BufferAtomic64Update) is as before. Still stacked on #321; review only the last commit.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:57:20Z.
This passed my PPSA21564 check too; it needs a rebase once #321 is rebased, since #319 to #331 are now on main. Then it's ready to merge from my side.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T10:01:59Z.
Rebased on the rebased #321 and current main (same MUBUF table conflict, both sides kept). BufferAtomicsFloat, BufferAtomicsIncDec64 and BufferAtomics pass on RADV and lavapipe.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:37:51Z.
Thanks for the rebase. Both commits have exactly the content I ran through my PPSA21564 check (the first is #321's head), and
agc_driver_buffer_atomics_float,agc_driver_buffer_atomics_inc_dec64andagc_driver_buffer_atomicspass here on current main. Ready to merge right after #321.