renderer: reuse texture lookups for unchanged descriptors #1289

Open
github-bot wants to merge 3 commits from github-bot/gh-1289 into main AGit
Owner

@⁠NeySlim on GitHub · 2026-10-09 07:40 UTC · original
NeySlim:perf/texture-lookup-cache → main · +521 −35 · 7 files · 3 commits · open

Problem

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::FindImage calls per frame. For each one:

  • RenderExecutor::ResolveTexture decodes 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;
  • FindImage walks 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 (FindImage 6.9%, half of it in the page-table walk, and 2.6% for the rest of ResolveTexture), while the descriptors and the set of cached images rarely change between two draws.

Change

  • TextureCache::FindImage remembers its exact matches: the image an exhaustive search returned (SameBacking or 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, so RegisterImage, UnregisterImage and AssociateStencil (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 of FindImage (access tick, LRU, fast-clear materialization, video-out checks) still runs.
  • RenderExecutor::ResolveTexture keeps 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.
  • Both caches are bounded (16384 entries) and start over when full.

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, ctest texture_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 in RegisterImage/UnregisterImage or in AssociateStencil, 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.

  • God of War Ragnarök from a new game, alternating the caches on and off every 5 s within a session, so both see the same scenes (two sessions, about 3 minutes of each scene per setting). Time spent per frame resolving texture bindings and render targets (ResolveTexture, ResolveRenderColorTarget, ResolveRenderDepthTarget, with their FindImage calls):
Before After
Cutscene (about 14,000 lookups per frame) 13.5 ms 11.7 ms
Gameplay (about 18,000 lookups per frame) 19.1 ms 16.7 ms

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_tests and the new texture_cache_lookup_reuse pass.
  • 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).
  • Per-page stamps: with one generation for the whole cache, 8.4% of the lookups found a stale entry, because any image registered or removed anywhere invalidated every entry. With them, profile of the GPU command thread in the opening cutscene: FindImagesInRegion 0.91 -> 0.42 ms per frame, plus 0.29 ms for checking the stamps. TextureLookupReuse now 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.

**@⁠NeySlim** on GitHub · 2026-10-09 07:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1289) `NeySlim:perf/texture-lookup-cache` → `main` · +521 −35 · 7 files · 3 commits · open ## Problem 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::FindImage` calls per frame. For each one: - `RenderExecutor::ResolveTexture` decodes 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; - `FindImage` walks 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 (`FindImage` 6.9%, half of it in the page-table walk, and 2.6% for the rest of `ResolveTexture`), while the descriptors and the set of cached images rarely change between two draws. ## Change - `TextureCache::FindImage` remembers its exact matches: the image an exhaustive search returned (`SameBacking` or 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, so `RegisterImage`, `UnregisterImage` and `AssociateStencil` (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 of `FindImage` (access tick, LRU, fast-clear materialization, video-out checks) still runs. - `RenderExecutor::ResolveTexture` keeps 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. - Both caches are bounded (16384 entries) and start over when full. 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`, ctest `texture_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 in `RegisterImage`/`UnregisterImage` or in `AssociateStencil`, 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. - God of War Ragnarök from a new game, alternating the caches on and off every 5 s within a session, so both see the same scenes (two sessions, about 3 minutes of each scene per setting). Time spent per frame resolving texture bindings and render targets (`ResolveTexture`, `ResolveRenderColorTarget`, `ResolveRenderDepthTarget`, with their `FindImage` calls): | | Before | After | |---|---|---| | Cutscene (about 14,000 lookups per frame) | 13.5 ms | 11.7 ms | | Gameplay (about 18,000 lookups per frame) | 19.1 ms | 16.7 ms | 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_tests` and the new `texture_cache_lookup_reuse` pass. - `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). - Per-page stamps: with one generation for the whole cache, 8.4% of the lookups found a stale entry, because any image registered or removed anywhere invalidated every entry. With them, profile of the GPU command thread in the opening cutscene: `FindImagesInRegion` 0.91 -> 0.42 ms per frame, plus 0.29 ms for checking the stamps. `TextureLookupReuse` now 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:51:41 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 07:40 UTC · original · edited 2026-10-21 23:04 UTC

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

  • Last reviewed commit: 9a677ab04c20074d09512fda07eed2f411c97b8c
  • Latest commit, not reviewed: b531f6f835

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 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.txt
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/render.h
  • tests/ShaderRecompilerComputeTests.cpp

