perf(agc): import adjacent host ranges as aligned blocks and stop re-trying budget refusals #6457
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6457"
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 EagleBearerYS on 2026-10-15T16:16:49Z.
What
A title that maps its GPU heap in 64 KiB pieces got one host import per piece. Resident Evil Village holds about 27,600 such ranges by its first scene and fills the import budget. At a full budget, every rebuild of the address-based build's address space asked again for every range the budget had refused.
APS5_TRACE_HOST_IMPORTlines;[gpu] host imports at shutdown: ….FlushGpuWrites, as readers of guest memory must.The worst case. A window that fills, or empties, one piece at a time with builds in between pays for each block upgrade: every doubling imports the block again, the old half included.
Overlap with #6499 (parl0v, the #6060 follow-up): it keeps an import whose head or tail a guest protect or unmap cuts off, re-attached to the surviving range with a new
VkBufferon the same memory.ImportWatched,replaceRangeor what a split keeps.GuestBufferMemory.cppin three places: the replaced-bytes sum inimportAllocation, the fields set on a new import, and the start ofrefreshImports. Whichever merges second keeps both sides, with the replaced-bytes sum counting #6499'spinnedBytes. Either order works.With #7339 and #6678 (both merged): this branch's merge of
main3de84fa106(399cc69e9f) takes #7339's guard over a host import while it is built, with this PR's signature and requester counts. On the failure path that retries as smaller blocks, the failed attempt's alias is unmapped before the retry and handed to the guard as null, so it is unmapped once. #6678's settle structures and calls sit beside this PR's refusals, as its description lists. #7339's copy lifetime check mapped its source and destination back to back, which this PR imports as one aligned block, so the source's protection change retired both;1b304c8e9fmaps them with an unmapped block between them, so the check still covers two separate imports. The merge ofmain66e71b63d1(0b84427db3) takes #5390'sHostImportOffsetwording inHostImportFor's declaration with this PR'srequesterparameter; this PR's own code computes no buffer offset asaddress - base, so #5390'sleadreaches it throughHostImportOffset.Related: #4260 (its first cause: a buffer crossing adjacent ranges of a window that is not full is now imported in place when one filled aligned block holds it; a buffer crossing a block or window edge is still copied. #4367 fixed its second cause, the Windows alias).
Tested
Resident Evil Village (PPSA01556), Windows 11, RTX 3070 Laptop GPU (driver 617.42), on main
6ea62f9b40with #6366, #5703 and #5815 (open) and local commits for its sample-count stops, at main's default budget:[gpu] host import budget: 5840 MiB live of 5840 MiB (APS5_HOST_IMPORT_MIB)).[gpu] host import budget: 5375 MiB live of 5840 MiB (APS5_HOST_IMPORT_MIB); 21138 imports (71872 MiB) refused so far, last 0x200200000+0x30000000. The last is the 768 MiB heap, retried again and again.Linux, lavapipe (CI's job mirror):
^agc598/598, and the new tests 10 of 10 at each commit.AcquireRegisteredper rebuild: 57.8 → 43.2 ms with the budget at 60 % of the registry, and 50.0 → 19.7 ms at 100 %;importRun: +111 ns per call.Windows (GitHub's runner, MinGW, no Vulkan device), on this branch before its rebase onto
main(0f85236fef, the same code; run): it builds, and 591 of 592^agctests pass (460 skip without Vulkan). The one failure,agc_driver_pm4_replay_tool(0xc0000139), and libkernel'sguest_kqueuealso fail onmainon that runner.Windows 11, RTX 3070 Laptop GPU (driver 617.42), at this head: the new and changed tests (
agc_storage_writeback_blocks,agc_driver_graphics,agc_driver_storage_write_back_overhang) pass 5 of 5. With the import code before the aligned blocks,agc_storage_writeback_blocksfails with "a 4 MiB image over 64 adjacent 64 KiB pieces: the write-back made 64 imports, expected 1", andagc_driver_graphicswith the host import report line (no remembered count).Merged with
main66e71b63d1(0b84427db3, after #5390), on GitHub's runners (run): the host import, settle, lifetime and sparse tests pass 3 runs in a row on Linux, as do the^agctests (709, 0 failed), and the libc and libkernel suites pass; on Windows only the two replay tools named below fail. The earlier merge withmain3de84fa106(1b304c8e9f) ran the same way (run): the host import, settle and lifetime tests pass 3 runs in a row on Linux, as do the^agctests (709, 0 failed), and the libc and libkernel suites pass. On Windows the only failures areagc_driver_pm4_replay_toolandagc_shader_replay_tool, which fail the same way on that runner for an unrelated branch (run). Before the test commit, the merge withmain3b887b51c8failedagc_driver_guest_memory_lifetime_copyon Linux with "source retirement unnecessarily retired the copy destination" (run); with it, that test and the host import tests passed 10 runs in a row (run).Checklist
main0029e62f97, merged withmain66e71b63d1. The tests above ran on598dd15954; the rebase changed one line of the debt file, next to main's new entry. No other open PR implements the same functions. Overlaps (git merge-treewith each):refreshImports' pruning ofstate.failed: merged, #6442'ssameRangefor failures passes the budget toimportRun, as this PR's loop does.agc_storage_write_back, this PR'sagc_storage_writeback_blocks); if both land, both tests run on the merge.importRunfor every requester: one adjacent declaration.importRun's walk to the ends of the run per lease snapshot (walkRunBounds,importRunBounds), and hassameRangeandimportAllocation's whole-run lookup compare an import with the run's whole span. This PR imports an aligned block inside that run, or the containing range alone, and skips remembered refusals there, so an import can cover only part of its run. They conflict inimportRunandsameRangeinGuestBufferMemory.cpp. Whichever merges second should have this PR'simportRuntakefirst,lastandindexfromimportRunBounds, and keepsameRangeand the whole-run lookup comparing with the blockimportRunreturns for the current budget, since an aligned block import doesn't span the whole run. That merge hasn't been built yet.HostImportsfields and map time's call inGuestBufferMemory; keep both sides.NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file (none added).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-15T16:37:14Z.
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)docs/dev/debt/libSceAgcDriver.mdL137core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL1253-1256, L1272-1276, L1347, L1489core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL1522-1523, L3447-3448, L3451core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppL7, L75core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL1603-1608, L1841-1843, L3205-3206, L3223docs/dev/debt/libSceAgcDriver.mdL137-138core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL1506docs/dev/debt/libSceAgcDriver.mdL195core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL1801-1810Some 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/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cppcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-18T05:24:44Z.
@oneandonlydean a question on #7339's copy lifetime check, which this PR's merge of
mainran into.CheckCopymaps its source and destination back to back, and this PR imports adjacent registered ranges that fill an aligned power-of-two block as one import. So the two 64 KiB ranges became one 128 KiB import, and the source's protection change retired the destination with it. The data stays correct:CheckPattern(destination)passes just before the failing check.1b304c8e9f, a separatetest(agc)commit after the merge, maps the two ranges with an unmapped block between them, so each is its own import and the check still shows that retiring one import leaves an unrelated one in place. Would you rather keep that, or have this PR split a block when one of its pieces changes, so the other pieces keep their imports? We'll go with whichever you prefer.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T19:33:43Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T03:22:14Z.
@EagleBearerYS keep
1b304c8e9f. There's no need to split blocks in this PR.refreshImportsretires any import whose ranges no longer match (sameRange), andCheckPattern(destination)shows the data is intact.importAllocationon its next access. That's one re-import, bounded by the 8 MiB window, the same kind of cost as the block upgrades the description already accepts.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-19T03:24:14Z.
@oneandonlydean thank you, that settles it:
1b304c8e9fstays, and the block isn't split in this PR. If a title shows re-import churn from a retired block, it goes to #6499's sub-range re-binding as a follow-up.