perf(agc): record unimported labels in large allocations through a 64 KiB import window #26718
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26718"
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 root-over on 2026-11-24T17:07:49Z.
What
Since #7464 a queue-0 label whose guest memory no host import covers syncs the recorder and is stored on the CPU (
WriteLabelOnGpureason 7). That keeps the small blocks #7464 measured (mapped every frame, 64 KiB or less) from being imported for their labels. A label in a large allocation that the host import budget refuses takes the same path, so each one waits for every batch in flight.Cult of the Lamb (PPSA06465) on a Renoir APU hits this in gameplay: the budget there is 586 MiB, the title's labels land in 16 MiB and 4 MiB allocations the budget refuses, and
Recorder.Synctakes 63.3 ms of the draw committer per frame (trace below). The labels are few (64 in 130 s in a counting build, in 12 allocations), but each one drains the GPU.This PR imports a 64 KiB window of such an allocation for the label and records the label on the GPU:
importWindowBoundsandwindowRuntake the window as a parameter (default unchanged).ImportRequester::Label("label" in the host import report).WriteLabelOnGpurequests it before taking reason 7; when the window imports, the label is recorded on the GPU as a covered label is.max(64 KiB, hostImportAlignment). An allocation no larger than the window gets no label import, so #7464's small blocks keep the CPU path unchanged.evictableBytes,retireLeastRecent) skips them, and a normal import that replaces a label window gets no credit for its bytes. They have a limit of their own: at most 16 MiB of windows are live. Past it, the least recently used label window that the import eviction rule would let go (not held by a build, not used in this or the previous frame) is retired and rewatched asretireLeastRecentdoes; when none can go, the label keeps reason 7.HostImportCounts::labelBytesreports the live window bytes (; 1.5 MiB of label windowsin the report).agc_driver_label_import_window(and its_draw_pipeline/_plan_verifyvariants) leaves an unregistered 64 KiB gap after each of its blocks, so no import of one block covers the next, and checks that a label in a 1 MiB allocation over the budget is recorded on the GPU (reason 0) through exactly one 64 KiB window and lands without touching its neighbours; that a label in a 64 KiB allocation still returns reason 7 without importing; that labels fill the windows to 16 MiB, that a label past the limit keeps reason 7 while every window is held, and that after a build the least recently used window is retired (and rewatched as before), the newer ones stay and every label lands; and that with the windows full, a normal import within the budget is made without retiring the earlier normal import or a label window; and that a normal import over the budget that would replace a label window, withAPS5_IMPORT_RETIRE_CREDITon, does not leave normal imports over the budget.#26384 also imports labelled memory, after a mapping outlived three flips, through the budgeted
HostImportFor. On this machine it does not change Cult of the Lamb (table below), since the budget still refuses these allocations; the two changes touch the same line ofWriteLabelOnGpuand should compose (a settled mapping imports through #26384, a refused large one through its window).Tested
Ubuntu 26.04 (Linux 7.0.0-43), GCC 15.2.0, Release, Ryzen 5 5625U, AMD Radeon Graphics (RADV RENOIR, gfx90c), Mesa 26.0.8, on
maine68be05111.GPU tests,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, validation layer 1.4.341,ctest -R '^agc_driver_(graphics|label_import_window.*|unimported_label_order.*|same_queue_label_wait.*|cpu_label_wake|label_.*|host_import_.*)$' -V:maine68be05111b1c9409abdInsert instance layer "VK_LAYER_KHRONOS_validation"was not found but was requested by env var VK_INSTANCE_LAYERSVUID-The whole
^agc_suite (2064 tests) under the same layer on an earlier head of this branch (5bb725a05f, before the retire rule took the import eviction rule and the rewatch): 2063 pass, 1921 layer inserts, 0VUID-; the failure isagc_driver_cvt_f32_f64_denormal_result, which fails onmainon this GPU (#26142). Every commit builds on its own and the new test passes from the commit that adds it.Negative controls, each a local revert of one rule,
agc_driver_label_import_window:Labelrequest inWriteLabelOnGpu:a label in an allocation over the import budget was not recorded on the GPU (reason 7)a label in an allocation no larger than a window did not keep its CPU path (reason 0)a label past the limit while every label window is held did not keep its CPU path (reason 0)a label past the limit was not recorded on the GPU once older windows were released (reason 7)d71f6b1da4):cannot record work on a fresh allocation(the normal import is refused)d2d884ab94):label bytes were credited to a normal import over the normal budgetpython3 tools/check_conventions.py --base origin/mainandpython3 tools/debt_fold.py --checkpass.Cult of the Lamb (PPSA06465,
01.000.023), 1920x1080, the same converted title and save each run; a recorded pad route (APS5_PAD_REPLAY) goes from the title screen into gameplay, 150 s per run, the numbers are the mean over the 10 s intervals from 90 s (gameplay). Runs alternate the arms by swapping the build'slibsdirectory.d71f6b1da4maine68be05111After the budget fix (
d2d884ab94), a batch in round order against the previous head andmain(the secondmainrun crashed in the game, a guestfree()atapp.elf+0x1697553, before the measured window, and is left out):d2d884ab94d71f6b1da4maine68be05111All arms run faster in this batch than in the one above (the machine, not the code:
mainis the same build); the gap between this PR andmainis 15 % here and 23 % above.An earlier batch in round order (this PR's previous head
5bb725a05f, which differs only in the retire path these runs never reach, at most 12 windows here), with #26384's head81f6333f36merged into the samemain(c9b670179e, local merge); a first round that ran while a build was compiling is left out:5bb725a05f)mainmain+ #26384Traces, summary lines and digests, SHA-256
3ce8f74d236b733486d4f4e9d5433a6adb54c2ab69847a372765a519a05cd337.Performance report
One run each with
APS5_TRACE_SECONDS=100:10(gameplay), same machine, route and build as above,mainfirst.Summary lines (main, this PR)
tools/trace_digest.py, main
seconds 100:10 from present 2621: 84 presents, frame p50 119.8 / p90 123.2 / p99 129.3 / max 129.3 ms, GPU busy 63.1 ms per present
AMD Radeon Graphics (RADV RENOIR), radv Mesa 26.0.8-1ubuntu0.3, Linux 7.0.0-43-generic, 1920x1080, commit
e68be05111, dropped: noSlowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
tools/trace_digest.py, this PR
seconds 100:10 from present 2854: 100 presents, frame p50 99.8 / p90 103.8 / p99 106.4 / max 106.4 ms, GPU busy 67.5 ms per present
AMD Radeon Graphics (RADV RENOIR), radv Mesa 26.0.8-1ubuntu0.3, Linux 7.0.0-43-generic, 1920x1080, commit
d71f6b1da4, dropped: noSlowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
In the window,
Recorder.Syncon the draw committer goes from 63.3 to 4.3 ms per frame, presents from 84 to 100 and frame p50 from 119.8 to 99.8 ms. GPU busy per present goes from 63.1 to 67.5 ms, as the GPU now runs the label stores and the committer feeds it faster.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 mihiii1337 on 2026-11-24T17:58:22Z.
Review: CHANGES_REQUESTED
Requesting changes for two independent, reproducible blockers at
d71f6b1da47d06934e29acc32308f891d417c091(recorded based1d700affa94d499003c1fec960e745dca2e23d5).The Windows fixture does not isolate
small.FillBuffer(work)runs before the small-block check, and separately registeredVirtualAllocblocks can be adjacent. The import run can therefore already coversmall, so line 123 observes GPU reason 0 instead of exercising the intended CPU fallback. On the clean exact head, all three registered variants fail at that assertion on both physical GPUs below. With only a scratch fixture change that reserves one extra unregistered 64 KiB after each registered block, the same production source passes 3/3 on each GPU. Please make the fixture guarantee that separation (or otherwise prove thatsmallis not already covered before testing the label-only path).Label windows still consume the normal host-import budget. The label admission path bypasses the normal budget guard at
GuestBufferMemory.cpp:2548-2549, but every label is added tostate.liveBytesat:2782-2785.pinnedTotalincludes allliveBytes(:617-618), and the normal admission/remaining-budget paths use that total.retireLeastRecent(:2037-2049) also does not exclude.label. A scratch-only regression first admitted a normal control import, filled the label pool to 16 MiB, then requested a fresh normal import and checked that neither the control nor the labels were evicted. All three variants fail on both GPUs withlabel windows consumed the normal host import budget. That contradicts the stated separation from the normal host-import budget and its eviction. Please account label windows outside the normal budget and exclude them from normal-budget eviction, with a regression that requests a new normal import after filling the label pool.Windows 11 build 26300, Release, WinLibs GCC 15.2.0 r7. Physical devices: Intel A78B (driver 101.6127, Vulkan 1.3.295) and NVIDIA RTX 4070 Laptop (driver 621.01). Khronos validation 1.4.369 was enabled at instance/device level with synchronization validation; no VUID or SYNC errors were emitted.
Tests on each GPU:
agc_driver_label_import_window,_draw_pipeline,_plan_verify: 0/3, fixture assertion above;The scratch changes were not committed or pushed. AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T07:01:00Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change based on the inspected code; the targeted source and test logic support the stated label-window behavior, though not every changed file was read.
What I ran
Reviewed head
d71f6b1da47d06934e29acc32308f891d417c091using the prepared diff andrepo_read.pyfor targeted source ranges. No build or tests were run during this review.Results
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
The full text of
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppwas excluded from the review folder for size; targeted relevant ranges were read throughrepo_read.py. Other changed files read:core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp,core/libs/prx/libSceAgcDriver/tests/execution/LabelImportWindow.cpp, andreview/commits.md.core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp,core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_label_import_window_tests.cmake,review/description.md, andreview/manifest.jsonwere not read in full. No independent build, test run, platform check, or console behavior was verified.To get this to a good state
Nothing is required. The behavior has focused coverage described in the change, but those tests were not run in this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T07:59:38Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this review; the findings below are optional.
What I ran
Reviewed head
d2d884ab94ceecd76e055cbca107b64aaff97cfe. No commands or tests were run; I reviewed the prepared diff and targeted source ranges. The test and performance results in the PR description are author-reported.Results
Findings
Blocking
None found in the code inspected.
Non-blocking
None.
Not verified
The full text of
VulkanDevice.cppandGuestBufferMemory.cppwas not read; I inspected their relevant changed hunks and surrounding code throughrepo_read.py. The full text ofGuestBufferMemory.hpp,BdaResources.cpp, andLabelImportWindow.cppwas read. The new CMake test registration file was not read. No repository tests, builds, negative controls, or performance runs were performed. The supplied manifest identifies six changed files; five were inspected at least in part, and the CMake registration was not inspected. The PR’s test and performance claims were not independently verified.To get this to a good state
Nothing is required. Optional: run the reported checks on this exact head and inspect the CMake registration file before treating the review as complete.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-25T13:34:16Z.
Review: CHANGES_REQUESTED
The two original blockers are fixed on exact head
d2d884ab94ceecd76e055cbca107b64aaff97cfe: the separated Windows fixture and the full-label-pool normal-budget case both pass. A separate overlapping-range case still lets label bytes count as normal-budget replacement credit whenAPS5_IMPORT_RETIRE_CREDIT=1.importRunAtadds every overlapping import toreplacedatGuestBufferMemory.cpp:2537-2543, including.labelentries.pinnedTotaldeliberately excludes label bytes. The immediate-credit path then computeslive = pinned - replaced, so a normal import can subtract a label window that was never charged to the normal budget.Independent Windows 11 reproduction on the exact production head:
APS5_IMPORT_RETIRE_CREDIT=1, request a normal import covering all five windows.That request should be refused: normal live plus five windows exceeds the normal budget by one window, and the overlapping label window is outside that budget. Instead it succeeds on both physical devices, failing the test-only assertion
label bytes were credited to a normal import over the normal budget:The local regression changed only
LabelImportWindow.cpp; it was not committed or pushed. Before adding it, the stock exact-head trio passed 3/3 on Intel and 3/3 on NVIDIA with Vulkan required, shader cache disabled, and Khronos validation enabled. Conventions andgit diff --checkalso pass.Please exclude label entries from normal replacement credit (or track normal replacement bytes separately) and add an overlapping label-to-normal regression with retire credit enabled. I did not reproduce the issue with the default-off retire-credit path.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T14:07:50Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the evidence inspected supports merging.
What I ran
Reviewed head
b1c9409abdd8bc98a1288857e0185a7bc07b05a6using the pinnedrepo_read.pyreader. No commands or tests were run by me; test and performance results below are reported by the author.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read every changed line listed as reviewed in the manifest. The full
GuestBufferMemory.cppandVulkanDevice.cppfiles were excluded from the prepared review folder; I used the reader for the relevant changed implementation ranges. I did not independently run tests, convention checks, performance captures, or console behavior checks. The reader did not providefiles.json; the folder listing and manifest identify all six changed files and show their included/excluded status.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-25T15:22:57Z.
Review: APPROVED
Reviewed exact head
b1c9409abdd8bc98a1288857e0185a7bc07b05a6. The overlapping label-to-normal budget blocker is fixed: replacement credit now excludes label imports, and the committed regression recreates the five-window request under a four-window normal budget with retire credit enabled, then verifies normal live bytes stay within that budget.Independent Windows 11 verification on the exact head:
agc_driver_label_import_window_testscompleted;agc_driver_label_import_window,_draw_pipeline, and_plan_verify: 3/3 passed on Intel A78B;tools/check_conventions.py --base d1d700affa94d499003c1fec960e745dca2e23d5andgit diff --checkpassed.The hosted checks for this fresh head are still queued. I did not run a title or console test. No blocking finding remains in the reviewed fix.
AI-assisted: yes.