feat(shader): emulate 64-bit global and flat atomics on devices without them #25967
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25967"
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 Gonic0 on 2026-11-23T01:54:42Z.
What
On a device without
shaderBufferInt64Atomics(MoltenVK on Apple GPUs, some integrated GPUs), any program with aglobal_atomic_*_x2or aflat_atomic_*_x2that reaches the device address table failed to compile with "64-bit buffer atomics need shaderBufferInt64Atomics". The 64-bit buffer atomics already had an emulation for such devices (#18842): the two dwords are read and written with 32-bit atomics under a word of the atomic lock table, chosen by a hash of the guest address of the 8-byte word. This extends that emulation to global and flat atomics on the device address table.bufferAtomicLocksno longer excludes programs with address atomics, so buffer and address atomics of one program share the lock table and the same per-qword key.OpAtomicLoad, computes the result with the existingFlatAtomicNext64(every 64-bit address opcode, including inc/dec and the float min/max/cmpswap forms), and stores both dwords withOpAtomicStore. The module never declaresInt64Atomics.SpirvRuntimeBuffer.cpptoEmitQwordAtomicLockPointerso both paths use the same key. Only one table lock is held at a time.shaderBufferInt64Atomicsare unchanged: the address path emits exactly what it did before.agc_driver_global_atomics64,agc_driver_global_atomics_float,agc_driver_global_atomics_lanes,agc_driver_memory_float_atomic_modesand the 64-bit atomic rows ofagc_driver_flat_aperturesno longer skip withoutshaderBufferInt64Atomics.verifyInt64AtomicCapabilitieschecks that aglobal_atomic_swap_x2, alone and with abuffer_atomic_inc_x2, declares noInt64Atomicsand asks for the lock table without the feature, and uses the native atomic with it. GDS 64-bit atomics are not covered here and still need the feature. The debt entry is updated through a fragment.The emulation uses the existing
LockedDeviceUpdate; #24081 changes it to elect one lane per subgroup after a contended buffer atomic hung an Apple M1. It did not hang on the M5 below, and this pull request does not depend on that change.Tested
Apple M5 Pro, macOS 27.3, MoltenVK (Vulkan SDK 1.4.363.0, subgroup size 32,
shaderBufferInt64Atomicsfalse), x86_64 Release under Rosetta 2,main4b7d1c3660plus #17425 and #11049, whichmainstill needs to build on macOS; the branch was then rebased onto3deea61b30without conflicts. The same build directory formainand this change.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer(Khronos validation layer 1.4.363); each log shows the loader inserting the layer and none reports it missing.ctest -R 'atomic|flat_apertures|look_back|agc_shader_memory|bda|agc_driver_global|lds|gds' -Vmainagc_driver_gds_m0_base("64-bit GDS atomics need shaderBufferInt64Atomics", #24072)VUID-VUID-VkDeviceCreateInfo-sType-uniqueglobal_atomics64,global_atomics_float,global_atomics_lanes,memory_float_atomic_modes,flat_apertures_0to_13): 18 of 18 in each of 3 runs, noVUID-.main's code: those 18 tests andagc_shader_memoryfail, all with "SPIR-V module emission failed: 64-bit buffer atomics need shaderBufferInt64Atomics".agc_driver_look_back_scankeeps its skip: without it, it fails on this change because it reads thebuffer_atomic_swap_x2words with plain loads, which never take the lock (the limitation already in the debt entry).tools/check_conventions.py --base upstream/mainandtools/debt_fold.py --checkpass.Not run on a device with
shaderBufferInt64Atomics; thereverifyInt64AtomicCapabilitieschecks the native path. Not tested with a title.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:09:44Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected changes blocks merge; the device address atomic emulation uses the shared qword lock and preserves the existing native path when 64-bit atomics are supported.
What I ran
Read the prepared diff and targeted source at head
8d53b3e23ee5a8e34c51105216c81caaff5a8b0e. I did not run commands or tests. The author reports device tests and a negative control indescription.md; those results were not independently run here.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
The full
ShaderMemory.cppfile was not read; only its changed lines in the diff were inspected. Other changed files with no added lines were not read at the pinned head; their diff hunks were inspected. Runtime behavior and author-reported device test results were not independently verified. The excluded debt fragment was not reviewed.To get this to a good state
Nothing is required.
Sources
Prepared diff and targeted source files at the pinned head.