graphics: compare image subresources by containment (Uncharted: Legacy of Thieves Collection) #2410

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

@⁠Nawid3333 on GitHub · 2026-11-19 15:18 UTC · original
Nawid3333:fix/subresource-containment → main · +403 −18 · 4 files · 8 commits · open

Two games stop at the same texture cache check:

TextureCache: unresolvable equal-address image overlap, address=0x00000012a2b70000 requested=1x8 cached=10x1 requested_size=0x0000000000200000 cached_size=0x0000000000060000 type=9/9 tile=9/9

(Uncharted: Legacy of Thieves Collection, A Thief's End, #2385) and

TextureCache: unresolvable equal-address image overlap, address=0x0000081130000000 requested=9x2 cached=11x1 requested_size=0x00000000002c0000 cached_size=0x0000000000160000 type=9/9 tile=9/9

(Warhammer Age of Sigmar Realms of Ruin, #774).

ImageSubresources has a defaulted operator<=>, which orders {levels, layers} with levels first. So {1, 8} > {10, 1} is false, and ResolveOverlap skips the growth branch for a request with more layers but fewer levels than the cached image. ResolveDepthOverlap and FindImage use the same order to decide whether the cached image covers the request.

Change

  • ImageSubresources::Contains: true only when both the level count and the layer count cover the other. It replaces < / > in ResolveOverlap, ResolveDepthOverlap and FindImage.
  • Growing {10, 1} to {1, 8} drops subresources of the cached image, so the old index copy would lose its GPU-written levels. ExpandImage now retires the cached image through guest memory when the types match, the replacement does not contain the cached subresources, has one sample and is uncompressed: a cached image with GPU writes is first published (BcAlias::Publish, which needs SafeToDownload), then the replacement is initialized from guest memory. A cached image without GPU writes already matches guest memory, so it is retired the same way without the publish; copying it by subresource index would put its levels at the wrong guest offsets. The FindImage fallback publishes the same way before it frees the image.
  • With Contains, ResolveDepthOverlap recreates a depth image that does not contain the request, for example 2 levels x 1 layer read as 1 level x 4 layers. It retires the cached image through the same helper as ExpandImage (RetireThroughGuestMemory). When that does not apply (for example the replacement drops nothing, or a GPU-written cached image cannot be published), main's initialization of the added levels and layers (1b0f689df, which replaced this PR's own) and the copy run as before. A depth image that grows as depth (grow_depth, also 1b0f689df) hands its HTile clear state to the replacement before the retire, because freeing the cached image erases the HTile state it still owns.

The same comparison of each count is part of two larger open PRs: #1899 (@⁠claxten10, The Last of Us Part I) at all three places, and #1518 (@⁠FxDrops) in ResolveDepthOverlap and FindImage. This PR takes only that comparison and adds the publish above and the tests below.

Test

--buffer-cache-range-only (UnifiedTextureCacheFlow):

  • 11 levels x 1 layer, then 9 levels x 2 layers at the same address (#774's shape): without the change it stops with requested=9x2 cached=11x1.
  • a 256x256 R8 kStandard64KB texture with 9 levels, then read as 1 level x 8 layers (#2385's shape, with 9 levels where the game's image has 10): without the change it stops with requested=1x8 cached=9x1. With the change, the old level 0 is found in the layer at its guest offset.
  • in the #774 shape, a GPU-written tail level (level 9) survives the replacement. Without the ExpandImage publish this case fails ("retiring the mip chain lost a GPU-only tail mip").
  • the #2385 shape again, uploaded from guest memory only (no GPU writes) with different guest bytes in each layer: the layers keep their own guest bytes. Before 9535d526c this case fails ("a guest-current source overwrote layers at the wrong guest offsets"): layer 0 got level 0's bytes.
  • a linear 2x1 D32 depth target with 2 levels, both cleared on the GPU, then read as 1 level x 4 layers and back: the cleared level 1 shows up in layer 1 (its guest offset), layer 3 holds its guest bytes, and a GPU clear of layer 1 comes back as level 1. A second case grows a 2x1 depth target with 1 level x 1 layer, uploaded with UpdateImage and without GPU writes, to 4 layers and checks layer 3. Before this depth change the test fails at "depth layer growth contents"; without the publish it fails there too (measured before the rebase, on 5384a7bb0 and 65cdc6fa8).
  • a 2x1 D32 depth target with HTile metadata and 2 levels, both cleared on the GPU, then sampled as R32 with 1 level x 4 layers: it grows as depth (grow_depth) through RetireThroughGuestMemory, keeps its HTile clear state (slice 0 consumed with TouchMeta before the growth stays consumed, slice 1 stays pending), shows the cleared level 1 in layer 1 and the guest bytes in layer 3. With the HTile hand-off after the retire (main's order) it fails ("the grown depth array lost its HTile clear state", measured on 9535d526c).

DepthTargetFootprints asserted the old order ({2, 1} > {1, 4}); it now checks that {2, 4} contains {2, 1} and {1, 4}, and that neither of {2, 1} and {1, 4} contains the other.

Full test suite on 9535d526c against main a21fd80c8: the same results (194 passed; GpuSelectedFormattedRgba16Store and IndirectImageQueryDimensions fail on both, and both runs stop at the same later check, image format does not support required usage: format=129 ... samples=2 in image.cpp). Windows 11, RX 9070 XT, clang-cl. The compute test cases need the robust-buffer harness change of #2038 on this GPU. Rebased onto main a21fd80c8 (94119354c, 4cfdc862e and 1b0f689df changed the same functions). PR CI run 44832736912 on 9535d526c: green on Windows, Linux and macOS (builds, and the unit tests CI runs; the GPU test cases above ran only on the RX 9070 XT).

Game

@⁠Crispy81 ran a fork build with this change (#2385 comment): A Thief's End now gets past the unresolvable equal-address image overlap stop and runs until a different stop (shader resource specialization failed: indirect image resource=10 source=3 candidates=17). That build also had the change of #2409 (the stop before this one) and a device-lost log. Warhammer Age of Sigmar Realms of Ruin (#774) stopped with the same check on build 0cad467. A test build with the comparison change (15a1722 = main 96b251749 + that change + the Windows build fix of #2165, #774 comment) got past it to a different stop (log: GetImageResource dword 0 is not a valid runtime value, which #2278 is for). Nobody has run Warhammer with this PR's guest-memory publish yet.

Written with Claude Code (AI): Claude Code found the cause from the testers' log lines, wrote the change and the tests, and ran them.

**@⁠Nawid3333** on GitHub · 2026-11-19 15:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410) `Nawid3333:fix/subresource-containment` → `main` · +403 −18 · 4 files · 8 commits · open Two games stop at the same texture cache check: ``` TextureCache: unresolvable equal-address image overlap, address=0x00000012a2b70000 requested=1x8 cached=10x1 requested_size=0x0000000000200000 cached_size=0x0000000000060000 type=9/9 tile=9/9 ``` (Uncharted: Legacy of Thieves Collection, A Thief's End, #2385) and ``` TextureCache: unresolvable equal-address image overlap, address=0x0000081130000000 requested=9x2 cached=11x1 requested_size=0x00000000002c0000 cached_size=0x0000000000160000 type=9/9 tile=9/9 ``` (Warhammer Age of Sigmar Realms of Ruin, #774). `ImageSubresources` has a defaulted `operator<=>`, which orders `{levels, layers}` with levels first. So `{1, 8} > {10, 1}` is false, and `ResolveOverlap` skips the growth branch for a request with more layers but fewer levels than the cached image. `ResolveDepthOverlap` and `FindImage` use the same order to decide whether the cached image covers the request. ## Change - `ImageSubresources::Contains`: true only when both the level count and the layer count cover the other. It replaces `<` / `>` in `ResolveOverlap`, `ResolveDepthOverlap` and `FindImage`. - Growing `{10, 1}` to `{1, 8}` drops subresources of the cached image, so the old index copy would lose its GPU-written levels. `ExpandImage` now retires the cached image through guest memory when the types match, the replacement does not contain the cached subresources, has one sample and is uncompressed: a cached image with GPU writes is first published (`BcAlias::Publish`, which needs `SafeToDownload`), then the replacement is initialized from guest memory. A cached image without GPU writes already matches guest memory, so it is retired the same way without the publish; copying it by subresource index would put its levels at the wrong guest offsets. The `FindImage` fallback publishes the same way before it frees the image. - With `Contains`, `ResolveDepthOverlap` recreates a depth image that does not contain the request, for example 2 levels x 1 layer read as 1 level x 4 layers. It retires the cached image through the same helper as `ExpandImage` (`RetireThroughGuestMemory`). When that does not apply (for example the replacement drops nothing, or a GPU-written cached image cannot be published), main's initialization of the added levels and layers (1b0f689df, which replaced this PR's own) and the copy run as before. A depth image that grows as depth (`grow_depth`, also 1b0f689df) hands its HTile clear state to the replacement before the retire, because freeing the cached image erases the HTile state it still owns. The same comparison of each count is part of two larger open PRs: #1899 (@⁠claxten10, The Last of Us Part I) at all three places, and #1518 (@⁠FxDrops) in `ResolveDepthOverlap` and `FindImage`. This PR takes only that comparison and adds the publish above and the tests below. ## Test `--buffer-cache-range-only` (`UnifiedTextureCacheFlow`): - 11 levels x 1 layer, then 9 levels x 2 layers at the same address (#774's shape): without the change it stops with `requested=9x2 cached=11x1`. - a 256x256 R8 `kStandard64KB` texture with 9 levels, then read as 1 level x 8 layers (#2385's shape, with 9 levels where the game's image has 10): without the change it stops with `requested=1x8 cached=9x1`. With the change, the old level 0 is found in the layer at its guest offset. - in the #774 shape, a GPU-written tail level (level 9) survives the replacement. Without the `ExpandImage` publish this case fails ("retiring the mip chain lost a GPU-only tail mip"). - the #2385 shape again, uploaded from guest memory only (no GPU writes) with different guest bytes in each layer: the layers keep their own guest bytes. Before 9535d526c this case fails ("a guest-current source overwrote layers at the wrong guest offsets"): layer 0 got level 0's bytes. - a linear 2x1 D32 depth target with 2 levels, both cleared on the GPU, then read as 1 level x 4 layers and back: the cleared level 1 shows up in layer 1 (its guest offset), layer 3 holds its guest bytes, and a GPU clear of layer 1 comes back as level 1. A second case grows a 2x1 depth target with 1 level x 1 layer, uploaded with `UpdateImage` and without GPU writes, to 4 layers and checks layer 3. Before this depth change the test fails at "depth layer growth contents"; without the publish it fails there too (measured before the rebase, on 5384a7bb0 and 65cdc6fa8). - a 2x1 D32 depth target with HTile metadata and 2 levels, both cleared on the GPU, then sampled as R32 with 1 level x 4 layers: it grows as depth (`grow_depth`) through `RetireThroughGuestMemory`, keeps its HTile clear state (slice 0 consumed with `TouchMeta` before the growth stays consumed, slice 1 stays pending), shows the cleared level 1 in layer 1 and the guest bytes in layer 3. With the HTile hand-off after the retire (main's order) it fails ("the grown depth array lost its HTile clear state", measured on 9535d526c). `DepthTargetFootprints` asserted the old order (`{2, 1} > {1, 4}`); it now checks that `{2, 4}` contains `{2, 1}` and `{1, 4}`, and that neither of `{2, 1}` and `{1, 4}` contains the other. Full test suite on 9535d526c against main a21fd80c8: the same results (194 passed; `GpuSelectedFormattedRgba16Store` and `IndirectImageQueryDimensions` fail on both, and both runs stop at the same later check, `image format does not support required usage: format=129 ... samples=2` in `image.cpp`). Windows 11, RX 9070 XT, clang-cl. The compute test cases need the robust-buffer harness change of #2038 on this GPU. Rebased onto main a21fd80c8 (94119354c, 4cfdc862e and 1b0f689df changed the same functions). PR CI [run 44832736912](https://github.com/KytyPS5/KytyPS5/actions/runs/44832736912) on 9535d526c: green on Windows, Linux and macOS (builds, and the unit tests CI runs; the GPU test cases above ran only on the RX 9070 XT). ## Game @⁠Crispy81 ran a fork build with this change ([#2385 comment](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/2385)): A Thief's End now gets past the `unresolvable equal-address image overlap` stop and runs until a different stop (`shader resource specialization failed: indirect image resource=10 source=3 candidates=17`). That build also had the change of #2409 (the stop before this one) and a device-lost log. Warhammer Age of Sigmar Realms of Ruin (#774) stopped with the same check on build 0cad467. A test build with the comparison change (15a1722 = main 96b251749 + that change + the Windows build fix of #2165, [#774 comment](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/774)) got past it to a different stop ([log](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/774): `GetImageResource dword 0 is not a valid runtime value`, which #2278 is for). Nobody has run Warhammer with this PR's guest-memory publish yet. Written with Claude Code (AI): Claude Code found the cause from the testers' log lines, wrote the change and the tests, and ran them.
ImageSubresources ordered {levels, layers} lexicographically, so the
texture cache treated 11 levels x 1 layer as covering 9 levels x 2 layers.
ResolveOverlap then skipped the growth branch and exited with
"unresolvable equal-address image overlap" (#774), and the depth overlap
and FindImage checks kept a backing that lacked a requested layer.
Replace the order with Contains, true only when both the level and the
layer counts cover the request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit f255e675bc2ed3372fdf4e943781dd1faab581ce)
(cherry picked from commit 4297034a5f4193d7305dd25568abb0db8f283d57)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A replacement that drops subresources of an image without GPU writes still
copied the old image by subresource index after initializing from guest
memory, so a tiled 9-level image read as 8 layers put level 0's bytes into
layer 0 instead of the layer at its guest offset. Guest memory already holds
such an image, so retire it the same way and publish only GPU-written ones.

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

@⁠coderabbitai[bot] on GitHub · 2026-11-19 15:26 UTC · original · edited 2026-11-26 23:39 UTC

Explain Change →

Note

Reviews paused

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

Use the following commands to manage reviews:

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

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The texture cache now uses subresource containment checks when resolving overlaps and reusing cached images. Eligible images can be published through guest memory and retired during replacement or expansion. Tests cover changes to mip levels and array layers, including preservation of GPU-written contents and initialization from guest memory.

Suggested reviewers: thecruz, nmzik, claxten10

Change: Bug fix

Merge Risk: Low · up to c65b1

This change makes image reuse in the texture cache follow subresource containment and keeps GPU-written data when images are recreated. One known gap remains: GPU-written stencil contents of a retired depth image are not published. That loss already existed on the old copy path, and fixing it needs a separate stencil readback. The change is reasonable to merge, with the stencil gap tracked as a follow-up.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: image subresource comparisons switch from lexicographic ordering to containment. It also names the game (Uncharted: Legacy of Thieves Collection), which is the trigger…
Description check Passed The description explains the bug with the reported log lines, the cause in the defaulted operator<=> ordering, and the fix through ImageSubresources::Contains. It also covers the guest-memory retire p…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: image subresource comparisons switch from lexicographic ordering to containment. It also names the game (Uncharted: Legacy of Thieves Collection), which is the trigger case. The raw summary and objectives confirm the containment change in ImageSubresources, ResolveOverlap, ResolveDepthOverlap and FindImage.

Full details: Description check

Explanation

The description explains the bug with the reported log lines, the cause in the defaulted operator<=> ordering, and the fix through ImageSubresources::Contains. It also covers the guest-memory retire path, the tests added, and the game test results. This matches the changeset described in the raw summary and objectives.

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9535d526c1 and c65b1abe82.

Files selected for processing: 4

  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
  • src/graphics/host_gpu/renderer/image/imageInfo.h
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-19 15:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#issuecomment-7013548214) · edited 2026-11-26 23:39 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/2410?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-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > - Last reviewed commit: c65b1abe825cc4ef2eebd3e8e082f72885f2e3fe > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> The texture cache now uses subresource containment checks when resolving overlaps and reusing cached images. Eligible images can be published through guest memory and retired during replacement or expansion. Tests cover changes to mip levels and array layers, including preservation of GPU-written contents and initialization from guest memory. **Suggested reviewers:** `thecruz`, `nmzik`, `claxten10` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"c65b1abe825cc4ef2eebd3e8e082f72885f2e3fe" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix <!-- 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-low-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Low</strong> · up to <code>c65b1</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `c65b1` --> <!-- final_review_risk_coverage:{"sourceCommitId":"c65b1abe825cc4ef2eebd3e8e082f72885f2e3fe","coveredCommitId":"c65b1abe825cc4ef2eebd3e8e082f72885f2e3fe","kind":"reviewed"} --> This change makes image reuse in the texture cache follow subresource containment and keeps GPU-written data when images are recreated. One known gap remains: GPU-written stencil contents of a retired depth image are not published. That loss already existed on the old copy path, and fixing it needs a separate stencil readback. The change is reasonable to merge, with the stencil gap tracked as a follow-up. <!-- 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</strong></summary> <dl> <dd> <br> | 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: image subresource comparisons switch from lexicographic ordering to containment. It also names the game (Uncharted: Legacy of Thieves Collection), which is the trigger… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description explains the bug with the reported log lines, the cause in the defaulted operator<=> ordering, and the fix through ImageSubresources::Contains. It also covers the guest-memory retire p… | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title names the main change: image subresource comparisons switch from lexicographic ordering to containment. It also names the game (Uncharted: Legacy of Thieves Collection), which is the trigger case. The raw summary and objectives confirm the containment change in ImageSubresources, ResolveOverlap, ResolveDepthOverlap and FindImage. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description explains the bug with the reported log lines, the cause in the defaulted operator&lt;=&gt; ordering, and the fix through ImageSubresources::Contains. It also covers the guest-memory retire path, the tests added, and the game test results. This matches the changeset described in the raw summary and objectives. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2410)! 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> <br> - [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> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <br> <!-- review_info_content --> <details> <summary><strong><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</strong></summary> <dl> <dd> <br> - **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/61db2f8874d4a94fd2908a87cefa973ddc48ef6e/.coderabbit.yaml>) - **Commit**: [61db2f8](<https://github.com/KytyPS5/KytyPS5/commit/61db2f8874d4a94fd2908a87cefa973ddc48ef6e>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `5f332b51-33fd-4f08-8f46-ea5f00077946` </dd> </dl> </details> <details> <summary><strong><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</strong></summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 9535d526c191654136a3f76bee08aa9ff9c575bb and c65b1abe825cc4ef2eebd3e8e082f72885f2e3fe. </dd> </dl> </details> <details> <summary><strong><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: 4</strong></summary> <dl> <dd> <br> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.h` * `src/graphics/host_gpu/renderer/image/imageInfo.h` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
@ -624,3 +624,3 @@
!requested.IsVolume() && requested.samples == cached.info.samples &&
IsSupportedSampledDepthFormat(cached.info.pixel_format, requested.pixel_format);
bool recreate = cached.info.resources < requested.resources ||
bool recreate = !cached.info.resources.Contains(requested.resources) ||
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-19 15:26 UTC · original · edited 2026-11-19 17:08 UTC

Major · Data Integrity & Integration · Quick win

Preserve cached-only depth mips before recreation.

For a single-sample linear D32 image, change resources from {2,1} to {1,4} at the same address and extent. This condition now reaches the depth recreation path. Image::CopyImage copies only the common mip count, then FreeImage(cached_id) discards the GPU-written mip 1 without publishing it. A later lookup of the original shape loses that data. Preserve the cached-only mips before freeing the cached image. (raw.githubusercontent.com)


Major · Data Integrity & Integration · Quick win

Initialize added depth layers before copying cached contents.

For the same {2,1} to {1,4} change, the replacement receives only layer 0. CopyImage calls RefreshComplete() without first initializing the replacement. This clears the CPU-dirty state while layers 1–3 remain unwritten. Later refreshes therefore do not upload their guest contents. Initialize the replacement before copying the cached intersection. This is separate from preserving retired mips. (raw.githubusercontent.com)

✅ Confirmed as addressed by @⁠Nawid3333

**@⁠coderabbitai[bot]** on GitHub · 2026-11-19 15:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#discussion_r4630893578) · edited 2026-11-19 17:08 UTC <!-- 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** · **Data Integrity & Integration** · **Quick win** **Preserve cached-only depth mips before recreation.** For a single-sample linear D32 image, change resources from `{2,1}` to `{1,4}` at the same address and extent. This condition now reaches the depth recreation path. `Image::CopyImage` copies only the common mip count, then `FreeImage(cached_id)` discards the GPU-written mip 1 without publishing it. A later lookup of the original shape loses that data. Preserve the cached-only mips before freeing the cached image. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/5384a7bb004bdeb578886ea5cce6fcab1fd56b7d/src/graphics/host_gpu/renderer/image/image.cpp)) <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:8e4d11fb0e85d2ba862841b6 --> --- **<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** · **Data Integrity & Integration** · **Quick win** **Initialize added depth layers before copying cached contents.** For the same `{2,1}` to `{1,4}` change, the replacement receives only layer 0. `CopyImage` calls `RefreshComplete()` without first initializing the replacement. This clears the CPU-dirty state while layers 1–3 remain unwritten. Later refreshes therefore do not upload their guest contents. Initialize the replacement before copying the cached intersection. This is separate from preserving retired mips. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/5384a7bb004bdeb578886ea5cce6fcab1fd56b7d/src/graphics/host_gpu/renderer/image/image.cpp)) <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:02ce2161a7b8bf9ddca9d016 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠Nawid3333 <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-19 15:26 UTC · original · reviewed

Actionable comments posted: 2

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5ad27cdd1a and 5384a7bb00.

Files selected for processing: 3

  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/image/imageInfo.h
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-19 15:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#pullrequestreview-5977930526) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 2** <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <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> <br> - **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/5ad27cdd1aeb48a7885b1a71d5a8321590b31ecd/.coderabbit.yaml>) - **Commit**: [5ad27cd](<https://github.com/KytyPS5/KytyPS5/commit/5ad27cdd1aeb48a7885b1a71d5a8321590b31ecd>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `bd9c9859-77ed-43d5-a153-a7e5ad2dadaf` </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> <br> Reviewing files that changed from the base of the PR and between 5ad27cdd1aeb48a7885b1a71d5a8321590b31ecd and 5384a7bb004bdeb578886ea5cce6fcab1fd56b7d. </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> <br> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/image/imageInfo.h` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=b428b7d3-39f2-438a-9f2f-815b0f7b8abc attempt=5d1ef598-c9e7-4336-a0d8-824d8ba11e62 batch=1/1 -->
@ -894,0 +909,4 @@
return false;
}
InitializeImage(replacement_id);
FreeImage(retired_id);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-19 16:50 UTC · original · edited 2026-11-19 17:14 UTC

Major · Data Integrity & Integration · Heavy lift

Publish stencil planes before a retired depth backing is freed.

RetireThroughGuestMemory publishes only the depth image. BcAlias::Publish downloads the depth aspect, and FreeImage(retired_id) then deletes every stencil plane in stencil_ids without publishing it. A stencil plane that the GPU wrote can lose those contents when the replacement drops the same subresources. For example, a D32/S8 backing that changes from {2,1} to {1,4} can lose GPU-written stencil in mip 0, layer 0. The replacement's stencil plane is then populated from guest memory, which does not contain those writes.

The skipped CopyImage did not copy stencil either, so this loss predates the early return. This change makes the retirement path reach it.

Publish each GPU-modified stencil plane associated with the retired depth before freeing it, or preserve its contents in the replacement. Depth-only publication does not meet the rule that a recreated depth backing publishes the subresources it drops.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-19 16:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#discussion_r4632061993) · edited 2026-11-19 17:14 UTC <!-- 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** · **Data Integrity & Integration** · **Heavy lift** **Publish stencil planes before a retired depth backing is freed.** `RetireThroughGuestMemory` publishes only the depth image. `BcAlias::Publish` downloads the depth aspect, and `FreeImage(retired_id)` then deletes every stencil plane in `stencil_ids` without publishing it. A stencil plane that the GPU wrote can lose those contents when the replacement drops the same subresources. For example, a D32/S8 backing that changes from `{2,1}` to `{1,4}` can lose GPU-written stencil in mip 0, layer 0. The replacement's stencil plane is then populated from guest memory, which does not contain those writes. The skipped `CopyImage` did not copy stencil either, so this loss predates the early return. This change makes the retirement path reach it. Publish each GPU-modified stencil plane associated with the retired depth before freeing it, or preserve its contents in the replacement. Depth-only publication does not meet the rule that a recreated depth backing publishes the subresources it drops. <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:5cd19e48fde8380f07b2d931 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-19 16:50 UTC · original · reviewed

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5384a7bb00 and 65cdc6fa85.

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 10 included reviews per hour; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-19 16:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#pullrequestreview-5979441283) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <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> <br> - **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/5ad27cdd1aeb48a7885b1a71d5a8321590b31ecd/.coderabbit.yaml>) - **Commit**: [5ad27cd](<https://github.com/KytyPS5/KytyPS5/commit/5ad27cdd1aeb48a7885b1a71d5a8321590b31ecd>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `6fa42234-a91e-4eac-b254-fdab04ad906b` </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> <br> Reviewing files that changed from the base of the PR and between 5384a7bb004bdeb578886ea5cce6fcab1fd56b7d and 65cdc6fa850f5e72f433baf2d6ba4d52a454a2c7. </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> <br> * `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 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=50607d96-11cd-4a94-98f6-b7b70fede772 attempt=dc16ac51-344e-4dd1-84b1-b2766891d0d8 batch=1/1 -->
@ -624,3 +624,3 @@
!requested.IsVolume() && requested.samples == cached.info.samples &&
IsSupportedSampledDepthFormat(cached.info.pixel_format, requested.pixel_format);
bool recreate = cached.info.resources < requested.resources ||
bool recreate = !cached.info.resources.Contains(requested.resources) ||
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-19 17:07 UTC · original

@⁠coderabbitai Both points are right, and both are fixed in 65cdc6fa8 with a test in f84ed8bac.

  • Dropped levels: ResolveDepthOverlap now retires the cached image the way ExpandImage already did, through one helper, RetireThroughGuestMemory. When the replacement does not contain the cached subresources (same type, one sample, uncompressed) and the cached image is SafeToDownload, it publishes the cached image to guest memory, initializes the replacement from guest memory and frees the cached image.
  • Added layers: when that path does not apply (the replacement drops nothing, or the cached image holds no GPU writes) and the replacement has subresources the cached image lacks, the replacement is initialized from guest memory before the copy, so RefreshComplete() no longer hides the added layers. A replacement that the cached image fully covers still takes only the copy.

The test in UnifiedTextureCacheFlow (--buffer-cache-range-only) uses your shape: a linear 2x1 D32 depth target with 2 levels, both levels cleared on the GPU, then read as 1 level x 4 layers, then the old shape again. The cleared level 1 must show up in layer 1 (it is at that guest offset), layer 3 must hold its guest bytes, and a later GPU clear of layer 1 must come back as level 1. A second case starts from the same 2x1 depth target with 1 level x 1 layer and no GPU writes, reads it as 1 level x 4 layers and checks that layer 3 holds its guest bytes. On 5384a7bb0 the test fails at "depth layer growth contents"; with the change it passes. Removing either half of the change makes it fail again.

**@⁠Nawid3333** on GitHub · 2026-11-19 17:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#discussion_r4632273812) @⁠coderabbitai Both points are right, and both are fixed in 65cdc6fa8 with a test in f84ed8bac. - Dropped levels: `ResolveDepthOverlap` now retires the cached image the way `ExpandImage` already did, through one helper, `RetireThroughGuestMemory`. When the replacement does not contain the cached subresources (same type, one sample, uncompressed) and the cached image is `SafeToDownload`, it publishes the cached image to guest memory, initializes the replacement from guest memory and frees the cached image. - Added layers: when that path does not apply (the replacement drops nothing, or the cached image holds no GPU writes) and the replacement has subresources the cached image lacks, the replacement is initialized from guest memory before the copy, so `RefreshComplete()` no longer hides the added layers. A replacement that the cached image fully covers still takes only the copy. The test in `UnifiedTextureCacheFlow` (`--buffer-cache-range-only`) uses your shape: a linear 2x1 D32 depth target with 2 levels, both levels cleared on the GPU, then read as 1 level x 4 layers, then the old shape again. The cleared level 1 must show up in layer 1 (it is at that guest offset), layer 3 must hold its guest bytes, and a later GPU clear of layer 1 must come back as level 1. A second case starts from the same 2x1 depth target with 1 level x 1 layer and no GPU writes, reads it as 1 level x 4 layers and checks that layer 3 holds its guest bytes. On 5384a7bb0 the test fails at "depth layer growth contents"; with the change it passes. Removing either half of the change makes it fail again.
@ -894,0 +909,4 @@
return false;
}
InitializeImage(replacement_id);
FreeImage(retired_id);
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-19 17:14 UTC · original

@⁠coderabbitai Agreed that a GPU-written stencil plane is lost here, and as you say, it was lost before this change too: Image::CopyImage removes the stencil aspect from both sides of the copy (FullAspectMask(...) & ~eStencil), and FreeImage of a depth image frees every stencil association without a download (DeleteImage). The texture cache has no stencil readback at all; that is why garbage collection keeps a GPU-written image with stencil instead of downloading it (owner->info.HasStencil() in the pressured eviction check). So the same loss happens today on every path that frees such an image, not only on this one.

Publishing stencil needs a new stencil-plane download (S8 readback into the guest stencil range, tiled and linear), which is a separate change from this PR's subresource comparison. This PR keeps the depth publish, which does not change what happens to stencil.

**@⁠Nawid3333** on GitHub · 2026-11-19 17:14 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#discussion_r4632378693) @⁠coderabbitai Agreed that a GPU-written stencil plane is lost here, and as you say, it was lost before this change too: `Image::CopyImage` removes the stencil aspect from both sides of the copy (`FullAspectMask(...) & ~eStencil`), and `FreeImage` of a depth image frees every stencil association without a download (`DeleteImage`). The texture cache has no stencil readback at all; that is why garbage collection keeps a GPU-written image with stencil instead of downloading it (`owner->info.HasStencil()` in the pressured eviction check). So the same loss happens today on every path that frees such an image, not only on this one. Publishing stencil needs a new stencil-plane download (S8 readback into the guest stencil range, tiled and linear), which is a separate change from this PR's subresource comparison. This PR keeps the depth publish, which does not change what happens to stencil.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-20 22:41 UTC · original · edited 2026-11-20 23:52 UTC
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 907 (outdated):

@@ -891,6 +898,20 @@ ImageId TextureCache::ExpandImage(const ImageInfo& info, ImageId source_id) {
 	return expanded_id;
 }
 
+bool TextureCache::RetireThroughGuestMemory(ImageId replacement_id, ImageId retired_id) {
+	const auto& replacement = m_slot_images[replacement_id].info;
+	auto&       retired     = m_slot_images[retired_id];
+	if (replacement.type != retired.info.type ||
+	    replacement.resources.Contains(retired.info.resources) || replacement.samples != 1 ||
+	    replacement.metadata.compression != VideoOutCompression::Uncompressed ||
+	    !retired.SafeToDownload() || !BcAlias::Publish(*this, retired)) {

Major · Data Integrity & Integration · Quick win

Handle guest-current replacements without copying the old mip layout.

For a linear R8Uint 256x256 image, change {2,1} to {1,4}. Cached mip 0 starts at guest offset 0x8000; replacement layer 0 starts at offset 0. Give these offsets different bytes. (raw.githubusercontent.com)

If the cached image was only uploaded through FindTexture, SafeToDownload() is false because no GPU write occurred. Line 907 rejects retirement. ExpandImage then initializes the correct guest contents, but CopyImage overwrites replacement layer 0 with cached mip 0. The request therefore reads bytes from the wrong guest offset. (raw.githubusercontent.com)

When guest or buffer memory already holds the current contents, initialize the replacement and retire the source without the logical-subresource copy. Retain publication for GPU-written sources.

✅ Addressed in commits 10f064f to 9535d52

**@⁠coderabbitai[bot]** on GitHub · 2026-11-20 22:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#discussion_r4648533705) · edited 2026-11-20 23:52 UTC On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 907 (outdated): ```diff @@ -891,6 +898,20 @@ ImageId TextureCache::ExpandImage(const ImageInfo& info, ImageId source_id) { return expanded_id; } +bool TextureCache::RetireThroughGuestMemory(ImageId replacement_id, ImageId retired_id) { + const auto& replacement = m_slot_images[replacement_id].info; + auto& retired = m_slot_images[retired_id]; + if (replacement.type != retired.info.type || + replacement.resources.Contains(retired.info.resources) || replacement.samples != 1 || + replacement.metadata.compression != VideoOutCompression::Uncompressed || + !retired.SafeToDownload() || !BcAlias::Publish(*this, retired)) { ``` <!-- 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** · **Data Integrity & Integration** · **Quick win** **Handle guest-current replacements without copying the old mip layout.** For a linear R8Uint 256x256 image, change `{2,1}` to `{1,4}`. Cached mip 0 starts at guest offset `0x8000`; replacement layer 0 starts at offset `0`. Give these offsets different bytes. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/94a5d60fae90cab128f4780a46ba2fe0cb117225/src/graphics/guest_gpu/tile.cpp)) If the cached image was only uploaded through `FindTexture`, `SafeToDownload()` is false because no GPU write occurred. Line 907 rejects retirement. `ExpandImage` then initializes the correct guest contents, but `CopyImage` overwrites replacement layer 0 with cached mip 0. The request therefore reads bytes from the wrong guest offset. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/94a5d60fae90cab128f4780a46ba2fe0cb117225/src/graphics/host_gpu/renderer/image/image.h)) When guest or buffer memory already holds the current contents, initialize the replacement and retire the source without the logical-subresource copy. Retain publication for GPU-written sources. <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:bd1e3731daf5340093de69a1 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commits 10f064f to 9535d52
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-20 22:41 UTC · original · edited 2026-11-20 23:52 UTC
On tests/ShaderRecompilerComputeTests.cpp line 7459 (outdated):

@@ -7168,6 +7168,307 @@ class VulkanHarness {
               "wide/block image readback was not aligned to its texel block");
       resources.MapMemory(base, allocation_size);
 
+      {
+        constexpr uint64_t offset = 0x4800000;
+        std::memset(memory + offset, 0x5a, 0x2c0000);
+        auto cached = MakeLinearDesc(
+            base + offset, 0, vk::Format::eR8Uint,
+            Prospero::BufferFormat::k8UInt, Prospero::ImageType::kColor2D,
+            {1024, 1024, 1}, 1, 1, 1);
+        cached.info.tile_mode = Prospero::TileMode::kStandard64KB;
+        cached.info.resources = {11, 1};
+        cached.view_info.level_count = 11;
+        cached.info.UpdateSize();
+        auto requested = cached;
+        requested.info.data.size = 0;
+        requested.info.resources = {9, 2};
+        requested.view_info.level_count = 9;
+        requested.view_info.layer_count = 2;
+        requested.view_info.type = vk::ImageViewType::e2DArray;
+        requested.info.UpdateSize();
+        Require(name, "mixed resource footprints",
+                cached.info.data.size == 0x160000 &&
+                    requested.info.data.size == 0x2c0000 &&
+                    cached.info.first_tail_level == 3 &&
+                    requested.info.first_tail_level == 3,
+                "unexpected tiled fixture layout");
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(before, cached);
+        for (uint32_t mip = 0; mip < cached.info.resources.levels; ++mip) {
+          vk::ClearValue clear{};
+          clear.color.uint32.fill(0x10u + mip);
+          TextureCacheTestAccess::ClearImage(
+              texture_cache, scheduler.Current(), before,
+              {vk::ImageAspectFlagBits::eColor, mip, 1, 0, 1}, clear);
+        }
+        const auto after = texture_cache.FindImage(requested);
+        Require(name, "layer growth with fewer levels",
+                after != before &&
+                    !TextureCacheTestAccess::Contains(texture_cache, before) &&
+                    texture_cache.GetImage(after).info.resources ==
+                        requested.info.resources,
+                "insufficient backing was retained");
+        (void)texture_cache.FindTexture(after, requested);
+        for (uint32_t mip = 0; mip < 9; ++mip) {
+          Require(name, "mixed resource contents",
+                  ReadCachedTexel(name, context, after, {}, {4, 1, 1}, 0, mip) ==
+                          std::vector<u32>{(0x10u + mip) * 0x01010101u} &&
+                      ReadCachedTexel(name, context, after, {}, {4, 1, 1}, 1, mip) ==
+                          std::vector<u32>{0x5a5a5a5au},
+                  "lost GPU contents or failed to initialize the added layer");
+        }
+        const auto restored = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(restored, cached);
+        Require(name, "mixed resource round trip",
+                ReadCachedTexel(name, context, restored, {}, {2, 2, 1}, 0, 9) ==
+                    std::vector<u32>{0x19191919u},
+                "retiring the mip chain lost a GPU-only tail mip");
+      }
+      {
+        constexpr uint64_t offset = 0x4b10000;
+        constexpr uint32_t requested_layers = 8;
+        std::memset(memory + offset, 0x6b, 0x80000);
+        auto cached = MakeLinearDesc(
+            base + offset, 0, vk::Format::eR8Uint,
+            Prospero::BufferFormat::k8UInt, Prospero::ImageType::kColor2D,
+            {256, 256, 1}, 1, 1, 1);
+        cached.info.tile_mode = Prospero::TileMode::kStandard64KB;
+        cached.info.resources = {9, 1};
+        cached.view_info.level_count = 9;
+        cached.info.UpdateSize();
+        auto requested = cached;
+        requested.info.data.size = 0;
+        requested.info.resources = {1, requested_layers};
+        requested.view_info.level_count = 1;
+        requested.view_info.layer_count = requested_layers;
+        requested.view_info.type = vk::ImageViewType::e2DArray;
+        requested.info.UpdateSize();
+        const uint64_t layer_size = requested.info.data.size / requested_layers;
+        const uint32_t mip0_layer =
+            static_cast<uint32_t>(cached.info.mip_layout[0].offset / layer_size);
+        Require(name, "array footprints",
+                requested.info.data.size == 0x80000 &&
+                    requested.info.data.size > cached.info.data.size &&
+                    cached.info.mip_layout[0].offset % layer_size == 0 &&
+                    mip0_layer + 1 < requested_layers,
+                "unexpected tiled array fixture layout");
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(before, cached);
+        vk::ClearValue clear{};
+        clear.color.uint32.fill(0x21u);
+        TextureCacheTestAccess::ClearImage(
+            texture_cache, scheduler.Current(), before,
+            {vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1}, clear);
+        clear.color.uint32.fill(0x37u);
+        TextureCacheTestAccess::ClearImage(
+            texture_cache, scheduler.Current(), before,
+            {vk::ImageAspectFlagBits::eColor, 1, 1, 0, 1}, clear);
+        const auto after = texture_cache.FindImage(requested);
+        Require(name, "array growth with one level",
+                after != before &&
+                    !TextureCacheTestAccess::Contains(texture_cache, before) &&
+                    texture_cache.GetImage(after).info.resources ==
+                        requested.info.resources,
+                "insufficient backing was retained");
+        (void)texture_cache.FindTexture(after, requested);
+        Require(name, "array growth contents",
+                ReadCachedTexel(name, context, after, {}, {4, 1, 1}, mip0_layer) ==
+                        std::vector<u32>{0x21212121u} &&
+                    ReadCachedTexel(name, context, after, {}, {4, 1, 1},
+                                    requested_layers - 1) ==
+                        std::vector<u32>{0x6b6b6b6bu},
+                "lost GPU contents or failed to initialize the added layers");
+        const auto restored = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(restored, cached);
+        Require(name, "array resource round trip",
+                ReadCachedTexel(name, context, restored, {}, {4, 1, 1}, 0, 1) ==
+                    std::vector<u32>{0x37373737u},
+                "retiring the mip chain lost a GPU-only mip");
+      }
+      {
+        constexpr uint64_t offset = 0x4b00000;
+        const std::array<uint32_t, 4> values{
+            0x11111111u, 0x22222222u, 0x33333333u, 0x44444444u};
+        std::memcpy(memory + offset, values.data(), sizeof(values));
+        auto cached = MakeLinearDesc(
+            base + offset, sizeof(values), vk::Format::eR32Uint,
+            Prospero::BufferFormat::k32UInt, Prospero::ImageType::kColor2D,
+            {2, 1, 1}, 1, 4, 1);
+        cached.info.resources = {2, 1};
+        cached.info.mip_layout[0] = {0, 8, 2, 1};
+        cached.info.mip_layout[1] = {8, 4, 1, 1};
+        cached.view_info.level_count = 2;
+        auto requested = MakeLinearDesc(
+            base + offset, sizeof(values), vk::Format::eR32Uint,
+            Prospero::BufferFormat::k32UInt, Prospero::ImageType::kColor2D,
+            {2, 1, 1}, 2, 4, 1);
+        requested.view_info.base_layer = 1;
+        requested.view_info.layer_count = 1;
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(before, cached);
+        vk::ClearValue clear{};
+        clear.color.uint32.fill(0xabcdef01u);
+        TextureCacheTestAccess::ClearImage(
+            texture_cache, scheduler.Current(), before,
+            {vk::ImageAspectFlagBits::eColor, 1, 1, 0, 1}, clear);
+        const auto after = texture_cache.FindImage(requested);
+        Require(name, "missing-layer fallback replacement",
+                after != before &&
+                    !TextureCacheTestAccess::Contains(texture_cache, before) &&
+                    texture_cache.GetImage(after).info.resources ==
+                        requested.info.resources,
+                "FindImage returned a backing without the requested layer");
+        Require(name, "missing-layer texture acquisition",
+                texture_cache.FindTexture(after, requested) != nullptr &&
+                    ReadCachedTexel(name, context, after, {}, {1, 1, 1}, 1) ==
+                        std::vector<u32>{0xabcdef01u},
+                "the requested layer lost GPU-written guest bytes");
+        clear.color.uint32.fill(0x55667788u);
+        TextureCacheTestAccess::ClearImage(
+            texture_cache, scheduler.Current(), after,
+            {vk::ImageAspectFlagBits::eColor, 0, 1, 1, 1}, clear);
+        const auto restored = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(restored, cached);
+        Require(name, "missing-layer round trip",
+                ReadCachedTexel(name, context, restored, {}, {1, 1, 1}, 0, 1) ==
+                    std::vector<u32>{0x55667788u},
+                "retiring the array lost GPU-written guest bytes");
+      }
+      const auto linear_d32 = [](uint64_t address, uint64_t size,
+                                 uint32_t levels, uint32_t layers) {
+        auto desc = MakeLinearDesc(address, size, vk::Format::eD32Sfloat,
+                                   Prospero::BufferFormat::k32Float,
+                                   Prospero::ImageType::kColor2D, {2, 1, 1},
+                                   layers, sizeof(float), 1);
+        desc.type = BindingType::DepthTarget;
+        desc.info.resources.levels = levels;
+        desc.view_info.format = vk::Format::eD32Sfloat;
+        desc.view_info.aspect = vk::ImageAspectFlagBits::eDepth;
+        desc.view_info.usage = vk::ImageUsageFlagBits::eDepthStencilAttachment;
+        desc.view_info.level_count = levels;
+        desc.view_info.layer_count = layers;
+        desc.view_info.type = layers > 1 ? vk::ImageViewType::e2DArray
+                                         : vk::ImageViewType::e2D;
+        return desc;
+      };
+      const auto depth_texels = [](float first, float second) {
+        return std::vector<u32>{std::bit_cast<u32>(first),
+                                std::bit_cast<u32>(second)};
+      };
+      constexpr uint32_t depth_array_layers = 4;
+      constexpr std::array<float, 2 * depth_array_layers> depth_guest{
+          0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.75f, 0.875f, 1.0f};
+      {
+        constexpr uint64_t offset = 0x4ba0000;
+        constexpr std::array<float, 2> mip_clears{0.0625f, 0.9375f};
+        constexpr float layer_clear = 0.3125f;
+        std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest));
+        auto cached = linear_d32(base + offset, 3 * sizeof(float), 2, 1);
+        cached.info.mip_layout[0] = {0, 2 * sizeof(float), 2, 1};
+        cached.info.mip_layout[1] = {2 * sizeof(float), sizeof(float), 1, 1};
+        auto requested =
+            linear_d32(base + offset, sizeof(depth_guest), 1, depth_array_layers);
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindDepthTarget(before, cached);
+        for (uint32_t mip = 0; mip < mip_clears.size(); ++mip) {
+          vk::ClearValue clear{};
+          clear.depthStencil.depth = mip_clears[mip];
+          TextureCacheTestAccess::ClearImage(
+              texture_cache, scheduler.Current(), before,
+              {vk::ImageAspectFlagBits::eDepth, mip, 1, 0, 1}, clear);
+        }
+        const auto after = texture_cache.FindImage(requested);
+        Require(name, "depth layer growth",
+                after != before &&
+                    !TextureCacheTestAccess::Contains(texture_cache, before) &&
+                    texture_cache.GetImage(after).info.resources ==
+                        requested.info.resources,
+                "insufficient depth backing was retained");
+        (void)texture_cache.FindDepthTarget(after, requested);
+        Require(name, "depth layer growth contents",
+                ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 0) ==
+                        depth_texels(mip_clears[0], mip_clears[0]) &&
+                    ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 1) ==
+                        depth_texels(mip_clears[1], depth_guest[3]) &&
+                    ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 3) ==
+                        depth_texels(depth_guest[6], depth_guest[7]),
+                "lost a GPU-only depth mip or failed to initialize the added layers");
+        vk::ClearValue clear{};
+        clear.depthStencil.depth = layer_clear;
+        TextureCacheTestAccess::ClearImage(
+            texture_cache, scheduler.Current(), after,
+            {vk::ImageAspectFlagBits::eDepth, 0, 1, 1, 1}, clear);
+        const auto restored = texture_cache.FindImage(cached);
+        (void)texture_cache.FindDepthTarget(restored, cached);
+        Require(name, "depth mip round trip",
+                ReadCachedTexel(name, context, restored, {}, {1, 1, 1}, 0, 1) ==
+                    std::vector<u32>{std::bit_cast<u32>(layer_clear)},
+                "retiring the depth array lost GPU-written guest bytes");
+      }
+      {
+        constexpr uint64_t offset = 0x4bc0000;
+        constexpr uint64_t htile_address = base + offset + 0x800;
+        constexpr std::array<float, 2> mip_clears{0.0625f, 0.9375f};
+        std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest));
+        auto cached = linear_d32(base + offset, 3 * sizeof(float), 2, 1);
+        cached.info.mip_layout[0] = {0, 2 * sizeof(float), 2, 1};
+        cached.info.mip_layout[1] = {2 * sizeof(float), sizeof(float), 1, 1};
+        cached.info.metadata.kind = ImageMetadataKind::Htile;
+        cached.info.metadata.range = {htile_address, 0x200};
+        cached.info.htile_initial_clear = true;
+        auto sampled = MakeLinearDesc(
+            base + offset, sizeof(depth_guest), vk::Format::eR32Sfloat,
+            Prospero::BufferFormat::k32Float, Prospero::ImageType::kColor2D,
+            {2, 1, 1}, depth_array_layers, sizeof(float), 1);
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindDepthTarget(before, cached);
+        for (uint32_t mip = 0; mip < mip_clears.size(); ++mip) {
+          vk::ClearValue clear{};
+          clear.depthStencil.depth = mip_clears[mip];
+          TextureCacheTestAccess::ClearImage(
+              texture_cache, scheduler.Current(), before,
+              {vk::ImageAspectFlagBits::eDepth, mip, 1, 0, 1}, clear);
+        }
+        const auto grown = texture_cache.FindImage(sampled);
+        Require(name, "sampled depth growth over a dropped mip",
+                grown != before &&
+                    !TextureCacheTestAccess::Contains(texture_cache, before) &&
+                    texture_cache.GetImage(grown).backing.format ==
+                        vk::Format::eD32Sfloat &&
+                    texture_cache.GetImage(grown).info.resources ==
+                        sampled.info.resources &&
+                    texture_cache.IsMetaCleared(htile_address, 0),
+                "the grown depth array lost its pending HTile clears");
+        Require(name, "sampled depth growth contents",
+                texture_cache.FindTexture(grown, sampled) != nullptr &&
+                    ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 0) ==
+                        depth_texels(mip_clears[0], mip_clears[0]) &&
+                    ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 1) ==
+                        depth_texels(mip_clears[1], depth_guest[3]) &&
+                    ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 3) ==
+                        depth_texels(depth_guest[6], depth_guest[7]),
+                "the grown depth array lost a GPU-only mip or skipped guest memory");
+      }
+      {
+        constexpr uint64_t offset = 0x4bb0000;
+        std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest));
+        auto cached = linear_d32(base + offset, 2 * sizeof(float), 1, 1);
+        auto requested =
+            linear_d32(base + offset, sizeof(depth_guest), 1, depth_array_layers);
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindDepthTarget(before, cached);