Included 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: nmzik

Priority: ➖ Normal

Change: Refactor

Merge Risk: ⚪ Minimal · up to 9a677

No identified texture-lookup issue remains to block merging after normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive 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: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely summarizes the primary change: reusing texture lookups for unchanged descriptors.
Description check Passed The description directly explains the texture lookup and texture description caches, invalidation rules, tests, performance results, and validation status.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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.)

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 07:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1289#issuecomment-6076644805) · edited 2026-10-21 23:04 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1289?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > - Last reviewed commit: 9a677ab04c20074d09512fda07eed2f411c97b8c > - Latest commit, not reviewed: b531f6f835f3a36e63afce1ef93a91dcf108f0de > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `b0a16f35-03ad-48f1-a63e-3e8377b48cc5` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 3d568f1ff72f7030b794b3c91b6b25fad650a9dd and 9a677ab04c20074d09512fda07eed2f411c97b8c. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 5</strong></summary> <dl> <dd> * `CMakeLists.txt` * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/host_gpu/renderer/render.h` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> 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:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"9a677ab04c20074d09512fda07eed2f411c97b8c" --> **Change:** Refactor <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>9a677</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `9a677` --> <!-- final_review_risk_coverage:{"sourceCommitId":"9a677ab04c20074d09512fda07eed2f411c97b8c","coveredCommitId":"9a677ab04c20074d09512fda07eed2f411c97b8c","kind":"reviewed"} --> No identified texture-lookup issue remains to block merging after normal checks. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | 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: … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely summarizes the primary change: reusing texture lookups for unchanged descriptors. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the texture lookup and texture description caches, invalidation rules, tests, performance results, and validation status. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **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.) </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1289)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-10 02:13 UTC · original

Rebased on main after 5559cfcb. FindImage now also matches stencil planes through their depth owner, and AssociateStencil re-describes a registered plane in place, so the lookup key gained the guest format and binding type, and AssociateStencil advances the generation when it re-describes a plane. TextureLookupReuse gained 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-10 02:13 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1289#issuecomment-6092584522) Rebased on main after 5559cfcb. `FindImage` now also matches stencil planes through their depth owner, and `AssociateStencil` re-describes a registered plane in place, so the lookup key gained the guest format and binding type, and `AssociateStencil` advances the generation when it re-describes a plane. `TextureLookupReuse` gained 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.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-12 04:13 UTC · original

Rebased on main after dad900c6. FindImage now 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 a BcAlias::Matches alias stays registered in the range; frees from the alias merge and from the garbage collector go through UnregisterImage and already advance the generation. TextureLookupReuse gained 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.

**@⁠NeySlim** on GitHub · 2026-10-12 04:13 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1289#issuecomment-6117621858) Rebased on main after dad900c6. `FindImage` now 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 a `BcAlias::Matches` alias stays registered in the range; frees from the alias merge and from the garbage collector go through `UnregisterImage` and already advance the generation. `TextureLookupReuse` gained 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.
Author
Owner

@⁠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.cpp line 675 (outdated):

@@ -637,23 +639,91 @@ TextureBinding RenderExecutor::ResolveTexture(const ShaderRecompiler::IR::ImageR
 	                                 view_levels, desc.info.resources.layers);
 	desc.view_info.base_level = view_base;
 	desc.type = storage ? TextureCache::BindingType::Storage : TextureCache::BindingType::Texture;
