perf(recompiler): loop the BDA byte stores and written-page probes #1265
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1265"
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 popcoder565 on 2026-10-07T20:28:23Z.
What
Addresses the code size reported in #1256. Two changes, one commit each. Neither changes what is stored, which faults are recorded or in which order.
get_bda_write_pointerlookup and onenote_bda_writeper byte at the store site, so a 32-bit store carried five write lookups. These byte stores now callwrite_bda_bytes(one per coherence,DontInlinelikeread_bda_dword_bytes), which loops over the bytes and does, per byte and in order, the same lookup, the store when the byte is mapped and the write note. Aligned 32-bit stores keep their single 4-byte lookup. The probe-first path of the reads is not used here, as it would change how an aligned store that crosses a range boundary records its fault.note_bda_writeunrolled its 8 compare-exchange probes and is inlined at every BDA store and atomic. The probes now run in a loop that tries the same slots in the same order and stops at the same slot, so the recorded pages and the overflow flag are unchanged.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 3060 Laptop GPU.
agc_driver_flat_storewithAPS5_PIPELINE_STATS=1,ANYPS5_NO_SHADER_CACHE=1and a freshAPS5_LOOP_GUARDper run to miss the driver's pipeline cache:mainEvery other test with BDA stores or atomics shrinks too: largest pipeline, same settings,
main1e1e1390against it merged with this PR.mainglobal_vcc_baseglobal_store_addtidglobal_atomics_floatflat_cache_bitsglobal_atomicsglobal_atomics64global_atomics_lanesglobal_atomic_csubBuffer, LDS and image atomics are unchanged.
ANYPS5_ENABLE_SPIRV_TOOLS=ON, which validates every module before and after optimization:flat_store,global_store_addtid,global_atomics,global_atomics64,global_atomics_float,global_atomics_lanes,global_atomic_csub,flat_cache_bits,global_vcc_base,flat_loads,d16_memoryandagc_driver_bda_device_testspass.guest_system_font, which fails the same way onmainon Windows (#1172);agc_driver_bda_device_tests(not in ctest) passes.Measured on Intel by @hashaam1217 (comment): Linux, Iris Xe (Alder Lake GT2), Mesa 25.2.8 ANV, cold caches, applied to
2cc5735d.flat_storemainglobal_store_addtidandglobal_vcc_baseshrink the same way: 20,550 → 8,725 and 67,050 → 43,416 GEN instructions for their largest pipelines.main, and their RTX 3060 run passes all 402.flat_storeandglobal_vcc_basepass instead of being killed above 5 GiB.Measured on AMD by @johnmaia (comment): Ubuntu 24.04, Radeon RX 7600 (RADV NAVI33, Mesa 25.2.8), cold caches, merged onto
6b56175a.mainflat_storeglobal_vcc_baseglobal_store_addtidmain, so RADV never had the long cold compiles. The store-heavy pipelines still shrink by 38–59%; the atomics tests change by about 2%.mainand on this PR, with the GPU tests on the RX 7600.mainand 1.43 ms here.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)Imported from boykopovar/AnyPS5. Originally posted by hashaam1217 on 2026-10-08T02:09:30Z.
Measured on Intel, which the description lists as not run: Linux, Iris Xe (Alder Lake GT2), Mesa 25.2.8 ANV, applied to
2cc5735d, cold caches.flat_store: 84.4 s and 7.04 GiB peak RSS on main, 27.0 s and 1.81 GiB with this change. Its two pipelines compile to 26,393 and 50,309 GEN instructions instead of 55,929 and 111,860.global_store_addtidandglobal_vcc_baseshrink the same way (20,550 → 8,725 and 67,050 → 43,416 instructions for the largest pipeline).flat_storeandglobal_vcc_basepass instead of being killed above 5 GiB.Tables and the other PRs are in https://github.com/boykopovar/AnyPS5/issues/1256#issuecomment-6050724960.
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-08T02:58:32Z.
@hashaam1217 thanks for measuring this on Intel. That was the gap in my testing, so I've added your numbers to the Tested section, with a link to your comment.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-08T12:31:28Z.
Review: APPROVED
Reviewed the semantics against the unrolled original and the surrounding helpers; this matches what the description claims, and the two things I specifically tried to break both hold:
BdaCoherent(state, inst)readsmemoryInfo[index].coherentfrom the same vector theany_ofinDefineBdaByteWriteFunctionsscans, socoherentAccesses == falseprovably implies no store can select index 1 and hit thefunction == 0failure. TheFailremains as a genuine assertion, not a reachable path.OpLoopMergeimmediately before the header's conditional branch, back-edge from the continuation block, entry block closed with a branch), and the per-byte/per-probe behaviour — guest address computation, shift amounts (max 24 for a 4-byte store), faultpcpropagation, probe slot order and early-exit-on-done— is identical to the unrolled forms.BdaAccessMask(coherent)inside the helper equalsBdaAccessMask(state, inst)at every call site by construction.Two things before this lands, one a request for a number, one a coverage note:
1. Every measurement in the PR is cold-compile time or code size — there is no runtime number for the path that changed. Byte stores (all 8/16-bit stores plus the unaligned half of 32-bit stores) now pay a
DontInlinefunction call and a loop where they previously had inline unrolled code. On paper that is the right trade for a 20x cold-compile win, but a shader doing a large volume of small stores in a hot loop is exactly the case where it could regress runtime while every compile-time metric improves. A warm-run timing ofagc_driver_flat_store(or a title with heavy byte-store traffic) on the NVIDIA box that produced the other numbers would close this; if it is flat, this is unambiguously good.2. Not run on AMD (stated in the description). The probe-loop conversion changes the shape of atomically-executed code in
note_bda_writesubstantially, and this repo's test failures cluster on RADV/RDNA (e.g. #825, #985). A single RADV run of the BDA/atomics set (agc_driver_flat_store,global_atomics*,flat_cache_bits) would rule out a driver-specific surprise — happy to run it if someone confirms the commands.Minor, no action needed: the non-coherent
write_bda_bytesis defined for every program withbdaWriteseven when only aligned 32-bit stores are emitted, so such programs carry one dead helper. Drivers strip it and it is a handful of instructions; only worth touching if you ever gate it on a pre-scan.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-08T12:31:38Z.
Correction to my review: I wrote I was happy to run the RADV set — I checked afterwards and this box has no Vulkan device (virtual VGA, no ICDs), so the AMD run needs someone with a RADV GPU. Everything else in the review stands.
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-08T18:59:02Z.
Measured on AMD, which the description lists as not run: Ubuntu 24.04.5 (kernel 6.8), GCC 13.3, Release, AMD Radeon RX 7600 (RADV NAVI33, Mesa 25.2.8). This PR's head is
d3cdffac, merged onto main6b56175a.The settings were
ANYPS5_NO_SHADER_CACHE=1andMESA_SHADER_CACHE_DISABLE=true, so every run compiles cold, plusAPS5_PIPELINE_STATS=1for RADV's code size and instruction count. Times are the median of three runs.maincode size / instructions (largest pipeline)mainrunflat_storeglobal_vcc_baseglobal_store_addtidflat_cache_bitsglobal_atomicsglobal_atomics64global_atomics_floatglobal_atomics_lanesglobal_atomic_csubmain, so RADV never showed the 20 s and 84 s cold compiles seen on NVIDIA and Intel. The byte-store helper still cuts the store-heavy pipelines by 38–59%.mainand on this PR, with the GPU tests running on the RX 7600 (none skipped).APS5_PROFILE_GPU, two 10 s windows of about 600 presents): 1.45 ms onmain, 1.43 ms here.Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T02:56:18Z.
@johnmaia thanks for the AMD run. I added a summary of it to the description in place of "Not run on AMD".
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:03:29Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvBda.hppL28core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cppL234-235Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:40:47Z.
Checked the diff against the unrolled original: the byte loop keeps the per-byte order (write lookup, store when mapped, write note), the 8-probe loop in
note_bda_writetries the same slots and stops at the same one, andBdaCoherentmatches theany_ofthat decides which variants exist. Built on currentmain: ctest green apart frompatched_libraries(missinglibkernel.prxin the build dir, unrelated); the BDA store/atomic tests pass on RADV. Intel/AMD/NVIDIA numbers from @hashaam1217, @johnmaia and the PR author cover the rest. Merging.