feat(shader): implement buffer_atomic_csub #594
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/594"
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 DotDebian on 2026-10-05T00:17:24Z.
What
MUBUF opcode
0x34,buffer_atomic_csub, had no entry in the decode table. It is now decoded and translated: the instruction subtracts the data register from a buffer dword, clamps the result to zero when the subtrahend is larger than the stored value, and returns the previous value in the data register.RdnaOpcode::BufferAtomicCsub, decoded like the other 32-bit buffer atomicsIrOpcode::BufferAtomicUSubSat32, emitted through the existingEmitAtomicUpdateloop withold >= value ? old - value : 0glcthrows: LLVM defines only the returning variant of this instruction (BUFInstructions.td,BUFFER_ATOMIC_CSUBunder the GFX10 B encoding), so there is nothing to base the other one onOnly the MUBUF instruction is covered.
global_atomic_csubbelongs with the flat and global atomics of #491, #495 and #506 and is left to them. Those three PRs and #573 add lines next to the ones added here, so whichever lands second needs a small textual rebase; none of them touches MUBUF0x34.Tested
Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA RTX 5080. No title run.
New execution test
agc_driver_buffer_atomic_csub: a compute shader runs the instruction on wave32 with 32 and 64 threads and on wave64 with 64 threads. Each thread has its own dword and subtrahend (16 edge rows such as0 - 1,1 - 0xffffffff,0x80000000 - 0x7fffffff, then hashed values), once with a full exec mask and once with0x55555555. It checks the stored value, the returned value, and that inactive lanes leave both memory and the data register alone. Two more dwords are shared by all lanes: one that stays above zero and one that every lane drives to zero. The form withoutglcis checked to throw.ctest(Release): 222/222 passed.Not tested on AMD hardware, and not compared against a console.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T00:17:45Z.
Progress report (
9651ec9→da9752b)📈 GPU shader instructions: 83.96% (+0.08%, +1 implemented instructions)
✅ 1 implemented
BUFFER_ATOMIC_CSUBImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T01:18:41Z.
Thanks. I checked the test kernel with llvm-mc for gfx1030: it disassembles to the three loads,
buffer_atomic_csub ... offen glcwith the full exec mask and again at offset 4 underexec_lo = 0x55555555, the two shared dwords at offsets 2048 and 2052, and the stores, which matches whatCheckexpects. The clamp (old >= value ? old - value : 0, returning the old value) is the ISA's definition, and going throughEmitAtomicUpdatekeeps it atomic like inc and dec. Throwing for the form withoutglcis fine.One note for the record: LLVM only has this instruction for gfx10.3. For gfx1013 llvm-mc says "instruction not supported on this GPU", so I can't confirm from LLVM that the PS5 has it. On gfx10.1 MUBUF 0x34 is unused, though, so decoding it can't hide another instruction, and a title that never uses it is unaffected.
agc_driver_buffer_atomic_csubpasses here and fails on main's code ("MUBUF opcode is not supported"). PPSA21564 has nobuffer_atomic_csubin its shaders, so this doesn't change my runs. Ready to merge from my side.