Skip to content

perf(agc): let the sampled texture cache grow into host memory while a frame's textures don't fit - #12684

Closed
milescoviello wants to merge 3 commits into
boykopovar:mainfrom
milescoviello:perf/sampled-cache-spill
Closed

milescoviello wants to merge 3 commits into
boykopovar:mainfrom
milescoviello:perf/sampled-cache-spill

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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_budget budget 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. admitTexture then 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

sampledBudget adds 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: admitTexture turning 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.

  • At each budget read (at most once a second) after either, the room grows by 256 MiB, up to 2 GiB and up to a quarter of the largest non-device-local heap's VK_EXT_memory_budget budget (its size without the extension) in whole steps (SampledSpillCeiling). Only a discrete GPU gets room at all.
  • It gives 256 MiB back at a read after 10 s without either, while the cache's bytes leave at least two steps of it unused.
  • SampledTextureSpill is 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, ReleaseTextureCaches stops 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 by BufferPool::AllocateMemory around 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 budget line now says how much of the budget is past the device's share, and the [gpu] texture caches released line 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=3072 on 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_MIB still 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 main c9207624bc unless noted:

  • New agc_sampled_cache_spill (CPU only):

    • SampledTextureSpill grows 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.
    • SampledSpillCeiling is 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 fake VK_EXT_memory_budget hook 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.
    • The two host-heap recovery modes skip on a device with no memory type outside its device-local heaps.
  • Each piece taken out alone fails its test (one run each). Without the stop at recent entries, recover_sampled-recent fails. With the stop regardless of room, recover_sampled-recent-noroom fails. Without admitTexture's count, spill_growth fails. Without the recovery's count, recover_sampled-recent-noroom fails. Without the discrete-GPU check, agc_sampled_cache_spill and spill_growth fail.

  • 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_pool pass 3 of 3.

  • Validation layer (Khronos VK_LAYER_KHRONOS_validation 1.4.363, LunarG SDK), on main c9207624bc and 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$' -V

    • main passes 5 of 5 (the new modes don't exist there) and the head 9 of 9. Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS.
    • The layer checked the 5 and 9 devices those tests create, with no VUID- messages on either side.
    • At 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_reuse was also clean: 5 of 5 on each side, with 3 devices checked.
  • Ghost of Tsushima (PPSA02225 02.024.000). Plain main stops 9-29 s in on native multisample stencil or depth format import is not implemented (feat(agc): sample the stencil plane of a native multisampled D32S8 target #9717). So this was a local stack that runs it, with and without this change: main d5ef780bb4 with feat(agc): sample the stencil plane of a native multisampled D32S8 target #9717 (fix(agc): import native multisample D32S8 targets with a separate stencil plane and a depth-only HTILE #9533 inside it), fix(agc): accept a colour alias over a native multisample depth plane when HTILE proves its clear #9742, fix(agc): build a partially committed sampled 3D view from its committed slices #10064, fix(agc): keep a registered shader's register state as a sorted list #10727, fix(agc): bound the SPIR-V that background compute pipeline builds compile at once #12147, feat(agc): store the pipeline journal's modules compressed #8365, fix(agc): build one compute pipeline when results differ only in a table's size #8212, fix(shader): read a 2D MSAA T# through image_sample_a as its sample 0 #12561, feat(agc): read sample 0 of a native multisampled depth surface through a 2D image #12612, fix(agc): take a storage image's writes to the stencil plane when a depth target binds #12617 and env-gated diagnostics (a1012e1e49), then this change on top (fd488704ff, the same code as 662b49d7b7; b31f5f73d9 adds 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:

    Run Presents 210-600 s Sampled textures made 210-600 s Budget
    with, 1 20 55,000 4096 MiB (2048 past the device's share)
    without, 2 6 164,600 2048 MiB
    with, 3 20 65,400 4096 MiB
    without, 4 9 157,000 2048 MiB
    • The two runs with this change made 5,414 and 6,504 out-of-memory recoveries, and 5,385 and 6,252 of them stopped at a sampled texture of the last two presents. After that stop, the recovery releases storage images instead, so the textures still fit in device memory. None of the runs with this change placed a texture in host memory.
    • The lowest MemAvailable (32 GB host) was 4.2 and 4.5 GB with this change, and 2.7 and 4.5 GB without it.
    • An earlier version that grew only when admitTexture turned 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, a1012e1e49 and ee55f90649), 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 the performance_compare.py output are in this comment.

  • Call of Duty: Black Ops II (PPSA34502), 300 s with pad input (main + fix(libSceVoice): report inactive input voice activity #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. On main c9207624bc, 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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none. Two open PRs conflict with this: fix(agc): grow the storage cache budget while it evicts under pressure #6194, which grows the storage image cache under eviction (ShaderResources.cpp/.hpp and the debt entry), and perf(agc): reuse a texture the sampled cache refuses while frames keep using it #12575, which keeps refused textures for their present (one hunk in ReleaseTextureCaches). The order is in the comments below.
  • Fixes: none
  • Unblocks: none (Ghost of Tsushima's opening frame rate, see Tested)
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti (Linux)
  • AI-assisted: yes

🤖 Generated with Claude Code

…a frame's textures don't fit

When every entry the sampled texture cache could evict was used in the current or previous present, it turns new textures away, and a frame larger than its budget makes those textures again at every use. Ghost of Tsushima's brightness screen does this with a 27,000-texture image table on a 12 GB GPU, where the budget sits at its 2 GiB floor. The budget now grows by 256 MiB at each read while textures are turned away, up to 2 GiB past the reported share, when the device has a non-device-local heap, and shrinks again after 10 s without a turned-away texture. While it is grown, the out-of-memory recovery of an allocation that can fall back to host memory no longer releases sampled textures used in the last two presents, so the extra textures go to host memory instead of pushing the frame's own textures out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Oct 29, 2026
@github-actions

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@milescoviello

Copy link
Copy Markdown
Contributor Author

On the overlap with #6194 (@Thunderhawkk, opened 10-15): that PR grows the storage image cache's budget while it evicts under its own budget, and this one grows the sampled texture cache's budget. They're separate changes, but they edit neighbouring code in ShaderResources.cpp/.hpp (the budget functions and ReleaseTextureCaches) and the same "Texture cache budgets" debt entry, so they conflict textually. #6194 also conflicts with main in those files right now. I'm happy for #6194 to go first, and I'll rebase this one onto it. If this lands first, #6194's rebase keeps both growth rules side by side; they don't depend on each other.

One data point from Ghost of Tsushima that may matter for #6194: raising only the storage budget to 4 GiB (a local override) gave 6 and 5 presents over 300-590 s, against 5 and 5 with defaults, so in that title the storage cache wasn't the limit. With this PR, the recovery releases storage images where it used to release the frame's sampled textures (about 50,000 re-created over 210-600 s), which a storage-side rule like #6194's could address next.

AI-assisted: yes (Claude Code)

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • This PR is labelled perf, so it needs the aps5-summary.jsonl line of a capture on main and one with the change, from the same title, scene and machine, plus the output of tools/trace_digest.py on both (AGENTS.md, GAME_TESTING.md "Pull requests labelled perf"). The present counts in Tested are not a substitute; tools/performance_compare.py can produce the comparison. Attach both traces to the PR.
  • The new test (spill-cpu) pins only SampledTextureSpill. The part that changes behaviour, ReleaseTextureCaches stopping at an entry used in the last two presents when ReclaimHasHostFallback() is set and cache.spill != 0 (ShaderResources.cpp:1469-1482), and BufferPool::AllocateMemory setting the flag (BufferPool.cpp:94-97), has no test that fails without it. Please add one to agc_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.

@milescoviello

Copy link
Copy Markdown
Contributor Author

@adriadam10 thanks, working on both:

  • The test is written: two new modes in the recovery test, next to agc_driver_sampled_cache_budget's cases. With a host-visible heap, a sampled texture used in the current present survives a host-fallback reclaim and the allocation goes to host memory. When every heap is device-local, the same reclaim releases it. It is running now, together with a check that it fails with the keep-recent stop taken out.
  • The captures are queued on the same machine and scene: APS5_TRACE_SUMMARY_EVERY=10 plus a 60 s trace window, alternating the stack without and with this change, two runs each. I'll post the summary lines, trace_digest.py and performance_compare.py output, and attach the traces once they finish.

AI-assisted: yes (Claude Code)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@milescoviello the mechanism is well bounded (256 MiB per read, 2 GiB cap, a step back after 10 quiet seconds only while the cache leaves two steps unused, nothing at all without a non-device-local heap), the thread-local flag around the recovery call is scoped correctly, and agc_sampled_cache_spill checks the step function. Three requests:

  1. The body and the new debt text say that integrated GPUs, "where every heap is device-local", are unchanged. That is not true of every integrated GPU: hasHostHeap is true for any device with a heap that lacks VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, and an APU under RADV (Steam Deck class hardware) reports a small VRAM heap plus a GTT heap that is not device-local, so the room does grow there. Please say which case you mean, or check the device type: if growth on such a device is intended, say so in USAGE.md and the debt entry; if not, skip it for VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU.
  2. Nothing limits the room to what the host can give. The cap is a fixed 2 GiB whatever the size or budget of the non-device-local heap. Please bound it by that heap (for example by a fraction of its size, or of its VK_EXT_memory_budget budget when the extension is present), or state why a fixed 2 GiB is safe on an 8 GB host.
  3. The two pieces that carry the change in your title run, admitTexture counting a refused texture and ReleaseTextureCaches stopping at a sampled entry of the last two presents when ReclaimHasHostFallback() is set, have no test; spill-cpu only covers SampledTextureSpill. A small execution case in SampledCacheBudget that (a) sets the flag through a reclaim callback and checks that the release stops at the recent entry once the room is non-zero and continues past it when it is zero, and (b) that a refused admission raises the budget at the next read would cover it. This is a request, not a blocker for the numbers you measured.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 12575 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L1440

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1368 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 1395 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 2434 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 3786 docs/user/USAGE.md
PR 4448 docs/dev/debt/libSceAgcDriver.md
PR 4449 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 4472 core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp
PR 5021 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
docs/user/USAGE.md
PR 5371 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5372 docs/dev/debt/libSceAgcDriver.md
PR 5925 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
docs/user/USAGE.md
PR 6185 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6186 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6187 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6188 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6192 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6194 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6209 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6223 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6280 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6300 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6412 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6481 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6548 docs/dev/debt/libSceAgcDriver.md
PR 6549 docs/dev/debt/libSceAgcDriver.md
PR 6804 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6808 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6905 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6924 docs/user/USAGE.md
PR 6970 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6977 docs/dev/debt/libSceAgcDriver.md
PR 6987 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6989 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6995 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 7002 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7048 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 7256 docs/dev/debt/libSceAgcDriver.md
PR 7275 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7449 docs/dev/debt/libSceAgcDriver.md
PR 7457 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7464 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7514 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7604 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 7642 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
docs/user/USAGE.md
PR 7689 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 7844 docs/dev/debt/libSceAgcDriver.md
PR 7978 docs/dev/debt/libSceAgcDriver.md
PR 8014 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 8223 docs/dev/debt/libSceAgcDriver.md
PR 8246 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8319 docs/dev/debt/libSceAgcDriver.md
PR 8484 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8592 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 8874 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 8963 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 9012 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
PR 9345 docs/user/USAGE.md
PR 9356 docs/dev/debt/libSceAgcDriver.md
PR 9387 docs/dev/debt/libSceAgcDriver.md
PR 9432 docs/dev/debt/libSceAgcDriver.md
PR 9508 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
docs/dev/debt/libSceAgcDriver.md
docs/user/USAGE.md
PR 9592 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 9700 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 9712 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 9748 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 9891 docs/dev/debt/libSceAgcDriver.md
PR 9893 docs/dev/debt/libSceAgcDriver.md
PR 9895 docs/dev/debt/libSceAgcDriver.md
PR 9897 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 9898 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 9899 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9915 docs/dev/debt/libSceAgcDriver.md
PR 10026 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 10049 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 10193 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
docs/user/USAGE.md
PR 10233 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 10442 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 10472 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 10492 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 10497 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 10757 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 10792 docs/user/USAGE.md
PR 10861 docs/user/USAGE.md
PR 10920 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
PR 11444 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 11551 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
docs/dev/debt/libSceAgcDriver.md
PR 11554 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 12070 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 12120 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 12324 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 12348 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 12702 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/user/USAGE.md
PR 12828 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 12862 core/libs/prx/libSceAgcDriver/CMakeLists.txt

milescoviello and others added 2 commits October 29, 2026 02:44
…e GPUs, up to a quarter of the host heap

The room grew on any device with a heap outside device-local memory, up to a
fixed 2 GiB. An integrated GPU under RADV reports a GTT heap that is not
device-local, but that heap is the system memory the title itself uses, so
`SampledSpillCeiling` now gives no room unless the device is a discrete GPU.
On a discrete GPU the room is at most a quarter of the largest
non-device-local heap's VK_EXT_memory_budget budget (its size without the
extension), in whole 256 MiB steps, and still at most 2 GiB.
`SampledTextureSpill` takes that ceiling and clamps the room to it.

The room now has its own debt entry, and the texture cache budgets entry is
back to its text on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he room's growth

New modes of agc_driver_sampled_cache_budget_tests, run without a fixed
cache budget and with a reported 64 GiB heap budget:
- recover-sampled-recent: with room past the device's share, a recovery
  for an allocation that can go to host memory keeps the current present's
  texture, and the new texture is placed in host memory.
- recover-sampled-recent-noroom: with no room, the same recovery releases
  that texture, and the next budget read is one 256 MiB step past the
  device's share.
- recover-sampled-recent-device: with every heap device-local, the recovery
  releases it.
- spill-growth (agc_driver_sampled_cache_spill_growth): a texture turned
  away by a cache full of the current present's textures adds one step at
  the next budget read; a read with nothing turned away keeps it; a GPU
  that is not discrete gets none. It adds a host heap no memory type uses,
  so it runs on devices without one.

The two host-heap recovery modes skip on a device with no memory type
outside its device-local heaps (lavapipe). SetSampledSpillForTest also
restarts the quiet time, so the first budget read doesn't give the room
straight back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milescoviello

Copy link
Copy Markdown
Contributor Author

@oneandonlydean thanks. I pushed two commits on top of b31f5f73d9; the head is now ba0eaedff6.

  1. Integrated GPUs. The room is now given only when the device is a discrete GPU (Context::discreteGpu). On an APU, the non-device-local heap (RADV's GTT heap, for example) is the system memory the title itself uses, so its budget stays at the reported share. USAGE.md and the debt entry say so.
  2. Host bound. SampledSpillCeiling caps the room at a quarter of the largest non-device-local heap's VK_EXT_memory_budget budget (its size without the extension), in whole 256 MiB steps, and at 2 GiB. SampledTextureSpill clamps the room to that ceiling, so it also comes down if the ceiling falls.
    • Here the host heap is 22.7 GiB (on a 32 GB host), and NVIDIA 615 reports its budget as its size. The ceiling is therefore the 2 GiB cap, and the Ghost of Tsushima runs behave as before.
    • A host heap with a 6 GiB budget would get 1.5 GiB.
    • spill-cpu now also checks the quarter, the rounding down to whole steps, the size fallback, a heap whose quarter is under one step, a GPU that isn't discrete, and all-device-local heaps.
  3. Tests, all in agc_driver_sampled_cache_budget_tests. These modes run without a fixed cache budget, so the budget reads go through the spill code. The fake memory-budget hook reports 64 GiB for every heap.
    • recover-sampled-recent: with room, a host-fallback recovery stops at the current present's texture, and the new texture goes to host memory.
    • recover-sampled-recent-noroom (new): with no room, the same recovery releases that texture. The next budget read is the device's share plus one 256 MiB step.
    • recover-sampled-recent-device: when every heap is device-local, the recovery releases it.
    • spill-growth (new, agc_driver_sampled_cache_spill_growth):
      • A texture turned away by a cache full of the current present's textures adds one step at the next read.
      • A read with nothing turned away in between keeps the room.
      • A GPU that isn't discrete gets none.
      • It adds a host heap that no memory type uses, so it doesn't need one on the device.
    • The two host-heap recovery modes print skipped, the device has no memory type outside its device-local heaps ... and skip on a device without one.
    • SetSampledSpillForTest now also restarts the quiet time. Otherwise the first budget read could give the room straight back.

Each piece of the change, taken out on its own, fails its test (one run each on the RTX 4070 Ti):

Taken out Failing test Message
the stop at recent entries (keepRecent = false) agc_driver_recover_sampled-recent_allocation ... an allocation that could go to host memory released a texture of the current present
the room condition (keepRecent = hostFallback) agc_driver_recover_sampled-recent-noroom_allocation ... kept the texture of the current present instead of releasing it
admitTexture's count of a refused texture agc_driver_sampled_cache_spill_growth the budget read after a texture was turned away is 41986 MiB, not one 256 MiB step past the device's share of 41986 MiB
the recovery's count of a recent entry agc_driver_recover_sampled-recent-noroom_allocation a recovery that released a texture of the current present left the next budget read at 41985 MiB, not one 256 MiB step ...
the discrete-GPU check agc_sampled_cache_spill, agc_driver_sampled_cache_spill_growth a GPU that is not discrete ... was given room past its share

At the head, the 19 tests matching ^agc_driver_recover_|^agc_sampled_cache|^agc_driver_sampled_cache|^agc_driver_storage_cache|^agc_buffer_pool pass 3 of 3.

The room now has its own debt entry (under 1000 characters), and the texture cache budgets entry is back to its text on main. The validation-layer comparison and the Windows VM run of this head are running. I'll add them to the body together with the captures for @adriadam10.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

Overlap note: #12575 (QRMOE, opened 2026-10-28 21:15Z, before this PR) also changes ReleaseTextureCaches and SampledCacheBudget.cpp. It keeps a texture the sampled cache turns away for the rest of its present. This PR grows the budget while textures are turned away, and stops the out-of-memory recovery at the frame's own textures, so the two address different parts of the same problem.

git merge-tree of #12575's head 408f4375cc with this head ba0eaedff6 shows one conflict hunk, at the top of the sampled loop in ReleaseTextureCaches:

Keeping both, #12575's loop first, resolves it. A refused texture still goes through the refusal in admitTexture that this PR counts, so the room still grows with #12575 in.

Order: #12575 first, since it was first. If it merges before this PR, I'll rebase this onto it and rerun the tests in Tested.

AI-assisted: yes (Claude Code)

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, -device and spill-growth each pin a piece that changes behaviour (the stop at recent entries, the flag set in BufferPool::AllocateMemory, the count of a refused texture), and your table shows each failing without it.

One point is still open:

  • This PR is labelled perf: it needs the aps5-summary.jsonl line of a capture on main and one with the change, from the same title, scene and machine, plus the output of tools/trace_digest.py on both, and tools/performance_compare.py output. You said they are running; please attach them to the PR. Also add the VK_LAYER_KHRONOS_validation comparison of main vs the change for the focused tests (AGENTS.md, AGC changes), confirming no new VUID- errors.

Once those are in, this is ready from my side. #12575 conflicts in ReleaseTextureCaches; whichever lands second rebases.

@milescoviello

Copy link
Copy Markdown
Contributor Author

@adriadam10 the captures are attached as the release pr12684-got-captures. It has each run's trace, aps5-summary.jsonl, and trace_digest.py output on the trace and on the summary file, plus performance_compare.py on two pairs.

Setup. Ghost of Tsushima Director's Cut (PPSA02225 02.024.000), RTX 4070 Ti 12 GB, NVIDIA 615.71.09, Ubuntu 26.04.1, i7-13700K, 32 GB.

Run Build Presents in the interval lines from 195 s Frame p50 in those intervals
B1 without (a1012e1e49) 7 15.8 to 77.2 s, rising
B3 without 7 10.5 to 81.7 s
S4 with (ee55f90649) 13 mostly 15-22 s, then 35-56 s
S5 with 22 11.2 to 26.6 s
  • Window lines. At these frame times, the 60 s trace window holds one frame interval per run. So the window lines and performance_compare.py compare one frame on each side: B3 against S4 gives frame p50 +4.4 %, mean frame -26.5 % and GPU busy per present -22.2 %; B1 against S5 gives frame p50 -76.3 %, mean frame -74.5 % and GPU busy -30.3 %. The interval lines cover the whole run, and their tables are in each *-summary-digest.txt.
  • A fifth run with the change (S2) was killed 120 s in, and no trace was written. That isn't this PR. On those runs the title builds a 2288 MiB sampled array (143 slices, of which 72 fit its guest allocation), and its upload buffers go to host memory along with it. Host memory then fell under the run's 2 GB guard. The same happens without this PR, in a later base run at 127 s. I'm looking at that separately.
Window summary lines (B3 without, S4 with)
{"commit":"a1012e1e4976","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PROFILE_DRAW":"1","APS5_TRACE_SECONDS":"300:60","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA02225","title":"Ghost of Tsushima","content_version":"02.024.000","resolution":"3840x2160","window":{"spec":"seconds 300:60","first_present":1114,"ms":105220.220},"presents":2,"frame_ms":{"p50":53147.830,"p90":53147.830,"p99":53147.830,"max":53147.830},"gpu_busy_ms_per_present":3649.549,"worker_busy_pct":{"queue worker 0x0":98.253,"queue worker 0x40":3.968,"queue worker 0x20":44.113,"queue worker 0x48":4.638,"queue worker 0x38":49.913,"queue worker 0x52":36.444,"queue worker 0x30":48.364,"queue worker 0x50":54.543,"queue worker 0x51":0.431},"top_phases_ms_per_frame":{"Driver.Packet":178959.343,"Driver.Packet.memory_wait":113281.201,"Driver.Packet.draw":31037.760,"Driver.Draw":31032.087,"Driver.Packet.dispatch":30506.648,"Graphics.Draw":27787.900,"Graphics.Draw.draw_and_resource_release":27414.661,"Resources.Complete":23039.212},"trace_dropped":false,"trace":"aps5-trace-a1012e1e4976-3.json.gz"}
{"commit":"ee55f9064948","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PROFILE_DRAW":"1","APS5_TRACE_SECONDS":"300:60","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA02225","title":"Ghost of Tsushima","content_version":"02.024.000","resolution":"3840x2160","window":{"spec":"seconds 300:60","first_present":1135,"ms":77332.978},"presents":2,"frame_ms":{"p50":55476.022,"p90":55476.022,"p99":55476.022,"max":55476.022},"gpu_busy_ms_per_present":2839.650,"worker_busy_pct":{"queue worker 0x0":98.440,"queue worker 0x40":0.039,"queue worker 0x20":83.704,"queue worker 0x48":4.271,"queue worker 0x38":95.761,"queue worker 0x52":64.682,"queue worker 0x30":95.265,"queue worker 0x50":31.903,"queue worker 0x51":1.539},"top_phases_ms_per_frame":{"Driver.Packet":183402.453,"Driver.Packet.memory_wait":141407.974,"Driver.Packet.draw":34488.846,"Driver.Draw":34483.803,"Graphics.Draw":29326.788,"Graphics.Draw.draw_and_resource_release":29001.811,"Driver.Draw.draw_enqueued":22792.961,"Resources.Complete":21990.619},"trace_dropped":false,"trace":"aps5-trace-ee55f9064948-3.json.gz"}
trace_digest.py on the summary files: interval tables (B3 without, S4 with)

24 intervals, 0.0 to 561.9 s, 1118 presents
NVIDIA GeForce RTX 4070 Ti, NVIDIA 615.71.09, Linux 7.0.0-38-generic, 3840x2160, commit a1012e1e4976

# seconds presents p50 p90 p99 max GPU busy busiest worker largest phase
1 0-10 234 16.7 87.7 306.3 2703.3 10.0 61 % Driver.Packet 67.8
2 10-20 126 78.9 82.5 92.1 93.1 39.0 87 % Driver.Packet 173.7
3 20-32 207 16.7 16.7 163.9 6455.0 3.8 11 % Shader.PrepareArtifact 94.4
4 32-42 241 23.8 68.4 388.1 420.9 12.6 51 % Driver.Packet 47.5
5 42-60 113 52.7 78.9 114.7 12696.7 19.5 81 % Driver.Packet 360.6
6 60-71 18 540.9 1120.2 1253.0 1253.0 193.9 92 % Driver.Packet 2384.2
7 71-81 22 430.4 493.8 791.0 791.0 126.0 91 % Driver.Packet 1798.8
8 81-91 23 433.5 488.3 812.6 812.6 134.4 91 % Driver.Packet 1773.8
9 91-101 24 431.7 453.8 460.3 460.3 116.9 91 % Driver.Packet 1677.7
10 101-112 24 418.7 446.4 517.7 517.7 118.2 91 % Driver.Packet 1646.3
11 112-122 23 430.9 471.6 759.2 759.2 117.8 92 % Driver.Packet 1757.4
12 122-132 22 451.0 495.8 514.0 514.0 121.1 92 % Driver.Packet 1750.3
13 132-143 20 439.3 1774.3 1832.6 1832.6 199.3 86 % Driver.Packet 2052.6
14 143-155 10 1061.5 2109.3 2109.3 2109.3 434.8 95 % Driver.Packet 4481.1
15 155-177 2 14303.3 14303.3 14303.3 14303.3 2831.2 100 % Driver.Packet 52683.0
16 177-195 1 17445.6 17445.6 17445.6 17445.6 7986.4 92 % Driver.Packet 73487.3
17 195-210 1 14951.9 14951.9 14951.9 14951.9 2328.4 99 % Driver.Packet 70805.9
18 210-220 1 10525.8 10525.8 10525.8 10525.8 3594.2 99 % Driver.Packet 50519.9
19 220-268 1 47997.5 47997.5 47997.5 47997.5 2660.8 100 % Driver.Packet 168004.8
20 268-311 1 42737.1 42737.1 42737.1 42737.1 3761.6 80 % Driver.Packet 135191.3
21 311-363 1 52072.4 52072.4 52072.4 52072.4 3672.4 97 % Driver.Packet 207706.1
22 363-416 1 53147.8 53147.8 53147.8 53147.8 3626.7 100 % Driver.Packet 150212.6
23 416-498 1 81685.8 81685.8 81685.8 81685.8 4116.0 100 % Driver.Packet 234335.8
24 498-562 1 64219.4 64219.4 64219.4 64219.4 4809.6 95 % Driver.Packet 182923.1

29 intervals, 0.0 to 539.3 s, 1142 presents
NVIDIA GeForce RTX 4070 Ti, NVIDIA 615.71.09, Linux 7.0.0-38-generic, 3840x2160, commit ee55f9064948

# seconds presents p50 p90 p99 max GPU busy busiest worker largest phase
1 0-10 249 16.7 80.7 224.1 1379.5 13.9 59 % Driver.Packet 60.0
2 10-20 125 79.9 82.7 86.8 90.3 40.7 87 % Driver.Packet 176.0
3 20-32 207 16.7 16.7 188.2 6248.0 4.0 11 % Shader.PrepareArtifact 94.0
4 32-42 227 20.2 74.0 396.0 429.0 13.7 50 % Driver.Packet 50.4
5 42-61 135 47.9 71.8 76.7 13145.7 17.4 81 % Driver.Packet 315.2
6 61-71 17 460.7 762.8 2138.6 2138.6 207.4 91 % Driver.Packet 2609.2
7 71-82 21 424.0 694.4 770.4 770.4 128.1 92 % Driver.Packet 1980.6
8 82-92 24 420.6 448.4 478.4 478.4 122.4 91 % Driver.Packet 1657.3
9 92-102 24 433.4 450.0 450.4 450.4 123.6 91 % Driver.Packet 1669.0
10 102-112 24 428.8 456.0 502.6 502.6 119.1 91 % Driver.Packet 1671.7
11 112-122 22 430.9 470.6 950.0 950.0 129.0 91 % Driver.Packet 1821.3
12 122-133 23 449.2 484.0 516.0 516.0 125.4 92 % Driver.Packet 1735.2
13 133-144 18 444.5 1342.7 2665.9 2665.9 250.7 93 % Driver.Packet 2328.9
14 144-156 9 901.5 3103.5 3103.5 3103.5 416.4 96 % Driver.Packet 5399.9
15 156-176 2 14267.4 14267.4 14267.4 14267.4 1173.5 99 % Driver.Packet 48080.1
16 176-194 1 17912.1 17912.1 17912.1 17912.1 10777.5 92 % Driver.Packet 75603.6
17 194-212 1 18465.2 18465.2 18465.2 18465.2 2639.1 99 % Driver.Packet 87935.2
18 212-231 1 19088.9 19088.9 19088.9 19088.9 3896.2 99 % Driver.Packet 88460.1
19 231-247 1 15487.4 15487.4 15487.4 15487.4 2401.7 99 % Driver.Packet 72602.3
20 247-263 1 16730.6 16730.6 16730.6 16730.6 2478.3 99 % Driver.Packet 77263.3
21 263-279 1 15442.1 15442.1 15442.1 15442.1 2301.4 99 % Driver.Packet 70603.2
22 279-299 1 20275.1 20275.1 20275.1 20275.1 2688.9 100 % Driver.Packet 93474.0
23 299-317 1 17945.9 17945.9 17945.9 17945.9 3116.0 100 % Driver.Packet 83318.7
24 317-339 1 21857.0 21857.0 21857.0 21857.0 3061.2 99 % Driver.Packet 100475.5
25 339-394 1 55476.0 55476.0 55476.0 55476.0 2618.1 98 % Driver.Packet 266329.4
26 394-409 1 15000.5 15000.5 15000.5 15000.5 14390.3 99 % Driver.Packet 67248.6
27 409-450 2 35303.3 35303.3 35303.3 35303.3 1727.4 100 % Driver.Packet 96614.9
28 450-499 1 49503.2 49503.2 49503.2 49503.2 6928.4 98 % Driver.Packet 229080.4
29 499-539 1 40077.7 40077.7 40077.7 40077.7 13938.6 100 % Driver.Packet 183142.2
trace_digest.py on the traces, first lines (B3 without, S4 with)

seconds 300:60 from present 1114: 2 presents, frame p50 53147.8 / p90 53147.8 / p99 53147.8 / max 53147.8 ms, GPU busy 3649.5 ms per present
NVIDIA GeForce RTX 4070 Ti, NVIDIA 615.71.09, Linux 7.0.0-38-generic, 3840x2160, commit a1012e1e4976, dropped: no

seconds 300:60 from present 1135: 2 presents, frame p50 55476.0 / p90 55476.0 / p99 55476.0 / max 55476.0 ms, GPU busy 2839.7 ms per present
NVIDIA GeForce RTX 4070 Ti, NVIDIA 615.71.09, Linux 7.0.0-38-generic, 3840x2160, commit ee55f9064948, dropped: no

The full outputs, with thread and phase tables, are in the release.

performance_compare.py, B3 against S4

Performance comparison

Capture Commit Trace Presents Window (ms)
baseline a1012e1e4976 aps5-trace-a1012e1e4976-3.json.gz 2 105220.220
candidate ee55f9064948 aps5-trace-ee55f9064948-3.json.gz 2 77332.978
  • Compare captures from the same machine, title, content version and scene; matching recorded metadata cannot verify the physical machine or scene.
  • Changes are candidate minus baseline. A negative frame-time change means a shorter frame interval.
  • A missing top phase is unreported, not zero; its change is unavailable.

Frame and GPU times (ms)

Metric Baseline Candidate Change Change (%)
frame_ms.p50 53147.830 55476.022 +2328.192 +4.381
frame_ms.p90 53147.830 55476.022 +2328.192 +4.381
frame_ms.p99 53147.830 55476.022 +2328.192 +4.381
frame_ms.max 53147.830 55476.022 +2328.192 +4.381
mean_frame_ms 52610.110 38666.489 -13943.621 -26.504
gpu_busy_ms_per_present 3649.549 2839.650 -809.899 -22.192

Top phases (ms per frame)

Metric Baseline Candidate Change Change (%)
Driver.Draw 31032.087 34483.803 +3451.716 +11.123
Driver.Draw.draw_enqueued n/a 22792.961 n/a n/a
Driver.Packet 178959.343 183402.453 +4443.110 +2.483
Driver.Packet.dispatch 30506.648 n/a n/a n/a
Driver.Packet.draw 31037.760 34488.846 +3451.086 +11.119
Driver.Packet.memory_wait 113281.201 141407.974 +28126.773 +24.829
Graphics.Draw 27787.900 29326.788 +1538.888 +5.538
Graphics.Draw.draw_and_resource_release 27414.661 29001.811 +1587.150 +5.789
Resources.Complete 23039.212 21990.619 -1048.593 -4.551
performance_compare.py, B1 against S5

Performance comparison

Capture Commit Trace Presents Window (ms)
baseline a1012e1e4976 aps5-trace-a1012e1e4976-3.json.gz 2 121721.544
candidate ee55f9064948 aps5-trace-ee55f9064948-3.json.gz 4 62001.788
  • Compare captures from the same machine, title, content version and scene; matching recorded metadata cannot verify the physical machine or scene.
  • Changes are candidate minus baseline. A negative frame-time change means a shorter frame interval.
  • A missing top phase is unreported, not zero; its change is unavailable.

Frame and GPU times (ms)

Metric Baseline Candidate Change Change (%)
frame_ms.p50 64700.771 15336.243 -49364.528 -76.297
frame_ms.p90 64700.771 20203.742 -44497.029 -68.774
frame_ms.p99 64700.771 20203.742 -44497.029 -68.774
frame_ms.max 64700.771 20203.742 -44497.029 -68.774
mean_frame_ms 60860.772 15500.447 -45360.325 -74.531
gpu_busy_ms_per_present 4130.639 2880.145 -1250.494 -30.274

Top phases (ms per frame)

Metric Baseline Candidate Change Change (%)
Driver.Draw 38973.784 12452.928 -26520.856 -68.048
Driver.Draw.shader_compile_and_link n/a 10612.571 n/a n/a
Driver.Packet 195032.712 71014.811 -124017.901 -63.588
Driver.Packet.dispatch 31047.547 n/a n/a n/a
Driver.Packet.draw 38980.192 12457.554 -26522.638 -68.041
Driver.Packet.memory_wait 123483.089 52928.066 -70555.023 -57.137
Graphics.Draw 38131.856 4950.903 -33180.953 -87.016
Graphics.Draw.draw_and_resource_release 37713.130 n/a n/a n/a
Resources.Complete 27914.987 n/a n/a n/a
Shader.DrawStage n/a 10207.633 n/a n/a
Shader.DrawStage.capture_resources n/a 7012.988 n/a n/a

The validation-layer comparison is in Tested: main 5 of 5, the head 9 of 9, no VUID- messages on either side. I also started longer trace windows over 210-540 s; I will add them if those runs get past the 120 s spike.

AI-assisted: yes (Claude Code)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@adriadam10 we'll merge this once the requests above are addressed and exact-head CI is green, unless you'd rather merge it yourself.

@milescoviello

Copy link
Copy Markdown
Contributor Author

Overlap note: #10472 (@nikhilpanchal1, opened 2026-10-24, before this PR) suballocates sampled and storage image memory, and the two heads conflict in four hunks, all mechanical (git merge-tree of ba0eaedff6 and #10472's head):

The two don't change the same behaviour: #10472 changes where image memory comes from, and this PR changes how much the sampled cache may keep and where its recovery stops. With suballocation, the fallback flag still describes the allocation being tried. As with #12575, whichever lands second rebases. If #10472 lands first, I'll rebase this PR onto it and rerun its tests.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

@adriadam10 both items from your review are in, for when you have a moment to re-check:

Order notes since then: #12575 and #10472 (overlap note above): whichever lands second rebases.

AI-assisted: yes (Claude Code)

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head ba0eaed merged onto main 52c09d5 · tested 2026-10-29 11:52 UTC · 34 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,281 passed · 4 failed (0 new, 4 also fail on main) · 39 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,324 of 2,873 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (898 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) none
Intermittent validation messages (1, seen once in the parallel run, not reproduced when the test was re-run alone 2 times; not counted against this PR)
agc_driver_depth_clear_hle: VUID-vkCmdCopyBuffer-commonparent (6x)
Failing on main too (4, not counted against this PR)
agc_compute_pipeline_inspection
agc_submit_progress_no_timeline
guest_mmap_executable
guest_socket_options_multicast
Passed on retry (1, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)
agc_driver_depth_clear_hle: SEGFAULT in the parallel run; also passed only on retry in 24 other runs in the last 7 days
Validated but not compared (5, not in the main baseline's validation pass)
agc_driver_recover_sampled-recent-device_allocation
agc_driver_recover_sampled-recent-noroom_allocation
agc_driver_recover_sampled-recent_allocation
agc_driver_sampled_cache_spill_growth
agc_sampled_cache_spill
Validation IDs already present on main (4 IDs in 436 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (436 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_passes, agc_driver_address_passes_draw_transitions, agc_driver_address_passes_targets_split, agc_driver_alpha_to_coverage, agc_driver_array_layer_target_cpu, agc_driver_bc_block_copy, and 428 more
VUID-vkCmdCopyImage-srcImage-01548 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-vkCmdCopyImage-srcImage-01551 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
Skipped (39)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_msaa_dcc_compared_import_2: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_4: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_8: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_stencil_ref_export: skipped, the device lacks VK_EXT_shader_stencil_export
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fresh: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_labels: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SD
Reproduce
git fetch origin ba0eaedff633434f93e03d39a19913ee4b799edd 52c09d567d2fa453494dd720fcf53a98149468e4
git checkout 52c09d567d2fa453494dd720fcf53a98149468e4 && git merge --no-ff ba0eaedff633434f93e03d39a19913ee4b799edd
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@Tehshortbus

Copy link
Copy Markdown
Contributor

A data point from Ghost of Yōtei (PPSA26344, 02.002.000), which shares the sampled-cache thrash this targets. Same machine and settings for every run: RTX 4070 SUPER 12 GB (615.78.08, VK_EXT_memory_budget device-local budget about 9 GB), CachyOS Linux, Release, APS5_PROFILE_DRAW=1 APS5_TRACE_SUMMARY_EVERY=10, warm shader cache. Each run is 15 minutes from launch, in the order base, this PR, this PR, base.

Over the first 41 [texture-cache] intervals (about 520 s):

Run Cached Used uncached Evicted Presents by 520 s
base 1 65,006 39,163 36,562 539
this PR 2 64,205 30,324 18,568 553
base 4 64,528 45,311 37,708 569

So in this title the spill engages (2048 MiB of it past the device's share for a frame that did not fit). It turns away about a quarter fewer textures and halves the evictions, but the presents fall between the two base runs. The frames here are bound by resource builds (the images and stage B phases), not only by refusals.

Both runs with this PR aborted; both base runs ran the full 15 minutes:

  • Run 3, at 528 s, with AGC graphics: the partial write of a packed color target does not store into the target's resident image (Draw.cpp, the merged-target check). The lines just before it are two vkAllocateMemory storage texture recovered ... initialResult=-2 reclaims. The sampled budget was 7979 MiB at that point, so the storage images had less room than in the base runs.
  • Run 2, at 58 s, with AGC driver: unsupported PM4 packet type: header 0x00000008 at DWORD 129 of 552. That was before any spill (3 budget lines in), and I haven't seen this message in about 20 other Yōtei runs, so I can't tie it to this PR.

Only two runs per arm, so this is a data point, not a measurement. I can rerun with more rounds, or with a capture, if that helps.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

@Tehshortbus thanks, that's useful, and it matches what I'm seeing on Ghost of Tsushima (PPSA02225) today on an RTX 4070 Ti with a 9.3 GB budget.

With the room at its 2048 MiB limit, the sampled cache takes VRAM the storage images then lack. Right before the host-memory kills, storage texture ... placed in host memory reached 2748 MiB in 128 allocations. That fits your run 3: two storage texture recovered reclaims at a 7979 MiB sampled budget, then the merged-target abort. With the room off (a local APS5_SAMPLED_ROOM_MIB=0 cap), those placements stopped, but then about 6,400 textures per 10 s are used uncached, and texture creation spends 49 s in allocation over 77,200 textures. So the room trades one stall for another, and in both titles it doesn't buy presents.

I'm testing @QRMOE's #12575 on the same GoT stack now. It keeps refused textures through the present instead of growing the budget, and touches the same function. If it holds up there, I'll narrow this PR so the room can't take the share the storage cache needs, or close it in favour of #12575. I'll post the GoT numbers here either way.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

As promised, the Ghost of Tsushima (PPSA02225) numbers. They're from an RTX 4070 Ti (12 GB, 10.5 GB VK_EXT_memory_budget budget), NVIDIA 615.71.09, Linux, on my GoT test stack.

These aren't matched pairs: the stack and the save state changed between them, so they don't measure this PR on its own. Still, the extra room doesn't buy presents in either GoT or @Tehshortbus's Ghost of Yōtei runs, and in GoT it costs the storage images their VRAM. #12575 deals with the refused-texture churn without growing the budget. So I'm closing this in favour of #12575. Thanks @adriadam10 and @Tehshortbus for the reviews and data.

AI-assisted: yes (Claude Code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs perf numbers missing perf pull request without a before and after summary line perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants