feat(shader): implement image_atomic_fmin, fmax and fcmpswap #562

Merged
adriadam10 merged 3 commits from upstream-pr/562 into main 2026-10-04 22:44:48 +00:00
adriadam10 commented 2026-10-04 21:01:53 +00:00 (Migrated from github.com)

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.

Opcode Semantics (measured on an RDNA2 GPU)
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 like image_atomic_cmpswap
image_atomic_fmin (0x1e) / image_atomic_fmax (0x1f) IEEE minNum/maxNum: −0 < +0. A signalling NaN operand gives that NaN quieted (src first). A quiet NaN loses to a number. Two quiet NaNs give src

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_UINT and a 32_FLOAT T#. Without glc the data VGPR is left untouched, as for the other image atomics.

Implementation:

  • Decoder, IR opcode and dispatch entries next to the integer image atomics.
  • The emitter runs AtomicUpdate's compare-exchange loop on the existing u32 texel pointer, as image_atomic_inc/dec already do. The value is computed on the raw bits through #332's AtomicFloatBits, which is reached through two helpers, AtomicFloatMinMax and AtomicFloatCompareSwap. So the driver's float controls (denormals, NaN payloads) don't matter, and no Vulkan float-atomic feature is needed.
  • Image atomics are still only accepted on 32_UINT textures (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):

  • 800 rows, measured on hardware: every pair of 20 special values (±0, ±1, ±inf, qNaN/sNaN with payloads, ±denormal min/max, ±π, max finite, min normal), once with cmp = src and once with cmp = old.
  • Each row checks the returned value and the resulting texel for fmin, fmax and fcmpswap with glc, and fmin without glc. Everything is compared bit for bit. The emitted code only uses integer ops on the bits, so NVIDIA's NaN canonicalisation doesn't apply.
  • It runs as wave32, as wave64 and as wave64 split into two 32-wide halves (ComputeTarget(32)).
  • 0 s cold on CI's lavapipe (Mesa 25.2.8).

The test fails without the change in each of these cases (each checked separately):

  • fmin and fmax swapped
  • a signed-integer min/max instead of the float rule
  • fcmpswap comparing bits instead of floats
  • src and cmp swapped
  • the comparator not read

