perf(agc-driver): join the imports of adjacent large ranges when a buffer is bound across them #4515
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4515"
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 AlxcBTW on 2026-10-12T14:09:21Z.
Sword of the Sea (PPSA25344) main menu: a 368 MiB buffer bound across two registered ranges is imported once instead of being copied whole on every use. In the default env the menu goes from 289 to 134 ms per frame (3.5 to 7.5 FPS).
What
#3425 imports adjacent registered ranges as one only where they fill a whole aligned 8 MiB window. A range larger than the window always crosses a window edge, so it is imported alone. When a buffer is bound across two such ranges, no import covers it, and the whole region is copied on every use. Sword of the Sea binds a 368 MiB buffer across a 320.75 MiB range and the 47.3 MiB range right after it. Both are registered early and never grow, but they stay two imports. On
mainthe buffer is copied on almost every use: 549 times (202 GB) in a 180 s menu run.With this change,
UploadFinishlooks at every pending region that no import covers. If the region crosses adjacent registered ranges and each of them is larger than the window, the run of those ranges is imported once and their own imports are retired.UploadPrepareor by the cached address space are resolved again instead of trusted.refreshImportskeeps the joined import while exactly its ranges stand (HostImport::joined;sameRangechecks the joined run). A lookup on a stale registry no longer splits it.failedJoins(anImportFailurelikefailed, dropped once the joined run changes), so its ranges still import alone and the buffer is copied as before.joinedCovers).HostImportForreturns a joined import for a range that no single run covers, once it has reconciled.The TechnicalDebt entry for host imports says which ranges are joined now, and that a heap grown in pieces larger than 8 MiB would re-import its joined run once for each piece a bound buffer crosses into.
Tested
Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, on #4385 and #4367 (this branch is on top of both, on
mainffa198407).importJoinTests(new, inagc_driver_graphics). Onmainwith only this test it fails witha buffer bound across two adjacent ranges larger than the import window was not imported as one. It sets a 128 KiB window and checks:Non-GPU suite (Lenovo node,
ctest -E "^agc_driver|^video_out|^guest_video"): 600 of 601 pass, includingguest_memoryandagc_host_import_retire;log_macrosfails as onmainon that machine.agc_driver_graphics: passes on an RTX 5070 Laptop (616.92), withimportJoinTests.Sword of the Sea menu, 180 s rows, A B A B on our lab branch (
maina11c8f7f7plus local patches for this title), one build with the join switched off (A) and on (B). These rows were measured with this join on a lab build whose cross-section alias was our own earlier alias change rather than #4367. The mechanism is the same, and #4367 replaces it. A rerun on #4367 follows when the lab has a slot.Upstream default env (
APS5_RESOURCE_CACHE_ENTRIES=8192,APS5_PROFILE_DRAW=1):vkQueueSubmitmeanB's trace has
host import of 0x30b1880000+0x17010000 ok (...), joined at bind; its t170 capture shows the normal menu.With host imports kept write-watched and unit shadows off (
APS5_WRITE_WATCH_IMPORTS=watch, a local switch of ours that is not onmain, plusAPS5_NO_UNIT_SHADOW=1), the same A/B goes from 437 / 419 to 202 / 208 ms per frame, CPU copies from 269,671 to 10,381 MiB, and buffer pool evictions from 1762 to 0.Conventions:
tools/check_conventions.py --base origin/mainpasses.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 blawesom on 2026-10-12T14:53:43Z.
Pre-review found a deterministic test failure on Linux/RADV — same as flagged on #4517, which contains this PR's commits plus a generalization:
agc_host_import_retirefails 3/3 runs withAGC graphics: missing Vulkan function: vkCmdCopyBuffer(core 1.0 function, present on this device) — the new code resolves it throughcontext.Resolved(&DeviceFunctions::cmdCopyBuffer, ...)on a route where the test context has neither the table entry nor adeviceProcfallback.Since #4517 supersedes this PR's scope ("any size" vs "large ranges"), fixing it there and marking this one Depends on: #4517 (or closing it) may be cleaner than fixing both.
Reproduce:
ctest -R agc_host_import_retire --output-on-failureImported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T15:47:42Z.
@blawesom thanks for running it on RADV. The failing call wasn't the retire path: on Linux with uffd write watching, the first import runs the write-protection probe (
ProbeImportWriteProtection), which records avkCmdCopyBufferthrough the test's mock device, and that mock has none. The test now keeps its imports out of the probe on non-Windows (APS5_WRITE_WATCH_IMPORTS=unwatch, as on Windows), in #4385's63ddeb09f, merged into this branch.Checked on a fork runner (Ubuntu 24.04, kernel 6.17, lavapipe): with the previous test file it fails with exactly
missing Vulkan function: vkCmdCopyBuffer; with the fixagc_host_import_retirepasses 3/3. Windows non-GPU suite 600/601 (log_macrosas onmain), and the test passes on NVIDIA.On the dependency: #4517's body lists
Depends on: #4515; #4515 lists #4385 and #4367.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T10:32:04Z.
Please rebase onto main as this PR's own commit, without the merge commits: the branch has three, still carries #4367's old commit 87af6e09d (on main now as
2d1cc82bc), and conflicts indocs/dev/debt/libSceAgcDriver.md.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-13T11:46:32Z.
Rebased onto current main as the single PR commit, without merge commits. Dropped the old #4367 commit, which is on main now. The conflict in docs/dev/debt/libSceAgcDriver.md is resolved by keeping main's Windows alias sentence and re-applying our join sentences. Checked with check_conventions and a full Linux and Windows run on a fork branch before the push.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T16:34:04Z.
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/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL655-656, L662-664, L666-667, L669-680, L809, L2015-2017core/libs/prx/libSceAgcDriver/tests/BdaResources.cppL245, L1242