feat(shader): implement image_atomic_fmin, fmax and fcmpswap #562
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/562"
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-04T21:01:53Z.
What
This implements the three MIMG float atomics, which threw as unknown opcodes. The ISA sweep found them.
image_atomic_fcmpswap(0x1d)texel = (texel == cmp) ? src : texel, compared as floats: −0 equals +0, NaN equals nothing.vdata[0]= src,vdata[1]= cmp, dmask must be 0x3 likeimage_atomic_cmpswapimage_atomic_fmin(0x1e) /image_atomic_fmax(0x1f)These are the same rules the float buffer atomics follow in #332. On the hardware the image forms gave the same results as the buffer forms (800/800 rows), and the same results on a
32_UINTand a32_FLOATT#. Withoutglcthe data VGPR is left untouched, as for the other image atomics.Implementation:
AtomicUpdate's compare-exchange loop on the existing u32 texel pointer, asimage_atomic_inc/decalready do. The value is computed on the raw bits through #332'sAtomicFloatBits, which is reached through two helpers,AtomicFloatMinMaxandAtomicFloatCompareSwap. So the driver's float controls (denormals, NaN payloads) don't matter, and no Vulkan float-atomic feature is needed.32_UINTtextures (ResourceMaterializer, "atomic image descriptor uses an unsupported format"). A float-format texture keeps throwing there. Accepting one needs a uint view of a float texture in the driver, which belongs in a separate PR.Tested
Arch Linux, RDNA2 iGPU (Radeon 660M), RADV and lavapipe. No title.
New execution test
agc_driver_image_atomics_float_tests(ImageAtomicsFloat.cpp):cmp = srcand once withcmp = old.glc, and fmin withoutglc. Everything is compared bit for bit. The emitted code only uses integer ops on the bits, so NVIDIA's NaN canonicalisation doesn't apply.ComputeTarget(32)).The test fails without the change in each of these cases (each checked separately):
Release build: full ctest passes except
agc_driver_pixel_helper_lanes, which also fails onmainon local RADV.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-04T21:02:17Z.
Progress report (
d7f0c49→d1f7710)📈 GPU shader instructions: 81.99% (+1.72%, +20 implemented instructions)
✅ 20 implemented
IMAGE_ATOMIC_FCMPSWAPIMAGE_ATOMIC_FMAXIMAGE_ATOMIC_FMINBUFFER_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 oneandonlydean on 2026-10-04T22:38:16Z.
Thanks. I checked the encodings with llvm-mc for gfx1013: image_atomic_fcmpswap, image_atomic_fmin and image_atomic_fmax are MIMG opcodes 0x1d, 0x1e and 0x1f, and the RDNA2 ISA guide gives the same semantics you measured (fcmpswap stores src when
tmp == cmpas a float compare, with DATA[0] = src and DATA[1] = cmp, so dmask 0x3 like cmpswap). The emitter reuses #332'sAtomicFloatBitsthrough the existingAtomicUpdateloop on the u32 texel pointer, the same way image inc/dec already work, so the result never depends on the driver's float controls.equaltreats -0 and +0 as equal and a NaN as equal to nothing, andminMaxis the rule I already checked on #332.The first two commits are patch-identical to #321 and #332, so this lands after them. Image atomics are still only accepted on 32_UINT views, and float-format textures keep throwing in the materializer, which is the right place to stop for now.
agc_driver_image_atomics_floatpasses on my NVIDIA machine on current main (with #321 and #332), and fails on main's code.One note for the merge order: #506 also edits
SpirvMemoryInstructions.cppnext to the same helpers and conflicts textually with this one, so whichever lands second needs a small rebase.This only adds encodings that main refused, so it's ready to merge from my side once #321 and #332 are in.