Repository navigation
rdna2spirv: global_atomic_inc/dec and buffer_atomic_inc/dec - #3097
LouisRiverstone wants to merge 1 commit into
Conversation
All four raised Unsupported. inc stores (M >= D) ? 0 : M + 1 and dec (M == 0 || M > D) ? D : M - 1 (unsigned, RDNA2 ISA); no SPIR-V atomic does that, so they are an OpAtomicCompareExchange loop (atomic_cas_loop, the loop global_atomic_float uses), exact under contention. Operands, glc and inactive lanes as the other global atomics; the buffer forms use buffer_atomic's address and bounds. tests/semantic/test_atomic_inc_dec.py covers value grids, no glc, buffer bounds, 32 lanes contending on one dword (equal to 32 sequential updates) and seeded values; test_global_atomics.py's rejected list now uses global_atomic_inc_x2. docs/design.md row added.
|
Tested 1014e55 (merged on current main) on RTX 3090, driver 616.56, Windows 11 23H2: pass. With this translator change, Overlap: #2448 (open, another author) implements the same instructions, 32-bit AI-assisted test run. |
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Reviewed and verified locally (Windows 11, Python 3.14, SPIRV-Tools / Vulkan 1.3):
Audit & Verification Details
- Compilation & Unit Tests:
- python -m compileall -q make_game.py tools tests passes cleanly.
- python -I tests/semantic/test_atomic_inc_dec.py -v: 7/7 test suites pass (including 32-lane contention, boundary checks, buffer out-of-bounds glc=0, seeded values, rejected forms).
- python -I tests/semantic/test_global_atomics.py -v: 12/12 pass with no regression.
- SPIR-V Validation:
- Assembled generated SPIR-V for both global_atomic_inc and �uffer_atomic_dec via spirv-as --target-env vulkan1.3 and validated via spirv-val --target-env vulkan1.3. Both pass with 0 errors.
- Loop structure (OpLoopMerge, OpBranchConditional, OpAtomicCompareExchange with Device scope %uint_1 on PhysicalStorageBuffer) is strictly compliant.
- ISA Semantics:
- RDNA2 ISA formulas for unsigned inc ((M >= D) ? 0 : M + 1) and dec ((M == 0 || M > D) ? D : M - 1) are faithfully implemented via OpUGreaterThanEqual / OpIEqual + OpUGreaterThan + OpLogicalOr.
- Inactive lane and buffer out-of-bounds preservation and glc return semantics strictly observed.
- docs/design.md row updated cleanly without game assets.
Excellent work. Approving!
|
Tested 1. The formulas on hardware. The PR takes inc/dec from the ISA guide. I ran the native instructions on an AMD Radeon iGPU (Ryzen 9 9950X3D, 2. The translated CAS loops under contention. A hand-written compute shader (not part of this PR), translated with this head and run through
The same on the NVIDIA GeForce RTX 5080 (driver 621.01) and the gfx1036 iGPU. Controls: Also: I didn't look at the overlap with #2448 that @CharlyRien pointed out. |
|
Thanks @CharlyRien for spotting the overlap. #2448 (FaKL-Code) implements the same four ops the same way (a CAS loop with the same inc/dec formulas), was opened first (17:05) and was claimed on #2300, so I missed it when I searched before claiming. Closing this in favour of #2448. @TheMrBeez's hardware results above check the formulas on gfx1036 (648/648) and the CAS loops under 4096-thread contention on an RTX 5080 and gfx1036. They apply to #2448 as well, since both PRs emit the same formulas and loop. My #3193 ( |
|
Tested
Tools: llvm-mc 21.1.8 with AMDGPU target, SPIRV-Tools 2026.1, GCC 13.3.0, Python 3.12.3. No code was edited or pushed; only synthetic fixtures were used. AI-assisted. |
global_atomic_inc/decandbuffer_atomic_inc/decraisedUnsupported. RDNA2 ISA, unsigned:M = (M >= D) ? 0 : M + 1M = (M == 0 || M > D) ? D : M - 1With
glc, the old M comes back.Implementation: no SPIR-V atomic does this, so each is an
OpAtomicCompareExchangeloop.Gen.atomic_cas_loopis the same loopglobal_atomic_floatalready uses onmain. It loads, computes, exchanges if the dword still holds the value read, and otherwise retries with what it holds.Gen.inc_dec_valueis the formula.glcand inactive lanes as the otherglobal_atomic_*.buffer_atomic's address and bounds. An inactive or out-of-range lane leaves memory alone, and itsglcresult is 0.Unsupported: the_x2forms. The LDS forms are rdna2spirv: implement 10 32-bit LDS CAS atomics (SHADER-448) #2495's, andbuffer_atomic_fmin/fmaxis SHADER-480: rdna2spirv atomic natural alignment (gfx1036) and buffer_atomic_{fmin,fmax} #2710's.Tests:
tests/semantic/test_atomic_inc_dec.py:glc(vdstkept)_x2andslcforms are still rejectedWithout the change the file fails (120 errors); with it, 7/7 pass.
test_global_atomics.py's rejected list now usesglobal_atomic_inc_x2.python -I -m unittest discover -s tests/semantic: OK.docs/design.md: new row after "Global atomics".Tested on CPU only; no GPU run. No game files. Claimed on #2891 before starting.
AI-assisted (Claude Code): I reviewed and ran the change and the tests.