Minor · Functional Correctness · Quick win

Keep the source backing free of GPU modifications in the guest-only test.

FindDepthTarget calls CommitGpuWrite, which marks before as GPU-modified even without a draw or clear. The layer 3 assertion can still pass because this growth keeps all old subresources and takes the copy path. The test therefore does not exercise growth from a backing with no GPU modifications. Replace the first FindDepthTarget call with UpdateImage(before) and assert !texture_cache.GetImage(before).IsGpuModified() before requesting the larger image. Keep the final depth-target acquisition and readback. (raw.githubusercontent.com)

✅ Addressed in commits 10f064f to 9535d52

**@⁠coderabbitai[bot]** on GitHub · 2026-11-20 22:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#discussion_r4648533712) · edited 2026-11-20 23:52 UTC On `tests/ShaderRecompilerComputeTests.cpp` line 7459 (outdated): ```diff @@ -7168,6 +7168,307 @@ class VulkanHarness { "wide/block image readback was not aligned to its texel block"); resources.MapMemory(base, allocation_size); + { + constexpr uint64_t offset = 0x4800000; + std::memset(memory + offset, 0x5a, 0x2c0000); + auto cached = MakeLinearDesc( + base + offset, 0, vk::Format::eR8Uint, + Prospero::BufferFormat::k8UInt, Prospero::ImageType::kColor2D, + {1024, 1024, 1}, 1, 1, 1); + cached.info.tile_mode = Prospero::TileMode::kStandard64KB; + cached.info.resources = {11, 1}; + cached.view_info.level_count = 11; + cached.info.UpdateSize(); + auto requested = cached; + requested.info.data.size = 0; + requested.info.resources = {9, 2}; + requested.view_info.level_count = 9; + requested.view_info.layer_count = 2; + requested.view_info.type = vk::ImageViewType::e2DArray; + requested.info.UpdateSize(); + Require(name, "mixed resource footprints", + cached.info.data.size == 0x160000 && + requested.info.data.size == 0x2c0000 && + cached.info.first_tail_level == 3 && + requested.info.first_tail_level == 3, + "unexpected tiled fixture layout"); + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(before, cached); + for (uint32_t mip = 0; mip < cached.info.resources.levels; ++mip) { + vk::ClearValue clear{}; + clear.color.uint32.fill(0x10u + mip); + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eColor, mip, 1, 0, 1}, clear); + } + const auto after = texture_cache.FindImage(requested); + Require(name, "layer growth with fewer levels", + after != before && + !TextureCacheTestAccess::Contains(texture_cache, before) && + texture_cache.GetImage(after).info.resources == + requested.info.resources, + "insufficient backing was retained"); + (void)texture_cache.FindTexture(after, requested); + for (uint32_t mip = 0; mip < 9; ++mip) { + Require(name, "mixed resource contents", + ReadCachedTexel(name, context, after, {}, {4, 1, 1}, 0, mip) == + std::vector<u32>{(0x10u + mip) * 0x01010101u} && + ReadCachedTexel(name, context, after, {}, {4, 1, 1}, 1, mip) == + std::vector<u32>{0x5a5a5a5au}, + "lost GPU contents or failed to initialize the added layer"); + } + const auto restored = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(restored, cached); + Require(name, "mixed resource round trip", + ReadCachedTexel(name, context, restored, {}, {2, 2, 1}, 0, 9) == + std::vector<u32>{0x19191919u}, + "retiring the mip chain lost a GPU-only tail mip"); + } + { + constexpr uint64_t offset = 0x4b10000; + constexpr uint32_t requested_layers = 8; + std::memset(memory + offset, 0x6b, 0x80000); + auto cached = MakeLinearDesc( + base + offset, 0, vk::Format::eR8Uint, + Prospero::BufferFormat::k8UInt, Prospero::ImageType::kColor2D, + {256, 256, 1}, 1, 1, 1); + cached.info.tile_mode = Prospero::TileMode::kStandard64KB; + cached.info.resources = {9, 1}; + cached.view_info.level_count = 9; + cached.info.UpdateSize(); + auto requested = cached; + requested.info.data.size = 0; + requested.info.resources = {1, requested_layers}; + requested.view_info.level_count = 1; + requested.view_info.layer_count = requested_layers; + requested.view_info.type = vk::ImageViewType::e2DArray; + requested.info.UpdateSize(); + const uint64_t layer_size = requested.info.data.size / requested_layers; + const uint32_t mip0_layer = + static_cast<uint32_t>(cached.info.mip_layout[0].offset / layer_size); + Require(name, "array footprints", + requested.info.data.size == 0x80000 && + requested.info.data.size > cached.info.data.size && + cached.info.mip_layout[0].offset % layer_size == 0 && + mip0_layer + 1 < requested_layers, + "unexpected tiled array fixture layout"); + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(before, cached); + vk::ClearValue clear{}; + clear.color.uint32.fill(0x21u); + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1}, clear); + clear.color.uint32.fill(0x37u); + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eColor, 1, 1, 0, 1}, clear); + const auto after = texture_cache.FindImage(requested); + Require(name, "array growth with one level", + after != before && + !TextureCacheTestAccess::Contains(texture_cache, before) && + texture_cache.GetImage(after).info.resources == + requested.info.resources, + "insufficient backing was retained"); + (void)texture_cache.FindTexture(after, requested); + Require(name, "array growth contents", + ReadCachedTexel(name, context, after, {}, {4, 1, 1}, mip0_layer) == + std::vector<u32>{0x21212121u} && + ReadCachedTexel(name, context, after, {}, {4, 1, 1}, + requested_layers - 1) == + std::vector<u32>{0x6b6b6b6bu}, + "lost GPU contents or failed to initialize the added layers"); + const auto restored = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(restored, cached); + Require(name, "array resource round trip", + ReadCachedTexel(name, context, restored, {}, {4, 1, 1}, 0, 1) == + std::vector<u32>{0x37373737u}, + "retiring the mip chain lost a GPU-only mip"); + } + { + constexpr uint64_t offset = 0x4b00000; + const std::array<uint32_t, 4> values{ + 0x11111111u, 0x22222222u, 0x33333333u, 0x44444444u}; + std::memcpy(memory + offset, values.data(), sizeof(values)); + auto cached = MakeLinearDesc( + base + offset, sizeof(values), vk::Format::eR32Uint, + Prospero::BufferFormat::k32UInt, Prospero::ImageType::kColor2D, + {2, 1, 1}, 1, 4, 1); + cached.info.resources = {2, 1}; + cached.info.mip_layout[0] = {0, 8, 2, 1}; + cached.info.mip_layout[1] = {8, 4, 1, 1}; + cached.view_info.level_count = 2; + auto requested = MakeLinearDesc( + base + offset, sizeof(values), vk::Format::eR32Uint, + Prospero::BufferFormat::k32UInt, Prospero::ImageType::kColor2D, + {2, 1, 1}, 2, 4, 1); + requested.view_info.base_layer = 1; + requested.view_info.layer_count = 1; + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(before, cached); + vk::ClearValue clear{}; + clear.color.uint32.fill(0xabcdef01u); + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eColor, 1, 1, 0, 1}, clear); + const auto after = texture_cache.FindImage(requested); + Require(name, "missing-layer fallback replacement", + after != before && + !TextureCacheTestAccess::Contains(texture_cache, before) && + texture_cache.GetImage(after).info.resources == + requested.info.resources, + "FindImage returned a backing without the requested layer"); + Require(name, "missing-layer texture acquisition", + texture_cache.FindTexture(after, requested) != nullptr && + ReadCachedTexel(name, context, after, {}, {1, 1, 1}, 1) == + std::vector<u32>{0xabcdef01u}, + "the requested layer lost GPU-written guest bytes"); + clear.color.uint32.fill(0x55667788u); + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), after, + {vk::ImageAspectFlagBits::eColor, 0, 1, 1, 1}, clear); + const auto restored = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(restored, cached); + Require(name, "missing-layer round trip", + ReadCachedTexel(name, context, restored, {}, {1, 1, 1}, 0, 1) == + std::vector<u32>{0x55667788u}, + "retiring the array lost GPU-written guest bytes"); + } + const auto linear_d32 = [](uint64_t address, uint64_t size, + uint32_t levels, uint32_t layers) { + auto desc = MakeLinearDesc(address, size, vk::Format::eD32Sfloat, + Prospero::BufferFormat::k32Float, + Prospero::ImageType::kColor2D, {2, 1, 1}, + layers, sizeof(float), 1); + desc.type = BindingType::DepthTarget; + desc.info.resources.levels = levels; + desc.view_info.format = vk::Format::eD32Sfloat; + desc.view_info.aspect = vk::ImageAspectFlagBits::eDepth; + desc.view_info.usage = vk::ImageUsageFlagBits::eDepthStencilAttachment; + desc.view_info.level_count = levels; + desc.view_info.layer_count = layers; + desc.view_info.type = layers > 1 ? vk::ImageViewType::e2DArray + : vk::ImageViewType::e2D; + return desc; + }; + const auto depth_texels = [](float first, float second) { + return std::vector<u32>{std::bit_cast<u32>(first), + std::bit_cast<u32>(second)}; + }; + constexpr uint32_t depth_array_layers = 4; + constexpr std::array<float, 2 * depth_array_layers> depth_guest{ + 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.75f, 0.875f, 1.0f}; + { + constexpr uint64_t offset = 0x4ba0000; + constexpr std::array<float, 2> mip_clears{0.0625f, 0.9375f}; + constexpr float layer_clear = 0.3125f; + std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest)); + auto cached = linear_d32(base + offset, 3 * sizeof(float), 2, 1); + cached.info.mip_layout[0] = {0, 2 * sizeof(float), 2, 1}; + cached.info.mip_layout[1] = {2 * sizeof(float), sizeof(float), 1, 1}; + auto requested = + linear_d32(base + offset, sizeof(depth_guest), 1, depth_array_layers); + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindDepthTarget(before, cached); + for (uint32_t mip = 0; mip < mip_clears.size(); ++mip) { + vk::ClearValue clear{}; + clear.depthStencil.depth = mip_clears[mip]; + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eDepth, mip, 1, 0, 1}, clear); + } + const auto after = texture_cache.FindImage(requested); + Require(name, "depth layer growth", + after != before && + !TextureCacheTestAccess::Contains(texture_cache, before) && + texture_cache.GetImage(after).info.resources == + requested.info.resources, + "insufficient depth backing was retained"); + (void)texture_cache.FindDepthTarget(after, requested); + Require(name, "depth layer growth contents", + ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 0) == + depth_texels(mip_clears[0], mip_clears[0]) && + ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 1) == + depth_texels(mip_clears[1], depth_guest[3]) && + ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 3) == + depth_texels(depth_guest[6], depth_guest[7]), + "lost a GPU-only depth mip or failed to initialize the added layers"); + vk::ClearValue clear{}; + clear.depthStencil.depth = layer_clear; + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), after, + {vk::ImageAspectFlagBits::eDepth, 0, 1, 1, 1}, clear); + const auto restored = texture_cache.FindImage(cached); + (void)texture_cache.FindDepthTarget(restored, cached); + Require(name, "depth mip round trip", + ReadCachedTexel(name, context, restored, {}, {1, 1, 1}, 0, 1) == + std::vector<u32>{std::bit_cast<u32>(layer_clear)}, + "retiring the depth array lost GPU-written guest bytes"); + } + { + constexpr uint64_t offset = 0x4bc0000; + constexpr uint64_t htile_address = base + offset + 0x800; + constexpr std::array<float, 2> mip_clears{0.0625f, 0.9375f}; + std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest)); + auto cached = linear_d32(base + offset, 3 * sizeof(float), 2, 1); + cached.info.mip_layout[0] = {0, 2 * sizeof(float), 2, 1}; + cached.info.mip_layout[1] = {2 * sizeof(float), sizeof(float), 1, 1}; + cached.info.metadata.kind = ImageMetadataKind::Htile; + cached.info.metadata.range = {htile_address, 0x200}; + cached.info.htile_initial_clear = true; + auto sampled = MakeLinearDesc( + base + offset, sizeof(depth_guest), vk::Format::eR32Sfloat, + Prospero::BufferFormat::k32Float, Prospero::ImageType::kColor2D, + {2, 1, 1}, depth_array_layers, sizeof(float), 1); + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindDepthTarget(before, cached); + for (uint32_t mip = 0; mip < mip_clears.size(); ++mip) { + vk::ClearValue clear{}; + clear.depthStencil.depth = mip_clears[mip]; + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eDepth, mip, 1, 0, 1}, clear); + } + const auto grown = texture_cache.FindImage(sampled); + Require(name, "sampled depth growth over a dropped mip", + grown != before && + !TextureCacheTestAccess::Contains(texture_cache, before) && + texture_cache.GetImage(grown).backing.format == + vk::Format::eD32Sfloat && + texture_cache.GetImage(grown).info.resources == + sampled.info.resources && + texture_cache.IsMetaCleared(htile_address, 0), + "the grown depth array lost its pending HTile clears"); + Require(name, "sampled depth growth contents", + texture_cache.FindTexture(grown, sampled) != nullptr && + ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 0) == + depth_texels(mip_clears[0], mip_clears[0]) && + ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 1) == + depth_texels(mip_clears[1], depth_guest[3]) && + ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 3) == + depth_texels(depth_guest[6], depth_guest[7]), + "the grown depth array lost a GPU-only mip or skipped guest memory"); + } + { + constexpr uint64_t offset = 0x4bb0000; + std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest)); + auto cached = linear_d32(base + offset, 2 * sizeof(float), 1, 1); + auto requested = + linear_d32(base + offset, sizeof(depth_guest), 1, depth_array_layers); + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindDepthTarget(before, cached); ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Functional Correctness** · **Quick win** **Keep the source backing free of GPU modifications in the guest-only test.** `FindDepthTarget` calls `CommitGpuWrite`, which marks `before` as GPU-modified even without a draw or clear. The layer 3 assertion can still pass because this growth keeps all old subresources and takes the copy path. The test therefore does not exercise growth from a backing with no GPU modifications. Replace the first `FindDepthTarget` call with `UpdateImage(before)` and assert `!texture_cache.GetImage(before).IsGpuModified()` before requesting the larger image. Keep the final depth-target acquisition and readback. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/94a5d60fae90cab128f4780a46ba2fe0cb117225/src/graphics/host_gpu/renderer/cache/textureCache.cpp)) <!-- fingerprinting:phantom:medusa:wombat62 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:2ecd66083eb0cd5e959bb042 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commits 10f064f to 9535d52
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-20 22:41 UTC · original · reviewed

