Repository navigation
feat(shader): implement the float and 64-bit inc/dec flat and global atomics - #506
Conversation
Progress report (00407df → c67634a)📈 GPU shader instructions: 93.65% (+5.49%, +64 implemented instructions) ✅ 64 implemented
|
|
Thanks. I looked at the last commit only, as asked. The opcodes match LLVM's gfx1013 encodings (fcmpswap/fmin/fmax 0x3e to 0x40, the Since it carries #390, #491, #321 and #332, which are still open, I'll come back to it once those are in. A rebase down to this commit then would make it quick to merge; it touches #332's buffer atomic emitters, so I'll also run it through my PPSA21564 check at that point. |
|
Rebased on current main: #321 and #332 are merged and dropped from the branch; the #390 and #491 commits are patch-identical to those PRs' heads and the last commit applied unchanged. |
c8dada7 to
6c95d6c
Compare
|
Thanks for the rebase, and you're right that the #390 and #491 commits here are patch-identical to those PRs, and your last commit applied unchanged. One merge-order detail, though: patch-identical isn't quite enough for GitHub. #390's branch is at 673401b, #491 carries an older copy of that commit (6a58101), #495 another one (6ce4b28), and this branch a third (357bb14). Merged as they stand, #390 and then #491, #495 or this one conflict in #390 and #491 are still waiting on my PPSA21564 check (PPSA21564 has a few |
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>
…atomics Co-Authored-By: Claude <noreply@anthropic.com>
6c95d6c to
c67634a
Compare
|
Thanks, done: #491, #495 and this PR now share the same commits. #491 was rebased onto current main (be866e4 = #390's patch, then 038ded6), and #495 and this branch sit directly on 038ded6, each with only its own commit on top. A rebase onto #390's head itself didn't work: 673401b is based on 313de1c, and main has since added the FLAT D16 rows and the float64 analysis next to the lines #491 changes, and this commit needs main's newer atomic helpers. I simulated the merges with |
|
Gated on PPSA21564 on top of #491: no visual or FPS change. |
…mics On RDNA2 the image, buffer and global float atomics (fmin, fmax, fcmpswap and the _x2 forms) flush both operands to a signed zero when bit 0 of the shader's denormal field is clear, as the LDS forms do: the f32 field for the 32-bit forms, the f16/f64 field for _x2. Only the LDS forms flushed here. floatAtomicFlush (was sharedFloatFlush) now sets MemoryInfo::flushDenormals for every float atomic, and AtomicFloatBits applies it in minMax and compareSwap. The float atomic tests from boykopovar#332, boykopovar#506 and boykopovar#562 were measured with denormals kept, so they now set FLOAT_MODE 0xf0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
This implements the eight FLAT/GLOBAL atomics that #491 left throwing (16 with both segments):
{flat,global}_atomic_fcmpswap,fmin,fmax,fcmpswap_x2,fmin_x2,fmax_x2,inc_x2,dec_x2. Before this, the decoder threwFLAT opcode is not supportedfor each of them.They run through the same BDA atomic path as the integer ones (
EmitBdaAtomic). The value is computed in a compare-exchange loop (AtomicUpdateTyped, on u32 or u64) with the rules #332 measured for the buffer forms (AtomicFloatBits). The float compare and minNum/maxNum work on the raw bits, so the driver's denormal and NaN float controls don't matter:fcmpswap(_x2):mem = (mem == cmp) ? src : mem, compared as floats: −0 equals +0, NaN equals nothing, denormals compare exactly.srcis invdata[0]([0:1]for x2) andcmpinvdata[1]([2:3]), the same as the integercmpswap.fmin/fmax(_x2): IEEE minNum/maxNum, with −0 < +0. A signalling NaN operand gives that NaN quieted (src first). A quiet NaN loses to a number. Two quiet NaNs give src.inc_x2/dec_x2: the 32-bitinc/decwrap rule on u64.AtomicFloatBitsgetscompareSwap,incrementanddecrement, and the buffer forms from #332 now call them, so each rule is written once.Opcodes from
llvm-mc -mcpu=gfx1013 -show-encoding: fcmpswap 0x3e, fmin 0x3f, fmax 0x40, inc_x2 0x5c, dec_x2 0x5d, fcmpswap_x2 0x5e, fmin_x2 0x5f, fmax_x2 0x60.Depends on #491 (integer flat/global atomics, which includes #390) and #332 (float buffer atomics, which includes #321). Their commits are included here. Only the last commit is this PR.
Behaviour measured on HW
Radeon 660M (gfx1035, same FLAT encoding as gfx1013), with the memory in the coarse-grained pool (float atomics aren't performed on fine-grained system memory, see #332). Every pair of 16 f32 or f64 values was used: ±0, ±1, 1.5, −2.5, ±inf, quiet NaNs with and without payload, signalling NaNs, denormals, the largest finite value and the smallest normal. The fcmpswap comparator was the memory value, the memory with its sign flipped, another value, or the data. inc/dec_x2 used 16 integer edge values (0, 1, 2³²−1, 2³², 2⁶³, 2⁶⁴−1…) plus random rows with limit = mem or mem + 1. Each op ran through
global_*and throughflat_*with a 64-bit VGPR address: 4160/4160 rows match the model above, for both the returned pre-op value and the stored value. Global and flat gave the same results.Tested
Arch Linux, RADV (Radeon 660M) plus lavapipe (local Mesa and the CI version, Ubuntu Mesa 25.2.8).
GlobalAtomicsFloat: 8 atomics with 64 HW rows each (512 rows), picked to cover every class pair. fcmpswap, fmax, fcmpswap_x2, fmin_x2 and inc_x2 go throughglobal_*, while fmin, fmax_x2 and dec_x2 go throughflat_*. It runs as wave32 and wave64 and checks the returned value, the stored value, and that nothing else in the 64 KiB guest block changes. It takes 6 s on CI's lavapipe.GlobalAtomics,BufferAtomicsFloatandBufferAtomicsIncDec64still pass (the buffer forms now use the shared helpers).memory 0x0 … comparator 0x80000000), if fmin and fmax are swapped, if fmax picks by order without the NaN rules, if inc_x2/dec_x2 don't wrap, or if the flat fcmpswap drops its comparator.ctest: 188/189. The one failure,agc_driver_pixel_helper_lanes, also fails onmainon local RADV since fix(recompiler): start pixel waves without their helper invocations in EXEC #305.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)