fix(agc): mirror the whole contiguous run of releasable allocations a joined heap belongs to #15297
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15297"
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 Prophet069 on 2026-11-02T23:01:29Z.
What
A joined heap mirror covered only the allocations the draw's range crossed, so every draw that reached one allocation further built a new multi-GiB mirror of an overlapping run while the previous one stayed alive.
The joined range is now the whole run of contiguous releasable allocations, and joined runs that a longer run of the same allocations replaces are released, so their mirrors are swept instead of holding a second copy.
Tested
NVIDIA GeForce RTX 3080 Laptop GPU, driver 616.64, Windows 10 Pro 22H2 (19045.6466).
Focused tests on
main(9090972b7e) and on this branch withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V -R "heap_mirror|^agc_driver_graphics$|^agc_driver_key_miss$|^agc_driver_bda_device$|^agc_driver_recorder$|native_multisample_depth|depth_storage|^agc_host_import_retire$|^agc_host_import_sparse$":main: 17 of 20 selected tests passed (agc_host_import_sparse skips on this machine; the three agc_driver_depth_storage_* tests were not built in this run); validation layer loaded in both logs;VUID-errors: none.VUID-errors: none.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T07:53:54Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The fix does what it says for overlapping draws, but it also makes the joined mirror's size depend on the whole run rather than on what the draw needs, so a heap whose run is over the heap mirror budget is now copied instead of mirrored.
What I ran
Head
b8fd3637f5a0f787e2e6c178295386054c9cb300,maind1ae628bc2f62459cce1e9872ba5632c938c71f2, merged tree5ee43a854dabdc5399ed7847cee248b6771f605a(Release, GCC 14.2.0, Ninja; Debian 13 VM, lavapipe / Mesa 26.1.6, no GPU).Results
git diff --checkcheck_conventions.pymainVUID-vsmainagc_driver_graphicstook 35.0 s while running in parallel with the others. The PR changes no tests, so the time is not the PR's.main: 2 overlapping mirrors held together (4 MiB)main: both mirroredProbe output
The probe uses three adjacent 1 MiB releasable allocations, with only the first 64 KiB page of each committed (a sparse heap). Bind 1 is
[a0, a0+2 MiB)and bind 2 is[a1, a1+2 MiB). The counters areMirrorCounters().heapMirrorsandheapBytes, read before, after bind 1 and after bind 2.PR, default budget:
main, default budget:
main,
SetHeapMirrorBudget(2.5 MiB):PR,
SetHeapMirrorBudget(2.5 MiB):The probe's own cleanup sweep then threw under the tiny budget while building per-allocation mirrors. That is an artifact of the probe, not of this PR's path.
Negative control
The PR adds no test, so there is nothing to revert against. Instead, the temporary probe above serves as one: with
main'sGuestBufferMemory.cppit shows the duplicate mirror the description reports (2 mirrors, 4 MiB for a 3 MiB run), and with the PR's file the duplicate is gone. This settles the question BunnyFl left open: none of the existing focused tests builds a joined heap across a growing or shifted run, so their passing proves nothing about the fix. After the probe I restored the merged files and rebuilt;git status --porcelainis empty.Findings
Blocking
The joined mirror now covers the whole releasable run, so a run over the heap mirror budget is never mirrored, even when the part the draw needs fits.
wholeReleasableRunextends the run over every adjacent releasable allocation, with no limit (lines 5154-5155).joinedHeapRangethen hands that range toacquireMirror. A mirror larger thanheapMirrorBudget()(24 GiB by default, orAPS5_HEAP_MIRROR_MIB) throws "past the budget".bindSparseMirrorthen falls back to copying.On
main, only the crossed allocations were mirrored, so such a heap was mirrored. The probe shows the change directly: with a 2.5 MiB budget,mainmirrors both 2 MiB binds, and the PR copies both.The cost also grows when nothing fails. A draw that crosses two small allocations inside a long run of releasable ones now builds, holds and refreshes a mirror of the entire run. The rule "implement the general behaviour" applies here: the size of the mirror should not depend on how many unrelated allocations happen to sit next to the heap.
Suggested fix: keep the whole run only when it fits, for example extend only while
run.bytesstays withinheapMirrorBudget()(or a fraction of it), and otherwise fall back to the crossed run as onmain. Add a test for both cases (see below).Non-blocking
No regression test for the fix. The overlapping-mirror case is easy to pin with the existing mock setup: three adjacent releasable allocations, binds at
[a0, a2)and[a1, a3), thenMirrorCounters().heapMirrorsmust have grown by exactly 1 andheapBytesmust equal the run size. Withmain's file this fails (2 mirrors and 4 MiB in my probe), so it works as the negative control. A second case withSetHeapMirrorBudgetbelow the run size would cover the blocking finding. It finishes in milliseconds.I reviewed the superseded-entry loop in
joinedHeapRangeand found no problem. It erases overlapping entries under the joined-heaps lock, drops them after the lock is released, and bumpsMirrors().versionsosweepMirrorscannot return early. This agrees with BunnyFl's reading.Not verified
To get this to a good state
main'sGuestBufferMemory.cpp.Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T15:48:42Z.
Review: COMMENTED
Ran
b8fd3637f5merged onmain302864d48con Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos validation layer 1.4.368),ctest -R '^agc_driver_resident_heap_mirror' -V:mainwas not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has aVUID-. To be sure validation messages reach these logs, the same layer with best practices on printed 28BestPractices-warnings into anagc_driver_recorderlog on each GPU.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T19:46:14Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed implementation and its existing focused tests support merging.
What I ran
Reviewed head
b8fd3637f5a0f787e2e6c178295386054c9cb300usingrepo_read.pyto read the prepared description, commit list, manifest, diff, changed source, and targeted call sites. No commands or tests were run. The author reports focused tests on main and this branch; those results were not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The manifest lists only
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppunder reviewed changes, and its full text was available and read. The prepared diff contains no test-file changes; existing targeted tests were inspected incore/libs/prx/libSceAgcDriver/tests/BdaResources.cpp, including coverage for joined heaps across adjacent ranges, partial import retention, and release after full import. No build, test run, or runtime behavior was independently verified. The author reports 17 of 20 selected tests passed on both main and this branch, with the same skips and no validation-layerVUID-errors.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:45:09Z.
Review: COMMENTED
The trial merge onto
c1601e56d5conflicts inGuestBufferMemory.cpp. Please cover extension of a joined run at the same base as well as a new run that starts earlier. The new sweep-generation bump is driven by thesupersededlist, and that list skips the entry atrun.base. A same-base replacement takes a different retirement path. A test that checks live mirror bytes after both changes would verify that the old run can be released without discarding in-flight work.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.