perf(agc): keep device buffers placed in host memory for reuse while the device heap is full #8748
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8748"
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-20T23:27:52Z.
What
When a device buffer doesn't fit in the budget
VK_EXT_memory_budgetreports for the device-local heap,DeviceMemoryTypeplaces it in host memory (d04e98320). On release such a buffer was freed rather than pooled, so that host memory would never be handed out as device memory later. That keeps placement right, but while the heap stays over budget, every request allocates host memory again and frees it on release.An APU with the common 512 MiB carve-out is always in that state. On a Radeon 860M (device-local heap 512 MiB, budget 486 MiB) the heap reports 512/486 MiB from the menu on. SuperTuxKart's tutorial race placed 8192 buffers in host memory per run, about 97–102 GiB, nearly all of them 8 MiB. A discrete GPU whose VRAM sits at its budget takes the same path.
hostPlaced, a new field ofBufferAllocationand of the pool's slot key.DeviceBufferasks for a device-local slot first. Only on a miss does it take a host-placed slot. It keeps that slot only whenContext::DeviceLocalFitssays a new allocation would not fit the device-local heap either; otherwise it puts the slot back and allocates as before. So a buffer gets device-local memory whenever the reported budget has room for it, and the budget is read only when a host-placed slot is there to take.DeviceMemoryTypeasks them before a new host placement (sincee2c1c305ff), but on a heap that stays over budget, a release for every such request would move the churn into the texture caches. A new allocation, with no host-placed slot to take, still asks the caches first.HostSlotBeforeCacheReleasepins both. This order was not measured in a title: the captures below predatee2c1c305ff.DeviceLocalFitsandDeviceMemoryTypeshare one budget read (Context::ReportedHeap) and its fit test; onlyDeviceMemoryTypegoes on to the texture-cache release.Tested
Head
28f80c25a9onmainaaccd0ba39.agc_buffer_poolpasses.HostPlacementandRefusedDevicePlacementcheck three things: a host-placed buffer is kept after release; it is reused while the device-local heap has no room; and a request that fits gets device-local memory, not the retained host memory. WithResources.cppfrommain, the first two checks fail.HostSlotBeforeCacheRelease(headd845d4bfc5, onmain4f41f4c375) retains a host-placed buffer, then sets a texture-cache release that would free any amount: the next request of that size takes the retained buffer without calling it, and a new request of another size calls it once and gets device-local memory. With the probe inResources.cppchanged to try the release before taking the slot, all three checks fail.agc_buffer_pool, its two small-device modes, the threeagc_memory_accountingtests andagc_device_memory_fallbackpass, 7/7, on the Radeon 860M laptop (Windows 11, WinLibs GCC, Release).ctest -R "buffer|pool|resources|device_memory|host_placement|budget"withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 76/76 pass on Windows 11, i5-10600K, RTX 5060 Ti (driver 621.01), WinLibs GCC 15.2.0, Release.1002:1114, 512 MiB carve-out, driver 32.0.13058.8001), Windows 11 26300,APS5_TRACE_SECONDS=95:20,mainand this head alternating in one session. Summary lines, traces andtools/trace_digest.pyoutput for every run are in this comment.mainaaccd0ba3928f80c25a9The change removes the host-memory allocation churn. On current
mainthe frame rate difference is within run-to-run spread: both trees fall into the same two modes, about 27 and 44 ms of GPU time per present. An earlier comparison onec7eacc62, where the race ran at about 2.5 FPS, gave 2.47 FPS onmainand 2.94 with this change; that gain does not reproduce on currentmain.Overlap. #6553 changes the body of
DeviceMemoryType(host heap selection), so the two conflict textually there, not in what they do. #4472 stops pooling device buffers while the device-local heap is over budget. On a 512 MiB carve-out that is always the case, so as written it would drop these host-placed slots too and bring the churn back. They hold no device-local memory, so I think they could be left out of that check.tools/pr_overlap.pyfound no other overlap among the PRs it could compare.Idle device reclaim (#8672).
ReclaimIdleDevicenow skips host-placed slots. They live indeviceTier, but their memory is on the host heap.IdleReclaimSkipsHostPlacedretains an older host-placed slot and a younger device-local slot, and checks that the reclaim frees and counts only the device-local one. Without the skip it fails.agc_buffer_pooland its two small-device modes pass, 3/3.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-20T23:28:08Z.
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-20T23:33:50Z.
Review: APPROVED
Reviewed the allocation-selection and pool-key changes plus the host-placement regression cases. The device-local pool is still preferred; a retained host-placed slot is reused only after a fresh budget check says a new device-local allocation would not fit, and the tests assert both reuse under pressure and device-local selection once the budget allows it. The PR includes paired same-machine SuperTuxKart captures and reports the buffer-allocation drop from 8,192 placements to 5. Eligibility, conventions, intake, labels, and report checks pass; hosted platform/runtime jobs are skipped, and the author notes the Khronos validation layer was unavailable.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-21T18:08:02Z.
SuperTuxKart race data with the rest of the STK fixes underneath. This PR removes the device-buffer churn that is left once the storage round trip and the label waits are gone.
Setup.
APS5_PAD_INPUT_FILE, withAPS5_TRACE_SECONDS=95:20.maind34da5d694+ #6718 + #7464 + #7465 + #8858, asb097216c65. #7465 conflicted only intests/execution/HostImportWindows.cpp, where both sides add a test; I kept both.d1ce2c5127, ase0d6148d07(clean merge).The frame rate gain is small, 5 to 10 %. What the PR removes shows on the draw committer: one run per side with
APS5_PROFILE_DRAW=1, a 10 s window in the race.keepreadTargetOn the base, the committer is the busiest thread. Sampling it puts about 19 % of its time inside the driver under
BufferPool::AllocateMemory, inD3DKMTCreateAllocation/FreeGpuVirtualAddress, throughDeviceBuffer::DeviceBuffer. With this PR, the placed allocations drop to 32 for the whole run. The busiest thread is then the title's own: about 64 % of its samples are insceKernelUsleep, waiting for GPU work. So the committer is no longer what bounds the race.Traces and summary lines: pr8748-race-traces.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:10:38Z.
Review: CHANGES_REQUESTED
Re-check — changes requested\n\nThe additional ReclaimIdleDevice change and IdleReclaimSkipsHostPlaced test address the accounting issue: reclaim now skips host-placed slots instead of freeing host memory while reporting it as released device memory. The new NVIDIA report on head 70a183ef7f is useful broad coverage, but it is not a comparison against current main and does not repeat the title performance measurement.\n\nThe branch is based on
acbfd7c7fe, and current main isaaccd0ba39. Main has changed all five PR paths since that base: BufferPool.hpp/cpp, Context.hpp, Resources.cpp and BufferPool.cpp tests. Please rebase onto current main, preserve the device-local-first/host-fallback budget behavior and the reclaim regression, then rerun agc_buffer_pool and the focused memory-budget tests on the exact updated head. Because this is labeled perf, refresh the same-machine SuperTuxKart main/change captures, summary lines, traces and digests after the integration as well. I did not run local tests or GPU captures.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T12:26:39Z.
Review: APPROVED
Reviewed — approved
Head
28f80c25a9merges cleanly onto currentmain, builds, and passes the focused buffer-pool and device-memory tests with the Khronos validation layer active and noVUID-lines on either side; the newagc_buffer_poolchecks fail when the production files are reverted tomain.What I ran
28f80c25a9b466b067a3c3b9bbbd504d548e0376main:5454cd2e455994d992aca39335ce60507eeda1eb(merge base of the branch:aaccd0ba39)Results
maingit diff --checktools/check_conventions.py --base origin/mainAll conventions checks passed.libs(merged tree)main, with validationVUID-linesmain, 0 on the merged treewas not found but was requested by env var VK_INSTANCE_LAYERSVK_LAYER_KHRONOS_validation6 times in each run (the GPU tests in the set)10de:2705, driver 615.78.08agc_buffer_pool0.38 s; whole set 1.32 sMerged tree, ctest summary
Negative control
Restored
BufferPool.hpp,Context.hpp,BufferPool.cppandResources.cppfrommainand kept the PR'stests/BufferPool.cpp.agc_buffer_poolfails; the two small-device modes still pass:On the merged tree, removed only the
slot.allocation.hostPlaced ||condition fromReclaimIdleDevice.agc_buffer_poolfails:This confirms the author's report on the #8672 composition, which oneandonlydean raised.
Both changes were restored afterwards.
Findings
Blocking
None.
Non-blocking
A host-placed slot that is probed and refused is re-inserted as the newest slot.
Resources.cppL166-L172 puts the slot back withcache->Put(*pooled)whenDeviceLocalFitssays device memory is available.Putgives it a freshlastUse(++clock,BufferPool.cppL578), andTakehas already counted the probe in++tier.hits(BufferPool.cppL409-L426). Once the heap is back under budget, a host-placed slot holds host memory that the pool will not hand out while device memory fits. Each refused probe also makes that slot the youngest in the device tier.evictOldestthen drops reusable device-local slots of other keys before it, andReclaimIdleDeviceskips it by design. TheAPS5_PROFILE_DRAWdevice-tier hit count also includes these refused probes. Suggested fix: when the probe is refused, destroy the slot rather than putting it back, because device memory fits and the host copy is the wrong placement. Alternatively, re-insert it with its originallastUseand leavehitsuncounted.DeviceLocalFitsdoes not check exactly what the fresh path checks. The probe callsDeviceLocalFits(~0u, capacity). The fresh allocation it competes with usesDeviceMemoryType(requirements.memoryTypeBits, ClassAllocationBytes(requirements, capacity), ...)(Resources.cppL200-L210). With~0u,MemoryTypecan pick a device-local type the buffer cannot use. The size also lacks the alignment rounding. On the usual single device-local heap these agree. In the edge case, a request just at the budget boundary passes over the host slot, then gets host memory anyway from a new allocation. The description says both decisions use "the same rule", and that holds only approximately. Passing the slot's alignment-roundedallocationByteswould make the two match exactly.The
GPUs testedline does not match the validation evidence. The checklist names only the Radeon 860M, where the description says the Khronos validation layer is not installed. The author's later run with validation on head28f80c25a9used an RTX 5060 Ti and covered only the change, notmain. CONTRIBUTING asks for the same focused tests onmainand the change with the layer, with each GPU named on that line. The comparison above on the RTX 4070 Ti SUPER, and the earlier ones by JulesB40 and the NVIDIA CI comment, show no newVUID-lines, so I do not treat this as blocking. Adding the 5060 Ti, and amainrun on it, to the description would close it.Overlap with #4472, as the description already says: #4472 stops pooling device buffers while the device-local heap is over budget. Whichever lands second has to exempt
hostPlacedslots, or the churn this PR removes comes back on 512 MiB carve-outs. Agreeing the order with that author, and noting it underDepends onif needed, would help.Not verified
d1ce2c51278fagainstmainec7eacc62, not the current head. MarcZX10 asked for a refresh on currentmain, and the author says that is pending. The code behind the measured path is the same apart from the reclaim skip, but I have not reproduced the numbers.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T01:20:49Z.
Review: APPROVED
Reviewed — looks good
I reviewed head
28f80c25a9b466b067a3c3b9bbbd504d548e0376; the updated evidence supports reduced host-memory allocation churn, while correctly making no repeatable FPS-gain claim.What I ran
28f80c25a9b466b067a3c3b9bbbd504d548e0376with currentmain1a217758a55c09e817366fa4411daac854eeb3f9; their merge base isaaccd0ba39b7d40fdbf19664575a7e567d8542f7and the merge preview is clean (8c6773cdd121de6ed2d9fa52bfb5f7ee5275c1dd). None of the five PR files changed onmainafter that baseline.git diff --check upstream/main...refs/review/upstream-8748andpython tools/check_conventions.py --base upstream/main --head refs/review/upstream-8748on Linux with Python 3.11.2. No local build or tests were run.Results
8c6773cdd121de6ed2d9fa52bfb5f7ee5275c1ddgit diff --checkAll conventions checks passed.28f80c25a9, with Vulkan validation enabledmainaaccd0ba39b7and PR-head28f80c25a9b4captures, summaries, digests, and traces. Buffer placements fell from 8,192+ to 3; the measured FPS modes overlap, so the report does not claim a repeatable FPS gain.Findings
Blocking
None.
Non-blocking
The evidence supports the reduced allocation churn. It does not establish a general frame-rate improvement, and the updated description states that limitation clearly.
Sources
Not verified
I did not build or run tests locally, download or independently digest the attached traces, or test Linux behavior. Hosted Linux and specialized jobs were skipped.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T08:26:52Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
This pull request does not merge cleanly into
main(4f41f4c375): head7cd426f00fconflicts incore/libs/prx/libSceAgcDriver/tests/BufferPool.cppPlease rebase it onto current
main. I will review the change once it merges cleanly.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T11:09:52Z.
Review: APPROVED
Re-checked — approved
Since my last review the branch was rebased onto newer
mainand gained commit7cd426f00f, which re-reads the heap report throughReportedHeapaftermain's texture-cache release.main4f41f4cwas also merged into it, and the description now has matched 860M captures. The merged tree builds, the focused tests pass with the Khronos layer active, and the new checks still fail without the production change. One new non-blocking point: how this change interacts withmain's texture-cache release.What changed since my last review
48b6bc5d12now passes thecategoryargument thatmainadded toBufferPool::Take. Otherwise its logic is unchanged.0ac7f6d55e(the reclaim skip) is identical to the commit I reviewed before.7cd426f00f.main'se2c1c305ffadded a texture-cache release toDeviceMemoryTypebefore it falls back to host memory. That code re-read the budget through locals this PR removed. It now callsReportedHeap(heap)again after a release and applies the same fit test.53570aa5ffmergesmain4f41f4c. The only conflict was intests/BufferPool.cpp. The resolution keepsIdleReclaimSkipsHostPlacedand its call inmain().mainaaccd0ba39and head28f80c25a9, and it claims only the removed allocation churn, not a frame-rate gain. TheGPUs testedline now names the RTX 5060 Ti too.What I ran
Head
53570aa5ffeabb0b4b49dd951649de8a5afa0e71,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree25ccd1a440c2976735630c9f7f144eb5981ffc72. Machine: Debian 13 VM, 2× Xeon Gold 6136, GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19).git diff --checkcheck_conventions.pyAll conventions checks passed.libs, merged tree (script)main: the denormal/divisionagc_driver_*tests,vector_constant_factor_tininessand oneunwrap_selftest.VUID-vkCmdDispatch-groupCountX-00386inagc_driver_native_depth_uniform_planes, a test that is newer than the baseline. It comes frommain; see below.agc_buffer_pool0.49 s)agc_buffer_poolfails with 3 messages; see belowgit status --porcelainemptyVUID check with main's production files
With the four production files restored from
main,agc_driver_native_depth_uniform_planesreports the same 4×VUID-vkCmdDispatch-groupCountX-00386as on the merged tree. The test was added onmainbyc9987271e3, after the validation baselined1ae628bc2. The message comes frommain, not from this PR.Negative control
I restored
BufferPool.hpp,Context.hpp,BufferPool.cppandResources.cppfrommainand kept the PR'stests/BufferPool.cpp.agc_buffer_poolfails; the two small-device modes still pass:After restoring the merged files and rebuilding, all 5 tests pass.
Previous findings
Resources.cppL179-L186 still callscache->Put(*pooled), andPutgives the slot a fresh++clock(BufferPool.cppL589).DeviceLocalFits(~0u, capacity)does not test what the fresh path tests. Still open, non-blocking. The fresh path uses the buffer'smemoryTypeBitsand the alignment-roundedClassAllocationBytes.GPUs testedline vs the validation evidence. Resolved for the checklist: the line now names the RTX 5060 Ti next to the 860M. The author has not posted amain-side layer run on the 5060 Ti. The lavapipe comparison here, the AMD RX 6300 CI comment on this exact head, and the earlier NVIDIA runs show no new IDs, which covers that gap.The perf evidence MarcZX10 asked for is now posted (three PR runs and two
mainruns, with summary lines, traces and digests). It supports the narrowed claim that 8192+ host placements per run drop to 3. I accept those numbers as author-reported; I could not reproduce them.New findings
Blocking
None.
Non-blocking
main's texture-cache release, so a retained host slot now wins over a device-local placement that the cache release could make possible. Sincee2c1c305ff, a fresh over-budget request first asks the texture caches for the request plus the heap's overage. If they release enough, or the budget read again has room, the request stays device-local (Context.hppL357-L372). The probe inResources.cppL182 only reads the budget throughDeviceLocalFits. While a matching host-placed slot exists, the cache release never runs for that size, and the buffer stays in host memory. This contradicts two claims in the description: "a buffer still gets device-local memory whenever there is room for it" and "both decide with the same rule". It may be the better trade-off: releasing textures on every 8 MiB request on a permanently full 512 MiB heap could just move the churn into the texture cache. But it was not measured: the captures are onaaccd0ba39, which predatese2c1c305ff(git merge-base --is-ancestorconfirms this). Suggested fix: either state that a retained host slot is preferred over a texture-cache release, and add a mock case withcacheReclaimset that pins this, or try the release before taking the host slot.Context.hppL368-L371) writes out the fit test by hand instead of callingafter.Fits(bytes). The two differ only when the budget is 0, which the firstFitsalready handled, so behaviour is the same. CallingFitswould keep a single rule.Not verified
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T12:09:02Z.
Review: APPROVED
Re-checked — approved
Since my last review,
bd4354ef0caddsHostSlotBeforeCacheRelease, which pins the order between a retained host-placed slot andmain's texture-cache release.d845d4bfc5replaces the hand-written re-check after a release withafter.Fits(bytes). The description now states the order and that the captures predatee2c1c305ff. Both points I raised last time are addressed. The new test fails in both negative controls, and nothing blocking remains.What changed since my last review
bd4354ef0c(test only).HostSlotBeforeCacheReleaseretains a 176 MiB host-placed buffer, then installs acacheReclaimthat releases any amount and counts its calls. It checks two things. First, a new request of the same size reuses the retained buffer and makes zero release calls. Second, a 64 MiB request, which has no host slot, makes exactly one release call and gets device-local memory.d845d4bfc5. InDeviceMemoryType, the re-check after a partial release is nowafter.Fits(bytes)(Context.hppL364-L371). Production code changed nowhere else (git diff 53570aa5ff d845d4bfc5 --stat: 1 line inContext.hpp, 31 lines intests/BufferPool.cpp).Description. It now says a matching host-placed slot is taken without a cache release, and it gives the reason. "Whenever there is room" became "whenever the reported budget has room". It notes that the order was not measured in a title.
Author reply (11:46 UTC). The author kept the order on purpose and gave two reasons:
I agree with both: the first is the trade-off I raised, and the second is a real cost of the alternative order. With the order now documented and pinned by a test, I withdraw the request.
What I ran
Head
d845d4bfc50963a172bbefb624641ed48e704fb5,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree4abace0fa91fceb7f140487b1aed12fbd3ce130f. Machine: Debian 13 VM, 2× Xeon Gold 6136, GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19).git diff --checkcheck_conventions.pyAll conventions checks passed.libs, merged tree (script)agc_driver_*tests,vector_constant_factor_tininessand oneunwrap_selftest) also fail onmain.VUID-vkCmdDispatch-groupCountX-00386inagc_driver_native_depth_uniform_planes. That test is newer than the baselined1ae628bc2. My last review reproduced this ID withmain's production files, and the one production line changed since cannot reach a dispatch. It is not counted against this PR.agc_buffer_pool0.55 s). NoVUID-lines and nowas not found but was requestedlines. These are mock-device tests.agc_buffer_poolfails with the 3 new messagesmain)agc_buffer_poolfails with 6 messagesgit status --porcelainemptyNegative control output
A, release tried before keeping the host slot:
B, production files from
main:In both runs,
agc_buffer_pool_small_device_sharedand_no_stagingpassed. Control A confirms the author's statement that all three checks fail.Previous findings
Resources.cppL179-L186 is unchanged.DeviceLocalFits(~0u, capacity)does not test what the fresh path tests (the fresh path usesmemoryTypeBitsandClassAllocationBytes). Still open, non-blocking. The code is unchanged.GPUs testedline. Resolved in my last review. Nothing changed.main's texture-cache release. Resolved. The order is now intentional and documented in the description.HostSlotBeforeCacheReleasepins it, and that test fails when the order is reversed (control A).after.Fits(bytes)(Context.hppL368-L371).New findings
Blocking
None.
Non-blocking
None.
Not verified
e2c1c305ff.agc_driver_native_depth_uniform_planeswithmain's files on this head; the attribution tomainrests on my previous run.