feat(shader): implement the integer flat and global atomics #491
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/491"
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-04T08:27:25Z.
What
Implements the 24 integer FLAT/GLOBAL atomics of gfx1013 (
flat_atomic_*andglobal_atomic_*: swap, cmpswap, add, sub, smin, umin, smax, umax, and, or, xor, inc, dec, plus the_x2forms of swap through xor).flat_atomic_inc_x2/dec_x2(0x5c, 0x5d) and their global forms are not in this PR and still throw. Found by the ISA coverage sweep; onmainthe decoder throwsFLAT opcode is not supportedfor all of them. The float ones (fcmpswap, fmin, fmax and their_x2) are not in this PR and still throw.Depends on #390 (DotDebian, stores through FLAT/GLOBAL addresses): the atomics need the same BDA write path (write lookup,
note_bda_write,bdaWrites). Its commit is included here; only the second commit is this PR.llvm-mc -mcpu=gfx1013 -show-encoding) in the FLAT table.glcis accepted for atomics only (it selects the pre-op return); the data operand goes tosource2; withoutglcthe destination isNone, so no VGPR is counted as written. Scratch-segment atomics still throw.AddressAtomic*32/*64with a newAddressAccess::Atomic. They count as side effects, setbdaWritesand, for the 64-bit ones, theInt64Atomicsrequirement the buffer_x2atomics already use.EmitBdaAtomic): oneget_bda_write_pointerlookup for the 4 or 8 bytes, then the native atomic on thePhysicalStorageBufferpointer, thennote_bda_write. A misaligned address records anUnalignedfault and returns 0, the way theEmitBdaWriteV# store does. A read-only or unmapped range is not written and returns 0. inc/dec use the existingAtomicUpdateCAS loop withAtomicIncrement/AtomicDecrement(the same rule as the LDS/image atomics). The VGPR limit also counts the atomic's data registers (x2 cmpswap = 4).Behaviour measured on HW
Every opcode was run on a Radeon 660M (gfx1035, same VMEM atomics as gfx1013) with
global_atomic_* ... glcover 32 lanes of edge values (0, 1, INT_MIN/MAX, -1, carries across the 64-bit halves, inc/dec at and around the limit, cmpswap hit and miss). That's 768 rows, and a Python model matches all of them: integer semantics as in the ISA doc, inc =old >= src ? 0 : old + 1, dec =old == 0 || old > src ? src : old - 1, cmpswap =old == cmp ? src : oldwith data invdata[0]([0:1]for x2) and the comparator invdata[1]([2:3]), return = pre-op value.Tested
Arch Linux, RADV (Radeon 660M) plus lavapipe (local Mesa and the CI version, Ubuntu Mesa 25.2.8): new execution test
GlobalAtomics. 64 threads run as wave32 and wave64, and a third dispatch runs against a read-only range:flat_atomic_xorthrough a 64-bit VGPR address, a contended non-returningglobal_atomic_addonto one dword (the sum is checked, and every lane's return must be a distinct prefix sum), a non-returningglobal_atomic_orunder a partial EXEC, and the read-only range left untouched.The test fails without each piece of the fix (negative checks): cmpswap operand order, x2 comparator register offset, inc vs dec, signed vs unsigned min, EXEC ignored,
glcreturn dropped, and x2 data width (the IR validator rejects it). Droppingnote_bda_writeis not visible to the test (as in #390's FlatStore).Full Release build plus
ctest: 174/175; the one failure,agc_driver_pixel_helper_lanes, also fails onmainon local RADV since #305.GlobalAtomicstakes ~34 s on lavapipe (BDA lookups are slow there; FlatStore takes ~80 s locally).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-04T08:27:46Z.
Progress report (
00407df→038ded6)📈 GPU shader instructions: 92.28% (+4.12%, +48 implemented instructions)
✅ 48 implemented
FLAT_ATOMIC_ADDFLAT_ATOMIC_ADD_X2FLAT_ATOMIC_ANDFLAT_ATOMIC_AND_X2FLAT_ATOMIC_CMPSWAPFLAT_ATOMIC_CMPSWAP_X2FLAT_ATOMIC_DECFLAT_ATOMIC_INCFLAT_ATOMIC_ORFLAT_ATOMIC_OR_X2FLAT_ATOMIC_SMAXFLAT_ATOMIC_SMAX_X2FLAT_ATOMIC_SMINFLAT_ATOMIC_SMIN_X2FLAT_ATOMIC_SUBFLAT_ATOMIC_SUB_X2FLAT_ATOMIC_SWAPFLAT_ATOMIC_SWAP_X2FLAT_ATOMIC_UMAXFLAT_ATOMIC_UMAX_X2FLAT_ATOMIC_UMINFLAT_ATOMIC_UMIN_X2FLAT_ATOMIC_XORFLAT_ATOMIC_XOR_X2GLOBAL_ATOMIC_ADDGLOBAL_ATOMIC_ADD_X2GLOBAL_ATOMIC_ANDGLOBAL_ATOMIC_AND_X2GLOBAL_ATOMIC_CMPSWAPGLOBAL_ATOMIC_CMPSWAP_X2GLOBAL_ATOMIC_DECGLOBAL_ATOMIC_INCGLOBAL_ATOMIC_ORGLOBAL_ATOMIC_OR_X2GLOBAL_ATOMIC_SMAXGLOBAL_ATOMIC_SMAX_X2GLOBAL_ATOMIC_SMINGLOBAL_ATOMIC_SMIN_X2GLOBAL_ATOMIC_SUBGLOBAL_ATOMIC_SUB_X2GLOBAL_ATOMIC_SWAPGLOBAL_ATOMIC_SWAP_X2GLOBAL_ATOMIC_UMAXGLOBAL_ATOMIC_UMAX_X2GLOBAL_ATOMIC_UMINGLOBAL_ATOMIC_UMIN_X2GLOBAL_ATOMIC_XORGLOBAL_ATOMIC_XOR_X2Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:52:38Z.
Thanks, this looks right to me. The opcodes match LLVM's gfx10 FLAT and GLOBAL tables, and all 384 rows in the test agree with the ISA definitions: inc and dec at the limits, cmpswap with the data in vdata[0] and the comparator in vdata[1], and the pre-op return with glc. Read-only, unmapped and misaligned addresses go through the same write lookup as the stores in #390, so they're reported instead of written.
One small thing for the description: gfx10 also has flat_atomic_inc_x2 and dec_x2 (0x5c and 0x5d). They still throw here, which is fine, but "all but inc/dec" reads as if they don't exist.
Since this carries #390's commit unchanged, I'd like #390 to land first. After that it's ready to merge from my side once it has been through my PPSA21564 test runs.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T10:03:37Z.
flat_atomic_inc_x2/dec_x2(0x5c, 0x5d) and their global forms exist and still throw.SpirvAnalysis.cpp; both sides kept). #390's commit is carried unchanged (same patch as its current head). GlobalAtomics, FlatStore and D16Memory pass on RADV and lavapipe.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:38:08Z.
Thanks, the description now covers
flat_atomic_inc_x2/dec_x2, and the rebase only adds the FLAT table rows and the float64 check next to #390's code; #390's commit is carried unchanged (same patch as #390's head).agc_driver_global_atomicsandagc_driver_flat_storepass on my NVIDIA machine on current main, and both fail on main's code. I'll put #390 and this one through my PPSA21564 test runs together and merge #390 first if they pass.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T22:40:17Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/tests/execution/FlatStore.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T03:06:46Z.
Rebased onto current main so #495 and #506 can share these exact commits (requested on #506). The #390 commit is still the same patch as #390's head, and the atomics commit is unchanged. #390 then this one merges cleanly, and
agc_driver_global_atomicsandagc_driver_flat_storepass on RADV and lavapipe.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:03:48Z.
Thanks for rebasing the three of them onto one set of commits: #495 and #506 now sit directly on
038ded6, and #491, then #495 and #506 (in either order) merge cleanly here. Your own commits are the same patches as before, and the full ctest passes with all three merged.The step before that still conflicts for me, though: #390 itself, then this one. #390's branch is still at
673401b(based on313de1c), and this branch carriesbe866e4, a separate copy of the same patch. Patch-identical copies are fine on their own, but your atomics commit then changes lines that #390 adds, so git sees two different edits of the same lines:ResourceTracker.cpp: them_info.bdaWrites = ...line (yours adds|| addressInfo.access == AddressAccess::Atomic)SpirvBda.hpp: theEmitBdaAtomicdeclaration afterEmitBdaStoreSpirvBdaRead.cpp:EmitBdaAtomicafter the end ofEmitBdaStoreI checked with
git merge-tree --write-tree(git 2.55): on top of main plus #390, and also #390's head against this one directly, the result is the same. The old three-argument form ofgit merge-treedoesn't report conflicts the same way, which may explain the clean result you saw. Merging this one first and #390 after it conflicts in the same three files.Since this branch already carries DotDebian's commit with their authorship, I'm merging this one (then #495 and #506) and closing #390 as included here.
#569 has a fourth copy of the #390 commit (f65e21f). #569 will need a rebase onto main once this lands. After that, #569 and this one only overlap in one place: both add enum entries after
FlatStoreDwordx4inRdnaOpcode.hpp, and the fix is to keep both.I gated this together with #495 and #506 on PPSA21564, including
be866e4: no visual or FPS change.