+	TextureDescription result {};
+	result.desc              = std::move(desc);
+	result.descriptor        = descriptor;
+	result.pixel_format      = pixel_format;
+	result.view_format       = view_format;
+	result.shader_conversion = shader_conversion;
+	return result;
+}
+
+static uint64_t TextureDescriptionKey(const ShaderRecompiler::IR::ImageResource&   resource,
+                                      const ShaderRecompiler::IR::DescriptorValue& value) {
+	uint64_t   hash = 0xcbf29ce484222325ull;
+	const auto mix  = [&hash](uint64_t word) {
+		hash = (hash ^ word) * 0x100000001b3ull;
+		hash ^= hash >> 32u;
+	};
+	for (uint32_t i = 0; i < value.dwords.size(); i += 2) {
+		mix(value.dwords[i] | (uint64_t {value.dwords[i + 1]} << 32u));
+	}
+	// Every compared field that tells two resources of the same descriptor apart.
+	mix(resource.source | (uint64_t {resource.first_use_pc} << 32u));
+	mix(resource.indirect_root | (uint64_t {resource.shader_swizzle} << 32u));
+	mix(static_cast<uint32_t>(resource.conversion_format) |
+	    (uint64_t {resource.indirect_mapping_offset} << 32u));
+	mix(value.dword_count | (uint64_t {static_cast<uint32_t>(resource.dimension)} << 32u));
+	mix(static_cast<uint32_t>(resource.resource_class) |
+	    (uint64_t {static_cast<uint32_t>(resource.numeric_class)} << 32u));
+	mix(static_cast<uint32_t>(resource.mip_mode) | (uint64_t {resource.mip_count} << 32u));
+	mix(uint64_t {resource.read} | (uint64_t {resource.written} << 8u) |
+	    (uint64_t {resource.atomic} << 16u) | (uint64_t {resource.atomic64} << 24u) |
+	    (uint64_t {resource.depth_compare} << 32u) | (uint64_t {resource.cube} << 40u) |
+	    (uint64_t {resource.r128} << 48u));
+	return hash;
+}

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -C4 'struct DescriptorValue' --type=cpp
rg -nP -C3 'dwords\s*;|dwords\s*\{' --type=cpp -g '*escriptor*'

Repository: KytyPS5/KytyPS5

Length of output: 889


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- ResourceSnapshot.h ---'
nl -ba src/graphics/shader/recompiler/ir/ResourceSnapshot.h | sed -n '1,100p'
printf '%s\n' '--- descriptors.cpp key and lookup context ---'
nl -ba src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '620,730p'
printf '%s\n' '--- equality and key references ---'
rg -n -F --glob '*.h' --glob '*.cpp' -- 'operator==(const ImageResource' src/graphics
rg -n -F --glob '*.h' --glob '*.cpp' -- 'FindTextureDescription' src/graphics

Repository: KytyPS5/KytyPS5

Length of output: 8678


🏁 Script executed:

nl -ba src/graphics/shader/recompiler/ir/ShaderIR.h | sed -n '120,170p'

Repository: KytyPS5/KytyPS5

Length of output: 2929


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- omitted-field references in descriptor pipeline ---'
rg -n -F --glob '*.cpp' --glob '*.h' -- 'resource.descriptor_index' src/graphics/host_gpu/renderer src/graphics/shader
rg -n -F --glob '*.cpp' --glob '*.h' -- 'resource.indirect_search_iterations' src/graphics/host_gpu/renderer src/graphics/shader
rg -n -F --glob '*.cpp' --glob '*.h' -- 'resource.indirect_resources' src/graphics/host_gpu/renderer src/graphics/shader
printf '%s\n' '--- DescribeTexture declaration and callers ---'
rg -n -F --glob '*.cpp' --glob '*.h' -- 'DescribeTexture(' src/graphics/host_gpu/renderer

Repository: KytyPS5/KytyPS5

Length of output: 1027


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- DescribeTexture ---'
nl -ba src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '490,650p'
printf '%s\n' '--- descriptor_index use ---'
nl -ba src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '870,905p'

Repository: KytyPS5/KytyPS5