Actionable comments posted: 2

Nitpick comments: 1

tests/ShaderRecompilerComputeTests.cpp: 1

7440-7440: Trivial · Maintainability & Code Quality · Quick win

Check that HTile growth preserves both pending and consumed clears.

FindDepthTarget starts with every clear bit set. The assertion checks only slice 0, so it also passes if growth resets all bits to pending. Before growth, call TouchMeta(htile_address, 0, false) and require it to succeed. After growth, check that slice 0 is still consumed and slice 1 is still pending. (raw.githubusercontent.com)

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 65cdc6fa85 and 94a5d60fae.

Files selected for processing: 3

  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/image/imageInfo.h
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-20 22:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#pullrequestreview-6000352592) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 2** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/brush-cleaning-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/brush-cleaning.svg" width="16" height="16" align="absmiddle" alt=""></picture> Nitpick comments: 1</summary><blockquote> <dl> <dd> <br> <details> <summary>tests/ShaderRecompilerComputeTests.cpp: 1</summary><blockquote> <dl> <dd> <br> `7440-7440`: **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/neutral-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Trivial** · **Maintainability & Code Quality** · **Quick win** **Check that HTile growth preserves both pending and consumed clears.** `FindDepthTarget` starts with every clear bit set. The assertion checks only slice 0, so it also passes if growth resets all bits to pending. Before growth, call `TouchMeta(htile_address, 0, false)` and require it to succeed. After growth, check that slice 0 is still consumed and slice 1 is still pending. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/94a5d60fae90cab128f4780a46ba2fe0cb117225/src/graphics/host_gpu/renderer/cache/textureCache.cpp)) <!-- cr-comment:v1:0dcdf898c31ce8d7bbf15482 --> </dd> </dl> </blockquote></details> </dd> </dl> </blockquote></details> <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <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> <br> - **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/a21fd80c8e570ebcde9248deec9c711c252ebc77/.coderabbit.yaml>) - **Commit**: [a21fd80](<https://github.com/KytyPS5/KytyPS5/commit/a21fd80c8e570ebcde9248deec9c711c252ebc77>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `b2ac4add-6e90-49ae-bb80-08c6642fc650` </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> <br> Reviewing files that changed from the base of the PR and between 65cdc6fa850f5e72f433baf2d6ba4d52a454a2c7 and 94a5d60fae90cab128f4780a46ba2fe0cb117225. </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> <br> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/image/imageInfo.h` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=046f99d6-79db-490b-9e1c-ca798d810843 attempt=242e8529-e049-46c0-9105-4cebaaab77d7 batch=1/1 -->
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-20 23:52 UTC · original
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 907 (outdated):

