graphics: compare image subresources by containment (Uncharted: Legacy of Thieves Collection) #2410
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2410
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2410"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Nawid3333 on GitHub · 2026-11-19 15:18 UTC · original
Nawid3333:fix/subresource-containment→main· +403 −18 · 4 files · 8 commits · openTwo games stop at the same texture cache check:
(Uncharted: Legacy of Thieves Collection, A Thief's End, #2385) and
(Warhammer Age of Sigmar Realms of Ruin, #774).
ImageSubresourceshas a defaultedoperator<=>, which orders{levels, layers}with levels first. So{1, 8} > {10, 1}is false, andResolveOverlapskips the growth branch for a request with more layers but fewer levels than the cached image.ResolveDepthOverlapandFindImageuse 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</>inResolveOverlap,ResolveDepthOverlapandFindImage.{10, 1}to{1, 8}drops subresources of the cached image, so the old index copy would lose its GPU-written levels.ExpandImagenow 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 needsSafeToDownload), 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. TheFindImagefallback publishes the same way before it frees the image.Contains,ResolveDepthOverlaprecreates 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 asExpandImage(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, also1b0f689df) 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
ResolveDepthOverlapandFindImage. This PR takes only that comparison and adds the publish above and the tests below.Test
--buffer-cache-range-only(UnifiedTextureCacheFlow):requested=9x2 cached=11x1.kStandard64KBtexture 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 withrequested=1x8 cached=9x1. With the change, the old level 0 is found in the layer at its guest offset.ExpandImagepublish this case fails ("retiring the mip chain lost a GPU-only tail mip").9535d526cthis case fails ("a guest-current source overwrote layers at the wrong guest offsets"): layer 0 got level 0's bytes.UpdateImageand 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, on5384a7bb0and65cdc6fa8).grow_depth) throughRetireThroughGuestMemory, keeps its HTile clear state (slice 0 consumed withTouchMetabefore 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 on9535d526c).DepthTargetFootprintsasserted 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
9535d526cagainst maina21fd80c8: the same results (194 passed;GpuSelectedFormattedRgba16StoreandIndirectImageQueryDimensionsfail on both, and both runs stop at the same later check,image format does not support required usage: format=129 ... samples=2inimage.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 maina21fd80c8(94119354c,4cfdc862eand1b0f689dfchanged the same functions). PR CI run 44832736912 on9535d526c: 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 overlapstop 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 build0cad467. A test build with the comparison change (15a1722 = main96b251749+ 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.
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)@coderabbitai[bot] on GitHub · 2026-11-19 15:26 UTC · original · edited 2026-11-26 23:39 UTC
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,claxten10Change: Bug fix
Merge Risk:
Low · up to
c65b1This 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:
4
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
5f332b51-33fd-4f08-8f46-ea5f00077946Reviewing files that changed from the base of the PR and between
9535d526c1andc65b1abe82.src/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/image/imageInfo.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@ -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) ||@coderabbitai[bot] on GitHub · 2026-11-19 15:26 UTC · original · edited 2026-11-19 17:08 UTC
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::CopyImagecopies only the common mip count, thenFreeImage(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)Initialize added depth layers before copying cached contents.
For the same
{2,1}to{1,4}change, the replacement receives only layer 0.CopyImagecallsRefreshComplete()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 · reviewed
Actionable comments posted: 2
bd9c9859-77ed-43d5-a153-a7e5ad2dadafReviewing files that changed from the base of the PR and between
5ad27cdd1aand5384a7bb00.src/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/image/imageInfo.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@ -894,0 +909,4 @@return false;}InitializeImage(replacement_id);FreeImage(retired_id);@coderabbitai[bot] on GitHub · 2026-11-19 16:50 UTC · original · edited 2026-11-19 17:14 UTC
Publish stencil planes before a retired depth backing is freed.
RetireThroughGuestMemorypublishes only the depth image.BcAlias::Publishdownloads the depth aspect, andFreeImage(retired_id)then deletes every stencil plane instencil_idswithout 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
CopyImagedid 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 · reviewed
Actionable comments posted: 1
6fa42234-a91e-4eac-b254-fdab04ad906bReviewing files that changed from the base of the PR and between
5384a7bb00and65cdc6fa85.src/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -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) ||@Nawid3333 on GitHub · 2026-11-19 17:07 UTC · original
@coderabbitai Both points are right, and both are fixed in
65cdc6fa8with a test inf84ed8bac.ResolveDepthOverlapnow retires the cached image the wayExpandImagealready did, through one helper,RetireThroughGuestMemory. When the replacement does not contain the cached subresources (same type, one sample, uncompressed) and the cached image isSafeToDownload, it publishes the cached image to guest memory, initializes the replacement from guest memory and frees the cached image.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. On5384a7bb0the 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);@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::CopyImageremoves the stencil aspect from both sides of the copy (FullAspectMask(...) & ~eStencil), andFreeImageof 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.
@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.cppline 907 (outdated):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 offset0x8000; replacement layer 0 starts at offset0. 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.ExpandImagethen initializes the correct guest contents, butCopyImageoverwrites 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
10f064fto9535d52@coderabbitai[bot] on GitHub · 2026-11-20 22:41 UTC · original · edited 2026-11-20 23:52 UTC
On
tests/ShaderRecompilerComputeTests.cppline 7459 (outdated):Keep the source backing free of GPU modifications in the guest-only test.
FindDepthTargetcallsCommitGpuWrite, which marksbeforeas 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 firstFindDepthTargetcall withUpdateImage(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
10f064fto9535d52@coderabbitai[bot] on GitHub · 2026-11-20 22:41 UTC · original · reviewed
Actionable comments posted: 2
b2ac4add-6e90-49ae-bb80-08c6642fc650Reviewing files that changed from the base of the PR and between
65cdc6fa85and94a5d60fae.src/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/image/imageInfo.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Nawid3333 on GitHub · 2026-11-20 23:52 UTC · original
On
src/graphics/host_gpu/renderer/cache/textureCache.cppline 907 (outdated):@coderabbitai Confirmed and fixed in
9535d526c. An image without GPU writes failedSafeToDownload(), soRetireThroughGuestMemorydeclined it, andExpandImagecopied it by subresource index after initializing the replacement from guest memory.RetireThroughGuestMemorynow 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 R8kStandard64KBimage 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 on10f064fa9(layer 0 gets level 0's bytes) and passes with the change.@Nawid3333 on GitHub · 2026-11-20 23:52 UTC · original
On
tests/ShaderRecompilerComputeTests.cppline 7459 (outdated):@coderabbitai Done in
10f064fa9: the guest-only depth case now uploads the source withUpdateImage(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.9535d526c1toc65b1abe82@akimfomin on GitHub · 2026-11-27 00:03 UTC · original
PortBridge checked the exact #2410 head
c65b1abeagainst61db2f88: 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.