Length of output: 11465


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- ResolveTexture callers ---'
rg -n -F --glob '*.cpp' --glob '*.h' -- 'ResolveTexture(' src/graphics
printf '%s\n' '--- image omitted-field assignments ---'
rg -n -F --glob '*.cpp' --glob '*.h' -- '.descriptor_index =' src/graphics/shader src/graphics/host_gpu
rg -n -F --glob '*.cpp' --glob '*.h' -- '.indirect_search_iterations =' src/graphics/shader src/graphics/host_gpu
rg -n -F --glob '*.cpp' --glob '*.h' -- '.indirect_resources =' src/graphics/shader src/graphics/host_gpu

Repository: KytyPS5/KytyPS5

Length of output: 2749


Align the texture-description cache key with its equality.

ImageResource::operator== compares descriptor_index, indirect_search_iterations, and indirect_resources, but TextureDescriptionKey omits them. If two resources differ only in these fields, FindTextureDescription maps them to the same key, rejects the stored entry, and overwrites it. Alternating inputs can therefore repeat DescribeTexture instead of reusing the cache.

Use cache-specific equality for the fields that affect the description, or include every compared field in the key. DescriptorValue::dwords is 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](https://github.com/KytyPS5/KytyPS5/pull/1289#discussion_r4244640140) · edited 2026-10-12 04:38 UTC On `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` line 675 (outdated): ```diff @@ -637,23 +639,91 @@ TextureBinding RenderExecutor::ResolveTexture(const ShaderRecompiler::IR::ImageR view_levels, desc.info.resources.layers); desc.view_info.base_level = view_base; desc.type = storage ? TextureCache::BindingType::Storage : TextureCache::BindingType::Texture; + TextureDescription result {}; + result.desc = std::move(desc); + result.descriptor = descriptor; + result.pixel_format = pixel_format; + result.view_format = view_format; + result.shader_conversion = shader_conversion; + return result; +} + +static uint64_t TextureDescriptionKey(const ShaderRecompiler::IR::ImageResource& resource, + const ShaderRecompiler::IR::DescriptorValue& value) { + uint64_t hash = 0xcbf29ce484222325ull; + const auto mix = [&hash](uint64_t word) { + hash = (hash ^ word) * 0x100000001b3ull; + hash ^= hash >> 32u; + }; + for (uint32_t i = 0; i < value.dwords.size(); i += 2) { + mix(value.dwords[i] | (uint64_t {value.dwords[i + 1]} << 32u)); + } + // Every compared field that tells two resources of the same descriptor apart. + mix(resource.source | (uint64_t {resource.first_use_pc} << 32u)); + mix(resource.indirect_root | (uint64_t {resource.shader_swizzle} << 32u)); + mix(static_cast<uint32_t>(resource.conversion_format) | + (uint64_t {resource.indirect_mapping_offset} << 32u)); + mix(value.dword_count | (uint64_t {static_cast<uint32_t>(resource.dimension)} << 32u)); + mix(static_cast<uint32_t>(resource.resource_class) | + (uint64_t {static_cast<uint32_t>(resource.numeric_class)} << 32u)); + mix(static_cast<uint32_t>(resource.mip_mode) | (uint64_t {resource.mip_count} << 32u)); + mix(uint64_t {resource.read} | (uint64_t {resource.written} << 8u) | + (uint64_t {resource.atomic} << 16u) | (uint64_t {resource.atomic64} << 24u) | + (uint64_t {resource.depth_compare} << 32u) | (uint64_t {resource.cube} << 40u) | + (uint64_t {resource.r128} << 48u)); + return hash; +} ``` **🩺 Stability & Availability** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash rg -nP -C4 'struct DescriptorValue' --type=cpp rg -nP -C3 'dwords\s*;|dwords\s*\{' --type=cpp -g '*escriptor*' ``` Repository: KytyPS5/KytyPS5 Length of output: 889 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- ResourceSnapshot.h ---' nl -ba src/graphics/shader/recompiler/ir/ResourceSnapshot.h | sed -n '1,100p' printf '%s\n' '--- descriptors.cpp key and lookup context ---' nl -ba src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '620,730p' printf '%s\n' '--- equality and key references ---' rg -n -F --glob '*.h' --glob '*.cpp' -- 'operator==(const ImageResource' src/graphics rg -n -F --glob '*.h' --glob '*.cpp' -- 'FindTextureDescription' src/graphics ``` Repository: KytyPS5/KytyPS5 Length of output: 8678 --- 🏁 Script executed: ```bash nl -ba src/graphics/shader/recompiler/ir/ShaderIR.h | sed -n '120,170p' ``` Repository: KytyPS5/KytyPS5 Length of output: 2929 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- omitted-field references in descriptor pipeline ---' rg -n -F --glob '*.cpp' --glob '*.h' -- 'resource.descriptor_index' src/graphics/host_gpu/renderer src/graphics/shader rg -n -F --glob '*.cpp' --glob '*.h' -- 'resource.indirect_search_iterations' src/graphics/host_gpu/renderer src/graphics/shader rg -n -F --glob '*.cpp' --glob '*.h' -- 'resource.indirect_resources' src/graphics/host_gpu/renderer src/graphics/shader printf '%s\n' '--- DescribeTexture declaration and callers ---' rg -n -F --glob '*.cpp' --glob '*.h' -- 'DescribeTexture(' src/graphics/host_gpu/renderer ``` Repository: KytyPS5/KytyPS5 Length of output: 1027 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- DescribeTexture ---' nl -ba src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '490,650p' printf '%s\n' '--- descriptor_index use ---' nl -ba src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '870,905p' ``` Repository: KytyPS5/KytyPS5 Length of output: 11465 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- ResolveTexture callers ---' rg -n -F --glob '*.cpp' --glob '*.h' -- 'ResolveTexture(' src/graphics printf '%s\n' '--- image omitted-field assignments ---' rg -n -F --glob '*.cpp' --glob '*.h' -- '.descriptor_index =' src/graphics/shader src/graphics/host_gpu rg -n -F --glob '*.cpp' --glob '*.h' -- '.indirect_search_iterations =' src/graphics/shader src/graphics/host_gpu rg -n -F --glob '*.cpp' --glob '*.h' -- '.indirect_resources =' src/graphics/shader src/graphics/host_gpu ``` Repository: KytyPS5/KytyPS5 Length of output: 2749 --- </details> **Align the texture-description cache key with its equality.** `ImageResource::operator==` compares `descriptor_index`, `indirect_search_iterations`, and `indirect_resources`, but `TextureDescriptionKey` omits them. If two resources differ only in these fields, `FindTextureDescription` maps them to the same key, rejects the stored entry, and overwrites it. Alternating inputs can therefore repeat `DescribeTexture` instead of reusing the cache. Use cache-specific equality for the fields that affect the description, or include every compared field in the key. `DescriptorValue::dwords` is a fixed eight-element array, so the odd-size out-of-bounds case cannot occur. <!-- fingerprinting:phantom:poseidon:beignet55 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:a17a0eacba78776ad6bbb12d --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit f328acd
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 04:17 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 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.txt
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/render.h
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 04:17 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1289#pullrequestreview-5486504762) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `eca0a0ea-1d5e-440c-a8f6-d9850b87929f` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between b77284cd22fe25e9aad12e1dcbf4e84e13a5a7f0 and 1ad79a273e4899e5c83fb1b622078c86fee58954. </details> <details> <summary>📒 Files selected for processing (6)</summary> * `CMakeLists.txt` * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.h` * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/host_gpu/renderer/render.h` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=56d14916-d120-4621-aee4-4ddcb13090de attempt=fb300d88-d1f1-43ad-b6d3-a0a05c97880e batch=1/1 -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-12 04:31 UTC · original
On src/graphics/host_gpu/renderer/pipeline/descriptors.cpp line 675 (outdated):

@@ -637,23 +639,91 @@ TextureBinding RenderExecutor::ResolveTexture(const ShaderRecompiler::IR::ImageR
 	                                 view_levels, desc.info.resources.layers);
 	desc.view_info.base_level = view_base;
 	desc.type = storage ? TextureCache::BindingType::Storage : TextureCache::BindingType::Texture;
+	TextureDescription result {};
+	result.desc              = std::move(desc);
+	result.descriptor        = descriptor;
+	result.pixel_format      = pixel_format;
+	result.view_format       = view_format;
+	result.shader_conversion = shader_conversion;
+	return result;
+}
+
+static uint64_t TextureDescriptionKey(const ShaderRecompiler::IR::ImageResource&   resource,
+                                      const ShaderRecompiler::IR::DescriptorValue& value) {
+	uint64_t   hash = 0xcbf29ce484222325ull;
+	const auto mix  = [&hash](uint64_t word) {
+		hash = (hash ^ word) * 0x100000001b3ull;
+		hash ^= hash >> 32u;
+	};
+	for (uint32_t i = 0; i < value.dwords.size(); i += 2) {
+		mix(value.dwords[i] | (uint64_t {value.dwords[i + 1]} << 32u));
+	}
+	// Every compared field that tells two resources of the same descriptor apart.
+	mix(resource.source | (uint64_t {resource.first_use_pc} << 32u));
+	mix(resource.indirect_root | (uint64_t {resource.shader_swizzle} << 32u));
+	mix(static_cast<uint32_t>(resource.conversion_format) |
+	    (uint64_t {resource.indirect_mapping_offset} << 32u));
+	mix(value.dword_count | (uint64_t {static_cast<uint32_t>(resource.dimension)} << 32u));
+	mix(static_cast<uint32_t>(resource.resource_class) |
+	    (uint64_t {static_cast<uint32_t>(resource.numeric_class)} << 32u));
+	mix(static_cast<uint32_t>(resource.mip_mode) | (uint64_t {resource.mip_count} << 32u));
+	mix(uint64_t {resource.read} | (uint64_t {resource.written} << 8u) |
+	    (uint64_t {resource.atomic} << 16u) | (uint64_t {resource.atomic64} << 24u) |
+	    (uint64_t {resource.depth_compare} << 32u) | (uint64_t {resource.cube} << 40u) |
+	    (uint64_t {resource.r128} << 48u));
+	return hash;
+}

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).

