gpu: fix corrupt textures when a shorter mip chain reuses a cached texture's memory (PPSA09809) #1781

Open
github-bot wants to merge 8 commits from github-bot/gh-1781 into main AGit
Owner

@⁠MrBigBritches on GitHub · 2026-10-21 03:32 UTC · original
MrBigBritches:texture-mip-layout-fix → main · +425 −10 · 3 files · 8 commits · open

A texture usually comes with mip levels, smaller copies of itself (half size, quarter size and so on) that the GPU uses when the surface is far away. On the PS5 the whole chain is stored in one block of memory, smallest level first. So where the full-size level (the base level) sits depends on how many levels the texture has. A one-level texture keeps its base level at the start of the block. An eight-level texture at the same address keeps it after the seven smaller levels.

Kyty caches each texture as a host image. When the game asked for a texture at an address the cache already had, Kyty only compared mip layouts when both had the same level count. A request with a different level count reused the cached image, so its base level was read from the wrong offset.

Octopath Traveler II streams one-level ground textures into memory that an eight-level texture used before. A few minutes into a session, the paving outside the mansion showed window-shaped bright rectangles and dark patches. Half of each texture was right and the other half was whatever followed it in memory, and it changed from run to run.

Example - Ground textures image

Changes

Compare mip placement whenever level counts differ

  • ResolveOverlap now compares the levels both layouts share whenever the level counts differ. Any difference makes the request a separate guest layout with its own image, as an equal-count mismatch already did.
  • A different layer count doesn't make mismatched levels compatible, so the check runs regardless of layer count.
  • FindImage's equal-backing fast path runs the same check. It used to accept a cached image with more levels and the same allocation size (common with padded tiled layouts) before ResolveOverlap ran.
  • Levels that differ only inside the mip tail leave every shared level in place, so those requests still reuse the cached image.

Retire the replaced image safely

When a request becomes a separate image, the cached image it replaces still needs handling. This applies to every same-address mismatch. That includes a different level count, a different tile mode, or a different mip layout with the same level count.

  • Image only mirrors guest memory: an idle one is freed, as before.
  • Image was written by the GPU and is idle: freeing it would lose contents that were never downloaded, but keeping it alongside the new image is just as bad. Range lookups could pick it, and texture GC could later download its stale contents over newer data. Its contents are now published to the buffer cache, the new image uploads from there, and the old image is freed. Upstream freed it without publishing.
  • Write order: when the request already has a newer image, the old image publishes first and the newer one last, so newer data wins where they overlap. If the newer image already has bytes waiting in the buffer cache, the old image isn't published at all.
  • Publishing isn't possible (for example a multisampled image): the cache logs it and frees the image, as upstream did.

Known limitations

  • Recently used images stay. An image used in the last 32 frames isn't retired, which matches upstream. Games that alternate layouts on one allocation (PPSA03541 alternates depth and colour) rely on this. If such an image was just written by the GPU, the new image uploads from guest memory, which doesn't have those writes yet. Before this PR the request reused the old image and read its levels from the wrong offsets.
  • Level and layer counts both differ. mip.size counts every layer, so if both counts differ the shared levels never match and the request gets its own image even when the per-layer placement is identical. This costs memory, not correctness. A temporary log found no such request in Octopath Traveler II, Astro Bot, LEGO Batman or Ratchet & Clank: Rift Apart.
  • 128-bit (r128) descriptors size the chain from LAST_LEVEL, because they have no MAX_MIP. A view with a shorter LAST_LEVEL than the real chain would now get its own image. A temporary log found no r128 textures at all in the same four games.

Testing

New UnifiedTextureCacheFlow cases in ShaderRecompilerComputeTests:

  • A one-level texture requested over a cached two-level linear chain gets its own image and reads its base level from the start of the allocation. The same request with an equal allocation size goes through the equal-backing fast path.
  • A one-level texture over a 9-level 64 KiB tiled chain gets its own image. Its first row reads the chain's mip tail block and level 1, not the chain's base level. This is the Octopath case with real tiled layouts.
  • An 8-level request over a 9-level tiled chain differs only inside the mip tail and reuses the cached image.
  • An idle, GPU-written two-level chain is retired through the buffer cache. The new texture sees the GPU-written data where the layouts overlap and guest memory elsewhere.
  • Two older GPU-written chains retired into a newer GPU-written image leave the newer contents in place.
  • A GPU-written image that can't be downloaded (multisampled) is still retired.
  • An idle, GPU-written linear image replaced by a tiled texture at the same address passes its contents to the new image.

Each new case was checked against a deliberately broken cache and fails without the code it covers. The full test suite passes except kernel_file_system, which fails the same way on main.

In-game, the Octopath Traveler II ground corruption is gone.

Partially fixes https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1617

