fix(recompiler): write a coherent dwordx2 as one 64-bit atomic store #7603
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7603"
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 HQasper on 2026-10-18T16:40:16Z.
What
A glc or dlc
buffer_store_dwordx2is one 64-bit write on the GPU. It was emitted as two dword stores, flag word first. A workgroup that polls the pair can then read the new flag with the old value. #919 made the coherentbuffer_load_dwordx2one 64-bit read, but only in programs that already had the u64 storage-buffer view, which means programs with 64-bit buffer atomics. The store side was never covered.GTA V (PPSA04264) builds each BLAS with a single-pass decoupled look-back scan. Its tiles publish
{flag, value}with a glcbuffer_store_dwordx2and poll the earlier tiles with glcbuffer_load_dwordx2. The program has no 64-bit atomics, so both its stores and its loads were split. I dumped one build (45 tiles):Changes:
LoadBufferU32x2orStoreBufferU32x2now gets the u64 view (buffers_u64,Int64,Int64Atomics) when the device hasshaderBufferInt64Atomics. Before, only programs with 64-bit buffer atomics got it. On a device without that feature nothing changes.OpAtomicStore. Otherwise it keeps the per-dword path.coherentPair. Before, it only checked the first dword with an 8-byte access, which went wrong in two cases:Tested
Windows 11 Pro 26300, NVIDIA GeForce RTX 5090 (617.42, 32-lane subgroups), MinGW-w64 Release build of this branch on
main91ddd9e3a. After the rebase onto81cb86339, whose two new commits touch neither the recompiler nor the AGC driver,agc_driver_look_back_scanpasses again.agc_driver_look_back_scan_testsnow also runs its scan kernel with the twobuffer_atomic_swap_x2replaced by glcbuffer_store_dwordx2(0xe0745000). Without the recompiler change the new variant fails its first whole scan:buffer_store_dwordx2 whole scan 0: block 116's prefix is 57920, expected 58669. With it both variants pass, in 6 of 6 runs.ctest -j 24: 1488 of 1489 pass. The one failure,agc_driver_pixel_lds, is unrelated. It loses the device (Vulkan result -4) on this RTX 5090, and did so on plainmain55f82fee8too.Linux and AMD not tested.
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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T16:54:58Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppImported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T18:06:18Z.
AMD run, since the description lists AMD as not tested. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Build:mainc3591adf9with #7623, #7612, #7611, #7603, #7579, #7563 and #7541 merged together (each merge clean, built once).agc_driver_look_back_scanandagc_driver_pixel_ldspass 3 runs of 3.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T18:44:09Z.
Verified at head
e5b4bd72d:agc_driver_look_back_scanpasses on NVIDIA RTX 3070 (driver 617.42) and Intel UHD 630 (ANYPS5_GPU=UHD, igvk64) - second NVIDIA datapoint and first Intel. Windows 11, MinGW (WinLibs GCC 15.2.0), Release.Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-18T21:53:04Z.
RDNA 4 data:
agc_driver_look_back_scanfails onmainand passes with this PR on an AMD RX 9070 XT. The Intel UHD 770 skips it, since it has noshaderBufferInt64Atomics.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This heade5b4bd72dmerged intomainf3059421f. "Without" means this PR's test files onmainf3059421f, with none of its other changes.agc_driver_look_back_scanshaderBufferInt64Atomics)buffer_store_dwordx2 whole scan 0: block 2's prefix is 0, expected 27I also ran full CTest with this PR and the 14 other open AGC PRs I tested in the same batch merged together (#7647, #7641, #7630, #7627, #7600, #7591, #7579, #7535, #7533, #7474, #7462, #7050, #7048, #7650). Neither GPU showed a failure beyond
main's own, except #7650's new test.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-19T12:14:53Z.
RDNA 2 data, the PS5's own architecture, which this PR hasn't had yet: RX 6700 XT (gfx1031), AMD driver 32.0.21045.5002, Windows 11 26200, WinLibs GCC 15.2.0 r7, Release.
main676269473; full builds in both columns.The test.
agc_driver_look_back_scan, 10 runs each:mainwith only this PR'sLookBackScan.cpp: fails 10 of 10, always inbuffer_store_dwordx2 whole scan 0, e.g.block 6's prefix is 1605, expected 2399andblock 4's prefix is 794, expected 1589.main+ this PR (e5b4bd72d): passes 10 of 10. The 27 tests matchinglook_back|buffer_store|buffer_load|atomic|coherent|glcpass, exceptagc_driver_lds_mixed_width_atomics, which fails onmainhere too (#6976).The hardware claim ("a glc or dlc
buffer_store_dwordx2is one 64-bit write"), measured natively through HIP. In one dispatch of 32 wave32 waves, 16 waves each store 20,000 pairs{i, i * 0x9e3779b9}with glc to 32 slots, and the other 16 waves read those slots 20,000 times with glc dlc and count pairs whose halves don't match. 10,240,000 reads per run, 3 runs per row:buffer_store_dwordx2/buffer_load_dwordx2global_store_dwordx2/global_load_dwordx2global_store_dword/global_load_dwordx2global_store_dwordx2/ twoglobal_load_dwordSo on RDNA 2 the 64-bit store and the 64-bit load are each single accesses, and the two controls show the check catches a split write or a split read when one exists. That supports emitting the pair as one 64-bit store and reading it as one, as this PR does. Desktop RDNA 2, not a PS5.
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T15:44:26Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
main43a2abaf7(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8): 1636/1638 with this PR, against 1636/1638 onmain. The failures are the same two on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784). The PR adds no new ctest entry; every existing test it touches passed.GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T10:45:01Z.
Checked the diff: the coherent
dwordx2store is now one device-scope 64-bitOpAtomicStorewhen both dwords are in bounds, adjacent and 8-byte aligned, otherwise the per-dword path; load and store sharecoherentPair, which also fixes the structured and swizzled pair cases of the load. The newLookBackScanstore variant fails without the change (reported on RDNA 2 by @thuanquang) and passes on the NVIDIA, AMD (RDNA 2/3.5/4, RADV) and Intel runs in the thread; merged.