**@⁠NeySlim** on GitHub · 2026-10-12 04:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1289#discussion_r4244692224) On `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` line 675 (outdated): ```diff @@ -637,23 +639,91 @@ TextureBinding RenderExecutor::ResolveTexture(const ShaderRecompiler::IR::ImageR view_levels, desc.info.resources.layers); desc.view_info.base_level = view_base; desc.type = storage ? TextureCache::BindingType::Storage : TextureCache::BindingType::Texture; + TextureDescription result {}; + result.desc = std::move(desc); + result.descriptor = descriptor; + result.pixel_format = pixel_format; + result.view_format = view_format; + result.shader_conversion = shader_conversion; + return result; +} + +static uint64_t TextureDescriptionKey(const ShaderRecompiler::IR::ImageResource& resource, + const ShaderRecompiler::IR::DescriptorValue& value) { + uint64_t hash = 0xcbf29ce484222325ull; + const auto mix = [&hash](uint64_t word) { + hash = (hash ^ word) * 0x100000001b3ull; + hash ^= hash >> 32u; + }; + for (uint32_t i = 0; i < value.dwords.size(); i += 2) { + mix(value.dwords[i] | (uint64_t {value.dwords[i + 1]} << 32u)); + } + // Every compared field that tells two resources of the same descriptor apart. + mix(resource.source | (uint64_t {resource.first_use_pc} << 32u)); + mix(resource.indirect_root | (uint64_t {resource.shader_swizzle} << 32u)); + mix(static_cast<uint32_t>(resource.conversion_format) | + (uint64_t {resource.indirect_mapping_offset} << 32u)); + mix(value.dword_count | (uint64_t {static_cast<uint32_t>(resource.dimension)} << 32u)); + mix(static_cast<uint32_t>(resource.resource_class) | + (uint64_t {static_cast<uint32_t>(resource.numeric_class)} << 32u)); + mix(static_cast<uint32_t>(resource.mip_mode) | (uint64_t {resource.mip_count} << 32u)); + mix(uint64_t {resource.read} | (uint64_t {resource.written} << 8u) | + (uint64_t {resource.atomic} << 16u) | (uint64_t {resource.atomic64} << 24u) | + (uint64_t {resource.depth_compare} << 32u) | (uint64_t {resource.cube} << 40u) | + (uint64_t {resource.r128} << 48u)); + return hash; +} ``` 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).
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 04:39 UTC · original
On src/graphics/host_gpu/renderer/pipeline/descriptors.cpp line 675 (outdated):

