perf(agc): keep a full sampled texture cache from refusing textures over entries unused for seconds #28914
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28914"
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-12-04T16:23:48Z.
What
When the sampled texture cache is over its budget,
admitTexture(ShaderResources.cpp) refuses a new texture while the least recently used entry was used in the current frame (for the texture's first use, in the current frame or the last one). The refused texture has already been built from guest memory; it serves that one lookup and is dropped, so its next lookup builds it again.The rule counts frames by presents. When presents are minutes apart (a long load, or a scene that takes minutes per frame on the host), "used in this frame" covers minutes, and the cache keeps entries that have not been used for minutes while the textures in use are rebuilt at every lookup.
This adds a time limit to the refusal: the least recently used entry keeps its place only if it was also used within the last 10 s (
APS5_TEXTURE_RECENT_USE_MS;0restores the old rule).used), set wherepresentis set: on a hit (touchTexture) and when the entry is inserted.Tested
c10c3779bf: the 24 tests matchingagc_driver_sampled_cache|agc_driver_resource_cache|agc_driver_recover_|agc_sampled_cache(including the newagc_driver_sampled_cache_stale_frame) pass in each of 3 runs, none skipped.agc_driver_sampled_cache_stale_framefails at "a texture first used in the same frame 400 ms later, when the least recently used entry had not been used for longer than APS5_TEXTURE_RECENT_USE_MS (200), was not cached".agc_driver_sampled_cache_stale_frame(SampledCacheBudget.cpp stale-frame, withAPS5_TEXTURE_RECENT_USE_MS=200): a frame fills the cache; a texture first used right after is refused, as before; 400 ms later, still in the same frame, a new texture is cached in place of the entry unused for 400 ms, while the entry used again just before stays.PPSA38500, Ubuntu 26.04.1, RTX 4070 Ti 12 GB (NVIDIA 615.71.09), on my local stack (
mainde4730493aplus about 40 open pull requests), with the cache forced to 6500 MiB (APS5_TEXTURE_CACHE_MIB=6500),APS5_PROFILE_DRAW=1, one boot of 3600 s per side. The rule was measured as a local switch with the same condition (refuse only if the entry was used within 10000 ms), not with this branch.Why: without the limit, the cache refused 913,046 lookups in the hour. At each refusal, the least recently used entry had last been used:
Per frame, only 1,000 to 3,700 distinct textures were refused, each rebuilt about 250 times.
With the limit, per present after the first 1200 s (about 3 presents per boot, so these are rough):
Resources.CompleteDriver.DispatchNot settled: the boot with the limit ended at 2832 s on a SIGSEGV inside the NVIDIA driver's
vkAllocateMemory(called fromBufferPool::allocateMemoryWithReuse). At that point device-local memory was full, so texture allocations were going to host memory, and the process was at its 32 GiB memory cap. The boot without the limit had neither. One boot per side cannot say whether the limit makes that more likely. More boots per side are running, and this stays a draft until they are in.Related: #12575 keeps a refused texture for as long as frames keep using it; this pull request changes when a texture is refused. Both change code around
admitTexture; neither changes the other's rule. #28620 changes only the notice sent for a refused texture.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)View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.