fix(shader): elect one lane for locked 64-bit updates #24081
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24081"
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 Romannachwievor on 2026-11-20T05:38:59Z.
What
On a device without native 64-bit buffer or image atomics, the recompiler emulates them with a device-scope spin lock per address (
LockedDeviceUpdate). Every pending lane of a subgroup ran the lock's compare-exchange at the same time and looped until it was served. On Apple GPUs through MoltenVK, a contended dispatch then never finishes: the batch is still running after 5 s, macOS resets the GPU, and the device is lost (agc_driver_buffer_atomics_or_swap64, 32 groups of 64 threads on one lock).Now one lane per host subgroup is elected each iteration to try the lock, with the same election and merge structure
LockedLdsUpdatealready uses. The other pending lanes wait at the merge and try again on a later iteration. A lane that gets the lock runs the update and releases the lock in the same iteration.Cost: lanes of one subgroup that update different addresses (different locks) now take turns, one per iteration, where before they could each take their own lock in the same iteration. This only affects devices that take the emulated path. I have not measured it.
Tested
macOS 26.5, Apple M1, x86_64 Release under Rosetta 2, MoltenVK from LunarG SDK 1.4.363.0. One tree and build directory (this branch on
main365fdeddbe). The base was built from the same tree with the parent version ofSpirvEmitterHelpers.hpp, then the change was rebuilt.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer,ctest --test-dir build -R '^<test>$' -V, 10 serial runs per test and side:agc_driver_buffer_atomics_or_swap64recorded batch 22 still running on the GPU after 5 s, thenLost VkDevice ... (victim of GPU error/recovery)andvkDeviceWaitIdle: Vulkan result -4. 7 of 10 runs logged the batch as still running after 5 s. Runs took 0.8 to 69.9 sagc_driver_image_atomics64All 40 logs show
Insert instance layer "VK_LAYER_KHRONOS_validation", none showswas not found but was requested by env var VK_INSTANCE_LAYERS, and none contains aVUID-message.Not tested: a device with native 64-bit atomics (this path is not used there), and the cost for uncontended lanes described above.
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)AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:42:19Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the elected lane serializes attempts while the subgroup ballot keeps waiting lanes active until each completes.
What I ran
Reviewed head
61b45000a4bbd084cb6873a047c5cdb53b215978. No commands or tests were run; the author-reported results are not independently verified. Readdescription.md,commits.md,manifest.json,diff.patch, and the full changed filecore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hpp. No changed files were excluded.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported MoltenVK runs, recompiler build, and
git diff --checkwere not run during this review. No other changed files were listed in the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-20T11:36:19Z.
Review: COMMENTED
Ran it on a second Mac: Apple M4, macOS 27.0.1, MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1), x86_64 Release build under Rosetta 2. Head
61b45000a4applied ontomaine825fa1492with #17425 and #11049 (needed for the macOS build); clean apply.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, each run beingctest -R '^<test>$' -j1.vulkaninforeportsshaderBufferInt64Atomics = falseandshaderSharedInt64Atomics = falseon this GPU, so these tests take the emulated path, as on the M1.mainagc_driver_buffer_atomics_or_swap64agc_driver_image_atomics64So the M4 does not hang on
main. The contended dispatch finishes here without the election, which suggests the M1 hang depends on how its GPU schedules the spinning lanes. The change causes no regression here. The other 12 tests matchingagc_driver_.*atomic.*64pass, or skip for lack of GDS, on both trees, 2 runs each.I ran these without the validation layer.
AI-assisted: yes (Claude Code)