perf(agc): import a range mapped again on first use instead of at map #8622
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8622"
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 LeandroLP23 on 2026-10-20T18:48:16Z.
What
ImportMappedRanges(#1961) imports a GPU-mapped range whole when it is mapped. This is right for a large pool mapped once. For a buffer the guest maps and unmaps over and over at the same address, each map pays a whole-range import on the mapping thread and each unmap retires it.SuperTuxKart (PPSA69421) maps and unmaps one 2 MiB direct-memory buffer,
0x255200000, about 48 times a frame (APS5_TRACE_MEMORY). Each time it ismap direct 0x255200000+0x200000 phys=0x54e00000 prot=0x33. In a 75 s menu run,APS5_TRACE_HOST_IMPORTlogged 21,697 imports by map (19,980 of them of that buffer). On Windows, a direct mapping with a single view is committed private memory, and its bytes are saved at unmap and copied back at map. The pages differ at every map, so the import cannot be kept across the unmap.The table now remembers the ranges (address and size) it imported at map. A range mapped again with the same address and size, and no import left over it, is no longer imported at map; its first GPU use imports it, as before #1961. The first mapping of a range is still imported at map, so the PPSA36082 case #1961 describes (pools mapped once while loading) is unchanged. A range whose import still exists is still checked at map, so the stale-probe repair keeps validating it there. The set is cleared when the table moves to another device and by
ClearHostImports.agc_driver_host_import_at_mapexpected a range mapped again to be imported at map. It now expects that range not to be imported at map, and expects its first GPU use (a fill) to import it. #8802's replacement-owner regression now expects the replacement to retry its predecessor's failed import on first use rather than at map.importAtMapOverBudgetTestsandimportRequesterTestsregister fresh ranges at heap addresses earlier fixtures used, so they start fromClearHostImports.Tested
Windows 11 26300, AMD Ryzen AI 7 350 / Radeon 860M (driver 32.0.13058.8001), WinLibs GCC 15.2.0, Release.
agc_driver_host_import_at_mappasses; withGuestBufferMemory.cppfrommainit fails with "a range mapped again was imported at map instead of on first use".agc_driver_graphicspasses. Onmain'sGuestBufferMemory.cppthe adapted #8802 check fails with "a replacement owner was imported again at map instead of on first use".agc_driver_graphics, the host-import, import-settle, sparse-run and BDA tests andagc_buffer_poolpass withANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1(25 of 25,agc_host_import_sparseskips). The Khronos validation layer is not installed on this machine.mainatec7eacc62and this PR rebased onto it, each a clean build of its commit.APS5_TRACE_SECONDS=40:8mainec7eacc62d58bf66eeccfdc9APS5_TRACE_SECONDS=95:20mainec7eacc62d58bf66eeccfdc9The menu gains 14 %. The race on
mainis bound by texture copies (about 400 ms a frame), and the change is within run-to-run noise there. Onmain+ #8538 + #6718, earlier and with window-title FPS, the race went from 7.55 to 7.8, one run each.Summary lines (menu)
Traces:
mainmenu, this PR menu,mainrace, this PR racetools/trace_digest.pyonmain(menu)seconds 40:8 from present 328: 83 presents, frame p50 96.6 / p90 102.9 / p99 110.2 / max 110.2 ms, GPU busy 5.6 ms per present
AMD Radeon(TM) 860M Graphics, AMD proprietary driver 24.30.58.08 (LLPC), Windows 10.0.26300, 1920x1080, commit
ec7eacc62d, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 93.9, Driver.WorkerWait.idle_and_completion_poll 93.8, Graphics.Draw 5.7, Graphics.Draw.draw_and_resource_release 4.8, Vulkan.DrawFromRecipe 4.5, Graphics.DrawWithRecipe 4.5, Graphics.DrawWithRecipe.draw_and_resource_release 4.5, Recorder.Submit 3.3, Driver.Packet 2.5, Driver.Packet.draw 2.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.pywith this PR (menu)seconds 40:8 from present 363: 94 presents, frame p50 85.1 / p90 90.0 / p99 100.8 / max 100.8 ms, GPU busy 5.8 ms per present
AMD Radeon(TM) 860M Graphics, AMD proprietary driver 24.30.58.08 (LLPC), Windows 10.0.26300, 1920x1080, commit
bf66eeccfd, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 81.9, Driver.WorkerWait.idle_and_completion_poll 81.8, Graphics.Draw 6.1, Graphics.Draw.draw_and_resource_release 5.2, Vulkan.DrawFromRecipe 5.1, Graphics.DrawWithRecipe 5.0, Graphics.DrawWithRecipe.draw_and_resource_release 5.0, Recorder.Submit 3.3, Driver.Packet 2.3, Driver.Packet.draw 2.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Skipping every map-time import gave 8.7 FPS in the same menu. Most of the remaining gap is the ranges imported at their first map that the GPU never reads: 322 imports, 961 MiB live, against 3 imports, 130 MiB. That is the trade #1961 describes, and this PR leaves it alone.
#7465 changes the same lines: it defers map imports of ranges up to 64 KiB. The 2 MiB buffer here is not covered by it.
tools/pr_overlap.pyfound no other overlap among the PRs it could compare.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-20T18:48:31Z.
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 MarcZX10 on 2026-10-20T19:33:49Z.
Code review location:
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp; line 241importedAtMapis a process-lifetime history: this inserts every distinct mapped range address, and the only clear in the diff is on device change. A workload that repeatedly maps fresh addresses and unmaps them can leave onestd::setnode per address after the corresponding imports are gone. Could this history be bounded (for example, evict older addresses at a fixed cap)? If an evicted address is seen again, eagerly importing it is the existing behavior, so the cap should affect only this optimization, not correctness.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-20T20:05:57Z.
These are the traces behind the two summary lines in the description. Both are SuperTuxKart main-menu captures with
APS5_TRACE_SECONDS=40:8, Radeon 860M, Windows 11 26300, taken one after the other:main: main-aps5-trace-976583da31c3-37108.json.gz. This is this branch built withGuestBufferMemory.cppfrommain892a4f132, so its summary says"dirty":true.The import and the retirement this PR moves run on the title thread, which is untraced (143 ms of the frame). That is why the digests show the change in frame time and presents, not in a named slice: 56 → 67 presents in 8.1 s, p50 144.2 → 120.8 ms.
tools/trace_digest.pyonmainseconds 40:8 from present 220: 56 presents, frame p50 144.2 / p90 148.2 / p99 151.4 / max 151.4 ms, GPU busy 6.1 ms per present
AMD Radeon(TM) 860M Graphics, AMD proprietary driver 24.30.58.08 (LLPC), Windows 10.0.26300, 1920x1080, commit 976583da31c3 (dirty), dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 140.5, Driver.WorkerWait.idle_and_completion_poll 140.4, Graphics.Draw 10.2, Vulkan.DrawFromRecipe 9.0, Graphics.DrawWithRecipe 9.0
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.pywith this PRseconds 40:8 from present 262: 67 presents, frame p50 120.8 / p90 126.9 / p99 134.2 / max 134.2 ms, GPU busy 6.0 ms per present
AMD Radeon(TM) 860M Graphics, AMD proprietary driver 24.30.58.08 (LLPC), Windows 10.0.26300, 1920x1080, commit 976583da31c3, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 116.4, Driver.WorkerWait.idle_and_completion_poll 116.3, Graphics.Draw 9.6, Graphics.Draw.draw_and_resource_release 8.3, Vulkan.DrawFromRecipe 8.0
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T01:27:11Z.
Related: #8802 fixes failure-memo lifetime in
ImportMappedRanges. It removes the blanket failure-cache clear when an unrelated mapping changes the registry generation during an import. Its regression checks both unrelated mappings and retry after replacement of the actual mapping owner.Your repeated-address deferral addresses a different case, but the nearby map-import code overlaps. #8802 does not depend on the deferral; I can rebase it and adapt its replacement-owner regression to first-use import if #8622 lands first. Please let me know your preferred order.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-21T06:37:15Z.
@JJenkx #8802 landed first, so I rebased this onto it (
bf66eeccf) and adapted its replacement-owner regression to the first-use import, as you suggested:probe.callsstays at 1. The first use (HostImportForover the whole range) then retries the predecessor's failed import, andprobe.callsreaches 2. Onmain'sGuestBufferMemory.cppthe new map-time assertion fails, as expected.importStaleProbeTestsexact-whole case).ClearHostImportsnow forgets the deferred ranges too.importAtMapOverBudgetTestsandimportRequesterTests, which register fresh ranges at reused heap addresses, start from a cleared state.Tested on a Radeon 860M, Windows 11 26300, WinLibs GCC 15.2.0, Release, with
ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1:agc_driver_graphics, the host-import, import-settle, sparse-run and BDA tests,agc_driver_host_import_at_mapandagc_buffer_poolall pass (25 of 25,agc_host_import_sparseskips).Edit: an earlier version of this comment said
agc_driver_graphics(PA_CL_CLIP_CNTL) andagc_driver_host_import_failure_handlesfailed onmainon this machine. That came from an incomplete build: ninja stopped at an unrelated compile error and left stale test binaries. With a full build both pass onmainand on this branch.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T22:46:02Z.
AMD/Linux data point on a second title, measured next to #7465 (which defers small imports by size).
Setup
mainb5d763770a, both merge cleanly: #7465 at bc14a64eb0, #8622 at aba29494bd. Plainmainis the base.APS5_TRACE_SECONDS=200:30with 2097152 events.main, #7465, #8622, #8622, #7465,main.mainmainOn
mainthis title maps and unmaps small direct-memory ranges continuously. About 1.2 million map-time imports are attempted per run and refused, and the refusals start once earlyINVALID_EXTERNAL_HANDLEfailures have lowered the import budget.mainrun, but does not reach the cap here.This PR helps here, and the result looks consistent with what it targets: a range mapped again at the same address and size. The ~2,600 remaining refusals suggest some of this title's ranges come back at a different size, which a size gate like #7465's also covers. This is one machine and one scene.
AI-assisted: yes (Claude Code); results above were run on this machine.