perf(agc): bound the device memory held by staging shadows #18356
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18356"
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 oneandonlydean on 2026-11-11T11:40:25Z.
What
Bounds the device memory held by staging shadows (the device-local buffers of written and atomic staged regions in
GuestBufferMemory).Every staged region of a cached build keeps its own shadow, so the total grows with the build cache instead of with what a frame uses. The only limit was the heap being within an eighth of its budget. Long before that point the shadows take the room the sampled texture cache budget is computed from (
SampledTextureBudgetis what the heap budget leaves after all other use), the budget falls to its 2048 MiB floor, and a level that needs more than that has its textures created again every frame. That is the slow state reported in #18020.The live total is now bounded to a sixteenth of the device-local heap budget (the heap size without
VK_EXT_memory_budget), at least 256 MiB.APS5_STAGING_SHADOW_MAX_MIBoverrides it. A shadow over the bound is refused the same way as one the device cannot provide: the region is bound in place, as withAPS5_NO_WRITTEN_SHADOW=1. The[buffers] stagingprofile line now also prints the live total and the bound.Tested
Linux, RTX 4090 (24 GB), NVIDIA 610.57.04, PPSA21564 01.007.000, 3840x2160,
-lvl underwater_aerial_garden, no input, 600 s per arm, one paired round in an exclusive window, cold shader cache per arm, default settings,APS5_PROFILE_DRAW=1 APS5_TRACE_SUMMARY_EVERY=10. Arm A ismaince111157b8, arm B is the same commit plus this change.Presents per second in each 60 s of the session (the first 60 s are the menu, the second the level load):
[texture-cache]lines, whole session)imagesphase of resource builds, totalNo crash, device loss or abort in either run log. Dumped frames show the level in both arms; with this PR the fly-in finishes and the character stands at the spawn, on main the session ends inside the fly-in.
Earlier runs of the default path on main
1682ed40aeon the same machine and scene collapsed the same way in 3 of 3 sessions, andAPS5_NO_WRITTEN_SHADOW=1held about 5 presents per second in 2 of 2, so the main arm above is not a one-off. This PR ends at about 7 presents per second, above the switch-off arm, because the first 1.3 GiB of shadows still take the staged path.One round only, on one GPU. Not tested on AMD or on a 16 GB or smaller card, where the bound is proportionally smaller; the reporters of #18020 can check with their scene. Unit and GPU ctests not run locally.
Capture lines for the
perf numbers missinglabel: one run per commit in one exclusive window on the same machine, on levelbig_hand_pirate_island(not the level of the round above), shader cache warmed by a run of the same build first, onlyAPS5_TRACE_SECONDS=210:60set. First linemaince111157b8(the merge base), second line this head4a69efb803. On this level the two commits read the same within the run to run spread: frame p50 227.4 ms and 225.5 ms, GPU busy per present 108.1 ms and 108.7 ms. The effect of the change is theunderwater_aerial_gardenround above, which these lines do not repeat.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 MarcZX10 on 2026-11-12T15:08:40Z.
Review: COMMENTED
Reviewed the staging shadow bound — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
4a69efb8030287d0634a2dad8446dcf15e102413, basemain. No build, no compile, no tests run here.diff.patch.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppat head (lines 5790 to 5930 of 7473), and searched for the callers ofstagingBufferand for the test hookdeviceLocalFullForTests.WithinDeviceLocalHeadroomincore/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp(lines 56 to 90).docs/dev/ENVIRONMENT.mdagainst the code.Results
ENVIRONMENT.mdrowCommands run (reader)
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:5843: the bound is checked, then the shadow is allocated, then the total is added at line 5849. The check and the add are not one atomic step. If two threads both read a live total just under the limit, both can pass and the live total can exceed the bound by up to one shadow per concurrent caller. Example: live 1200 MiB, limit 1322 MiB, two requests of 200 MiB each, both pass, live total 1600 MiB. Reserving withfetch_addand rolling back on refusal would close the gap. Whether these calls run on several threads was not checked.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:5836: the debt entry atdocs/dev/debt/libSceAgcDriver.md:161still describes only the older one-eighth rule. It does not mention this bound or the override. It also says a pool-retained shadow is "reused without the check". With this change a reused shadow also passes the new bound (line 5843) and is counted in the live total (line 5849), even though reuse allocates no device memory. Decide whether that is intended and update the entry either way.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:5815: the new bound has no test. The hookdeviceLocalFullForTests(line 5810) already exists, so a test can force a refusal. Nothing covers the limit, theAPS5_STAGING_SHADOW_MAX_MIBoverride, or the decrement in the deleter at line 5853. The existing tests incore/libs/prx/libSceAgcDriver/tests/BufferPool.cpp(lines 354 to 385) coverWithinDeviceLocalHeadroomonly.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:5817:strtoullreturns 0 for a value that is not a number, soAPS5_STAGING_SHADOW_MAX_MIB=abcsilently binds every shadow in place. A malformed value could fall back to the default, with one message on stderr.Not verified
GuestBufferMemory.cppwere read (lines 5790 to 5930 of 7473). The file is listed in the manifest as too large for the review folder, so its full text is not infiles/. The other callers ofstagingBuffer(lines 6167, 6601 and 6673) were located by search but not read. The claim that a refused shadow takes the in-place path rests on the comment at lines 5807 to 5809, not on those callers.docs/dev/ENVIRONMENT.mdwas read through its changed line indiff.patch. Its full text infiles/was not opened.main. None of them was run or checked here.To get this to a good state
Nothing is required.