perf(agc): defer small host imports until first GPU use #7465
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7465"
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 Dripl1x on 2026-10-18T08:46:52Z.
What
ImportMappedRangesinGraphics/src/GuestBufferMemory.cpp, the observer that runs when a title maps memory for the GPU, imports every such range at map time (#1961). A title that maps and unmaps small ranges over and over pays a whole host import on the mapping thread at every map, and retires it at every unmap.This PR leaves ranges of 64 KiB or less to their first GPU use:
ImportMappedRangesskips a mapped range of 64 KiB or less, and takes the registry lease only when a range in the batch still needs an eager import (five changed lines).HostImportFor, counted for theaccessrequester), as before #1961; a small range the GPU never uses is never imported. As @oneandonlydean noted above, that path is the existing fallback, so the change moves when a small range is imported, not whether it can be.Where it helps
mainb5d763770a, ordermain, this PR, #8622, #8622, this PR,main): onmainthe title attempts about 1.2 million map-time imports per run and has them refused once earlyINVALID_EXTERNAL_HANDLEfailures lower the import budget (1,252,731 and 1,183,020 refusals). With this PR, 59 refusals; the frame rate goes from 47.86 / 53.95 FPS to 59.94 / 59.94, the title's 60 FPS cap, with p99 16.7 ms in both runs. This is the PR's standalone gain. I could not reproduce it: I do not have the title.main2185dbf92eagainstmainwith the eleven PRs of that series, which include this one; a local counter build withAPS5_PROFILE_DRAW=1, not used for FPS):ImportMappedRanges784 µs to 0.26 µs per call andsceKernelMapDirectMemory869 µs to 23 µs per call, about 48 calls of each per frame.main94fbb8cea8main+ this PRa1cee90f52main+ this PR + #7464223f2469f5Tested
Update 2026-10-24. The head is now
de24508db4: currentmaine2b9700a98merged into this branch, with one conflict intests/BdaResources.cpp(importAtMapOverBudgetTests:main'sClearHostImports(context.device)from #8622 is kept together with this PR's 128 KiB range, as in #7464's merge). On that head, Windows 11 Pro 26300, RTX 3070 Laptop GPU, NVIDIA 621.01: the 133 ctest entries of the set below pass; under the validation layer (same switches as below) 133/133 pass onmaine2b9700a98and on the head, neither log reportswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither reports aVUID-. Linux (WSL Ubuntu 26.04, lavapipe):agc_driver_graphics,agc_driver_host_import_at_mapand the 69 entries ofagc_driver_recorder_tests(63 pass, the same 6 skip as below). The SuperTuxKart captures below were not repeated on this head. The rest of this section is about the previous head.The previous head was
a1cee90f52onmain94fbb8cea8: the change (789a5f686f), its map-time import test update (e0764b9e14), and a test fixture fix (a1cee90f52). Windows 11 Pro 26300, Ryzen 7 5800H, WinLibs GCC 15.2.0 r7, Release.importMappedFailureGenerationTestsintests/BdaResources.cpp, added tomainby #8802 after this PR's last rebase, maps one 64 KiB range and expectsImportMappedRangesto try its import; with this PR's previous head merged into currentmain,agc_driver_graphicsfailed with "the map failure fixture did not mutate an unrelated range during allocation". The fixture now maps 128 KiB as one window, which is still imported at map time. On plainmainthe updated test passes, and with #8802's fix reverted it fails at "an unrelated mapping during a failed import discarded its owner failure memo", so it still checks what #8802 added.ANYPS5_NO_SHADER_CACHE=1, three runs each: the 74 tests built fromtests/Recorder.cpp, andagc_driver_graphics,agc_driver_host_import_windows,agc_driver_host_import_at_map,agc_driver_host_import_teardown,agc_driver_indirect_arguments_pending_producer,agc_driver_unimported_label_order,agc_driver_same_queue_label_wait,agc_driver_alias_copy_label,agc_driver_pipelined_dma,guest_sleep_wake,guest_sleep_wake_coarse,guest_nanosleep,precise_wait: 87/87 on this head and onmain.main94fbb8cea8and on this head (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V, RTX 3070 Laptop GPU, NVIDIA 617.42;DISABLE_LAYER=1turns off a third-party implicit layer installed here, FPS Monitor, whosevkDestroyInstancehook crashes later instance lookups): 87/87 on both, neither log reportswas not found but was requested by env var VK_INSTANCE_LAYERS, and both report the same VUIDs the same number of times (VUID-VkImageViewCreateInfo-usage-022754,VUID-vkCmdCopyBuffer-srcBuffer-001182). The change adds none.ANYPS5_GPU=AMD), the same set once and once under the validation layer: 84/87 on this head and onmain. The same three tests fail on both (agc_sample_dumps,agc_driver_vertex_target_range_copied,agc_driver_vertex_target_range_imported), so they aremain's; the validation logs report the same VUIDs as on NVIDIA and none new.llvmpipe (LLVM 21.1.8)): 71 tests of the set are registered there; 65 pass, among themagc_driver_graphics,agc_driver_host_import_windows,agc_driver_host_import_at_mapandagc_driver_host_import_teardown, and 6 skip themselves with exit 77 (agc_pipeline_cache_file,agc_storage_clear_hand_over,agc_unit_shadow,agc_shadowed_key_stores,agc_driver_unit_shadow,agc_driver_unit_shadow_budget).384652a52(the same five changed lines, merged intomain07377573f): the 56 tests built fromtests/Recorder.cppandHostImportWindows.cpppass on an Intel UHD 770 (49 pass, 7 skip without a second queue family) and an AMD RX 9070 XT; with this PR's tests onmainwithout its change, 9 fail on both.tools/check_conventions.pypasses for this range.SuperTuxKart captures. RTX 3070 Laptop GPU, NVIDIA 617.42, same machine and build as above; SuperTuxKart (PPSA69421) tutorial prompt over the main menu, 1920x1080 internal rendering in a maximized 2560x1369 window, warm shader caches, audio muted, no input;
APS5_TRACE_SECONDS=20:8withAPS5_TRACE_EVENTS=1048576, console output not redirected, no otherAPS5_*switch; 2026-10-22, one session, ordermain, this PR, this PR + #7464 (twice; its lines are in #7464), this PR,main; every run kept the window in the foreground, and every summary line reportsdirty: falseandtrace_dropped: false.Summary lines (main, this PR, this PR, main)
tools/performance_compare.py(first capture ofmainagainst the first capture of this PR)**Performance comparison
**
94fbb8cea8a1cee90f52**Configuration differences
**
**Frame and GPU times (ms)
**
**Top phases (ms per frame)
**
tools/trace_digest.py(first capture ofmain, then of this PR; every digest is in the evidence archive)v23-s01-mainseconds 20:8 from present 38: 80 presents, frame p50 99.8 / p90 110.5 / p99 128.3 / max 128.3 ms, GPU busy 5.6 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 1920x1080, commit
94fbb8cea8, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 97.8, Driver.WorkerWait.idle_and_completion_poll 97.7, Graphics.Draw 7.9, Graphics.Draw.draw_and_resource_release 7.6, Vulkan.DrawFromRecipe 6.3, Graphics.DrawWithRecipe 6.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
v23-s02-7465seconds 20:8 from present 55: 83 presents, frame p50 94.7 / p90 106.2 / p99 130.0 / max 130.0 ms, GPU busy 5.7 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 1920x1080, commit
a1cee90f52, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 94.0, Driver.WorkerWait.idle_and_completion_poll 94.0, Graphics.Draw 8.2, Graphics.Draw.draw_and_resource_release 7.9, Vulkan.DrawFromRecipe 6.6, Graphics.DrawWithRecipe 6.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Evidence: 7465-evidence-20261022.zip (traces, summary lines, digests and comparisons, test and validation-layer logs).
Known limitations
Dependencies and overlap
tests/BdaResources.cpponly (map-time import expectations). #8622 is inmainsince 2026-10-23, and the merge ofmaininto this branch runs both rules together.ImportMappedRangesleases the registry, at the lines this PR changes; they conflict textually inGuestBufferMemory.cpp, and either order needs a small rebase. Neither depends on the other.Checklist
main(e2b9700a98merged in); no other open PR implements the same functions (#9011 above; #8622 is inmainnow)NotImplemented_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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T04:52:47Z.
@Dripl1x thanks, this looks correct: first-use import is the existing fallback, so deferring only drops an optimisation. The +9% rests on one capture, though. Could you repeat it interleaved (main, PR, PR, main) in the same scene, or post the count of imports avoided? Also, together with #7464, a small GPU-mapped label page would never be imported, so every label to it would wait for all recorded GPU work. We'll measure the two together if both go in.
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T06:35:57Z.
Intel and AMD Windows data: with this PR the 56 tests built from
tests/Recorder.cppandHostImportWindows.cpppass on an Intel UHD 770 and an AMD RX 9070 XT. Without it,agc_driver_host_import_windowsand 8 import-settle and host-import tests fail on both.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This head384652a52merged intomain07377573f. "Without" means this PR's test files onmain07377573f, with none of its other changes.agc_driver_host_import_windows(mapping did not defer exactly the small import), and with(9) a scan under a pending write was keptthe 6 import-settle tests,agc_driver_host_import_lifetimeandagc_driver_host_import_mutation_raceagc_driver_host_import_windows(same message), and witha signaled batch's read still refuses(... write is not settledforsettle_deferred) the same 8This is a correctness check only; I measured no speed.
I also ran full CTest with this PR and the 13 other open AGC and shader PRs I tested in the same batch merged together (#7668, #7659, #7504, #7432, #7426, #7413, #7480, #7466, #7464, #7449, #7489, #7673, #7560). Neither GPU showed a failure beyond
main's own: the five image-table tests (#6647) andagc_driver_sample_multisample_target(#6957) on the UHD 770, andagc_driver_layered_volume_vertex_no_gpl(#4768) on the RX 9070 XT.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-20T23:34:12Z.
@oneandonlydean, thanks. Measured together with #7464 on main
2185dbf92e, interleaved, with counters for the imports:sceKernelMapDirectMemory869 -> 23 µs per call), but in this title the first label then imports the block, so alone the frame rate stays at main's level (8.66 / 8.91 FPS). The earlier single capture came from a dirty build and is replaced by these runs.Counters, summary lines of both configurations, traces and the probe patch are linked in the description.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T02:03:06Z.
@Dripl1x two things since the last CI run on
384652a525.agc_driver_graphicsnow fails on Linux and Windows (andagc_driver_graphics_maps_fallbackon Linux) with "a range imported at map time was not counted for the map requester". That check is in a testmaingained after this branch's base (tests/BdaResources.cpp, the import-requester test from5f532117d3). It maps a 64 KiB piece and expectsImportMappedRangesto import it and count it asImportRequester::Map, and this PR now defers ranges of<= 0x10000. You made the same adjustment inRecorder.cpp(UnitBytesto 2 × 64 KiB). Could you do the same there? Better still, assert the new behaviour: a range of 64 KiB or less isn't imported at map time, and is imported, under its real requester, at first GPU use. The other directImportMappedRangescalls in that file are worth checking for the same size.#7473 has merged, and the branch now conflicts with
mainintests/execution/HostImportWindows.cpp. #7473 also wraps import validation inHostImportAccess(Windows resident runs can be read-only between collections). When you rebase, please make sure the deferred import at first GPU use goes through that same path, so it validates inside the bracket.Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-21T02:29:42Z.
@oneandonlydean thanks, both are done in
f752bb6a17, rebased onto main6696def6e6. The source change is the same hunk as before; only tests changed.Map-time import tests.
importRequesterTestsnow counts the map requester on a 128 KiB range (two 64 KiB pieces). It also asserts the new behaviour on a 64 KiB range:ImportMappedRangesleaves it unimported and the map count unchanged, and the firstHostImportForimports it, counted foraccess, with the map count still unchanged. Of the other directImportMappedRangescalls,importAtMapOverBudgetTestsalso mapped 64 KiB, so with this PR it passed without ever reaching the budget check; it now maps 128 KiB. The stale-probe fixture maps 3 × 64 KiB and is unaffected.importBlockMapTestsmaps 64 KiB pieces one by one and checks for one 4 MiB block at the first lookup, which still holds when the pieces are left to that lookup.agc_driver_graphicspasses on Windows, and on Linux (WSL Ubuntu 26.04, mirrored build) bothagc_driver_graphicsandagc_driver_graphics_maps_fallbackpass.Rebase over #7473. The
HostImportWindows.cppconflict kept both tests: #7473's resident import after collection, and this PR's small mapping imported at first use. The deferred import already validates inside the bracket.HostImportFor→importAccess→importAllocation, andimportAllocationconstructsGuestArena::HostImportAccessbefore it queries the pages (GuestBufferMemory.cpp:1775at the new head). That is the same function the map-time pass calls (:3549). This PR only skips small ranges inImportMappedRangesand adds no import path of its own.agc_driver_host_import_windowspasses with both tests.Under the Khronos validation layer (
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V; RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 11), the 65 recorder tests,agc_driver_graphicsandagc_driver_host_import_windowspass 67/67 on main6696def6e6and onf752bb6a17. Both logs report the same two VUIDs the same number of times, so the change adds none.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T22:46:01Z.
AMD/Linux data point on a second title, for this PR and #8622 side by side.
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.So on this title this PR's size gate is the larger win of the two. This is one machine and one scene, three alternated pairs.
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-22T02:59:20Z.
Updated on 2026-10-22; the description is rewritten to match.
main94fbb8cea8; the head is nowa1cee90f52, and the empty metadata commit is gone. The source change is the same five lines as before.a1cee90f52): #8802 addedimportMappedFailureGenerationTestsafter this PR's previous rebase. It maps a 64 KiB range and expects a map-time import, so with the previous head merged into currentmain,agc_driver_graphicsfailed ("the map failure fixture did not mutate an unrelated range during allocation"). The fixture now maps 128 KiB as one window, which is still imported at map time. The test passes onmainand still fails with #8802's fix reverted.main: the label and import tests three times on an RTX 3070 Laptop GPU, once on the AMD integrated GPU and on lavapipe; the validation layer reports the same VUIDs on both.main9.91 / 10.24 FPS, this PR 10.29 / 10.19, this PR with #7464 25.87 / 25.99.