renderer: reuse texture lookups for unchanged descriptors #1289
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1289
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1289"
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?
@NeySlim on GitHub · 2026-10-09 07:40 UTC · original
NeySlim:perf/texture-lookup-cache→main· +521 −35 · 7 files · 3 commits · openProblem
Every draw and dispatch resolves each of its textures again from scratch, and each draw resolves its color and depth targets again: in God of War Ragnarök (PPSA08332, 05.005) about 10,000 texture bindings and 14,000
TextureCache::FindImagecalls per frame. For each one:RenderExecutor::ResolveTexturedecodes the T# and recomputes the guest layout (TileGetTextureSize,TileGetTiledTextureLayout, mip layout, view), although the result depends only on the descriptor and the shader's image resource;FindImagewalks the image page table over the whole image (1 MiB pages: about 66 pages for a 3840x2160 RGBA16F target) to collect candidates before it compares their backings.In the opening cutscene this is about 10% of the GPU command thread's samples (
FindImage6.9%, half of it in the page-table walk, and 2.6% for the rest ofResolveTexture), while the descriptors and the set of cached images rarely change between two draws.Change
TextureCache::FindImageremembers its exact matches: the image an exhaustive search returned (SameBackingor the stencil plane test), or the image it just created for that description, keyed by the requested fields that decide the match (range, extent, subresources, samples, block size, tile mode, color transform, pixel and guest formats, type, binding type, exact format). An entry holds while no image is registered, unregistered or re-described: the match depends only on the registered images and their descriptions, soRegisterImage,UnregisterImageandAssociateStencil(when it re-describes a stencil plane for another depth image) stamp the 1 MiB pages they cover with a new generation. An entry holds while none of the pages of its request has a newer stamp: the exact match only depends on the images registered on those pages, the candidates the page-table walk would collect. A match is not remembered while a block-compressed alias of the image (BcAlias::Matches) stays registered in the range, since a later full search merges that alias once it holds GPU writes. A hit skips the page-table walk and the comparisons; the rest ofFindImage(access tick, LRU, fast-clear materialization, video-out checks) still runs.RenderExecutor::ResolveTexturekeeps the descriptions it computed (everything before the cache lookup), keyed by the image resource and the descriptor value and used only when both compare equal. The description is a function of these inputs only. The lookup, stencil association and the checks that depend on the cached image still run on every binding.Nothing else is skipped: CPU writes to image memory, fast clears and metadata, and target and storage state are still checked on every binding, as before.
Test
New
TextureLookupReuse(--texture-lookup-only, ctesttexture_cache_lookup_reuse, also in the default run): a texture bound again with the same descriptor finds its image without searching the image page table; after another image with the same backing is registered, the lookup returns it (the last exact match, as a full search does); after it is removed, the first one again; another descriptor resolves to another image; a stencil plane read finds its depth association, and stops matching it once the plane is re-associated with a depth image of another sample count; a raw alias of a BC image, left in place while it has no GPU writes, is merged by the next lookup of the BC image once the GPU writes it. Without the change the first check fails (the page table is searched again); without the generation step inRegisterImage/UnregisterImageor inAssociateStencil, the registration or the re-association check fails; if matches are remembered while a BC alias remains, the alias merge check fails.Validation
Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.3.
ResolveTexture,ResolveRenderColorTarget,ResolveRenderDepthTarget, with theirFindImagecalls):92% of the lookups are exact-match hits and 99.9% of the descriptions are reused. Most of what remains is the per-binding work that still runs (locking, fast-clear checks, access bookkeeping). Screenshots of the same scenes show no rendering difference.
resource_tracking_tests,resource_materialization_testsand the newtexture_cache_lookup_reusepass.shader_recompiler_compute_tests, one case per process: same results as main (614 of 624 cases pass with the change, 613 of 623 on main; the same 10 fail on both on this RADV setup).FindImagesInRegion0.91 -> 0.42 ms per frame, plus 0.29 ms for checking the stamps.TextureLookupReusenow also checks that a registration on another page keeps the entry, and that a BC image across two pages with an alias registered on the second page only is still merged after a GPU write; it fails with each of 8 mutations I tried. GPU suite, one case per process: 614/624, as before.Not tested on Windows or macOS; the change is platform-independent (standard containers, no platform-specific code), and the new check runs on every platform.
AI use
I used Claude Code (AI agent) to profile the GPU command thread, write the change and the test, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
@coderabbitai[bot] on GitHub · 2026-10-09 07:40 UTC · original · edited 2026-10-21 23:04 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
b0a16f35-03ad-48f1-a63e-3e8377b48cc5📥 Commits
Reviewing files that changed from the base of the PR and between 3d568f1ff72f7030b794b3c91b6b25fad650a9dd and 9a677ab04c20074d09512fda07eed2f411c97b8c.
📒 Files selected for processing: 5
CMakeLists.txtsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/render.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.
📝 Walkthrough
The change adds caches for descriptor-derived texture descriptions and exact image matches. Description entries are reused only when their resource and descriptor inputs match. Exact image entries are reused only while their registration generation is current. A Vulkan-backed test checks lookup behavior across repeated resolutions, image changes, descriptor changes, stencil-plane reassociation, and BC alias handling. CTest runs the test through a dedicated selector.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Refactor
Merge Risk: ⚪ Minimal · up to
9a677No identified texture-lookup issue remains to block merging after normal checks.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 13.64% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 5 files. (2 skipped: 1 unsupported, 1 too large.)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@NeySlim on GitHub · 2026-10-10 02:13 UTC · original
Rebased on main after
5559cfcb.FindImagenow also matches stencil planes through their depth owner, andAssociateStencilre-describes a registered plane in place, so the lookup key gained the guest format and binding type, andAssociateStenciladvances the generation when it re-describes a plane.TextureLookupReusegained a re-association check, which fails without that step. GPU suite, one case per process: same failures as main (604/614 vs 603/613). The in-game timings were not measured again.@NeySlim on GitHub · 2026-10-12 04:13 UTC · original
Rebased on main after
dad900c6.FindImagenow resolves block-compressed aliases during the full search, and an alias left in place (no GPU writes yet, or CPU-dirty) is merged by a later search once it can be downloaded, without any registration change. So the lookup cache no longer remembers a match while aBcAlias::Matchesalias stays registered in the range; frees from the alias merge and from the garbage collector go throughUnregisterImageand already advance the generation.TextureLookupReusegained a BC alias check, which fails if matches are remembered while the alias remains. Texture cache ctests: same results as main. GPU suite, one case per process: same failures as main (614/624 vs 613/623). The in-game timings were not measured again.@coderabbitai[bot] on GitHub · 2026-10-12 04:17 UTC · original · edited 2026-10-12 04:38 UTC
On
src/graphics/host_gpu/renderer/pipeline/descriptors.cppline 675 (outdated):🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 889
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8678
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2929
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 1027
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11465
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2749
Align the texture-description cache key with its equality.
ImageResource::operator==comparesdescriptor_index,indirect_search_iterations, andindirect_resources, butTextureDescriptionKeyomits them. If two resources differ only in these fields,FindTextureDescriptionmaps them to the same key, rejects the stored entry, and overwrites it. Alternating inputs can therefore repeatDescribeTextureinstead of reusing the cache.Use cache-specific equality for the fields that affect the description, or include every compared field in the key.
DescriptorValue::dwordsis a fixed eight-element array, so the odd-size out-of-bounds case cannot occur.✅ Addressed in commit f328acd
@coderabbitai[bot] on GitHub · 2026-10-12 04:17 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
eca0a0ea-1d5e-440c-a8f6-d9850b87929f📥 Commits
Reviewing files that changed from the base of the PR and between b77284cd22fe25e9aad12e1dcbf4e84e13a5a7f0 and 1ad79a273e4899e5c83fb1b622078c86fee58954.
📒 Files selected for processing (6)
CMakeLists.txtsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/render.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@NeySlim on GitHub · 2026-10-12 04:31 UTC · original
On
src/graphics/host_gpu/renderer/pipeline/descriptors.cppline 675 (outdated):Valid. DescribeTexture only reads resource_class, numeric_class, dimension, mip_mode, mip_count, read, written, atomic, atomic64, depth_compare, cube and r128. Fixed in f328acd4: the lookup now projects the resource onto those fields and uses that projection for the key, the equality check and DescribeTexture itself, so the description cannot depend on a field the cache ignores. TextureLookupReuse now alternates two resources that differ only in source, descriptor_index, first_use_pc and the indirect fields, and checks that they share one entry (fails without the fix).
@coderabbitai[bot] on GitHub · 2026-10-12 04:39 UTC · original
On
src/graphics/host_gpu/renderer/pipeline/descriptors.cppline 675 (outdated):@NeySlim, thanks for the clarification and fix. The supplied code uses the same resource projection for the key, equality check, andDescribeTexture. This addresses the cache-reuse mismatch. The reported alternating-resource test covers the original failure case.✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@NeySlim on GitHub · 2026-10-13 20:53 UTC · original
Added 3d568f1f: lookups are now invalidated per 1 MiB page instead of on every registration anywhere, which made 8.4% of them stale. Same BC alias rule. Description updated.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.