feat(shader): implement buffer_atomic_inc/dec and the 64-bit integer buffer atomics #321

Merged
adriadam10 merged 1 commit from upstream-pr/321 into main 2026-10-04 22:39:23 +00:00
adriadam10 commented 2026-10-02 05:17:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T05:17:12Z.


What

These threw "MUBUF opcode is not supported":

  • buffer_atomic_inc, buffer_atomic_dec
  • buffer_atomic_cmpswap_x2
  • buffer_atomic_{add,sub,smin,umin,smax,umax,and,xor}_x2

The 64-bit ops get IR ops BufferAtomic{IAdd,ISub,SMin,UMin,SMax,UMax,And,Xor,CmpSwap}64, which reuse BufferAtomic64, the native 64-bit SPIR-V atomic path that swap_x2 and or_x2 already use. cmpswap_x2 does an OpAtomicCompareExchange with vdata[0:1] as the new value and vdata[2:3] as the comparator, like the 32-bit cmpswap. inc/dec (BufferAtomicInc32/Dec32) use the compare-exchange loop with the existing AtomicIncrement/AtomicDecrement helpers (old >= data ? 0 : old + 1, old == 0 || old > data ? data : old - 1). With glc every op returns the old value, as before.

Test agc_driver_buffer_atomics: one wave32 shader. Each op runs on its own slot of the output buffer, set to a known value first. The test checks the memory afterwards and the glc return values of inc, dec, add_x2 and cmpswap_x2. Inputs are signed/unsigned 64-bit edges (0, -1, INT64_MIN/MAX), random values, small values for the inc/dec wrap, and matching/non-matching compare values for cmpswap_x2.

Tested

Linux, full ctest (99) passes.

  • RADV (Radeon 660M) and lavapipe: the test passes.
  • Without the change it fails with "MUBUF opcode is not supported".

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: #251 (test harness); review only the last commit
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4712965882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/321). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T05:17:12Z. --- ### What These threw "MUBUF opcode is not supported": - `buffer_atomic_inc`, `buffer_atomic_dec` - `buffer_atomic_cmpswap_x2` - `buffer_atomic_{add,sub,smin,umin,smax,umax,and,xor}_x2` The 64-bit ops get IR ops `BufferAtomic{IAdd,ISub,SMin,UMin,SMax,UMax,And,Xor,CmpSwap}64`, which reuse `BufferAtomic64`, the native 64-bit SPIR-V atomic path that `swap_x2` and `or_x2` already use. `cmpswap_x2` does an `OpAtomicCompareExchange` with `vdata[0:1]` as the new value and `vdata[2:3]` as the comparator, like the 32-bit `cmpswap`. `inc`/`dec` (`BufferAtomicInc32/Dec32`) use the compare-exchange loop with the existing `AtomicIncrement`/`AtomicDecrement` helpers (`old >= data ? 0 : old + 1`, `old == 0 || old > data ? data : old - 1`). With `glc` every op returns the old value, as before. Test `agc_driver_buffer_atomics`: one wave32 shader. Each op runs on its own slot of the output buffer, set to a known value first. The test checks the memory afterwards and the `glc` return values of `inc`, `dec`, `add_x2` and `cmpswap_x2`. Inputs are signed/unsigned 64-bit edges (0, -1, INT64_MIN/MAX), random values, small values for the inc/dec wrap, and matching/non-matching compare values for `cmpswap_x2`. ### Tested Linux, full ctest (99) passes. - RADV (Radeon 660M) and lavapipe: the test passes. - Without the change it fails with "MUBUF opcode is not supported". ### Checklist - [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: #251 (test harness); review only the last commit - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-02 05:17:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T05:17:34Z.


Progress report (2cf901b → ae36aaf)

📈 GPU shader instructions: 81.22% (+0.95%, +11 implemented instructions)

✅ 11 implemented
Encoding Name
MUBUF BUFFER_ATOMIC_ADD_X2
MUBUF BUFFER_ATOMIC_AND_X2
MUBUF BUFFER_ATOMIC_CMPSWAP_X2
MUBUF BUFFER_ATOMIC_DEC
MUBUF BUFFER_ATOMIC_INC
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:5946042926 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/321#issuecomment-5946042926). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-02T05:17:34Z. --- <!-- progress-report --> ### Progress report (2cf901b → ae36aaf) 📈 **GPU shader instructions**: 81.22% (+0.95%, +11 implemented instructions) <details> <summary>✅ 11 implemented</summary> | Encoding | Name | | - | - | | MUBUF | `BUFFER_ATOMIC_ADD_X2` | | MUBUF | `BUFFER_ATOMIC_AND_X2` | | MUBUF | `BUFFER_ATOMIC_CMPSWAP_X2` | | MUBUF | `BUFFER_ATOMIC_DEC` | | MUBUF | `BUFFER_ATOMIC_INC` | | 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 09:57:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:57:19Z.


This passed my PPSA21564 check, but it now conflicts with main after #319, #329, #330 and #331 merged. Could you rebase? Then it's ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978751890 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/321#issuecomment-5978751890). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T09:57:19Z. --- This passed my PPSA21564 check, but it now conflicts with main after #319, #329, #330 and #331 merged. Could you rebase? Then it's ready to merge from my side.
adriadam10 commented 2026-10-04 10:01:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T10:01:58Z.


Rebased on current main (conflict was the MUBUF table next to the new D16 format rows from #319-#331, both kept). BufferAtomics passes on RADV and lavapipe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978801670 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/321#issuecomment-5978801670). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T10:01:58Z. --- Rebased on current main (conflict was the MUBUF table next to the new D16 format rows from #319-#331, both kept). BufferAtomics passes on RADV and lavapipe.
oneandonlydean commented 2026-10-04 22:37:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:37:48Z.


Thanks for the rebase. The rebased commit has exactly the content I ran through my PPSA21564 check, and the full ctest passes here on current main. Ready to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985217613 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/321#issuecomment-5985217613). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T22:37:48Z. --- Thanks for the rebase. The rebased commit has exactly the content I ran through my PPSA21564 check, and the full ctest passes here on current main. Ready to merge.
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!321
No description provided.