perf(agc): keep sampled textures that are bound or used this frame #1971
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1971"
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 Celegans12 on 2026-10-09T03:26:49Z.
What
The sampled texture cache evicts its least recently used entry even when a build, a recorded batch or a cached resource set still holds that texture, which frees no device memory and makes the next lookup create a second copy. A frame that samples more textures than the cache holds also misses on all of them every frame: least recently used order evicts each texture just before the next frame asks for it again. In PPSA26344 every texture of a 16,386-entry image table is made again each frame.
Recorder::Presents), a texture's first use in the frame is returned uncached, and a second use in the same frame evicts as before. So a miss early in a frame does not evict what the rest of the frame needs, and a new set of textures replaces the old one on its second frame. Before the first present the order is plain LRU.APS5_PROFILE_DRAWadds a[texture-cache]line (cached, used uncached, evicted, passed over, found changed).ShaderResources, not with this commit.Tested
main6b56175awith #1059: configure-DBUILD_TESTING=ON, full build,--target libs,ctest:ctest --output-on-failure)mainf1451396: 500/500 passagc_driver_sampled_cache_budgetextended: held textures are not made twice below the ceiling, released ones behind held ones leave a second later, a view survives snapshot pressure; a set two larger than the cache keeps the cache's share in the next frame, a second use is cached, a new set replaces the old on its second frame, and a new texture first used ahead of the cached ones leaves all of them cached. Fails on #1059.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:39:26Z.
Review: COMMENTED
Could
firstUsesstoreTextureKeyvalues withTextureKeyHashinstead of onlysize_thashes? Two distinct descriptors can collide inTextureKeyHash; after one first-use miss, the collision makes the other descriptor look like it already missed this present, so it can bypass the recent-entry guard and evict a texture used this or last present on its first use. The cache index already has the full key equality available.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T04:52:33Z.
Linux results, since this was tested on Windows only. Everything passes here.
Nobara 44 (Linux 7.2), GCC 16.2.1, Release,
BUILD_TESTING=ON. This PR merged ontomainf1451396cleanly.mainf1451396main+ this PRctest -R agc_driver -j1-E agc_driver)The CPU failure is
guest_dynamic_loader, which fails the same way onmain.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-09T05:18:32Z.
Thanks, you're right. A hash match was all it took to count as "already missed this present". So a second descriptor whose hash happened to equal the first one's was treated as a second use: it skipped the guard and evicted a texture the last frame had used.
firstUsesis now astd::unordered_set<TextureKey, TextureKeyHash>, so it compares full keys the same way the cache index does. The per-present reset hasn't changed.To test it I built a real collision instead of injecting a fake hash.
agc_driver_sampled_cache_budgethas a new case that makes two descriptors of the same surface. They differ only in word 6's statistics counter and the meta address bits, which the decoder ignores when META_COMPRESS is off, and word 7 is picked so that both keys get the sameTextureKeyHash. The test fills the cache in one frame. In the next frame it uses both descriptors for the first time and checks that every cached texture is still there. On the old head (31c70367) it fails with 3 of the 4 textures left; with the change it passes. One caveat: to find the pair, the test repeats the FNV-1a steps ofTextureKeyHash, so if the hash ever changes, the test needs the same change. If you'd rather have a test that injects a colliding hash, I can switch it.The new head is e3180e13. Windows NVIDIA ctest is 476/476, and upstream's Linux job on the merge with
mainf1451396is 500/500.Details
agc_driver_sampled_cache_budget):the first use of a descriptor whose cache key hash equals that of another descriptor first used in the frame left 3 of the 4 textures the last frame used cachedmainf1451396) buildslibsand passesagc_driver_sampled_cache_budget,agc_driver_sampled_cache_budget_memory,agc_driver_storage_cache_budgetandagc_driver_graphics.