feat(shader): emulate 64-bit GDS atomics on devices without them #25978
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25978"
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-23T02:48:57Z.
What
On a device without
shaderBufferInt64Atomics(MoltenVK on Apple GPUs), any program with a 64-bit GDS atomic (ds_*_u64,ds_*_b64,ds_wrxchg2*_b64on GDS) failed to compile with "64-bit GDS atomics need shaderBufferInt64Atomics". This emulates them with the atomic lock table that 64-bit image and buffer atomics already use on such devices (#18842), following up #25967, which did the same for global and flat atomics.gdsAtomicLocksis set when a program has any GDS atomic, append or consume and the target lacksInt64Atomics. The module then declares neitherInt64Atomicsnor the aliasedgds_u64view, and asks for the lock table. A dword-only stage therefore takes the same lock as a qword stage that shares the GDS in one pipeline.OpAtomicLoad, computes the result withAtomicNext64for the native operations or the existing replacement forrsub,inc,dec,cmpstandmskor, and stores both dwords withOpAtomicStore. Bounds, alignment faults and old-value returns are unchanged.EmitLdsAtomic32) and GDS append/consume included. One word for all of GDS keeps both widths ordered and keeps two-address exchanges from taking two locks that could hash to the same word. Only one lane per subgroup tries the word at a time, whichLockedDeviceUpdateonmainnow does for every caller (61b45000a4).Int64Atomicsare unchanged.agc_driver_gds_integer_atomics64*no longer skip without the feature. Their dispatches now compile with the device's own capabilities instead of always addingInt64Atomics, and therequirementscase, which expected the compile to fail without the feature, now checks that it declares noInt64Atomicsand asks for the lock table. The debt entry drops "they requireshaderBufferInt64Atomics" and a new entry describes the lock, through a fragment. With this changeagc_driver_gds_m0_baseruns its 64-bit add on such devices, so #24072's skip is no longer needed there.Tested
Apple M5 Pro, macOS 27.3, MoltenVK (Vulkan SDK 1.4.363.0,
shaderBufferInt64Atomicsfalse), x86_64 Release under Rosetta 2,main441fa65119plus #17425 and #11049, whichmainstill needs to build on macOS; the branch was then rebased ontob09b3f76b2without 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")VUID-VUID-VkDeviceCreateInfo-sType-uniqueagc_driver_gds_m0_baseand the nineagc_driver_gds_integer_atomics64*tests (operations, exchanges, contention, bounds, requirements, alignment, coherence, exchange-contention, copied): 10 of 10 in each of 3 runs, noVUID-.main's code: all ten fail with "SPIR-V module emission failed: 64-bit GDS atomics need shaderBufferInt64Atomics".tools/check_conventions.py --base upstream/mainandtools/debt_fold.py --checkpass.Review fix
89bbe3d6c2(dword-only stages take the lock; one lane per subgroup tries it, a part thatmainnow has on its own), A/B against954a9d7736on the same machine and settings, 51 GDS, LDS, buffer, image and global atomic tests plus the label ordered flush tests, 2 runs each: 40 passed and the same 9 skipped on both sides;agc_driver_label_ordered_flushand_unimportedfail on both; each side has 49 layer insertions, 0was not found, 0VUID-. The new dword-only requirements check fails on954a9d7736. With the contention test temporarily raised to 256 workgroups, one wave32 dispatch took 1.1 to 45.7 s on954a9d7736and 87 to 93 ms with the fix (wave64: about 285 ms and 67 to 69 ms).Rebased onto
upstream/mainfc294cbbb5as two commits; the tree is identical to the earlier head merged with thatmain. The review fix no longer passesoneLanePerSubgroup, sincemain'sLockedDeviceUpdatealways elects one lane. The nineagc_driver_gds_integer_atomics64*tests pass withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1and the validation layer inserted (9 insertions, 0was not found, 0VUID-);check_conventions.py --base upstream/mainpasses.Not run on a device with
shaderBufferInt64Atomics, or on the Intel UHD from the review. This pull request and #25967 each edit the samesubgroupBallotandEmitBaseHeaderlines; whichever lands second needs a one-line rebase.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
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T03:01:55Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
954a9d7736905a175f4af7662c3ea0a77f4ed2d6. I read the prepared description, commits, manifest and diff, plus the changed implementation and test sections and their lock helper, atomic operation mapping, requirement analysis, and lock-table specialization context. No commands or tests were run; the test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
Int64Atomics, but does not inspect the emitted fallback instructions. An assertion that the no-capability SPIR-V accesses the two dwords under the lock would make this regression test more direct.Not verified
reviewedin the manifest. The excluded debt fragmentdocs/dev/debt/changes/feat-shader-locked-gds-atomics64.mdwas not included by rule.shaderBufferInt64Atomicswas not tested.To get this to a good state
Nothing is required. The optional test assertion above would strengthen coverage.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T05:41:48Z.
Review: CHANGES_REQUESTED
The per-program lock protects mixed-width GDS atomics inside one module, but it does not protect a multi-stage graphics pipeline that combines a qword-atomic module with a dword-only module. Both stages bind the same process-global GDS buffer and can overlap within one draw. Because
gdsAtomicLocksis enabled only for the module that contains a 64-bit GDS atomic, the dword-only stage does not take the shared lock.A concrete lost-update interleaving is: the locked 64-bit add loads low/high from zero; the other stage performs a lockless 32-bit add on the low word; the 64-bit path stores its value computed from zero and overwrites that update. The host barriers before and after the draw cannot serialize invocations inside the draw. On devices without
Int64Atomics, the old path refused the qword module; this change would instead produce a silent race. The new execution fixture exercises both widths in one program and therefore cannot expose it.Please make every GDS atomic module that can share such a pipeline participate in the same fallback lock on these targets, or preserve a refusal/guard for the mixed-program case (or an equivalent scheme that establishes ordering).
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T13:25:26Z.
Review: APPROVED
Thanks for fixing both paths. In the fallback, dword and qword GDS atomics and append/consume now use word zero of the same device lock table. The new requirements test checks lock-table participation for dword-only add and append programs. I verified the shared lock address and call paths in the source. The requirements test compiles the separate programs without executing a mixed-stage draw.
I rebuilt exact head
89bbe3d6c2on Windows with WinLibs GCC 15.2 Release. On the same Intel UHD A78B (0x8086:0xa78b, driver 32.0.101.6127, no buffer Int64 atomics), both CTest entries passed once: agc_driver_gds_integer_atomics64_requirements and agc_driver_gds_integer_atomics64_contention. The unmodified 32-workgroup contention test finished in 0.62 s and passed wave32 and wave64, including the dword add and both permutation cases. This is the adapter on which the older head failed the contention test in all three earlier runs.Vulkan was required and the shader cache was disabled. Each log confirms Khronos validation 1.4.369 was inserted and the Intel device was selected. There were zero skips, VUIDs, validation errors or device-loss messages, and no new LiveKernelEvent 141 or Display 4101 in the follow-up event-log check. I did not rerun the old head, raise the workgroup count, or test the RTX on this head.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T10:43:36Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
89bbe3d6c2e34f6e0710d0a30fedaa1e942ddc9eusing the prepared diff and pinned repository reader. I did not run commands or tests.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, test suite, negative control, hardware, or Vulkan validation run was performed for this review. The PR description reports those runs, but they were not independently verified here.
docs/dev/debt/changes/feat-shader-locked-gds-atomics64.mdwas excluded by review rule.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T16:53:00Z.
Review: APPROVED
Reviewed — looks good
The reviewed change at
b7da02aae47d6f3d0d27a0edd38e024ac5926524has no verified blocking defects in the changed code; reported runtime and benchmark results are author supplied and were not independently run.What I ran
No commands or tests were run. Read the prepared description, commits, manifest and diff, then inspected the changed code and nearby implementations through
repo_read.pyat the pinned head.Results
Findings
Blocking
None identified in the changed code reviewed.
Non-blocking
None.
Not verified
Did not run tests, build, or independently reproduce the device behavior or reported performance measurements. The technical debt entry
docs/dev/debt/changes/feat-shader-locked-gds-atomics64.mdwas excluded by the review bundle rule and was not read. All files marked included in the manifest were read; no changed source file listed in the manifest was excluded.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T07:07:17Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change based on the diff and targeted code reviewed; the author reported test results were not independently run here.
What I ran
Reviewed head
c7e4549dfc5fac7ce83057db2a012e3eea96820cusingrepo_read.pyto inspect prepared review artifacts and targeted code ranges. No tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The complete text for all changed files was not read; targeted ranges in
SpirvMemoryInstructions.cpp,SpirvAnalysis.cpp, andSpirvEmitter.cppwere read alongside the prepared diff and manifest. Test behavior and the author reported platform results were not independently verified.docs/dev/debt/changes/feat-shader-locked-gds-atomics64.mdwas excluded by rule. The described concurrency and performance results were not independently checked.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-02T17:07:58Z.
Review: APPROVED
Reviewed — looks good
The reviewed change is sound at head
a919972b203a31366765e84a76f4ed5cfb245a57; the inspected implementation and reported checks support merging.What I ran
No commands or tests were run independently. I reviewed the prepared diff and source at the pinned head. The PR description reports validation on an Apple M5 Pro with MoltenVK; those results are author-reported.
Results
Negative control
Not run independently. The author reports that all ten relevant tests fail on
mainwith the prior unsupported-atomic error.Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed the prepared diff and pinned-head source for the GDS atomic lowering, lock handling, requirement analysis, module setup, and execution tests.
Not verified
Physical-console behavior and behavior on a device with native
shaderBufferInt64Atomicswere not independently verified. The excluded filedocs/dev/debt/changes/feat-shader-locked-gds-atomics64.mdwas not read.Files read, matching all files listed under
reviewedinfiles.json:core/libs/prx/libSceAgcDriver/tests/execution/GdsIntegerAtomics64.cpp;core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvAnalysis.hpp;core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hpp;core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvMemory/SpirvBufferAccess.hpp;core/shader/recompiler/SpirvBackend/src/SpirvAnalysis.cpp;core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp;core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvBufferAccess.cpp;core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp;core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp; andcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cpp.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-02T17:45:31Z.
Review: COMMENTED
Actionable comments
f782d94d-5720-4a97-86fa-0f14daf5cf1cReviewing files that changed from the base of the PR and between
c7e4549dfcanda919972b20.core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:30:29Z.
Review: COMMENTED
The requirements test confirms that a dword-only module requests the lock table where Int64Atomics is unavailable. Please also exercise mixed-width contention on the same GDS location on the fallback path. The lock table declaration and the standalone qword contention results leave open whether the emitted dword and qword operations observe one coherent update order when they interact. The paired GDS tests are queued on lavapipe. The native Metal path relies on the posted MoltenVK run.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T03:23:48Z.
Review: COMMENTED
Actionable comments
30798cf8-ce93-47e5-b6c6-b7577731e08eReviewing files that changed from the base of the PR and between
a919972b20and3960cbee22.core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_gds_integer_atomics64_tests.cmakecore/libs/prx/libSceAgcDriver/tests/execution/GdsIntegerAtomics64.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T04:21:28Z.
Review: APPROVED
Reviewed — looks good
The change implements locked 64-bit GDS atomics for targets without native support, and I found no blocking defects in the reviewed code.
What I ran
Reviewed head
3960cbee22516d436f29962eb2e75478e8ff03d0using the prepared diff andrepo_read.pyfor pinned source context. I did not run tests or compile anything. Test results in the PR description are author-reported.Results
Negative control
Not run in this review. The PR description reports that its tests fail on the prior code; I did not independently verify that result.
Findings
Blocking
None.
Non-blocking
None.
Sources
The implementation detects GDS atomic operations and enables the lock path when native 64-bit atomics are unavailable (SpirvAnalysis.cpp, SpirvEmitter.cpp). The locked path reads and updates the two dwords while holding the shared GDS lock (SpirvMemoryInstructions.cpp).
Not verified
No tests, builds, or hardware behavior were independently verified. I reviewed the prepared description, commits, manifest, diff, and files.json; all 11 files listed under
reviewedwere examined. The excluded debt notedocs/dev/debt/changes/feat-shader-locked-gds-atomics64.mdwas not read.To get this to a good state
Nothing is required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.