@@ -891,6 +898,20 @@ ImageId TextureCache::ExpandImage(const ImageInfo& info, ImageId source_id) {
 	return expanded_id;
 }
 
+bool TextureCache::RetireThroughGuestMemory(ImageId replacement_id, ImageId retired_id) {
+	const auto& replacement = m_slot_images[replacement_id].info;
+	auto&       retired     = m_slot_images[retired_id];
+	if (replacement.type != retired.info.type ||
+	    replacement.resources.Contains(retired.info.resources) || replacement.samples != 1 ||
+	    replacement.metadata.compression != VideoOutCompression::Uncompressed ||
+	    !retired.SafeToDownload() || !BcAlias::Publish(*this, retired)) {

@⁠coderabbitai Confirmed and fixed in 9535d526c. An image without GPU writes failed SafeToDownload(), so RetireThroughGuestMemory declined it, and ExpandImage copied it by subresource index after initializing the replacement from guest memory. RetireThroughGuestMemory now retires such an image the same way (initialize the replacement from memory, free the old image) and publishes only images with GPU writes. A GPU-written image that cannot be published still takes the copy path.

New case in UnifiedTextureCacheFlow ("guest-current array growth contents"): a 256x256 R8 kStandard64KB image with 9 levels, uploaded from guest memory only, then read as 1 level x 8 layers. Level 0 sits in a later layer, and each layer has its own guest bytes. It fails on 10f064fa9 (layer 0 gets level 0's bytes) and passes with the change.

**@⁠Nawid3333** on GitHub · 2026-11-20 23:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#discussion_r4649046141) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 907 (outdated): ```diff @@ -891,6 +898,20 @@ ImageId TextureCache::ExpandImage(const ImageInfo& info, ImageId source_id) { return expanded_id; } +bool TextureCache::RetireThroughGuestMemory(ImageId replacement_id, ImageId retired_id) { + const auto& replacement = m_slot_images[replacement_id].info; + auto& retired = m_slot_images[retired_id]; + if (replacement.type != retired.info.type || + replacement.resources.Contains(retired.info.resources) || replacement.samples != 1 || + replacement.metadata.compression != VideoOutCompression::Uncompressed || + !retired.SafeToDownload() || !BcAlias::Publish(*this, retired)) { ``` @⁠coderabbitai Confirmed and fixed in 9535d526c. An image without GPU writes failed `SafeToDownload()`, so `RetireThroughGuestMemory` declined it, and `ExpandImage` copied it by subresource index after initializing the replacement from guest memory. `RetireThroughGuestMemory` now retires such an image the same way (initialize the replacement from memory, free the old image) and publishes only images with GPU writes. A GPU-written image that cannot be published still takes the copy path. New case in `UnifiedTextureCacheFlow` ("guest-current array growth contents"): a 256x256 R8 `kStandard64KB` image with 9 levels, uploaded from guest memory only, then read as 1 level x 8 layers. Level 0 sits in a later layer, and each layer has its own guest bytes. It fails on 10f064fa9 (layer 0 gets level 0's bytes) and passes with the change.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-20 23:52 UTC · original
On tests/ShaderRecompilerComputeTests.cpp line 7459 (outdated):

@@ -7168,6 +7168,307 @@ class VulkanHarness {
               "wide/block image readback was not aligned to its texel block");
       resources.MapMemory(base, allocation_size);
 
+      {
+        constexpr uint64_t offset = 0x4800000;
+        std::memset(memory + offset, 0x5a, 0x2c0000);
+        auto cached = MakeLinearDesc(
+            base + offset, 0, vk::Format::eR8Uint,
+            Prospero::BufferFormat::k8UInt, Prospero::ImageType::kColor2D,
+            {1024, 1024, 1}, 1, 1, 1);
+        cached.info.tile_mode = Prospero::TileMode::kStandard64KB;
+        cached.info.resources = {11, 1};
+        cached.view_info.level_count = 11;
+        cached.info.UpdateSize();
+        auto requested = cached;
+        requested.info.data.size = 0;
+        requested.info.resources = {9, 2};
+        requested.view_info.level_count = 9;
+        requested.view_info.layer_count = 2;
+        requested.view_info.type = vk::ImageViewType::e2DArray;
+        requested.info.UpdateSize();
+        Require(name, "mixed resource footprints",
+                cached.info.data.size == 0x160000 &&
+                    requested.info.data.size == 0x2c0000 &&
+                    cached.info.first_tail_level == 3 &&
+                    requested.info.first_tail_level == 3,
+                "unexpected tiled fixture layout");
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(before, cached);
+        for (uint32_t mip = 0; mip < cached.info.resources.levels; ++mip) {
+          vk::ClearValue clear{};
+          clear.color.uint32.fill(0x10u + mip);
+          TextureCacheTestAccess::ClearImage(
+              texture_cache, scheduler.Current(), before,
+              {vk::ImageAspectFlagBits::eColor, mip, 1, 0, 1}, clear);
+        }
+        const auto after = texture_cache.FindImage(requested);
+        Require(name, "layer growth with fewer levels",
+                after != before &&
+                    !TextureCacheTestAccess::Contains(texture_cache, before) &&
+                    texture_cache.GetImage(after).info.resources ==
+                        requested.info.resources,
+                "insufficient backing was retained");
+        (void)texture_cache.FindTexture(after, requested);
+        for (uint32_t mip = 0; mip < 9; ++mip) {
+          Require(name, "mixed resource contents",
+                  ReadCachedTexel(name, context, after, {}, {4, 1, 1}, 0, mip) ==
+                          std::vector<u32>{(0x10u + mip) * 0x01010101u} &&
+                      ReadCachedTexel(name, context, after, {}, {4, 1, 1}, 1, mip) ==
+                          std::vector<u32>{0x5a5a5a5au},
+                  "lost GPU contents or failed to initialize the added layer");
+        }
+        const auto restored = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(restored, cached);
+        Require(name, "mixed resource round trip",
+                ReadCachedTexel(name, context, restored, {}, {2, 2, 1}, 0, 9) ==
+                    std::vector<u32>{0x19191919u},
+                "retiring the mip chain lost a GPU-only tail mip");
+      }
+      {
+        constexpr uint64_t offset = 0x4b10000;
+        constexpr uint32_t requested_layers = 8;
+        std::memset(memory + offset, 0x6b, 0x80000);
+        auto cached = MakeLinearDesc(
+            base + offset, 0, vk::Format::eR8Uint,
+            Prospero::BufferFormat::k8UInt, Prospero::ImageType::kColor2D,
+            {256, 256, 1}, 1, 1, 1);
+        cached.info.tile_mode = Prospero::TileMode::kStandard64KB;
+        cached.info.resources = {9, 1};
+        cached.view_info.level_count = 9;
+        cached.info.UpdateSize();
+        auto requested = cached;
+        requested.info.data.size = 0;
+        requested.info.resources = {1, requested_layers};
+        requested.view_info.level_count = 1;
+        requested.view_info.layer_count = requested_layers;
+        requested.view_info.type = vk::ImageViewType::e2DArray;
+        requested.info.UpdateSize();
+        const uint64_t layer_size = requested.info.data.size / requested_layers;
+        const uint32_t mip0_layer =
+            static_cast<uint32_t>(cached.info.mip_layout[0].offset / layer_size);
+        Require(name, "array footprints",
+                requested.info.data.size == 0x80000 &&
+                    requested.info.data.size > cached.info.data.size &&
+                    cached.info.mip_layout[0].offset % layer_size == 0 &&
+                    mip0_layer + 1 < requested_layers,
+                "unexpected tiled array fixture layout");
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(before, cached);
+        vk::ClearValue clear{};
+        clear.color.uint32.fill(0x21u);
+        TextureCacheTestAccess::ClearImage(
+            texture_cache, scheduler.Current(), before,
+            {vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1}, clear);
+        clear.color.uint32.fill(0x37u);
+        TextureCacheTestAccess::ClearImage(
+            texture_cache, scheduler.Current(), before,
+            {vk::ImageAspectFlagBits::eColor, 1, 1, 0, 1}, clear);
+        const auto after = texture_cache.FindImage(requested);
+        Require(name, "array growth with one level",
+                after != before &&
+                    !TextureCacheTestAccess::Contains(texture_cache, before) &&
+                    texture_cache.GetImage(after).info.resources ==
+                        requested.info.resources,
+                "insufficient backing was retained");
+        (void)texture_cache.FindTexture(after, requested);
+        Require(name, "array growth contents",
+                ReadCachedTexel(name, context, after, {}, {4, 1, 1}, mip0_layer) ==
+                        std::vector<u32>{0x21212121u} &&
+                    ReadCachedTexel(name, context, after, {}, {4, 1, 1},
+                                    requested_layers - 1) ==
+                        std::vector<u32>{0x6b6b6b6bu},
+                "lost GPU contents or failed to initialize the added layers");
+        const auto restored = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(restored, cached);
+        Require(name, "array resource round trip",
+                ReadCachedTexel(name, context, restored, {}, {4, 1, 1}, 0, 1) ==
+                    std::vector<u32>{0x37373737u},
+                "retiring the mip chain lost a GPU-only mip");
+      }
+      {
+        constexpr uint64_t offset = 0x4b00000;
+        const std::array<uint32_t, 4> values{
+            0x11111111u, 0x22222222u, 0x33333333u, 0x44444444u};
+        std::memcpy(memory + offset, values.data(), sizeof(values));
+        auto cached = MakeLinearDesc(
+            base + offset, sizeof(values), vk::Format::eR32Uint,
+            Prospero::BufferFormat::k32UInt, Prospero::ImageType::kColor2D,
+            {2, 1, 1}, 1, 4, 1);
+        cached.info.resources = {2, 1};
+        cached.info.mip_layout[0] = {0, 8, 2, 1};
+        cached.info.mip_layout[1] = {8, 4, 1, 1};
+        cached.view_info.level_count = 2;
+        auto requested = MakeLinearDesc(
+            base + offset, sizeof(values), vk::Format::eR32Uint,
+            Prospero::BufferFormat::k32UInt, Prospero::ImageType::kColor2D,
+            {2, 1, 1}, 2, 4, 1);
+        requested.view_info.base_layer = 1;
+        requested.view_info.layer_count = 1;
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(before, cached);
+        vk::ClearValue clear{};
+        clear.color.uint32.fill(0xabcdef01u);
+        TextureCacheTestAccess::ClearImage(
+            texture_cache, scheduler.Current(), before,
+            {vk::ImageAspectFlagBits::eColor, 1, 1, 0, 1}, clear);
+        const auto after = texture_cache.FindImage(requested);
+        Require(name, "missing-layer fallback replacement",
+                after != before &&
+                    !TextureCacheTestAccess::Contains(texture_cache, before) &&
+                    texture_cache.GetImage(after).info.resources ==
+                        requested.info.resources,
+                "FindImage returned a backing without the requested layer");
+        Require(name, "missing-layer texture acquisition",
+                texture_cache.FindTexture(after, requested) != nullptr &&
+                    ReadCachedTexel(name, context, after, {}, {1, 1, 1}, 1) ==
+                        std::vector<u32>{0xabcdef01u},
+                "the requested layer lost GPU-written guest bytes");
+        clear.color.uint32.fill(0x55667788u);
+        TextureCacheTestAccess::ClearImage(
+            texture_cache, scheduler.Current(), after,
+            {vk::ImageAspectFlagBits::eColor, 0, 1, 1, 1}, clear);
+        const auto restored = texture_cache.FindImage(cached);
+        (void)texture_cache.FindTexture(restored, cached);
+        Require(name, "missing-layer round trip",
+                ReadCachedTexel(name, context, restored, {}, {1, 1, 1}, 0, 1) ==
+                    std::vector<u32>{0x55667788u},
+                "retiring the array lost GPU-written guest bytes");
+      }
+      const auto linear_d32 = [](uint64_t address, uint64_t size,
+                                 uint32_t levels, uint32_t layers) {
+        auto desc = MakeLinearDesc(address, size, vk::Format::eD32Sfloat,
+                                   Prospero::BufferFormat::k32Float,
+                                   Prospero::ImageType::kColor2D, {2, 1, 1},
+                                   layers, sizeof(float), 1);
+        desc.type = BindingType::DepthTarget;
+        desc.info.resources.levels = levels;
+        desc.view_info.format = vk::Format::eD32Sfloat;
+        desc.view_info.aspect = vk::ImageAspectFlagBits::eDepth;
+        desc.view_info.usage = vk::ImageUsageFlagBits::eDepthStencilAttachment;
+        desc.view_info.level_count = levels;
+        desc.view_info.layer_count = layers;
+        desc.view_info.type = layers > 1 ? vk::ImageViewType::e2DArray
+                                         : vk::ImageViewType::e2D;
+        return desc;
+      };
+      const auto depth_texels = [](float first, float second) {
+        return std::vector<u32>{std::bit_cast<u32>(first),
+                                std::bit_cast<u32>(second)};
+      };
+      constexpr uint32_t depth_array_layers = 4;
+      constexpr std::array<float, 2 * depth_array_layers> depth_guest{
+          0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.75f, 0.875f, 1.0f};
+      {
+        constexpr uint64_t offset = 0x4ba0000;
+        constexpr std::array<float, 2> mip_clears{0.0625f, 0.9375f};
+        constexpr float layer_clear = 0.3125f;
+        std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest));
+        auto cached = linear_d32(base + offset, 3 * sizeof(float), 2, 1);
+        cached.info.mip_layout[0] = {0, 2 * sizeof(float), 2, 1};
+        cached.info.mip_layout[1] = {2 * sizeof(float), sizeof(float), 1, 1};
+        auto requested =
+            linear_d32(base + offset, sizeof(depth_guest), 1, depth_array_layers);
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindDepthTarget(before, cached);
+        for (uint32_t mip = 0; mip < mip_clears.size(); ++mip) {
+          vk::ClearValue clear{};
+          clear.depthStencil.depth = mip_clears[mip];
+          TextureCacheTestAccess::ClearImage(
+              texture_cache, scheduler.Current(), before,
+              {vk::ImageAspectFlagBits::eDepth, mip, 1, 0, 1}, clear);
+        }
+        const auto after = texture_cache.FindImage(requested);
+        Require(name, "depth layer growth",
+                after != before &&
+                    !TextureCacheTestAccess::Contains(texture_cache, before) &&
+                    texture_cache.GetImage(after).info.resources ==
+                        requested.info.resources,
+                "insufficient depth backing was retained");
+        (void)texture_cache.FindDepthTarget(after, requested);
+        Require(name, "depth layer growth contents",
+                ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 0) ==
+                        depth_texels(mip_clears[0], mip_clears[0]) &&
+                    ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 1) ==
+                        depth_texels(mip_clears[1], depth_guest[3]) &&
+                    ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 3) ==
+                        depth_texels(depth_guest[6], depth_guest[7]),
+                "lost a GPU-only depth mip or failed to initialize the added layers");
+        vk::ClearValue clear{};
+        clear.depthStencil.depth = layer_clear;
+        TextureCacheTestAccess::ClearImage(
+            texture_cache, scheduler.Current(), after,
+            {vk::ImageAspectFlagBits::eDepth, 0, 1, 1, 1}, clear);
+        const auto restored = texture_cache.FindImage(cached);
+        (void)texture_cache.FindDepthTarget(restored, cached);
+        Require(name, "depth mip round trip",
+                ReadCachedTexel(name, context, restored, {}, {1, 1, 1}, 0, 1) ==
+                    std::vector<u32>{std::bit_cast<u32>(layer_clear)},
+                "retiring the depth array lost GPU-written guest bytes");
+      }
+      {
+        constexpr uint64_t offset = 0x4bc0000;
+        constexpr uint64_t htile_address = base + offset + 0x800;
+        constexpr std::array<float, 2> mip_clears{0.0625f, 0.9375f};
+        std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest));
+        auto cached = linear_d32(base + offset, 3 * sizeof(float), 2, 1);
+        cached.info.mip_layout[0] = {0, 2 * sizeof(float), 2, 1};
+        cached.info.mip_layout[1] = {2 * sizeof(float), sizeof(float), 1, 1};
+        cached.info.metadata.kind = ImageMetadataKind::Htile;
+        cached.info.metadata.range = {htile_address, 0x200};
+        cached.info.htile_initial_clear = true;
+        auto sampled = MakeLinearDesc(
+            base + offset, sizeof(depth_guest), vk::Format::eR32Sfloat,
+            Prospero::BufferFormat::k32Float, Prospero::ImageType::kColor2D,
+            {2, 1, 1}, depth_array_layers, sizeof(float), 1);
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindDepthTarget(before, cached);
+        for (uint32_t mip = 0; mip < mip_clears.size(); ++mip) {
+          vk::ClearValue clear{};
+          clear.depthStencil.depth = mip_clears[mip];
+          TextureCacheTestAccess::ClearImage(
+              texture_cache, scheduler.Current(), before,
+              {vk::ImageAspectFlagBits::eDepth, mip, 1, 0, 1}, clear);
+        }
+        const auto grown = texture_cache.FindImage(sampled);
+        Require(name, "sampled depth growth over a dropped mip",
+                grown != before &&
+                    !TextureCacheTestAccess::Contains(texture_cache, before) &&
+                    texture_cache.GetImage(grown).backing.format ==
+                        vk::Format::eD32Sfloat &&
+                    texture_cache.GetImage(grown).info.resources ==
+                        sampled.info.resources &&
+                    texture_cache.IsMetaCleared(htile_address, 0),
+                "the grown depth array lost its pending HTile clears");
+        Require(name, "sampled depth growth contents",
+                texture_cache.FindTexture(grown, sampled) != nullptr &&
+                    ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 0) ==
+                        depth_texels(mip_clears[0], mip_clears[0]) &&
+                    ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 1) ==
+                        depth_texels(mip_clears[1], depth_guest[3]) &&
+                    ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 3) ==
+                        depth_texels(depth_guest[6], depth_guest[7]),
+                "the grown depth array lost a GPU-only mip or skipped guest memory");
+      }
+      {
+        constexpr uint64_t offset = 0x4bb0000;
+        std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest));
+        auto cached = linear_d32(base + offset, 2 * sizeof(float), 1, 1);
+        auto requested =
+            linear_d32(base + offset, sizeof(depth_guest), 1, depth_array_layers);
+        const auto before = texture_cache.FindImage(cached);
+        (void)texture_cache.FindDepthTarget(before, cached);

