perf(recompiler): load the written-page slot before the CAS #1280
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1280"
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-07T21:42:07Z.
What
Depends on #1265. Until it merges, this PR also shows its three commits; only the last commit is new here.
note_bda_writeruns a device-scopeOpAtomicCompareExchangeon every probe, also when the slot already holds the page. The written-page table lives in the BDA fault buffer, which is host-visible memory, so every BDA store pays an atomic across PCIe. Almost every store hits a page that an earlier store already noted.OpAtomicLoadand runs the compare-exchange only when the slot does not hold the page.Why the CAS is the cost
DOOM homebrew PPSA99666 v1.1.1 (lowbit/ps5-doom, GPL-2.0) presents through a small compute kernel: 1080 workgroups of 64, each reads palette-indexed bytes and stores 1920 pixels through raw pointers, about 2.07 M BDA stores per frame. It waits 500 ms for the frame's fence and otherwise falls back to its CPU scaler.
mainAPS5_PROFILE_GPU)APS5_SYNC_DISPATCH, packet time)APS5_PROFILE_GPU, ~590 dispatches per 10 s)Experiments on
mainbefore writing this:DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT(ReBAR) instead of system memory gave the same gain: about 170 ms to about 10 ms per frame.APS5_SPIRV_OPT=fullchanged nothing.This change keeps both buffers where they are and needs no ReBAR.
Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti, Ryzen 7 7800X3D.
agc_*andshader_*tests pass on this branch.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_memoryand the BDA tests pass (13 tests).main, the same change before #1265 also passed all 396 registered tests.CTestTestfile.cmakefiles, because antivirus blocksctest.exeon this machine.APS5_DUMP_SHADERS,shader_202a81800.req, 304 code words) replays withagc_shader_replay; I can attach it.Not run on AMD, Intel or Linux.
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 johnmaia on 2026-10-08T18:59:03Z.
Measured on AMD and Linux, 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, resizable BAR on). This PR's head is
1dca7b4f(including #1265), merged onto main6b56175a.DOOM homebrew PPSA99666 v1.1.1, built from source, relinked with
--exclude-sce-module libc.prx. A test plan offrames 1500, a warm-up run first and then a measured run. GPU time is fromAPS5_PROFILE_GPU, in two 10 s windows of about 600 presents each:mainOn RADV the compare-exchange that this PR avoids is cheap, so
mainis already about 120× faster per present than the 174 ms measured on the RTX 5070 Ti. The fault buffer is in the same memory as on Windows:Bufferpicks host-visible, coherent, cached memory, which is system memory, not the ReBAR heap. The PR still takes 9% off the presenter's GPU time here, and nothing regressed.Code size with
APS5_PIPELINE_STATS=1and cold caches (largest pipeline). As expected, the extra load per probe adds a little:flat_store: 126,612 → 141,368 B.global_vcc_base: 195,996 → 207,616 B.global_store_addtid: 82,636 → 93,356 B.global_atomics: 51,016 → 56,840 B.The full table on #1265 is here.
Full ctest: 479/479 pass on this branch, the same as on
main, with the GPU tests running on the RX 7600.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T04:22:31Z.
Linux results, since this was tested on Windows only. Everything passes here.
Nobara 44 (Linux 7.2), GCC 16.2.1, Release,
BUILD_TESTING=ON. This PR merged ontomain29e533ac.main29e533acmain+ this PRctest -R agc_driver -j1-E agc_driver)The CPU failure is
guest_dynamic_loader, which fails the same way onmain.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:18:03Z.
Checked the diff against the original probe loop: same slots in the same order, same
doneand overflow behaviour; a stale 0 or another page in the load just falls through to the compare-exchange as before. Built on currentmain(#1265 is merged, so only this commit is new): ctest 551/551 green on Linux. Also confirmed by @johnmaia (RX 7600, RADV) and @fisherjoey (RTX 5070 Ti and RADV). Merging once CI is green.Note: no existing test fails if the page is never recorded through this path (I forced the "slot already holds the page" check to true and
agc_driver_flat_store,global_atomics,global_store_addtidstill passed). Not a regression of this PR, but a test pinning the written-page table would be welcome in a follow-up.