@@ -637,23 +639,91 @@ TextureBinding RenderExecutor::ResolveTexture(const ShaderRecompiler::IR::ImageR
 	                                 view_levels, desc.info.resources.layers);
 	desc.view_info.base_level = view_base;
 	desc.type = storage ? TextureCache::BindingType::Storage : TextureCache::BindingType::Texture;
+	TextureDescription result {};
+	result.desc              = std::move(desc);
+	result.descriptor        = descriptor;
+	result.pixel_format      = pixel_format;
+	result.view_format       = view_format;
+	result.shader_conversion = shader_conversion;
+	return result;
+}
+
+static uint64_t TextureDescriptionKey(const ShaderRecompiler::IR::ImageResource&   resource,
+                                      const ShaderRecompiler::IR::DescriptorValue& value) {
+	uint64_t   hash = 0xcbf29ce484222325ull;
+	const auto mix  = [&hash](uint64_t word) {
+		hash = (hash ^ word) * 0x100000001b3ull;
+		hash ^= hash >> 32u;
+	};
+	for (uint32_t i = 0; i < value.dwords.size(); i += 2) {
+		mix(value.dwords[i] | (uint64_t {value.dwords[i + 1]} << 32u));
+	}
+	// Every compared field that tells two resources of the same descriptor apart.
+	mix(resource.source | (uint64_t {resource.first_use_pc} << 32u));
+	mix(resource.indirect_root | (uint64_t {resource.shader_swizzle} << 32u));
+	mix(static_cast<uint32_t>(resource.conversion_format) |
+	    (uint64_t {resource.indirect_mapping_offset} << 32u));
+	mix(value.dword_count | (uint64_t {static_cast<uint32_t>(resource.dimension)} << 32u));
+	mix(static_cast<uint32_t>(resource.resource_class) |
+	    (uint64_t {static_cast<uint32_t>(resource.numeric_class)} << 32u));
+	mix(static_cast<uint32_t>(resource.mip_mode) | (uint64_t {resource.mip_count} << 32u));
+	mix(uint64_t {resource.read} | (uint64_t {resource.written} << 8u) |
+	    (uint64_t {resource.atomic} << 16u) | (uint64_t {resource.atomic64} << 24u) |
+	    (uint64_t {resource.depth_compare} << 32u) | (uint64_t {resource.cube} << 40u) |
+	    (uint64_t {resource.r128} << 48u));
+	return hash;
+}

