Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
adriadam10:feat/buffer-atomics
Oct 4, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
adriadam10:feat/buffer-atomics

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

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: ci: run the shader execution tests on lavapipe #251 (test harness); review only the last commit
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

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

@github-actions github-actions Bot added build shader core/shader agc libSceAgc* ci .github labels Oct 2, 2026
This was referenced Oct 2, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 3, 2026
@adriadam10
adriadam10 force-pushed the feat/buffer-atomics branch from f074308 to cd9e629 Compare October 3, 2026 09:44
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 3, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

…buffer atomics

buffer_atomic_inc, buffer_atomic_dec, buffer_atomic_cmpswap_x2 and
buffer_atomic_{add,sub,smin,umin,smax,umax,and,xor}_x2 threw in the decoder.
The 64-bit ones use native 64-bit SPIR-V atomics like the existing
swap_x2/or_x2; inc and dec wrap at the data operand through the existing
compare-exchange helpers.

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the feat/buffer-atomics branch from cd9e629 to ae36aaf Compare October 4, 2026 10:01
@adriadam10

Copy link
Copy Markdown
Collaborator Author

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

Copy link
Copy Markdown
Collaborator

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.

@oneandonlydean
oneandonlydean merged commit f83fcdb into boykopovar:main Oct 4, 2026
3 checks passed
@adriadam10
adriadam10 deleted the feat/buffer-atomics branch October 5, 2026 06:47
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 5, 2026
Conflicts resolved:
- libSceAudioPropagation/Export.cpp: upstream's boykopovar#482 + boykopovar#489 version taken; it is
  the same no-propagation model as astrobot's stand-in, with SourceRender and the
  handle-only UnregisterMaterial already in it.
- State.cpp (boykopovar#453): astrobot's resident depth model kept; it already skips the
  tests of an absent plane (boykopovar#453's test is on astrobot since e087a4f).
- Graphics.cpp, State.hpp, ShaderResources.cpp: astrobot's DepthTarget model kept
  (exportIndex, no DepthSurface.hpp), upstream's ThreadOwned include added.
- BdaResources.cpp: astrobot's form with boykopovar#390's message.
- VulkanDevice.cpp, Context.hpp, PacketExecution.cpp: both sides kept
  (calibrated timestamps, host query reset, GDS, memory budget; pipeline stats).
- Spirv: astrobot's split-wave rules first, then boykopovar#608's wave-mask ballot and
  boykopovar#587's host subgroup lane; astrobot's function LDS sizing and boykopovar#573's LDS lock
  both kept; conditionalDepth kept in the atomic update loops; upstream's
  buffer atomics (boykopovar#321 boykopovar#332 boykopovar#594) and 64-bit LDS atomics taken.
- TechnicalDebt.md: both sides, duplicate lines dropped.


Build fixes folded in: the upstream boykopovar#453 test block duplicated next to
astrobot's adapted copy removed; a lost closing brace after the host
query reset block restored; lookupLog() is a function since boykopovar#590; the
duplicate MUTEX_TYPE_ADAPTIVE constant (astrobot's 93b2d0e equals boykopovar#156)
removed; the ops boykopovar#596 drops removed from the masked-select list and the
BDA test message updated (the gate-batch-2 integ commits 559e4fab6 and
2ec968fb5).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build ci .github shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants