Repository navigation
feat(shader): implement the integer flat and global atomics - #491
Conversation
Progress report (00407df → 038ded6)📈 GPU shader instructions: 92.28% (+4.12%, +48 implemented instructions) ✅ 48 implemented
|
|
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. |
8605b1d to
0aa29e0
Compare
|
|
Thanks, the description now covers |
|
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.
|
flat_store_* and global_store_* decoded and translated, but a store whose
segment is not scratch was refused when the SPIR-V was emitted ("writable
FLAT/GLOBAL addresses require GPU ownership tracking").
Such a store now goes through the BDA page table like a store through a
GPU-selected V#: the write lookup needs Write permission, which only a
writable registered range imported in place has, and the written page is
noted for the host to mark GPU-written. Byte and short stores, and dword
stores to an address that is not dword aligned, are stored byte by byte.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
0aa29e0 to
038ded6
Compare
|
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 |
|
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 on 313de1c), and this branch carries be866e4, 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:
I checked with 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 I gated this together with #495 and #506 on PPSA21564, including be866e4: no visual or FPS change. |
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)