fix(shader): serialize locked LDS updates with a wave-uniform loop exit #833
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/833"
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 LeandroLP23 on 2026-10-06T08:16:41Z.
Closes #826.
What
64-bit LDS atomics in compute shaders go through the LDS lock (
LockedLdsUpdate). Each lane left the lock loop as soon as its compare-exchange acquired the lock, so the exit was divergent and the driver's compiler was free to move the critical section and the release past the loop exit. On AMD the lock holder then waited outside the loop for the lanes still spinning on its lock.Now each iteration elects one of the lanes not yet served (
OpGroupNonUniformElect); that lane alone spins on the lock, runs the update and releases it, and the loop exits once a ballot of the unserved lanes is empty. The exit is uniform across the subgroup, so the holder cannot be separated from the loop. The lock stays for exclusion between subgroups of a workgroup.ldsLocknow also requestssubgroupBallotfor the elect and ballot capabilities.Investigation
agc_driver_lds_atomics64on unmodifiedmainlogged aLiveKernelEvent 141(VIDEO_ENGINE_TIMEOUT_DETECTED) in Windows Error Reporting: the wait took ~5 s, none of the 4096 output words was written, andvkDeviceWaitIdlestill returned success.Tested
Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release with
BUILD_TESTING=ON, AMD Radeon 860M (RDNA 3.5), driver 32.0.13058.8001. No title or homebrew.agc_driver_lds_atomics64: passes in 0.34 s, contended serial-order checks included, and no LiveKernelEvent is logged.ctest: 356/358 passed; the 2 failures are #825 and #827 (fixed by #829), which also fail on unmodifiedmain.mainthe test hangs there too (NVRM: Xid 109 CTX SWITCH TIMEOUT, then a segfault, every run); with this PR it passes in about 0.3 s, 3 of 3 runs, and the fullctestpasses.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 fisherjoey on 2026-10-06T20:04:58Z.
Another data point for #826: the same test hangs the GPU on NVIDIA.
mainat5895ea72:agc_driver_lds_atomics64prints[gpu] recorded batch still running on the GPU after 5 s, the kernel logsNVRM: Xid 109 CTX SWITCH TIMEOUTfor the test process, and the test segfaults. It happens on every run.main+ this PR (e302d550): passes in about 0.3 s, 3 of 3 runs, no Xid. Full ctest (359 tests, with #928 also merged) passes.This supports the forward-progress explanation in #826. The lock spin never finishes on NVIDIA either, and the driver kills the context instead of returning stale output.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T07:57:05Z.
Checked on RADV, local lavapipe and CI's lavapipe (
agc_driver_lds_atomics64green, full ctest 385/385 merged onto main). On hardware (gfx1035, HW oracle), contendedds_add_rtn_u64/ds_max_rtn_u64on one address serialize in lane order, which is exactly what electing the lowest active lane gives. The hang doesn't reproduce on RADV, so the fix itself rests on your Windows AMD run and @fisherjoey's NVIDIA one. Merging.