fix(shader): read GLC/DLC BDA dwords with device-scope atomic loads #2259
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2259"
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 TheAggie on 2026-10-09T13:30:47Z.
What
A GLC/DLC global load is translated as a
Volatileload through a physical-storage pointer. Under the GLSL450 memory model,Volatiledoesn't make another workgroup's stores visible within the same dispatch. On NVIDIA, a workgroup that spins on a flag written by another workgroup never sees the store.This is the pattern of decoupled look-back prefix scans. RADV's acceleration-structure build uses it (the radix sort), and vkQuake (PPSA99010) triggers that build with
r_rtshadows. Under AnyPS5 the scan spins until the GPU is lost (VK_ERROR_DEVICE_LOST), or spins silently.When the non-faulting BDA probe gives a coherent dword read a non-null, 4-byte-aligned physical address,
SpirvBdaRead.cppnow emitsOpAtomicLoadatScopeDevicewith relaxed semantics instead ofOpLoad ... Volatile. That covers the wide path inEmitBdaDwordReadsand the coherent single-dword helper inDefineBdaDwordReadFunctions. Unaligned addresses, unmapped addresses and reads that span two BDA ranges still take the existing byte path, which reports faults exactly as before. With byte reads forced (no probe), nothing changes. Non-coherent loads are unchanged.Tests:
tests/execution/CrossWorkgroupFlag.cpp: 25 hand-assembled GFX10 words, two workgroups. Workgroup 0 stores a flag withglobal_store_dword glc. Workgroup 1 spins onglobal_load_dword glc dlcand writes 2 if it sees the flag, or 3 after a 1M-iteration bailout, so a failure can't hang the GPU. It runs as wave64 and wave32. A control run with the flag preset by the CPU checks the harness itself.This conflicts textually with #1267, which reworks the same read sites; I'll rebase onto whichever lands first.
Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti (driver 610.88).
guest_sce_nettimed out (it times out locally on unrelated branches too, likely my network filtering). It was run from the generatedCTestTestfile.cmakecommands because antivirus blocksctest.exeon this machine.tools/check_conventions.py --base origin/mainpasses.CrossWorkgroupFlagfails on this NVIDIA GPU without the change and passes with it; lavapipe passes either way.mainplus my open RADV PRs and local stubs): the GPU hang during RADV's BVH build went away. The build's output is still wrong for a separate reason I haven't found yet, sor_rtshadowsdoesn't work yet.Not tested on Linux or macOS.
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 joelfernandes23 on 2026-10-09T14:29:04Z.
Tested exact PR head
fc01be39fa2a6e1389a3a8f9e892b53f1b408ed2on AMD Windows, based on maind70b89989473ba1f6ae13e44e079e67f1f8a44b0.Environment: Windows 11 Pro 10.0.26200, Ryzen 7 7700X, RX 7900 XT (RDNA 3, Vulkan device 0x744c), AMD driver 32.0.31041.1004, Vulkan 1.4.349. WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7, Release, BUILD_TESTING=ON, SPIRV-Tools OFF. ANYPS5_GPU=7900 XT and ANYPS5_REQUIRE_VULKAN=1.
agc_driver_cross_workgroup_flagpassed 30/30 consecutive runs with the PR. The verbose run selects the RX 7900 XT; both CPU-preset controls and both cross-workgroup dispatches reportflag 1, result 2in wave64 and wave32.SpirvBdaRead.cppto main, retaining the identical regression source, and rebuilt the test and its dependencies. The test also passed 30/30 runs without the production fix. This is an AMD Windows passing control, not a reproduction of the reported NVIDIA failure.agc_driver_shader_clock(#1615) andagc_driver_vopc_compare_table(#825). The third was a 30-secondwindows_import_modulestimeout; an isolated rerun passed in 4.38 seconds. Its cause has not been established. The skip isguest_video_out_wqhd_detection_no_vulkan.No title test or native-instruction hardware oracle was performed. No modifications to the PR implementation are proposed.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:53:33Z.
Reviewed the diff: the atomic path is only taken for mapped, 4-byte-aligned addresses (
SpirvBdaRead.cpp:176,:254), the byte path and non-coherent loads are unchanged, and the phi/merge structure is correct. Built merged onto main;agc_driver_cross_workgroup_flagpasses on RADV.What we can't confirm here: the test also passes without the change on RADV/lavapipe (and on an RX 7900 XT per @joelfernandes23), so it only fails on NVIDIA, which we can't run.
@oneandonlydean could you run
agc_driver_cross_workgroup_flagon the RTX 4090 with and without this change (expected: result 3 without, 2 with)? If it reproduces, this is good to merge.@TheAggie: this conflicts with #2349 in
SpirvBdaRead.cppandlibSceAgcDriver/CMakeLists.txt; whichever lands second will need a rebase.Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:05:26Z.
Additional platform validation on standalone PR head
8d6f765bd8e0f6abbcbe2f65b610a41ffd981fd7:Linux: passed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja.
Release /
BUILD_TESTING=ON: built the selected test targets; 1 CTest cases, 0 failures, 0 CTest skips.Tests:
agc_driver_cross_workgroup_flag.Reproduce after building the test targets:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^agc_driver_cross_workgroup_flag$".Vulkan: Mesa lavapipe 26.2.4 software Vulkan; no native Linux GPU/retail-title validation.
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-10T10:58:55Z.
Independent validation on real hardware
I built and ran the PR head
8d6f765bon my own box (not the author's):Release,BUILD_TESTING=ON.Result with the fix (PR head):
agc_driver_cross_workgroup_flag_testsPASSES on all three GPUs —result 2(flag seen) for both wave64 and wave32, and the CPU-preset control run also returns2.Rigor check (is the test real, or a pass-through?): I reverted only
core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cppback to the PR base (00112489) — i.e.OpAtomicLoad ScopeDevice→ the oldOpLoad Volatile/ byte path — rebuilt the test, and re-ran on the 5090:result 2→ the harness itself is correct;global_load_dword glc dlcspin →result 3("a workgroup did not see another workgroup's flag store") on both wave64 and wave32 → FAIL (exit 1).Restoring the fix puts it back to PASS. So this is a genuine regression test: it fails on base NVIDIA and the atomic-load change is exactly what turns it green — which matches the author's reported "result 3 → result 2" on NVIDIA.
Bottom line: On my 5090/4090/iGPU the PR is green, the new test is a real (non-pass-through) regression test, and it additionally passes on an AMD iGPU beyond what was reported. I did not test Linux/macOS or the 5070 Ti, and I didn't evaluate the noted textual conflict with #1267 (rebase is the author's call).
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T12:52:40Z.
Merged onto
main197ffac9this no longer builds (Linux, GCC 16.2.1):Addtakes a fifth argument (bool gpu) sincec84694ad, merged 2026-10-10; the other execution tests passtruethere. GitHub still reports the PR as mergeable because there is no textual conflict.With
Add(block, BlockBytes, true, true, true)applied locally,agc_driver_cross_workgroup_flag, 5 runs each on Linux:SpirvBdaRead.cpprevertedwave64: flag 1, result 3)Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T02:10:52Z.
Same as fma-rc's note above, still the case on current
main(d31b57a4, and84cc975e) on Windows 11 with WinLibs GCC 15.2.0:CrossWorkgroupFlag.cpp:44needs the fifthgpuargument ofGuestAllocations::Mutation::Add(c11a9cb5, merged inc84694ad). Sorry for the repeat, I missed the earlier comment.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-11T07:47:28Z.
Thanks @fma-rc and @Silverash-i8, fixed. The branch is rebased onto
main2bb78d2c, andeb33094epassestruefor the newgpuargument ofMutation::AddinCrossWorkgroupFlag.cpp, as the other execution tests do.On Windows 11 / RTX 5070 Ti it builds again, and
agc_driver_cross_workgroup_flagpasses along with the BDA and recompiler tests I reran with it (4 of 4).AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:26:26Z.
Checked the diff (atomic path only for mapped, 4-byte-aligned addresses; byte path and non-coherent loads unchanged; phi/merge structure correct). Built merged onto main:
agc_driver_cross_workgroup_flagand the rest of the Agc/AgcDriver ctest pass on RADV. The test only fails without the change on NVIDIA, which is confirmed independently by @fma-rc (Linux, RTX 5080: 5/5 with the change, 0/5 reverted,result 3) and @klosixgaming-arch (Windows, RTX 5090: fails reverted, passes with the change). Merging.