**@⁠MrBigBritches** on GitHub · 2026-10-21 03:32 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781) `MrBigBritches:texture-mip-layout-fix` → `main` · +425 −10 · 3 files · 8 commits · open A texture usually comes with **mip levels**, smaller copies of itself (half size, quarter size and so on) that the GPU uses when the surface is far away. On the PS5 the whole chain is stored in one block of memory, **smallest level first**. So where the full-size level (the base level) sits depends on how many levels the texture has. A one-level texture keeps its base level at the start of the block. An eight-level texture at the same address keeps it after the seven smaller levels. Kyty caches each texture as a host image. When the game asked for a texture at an address the cache already had, Kyty only compared mip layouts when both had the same level count. A request with a different level count reused the cached image, so its base level was read from the wrong offset. Octopath Traveler II streams one-level ground textures into memory that an eight-level texture used before. A few minutes into a session, the paving outside the mansion showed window-shaped bright rectangles and dark patches. Half of each texture was right and the other half was whatever followed it in memory, and it changed from run to run. **Example - Ground textures** ![image](https://github.com/user-attachments/assets/8d9e91a0-d4f1-49ea-b8d6-4dda7bf73b37) ## Changes ### Compare mip placement whenever level counts differ - `ResolveOverlap` now compares the levels both layouts share whenever the level counts differ. Any difference makes the request a separate guest layout with its own image, as an equal-count mismatch already did. - A different layer count doesn't make mismatched levels compatible, so the check runs regardless of layer count. - `FindImage`'s equal-backing fast path runs the same check. It used to accept a cached image with more levels and the same allocation size (common with padded tiled layouts) before `ResolveOverlap` ran. - Levels that differ only inside the mip tail leave every shared level in place, so those requests still reuse the cached image. ### Retire the replaced image safely When a request becomes a separate image, the cached image it replaces still needs handling. This applies to every same-address mismatch. That includes a different level count, a different tile mode, or a different mip layout with the same level count. - **Image only mirrors guest memory:** an idle one is freed, as before. - **Image was written by the GPU and is idle:** freeing it would lose contents that were never downloaded, but keeping it alongside the new image is just as bad. Range lookups could pick it, and texture GC could later download its stale contents over newer data. Its contents are now published to the buffer cache, the new image uploads from there, and the old image is freed. Upstream freed it without publishing. - **Write order:** when the request already has a newer image, the old image publishes first and the newer one last, so newer data wins where they overlap. If the newer image already has bytes waiting in the buffer cache, the old image isn't published at all. - **Publishing isn't possible** (for example a multisampled image): the cache logs it and frees the image, as upstream did. ## Known limitations - **Recently used images stay.** An image used in the last 32 frames isn't retired, which matches upstream. Games that alternate layouts on one allocation (PPSA03541 alternates depth and colour) rely on this. If such an image was just written by the GPU, the new image uploads from guest memory, which doesn't have those writes yet. Before this PR the request reused the old image and read its levels from the wrong offsets. - **Level and layer counts both differ.** `mip.size` counts every layer, so if both counts differ the shared levels never match and the request gets its own image even when the per-layer placement is identical. This costs memory, not correctness. A temporary log found no such request in Octopath Traveler II, Astro Bot, LEGO Batman or Ratchet & Clank: Rift Apart. - **128-bit (`r128`) descriptors** size the chain from `LAST_LEVEL`, because they have no `MAX_MIP`. A view with a shorter `LAST_LEVEL` than the real chain would now get its own image. A temporary log found no `r128` textures at all in the same four games. ## Testing New `UnifiedTextureCacheFlow` cases in `ShaderRecompilerComputeTests`: - A one-level texture requested over a cached two-level linear chain gets its own image and reads its base level from the start of the allocation. The same request with an equal allocation size goes through the equal-backing fast path. - A one-level texture over a 9-level 64 KiB tiled chain gets its own image. Its first row reads the chain's mip tail block and level 1, not the chain's base level. This is the Octopath case with real tiled layouts. - An 8-level request over a 9-level tiled chain differs only inside the mip tail and reuses the cached image. - An idle, GPU-written two-level chain is retired through the buffer cache. The new texture sees the GPU-written data where the layouts overlap and guest memory elsewhere. - Two older GPU-written chains retired into a newer GPU-written image leave the newer contents in place. - A GPU-written image that can't be downloaded (multisampled) is still retired. - An idle, GPU-written linear image replaced by a tiled texture at the same address passes its contents to the new image. Each new case was checked against a deliberately broken cache and fails without the code it covers. The full test suite passes except `kernel_file_system`, which fails the same way on `main`. In-game, the Octopath Traveler II ground corruption is gone. Partially fixes [https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1617](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1617)
Guest mip chains run backwards (smaller levels first), so a texture with
fewer mip levels keeps its base level at a different offset than a
texture with a longer chain at the same address. When an equal-address
request differed from a cached image only in its level count,
ResolveOverlap skipped the mip-layout comparison and reused the cached
image, so the request's base level was read from the wrong offset.

Octopath Traveler II streams one-level ground textures into memory that
an eight-level texture had used. The ground then showed half of the
streamed texture and half of whatever followed it in memory, a few
minutes into a session and differently each run.

Compare the levels both layouts share and treat any difference as a
separate guest layout, as an equal-count mismatch already was.

Adds a UnifiedTextureCacheFlow case: a one-level texture requested at
the address of a cached two-level image must get its own image and read
its base level from the start of the allocation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-ups for the mip-layout fix:

- FindImage accepted a cached image through SameBacking before
  ResolveOverlap ran. SameBacking allows a cached image with more levels
  and the same allocation size (common with padded tiled layouts), so a
  shorter-chain request could still read its base level from the wrong
  offset. Require the shared levels to be placed identically when the
  level counts differ.
- When a layout mismatch turns the request into a separate image, an
  idle cached image was freed even if the GPU had written it, dropping
  contents that were never downloaded. Retire it only when it mirrors
  guest memory; texture GC downloads GPU-written images before freeing.
- The shared-level comparison now only applies when the level counts
  differ, so equal-count lookups behave as before.

The regression test also requests a one-level texture with the same
allocation size as the cached two-level image, which exercised the
SameBacking path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a request's mip placement differs from a cached image at the same
address, the request becomes a separate image. Compare shared levels
whatever the layer counts are: guest mip layouts are per layer, so a
different layer count does not make mismatched levels compatible.

An idle cached image that was GPU-written was kept so its contents would
not be dropped, but then it coexisted with the new image: range lookups
could pick it and texture GC could later download its stale contents
over newer data. Retire it the way BC aliases are retired instead:
publish its contents to the buffer cache, from which the new image
uploads, and free it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build the clear as a vk::ClearValue (no converting constructors), and
look the range up without ensure_valid: the new image is not GPU-written,
so the default lookup would skip it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The two-level chain keeps its 32-texel level 1 at offset 0, so a 64-texel
one-level texture over that row sees GPU-written data in its first half
and guest padding (preserved by the publish) in the second. The test
expected all 64 texels to hold the cleared value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The mip layout cases were linear with hand-built layouts. Add two cases
that use real UpdateSize() layouts of a 256x256 32-bit chain with
64 KiB tiling.

A one-level texture at the address of a 9-level tiled chain must get
its own image. Its first row reads the chain's mip tail block and
level 1, not the chain's base level. This is the Octopath Traveler II
ground texture case.

An 8-level request over a 9-level chain differs only inside the mip
tail. It must reuse the cached chain rather than create a second image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a request at the same address asks for another tile mode, the
cached image can't serve it. Upstream freed an idle cached image there,
which dropped anything the GPU had written to it. The branch now
publishes those contents to the buffer cache first, so the new image
starts from them.

Write a value into a linear 128x128 image on the GPU, leave it idle,
then request a 64 KiB tiled texture at the same address. The new image
must read the written value across the whole image, not the stale guest
memory, and the old image must be gone. At 128 texels both layouts have
the same pitch, so the request reaches the tile-mode check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ResolveOverlap asked ResolveDepthOverlap first, and that hands back a
cached depth image unchanged whenever it holds at least as many levels.
A depth request with a different level count could then get an image
whose shared levels sit somewhere else, the same bug this branch fixes
for color images.

Compute the shared-level check first. If the depth path would return the
cached image itself while the shared levels differ, fall through to the
separate-image branch instead. Its convert-and-copy result is kept, since
layered depth and color aliases rely on it.

Add a test where a one-level depth texture over a two-level depth chain
gets its own image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:05:33 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 03:38 UTC · original · edited 2026-10-27 22:24 UTC

Review in Change Stack →

Walkthrough

The texture cache compares shared mip placement when it resolves overlaps or reuses images with different mip counts. When an idle cached image has an incompatible tile mode or mip layout, RetireReplacedLayout conditionally publishes GPU-written contents, marks bindings for rediscovery, and frees the image. New tests cover linear and tiled mip chains, content preservation during retirement, and render-target base offsets when mip reuse is enabled.

Suggested reviewers: nmzik

Priority: Normal

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Moderate · up to 66675

Retiring an image with an incompatible layout can overwrite newer partial GPU buffer writes with older image contents. That could cause stale or corrupt data in uncommon alias scenarios. The mip-layout reuse fix itself looks sound, but this data-ordering gap should be resolved or explicitly accepted before merge.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… 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 names the main change: a shorter mip chain reusing a cached texture's memory caused corrupt textures, and the fix is in the texture cache. It matches the changeset, which compares mip placem…
Description check Passed The description is detailed and on-topic. It explains the mip-level placement problem in the texture cache, lists the changes to ResolveOverlap, FindImage and the image retirement path, and describes …
Linked Issues check Passed The only directly linked issue, #1617, is closed and completed. It supplies historical context only, so no active directly linked targets remain and no linked-issue coding requirements apply. The text…
Out of Scope Changes check Passed The whole-PR diff of textureCache.cpp is limited to texture cache behavior. It adds SameMipPlacement and SharedLevelsMatch helpers. It uses them in ResolveOverlap when level counts differ, and in the …
Full details: Title check

Explanation

The title names the main change: a shorter mip chain reusing a cached texture's memory caused corrupt textures, and the fix is in the texture cache. It matches the changeset, which compares mip placement in ResolveOverlap and FindImage and retires replaced images. The PPSA09809 game ID is extra detail but does not make the title inaccurate.

Full details: Description check

Explanation

The description is detailed and on-topic. It explains the mip-level placement problem in the texture cache, lists the changes to ResolveOverlap, FindImage and the image retirement path, and describes the new UnifiedTextureCacheFlow tests. It also states known limitations.

Full details: Linked Issues check

Explanation

The only directly linked issue, #1617, is closed and completed. It supplies historical context only, so no active directly linked targets remain and no linked-issue coding requirements apply. The texture cache changes in textureCache.cpp (whole-PR diff from merge base 0685bffb to head 66675fdb) address the mip-placement problem described in the current PR description. This is not a linked-issue requirement check.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff of textureCache.cpp is limited to texture cache behavior. It adds SameMipPlacement and SharedLevelsMatch helpers. It uses them in ResolveOverlap when level counts differ, and in the FindImage equal-backing fast path. It adds RetireReplacedLayout, which publishes or frees a replaced same-address image. It also adds a depth-overlap guard that returns the cached image only when shared levels match. textureCache.h adds one matching private declaration. The summary attributes the UnifiedTextureCacheFlow test additions in ShaderRecompilerComputeTests.cpp to these same paths. Each change connects directly to the mip-layout reuse defect in the PR description. No unrelated change is evidenced. The test file was assessed from the summary only, not by a line-level read.

Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 2 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • 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-21 03:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#issuecomment-6307433293) · edited 2026-10-27 22:24 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/1781?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 --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> The texture cache compares shared mip placement when it resolves overlaps or reuses images with different mip counts. When an idle cached image has an incompatible tile mode or mip layout, `RetireReplacedLayout` conditionally publishes GPU-written contents, marks bindings for rediscovery, and frees the image. New tests cover linear and tiled mip chains, content preservation during retirement, and render-target base offsets when mip reuse is enabled. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <strong>Priority: <picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/priority-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Normal</strong> <!-- change_assessment_commit:"66675fdb41b0dd1c8041e55d80ad4898a978fecc" --> **Change:** Bug fix · **Severity of issue fixed:** Low <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Moderate</strong> · up to <code>66675</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🟡 Moderate** · up to `66675` --> <!-- final_review_risk_coverage:{"sourceCommitId":"66675fdb41b0dd1c8041e55d80ad4898a978fecc","coveredCommitId":"66675fdb41b0dd1c8041e55d80ad4898a978fecc","kind":"reviewed"} --> Retiring an image with an incompatible layout can overwrite newer partial GPU buffer writes with older image contents. That could cause stale or corrupt data in uncommon alias scenarios. The mip-layout reuse fix itself looks sound, but this data-ordering gap should be resolved or explicitly accepted before merge. <!-- 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 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… | 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 names the main change: a shorter mip chain reusing a cached texture's memory caused corrupt textures, and the fix is in the texture cache. It matches the changeset, which compares mip placem… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description is detailed and on-topic. It explains the mip-level placement problem in the texture cache, lists the changes to ResolveOverlap, FindImage and the image retirement path, and describes … | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The only directly linked issue, `#1617`, is closed and completed. It supplies historical context only, so no active directly linked targets remain and no linked-issue coding requirements apply. The text… | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The whole-PR diff of textureCache.cpp is limited to texture cache behavior. It adds SameMipPlacement and SharedLevelsMatch helpers. It uses them in ResolveOverlap when level counts differ, and in the … | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> **Explanation** The title names the main change: a shorter mip chain reusing a cached texture's memory caused corrupt textures, and the fix is in the texture cache. It matches the changeset, which compares mip placement in ResolveOverlap and FindImage and retires replaced images. The PPSA09809 game ID is extra detail but does not make the title inaccurate. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> **Explanation** The description is detailed and on-topic. It explains the mip-level placement problem in the texture cache, lists the changes to ResolveOverlap, FindImage and the image retirement path, and describes the new UnifiedTextureCacheFlow tests. It also states known limitations. </dd> </dl> </details> <details> <summary><strong>Full details: Linked Issues check</strong></summary> <dl> <dd> **Explanation** The only directly linked issue, `#1617`, is closed and completed. It supplies historical context only, so no active directly linked targets remain and no linked-issue coding requirements apply. The texture cache changes in textureCache.cpp (whole-PR diff from merge base 0685bffb to head 66675fdb) address the mip-placement problem described in the current PR description. This is not a linked-issue requirement check. </dd> </dl> </details> <details> <summary><strong>Full details: Out of Scope Changes check</strong></summary> <dl> <dd> **Explanation** The whole-PR diff of textureCache.cpp is limited to texture cache behavior. It adds SameMipPlacement and SharedLevelsMatch helpers. It uses them in ResolveOverlap when level counts differ, and in the FindImage equal-backing fast path. It adds RetireReplacedLayout, which publishes or frees a replaced same-address image. It also adds a depth-overlap guard that returns the cached image only when shared levels match. textureCache.h adds one matching private declaration. The summary attributes the UnifiedTextureCacheFlow test additions in ShaderRecompilerComputeTests.cpp to these same paths. Each change connects directly to the mip-layout reuse defect in the PR description. No unrelated change is evidenced. The test file was assessed from the summary only, not by a line-level read. </dd> </dl> </details> </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 2 files. (1 skipped: 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </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=1781)! 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 -->
@ -820,2 +870,2 @@
left.surface_z == right.surface_z;
}))) {
cached.info.mip_layout.begin(), SameMipPlacement)) ||
shared_levels_differ) {
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 03:38 UTC · original · edited 2026-10-21 05:54 UTC

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve GPU-owned contents when rejecting an aged image.

If this new mismatch rejects a cached image more than 32 ticks after its last access, the existing safe_to_delete branch calls FreeImage. For a GPU-modified image, FreeImage clears the modification and deletes the image without downloading its contents. Retain or synchronize that image before retirement so a later read does not lose the GPU write.

✅ Addressed in commit 710da85

**@⁠coderabbitai[bot]** on GitHub · 2026-10-21 03:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#discussion_r4332793907) · edited 2026-10-21 05:54 UTC <!-- coderabbit-ai-generated:v1 --> **🗄️ Data Integrity & Integration** | **🟠 Major** | **🏗️ Heavy lift** **Preserve GPU-owned contents when rejecting an aged image.** If this new mismatch rejects a cached image more than 32 ticks after its last access, the existing `safe_to_delete` branch calls `FreeImage`. For a GPU-modified image, `FreeImage` clears the modification and deletes the image without downloading its contents. Retain or synchronize that image before retirement so a later read does not lose the GPU write. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:0198d3adf7a3530157edb0e7 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 710da85
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 03:38 UTC · original · reviewed

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Check mip layout before accepting SameBacking. · textureCache.cpp:1225

src/graphics/host_gpu/renderer/cache/textureCache.cpp:1225
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Check mip layout before accepting SameBacking.

FindImage accepts a SameBacking match before it calls ResolveOverlap. SameBacking does not compare mip layout. A valid descriptor can preserve an explicit allocation size while UpdateSize assigns different mip offsets. The cached two-level image can therefore match a one-level request by address and size, then serve the request from the cached base offset instead of offset zero.

Apply the shared-mip comparison to this fast path.

Suggested fix
 		bool block_alias = false;
+		const auto same_mip = [](const ImageMipInfo& left, const ImageMipInfo& right) {
+			return left.offset == right.offset && left.size == right.size &&
+			       left.pitch == right.pitch && left.height == right.height &&
+			       left.tail_x == right.tail_x && left.tail_y == right.tail_y &&
+			       left.surface_z == right.surface_z;
+		};
 
 		for (const auto id: candidates) {
 			const auto& image = m_slot_images[id];
@@
-			if (SameBacking(image.info, desc.info, exact_format)) {
+			if (SameBacking(image.info, desc.info, exact_format) &&
+			    (image.info.resources.layers != desc.info.resources.layers ||
+			     std::equal(desc.info.mip_layout.begin(),
+			                desc.info.mip_layout.begin() + desc.info.resources.levels,
+			                image.info.mip_layout.begin(), same_mip))) {
 				result = id;

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f313f0b0-caae-4abf-b2a5-c34a5e08ff48
📥 Commits

Reviewing files that changed from the base of the PR and between 7b7f9a70c6 and 29519f0b47a0c63af492b3d8612a728dc3eb75d8.

📒 Files selected for processing: 2
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • 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-21 03:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#pullrequestreview-5594684361) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong>🟠 Major</strong> · Check mip layout before accepting <code>SameBacking</code>. · <code>textureCache.cpp:1225</code></summary><blockquote> > > `src/graphics/host_gpu/renderer/cache/textureCache.cpp:1225` > **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** > > **Check mip layout before accepting `SameBacking`.** > > `FindImage` accepts a `SameBacking` match before it calls `ResolveOverlap`. `SameBacking` does not compare mip layout. A valid descriptor can preserve an explicit allocation size while `UpdateSize` assigns different mip offsets. The cached two-level image can therefore match a one-level request by address and size, then serve the request from the cached base offset instead of offset zero. > > Apply the shared-mip comparison to this fast path. > > <details> > <summary>Suggested fix</summary> > > ```diff > bool block_alias = false; > + const auto same_mip = [](const ImageMipInfo& left, const ImageMipInfo& right) { > + return left.offset == right.offset && left.size == right.size && > + left.pitch == right.pitch && left.height == right.height && > + left.tail_x == right.tail_x && left.tail_y == right.tail_y && > + left.surface_z == right.surface_z; > + }; > > for (const auto id: candidates) { > const auto& image = m_slot_images[id]; > @@ > - if (SameBacking(image.info, desc.info, exact_format)) { > + if (SameBacking(image.info, desc.info, exact_format) && > + (image.info.resources.layers != desc.info.resources.layers || > + std::equal(desc.info.mip_layout.begin(), > + desc.info.mip_layout.begin() + desc.info.resources.levels, > + image.info.mip_layout.begin(), same_mip))) { > result = id; > ``` > > </details> > > <!-- cr-comment:v1:a372280dff5300a8d694de1b --> > > </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `f313f0b0-caae-4abf-b2a5-c34a5e08ff48` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 7b7f9a70c652afd6ec8ea8599884d9b4b3abc9f3 and 29519f0b47a0c63af492b3d8612a728dc3eb75d8. </details> <details> <summary>📒 Files selected for processing: 2</summary> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `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=d6a3299e-17da-4a48-80e3-fbf70862195b attempt=7138140d-5b59-4563-81d3-2fb4995b332a batch=1/1 -->
Author
Owner

@⁠MrBigBritches on GitHub · 2026-10-21 05:54 UTC · original

Both addressed in 710da851. FindImage’s SameBacking fast path now also requires the shared mip levels to be placed identically when the level counts differ (the regression test covers the equal-size case). A cached image rejected for a layout mismatch is only freed when it isn’t GPU-modified; GPU-written images are left for texture GC, which downloads before freeing.

**@⁠MrBigBritches** on GitHub · 2026-10-21 05:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#issuecomment-6309133608) Both addressed in 710da851. FindImage’s SameBacking fast path now also requires the shared mip levels to be placed identically when the level counts differ (the regression test covers the equal-size case). A cached image rejected for a layout mismatch is only freed when it isn’t GPU-modified; GPU-written images are left for texture GC, which downloads before freeing.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 06:00 UTC · original · edited 2026-10-21 06:26 UTC
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 819 (outdated):

@@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
 		}
 		// Equal pitch does not imply equal mip placement: a changed extent can move
 		// a level into or out of the mip tail. These are separate guest layouts.
+		// The mip count matters too: if any level both layouts have is placed differently, the
+		// cached image cannot serve the request.
+		const bool shared_levels_differ =
+		    requested.resources.levels != cached.info.resources.levels &&
+		    requested.resources.layers == cached.info.resources.layers &&
+		    !SharedLevelsMatch(requested, cached.info);

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '30,60p;795,860p;1215,1250p' src/graphics/host_gpu/renderer/cache/textureCache.cpp

Repository: KytyPS5/KytyPS5

Length of output: 6639


🏁 Script executed:

set -eu
printf '%s\n' '--- merge-base ResolveOverlap region ---'
git show 7b7f9a70c652afd6ec8ea8599884d9b4b3abc9f3:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '790,855p'
printf '%s\n' '--- reviewed-head ResolveOverlap region ---'
git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '800,855p'
printf '%s\n' '--- relevant definitions and callers in reviewed head ---'
rg -n -F -- 'ResolveOverlap(' 'SameBacking(' 'SharedLevelsMatch(' 'FindImageFromRange(' src/graphics/host_gpu/renderer/cache/textureCache.cpp
git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '1040,1135p'

Repository: KytyPS5/KytyPS5

Length of output: 8099


🏁 Script executed:

set -eu
for rev in 7b7f9a70c652afd6ec8ea8599884d9b4b3abc9f3 710da85162bfd595719a24e26a9aada59d8563b1; do
  echo "--- $rev ResolveOverlap 852-940 ---"
  git show "$rev:src/graphics/host_gpu/renderer/cache/textureCache.cpp" | nl -ba | sed -n '852,940p'
done
echo '--- current matching symbols ---'
rg -n -F -- 'SameBacking' src/graphics/host_gpu/renderer/cache
rg -n -F -- 'SharedLevelsMatch' src/graphics/host_gpu/renderer/cache
rg -n -F -- 'FindImage' src/graphics/host_gpu/renderer/cache/textureCache.cpp
echo '--- current FindImage owner block ---'
git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '1180,1265p'

Repository: KytyPS5/KytyPS5

Length of output: 15054


🏁 Script executed:

set -eu
echo '--- reviewed-head SameBacking and nearby helpers ---'
git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '130,185p'
echo '--- reviewed-head FindImagesInRegion ---'
git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '400,465p'
echo '--- reviewed-head ResolveOverlap entry ---'
git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '730,810p'

Repository: KytyPS5/KytyPS5

Length of output: 8975


Compare shared mip placement when layer counts differ.

ResolveOverlap skips SharedLevelsMatch when mip counts differ and layer counts differ. SameBacking allows a cached image with equal-or-greater layer and mip counts, and the later fallback can return that image when the request is smaller. The old code also compared full mip layouts only when all resource counts matched.

Remove the layer-count condition:

Suggested fix
--- "a/src/graphics/host_gpu/renderer/cache/textureCache.cpp"
+++ "b/src/graphics/host_gpu/renderer/cache/textureCache.cpp"
@@ -813,10 +813,9 @@
 		// a level into or out of the mip tail. These are separate guest layouts.
 		// The mip count matters too: if any level both layouts have is placed differently, the
 		// cached image cannot serve the request.
 		const bool shared_levels_differ =
 		    requested.resources.levels != cached.info.resources.levels &&
-		    requested.resources.layers == cached.info.resources.layers &&
 		    !SharedLevelsMatch(requested, cached.info);
 		if (requested.tile_mode != cached.info.tile_mode ||
 		    (requested.resources == cached.info.resources &&
 		     !std::equal(requested.mip_layout.begin(), requested.mip_layout.end(),

✅ Addressed in commit 3a48875

**@⁠coderabbitai[bot]** on GitHub · 2026-10-21 06:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#discussion_r4333521700) · edited 2026-10-21 06:26 UTC On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 819 (outdated): ```diff @@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } // Equal pitch does not imply equal mip placement: a changed extent can move // a level into or out of the mip tail. These are separate guest layouts. + // The mip count matters too: if any level both layouts have is placed differently, the + // cached image cannot serve the request. + const bool shared_levels_differ = + requested.resources.levels != cached.info.resources.levels && + requested.resources.layers == cached.info.resources.layers && + !SharedLevelsMatch(requested, cached.info); ``` <!-- coderabbit-ai-generated:v1 --> **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '30,60p;795,860p;1215,1250p' src/graphics/host_gpu/renderer/cache/textureCache.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 6639 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- merge-base ResolveOverlap region ---' git show 7b7f9a70c652afd6ec8ea8599884d9b4b3abc9f3:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '790,855p' printf '%s\n' '--- reviewed-head ResolveOverlap region ---' git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '800,855p' printf '%s\n' '--- relevant definitions and callers in reviewed head ---' rg -n -F -- 'ResolveOverlap(' 'SameBacking(' 'SharedLevelsMatch(' 'FindImageFromRange(' src/graphics/host_gpu/renderer/cache/textureCache.cpp git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '1040,1135p' ``` Repository: KytyPS5/KytyPS5 Length of output: 8099 --- 🏁 Script executed: ```bash set -eu for rev in 7b7f9a70c652afd6ec8ea8599884d9b4b3abc9f3 710da85162bfd595719a24e26a9aada59d8563b1; do echo "--- $rev ResolveOverlap 852-940 ---" git show "$rev:src/graphics/host_gpu/renderer/cache/textureCache.cpp" | nl -ba | sed -n '852,940p' done echo '--- current matching symbols ---' rg -n -F -- 'SameBacking' src/graphics/host_gpu/renderer/cache rg -n -F -- 'SharedLevelsMatch' src/graphics/host_gpu/renderer/cache rg -n -F -- 'FindImage' src/graphics/host_gpu/renderer/cache/textureCache.cpp echo '--- current FindImage owner block ---' git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '1180,1265p' ``` Repository: KytyPS5/KytyPS5 Length of output: 15054 --- 🏁 Script executed: ```bash set -eu echo '--- reviewed-head SameBacking and nearby helpers ---' git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '130,185p' echo '--- reviewed-head FindImagesInRegion ---' git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '400,465p' echo '--- reviewed-head ResolveOverlap entry ---' git show 710da85162bfd595719a24e26a9aada59d8563b1:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '730,810p' ``` Repository: KytyPS5/KytyPS5 Length of output: 8975 --- </details> **Compare shared mip placement when layer counts differ.** `ResolveOverlap` skips `SharedLevelsMatch` when mip counts differ and layer counts differ. `SameBacking` allows a cached image with equal-or-greater layer and mip counts, and the later fallback can return that image when the request is smaller. The old code also compared full mip layouts only when all resource counts matched. Remove the layer-count condition: <details> <summary>Suggested fix</summary> ```diff --- "a/src/graphics/host_gpu/renderer/cache/textureCache.cpp" +++ "b/src/graphics/host_gpu/renderer/cache/textureCache.cpp" @@ -813,10 +813,9 @@ // a level into or out of the mip tail. These are separate guest layouts. // The mip count matters too: if any level both layouts have is placed differently, the // cached image cannot serve the request. const bool shared_levels_differ = requested.resources.levels != cached.info.resources.levels && - requested.resources.layers == cached.info.resources.layers && !SharedLevelsMatch(requested, cached.info); if (requested.tile_mode != cached.info.tile_mode || (requested.resources == cached.info.resources && !std::equal(requested.mip_layout.begin(), requested.mip_layout.end(), ``` </details> <!-- fingerprinting:phantom:medusa:beignet55 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:25ef642b21c668602993698d --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 3a48875
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 06:00 UTC · original · edited 2026-10-21 06:29 UTC
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 827 (outdated):

@@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
 		}
 		// Equal pitch does not imply equal mip placement: a changed extent can move
 		// a level into or out of the mip tail. These are separate guest layouts.
+		// The mip count matters too: if any level both layouts have is placed differently, the
+		// cached image cannot serve the request.
+		const bool shared_levels_differ =
+		    requested.resources.levels != cached.info.resources.levels &&
+		    requested.resources.layers == cached.info.resources.layers &&
+		    !SharedLevelsMatch(requested, cached.info);
 		if (requested.tile_mode != cached.info.tile_mode ||
 		    (requested.resources == cached.info.resources &&
 		     !std::equal(requested.mip_layout.begin(), requested.mip_layout.end(),
-		                 cached.info.mip_layout.begin(),
-		                 [](const ImageMipInfo& left, const ImageMipInfo& right) {
-			                 return left.offset == right.offset && left.size == right.size &&
-			                        left.pitch == right.pitch && left.height == right.height &&
-			                        left.tail_x == right.tail_x && left.tail_y == right.tail_y &&
-			                        left.surface_z == right.surface_z;
-		                 }))) {
-			if (safe_to_delete) {
+		                 cached.info.mip_layout.begin(), SameMipPlacement)) ||
+		    shared_levels_differ) {
+			// The request becomes a separate image. Retire an idle cached image only when it
+			// mirrors guest memory; GPU-written contents stay until texture GC downloads them.
+			if (safe_to_delete && !cached.IsGpuModified()) {

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

rg -n 'FindImageFromRange|SynchronizeBufferFromImage|IsGpuModified' src/graphics/host_gpu/renderer

Repository: KytyPS5/KytyPS5

Length of output: 2397


🏁 Script executed:

set -o pipefail
for range in \
  '230,315' \
  '390,435' \
  '580,645' \
  '780,850' \
  '1260,1365' \
  '1705,1775' \
  '1795,1850' \
  '1925,2005' \
  '440,475' \
  '560,605'; do
  echo "===== src/graphics/host_gpu/renderer/cache/textureCache.cpp:${range} ====="
  nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n "${range}p"
done
echo "===== src/graphics/host_gpu/renderer/cache/bufferCache.cpp:440-475 ====="
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '440,475p'
echo "===== declarations and relevant callers ====="
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.h | sed -n '35,75p'
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.h | sed -n '105,135p'
rg -n -F --glob '*.{cpp,h}' -e 'ResolveOverlap(' -e 'FindImageFromRange(' -e 'RegisterImage' -e 'UnregisterImage' -e 'SetGpuModified' src/graphics/host_gpu/renderer

Repository: KytyPS5/KytyPS5

Length of output: 37167


🏁 Script executed:

set -o pipefail
for range in '230,315' '390,435' '580,645' '780,850' '1260,1365' '1705,1775' '1795,1850' '1925,2005' '440,475' '560,605'; do
  echo "===== src/graphics/host_gpu/renderer/cache/textureCache.cpp:${range} ====="
  nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n "${range}p"
done
echo "===== src/graphics/host_gpu/renderer/cache/bufferCache.cpp:440-475 ====="
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '440,475p'
echo "===== declarations and relevant callers ====="
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.h | sed -n '35,75p'
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.h | sed -n '105,135p'
rg -n -F --glob '*.{cpp,h}' -e 'ResolveOverlap(' -e 'FindImageFromRange(' -e 'RegisterImage' -e 'UnregisterImage' -e 'SetGpuModified' src/graphics/host_gpu/renderer

Repository: KytyPS5/KytyPS5

Length of output: 37167


🏁 Script executed:

set -o pipefail
echo "===== textureCache.cpp:145-235 ====="
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '145,235p'
echo "===== textureCache.cpp:1160-1295 ====="
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '1160,1295p'
echo "===== textureCache.cpp:1768-1794 ====="
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '1768,1794p'
echo "===== image.h:88-122 ====="
nl -ba src/graphics/host_gpu/renderer/image/image.h | sed -n '88,122p'
echo "===== ImagePageTable and owner container definitions ====="
rg -n -F --glob '*.{cpp,h}' -e 'class ImagePageTable' -e 'struct ImagePageTable' -e 'using ImagePageTable' -e 'class.*PageTable' -e 'ForEach(' src/graphics/host_gpu/renderer src/common
echo "===== page-owner implementation candidates ====="
rg -n -F --glob '*.{cpp,h}' -e 'm_image_page_table' -e 'MultiLevelPageTable' src/graphics/host_gpu/renderer

Repository: KytyPS5/KytyPS5

Length of output: 14569


🏁 Script executed:

set -o pipefail
echo "===== textureCache.h:85-105 ====="
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.h | sed -n '85,105p'
echo "===== multiLevelPageTable.h:1-85 and 210-245 ====="
nl -ba src/graphics/host_gpu/renderer/cache/multiLevelPageTable.h | sed -n '1,85p'
nl -ba src/graphics/host_gpu/renderer/cache/multiLevelPageTable.h | sed -n '210,245p'
echo "===== ImageIds definition and GPU-write call sites ====="
rg -n -F --glob '*.{cpp,h}' -e 'using ImageIds' -e 'MarkGpuWritten' -e 'MarkGpuModified' src/graphics/host_gpu/renderer
echo "===== overlap cleanup calls ====="
rg -n -F --glob 'src/graphics/host_gpu/renderer/cache/textureCache.cpp' -e 'FreeImage(' -e 'DeleteImage(' -e 'UnregisterImage(' -e 'MarkCpuDirty(' -e 'MarkBufferModified('

Repository: KytyPS5/KytyPS5

Length of output: 9247


🏁 Script executed:

set -o pipefail
echo "===== InlinePageOwnerList implementation ====="
nl -ba src/graphics/host_gpu/renderer/cache/multiLevelPageTable.h | sed -n '95,225p'
echo "===== MarkGpuWritten and adjacent GPU state paths ====="
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '1358,1482p'
echo "===== other ResolveOverlap cleanup branches ====="
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '850,945p'

Repository: KytyPS5/KytyPS5

Length of output: 16130


Keep the retained older image out of range-based synchronization.

When ResolveOverlap rejects a layout mismatch, the branch keeps a GPU-modified cached image registered. A later GPU write can mark the new equal-range image GPU-modified as well. FindImageFromRange can then select the older image first and BufferCache::SynchronizeBufferFromImage can download stale contents.

Keep the older image available for safe readback, but make range lookup select the newer safe equal-range image after it becomes GPU-written. Do not delete the older GPU-modified image before its contents are preserved.

✅ Addressed in commit 3a48875

**@⁠coderabbitai[bot]** on GitHub · 2026-10-21 06:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#discussion_r4333521703) · edited 2026-10-21 06:29 UTC On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 827 (outdated): ```diff @@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } // Equal pitch does not imply equal mip placement: a changed extent can move // a level into or out of the mip tail. These are separate guest layouts. + // The mip count matters too: if any level both layouts have is placed differently, the + // cached image cannot serve the request. + const bool shared_levels_differ = + requested.resources.levels != cached.info.resources.levels && + requested.resources.layers == cached.info.resources.layers && + !SharedLevelsMatch(requested, cached.info); if (requested.tile_mode != cached.info.tile_mode || (requested.resources == cached.info.resources && !std::equal(requested.mip_layout.begin(), requested.mip_layout.end(), - cached.info.mip_layout.begin(), - [](const ImageMipInfo& left, const ImageMipInfo& right) { - return left.offset == right.offset && left.size == right.size && - left.pitch == right.pitch && left.height == right.height && - left.tail_x == right.tail_x && left.tail_y == right.tail_y && - left.surface_z == right.surface_z; - }))) { - if (safe_to_delete) { + cached.info.mip_layout.begin(), SameMipPlacement)) || + shared_levels_differ) { + // The request becomes a separate image. Retire an idle cached image only when it + // mirrors guest memory; GPU-written contents stay until texture GC downloads them. + if (safe_to_delete && !cached.IsGpuModified()) { ``` <!-- coderabbit-ai-generated:v1 --> **🗄️ Data Integrity & Integration** | **🟠 Major** | **🏗️ Heavy lift** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash rg -n 'FindImageFromRange|SynchronizeBufferFromImage|IsGpuModified' src/graphics/host_gpu/renderer ``` Repository: KytyPS5/KytyPS5 Length of output: 2397 --- 🏁 Script executed: ```bash set -o pipefail for range in \ '230,315' \ '390,435' \ '580,645' \ '780,850' \ '1260,1365' \ '1705,1775' \ '1795,1850' \ '1925,2005' \ '440,475' \ '560,605'; do echo "===== src/graphics/host_gpu/renderer/cache/textureCache.cpp:${range} =====" nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n "${range}p" done echo "===== src/graphics/host_gpu/renderer/cache/bufferCache.cpp:440-475 =====" nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '440,475p' echo "===== declarations and relevant callers =====" nl -ba src/graphics/host_gpu/renderer/cache/textureCache.h | sed -n '35,75p' nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.h | sed -n '105,135p' rg -n -F --glob '*.{cpp,h}' -e 'ResolveOverlap(' -e 'FindImageFromRange(' -e 'RegisterImage' -e 'UnregisterImage' -e 'SetGpuModified' src/graphics/host_gpu/renderer ``` Repository: KytyPS5/KytyPS5 Length of output: 37167 --- 🏁 Script executed: ```bash set -o pipefail for range in '230,315' '390,435' '580,645' '780,850' '1260,1365' '1705,1775' '1795,1850' '1925,2005' '440,475' '560,605'; do echo "===== src/graphics/host_gpu/renderer/cache/textureCache.cpp:${range} =====" nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n "${range}p" done echo "===== src/graphics/host_gpu/renderer/cache/bufferCache.cpp:440-475 =====" nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '440,475p' echo "===== declarations and relevant callers =====" nl -ba src/graphics/host_gpu/renderer/cache/textureCache.h | sed -n '35,75p' nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.h | sed -n '105,135p' rg -n -F --glob '*.{cpp,h}' -e 'ResolveOverlap(' -e 'FindImageFromRange(' -e 'RegisterImage' -e 'UnregisterImage' -e 'SetGpuModified' src/graphics/host_gpu/renderer ``` Repository: KytyPS5/KytyPS5 Length of output: 37167 --- 🏁 Script executed: ```bash set -o pipefail echo "===== textureCache.cpp:145-235 =====" nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '145,235p' echo "===== textureCache.cpp:1160-1295 =====" nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '1160,1295p' echo "===== textureCache.cpp:1768-1794 =====" nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '1768,1794p' echo "===== image.h:88-122 =====" nl -ba src/graphics/host_gpu/renderer/image/image.h | sed -n '88,122p' echo "===== ImagePageTable and owner container definitions =====" rg -n -F --glob '*.{cpp,h}' -e 'class ImagePageTable' -e 'struct ImagePageTable' -e 'using ImagePageTable' -e 'class.*PageTable' -e 'ForEach(' src/graphics/host_gpu/renderer src/common echo "===== page-owner implementation candidates =====" rg -n -F --glob '*.{cpp,h}' -e 'm_image_page_table' -e 'MultiLevelPageTable' src/graphics/host_gpu/renderer ``` Repository: KytyPS5/KytyPS5 Length of output: 14569 --- 🏁 Script executed: ```bash set -o pipefail echo "===== textureCache.h:85-105 =====" nl -ba src/graphics/host_gpu/renderer/cache/textureCache.h | sed -n '85,105p' echo "===== multiLevelPageTable.h:1-85 and 210-245 =====" nl -ba src/graphics/host_gpu/renderer/cache/multiLevelPageTable.h | sed -n '1,85p' nl -ba src/graphics/host_gpu/renderer/cache/multiLevelPageTable.h | sed -n '210,245p' echo "===== ImageIds definition and GPU-write call sites =====" rg -n -F --glob '*.{cpp,h}' -e 'using ImageIds' -e 'MarkGpuWritten' -e 'MarkGpuModified' src/graphics/host_gpu/renderer echo "===== overlap cleanup calls =====" rg -n -F --glob 'src/graphics/host_gpu/renderer/cache/textureCache.cpp' -e 'FreeImage(' -e 'DeleteImage(' -e 'UnregisterImage(' -e 'MarkCpuDirty(' -e 'MarkBufferModified(' ``` Repository: KytyPS5/KytyPS5 Length of output: 9247 --- 🏁 Script executed: ```bash set -o pipefail echo "===== InlinePageOwnerList implementation =====" nl -ba src/graphics/host_gpu/renderer/cache/multiLevelPageTable.h | sed -n '95,225p' echo "===== MarkGpuWritten and adjacent GPU state paths =====" nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '1358,1482p' echo "===== other ResolveOverlap cleanup branches =====" nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '850,945p' ``` Repository: KytyPS5/KytyPS5 Length of output: 16130 --- </details> **Keep the retained older image out of range-based synchronization.** When `ResolveOverlap` rejects a layout mismatch, the branch keeps a GPU-modified cached image registered. A later GPU write can mark the new equal-range image GPU-modified as well. `FindImageFromRange` can then select the older image first and `BufferCache::SynchronizeBufferFromImage` can download stale contents. Keep the older image available for safe readback, but make range lookup select the newer safe equal-range image after it becomes GPU-written. Do not delete the older GPU-modified image before its contents are preserved. <!-- fingerprinting:phantom:medusa:beignet55 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:2a4cbc51b5f65c87922955d0 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 3a48875
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 06:00 UTC · original · reviewed

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b163a784-328b-451a-b75a-54aefc76eb5a
📥 Commits

Reviewing files that changed from the base of the PR and between 29519f0b47a0c63af492b3d8612a728dc3eb75d8 and 710da85162bfd595719a24e26a9aada59d8563b1.

📒 Files selected for processing: 2
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • 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-21 06:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#pullrequestreview-5595538375) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 2** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `b163a784-328b-451a-b75a-54aefc76eb5a` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 29519f0b47a0c63af492b3d8612a728dc3eb75d8 and 710da85162bfd595719a24e26a9aada59d8563b1. </details> <details> <summary>📒 Files selected for processing: 2</summary> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `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=8b188a1a-b089-4c9f-9c05-2287db143e65 attempt=dacfeea8-0a39-4ded-ba2e-909f9b256c1b batch=1/1 -->
Author
Owner

@⁠MrBigBritches on GitHub · 2026-10-21 06:17 UTC · original
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 819 (outdated):

@@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
 		}
 		// Equal pitch does not imply equal mip placement: a changed extent can move
 		// a level into or out of the mip tail. These are separate guest layouts.
+		// The mip count matters too: if any level both layouts have is placed differently, the
+		// cached image cannot serve the request.
+		const bool shared_levels_differ =
+		    requested.resources.levels != cached.info.resources.levels &&
+		    requested.resources.layers == cached.info.resources.layers &&
+		    !SharedLevelsMatch(requested, cached.info);

Layer counts: Agreed. mip_layout describes placement within a single layer, so the layer count doesn’t affect whether shared levels line up. I dropped the layer-count condition in 3a48875b.

**@⁠MrBigBritches** on GitHub · 2026-10-21 06:17 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#discussion_r4333626150) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 819 (outdated): ```diff @@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } // Equal pitch does not imply equal mip placement: a changed extent can move // a level into or out of the mip tail. These are separate guest layouts. + // The mip count matters too: if any level both layouts have is placed differently, the + // cached image cannot serve the request. + const bool shared_levels_differ = + requested.resources.levels != cached.info.resources.levels && + requested.resources.layers == cached.info.resources.layers && + !SharedLevelsMatch(requested, cached.info); ``` Layer counts: Agreed. mip_layout describes placement within a single layer, so the layer count doesn’t affect whether shared levels line up. I dropped the layer-count condition in 3a48875b.
Author
Owner

@⁠MrBigBritches on GitHub · 2026-10-21 06:17 UTC · original
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 827 (outdated):

@@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
 		}
 		// Equal pitch does not imply equal mip placement: a changed extent can move
 		// a level into or out of the mip tail. These are separate guest layouts.
+		// The mip count matters too: if any level both layouts have is placed differently, the
+		// cached image cannot serve the request.
+		const bool shared_levels_differ =
+		    requested.resources.levels != cached.info.resources.levels &&
+		    requested.resources.layers == cached.info.resources.layers &&
+		    !SharedLevelsMatch(requested, cached.info);
 		if (requested.tile_mode != cached.info.tile_mode ||
 		    (requested.resources == cached.info.resources &&
 		     !std::equal(requested.mip_layout.begin(), requested.mip_layout.end(),
-		                 cached.info.mip_layout.begin(),
-		                 [](const ImageMipInfo& left, const ImageMipInfo& right) {
-			                 return left.offset == right.offset && left.size == right.size &&
-			                        left.pitch == right.pitch && left.height == right.height &&
-			                        left.tail_x == right.tail_x && left.tail_y == right.tail_y &&
-			                        left.surface_z == right.surface_z;
-		                 }))) {
-			if (safe_to_delete) {
+		                 cached.info.mip_layout.begin(), SameMipPlacement)) ||
+		    shared_levels_differ) {
+			// The request becomes a separate image. Retire an idle cached image only when it
+			// mirrors guest memory; GPU-written contents stay until texture GC downloads them.
+			if (safe_to_delete && !cached.IsGpuModified()) {

Retained image: Good catch. Keeping the GPU-modified image avoided losing its writes but left a second image over the same range. In 3a48875b the idle cached image is retired the same way as a BC alias conflict (BcAlias::Resolve): it is published to the buffer cache first, the new image uploads from there, and then it’s freed. A new test covers this: an idle GPU-cleared chain replaced by a one-level texture is retired, FindImageFromRange returns the new image, and that image reads the GPU-written data. Images used in the last 32 frames still coexist with the new one, as they did before this PR. Retiring those every time would churn when a title alternates between views.

**@⁠MrBigBritches** on GitHub · 2026-10-21 06:17 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#discussion_r4333626992) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 827 (outdated): ```diff @@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } // Equal pitch does not imply equal mip placement: a changed extent can move // a level into or out of the mip tail. These are separate guest layouts. + // The mip count matters too: if any level both layouts have is placed differently, the + // cached image cannot serve the request. + const bool shared_levels_differ = + requested.resources.levels != cached.info.resources.levels && + requested.resources.layers == cached.info.resources.layers && + !SharedLevelsMatch(requested, cached.info); if (requested.tile_mode != cached.info.tile_mode || (requested.resources == cached.info.resources && !std::equal(requested.mip_layout.begin(), requested.mip_layout.end(), - cached.info.mip_layout.begin(), - [](const ImageMipInfo& left, const ImageMipInfo& right) { - return left.offset == right.offset && left.size == right.size && - left.pitch == right.pitch && left.height == right.height && - left.tail_x == right.tail_x && left.tail_y == right.tail_y && - left.surface_z == right.surface_z; - }))) { - if (safe_to_delete) { + cached.info.mip_layout.begin(), SameMipPlacement)) || + shared_levels_differ) { + // The request becomes a separate image. Retire an idle cached image only when it + // mirrors guest memory; GPU-written contents stay until texture GC downloads them. + if (safe_to_delete && !cached.IsGpuModified()) { ``` Retained image: Good catch. Keeping the GPU-modified image avoided losing its writes but left a second image over the same range. In 3a48875b the idle cached image is retired the same way as a BC alias conflict (BcAlias::Resolve): it is published to the buffer cache first, the new image uploads from there, and then it’s freed. A new test covers this: an idle GPU-cleared chain replaced by a one-level texture is retired, FindImageFromRange returns the new image, and that image reads the GPU-written data. Images used in the last 32 frames still coexist with the new one, as they did before this PR. Retiring those every time would churn when a title alternates between views.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 06:26 UTC · original
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 819 (outdated):

@@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
 		}
 		// Equal pitch does not imply equal mip placement: a changed extent can move
 		// a level into or out of the mip tail. These are separate guest layouts.
+		// The mip count matters too: if any level both layouts have is placed differently, the
+		// cached image cannot serve the request.
+		const bool shared_levels_differ =
+		    requested.resources.levels != cached.info.resources.levels &&
+		    requested.resources.layers == cached.info.resources.layers &&
+		    !SharedLevelsMatch(requested, cached.info);

@⁠MrBigBritches Thanks for the clarification and fix. The supplied ResolveOverlap code now checks shared mip placement when mip counts differ, regardless of layer counts. This addresses the finding.


✏️ Learnings added
Learnt from: MrBigBritches
Repo: KytyPS5/KytyPS5 PR: 1781
File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:818-818
Timestamp: 2026-10-21T06:26:10.820Z
Learning: In the C++ texture cache at src/graphics/host_gpu/renderer/cache/textureCache.cpp, ImageInfo::mip_layout describes mip placement within a single layer. Layer counts do not affect whether shared mip levels line up, so ResolveOverlap must not require equal layer counts before checking SharedLevelsMatch when mip counts differ.

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-21 06:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#discussion_r4333680306) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 819 (outdated): ```diff @@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } // Equal pitch does not imply equal mip placement: a changed extent can move // a level into or out of the mip tail. These are separate guest layouts. + // The mip count matters too: if any level both layouts have is placed differently, the + // cached image cannot serve the request. + const bool shared_levels_differ = + requested.resources.levels != cached.info.resources.levels && + requested.resources.layers == cached.info.resources.layers && + !SharedLevelsMatch(requested, cached.info); ``` <!-- coderabbit-ai-generated:v1 --> @⁠MrBigBritches Thanks for the clarification and fix. The supplied `ResolveOverlap` code now checks shared mip placement when mip counts differ, regardless of layer counts. This addresses the finding. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: MrBigBritches Repo: KytyPS5/KytyPS5 PR: 1781 File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:818-818 Timestamp: 2026-10-21T06:26:10.820Z Learning: In the C++ texture cache at src/graphics/host_gpu/renderer/cache/textureCache.cpp, ImageInfo::mip_layout describes mip placement within a single layer. Layer counts do not affect whether shared mip levels line up, so ResolveOverlap must not require equal layer counts before checking SharedLevelsMatch when mip counts differ. ``` > 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=Catch%20subtle%20texture-cache%20bugs%20with%20%40coderabbitai%20%F0%9F%90%87%20Its%20review%20fixed%20mip-layout%20matching%20across%20differing%20layer%20counts%E2%80%94preventing%20incorrect%20cached-image%20reuse.%20Try%20it%20for%20your%20PRs!%20%F0%9F%9A%80&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1781%23discussion_r4333521700)? 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

@⁠coderabbitai[bot] on GitHub · 2026-10-21 06:29 UTC · original
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 827 (outdated):

@@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
 		}
 		// Equal pitch does not imply equal mip placement: a changed extent can move
 		// a level into or out of the mip tail. These are separate guest layouts.
+		// The mip count matters too: if any level both layouts have is placed differently, the
+		// cached image cannot serve the request.
+		const bool shared_levels_differ =
+		    requested.resources.levels != cached.info.resources.levels &&
+		    requested.resources.layers == cached.info.resources.layers &&
+		    !SharedLevelsMatch(requested, cached.info);
 		if (requested.tile_mode != cached.info.tile_mode ||
 		    (requested.resources == cached.info.resources &&
 		     !std::equal(requested.mip_layout.begin(), requested.mip_layout.end(),
-		                 cached.info.mip_layout.begin(),
-		                 [](const ImageMipInfo& left, const ImageMipInfo& right) {
-			                 return left.offset == right.offset && left.size == right.size &&
-			                        left.pitch == right.pitch && left.height == right.height &&
-			                        left.tail_x == right.tail_x && left.tail_y == right.tail_y &&
-			                        left.surface_z == right.surface_z;
-		                 }))) {
-			if (safe_to_delete) {
+		                 cached.info.mip_layout.begin(), SameMipPlacement)) ||
+		    shared_levels_differ) {
+			// The request becomes a separate image. Retire an idle cached image only when it
+			// mirrors guest memory; GPU-written contents stay until texture GC downloads them.
+			if (safe_to_delete && !cached.IsGpuModified()) {

@⁠MrBigBritches Thanks for the fix and clarification. The supplied code now sends idle layout conflicts through BcAlias::Resolve, which publishes safe GPU-written contents before freeing the cached image. Your regression test covers retirement, replacement lookup, and data preservation.

Keeping recently used images avoids churn when a title alternates between views. That behavior is unchanged by this fix.


✏️ Learnings added
Learnt from: MrBigBritches
Repo: KytyPS5/KytyPS5 PR: 1781
File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:0-0
Timestamp: 2026-10-21T06:29:24.571Z
Learning: In the C++ texture cache at src/graphics/host_gpu/renderer/cache/textureCache.cpp, ResolveOverlap intentionally retains incompatible images accessed within the last 32 scheduler ticks. Titles can alternate between texture views, so retiring those images on every layout conflict would cause cache churn. This recent-image coexistence predates the mip-layout fix.

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.


🧠 Learnings used
Learnt from: MrBigBritches
Repo: KytyPS5/KytyPS5 PR: 1781
File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:818-818
Timestamp: 2026-10-21T06:26:15.823Z
Learning: In the C++ texture cache at src/graphics/host_gpu/renderer/cache/textureCache.cpp, ImageInfo::mip_layout describes mip placement within a single layer. Layer counts do not affect whether shared mip levels line up, so ResolveOverlap must not require equal layer counts before checking SharedLevelsMatch when mip counts differ.

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-21 06:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#discussion_r4333702148) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 827 (outdated): ```diff @@ -796,17 +811,20 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } // Equal pitch does not imply equal mip placement: a changed extent can move // a level into or out of the mip tail. These are separate guest layouts. + // The mip count matters too: if any level both layouts have is placed differently, the + // cached image cannot serve the request. + const bool shared_levels_differ = + requested.resources.levels != cached.info.resources.levels && + requested.resources.layers == cached.info.resources.layers && + !SharedLevelsMatch(requested, cached.info); if (requested.tile_mode != cached.info.tile_mode || (requested.resources == cached.info.resources && !std::equal(requested.mip_layout.begin(), requested.mip_layout.end(), - cached.info.mip_layout.begin(), - [](const ImageMipInfo& left, const ImageMipInfo& right) { - return left.offset == right.offset && left.size == right.size && - left.pitch == right.pitch && left.height == right.height && - left.tail_x == right.tail_x && left.tail_y == right.tail_y && - left.surface_z == right.surface_z; - }))) { - if (safe_to_delete) { + cached.info.mip_layout.begin(), SameMipPlacement)) || + shared_levels_differ) { + // The request becomes a separate image. Retire an idle cached image only when it + // mirrors guest memory; GPU-written contents stay until texture GC downloads them. + if (safe_to_delete && !cached.IsGpuModified()) { ``` <!-- coderabbit-ai-generated:v1 --> @⁠MrBigBritches Thanks for the fix and clarification. The supplied code now sends idle layout conflicts through `BcAlias::Resolve`, which publishes safe GPU-written contents before freeing the cached image. Your regression test covers retirement, replacement lookup, and data preservation. Keeping recently used images avoids churn when a title alternates between views. That behavior is unchanged by this fix. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: MrBigBritches Repo: KytyPS5/KytyPS5 PR: 1781 File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:0-0 Timestamp: 2026-10-21T06:29:24.571Z Learning: In the C++ texture cache at src/graphics/host_gpu/renderer/cache/textureCache.cpp, ResolveOverlap intentionally retains incompatible images accessed within the last 32 scheduler ticks. Titles can alternate between texture views, so retiring those images on every layout conflict would cause cache churn. This recent-image coexistence predates the mip-layout fix. ``` > 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> --- <details> <summary>🧠 Learnings used</summary> ``` Learnt from: MrBigBritches Repo: KytyPS5/KytyPS5 PR: 1781 File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:818-818 Timestamp: 2026-10-21T06:26:15.823Z Learning: In the C++ texture cache at src/graphics/host_gpu/renderer/cache/textureCache.cpp, ImageInfo::mip_layout describes mip placement within a single layer. Layer counts do not affect whether shared mip levels line up, so ResolveOverlap must not require equal layer counts before checking SharedLevelsMatch when mip counts differ. ``` </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=Catch%20stale%20GPU%20readbacks%3A%20%40coderabbitai%20found%20overlapping%20cached%20images%20where%20range%20lookup%20could%20pick%20an%20older%20GPU-modified%20copy.%20Retire%20it%20safely%2C%20preserve%20writes%2C%20and%20test%20the%20fix.%20Try%20it!%20%F0%9F%9B%A0%EF%B8%8F&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1781%23discussion_r4333521703)? 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

@⁠coderabbitai[bot] on GitHub · 2026-10-27 21:30 UTC · original · edited 2026-10-27 21:57 UTC
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 861 (outdated):

@@ -809,18 +854,21 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
 		}
 		// Equal pitch does not imply equal mip placement: a changed extent can move
 		// a level into or out of the mip tail. These are separate guest layouts.
+		// The mip count matters too: if any level both layouts have is placed differently, the
+		// cached image cannot serve the request.
+		const bool shared_levels_differ =
+		    requested.resources.levels != cached.info.resources.levels &&
+		    !SharedLevelsMatch(requested, cached.info);

Major · Functional Correctness · Quick win

Supported by static analysis

Script executed:

set -o pipefail
printf '%s\n' '--- relevant symbols ---'
rg -n -F -- 'ResolveDepthOverlap' src/graphics/host_gpu/renderer/cache/textureCache.cpp src/graphics/host_gpu/renderer/cache || true
rg -n -F -- 'SharedLevelsMatch' src/graphics/host_gpu/renderer/cache/textureCache.cpp src/graphics/host_gpu/renderer/cache || true
rg -n -F -- 'ImageOps::Validate' src/graphics/host_gpu src || true
printf '%s\n' '--- cache implementation ---'
sed -n '620,735p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '820,885p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
printf '%s\n' '--- validation definitions and callers ---'
rg -n -F -- 'bool Validate' src/graphics/host_gpu src/graphics || true
rg -n -F -- 'Validate(' src/graphics/host_gpu/renderer | head -80 || true

Repository: KytyPS5/KytyPS5

Length of output: 13422


Script executed:

sed -n '580,715p' src/graphics/host_gpu/renderer/image/image.cpp
rg -n -F -- 'bool IsDepth' src/graphics/host_gpu/renderer/image src/graphics/host_gpu
rg -n -F -- 'resources.levels' src/graphics/host_gpu/renderer/image/image.cpp | head -60

Repository: KytyPS5/KytyPS5

Length of output: 6892


Check shared mip placement before depth-image reuse.

ResolveOverlap calls ResolveDepthOverlap before checking shared_levels_differ. A multi-mip depth request with fewer levels can therefore reuse a cached depth image even when shared mip placement differs, which can expose the wrong mip offsets.

Suggested fix
--- "a/src/graphics/host_gpu/renderer/cache/textureCache.cpp"
+++ "b/src/graphics/host_gpu/renderer/cache/textureCache.cpp"
@@ -847,18 +847,20 @@
 
 	const uint32_t requested_block = requested.bytes_per_block * requested.samples;
 	const uint32_t cached_block    = cached.info.bytes_per_block * cached.info.samples;
 	if (requested.data.address == cached.info.data.address &&
 	    requested.BlockExtent() == cached.info.BlockExtent() && requested_block == cached_block) {
-		if (const auto depth_id = ResolveDepthOverlap(requested, binding, cached_id)) {
-			return {depth_id};
-		}
+		const bool shared_levels_differ =
+		    requested.resources.levels != cached.info.resources.levels &&
+		    !SharedLevelsMatch(requested, cached.info);
+		if (!shared_levels_differ) {
+			if (const auto depth_id = ResolveDepthOverlap(requested, binding, cached_id)) {
+				return {depth_id};
+			}
+		}
 		// Equal pitch does not imply equal mip placement: a changed extent can move
 		// a level into or out of the mip tail. These are separate guest layouts.
 		// The mip count matters too: if any level both layouts have is placed differently, the
-		// cached image cannot serve the request.
-		const bool shared_levels_differ =
-		    requested.resources.levels != cached.info.resources.levels &&
-		    !SharedLevelsMatch(requested, cached.info);
+		// cached image cannot serve the request.
 		if (requested.tile_mode != cached.info.tile_mode ||
 		    (requested.resources == cached.info.resources &&
 		     !std::equal(requested.mip_layout.begin(), requested.mip_layout.end(),

✅ Addressed in commit 66675fd

**@⁠coderabbitai[bot]** on GitHub · 2026-10-27 21:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#discussion_r4394391367) · edited 2026-10-27 21:57 UTC On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 861 (outdated): ```diff @@ -809,18 +854,21 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } // Equal pitch does not imply equal mip placement: a changed extent can move // a level into or out of the mip tail. These are separate guest layouts. + // The mip count matters too: if any level both layouts have is placed differently, the + // cached image cannot serve the request. + const bool shared_levels_differ = + requested.resources.levels != cached.info.resources.levels && + !SharedLevelsMatch(requested, cached.info); ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Quick win** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details.svg" width="16" height="16" align="absmiddle" alt=""></picture> Supported by static analysis</summary> <dl> <dd> Script executed: ```bash set -o pipefail printf '%s\n' '--- relevant symbols ---' rg -n -F -- 'ResolveDepthOverlap' src/graphics/host_gpu/renderer/cache/textureCache.cpp src/graphics/host_gpu/renderer/cache || true rg -n -F -- 'SharedLevelsMatch' src/graphics/host_gpu/renderer/cache/textureCache.cpp src/graphics/host_gpu/renderer/cache || true rg -n -F -- 'ImageOps::Validate' src/graphics/host_gpu src || true printf '%s\n' '--- cache implementation ---' sed -n '620,735p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '820,885p' src/graphics/host_gpu/renderer/cache/textureCache.cpp printf '%s\n' '--- validation definitions and callers ---' rg -n -F -- 'bool Validate' src/graphics/host_gpu src/graphics || true rg -n -F -- 'Validate(' src/graphics/host_gpu/renderer | head -80 || true ``` Repository: KytyPS5/KytyPS5 Length of output: 13422 --- Script executed: ```bash sed -n '580,715p' src/graphics/host_gpu/renderer/image/image.cpp rg -n -F -- 'bool IsDepth' src/graphics/host_gpu/renderer/image src/graphics/host_gpu rg -n -F -- 'resources.levels' src/graphics/host_gpu/renderer/image/image.cpp | head -60 ``` Repository: KytyPS5/KytyPS5 Length of output: 6892 --- </dd> </dl> </details> **Check shared mip placement before depth-image reuse.** `ResolveOverlap` calls `ResolveDepthOverlap` before checking `shared_levels_differ`. A multi-mip depth request with fewer levels can therefore reuse a cached depth image even when shared mip placement differs, which can expose the wrong mip offsets. <details> <summary>Suggested fix</summary> <dl> <dd> ```diff --- "a/src/graphics/host_gpu/renderer/cache/textureCache.cpp" +++ "b/src/graphics/host_gpu/renderer/cache/textureCache.cpp" @@ -847,18 +847,20 @@ const uint32_t requested_block = requested.bytes_per_block * requested.samples; const uint32_t cached_block = cached.info.bytes_per_block * cached.info.samples; if (requested.data.address == cached.info.data.address && requested.BlockExtent() == cached.info.BlockExtent() && requested_block == cached_block) { - if (const auto depth_id = ResolveDepthOverlap(requested, binding, cached_id)) { - return {depth_id}; - } + const bool shared_levels_differ = + requested.resources.levels != cached.info.resources.levels && + !SharedLevelsMatch(requested, cached.info); + if (!shared_levels_differ) { + if (const auto depth_id = ResolveDepthOverlap(requested, binding, cached_id)) { + return {depth_id}; + } + } // Equal pitch does not imply equal mip placement: a changed extent can move // a level into or out of the mip tail. These are separate guest layouts. // The mip count matters too: if any level both layouts have is placed differently, the - // cached image cannot serve the request. - const bool shared_levels_differ = - requested.resources.levels != cached.info.resources.levels && - !SharedLevelsMatch(requested, cached.info); + // cached image cannot serve the request. if (requested.tile_mode != cached.info.tile_mode || (requested.resources == cached.info.resources && !std::equal(requested.mip_layout.begin(), requested.mip_layout.end(), ``` </dd> </dl> </details> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:a813f5c46cda3f574ca23493 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 66675fd
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-27 21:30 UTC · original · reviewed

Actionable comments posted: 1


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 660dd70efaaa4f9486a186ef8b5e998f69af28db and 2ae9be679e.

Files selected for processing: 3
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.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-27 21:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#pullrequestreview-5674647835) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** --- <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/69fdb03dc237c49890092e514a68ae89e4e37aa4/.coderabbit.yaml>) - **Commit**: [69fdb03](<https://github.com/KytyPS5/KytyPS5/commit/69fdb03dc237c49890092e514a68ae89e4e37aa4>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `00291bc1-333a-4a91-9b15-ba256368bc8f` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 660dd70efaaa4f9486a186ef8b5e998f69af28db and 2ae9be679e80c8fee09303a69fe933260c561232. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 3</summary> <dl> <dd> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.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; 7 remain after this review. </dd> </dl> </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=348b226b-8fb3-4585-89f3-d1f6b0a78dd2 attempt=95847d12-3e15-45e8-b42f-67c30d1a5800 batch=1/1 -->
Author
Owner

@⁠MrBigBritches on GitHub · 2026-10-27 21:55 UTC · original
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 861 (outdated):

@@ -809,18 +854,21 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
 		}
 		// Equal pitch does not imply equal mip placement: a changed extent can move
 		// a level into or out of the mip tail. These are separate guest layouts.
+		// The mip count matters too: if any level both layouts have is placed differently, the
+		// cached image cannot serve the request.
+		const bool shared_levels_differ =
+		    requested.resources.levels != cached.info.resources.levels &&
+		    !SharedLevelsMatch(requested, cached.info);

Fixed in 66675fdb. The depth path no longer hands back the cached image unchanged when the shared mip placement differs, so the request gets its own image as color requests do. Its convert-and-copy result is kept, because existing layered depth/color aliases rely on it. That copy maps levels by index, which predates this PR. I'm tracking it as a follow-up along with the ResolveOverlap fallback that frees an idle image without publishing it.

**@⁠MrBigBritches** on GitHub · 2026-10-27 21:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#discussion_r4394641388) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 861 (outdated): ```diff @@ -809,18 +854,21 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } // Equal pitch does not imply equal mip placement: a changed extent can move // a level into or out of the mip tail. These are separate guest layouts. + // The mip count matters too: if any level both layouts have is placed differently, the + // cached image cannot serve the request. + const bool shared_levels_differ = + requested.resources.levels != cached.info.resources.levels && + !SharedLevelsMatch(requested, cached.info); ``` Fixed in 66675fdb. The depth path no longer hands back the cached image unchanged when the shared mip placement differs, so the request gets its own image as color requests do. Its convert-and-copy result is kept, because existing layered depth/color aliases rely on it. That copy maps levels by index, which predates this PR. I'm tracking it as a follow-up along with the ResolveOverlap fallback that frees an idle image without publishing it.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-27 21:57 UTC · original
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 861 (outdated):

@@ -809,18 +854,21 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
 		}
 		// Equal pitch does not imply equal mip placement: a changed extent can move
 		// a level into or out of the mip tail. These are separate guest layouts.
+		// The mip count matters too: if any level both layouts have is placed differently, the
+		// cached image cannot serve the request.
+		const bool shared_levels_differ =
+		    requested.resources.levels != cached.info.resources.levels &&
+		    !SharedLevelsMatch(requested, cached.info);

@⁠MrBigBritches The supplied code confirms the fix. When shared mip placement differs, ResolveOverlap rejects an unchanged cached_id from ResolveDepthOverlap. It still accepts a converted replacement image. This addresses the reuse concern without removing the existing conversion path.

The level-index copy behavior and the idle-image fallback remain separate follow-ups. Would you like me to open a GitHub issue for those two items?


🧠 Learnings used
Learnt from: MrBigBritches
Repo: KytyPS5/KytyPS5

Timestamp: 2026-10-21T06:29:29.449Z
Learning: In the C++ texture cache at src/graphics/host_gpu/renderer/cache/textureCache.cpp, ResolveOverlap intentionally retains incompatible images accessed within the last 32 scheduler ticks. Titles can alternate between texture views, so retiring those images on every layout conflict would cause cache churn. This recent-image coexistence predates the mip-layout fix.
Learnt from: MrBigBritches
Repo: KytyPS5/KytyPS5 PR: 1781
File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:818-818
Timestamp: 2026-10-21T06:26:15.823Z
Learning: In the C++ texture cache at src/graphics/host_gpu/renderer/cache/textureCache.cpp, ImageInfo::mip_layout describes mip placement within a single layer. Layer counts do not affect whether shared mip levels line up, so ResolveOverlap must not require equal layer counts before checking SharedLevelsMatch when mip counts differ.

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-27 21:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#discussion_r4394660260) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 861 (outdated): ```diff @@ -809,18 +854,21 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } // Equal pitch does not imply equal mip placement: a changed extent can move // a level into or out of the mip tail. These are separate guest layouts. + // The mip count matters too: if any level both layouts have is placed differently, the + // cached image cannot serve the request. + const bool shared_levels_differ = + requested.resources.levels != cached.info.resources.levels && + !SharedLevelsMatch(requested, cached.info); ``` <!-- coderabbit-ai-generated:v1 --> @⁠MrBigBritches The supplied code confirms the fix. When shared mip placement differs, `ResolveOverlap` rejects an unchanged `cached_id` from `ResolveDepthOverlap`. It still accepts a converted replacement image. This addresses the reuse concern without removing the existing conversion path. The level-index copy behavior and the idle-image fallback remain separate follow-ups. Would you like me to open a GitHub issue for those two items? --- <details> <summary>🧠 Learnings used</summary><blockquote> <dl> <dd> ``` Learnt from: MrBigBritches Repo: KytyPS5/KytyPS5 Timestamp: 2026-10-21T06:29:29.449Z Learning: In the C++ texture cache at src/graphics/host_gpu/renderer/cache/textureCache.cpp, ResolveOverlap intentionally retains incompatible images accessed within the last 32 scheduler ticks. Titles can alternate between texture views, so retiring those images on every layout conflict would cause cache churn. This recent-image coexistence predates the mip-layout fix. ``` ``` Learnt from: MrBigBritches Repo: KytyPS5/KytyPS5 PR: 1781 File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:818-818 Timestamp: 2026-10-21T06:26:15.823Z Learning: In the C++ texture cache at src/graphics/host_gpu/renderer/cache/textureCache.cpp, ImageInfo::mip_layout describes mip placement within a single layer. Layer counts do not affect whether shared mip levels line up, so ResolveOverlap must not require equal layer counts before checking SharedLevelsMatch when mip counts differ. ``` </dd> </dl> </blockquote></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=%40coderabbitai%20spotted%20a%20depth-cache%20reuse%20bug%3A%20mismatched%20shared%20mip%20placement%20could%20expose%20wrong%20offsets.%20The%20fix%20preserves%20valid%20depth%20aliases%20while%20avoiding%20unsafe%20reuse.%20Try%20CodeRabbit%20for%20actionable%20reviews%20%F0%9F%90%87%E2%9C%85&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1781%23discussion_r4394391367)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠MrBigBritches on GitHub · 2026-10-27 22:19 UTC · original

@⁠coderabbitai resume

**@⁠MrBigBritches** on GitHub · 2026-10-27 22:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#issuecomment-6455011820) @⁠coderabbitai resume
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-27 22:19 UTC · original · edited 2026-10-27 22:24 UTC

✅ Action performed

Reviews resumed and review finished.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-27 22:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#issuecomment-6455014063) · edited 2026-10-27 22:24 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated reply by CodeRabbit --> <!-- CodeRabbit review command invocation: 0de95f1a-3d14-43fb-a7c9-2197e191278d --> <details> <summary>✅ Action performed</summary> <dl> <dd> Reviews resumed and review finished. </dd> </dl> </details>
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-27 22:24 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Major · Preserve newer partial buffer writes when retiring the image. · textureCache.cpp:803-806

src/graphics/host_gpu/renderer/cache/textureCache.cpp:803-806
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve newer partial buffer writes when retiring the image.

If a GPU buffer write starts inside cached.info.data, InvalidateMemoryFromGPU leaves the cached image GPU-modified because the write address differs from the image address. merged_wins_overlap is true when merged is null, so BcAlias::Publish downloads the entire older image over the newer buffer bytes. The replacement image can then upload stale data. Reconcile byte ownership before publishing the cached image, or preserve buffer-modified ranges during publication. (raw.githubusercontent.com)


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 2ae9be679e and 66675fdb41.

Files selected for processing: 2
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-27 22:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#pullrequestreview-5675246556) · **reviewed** <!-- coderabbit-ai-generated:v1 --> > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major</strong> · Preserve newer partial buffer writes when retiring the image. · <code>textureCache.cpp:803-806</code></summary><blockquote> > <dl> > <dd> > > `src/graphics/host_gpu/renderer/cache/textureCache.cpp:803-806` > **🗄️ Data Integrity & Integration** | **🟠 Major** | **🏗️ Heavy lift** > > **Preserve newer partial buffer writes when retiring the image.** > > If a GPU buffer write starts inside `cached.info.data`, `InvalidateMemoryFromGPU` leaves the cached image GPU-modified because the write address differs from the image address. `merged_wins_overlap` is true when `merged` is null, so `BcAlias::Publish` downloads the entire older image over the newer buffer bytes. The replacement image can then upload stale data. Reconcile byte ownership before publishing the cached image, or preserve buffer-modified ranges during publication. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/66675fdb41b0dd1c8041e55d80ad4898a978fecc/src/graphics/host_gpu/renderer/cache/textureCache.cpp)) > > <!-- cr-comment:v1:419120d7b1550b35ab82cc19 --> > > </dd> > </dl> > </blockquote></details> --- <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/69fdb03dc237c49890092e514a68ae89e4e37aa4/.coderabbit.yaml>) - **Commit**: [69fdb03](<https://github.com/KytyPS5/KytyPS5/commit/69fdb03dc237c49890092e514a68ae89e4e37aa4>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `5e9f61e0-bd50-4677-8db7-05f6394b5b62` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 2ae9be679e80c8fee09303a69fe933260c561232 and 66675fdb41b0dd1c8041e55d80ad4898a978fecc. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 2</summary> <dl> <dd> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `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; 6 remain after this review. </dd> </dl> </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=ebb06972-6656-47b1-bc15-925ce94cd889 attempt=4425a993-39be-4488-bcb2-1f914ed27fa2 batch=1/1 -->
Author
Owner

@⁠MrBigBritches on GitHub · 2026-10-27 22:45 UTC · original

src/graphics/host_gpu/renderer/cache/textureCache.cpp:803-806
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve newer partial buffer writes when retiring the image.

If a GPU buffer write starts inside cached.info.data, InvalidateMemoryFromGPU leaves the cached image GPU-modified because the write address differs from the image address. merged_wins_overlap is true when merged is null, so BcAlias::Publish downloads the entire older image over the newer buffer bytes. The replacement image can then upload stale data. Reconcile byte ownership before publishing the cached image, or preserve buffer-modified ranges during publication.

The cause predates this PR: InvalidateMemoryFromGPU only flags images whose base address equals the write address, so a GPU buffer write that starts inside an image leaves it GPU-modified. BcAlias::Resolve on main already publishes through the same path with the same exposure. Before this PR the retired image's GPU contents were always dropped, so this change trades that loss for the narrower partial-write case. Fixing partial-overlap invalidation changes behaviour for every title, so I'm tracking it as a separate follow-up rather than widening this PR.

**@⁠MrBigBritches** on GitHub · 2026-10-27 22:45 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1781#issuecomment-6455440994) > `src/graphics/host_gpu/renderer/cache/textureCache.cpp:803-806` > **🗄️ Data Integrity & Integration** | **🟠 Major** | **🏗️ Heavy lift** > > **Preserve newer partial buffer writes when retiring the image.** > > If a GPU buffer write starts inside `cached.info.data`, `InvalidateMemoryFromGPU` leaves the cached image GPU-modified because the write address differs from the image address. `merged_wins_overlap` is true when `merged` is null, so `BcAlias::Publish` downloads the entire older image over the newer buffer bytes. The replacement image can then upload stale data. Reconcile byte ownership before publishing the cached image, or preserve buffer-modified ranges during publication. The cause predates this PR: InvalidateMemoryFromGPU only flags images whose base address equals the write address, so a GPU buffer write that starts inside an image leaves it GPU-modified. BcAlias::Resolve on main already publishes through the same path with the same exposure. Before this PR the retired image's GPU contents were always dropped, so this change trades that loss for the narrower partial-write case. Fixing partial-overlap invalidation changes behaviour for every title, so I'm tracking it as a separate follow-up rather than widening this PR.
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
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/1781/head:github-bot/gh-1781'
git switch 'github-bot/gh-1781'

Merge

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