fix(shader): coherent atomic loads on AMD (APS5_COHERENT_ATOMIC_LOADS) #18600
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18600"
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 zorde23 on 2026-11-11T22:44:54Z.
Requested by Matheus
What
A
glcbuffer load is emitted as aVolatileOpLoadon the coherent binding. On an RX 6750 XT (Windows) the driver keeps no load inside a loop that waits for another workgroup's flag (seen in its ISA throughVK_KHR_pipeline_executable_properties), so a compute program doing a decoupled look-back never sees the flag and the device is lost.APS5_COHERENT_ATOMIC_LOADS=1emits these loads as device-scope relaxedOpAtomicLoad, as the address-based read path already does, in both the runtime-buffer path (SpirvRuntimeBuffer.cpp) and the direct-buffer path (SpirvMemoryInstructions.cpp). The switch is off by default and is read once per process. It is part of the shader disk cache key (the recompiler'sAPS5_*switches are collected byShaderCacheVersion.cmake), so programs compiled with and without it never mix.agc_driver_coherent_atomic_loads(tests/execution/CoherentAtomicLoads.cpp). Without the switch it checks that theglcloads stay volatile loads. With it (registered asagc_driver_coherent_atomic_loads_enabled) it checks that they are atomic loads and dispatches 64 groups where each waits for the previous group's flag, then checks that the chain completes. The_enabledrun fails on a base that still emits volatile loads. The waiting dispatch runs only with the switch, because without it the loop may never end on AMD.agc_guarded_memory_loadsandagc_shader_memorytrace the SPIR-V their loads produce and only followedOpLoad, so with the switch on their read lists came back empty although the program was right. Both trackers now acceptOpAtomicLoad, and both suites are registered a second time with the switch (*_coherent_atomic_loads).docs/dev/ENVIRONMENT.md: the new switch.docs/dev/debt/shader.md: the coherent load entry, and a second entry on the same GPU: the device-scopeOpMemoryBarrierafter every buffer atomic is lowered to ans_barrier, which becomes divergent when only some waves take the atomic (a radix sort where wave 0 takes a ticket), so other groups wait forever. This PR does not change that; it only records it.Out of scope: a stricter check in the new test that counts only atomic loads whose pointer roots in the buffer arrays (today it counts every
OpAtomicLoad, and relies on "no volatile load left" to discriminate).Tested
Windows 11, MinGW-w64 GCC 15.2.0, RX 6750 XT (RDNA 2), AMD driver 32.0.21045.20006, Vulkan SDK 1.4.363.0. Release build,
BUILD_TESTING=ON, basemainat62bd7dd61eand this PR at 32bcb075e6 (the same commits before the rebase onto currentmain), full suite with validation layers:62bd7dd61e)APS5_COHERENT_ATOMIC_LOADS=1agc_driver_unregistered_label_on_gpu,agc_driver_sample_order_grid_referenceagc_driver_sample_order_grid_referenceagc_driver_coherent_atomic_loads/_enabledagc_guarded_memory_loads/agc_shader_memoryand their_coherent_atomic_loadsrunsBoth failures are on
maintoo.agc_driver_sample_order_grid_referencefails in all three runs, as it does on the base.agc_driver_unregistered_label_on_gpuis flaky on this machine: it failed onmainand with the switch unset, and passed with the switch on, so its result says nothing about this PR.Not tested on NVIDIA, Intel or Linux.
The branch is now rebased onto the current
main(3a0a54bbd8, head3149b9da26) without conflicts; the suite above ran on the same commits based on62bd7dd61e.Checklist
main; no other open PR implements the same functions (rebased onto3a0a54bbd8; #14217 touches the same files for MoltenVK but implements something different)NotImplemented_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