@⁠coderabbitai Done in 10f064fa9: the guest-only depth case now uploads the source with UpdateImage(before), requires !IsGpuModified() before the growth, and keeps the final depth-target acquisition and readback.

The same commit takes the HTile nitpick from the review: before the growth the test consumes slice 0 with TouchMeta(htile_address, 0, false), and afterwards it requires slice 0 to stay consumed and slice 1 to stay pending.

**@⁠Nawid3333** on GitHub · 2026-11-20 23:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#discussion_r4649050218) On `tests/ShaderRecompilerComputeTests.cpp` line 7459 (outdated): ```diff @@ -7168,6 +7168,307 @@ class VulkanHarness { "wide/block image readback was not aligned to its texel block"); resources.MapMemory(base, allocation_size); + { + constexpr uint64_t offset = 0x4800000; + std::memset(memory + offset, 0x5a, 0x2c0000); + auto cached = MakeLinearDesc( + base + offset, 0, vk::Format::eR8Uint, + Prospero::BufferFormat::k8UInt, Prospero::ImageType::kColor2D, + {1024, 1024, 1}, 1, 1, 1); + cached.info.tile_mode = Prospero::TileMode::kStandard64KB; + cached.info.resources = {11, 1}; + cached.view_info.level_count = 11; + cached.info.UpdateSize(); + auto requested = cached; + requested.info.data.size = 0; + requested.info.resources = {9, 2}; + requested.view_info.level_count = 9; + requested.view_info.layer_count = 2; + requested.view_info.type = vk::ImageViewType::e2DArray; + requested.info.UpdateSize(); + Require(name, "mixed resource footprints", + cached.info.data.size == 0x160000 && + requested.info.data.size == 0x2c0000 && + cached.info.first_tail_level == 3 && + requested.info.first_tail_level == 3, + "unexpected tiled fixture layout"); + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(before, cached); + for (uint32_t mip = 0; mip < cached.info.resources.levels; ++mip) { + vk::ClearValue clear{}; + clear.color.uint32.fill(0x10u + mip); + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eColor, mip, 1, 0, 1}, clear); + } + const auto after = texture_cache.FindImage(requested); + Require(name, "layer growth with fewer levels", + after != before && + !TextureCacheTestAccess::Contains(texture_cache, before) && + texture_cache.GetImage(after).info.resources == + requested.info.resources, + "insufficient backing was retained"); + (void)texture_cache.FindTexture(after, requested); + for (uint32_t mip = 0; mip < 9; ++mip) { + Require(name, "mixed resource contents", + ReadCachedTexel(name, context, after, {}, {4, 1, 1}, 0, mip) == + std::vector<u32>{(0x10u + mip) * 0x01010101u} && + ReadCachedTexel(name, context, after, {}, {4, 1, 1}, 1, mip) == + std::vector<u32>{0x5a5a5a5au}, + "lost GPU contents or failed to initialize the added layer"); + } + const auto restored = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(restored, cached); + Require(name, "mixed resource round trip", + ReadCachedTexel(name, context, restored, {}, {2, 2, 1}, 0, 9) == + std::vector<u32>{0x19191919u}, + "retiring the mip chain lost a GPU-only tail mip"); + } + { + constexpr uint64_t offset = 0x4b10000; + constexpr uint32_t requested_layers = 8; + std::memset(memory + offset, 0x6b, 0x80000); + auto cached = MakeLinearDesc( + base + offset, 0, vk::Format::eR8Uint, + Prospero::BufferFormat::k8UInt, Prospero::ImageType::kColor2D, + {256, 256, 1}, 1, 1, 1); + cached.info.tile_mode = Prospero::TileMode::kStandard64KB; + cached.info.resources = {9, 1}; + cached.view_info.level_count = 9; + cached.info.UpdateSize(); + auto requested = cached; + requested.info.data.size = 0; + requested.info.resources = {1, requested_layers}; + requested.view_info.level_count = 1; + requested.view_info.layer_count = requested_layers; + requested.view_info.type = vk::ImageViewType::e2DArray; + requested.info.UpdateSize(); + const uint64_t layer_size = requested.info.data.size / requested_layers; + const uint32_t mip0_layer = + static_cast<uint32_t>(cached.info.mip_layout[0].offset / layer_size); + Require(name, "array footprints", + requested.info.data.size == 0x80000 && + requested.info.data.size > cached.info.data.size && + cached.info.mip_layout[0].offset % layer_size == 0 && + mip0_layer + 1 < requested_layers, + "unexpected tiled array fixture layout"); + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(before, cached); + vk::ClearValue clear{}; + clear.color.uint32.fill(0x21u); + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1}, clear); + clear.color.uint32.fill(0x37u); + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eColor, 1, 1, 0, 1}, clear); + const auto after = texture_cache.FindImage(requested); + Require(name, "array growth with one level", + after != before && + !TextureCacheTestAccess::Contains(texture_cache, before) && + texture_cache.GetImage(after).info.resources == + requested.info.resources, + "insufficient backing was retained"); + (void)texture_cache.FindTexture(after, requested); + Require(name, "array growth contents", + ReadCachedTexel(name, context, after, {}, {4, 1, 1}, mip0_layer) == + std::vector<u32>{0x21212121u} && + ReadCachedTexel(name, context, after, {}, {4, 1, 1}, + requested_layers - 1) == + std::vector<u32>{0x6b6b6b6bu}, + "lost GPU contents or failed to initialize the added layers"); + const auto restored = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(restored, cached); + Require(name, "array resource round trip", + ReadCachedTexel(name, context, restored, {}, {4, 1, 1}, 0, 1) == + std::vector<u32>{0x37373737u}, + "retiring the mip chain lost a GPU-only mip"); + } + { + constexpr uint64_t offset = 0x4b00000; + const std::array<uint32_t, 4> values{ + 0x11111111u, 0x22222222u, 0x33333333u, 0x44444444u}; + std::memcpy(memory + offset, values.data(), sizeof(values)); + auto cached = MakeLinearDesc( + base + offset, sizeof(values), vk::Format::eR32Uint, + Prospero::BufferFormat::k32UInt, Prospero::ImageType::kColor2D, + {2, 1, 1}, 1, 4, 1); + cached.info.resources = {2, 1}; + cached.info.mip_layout[0] = {0, 8, 2, 1}; + cached.info.mip_layout[1] = {8, 4, 1, 1}; + cached.view_info.level_count = 2; + auto requested = MakeLinearDesc( + base + offset, sizeof(values), vk::Format::eR32Uint, + Prospero::BufferFormat::k32UInt, Prospero::ImageType::kColor2D, + {2, 1, 1}, 2, 4, 1); + requested.view_info.base_layer = 1; + requested.view_info.layer_count = 1; + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(before, cached); + vk::ClearValue clear{}; + clear.color.uint32.fill(0xabcdef01u); + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eColor, 1, 1, 0, 1}, clear); + const auto after = texture_cache.FindImage(requested); + Require(name, "missing-layer fallback replacement", + after != before && + !TextureCacheTestAccess::Contains(texture_cache, before) && + texture_cache.GetImage(after).info.resources == + requested.info.resources, + "FindImage returned a backing without the requested layer"); + Require(name, "missing-layer texture acquisition", + texture_cache.FindTexture(after, requested) != nullptr && + ReadCachedTexel(name, context, after, {}, {1, 1, 1}, 1) == + std::vector<u32>{0xabcdef01u}, + "the requested layer lost GPU-written guest bytes"); + clear.color.uint32.fill(0x55667788u); + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), after, + {vk::ImageAspectFlagBits::eColor, 0, 1, 1, 1}, clear); + const auto restored = texture_cache.FindImage(cached); + (void)texture_cache.FindTexture(restored, cached); + Require(name, "missing-layer round trip", + ReadCachedTexel(name, context, restored, {}, {1, 1, 1}, 0, 1) == + std::vector<u32>{0x55667788u}, + "retiring the array lost GPU-written guest bytes"); + } + const auto linear_d32 = [](uint64_t address, uint64_t size, + uint32_t levels, uint32_t layers) { + auto desc = MakeLinearDesc(address, size, vk::Format::eD32Sfloat, + Prospero::BufferFormat::k32Float, + Prospero::ImageType::kColor2D, {2, 1, 1}, + layers, sizeof(float), 1); + desc.type = BindingType::DepthTarget; + desc.info.resources.levels = levels; + desc.view_info.format = vk::Format::eD32Sfloat; + desc.view_info.aspect = vk::ImageAspectFlagBits::eDepth; + desc.view_info.usage = vk::ImageUsageFlagBits::eDepthStencilAttachment; + desc.view_info.level_count = levels; + desc.view_info.layer_count = layers; + desc.view_info.type = layers > 1 ? vk::ImageViewType::e2DArray + : vk::ImageViewType::e2D; + return desc; + }; + const auto depth_texels = [](float first, float second) { + return std::vector<u32>{std::bit_cast<u32>(first), + std::bit_cast<u32>(second)}; + }; + constexpr uint32_t depth_array_layers = 4; + constexpr std::array<float, 2 * depth_array_layers> depth_guest{ + 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.75f, 0.875f, 1.0f}; + { + constexpr uint64_t offset = 0x4ba0000; + constexpr std::array<float, 2> mip_clears{0.0625f, 0.9375f}; + constexpr float layer_clear = 0.3125f; + std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest)); + auto cached = linear_d32(base + offset, 3 * sizeof(float), 2, 1); + cached.info.mip_layout[0] = {0, 2 * sizeof(float), 2, 1}; + cached.info.mip_layout[1] = {2 * sizeof(float), sizeof(float), 1, 1}; + auto requested = + linear_d32(base + offset, sizeof(depth_guest), 1, depth_array_layers); + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindDepthTarget(before, cached); + for (uint32_t mip = 0; mip < mip_clears.size(); ++mip) { + vk::ClearValue clear{}; + clear.depthStencil.depth = mip_clears[mip]; + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eDepth, mip, 1, 0, 1}, clear); + } + const auto after = texture_cache.FindImage(requested); + Require(name, "depth layer growth", + after != before && + !TextureCacheTestAccess::Contains(texture_cache, before) && + texture_cache.GetImage(after).info.resources == + requested.info.resources, + "insufficient depth backing was retained"); + (void)texture_cache.FindDepthTarget(after, requested); + Require(name, "depth layer growth contents", + ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 0) == + depth_texels(mip_clears[0], mip_clears[0]) && + ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 1) == + depth_texels(mip_clears[1], depth_guest[3]) && + ReadCachedTexel(name, context, after, {}, {2, 1, 1}, 3) == + depth_texels(depth_guest[6], depth_guest[7]), + "lost a GPU-only depth mip or failed to initialize the added layers"); + vk::ClearValue clear{}; + clear.depthStencil.depth = layer_clear; + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), after, + {vk::ImageAspectFlagBits::eDepth, 0, 1, 1, 1}, clear); + const auto restored = texture_cache.FindImage(cached); + (void)texture_cache.FindDepthTarget(restored, cached); + Require(name, "depth mip round trip", + ReadCachedTexel(name, context, restored, {}, {1, 1, 1}, 0, 1) == + std::vector<u32>{std::bit_cast<u32>(layer_clear)}, + "retiring the depth array lost GPU-written guest bytes"); + } + { + constexpr uint64_t offset = 0x4bc0000; + constexpr uint64_t htile_address = base + offset + 0x800; + constexpr std::array<float, 2> mip_clears{0.0625f, 0.9375f}; + std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest)); + auto cached = linear_d32(base + offset, 3 * sizeof(float), 2, 1); + cached.info.mip_layout[0] = {0, 2 * sizeof(float), 2, 1}; + cached.info.mip_layout[1] = {2 * sizeof(float), sizeof(float), 1, 1}; + cached.info.metadata.kind = ImageMetadataKind::Htile; + cached.info.metadata.range = {htile_address, 0x200}; + cached.info.htile_initial_clear = true; + auto sampled = MakeLinearDesc( + base + offset, sizeof(depth_guest), vk::Format::eR32Sfloat, + Prospero::BufferFormat::k32Float, Prospero::ImageType::kColor2D, + {2, 1, 1}, depth_array_layers, sizeof(float), 1); + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindDepthTarget(before, cached); + for (uint32_t mip = 0; mip < mip_clears.size(); ++mip) { + vk::ClearValue clear{}; + clear.depthStencil.depth = mip_clears[mip]; + TextureCacheTestAccess::ClearImage( + texture_cache, scheduler.Current(), before, + {vk::ImageAspectFlagBits::eDepth, mip, 1, 0, 1}, clear); + } + const auto grown = texture_cache.FindImage(sampled); + Require(name, "sampled depth growth over a dropped mip", + grown != before && + !TextureCacheTestAccess::Contains(texture_cache, before) && + texture_cache.GetImage(grown).backing.format == + vk::Format::eD32Sfloat && + texture_cache.GetImage(grown).info.resources == + sampled.info.resources && + texture_cache.IsMetaCleared(htile_address, 0), + "the grown depth array lost its pending HTile clears"); + Require(name, "sampled depth growth contents", + texture_cache.FindTexture(grown, sampled) != nullptr && + ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 0) == + depth_texels(mip_clears[0], mip_clears[0]) && + ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 1) == + depth_texels(mip_clears[1], depth_guest[3]) && + ReadCachedTexel(name, context, grown, {}, {2, 1, 1}, 3) == + depth_texels(depth_guest[6], depth_guest[7]), + "the grown depth array lost a GPU-only mip or skipped guest memory"); + } + { + constexpr uint64_t offset = 0x4bb0000; + std::memcpy(memory + offset, depth_guest.data(), sizeof(depth_guest)); + auto cached = linear_d32(base + offset, 2 * sizeof(float), 1, 1); + auto requested = + linear_d32(base + offset, sizeof(depth_guest), 1, depth_array_layers); + const auto before = texture_cache.FindImage(cached); + (void)texture_cache.FindDepthTarget(before, cached); ``` @⁠coderabbitai Done in 10f064fa9: the guest-only depth case now uploads the source with `UpdateImage(before)`, requires `!IsGpuModified()` before the growth, and keeps the final depth-target acquisition and readback. The same commit takes the HTile nitpick from the review: before the growth the test consumes slice 0 with `TouchMeta(htile_address, 0, false)`, and afterwards it requires slice 0 to stay consumed and slice 1 to stay pending.
github-bot force-pushed github-bot/gh-2410 from 9535d526c1 to c65b1abe82 2026-11-27 00:43:32 +00:00 Compare
Author
Owner

