feat(shader): implement the 64-bit LDS atomics #573
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/573"
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 CnRJay on 2026-10-04T22:59:59Z.
What
The 35 64-bit DS atomics threw
DS opcode is not supported:ds_add/sub/rsub/inc/dec_u64,ds_min/max_i64,ds_min/max_u64,ds_and/or/xor/mskor_b64,ds_cmpst_b64/f64,ds_min/max_f64, their_rtnforms, andds_wrxchg_rtn_b64(DS 0x40-0x4c, 0x50-0x53, 0x60-0x6d, 0x70-0x73).LDS is emitted as a 32-bit
Workgrouparray, and 64-bit atomics on it would needVK_KHR_workgroup_memory_explicit_layoutplusshaderSharedInt64Atomics. Instead, each op reads and writes its two dwords under a lock dword placed after the guest LDS:Semantics follow the 32-bit forms (commit
c8af8892):cmpststoresdata1when memory equalsdata0, andmskorcomputes(old & ~data0) | data1.incanddecwrap as inds_inc_u32andds_dec_u32. The f64min/max/cmpstops are computed on the bits with the NaN and signed-zero rules measured for the f32 forms. This is recorded in TechnicalDebt together with the lock's scope: it orders 64-bit atomics against each other, not against concurrent 32-bit access to the same dwords.tools/progress.py: shaders 1013/1166 (86.88%), +35.Tested
Windows 11, MinGW GCC 15.2.0 r7, NVIDIA Vulkan,
-DANYPS5_ENABLE_SPIRV_TOOLS=ON.agc_driver_lds_atomics64runs one wave32 compute dispatch:ds_add_rtn_u64andds_max_rtn_u64. The test checks the total and that the returned values form one serial order.ds_min_i64's compare fails its lane checks.ctest: 212/213 pass.agc_shader_memoryfails identically without this change (SPIR-V validationOpSelectvector size).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-04T23:11:04Z.
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)docs/dev/TechnicalDebt.mdL78Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:44:02Z.
Thanks, this is a careful one. I checked the 35 opcodes with llvm-mc for gfx1013: the test shader disassembles to exactly the ops in
names, and the operand order matches the 32-bit forms (cmpst compares with data0 and stores data1, mskor is(old & ~data0) | data1, inc and dec wrap as in the ISA). The lock only exists in shaders that use a 64-bit LDS atomic, and the f64 rules are recorded in TechnicalDebt as not measured, which is what the project asks for.One thing to watch when CI runs (it still needs approval): in the contended part, all 32 lanes write 0 to the two shared slots and then do the
ds_add_rtn_u64/ds_max_rtn_u64on them with only ans_waitcntin between. That's correct for one wave on hardware and on a GPU with 32-lane subgroups. On a device whose subgroups are narrower than the wave (lavapipe in the Linux job, 8 lanes), the recompiled wave runs as several subgroups, so one subgroup's zeroing write can land after another subgroup's atomics and the total comes out short. The other cross-lane tests (LdsAddtid,DsPermute) skip there. If the Linux job fails on that check, ans_barrierafter the zeroing writes (or skipping the contended part below 32 lanes) would fix it.agc_driver_lds_atomics64passes here on NVIDIA (32-lane subgroups) and fails on main ("DS opcode is not supported"), so only the narrow-subgroup case is open.Small optional note: the lock dword adds 4 bytes, so a shader that already uses the device's whole shared memory would go over the limit. That's an edge I don't expect to see.
PPSA21564 has no 64-bit LDS atomics, so this doesn't affect my runs. Ready to merge from my side once CI is green.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T23:44:37Z.
Progress report (
f83ee12→7907e87)📈 GPU shader instructions: 86.88% (+3.0%, +35 implemented instructions)
✅ 35 implemented
DS_ADD_RTN_U64DS_ADD_U64DS_AND_B64DS_AND_RTN_B64DS_CMPST_B64DS_CMPST_F64DS_CMPST_RTN_B64DS_CMPST_RTN_F64DS_DEC_RTN_U64DS_DEC_U64DS_INC_RTN_U64DS_INC_U64DS_MAX_F64DS_MAX_I64DS_MAX_RTN_F64DS_MAX_RTN_I64DS_MAX_RTN_U64DS_MAX_U64DS_MIN_F64DS_MIN_I64DS_MIN_RTN_F64DS_MIN_RTN_I64DS_MIN_RTN_U64DS_MIN_U64DS_MSKOR_B64DS_MSKOR_RTN_B64DS_OR_B64DS_OR_RTN_B64DS_RSUB_RTN_U64DS_RSUB_U64DS_SUB_RTN_U64DS_SUB_U64DS_WRXCHG_RTN_B64DS_XOR_B64DS_XOR_RTN_B64Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T00:15:42Z.
Thanks for adding the barriers. I owe you a correction on my earlier note: the Linux job had already passed on
d78eea1(agc_driver_lds_atomics64passed all three repeats on lavapipe). The reason is that the recompiler already orders LDS accesses inside a single-wave compute workgroup:WaveLdsScopein SpirvEmitter.cpp puts a workgroup barrier between an LDS write and the next LDS access, and the new 64-bit atomics count as writes throughSharedAccessOf. So the zeroing writes were never racing with the atomics there.The two
s_barriers are still fine to keep. An explicit barrier resets that tracking, so nothing is emitted twice, and the test no longer depends on it. I disassembled the new code with llvm-mc for gfx1013: the only change is ans_barrierafter each of the twos_waitcnt lgkmcnt(0), one before the contended atomics and one before the reads.agc_driver_lds_atomics64passes here on the new head and still fails on main ("DS opcode is not supported"). The new push needs workflow approval again before CI runs. Ready to merge from my side once it's green.