fix(shader): coherent atomic loads on AMD (APS5_COHERENT_ATOMIC_LOADS) #18600

Merged
zorde23 merged 5 commits from upstream-pr/18600 into main 2026-11-13 01:23:06 +00:00
zorde23 commented 2026-11-11 22:44:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zorde23 on 2026-11-11T22:44:54Z.


Requested by Matheus

What

A glc buffer load is emitted as a Volatile OpLoad on 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 through VK_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=1 emits these loads as device-scope relaxed OpAtomicLoad, 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's APS5_* switches are collected by ShaderCacheVersion.cmake), so programs compiled with and without it never mix.

  • New execution test agc_driver_coherent_atomic_loads (tests/execution/CoherentAtomicLoads.cpp). Without the switch it checks that the glc loads stay volatile loads. With it (registered as agc_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 _enabled run 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_loads and agc_shader_memory trace the SPIR-V their loads produce and only followed OpLoad, so with the switch on their read lists came back empty although the program was right. Both trackers now accept OpAtomicLoad, 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-scope OpMemoryBarrier after every buffer atomic is lowered to an s_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, base main at 62bd7dd61e and this PR at 32bcb075e6 (the same commits before the rebase onto current main), full suite with validation layers:

VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_REQUIRE_VULKAN=1 [APS5_COHERENT_ATOMIC_LOADS=1] ctest --test-dir <build> --output-on-failure -j 4 --timeout 900
main (62bd7dd61e) this PR, switch unset this PR, APS5_COHERENT_ATOMIC_LOADS=1
Full test suite 5010/5012 5014/5016 5015/5016
Failures agc_driver_unregistered_label_on_gpu, agc_driver_sample_order_grid_reference the same 2 agc_driver_sample_order_grid_reference
Validation messages (VUID count) 0 0 0
agc_driver_coherent_atomic_loads / _enabled n/a pass pass
agc_guarded_memory_loads / agc_shader_memory and their _coherent_atomic_loads runs pass pass pass

Both failures are on main too. agc_driver_sample_order_grid_reference fails in all three runs, as it does on the base. agc_driver_unregistered_label_on_gpu is flaky on this machine: it failed on main and 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, head 3149b9da26) without conflicts; the suite above ran on the same commits based on 62bd7dd61e.

Checklist

  • Based on current main; no other open PR implements the same functions (rebased onto 3a0a54bbd8; #14217 touches the same files for MoltenVK but implements something different)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD RX 6750 XT (RDNA 2), Windows 11, AMD driver 32.0.21045.20006, Vulkan SDK 1.4.363.0
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5267899367 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18600). Originally posted by [zorde23](https://github.com/zorde23) on 2026-11-11T22:44:54Z. --- <!-- claude-projects-attribution: {"github_login":"zorde23"} --> _Requested by **Matheus**_ ### What A `glc` buffer load is emitted as a `Volatile` `OpLoad` on 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 through `VK_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=1` emits these loads as device-scope relaxed `OpAtomicLoad`, 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's `APS5_*` switches are collected by `ShaderCacheVersion.cmake`), so programs compiled with and without it never mix. - New execution test `agc_driver_coherent_atomic_loads` (`tests/execution/CoherentAtomicLoads.cpp`). Without the switch it checks that the `glc` loads stay volatile loads. With it (registered as `agc_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 `_enabled` run 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_loads` and `agc_shader_memory` trace the SPIR-V their loads produce and only followed `OpLoad`, so with the switch on their read lists came back empty although the program was right. Both trackers now accept `OpAtomicLoad`, 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-scope `OpMemoryBarrier` after every buffer atomic is lowered to an `s_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`, base `main` at 62bd7dd61e and this PR at 32bcb075e6 (the same commits before the rebase onto current `main`), full suite with validation layers: ``` VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_REQUIRE_VULKAN=1 [APS5_COHERENT_ATOMIC_LOADS=1] ctest --test-dir <build> --output-on-failure -j 4 --timeout 900 ``` | | main (62bd7dd61e) | this PR, switch unset | this PR, `APS5_COHERENT_ATOMIC_LOADS=1` | |---|---|---|---| | Full test suite | 5010/5012 | 5014/5016 | 5015/5016 | | Failures | `agc_driver_unregistered_label_on_gpu`, `agc_driver_sample_order_grid_reference` | the same 2 | `agc_driver_sample_order_grid_reference` | | Validation messages (VUID count) | 0 | 0 | 0 | | `agc_driver_coherent_atomic_loads` / `_enabled` | n/a | pass | pass | | `agc_guarded_memory_loads` / `agc_shader_memory` and their `_coherent_atomic_loads` runs | pass | pass | pass | Both failures are on `main` too. `agc_driver_sample_order_grid_reference` fails in all three runs, as it does on the base. `agc_driver_unregistered_label_on_gpu` is flaky on this machine: it failed on `main` and 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, head 3149b9da26) without conflicts; the suite above ran on the same commits based on 62bd7dd61e. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (rebased onto 3a0a54bbd8; #14217 touches the same files for MoltenVK but implements something different) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD RX 6750 XT (RDNA 2), Windows 11, AMD driver 32.0.21045.20006, Vulkan SDK 1.4.363.0 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!18600
No description provided.