perf(agc): let the sampled texture cache grow into host memory while a frame's textures don't fit #12684
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12684"
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 milescoviello on 2026-10-29T01:59:05Z.
What
Ghost of Tsushima Director's Cut (PPSA02225 02.024.000) runs its brightness screen and opening at about one frame per 30 to 50 seconds on an RTX 4070 Ti (12 GB) here. The draws are CPU bound in their resource builds. The sampled texture cache's budget sits at its 2 GiB floor: the device-local heap's
VK_EXT_memory_budgetbudget is about 9.2 GB, because other processes hold about 2.2 GB of the card, and about 6.4 GB of it is in use outside the texture caches.A frame's sampled textures don't fit in 2 GiB. One draw binds a 27,130-element image table, and the frame uses about 2.5 GiB of textures in all.
admitTexturethen finds every entry it could evict used in this or the previous present, so it turns the new texture away ("used uncached"), and the texture is made again at its next use. Over 210-600 s of a default run, the driver made 157,000 to 165,000 sampled textures. With this change, that stretch presents 20 frames instead of 6 and 9 (two runs each, see Tested).How
sampledBudgetadds room past the reported share while a frame's textures don't fit, when the device has a heap outside device-local memory. Two things count as a frame that doesn't fit:admitTextureturning a texture away, and an out-of-memory recovery for an allocation that could go to host memory reaching a sampled entry used in the last two presents. In Ghost of Tsushima the second is the common one: the cache stays at its budget, and the recoveries release the frame's own textures.VK_EXT_memory_budgetbudget (its size without the extension) in whole steps (SampledSpillCeiling). Only a discrete GPU gets room at all.SampledTextureSpillis that step, as a function of the previous room, whether the frame didn't fit since the last read, whether the cache is quiet, and the ceiling; room above a ceiling that fell is brought down to it.While the budget has that room,
ReleaseTextureCachesstops at the first sampled entry used in the last two presents when the allocation that ran out of device memory can go to host memory (ReclaimHasHostFallback, set byBufferPool::AllocateMemoryaround its recovery call). The allocation then goes to host memory through its existing fallback.Without that second part the grown cache only fills the device-local heap sooner. Each out-of-memory recovery then releases about 270 MiB of the frame's own textures, and the frame rate doesn't change. So the two parts are one change. The textures past the device's share also go to host memory once the heap is at its reported budget, through the existing placement in
Context::DeviceMemoryType.The
[gpu] sampled texture cache budgetline now says how much of the budget is past the device's share, and the[gpu] texture caches releasedline says when a recovery stopped at a recently used entry. Those stops come several times a second in Ghost of Tsushima, so the line is printed for the first five and then at each power of two, with the running count.A device whose frame fits its budget never turns textures away, so its budget doesn't change. That matters because USAGE.md records a title that got slower with a fixed larger budget (PPSA16064 with
APS5_TEXTURE_CACHE_MIB=3072on an 8 GB card). A GPU that isn't discrete gets no room: an integrated GPU's non-device-local heap (an APU's GTT heap under RADV, for example) is the same system memory the title uses. Neither does a device whose heaps are all device-local. On a discrete GPU the quarter bounds the room by what the host can give: here the host heap is 22.7 GiB of a 32 GB host, so the ceiling is the 2 GiB cap, and a host heap with a 6 GiB budget would get 1.5 GiB.APS5_TEXTURE_CACHE_MIBstill fixes the budget.The storage image cache is left as it is. In the experiments below, raising only its budget didn't change the frame rate.
USAGE.md describes the room. It has its own debt entry, which says where the step, the cap, the quarter and the 10 s came from; the texture cache budgets entry is as on
main.Tested
Linux (Ubuntu 26.04.1, GCC 15.2), RTX 4070 Ti 12 GB (NVIDIA 615.71.09), with about 2.2 GB of the card held by other processes. On
mainc9207624bcunless noted:New
agc_sampled_cache_spill(CPU only):SampledTextureSpillgrows by 256 MiB per read while the frame doesn't fit, stops at the ceiling (2 GiB or a lower one), keeps its room on a read that is neither, gives a step back on a quiet read (the rest when less than a step is left), and brings room above a lowered ceiling down to it.SampledSpillCeilingis 2 GiB for a 22 GiB host heap and 1.5 GiB for a 6 GiB host budget. It uses the heap's size without a reported budget, rounds down to whole steps, and gives 0 for a heap whose quarter is under a step, for a GPU that isn't discrete and when every heap is device-local.New execution modes of
agc_driver_sampled_cache_budget_tests. They run without a fixed cache budget and with a fakeVK_EXT_memory_budgethook reporting 64 GiB per heap:agc_driver_recover_sampled-recent_allocation: with room, a host-fallback recovery keeps the current present's texture, and the new texture goes to host memory.agc_driver_recover_sampled-recent-noroom_allocation: with no room, the same recovery releases the texture, and the next budget read is the device's share plus 256 MiB.agc_driver_recover_sampled-recent-device_allocation: with every heap device-local, the recovery releases it.agc_driver_sampled_cache_spill_growth: a texture turned away by a cache full of the current present's textures adds 256 MiB at the next read, a read with nothing turned away keeps it, and a GPU that isn't discrete gets none.Each piece taken out alone fails its test (one run each). Without the stop at recent entries,
recover_sampled-recentfails. With the stop regardless of room,recover_sampled-recent-noroomfails. WithoutadmitTexture's count,spill_growthfails. Without the recovery's count,recover_sampled-recent-noroomfails. Without the discrete-GPU check,agc_sampled_cache_spillandspill_growthfail.Area: at this head (
ba0eaedff6), the 19 tests matching^agc_driver_recover_|^agc_sampled_cache|^agc_driver_sampled_cache|^agc_driver_storage_cache|^agc_buffer_poolpass 3 of 3.Validation layer (Khronos
VK_LAYER_KHRONOS_validation1.4.363, LunarG SDK), onmainc9207624bcand at this head:VK_LAYER_PATH=<sdk>/layers VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R '^agc_driver_sampled_cache_budget$|^agc_driver_recover_|^agc_driver_sampled_cache_spill_growth$' -Vmainpasses 5 of 5 (the new modes don't exist there) and the head 9 of 9. Neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS.VUID-messages on either side.b31f5f73d9, the earlier comparison over^agc_driver_sampled_cache_budget$|^agc_driver_sampled_cache_budget_memory$|^agc_driver_storage_cache_budget$|^agc_driver_image_table_reusewas also clean: 5 of 5 on each side, with 3 devices checked.Ghost of Tsushima (PPSA02225 02.024.000). Plain
mainstops 9-29 s in onnative multisample stencil or depth format import is not implemented(#9717). So this was a local stack that runs it, with and without this change:maind5ef780bb4with #9717 (#9533 inside it), #9742, #10064, #10727, #12147, #8365, #8212, #12561, #12612, #12617 and env-gated diagnostics (a1012e1e49), then this change on top (fd488704ff, the same code as662b49d7b7;b31f5f73d9adds only the rate limit of its log line, and the head's ceiling is the 2 GiB cap on this machine). Runs alternate with and without, 600 s each, pad input, defaults otherwise. The brightness screen and opening start about 200 s in; I count presents from 210 to 600 s:MemAvailable(32 GB host) was 4.2 and 4.5 GB with this change, and 2.7 and 4.5 GB without it.admitTextureturned textures away gave 10 and 7 presents, against 9 and 6 without. In this scene the cache rarely turns textures away: the recoveries release them. That's why the recovery reaching a recent texture also counts.Trace captures (
APS5_TRACE_SUMMARY_EVERY=10 APS5_TRACE_SECONDS=300:60, the same stack without and with this PR's three commits,a1012e1e49andee55f90649), attached as a release. In the interval lines from 195 s, the runs without the change presented 7 and 7 frames, and the runs with it 13 and 22. The details and theperformance_compare.pyoutput are in this comment.Call of Duty: Black Ops II (PPSA34502), 300 s with pad input (
main+ #9656): its sampled cache held 365 MiB of a 3693 MiB budget and never turned a texture away. This change doesn't grow its budget.Windows 11 VM (GeForce GT 1030, WinLibs GCC 15.2, Release), at this head: the 17 tests matching
^agc_buffer_pool|^agc_sampled_cache|^agc_driver_sampled_cache|^agc_driver_recover_pass 3 of 3. Onmainc9207624bc, the 12 that exist there pass 3 of 3.Not tested: AMD, and a title whose frame fits its budget on a smaller card, such as PPSA16064 from USAGE.md. I don't have those here.
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)ShaderResources.cpp/.hppand the debt entry), and #12575, which keeps refused textures for their present (one hunk inReleaseTextureCaches). The order is in the comments below.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T02:10:08Z.
Review: CHANGES_REQUESTED
Thanks, the change is bounded (256 MiB steps, 2 GiB cap, given back after 10 quiet seconds) and the docs follow it. Before it can merge:
perf, so it needs theaps5-summary.jsonlline of a capture onmainand one with the change, from the same title, scene and machine, plus the output oftools/trace_digest.pyon both (AGENTS.md, GAME_TESTING.md "Pull requests labelledperf"). The present counts in Tested are not a substitute;tools/performance_compare.pycan produce the comparison. Attach both traces to the PR.spill-cpu) pins onlySampledTextureSpill. The part that changes behaviour,ReleaseTextureCachesstopping at an entry used in the last two presents whenReclaimHasHostFallback()is set andcache.spill != 0(ShaderResources.cpp:1469-1482), andBufferPool::AllocateMemorysetting the flag (BufferPool.cpp:94-97), has no test that fails without it. Please add one toagc_driver_sampled_cache_budget(sampled entries from the current present, a host-fallback reclaim keeps them; without fallback they are released).#6194 conflicts textually with this one, as you noted; whichever lands second rebases.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T03:11:16Z.
Review: CHANGES_REQUESTED
Thanks, the new head covers Dean's points (discrete GPUs only, room bounded by a quarter of the host heap's budget) and the tests:
recover-sampled-recent,-noroom,-deviceandspill-growtheach pin a piece that changes behaviour (the stop at recent entries, the flag set inBufferPool::AllocateMemory, the count of a refused texture), and your table shows each failing without it.One point is still open:
perf: it needs theaps5-summary.jsonlline of a capture onmainand one with the change, from the same title, scene and machine, plus the output oftools/trace_digest.pyon both, andtools/performance_compare.pyoutput. You said they are running; please attach them to the PR. Also add theVK_LAYER_KHRONOS_validationcomparison ofmainvs the change for the focused tests (AGENTS.md, AGC changes), confirming no newVUID-errors.Once those are in, this is ready from my side. #12575 conflicts in
ReleaseTextureCaches; whichever lands second rebases.Pull request closed