Release build: full ctest passes except agc_driver_pixel_helper_lanes, which also fails on main on local RADV.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #332 (on #321), whose two commits are included here. Only the last commit is new.
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4737599260 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/562). Originally posted by [adriadam10](https://github.com/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. | Opcode | Semantics (measured on an RDNA2 GPU) | |---|---| | `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 like `image_atomic_cmpswap` | | `image_atomic_fmin` (0x1e) / `image_atomic_fmax` (0x1f) | IEEE minNum/maxNum: −0 < +0. A signalling NaN operand gives that NaN quieted (src first). A quiet NaN loses to a number. Two quiet NaNs give src | 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_UINT` and a `32_FLOAT` T#. Without `glc` the data VGPR is left untouched, as for the other image atomics. Implementation: - Decoder, IR opcode and dispatch entries next to the integer image atomics. - The emitter runs `AtomicUpdate`'s compare-exchange loop on the existing u32 texel pointer, as `image_atomic_inc/dec` already do. The value is computed on the raw bits through #332's `AtomicFloatBits`, which is reached through two helpers, `AtomicFloatMinMax` and `AtomicFloatCompareSwap`. So the driver's float controls (denormals, NaN payloads) don't matter, and no Vulkan float-atomic feature is needed. - Image atomics are still only accepted on `32_UINT` textures (`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`): - 800 rows, measured on hardware: every pair of 20 special values (±0, ±1, ±inf, qNaN/sNaN with payloads, ±denormal min/max, ±π, max finite, min normal), once with `cmp = src` and once with `cmp = old`. - Each row checks the returned value and the resulting texel for fmin, fmax and fcmpswap with `glc`, and fmin without `glc`. Everything is compared bit for bit. The emitted code only uses integer ops on the bits, so NVIDIA's NaN canonicalisation doesn't apply. - It runs as wave32, as wave64 and as wave64 split into two 32-wide halves (`ComputeTarget(32)`). - 0 s cold on CI's lavapipe (Mesa 25.2.8). The test fails without the change in each of these cases (each checked separately): - fmin and fmax swapped - a signed-integer min/max instead of the float rule - fcmpswap comparing bits instead of floats - src and cmp swapped - the comparator not read Release build: full ctest passes except `agc_driver_pixel_helper_lanes`, which also fails on `main` on local RADV. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #332 (on #321), whose two commits are included here. Only the last commit is new. - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-04 21:02:17 +00:00 (Migrated from github.com)

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
Encoding Name
MIMG IMAGE_ATOMIC_FCMPSWAP
MIMG IMAGE_ATOMIC_FMAX
MIMG IMAGE_ATOMIC_FMIN
MUBUF BUFFER_ATOMIC_ADD_X2
MUBUF BUFFER_ATOMIC_AND_X2
MUBUF BUFFER_ATOMIC_CMPSWAP_X2
MUBUF BUFFER_ATOMIC_DEC
MUBUF BUFFER_ATOMIC_DEC_X2
MUBUF BUFFER_ATOMIC_FCMPSWAP
MUBUF BUFFER_ATOMIC_FCMPSWAP_X2
MUBUF BUFFER_ATOMIC_FMAX_X2
MUBUF BUFFER_ATOMIC_FMIN_X2
MUBUF BUFFER_ATOMIC_INC
MUBUF BUFFER_ATOMIC_INC_X2
MUBUF BUFFER_ATOMIC_SMAX_X2
MUBUF BUFFER_ATOMIC_SMIN_X2
MUBUF BUFFER_ATOMIC_SUB_X2
MUBUF BUFFER_ATOMIC_UMAX_X2
MUBUF BUFFER_ATOMIC_UMIN_X2
MUBUF BUFFER_ATOMIC_XOR_X2
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984348898 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/562#issuecomment-5984348898). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T21:02:17Z. --- <!-- progress-report --> ### Progress report (d7f0c49 → d1f7710) 📈 **GPU shader instructions**: 81.99% (+1.72%, +20 implemented instructions) <details> <summary>✅ 20 implemented</summary> | Encoding | Name | | - | - | | MIMG | `IMAGE_ATOMIC_FCMPSWAP` | | MIMG | `IMAGE_ATOMIC_FMAX` | | MIMG | `IMAGE_ATOMIC_FMIN` | | MUBUF | `BUFFER_ATOMIC_ADD_X2` | | MUBUF | `BUFFER_ATOMIC_AND_X2` | | MUBUF | `BUFFER_ATOMIC_CMPSWAP_X2` | | MUBUF | `BUFFER_ATOMIC_DEC` | | MUBUF | `BUFFER_ATOMIC_DEC_X2` | | MUBUF | `BUFFER_ATOMIC_FCMPSWAP` | | MUBUF | `BUFFER_ATOMIC_FCMPSWAP_X2` | | MUBUF | `BUFFER_ATOMIC_FMAX_X2` | | MUBUF | `BUFFER_ATOMIC_FMIN_X2` | | MUBUF | `BUFFER_ATOMIC_INC` | | MUBUF | `BUFFER_ATOMIC_INC_X2` | | MUBUF | `BUFFER_ATOMIC_SMAX_X2` | | MUBUF | `BUFFER_ATOMIC_SMIN_X2` | | MUBUF | `BUFFER_ATOMIC_SUB_X2` | | MUBUF | `BUFFER_ATOMIC_UMAX_X2` | | MUBUF | `BUFFER_ATOMIC_UMIN_X2` | | MUBUF | `BUFFER_ATOMIC_XOR_X2` | </details>
oneandonlydean commented 2026-10-04 22:38:16 +00:00 (Migrated from github.com)

Imported 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 == cmp as a float compare, with DATA[0] = src and DATA[1] = cmp, so dmask 0x3 like cmpswap). The emitter reuses #332's AtomicFloatBits through the existing AtomicUpdate loop on the u32 texel pointer, the same way image inc/dec already work, so the result never depends on the driver's float controls. equal treats -0 and +0 as equal and a NaN as equal to nothing, and minMax is 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_float passes 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.cpp next 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985221048 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/562#issuecomment-5985221048). Originally posted by [oneandonlydean](https://github.com/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 == cmp` as a float compare, with DATA[0] = src and DATA[1] = cmp, so dmask 0x3 like cmpswap). The emitter reuses #332's `AtomicFloatBits` through the existing `AtomicUpdate` loop on the u32 texel pointer, the same way image inc/dec already work, so the result never depends on the driver's float controls. `equal` treats -0 and +0 as equal and a NaN as equal to nothing, and `minMax` is 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_float` passes 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.cpp` next 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!562
No description provided.