@⁠akimfomin on GitHub · 2026-11-27 00:03 UTC · original

PortBridge checked the exact #2410 head c65b1abe against 61db2f88: the Git merge is clean, and the current test runner has an image-overlap filter that reaches the synthetic texture-cache checks without booting a title. Your RX 9070 XT baseline supplies the first device result.

I opened one optional Intel Arc check in PortBridge Test Lab with the two filters and the details to report. You or an interested tester can give that link to an agent and leave only the exact SHA, driver and two outcomes. PortBridge will verify the report, credit its author and link the result back here. AI-assisted source and Git check.

**@⁠akimfomin** on GitHub · 2026-11-27 00:03 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2410#issuecomment-7206134353) PortBridge checked the exact #2410 head `c65b1abe` against `61db2f88`: the Git merge is clean, and the current test runner has an [image-overlap filter](https://github.com/KytyPS5/KytyPS5/blob/c65b1abe825cc4ef2eebd3e8e082f72885f2e3fe/tests/ShaderRecompilerComputeTests.cpp#L59526-L59542) that reaches the synthetic texture-cache checks without booting a title. Your RX 9070 XT baseline supplies the first device result. I opened [one optional Intel Arc check in PortBridge Test Lab](https://github.com/akimfomin/PortBridge/issues/100) with the two filters and the details to report. You or an interested tester can give that link to an agent and leave only the exact SHA, driver and two outcomes. PortBridge will verify the report, credit its author and link the result back here. AI-assisted source and Git check.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2410/head:github-bot/gh-2410'
git switch 'github-bot/gh-2410'

Merge

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