@NeySlim, thanks for the clarification and fix. The supplied code uses the same resource projection for the key, equality check, and DescribeTexture. This addresses the cache-reuse mismatch. The reported alternating-resource test covers the original failure case.


✏️ Learnings added
Learnt from: NeySlim
Repo: KytyPS5/KytyPS5 PR: 1289
File: src/graphics/host_gpu/renderer/pipeline/descriptors.cpp:0-0
Timestamp: 2026-10-12T04:38:56.455Z
Learning: In src/graphics/host_gpu/renderer/pipeline/descriptors.cpp, the C++ texture-description cache depends only on ImageResource fields resource_class, numeric_class, dimension, mip_mode, mip_count, read, written, atomic, atomic64, depth_compare, cube, and r128. TextureDescriptionInputs projects these fields for the cache key, equality check, and DescribeTexture call. Resource source, descriptor_index, first_use_pc, and indirect fields do not affect the texture description.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 04:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1289#discussion_r4244720547) On `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` line 675 (outdated): ```diff @@ -637,23 +639,91 @@ TextureBinding RenderExecutor::ResolveTexture(const ShaderRecompiler::IR::ImageR view_levels, desc.info.resources.layers); desc.view_info.base_level = view_base; desc.type = storage ? TextureCache::BindingType::Storage : TextureCache::BindingType::Texture; + TextureDescription result {}; + result.desc = std::move(desc); + result.descriptor = descriptor; + result.pixel_format = pixel_format; + result.view_format = view_format; + result.shader_conversion = shader_conversion; + return result; +} + +static uint64_t TextureDescriptionKey(const ShaderRecompiler::IR::ImageResource& resource, + const ShaderRecompiler::IR::DescriptorValue& value) { + uint64_t hash = 0xcbf29ce484222325ull; + const auto mix = [&hash](uint64_t word) { + hash = (hash ^ word) * 0x100000001b3ull; + hash ^= hash >> 32u; + }; + for (uint32_t i = 0; i < value.dwords.size(); i += 2) { + mix(value.dwords[i] | (uint64_t {value.dwords[i + 1]} << 32u)); + } + // Every compared field that tells two resources of the same descriptor apart. + mix(resource.source | (uint64_t {resource.first_use_pc} << 32u)); + mix(resource.indirect_root | (uint64_t {resource.shader_swizzle} << 32u)); + mix(static_cast<uint32_t>(resource.conversion_format) | + (uint64_t {resource.indirect_mapping_offset} << 32u)); + mix(value.dword_count | (uint64_t {static_cast<uint32_t>(resource.dimension)} << 32u)); + mix(static_cast<uint32_t>(resource.resource_class) | + (uint64_t {static_cast<uint32_t>(resource.numeric_class)} << 32u)); + mix(static_cast<uint32_t>(resource.mip_mode) | (uint64_t {resource.mip_count} << 32u)); + mix(uint64_t {resource.read} | (uint64_t {resource.written} << 8u) | + (uint64_t {resource.atomic} << 16u) | (uint64_t {resource.atomic64} << 24u) | + (uint64_t {resource.depth_compare} << 32u) | (uint64_t {resource.cube} << 40u) | + (uint64_t {resource.r128} << 48u)); + return hash; +} ``` `@NeySlim`, thanks for the clarification and fix. The supplied code uses the same resource projection for the key, equality check, and `DescribeTexture`. This addresses the cache-reuse mismatch. The reported alternating-resource test covers the original failure case. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: NeySlim Repo: KytyPS5/KytyPS5 PR: 1289 File: src/graphics/host_gpu/renderer/pipeline/descriptors.cpp:0-0 Timestamp: 2026-10-12T04:38:56.455Z Learning: In src/graphics/host_gpu/renderer/pipeline/descriptors.cpp, the C++ texture-description cache depends only on ImageResource fields resource_class, numeric_class, dimension, mip_mode, mip_count, read, written, atomic, atomic64, depth_compare, cube, and r128. TextureDescriptionInputs projects these fields for the cache key, equality check, and DescribeTexture call. Resource source, descriptor_index, first_use_pc, and indirect fields do not affect the texture description. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Cache%20keys%20should%20reflect%20only%20what%20results%20depend%20on.%20Projecting%20textures%20onto%20%60DescribeTexture%60%E2%80%99s%20inputs%20avoids%20needless%20misses%20when%20unrelated%20metadata%20changes%E2%80%94and%20regression%20tests%20verify%20reuse.%20Try%20%40coderabbitai%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1289%23discussion_r4244640140)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠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.

**@⁠NeySlim** on GitHub · 2026-10-13 20:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1289#issuecomment-6154976464) 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.
This pull request has changes conflicting with the target branch.
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/render.h
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.
git fetch -u origin '+refs/pull/1289/head:github-bot/gh-1289'
git switch 'github-bot/gh-1289'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1289'
git switch 'github-bot/gh-1289'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1289'
git switch 'github-bot/gh-1289'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1289'
git switch 'main'
git merge --squash 'github-bot/gh-1289'
git switch 'main'
git merge --ff-only 'github-bot/gh-1289'
git switch 'main'
git merge 'github-bot/gh-1289'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.