graphics: release idle images when a new image cannot be allocated #2551

Open
github-bot wants to merge 4 commits from github-bot/gh-2551 into main AGit
Owner

@⁠Nawid3333 on GitHub · 2026-11-25 19:02 UTC · original
Nawid3333:fix/image-create-memory-pressure → main · +237 −26 · 5 files · 4 commits · open

Cause

When CreateImage (vmaCreateImage) fails, Image::Image stops the emulator with failed to create image: extent=... format=... (image.cpp), although the texture cache still holds images the current frame does not use. Idle images are only freed by the texture GC, which runs once per guest suspend point, deletes at most 10, 20 or 40 images per pass and only images idle for 16, 80 or 160 GC ticks (by memory pressure). During a loading burst it frees nothing in time.

Logs attached here stop this way with a VMA heap at or near its budget: 007 First Light (#1989), Until Dawn (#2388) and Avatar: Frontiers of Pandora (#2331); TxF-AI reports the same stop in UFC 6 (#2019). Assassin's Creed Valhalla stops with the same message (comment). TxF-AI measured it on UFC 6 (#2019): at the stop about 990 to 1,345 images hold 8.8 to 10.4 GB, and 78 to 95 % of the image bytes were touched in the last 16 GC ticks.

Change

  • Image::Image returns without a backing when CreateImage fails, instead of stopping. The body of ~Image moves to Image::ReleaseBacking().
  • TextureCache::InsertImage: while the new image has a format but no backing, it erases the slot, calls ReleaseIdleImages and tries again. When nothing can be released (also before the first GC pass) it stops with the same failed to create image message text as before, now from InsertImage.
  • ReleaseIdleImages(requested) goes through the LRU list from the oldest image and releases images not used in the current GC tick until their size reaches the requested size. It skips what the GC skips (unregistered images, stencil associations, heap-referenced images). An image whose newest data is a GPU write, with no later CPU or buffer write to its memory (SafeToDownload), is downloaded to guest memory first, as the GC does under memory pressure, and kept if it holds stencil or the download fails. It also keeps bound, target and video-out images, images accessed since the last guest suspend point and images that overlap the requested range. It frees the released images, waits once for the GPU (m_scheduler.Wait on the current tick, the submit-and-wait path a stream buffer wrap also takes while a draw is prepared) and destroys their backing.
  • Second commit: ResolveCache::Reuse marks a reused image as accessed through tick_accessed_last without moving it in the LRU list, so such an image is kept too.
  • Third commit: after the GPU wait, ReleaseIdleImages also waits for the priority operations of that tick (WaitPriorityOperations), as BufferCache::RunGarbageCollector does before it releases downloaded buffers. A released image's download reaches guest memory in such an operation; without the wait, its range could be found again and uploaded from guest memory before the data landed (found by CodeRabbit).
  • Fourth commit: a GPU-written candidate that is maybe CPU-dirty (a CPU write to a tracker page it shares, not to the image) is resolved the way RefreshImage does (TrackImage, then ResolveMaybeCpuHash(HashGuestEdges())) before the download check; before, SafeToDownload counted it as dirty and the image was released without its GPU write (found by CodeRabbit). The texture GC uses the same check and is unchanged.

#1271 had the same idea (evict and retry in InsertImage); it was closed with the comment "This is a hack and uses RAM as fallback (performance will be low)". #1961 (open, a Call of Duty Vanguard bring-up) contains a similar evict-and-retry among its other changes. This change keeps the GC's rules for what must not be lost (an image whose newest data is a GPU write is downloaded first; stencil holders and heap-referenced images stay), but not its minimum age or per-pass cap, and runs only where an allocation fails; it does not change where VMA places images (AUTO_PREFER_DEVICE, unchanged). Differences in the code: no second evictor with its own 256 MiB eviction target and 32 MiB download budget, no keep parameter threaded through the callers (images overlapping the request are kept instead), and no CommandScheduler::Finish() before the retry. When the images a game needs do not fit, they are created and uploaded again (slower), where the build before stopped.

Test

shader_recompiler_compute_tests --image-allocation-pressure-only (new ImageAllocationPressure): a second runtime context gets a VMA allocator whose heaps are limited (pHeapSizeLimit) to what the harness allocator already uses plus 256 MiB, fills them, creates a GPU-written 8 MiB image, advances one frame and asks for a second image.

  • main's source (93cce6656) with the test: exit 65, failed to create image: extent=1024x2048x1 format=37 layers=1 levels=1
  • with the change: exit 0, ImageAllocationPressure ok; the test also checks that the fill left no room for the new image, that the released image's GPU write is in guest memory as soon as the new image exists (a slow priority operation queued ahead of the download keeps it waiting), and that a small GPU-written image left maybe CPU-dirty by a write next to it is released with its GPU write.
  • without the third commit: exit 127, an image was released before its GPU write reached guest memory (5 of 5).
  • without the fourth commit: exit 127, a maybe-dirty image was released without its GPU write (5 of 5).

The other texture-cache selectors (--htile-clear-only, --image-overlap-only, --image-upload-only, --dcc-clear-only, --host-image-allocation-only, --image-view-cache-only, --depth-readback-only, --image-rebind-only, --storage-mip-host-only, --layered-image-only, --image-transition-only, --video-out-only, --descriptor-heap-only, --compute-meta-clear-only, --standard-tile-rt-only) give the same exit codes and last lines on main and with the change. Seven of them fail on both on this PC: image format does not support required usage (image.cpp), an unhandled host exception (runtimeLinker.cpp) and RenderExecutorStencilBindingDiscovery.

(Windows 11, RX 9070 XT, clang-cl. Local runs of shader_recompiler_compute_tests here need #2038's harness change, applied for the build only.)

Fork CI on this commit: run 45694520901: the Windows job (32 of 32 tests) and the Linux job (16 of 16) pass; the macOS job was cancelled before its first step. CI does not run shader_recompiler_compute_tests.

In a game

With tester builds that add a log line when images are released (not part of this PR):

  • #2019, UFC 6: TxF-AI (RX 6750 XT 12 GB) reports 10 releases in one run, the first four at a VMA heap at usage = budget, and no failed to create image; the same setup without the change stopped on it early in loading (comment). The run later stopped at a pipeline creation failure (shaders.cpp:417), a separate problem. A second run, with a build that also logs the pipeline creation result, had 33 releases and no failed to create image; it stopped at a device loss (createGraphicsPipelines failed: ErrorDeviceLost), also separate (comment).
  • #2308, Assassin's Creed Valhalla: Crispy81 (RX 9070 XT): idle images were released twice (comment), and the run then stopped at a buffer allocation (streamBuffer.cpp), which this change does not cover.

Loading time with the change was not measured.

Refs #2019
Refs #2308

Written with Claude Code (AI): Claude Code wrote the change and the test and ran them; DeepSeek reviewed the diff.

🤖 Generated with Claude Code

**@⁠Nawid3333** on GitHub · 2026-11-25 19:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551) `Nawid3333:fix/image-create-memory-pressure` → `main` · +237 −26 · 5 files · 4 commits · open ## Cause When `CreateImage` (`vmaCreateImage`) fails, `Image::Image` stops the emulator with `failed to create image: extent=... format=...` (image.cpp), although the texture cache still holds images the current frame does not use. Idle images are only freed by the texture GC, which runs once per guest suspend point, deletes at most 10, 20 or 40 images per pass and only images idle for 16, 80 or 160 GC ticks (by memory pressure). During a loading burst it frees nothing in time. Logs attached here stop this way with a VMA heap at or near its budget: 007 First Light (#1989), Until Dawn (#2388) and Avatar: Frontiers of Pandora (#2331); TxF-AI reports the same stop in UFC 6 (#2019). Assassin's Creed Valhalla stops with the same message ([comment](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/2307)). TxF-AI measured it on UFC 6 (#2019): at the stop about 990 to 1,345 images hold 8.8 to 10.4 GB, and 78 to 95 % of the image bytes were touched in the last 16 GC ticks. ## Change - `Image::Image` returns without a backing when `CreateImage` fails, instead of stopping. The body of `~Image` moves to `Image::ReleaseBacking()`. - `TextureCache::InsertImage`: while the new image has a format but no backing, it erases the slot, calls `ReleaseIdleImages` and tries again. When nothing can be released (also before the first GC pass) it stops with the same `failed to create image` message text as before, now from `InsertImage`. - `ReleaseIdleImages(requested)` goes through the LRU list from the oldest image and releases images not used in the current GC tick until their size reaches the requested size. It skips what the GC skips (unregistered images, stencil associations, heap-referenced images). An image whose newest data is a GPU write, with no later CPU or buffer write to its memory (`SafeToDownload`), is downloaded to guest memory first, as the GC does under memory pressure, and kept if it holds stencil or the download fails. It also keeps bound, target and video-out images, images accessed since the last guest suspend point and images that overlap the requested range. It frees the released images, waits once for the GPU (`m_scheduler.Wait` on the current tick, the submit-and-wait path a stream buffer wrap also takes while a draw is prepared) and destroys their backing. - Second commit: `ResolveCache::Reuse` marks a reused image as accessed through `tick_accessed_last` without moving it in the LRU list, so such an image is kept too. - Third commit: after the GPU wait, `ReleaseIdleImages` also waits for the priority operations of that tick (`WaitPriorityOperations`), as `BufferCache::RunGarbageCollector` does before it releases downloaded buffers. A released image's download reaches guest memory in such an operation; without the wait, its range could be found again and uploaded from guest memory before the data landed (found by CodeRabbit). - Fourth commit: a GPU-written candidate that is maybe CPU-dirty (a CPU write to a tracker page it shares, not to the image) is resolved the way `RefreshImage` does (`TrackImage`, then `ResolveMaybeCpuHash(HashGuestEdges())`) before the download check; before, `SafeToDownload` counted it as dirty and the image was released without its GPU write (found by CodeRabbit). The texture GC uses the same check and is unchanged. #1271 had the same idea (evict and retry in `InsertImage`); it was closed with the comment "This is a hack and uses RAM as fallback (performance will be low)". #1961 (open, a Call of Duty Vanguard bring-up) contains a similar evict-and-retry among its other changes. This change keeps the GC's rules for what must not be lost (an image whose newest data is a GPU write is downloaded first; stencil holders and heap-referenced images stay), but not its minimum age or per-pass cap, and runs only where an allocation fails; it does not change where VMA places images (`AUTO_PREFER_DEVICE`, unchanged). Differences in the code: no second evictor with its own 256 MiB eviction target and 32 MiB download budget, no `keep` parameter threaded through the callers (images overlapping the request are kept instead), and no `CommandScheduler::Finish()` before the retry. When the images a game needs do not fit, they are created and uploaded again (slower), where the build before stopped. ## Test `shader_recompiler_compute_tests --image-allocation-pressure-only` (new `ImageAllocationPressure`): a second runtime context gets a VMA allocator whose heaps are limited (`pHeapSizeLimit`) to what the harness allocator already uses plus 256 MiB, fills them, creates a GPU-written 8 MiB image, advances one frame and asks for a second image. - main's source (93cce6656) with the test: exit 65, `failed to create image: extent=1024x2048x1 format=37 layers=1 levels=1` - with the change: exit 0, `ImageAllocationPressure ok`; the test also checks that the fill left no room for the new image, that the released image's GPU write is in guest memory as soon as the new image exists (a slow priority operation queued ahead of the download keeps it waiting), and that a small GPU-written image left maybe CPU-dirty by a write next to it is released with its GPU write. - without the third commit: exit 127, `an image was released before its GPU write reached guest memory` (5 of 5). - without the fourth commit: exit 127, `a maybe-dirty image was released without its GPU write` (5 of 5). The other texture-cache selectors (`--htile-clear-only`, `--image-overlap-only`, `--image-upload-only`, `--dcc-clear-only`, `--host-image-allocation-only`, `--image-view-cache-only`, `--depth-readback-only`, `--image-rebind-only`, `--storage-mip-host-only`, `--layered-image-only`, `--image-transition-only`, `--video-out-only`, `--descriptor-heap-only`, `--compute-meta-clear-only`, `--standard-tile-rt-only`) give the same exit codes and last lines on main and with the change. Seven of them fail on both on this PC: `image format does not support required usage` (image.cpp), an unhandled host exception (runtimeLinker.cpp) and `RenderExecutorStencilBindingDiscovery`. (Windows 11, RX 9070 XT, clang-cl. Local runs of `shader_recompiler_compute_tests` here need #2038's harness change, applied for the build only.) Fork CI on this commit: [run 45694520901](https://github.com/Nawid3333/KytyPS5/actions/runs/45694520901/attempts/1): the Windows job (32 of 32 tests) and the Linux job (16 of 16) pass; the macOS job was cancelled before its first step. CI does not run `shader_recompiler_compute_tests`. ## In a game With tester builds that add a log line when images are released (not part of this PR): - #2019, UFC 6: TxF-AI (RX 6750 XT 12 GB) reports 10 releases in one run, the first four at a VMA heap at `usage = budget`, and no `failed to create image`; the same setup without the change stopped on it early in loading ([comment](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/2019)). The run later stopped at a pipeline creation failure (`shaders.cpp:417`), a separate problem. A second run, with a build that also logs the pipeline creation result, had 33 releases and no `failed to create image`; it stopped at a device loss (`createGraphicsPipelines failed: ErrorDeviceLost`), also separate ([comment](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/2019)). - #2308, Assassin's Creed Valhalla: Crispy81 (RX 9070 XT): idle images were released twice ([comment](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/2308)), and the run then stopped at a buffer allocation (`streamBuffer.cpp`), which this change does not cover. Loading time with the change was not measured. Refs #2019 Refs #2308 Written with Claude Code (AI): Claude Code wrote the change and the test and ran them; DeepSeek reviewed the diff. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
When vmaCreateImage fails in every memory type the image may use, the
texture cache now releases images that were not touched in the current
frame, publishing GPU-written ones to guest memory first, waits for the
GPU to finish with them, destroys them and retries. Heap-referenced,
bound, target, video-out and stencil-association images and images that
overlap the requested range are kept. Only when nothing is left to
release does it stop with the same "failed to create image" error.

The test limits each memory heap of a separate allocator so that a second
image cannot be allocated while an idle GPU-written image holds the memory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ResolveCache::Reuse marks a reused image as accessed in the current
frame through tick_accessed_last without moving it in the LRU list, so
the allocation-failure release must not count such an image as idle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A GPU-written image that ReleaseIdleImages downloads publishes its data to
guest memory in a priority operation that runs after the GPU tick completes.
Waiting only for the tick let the released range be found again and uploaded
from guest memory before that publication landed. Wait for the priority
operations of the tick as well, as BufferCache::RunGarbageCollector does
before it releases downloaded buffers.

The pressure test queues a slow priority operation ahead of the publication
and checks guest memory as soon as the new image is created.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A CPU write to a tracker page that an image shares, but not to the image
itself, leaves the image maybe CPU-dirty, and SafeToDownload treats that as
dirty. ReleaseIdleImages then released such a GPU-written image without
downloading it, and guest memory kept the older bytes. Resolve the state
the way RefreshImage does (track the image, compare the hash of its guest
edges) before the download check.

The pressure test adds a small GPU-written image that a CPU write next to
it leaves maybe-dirty, and checks that the fill really leaves no room for
the new image before it checks a release.

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

@⁠coderabbitai[bot] on GitHub · 2026-11-25 19:08 UTC · original · edited 2026-11-25 20:28 UTC

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

When image creation fails without backing, TextureCache removes the failed slot, releases eligible idle image backing, and retries. Image now exposes backing release and returns from construction when image creation fails. The Vulkan test suite adds an allocation-pressure check and supports running it separately.

Suggested reviewers: nmzik, thecruz

Change: Bug fix

Merge Risk: Minimal · up to 9e27d

When an image allocation fails, the texture cache now frees idle images and retries before stopping the emulator. GPU-written contents are saved to guest memory first, and in-use images are protected. Nothing concrete remains to fix before merge. The new pressure test is not run by CI, so the author's reported local run is the only check of this path.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: idle images are released when a new image allocation fails. The change matches this. The changeset adds ReleaseIdleImages, retries in InsertImage, and changes Image co…
Description check Passed The description is detailed and on-topic. It explains the cause (CreateImage failure stops the emulator while idle images remain), the change (Image::Image returns without backing, ReleaseBacking, Ins…
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: idle images are released when a new image allocation fails. The change matches this. The changeset adds ReleaseIdleImages, retries in InsertImage, and changes Image construction on CreateImage failure. The title is specific and concise, and it does not use vague terms.

Full details: Description check

Explanation

The description is detailed and on-topic. It explains the cause (CreateImage failure stops the emulator while idle images remain), the change (Image::Image returns without backing, ReleaseBacking, InsertImage retry, ReleaseIdleImages with GC-like protections, ResolveCache::Reuse accessed marking), and the test (ImageAllocationPressure). It matches the raw summary and the 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 e2c82ade02 and 9e27d264d9.

Files selected for processing: 2

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

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-25 19:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#issuecomment-7171878992) · edited 2026-11-25 20:28 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/2551?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 --> <!-- 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> When image creation fails without backing, `TextureCache` removes the failed slot, releases eligible idle image backing, and retries. `Image` now exposes backing release and returns from construction when image creation fails. The Vulkan test suite adds an allocation-pressure check and supports running it separately. **Suggested reviewers:** `nmzik`, `thecruz` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"9e27d264d9c8d6e0a62f53f5fd9aacaa1d48358a" --> <!-- 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-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>9e27d</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `9e27d` --> <!-- final_review_risk_coverage:{"sourceCommitId":"9e27d264d9c8d6e0a62f53f5fd9aacaa1d48358a","coveredCommitId":"9e27d264d9c8d6e0a62f53f5fd9aacaa1d48358a","kind":"reviewed"} --> When an image allocation fails, the texture cache now frees idle images and retries before stopping the emulator. GPU-written contents are saved to guest memory first, and in-use images are protected. Nothing concrete remains to fix before merge. The new pressure test is not run by CI, so the author's reported local run is the only check of this path. <!-- 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: idle images are released when a new image allocation fails. The change matches this. The changeset adds ReleaseIdleImages, retries in InsertImage, and changes Image co… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description is detailed and on-topic. It explains the cause (CreateImage failure stops the emulator while idle images remain), the change (Image::Image returns without backing, ReleaseBacking, Ins… | | 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: idle images are released when a new image allocation fails. The change matches this. The changeset adds ReleaseIdleImages, retries in InsertImage, and changes Image construction on CreateImage failure. The title is specific and concise, and it does not use vague terms. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description is detailed and on-topic. It explains the cause (CreateImage failure stops the emulator while idle images remain), the change (Image::Image returns without backing, ReleaseBacking, InsertImage retry, ReleaseIdleImages with GC-like protections, ResolveCache::Reuse accessed marking), and the test (ImageAllocationPressure). It matches the raw summary and the 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=2551)! 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/93cce66564bdced2fc7054ca9794451dfeef4d9d/.coderabbit.yaml>) - **Commit**: [93cce66](<https://github.com/KytyPS5/KytyPS5/commit/93cce66564bdced2fc7054ca9794451dfeef4d9d>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `f277efe9-9cc0-4592-b37b-48263a621dbc` </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 e2c82ade02d847514992a4610b59f0af9a577ac2 and 9e27d264d9c8d6e0a62f53f5fd9aacaa1d48358a. </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: 2</strong></summary> <dl> <dd> <br> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
Author
Owner

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 93cce66564 and 3bde87d248.

Files selected for processing: 5

  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
  • src/graphics/host_gpu/renderer/image/image.cpp
  • src/graphics/host_gpu/renderer/image/image.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-25 19:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#pullrequestreview-6063430169) · **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/93cce66564bdced2fc7054ca9794451dfeef4d9d/.coderabbit.yaml>) - **Commit**: [93cce66](<https://github.com/KytyPS5/KytyPS5/commit/93cce66564bdced2fc7054ca9794451dfeef4d9d>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `cd1a7a1b-ed77-4d3a-bc17-e51bbb6acc79` </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 93cce66564bdced2fc7054ca9794451dfeef4d9d and 3bde87d24860d1752190c1f3717112553f7bd327. </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: 5</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/image.cpp` * `src/graphics/host_gpu/renderer/image/image.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=5763f054-5e99-42da-b51a-531abf360150 attempt=90fd6df1-0aef-4440-9634-79993053aee4 batch=1/1 -->
@ -213,0 +245,4 @@
TrackImage(id);
image->ResolveMaybeCpuHash(image->HashGuestEdges());
}
if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) {
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-25 19:08 UTC · original · edited 2026-11-25 19:39 UTC

Minor · Stability & Availability · Quick win

Protect a depth owner while one of its stencil associations is in use.

ReleaseIdleImages checks only the depth owner's tick_accessed_last, heap references, and binding state. A stencil association that FindImage selected in the current frame does not update its owner's LRU entry or tick_accessed_last. A later allocation failure in the same draw can therefore call ReleaseIdleImages, which can select that owner. FreeImage then frees each association, so the draw can hold an association ID for an image that no longer exists.

The owner's heap references already protect resident heap bindings, because texture bindings resolve to the owner. The gap applies only to association use in the current frame. Make the recovery guard reject an owner while any of its stencil_ids has tick_accessed_last == m_gc_tick, or otherwise propagate association access to the owner. Confirm the chosen rule against the draw path that holds association IDs before merging.

✅ Addressed in commit e315b61

**@⁠coderabbitai[bot]** on GitHub · 2026-11-25 19:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4699616061) · edited 2026-11-25 19:39 UTC <!-- 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** · **Stability & Availability** · **Quick win** **Protect a depth owner while one of its stencil associations is in use.** `ReleaseIdleImages` checks only the depth owner's `tick_accessed_last`, heap references, and binding state. A stencil association that `FindImage` selected in the current frame does not update its owner's LRU entry or `tick_accessed_last`. A later allocation failure in the same draw can therefore call `ReleaseIdleImages`, which can select that owner. `FreeImage` then frees each association, so the draw can hold an association ID for an image that no longer exists. The owner's heap references already protect resident heap bindings, because texture bindings resolve to the owner. The gap applies only to association use in the current frame. Make the recovery guard reject an owner while any of its `stencil_ids` has `tick_accessed_last == m_gc_tick`, or otherwise propagate association access to the owner. Confirm the chosen rule against the draw path that holds association IDs before merging. <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:3e2b493abeb21f7d3454bb61 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit e315b61
@ -213,0 +245,4 @@
TrackImage(id);
image->ResolveMaybeCpuHash(image->HashGuestEdges());
}
if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) {
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-25 19:31 UTC · original

Fixed in e315b619d: ReleaseIdleImages now skips a depth image while any of its stencil associations was accessed in the current GC tick (tick_accessed_last == m_gc_tick). ImageAllocationPressure now also creates an older depth image with a stencil association, marks the association accessed in the current tick before the failing allocation, and checks that both are still registered afterwards; without the change it fails with a depth image was released while its stencil association was in use.

**@⁠Nawid3333** on GitHub · 2026-11-25 19:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4699879074) Fixed in e315b619d: `ReleaseIdleImages` now skips a depth image while any of its stencil associations was accessed in the current GC tick (`tick_accessed_last == m_gc_tick`). `ImageAllocationPressure` now also creates an older depth image with a stencil association, marks the association accessed in the current tick before the failing allocation, and checks that both are still registered afterwards; without the change it fails with `a depth image was released while its stencil association was in use`.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-25 19:36 UTC · original · edited 2026-11-25 20:09 UTC
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 257 (outdated):

@@ -205,11 +205,62 @@ TextureCache::BindingType TextureCache::UploadBinding(const Image& image) {
 }
 
 ImageId TextureCache::InsertImage(const ImageInfo& info) {
-	const auto id = m_slot_images.insert(m_graphics, m_scheduler, info);
+	auto id = m_slot_images.insert(m_graphics, m_scheduler, info);
+	while (info.pixel_format != vk::Format::eUndefined &&
+	       m_slot_images[id].backing.image == nullptr) {
+		m_slot_images.erase(id);
+		if (!ReleaseIdleImages(info.data)) {
+			EXIT("failed to create image: extent=%ux%ux%u format=%d layers=%u levels=%u\n",
+			     info.extent.width, info.extent.height, info.extent.depth,
+			     static_cast<int>(info.pixel_format), info.IsVolume() ? 1u : info.resources.layers,
+			     info.resources.levels);
+		}
+		id = m_slot_images.insert(m_graphics, m_scheduler, info);
+	}
 	RegisterImage(id);
 	return id;
 }
 
+bool TextureCache::ReleaseIdleImages(GuestRange requested) {
+	if (!m_scheduler.Active() || m_gc_tick == 0) {
+		return false;
+	}
+	std::vector<ImageId> candidates;
+	m_lru_cache.ForEachItemBelow(m_gc_tick - 1, [&](ImageId id) { candidates.push_back(id); });
+	std::vector<ImageId> released;
+	uint64_t             released_size = 0;
+	for (const auto id: candidates) {
+		if (released_size >= requested.size) {
+			break;
+		}
+		auto* image = m_slot_images.try_get(id);
+		if (image == nullptr || !image->registered || image->depth_id ||
+		    image->backing.image == nullptr || image->tick_accessed_last == m_gc_tick ||
+		    image->heap_refs.load(std::memory_order_relaxed) != 0u || image->binding.is_bound ||
+		    image->binding.is_target || image->usage.video_out ||
+		    image->Overlaps(requested.address, requested.size) ||
+		    std::ranges::any_of(image->stencil_ids, [this](ImageId association) {
+			    return m_slot_images[association].tick_accessed_last == m_gc_tick;
+		    })) {
+			continue;
+		}
+		if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) {
+			continue;
+		}
+		released_size += image->AccountedSize();
+		released.push_back(id);
+		FreeImage(id);
+	}
+	if (released.empty()) {
+		return false;
+	}
+	m_scheduler.Wait(m_scheduler.CurrentTick());

Major · Data Integrity & Integration · Quick win

Wait for priority publications before releasing an image.

ReleaseIdleImages waits only for the GPU tick. A GPU-written image that it releases can still have a deferred guest publication pending in the priority queue. Priority callbacks run asynchronously after that wait returns. A later reload of the same range can then upload the old guest bytes instead of the GPU-written data. Wait for the priority operations of the same tick before the released backings are destroyed.

Suggested fix

--- "a/src/graphics/host_gpu/renderer/cache/textureCache.cpp"
+++ "b/src/graphics/host_gpu/renderer/cache/textureCache.cpp"
@@ -254,7 +254,9 @@
 	if (released.empty()) {
 		return false;
 	}
-	m_scheduler.Wait(m_scheduler.CurrentTick());
+	const auto tick = m_scheduler.CurrentTick();
+	m_scheduler.Wait(tick);
+	m_scheduler.WaitPriorityOperations(tick);
 	for (const auto id: released) {
 		m_slot_images[id].ReleaseBacking();
 	}

✅ Confirmed as addressed by @⁠Nawid3333

**@⁠coderabbitai[bot]** on GitHub · 2026-11-25 19:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4699925841) · edited 2026-11-25 20:09 UTC On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 257 (outdated): ```diff @@ -205,11 +205,62 @@ TextureCache::BindingType TextureCache::UploadBinding(const Image& image) { } ImageId TextureCache::InsertImage(const ImageInfo& info) { - const auto id = m_slot_images.insert(m_graphics, m_scheduler, info); + auto id = m_slot_images.insert(m_graphics, m_scheduler, info); + while (info.pixel_format != vk::Format::eUndefined && + m_slot_images[id].backing.image == nullptr) { + m_slot_images.erase(id); + if (!ReleaseIdleImages(info.data)) { + EXIT("failed to create image: extent=%ux%ux%u format=%d layers=%u levels=%u\n", + info.extent.width, info.extent.height, info.extent.depth, + static_cast<int>(info.pixel_format), info.IsVolume() ? 1u : info.resources.layers, + info.resources.levels); + } + id = m_slot_images.insert(m_graphics, m_scheduler, info); + } RegisterImage(id); return id; } +bool TextureCache::ReleaseIdleImages(GuestRange requested) { + if (!m_scheduler.Active() || m_gc_tick == 0) { + return false; + } + std::vector<ImageId> candidates; + m_lru_cache.ForEachItemBelow(m_gc_tick - 1, [&](ImageId id) { candidates.push_back(id); }); + std::vector<ImageId> released; + uint64_t released_size = 0; + for (const auto id: candidates) { + if (released_size >= requested.size) { + break; + } + auto* image = m_slot_images.try_get(id); + if (image == nullptr || !image->registered || image->depth_id || + image->backing.image == nullptr || image->tick_accessed_last == m_gc_tick || + image->heap_refs.load(std::memory_order_relaxed) != 0u || image->binding.is_bound || + image->binding.is_target || image->usage.video_out || + image->Overlaps(requested.address, requested.size) || + std::ranges::any_of(image->stencil_ids, [this](ImageId association) { + return m_slot_images[association].tick_accessed_last == m_gc_tick; + })) { + continue; + } + if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) { + continue; + } + released_size += image->AccountedSize(); + released.push_back(id); + FreeImage(id); + } + if (released.empty()) { + return false; + } + m_scheduler.Wait(m_scheduler.CurrentTick()); ``` <!-- 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** **Wait for priority publications before releasing an image.** `ReleaseIdleImages` waits only for the GPU tick. A GPU-written image that it releases can still have a deferred guest publication pending in the priority queue. Priority callbacks run asynchronously after that wait returns. A later reload of the same range can then upload the old guest bytes instead of the GPU-written data. Wait for the priority operations of the same tick before the released backings are destroyed. <details> <summary>Suggested fix</summary> <dl> <dd> <br> ```diff --- "a/src/graphics/host_gpu/renderer/cache/textureCache.cpp" +++ "b/src/graphics/host_gpu/renderer/cache/textureCache.cpp" @@ -254,7 +254,9 @@ if (released.empty()) { return false; } - m_scheduler.Wait(m_scheduler.CurrentTick()); + const auto tick = m_scheduler.CurrentTick(); + m_scheduler.Wait(tick); + m_scheduler.WaitPriorityOperations(tick); for (const auto id: released) { m_slot_images[id].ReleaseBacking(); } ``` </dd> </dl> </details> <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:395680ebbb840555910cbbdc --> <!-- 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-25 19:36 UTC · original · reviewed

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3bde87d248 and e315b619dabe4e500ce9d7ccdc4d3edf67697750.

Files selected for processing: 2

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

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-25 19:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#pullrequestreview-6063826269) · **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/93cce66564bdced2fc7054ca9794451dfeef4d9d/.coderabbit.yaml>) - **Commit**: [93cce66](<https://github.com/KytyPS5/KytyPS5/commit/93cce66564bdced2fc7054ca9794451dfeef4d9d>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `486d3e78-9729-4457-9a00-bdd463f51036` </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 3bde87d24860d1752190c1f3717112553f7bd327 and e315b619dabe4e500ce9d7ccdc4d3edf67697750. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 2</summary> <dl> <dd> <br> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 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=9fc0eecc-629b-4312-a9d9-5651cd581c63 attempt=53fd5cc9-bb12-42e4-8565-75bb9b806957 batch=1/1 -->
@ -213,0 +245,4 @@
TrackImage(id);
image->ResolveMaybeCpuHash(image->HashGuestEdges());
}
if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) {
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-25 19:41 UTC · original

Analysis chain

Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- current revision ---'
git rev-parse HEAD
printf '%s\n' '--- relevant cache outlines ---'
ast-grep outline src/graphics/host_gpu/renderer/cache/textureCache.cpp --items all --match 'FindImage|ReleaseIdleImages|DeleteImage|FreeImage' --view expanded
printf '%s\n' '--- resolve cache and draw call sites ---'
rg -n -C 3 --type cpp '(\.FindImage\s*\(|\.Reuse\s*\(|tick_accessed_last|depth_id)' src/graphics/host_gpu/renderer/resolveCache.cpp src/graphics/host_gpu/renderer/render.cpp
printf '%s\n' '--- pressure test outline and selected assertions ---'
ast-grep outline tests/ShaderRecompilerComputeTests.cpp --items all --match 'CheckImageAllocationPressure|TextureCacheTestAccess' --view expanded
rg -n -C 6 'a depth image was released while its stencil association was in use|CheckImageAllocationPressure|Mark.*Access|tick_accessed_last' tests/ShaderRecompilerComputeTests.cpp

Length of output: 9055


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- image discovery and resolve reuse call sites ---'
rg -n -C 7 --type cpp '\b(FindImage|Reuse)\s*\(' src/graphics/host_gpu/renderer
printf '%s\n' '--- resolve cache outline and implementation ---'
ast-grep outline src/graphics/host_gpu/renderer/resolveCache.cpp --items all --view expanded
cat -n src/graphics/host_gpu/renderer/resolveCache.cpp | sed -n '1,100p'
printf '%s\n' '--- allocation pressure test setup and checks ---'
cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '2398,2525p'

Length of output: 31866


Script executed:

#!/bin/bash
set -u
ast-grep outline src/graphics/host_gpu/renderer/pipeline/descriptors.cpp --items all --match 'ResolveTexture|Prepare|Discover|BindImage' --view expanded
cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '625,770p'
cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '900,960p'

Length of output: 11466


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- all ResolveTexture call sites ---'
rg -n -C 8 --type cpp '\bResolveTexture\s*\(' src/graphics/host_gpu/renderer
printf '%s\n' '--- image heap source files ---'
fd -i 'imageheap' src/graphics/host_gpu/renderer
printf '%s\n' '--- heap references and binding context ---'
rg -n -C 5 --type cpp '\b(heap_refs|HeapChanged|Rebind)\b' src/graphics/host_gpu/renderer/pipeline src/graphics/host_gpu/renderer/cache/textureCache.cpp

Length of output: 27506


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- parent revision ---'
git rev-parse 'e315b619dabe4e500ce9d7ccdc4d3edf67697750^'
printf '%s\n' '--- descriptor and heap changes in fix commit ---'
git diff 'e315b619dabe4e500ce9d7ccdc4d3edf67697750^' e315b619dabe4e500ce9d7ccdc4d3edf67697750 -- src/graphics/host_gpu/renderer/pipeline/descriptors.cpp src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp src/graphics/host_gpu/renderer/resolveCache.cpp
printf '%s\n' '--- parent descriptor owner and bind logic ---'
git show 'e315b619dabe4e500ce9d7ccdc4d3edf67697750^:src/graphics/host_gpu/renderer/pipeline/descriptors.cpp' | rg -n -C 5 'stencil_association|BindImage\(image\.image_id'
printf '%s\n' '--- parent heap pin logic ---'
git show 'e315b619dabe4e500ce9d7ccdc4d3edf67697750^:src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp' | rg -n -C 5 'heap_refs\.fetch_add'

Length of output: 3003


@Nawid3333 Thanks for the guard and test. I need to correct my original finding.

ResolveTexture replaces the stencil association ID with the depth owner. PrepareBindings then binds the owner before it discovers the next image. ReleaseIdleImages already skips bound images. The image-heap path also pins the owner.

The test checks the new guard directly, but the draw path does not retain the association ID as I claimed. I withdraw the finding.


📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-25 19:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4699975905) <!-- coderabbit-ai-generated:v1 --> <details> <summary>Analysis chain</summary> <dl> <dd> <br> Script executed: ```shell #!/bin/bash set -u printf '%s\n' '--- current revision ---' git rev-parse HEAD printf '%s\n' '--- relevant cache outlines ---' ast-grep outline src/graphics/host_gpu/renderer/cache/textureCache.cpp --items all --match 'FindImage|ReleaseIdleImages|DeleteImage|FreeImage' --view expanded printf '%s\n' '--- resolve cache and draw call sites ---' rg -n -C 3 --type cpp '(\.FindImage\s*\(|\.Reuse\s*\(|tick_accessed_last|depth_id)' src/graphics/host_gpu/renderer/resolveCache.cpp src/graphics/host_gpu/renderer/render.cpp printf '%s\n' '--- pressure test outline and selected assertions ---' ast-grep outline tests/ShaderRecompilerComputeTests.cpp --items all --match 'CheckImageAllocationPressure|TextureCacheTestAccess' --view expanded rg -n -C 6 'a depth image was released while its stencil association was in use|CheckImageAllocationPressure|Mark.*Access|tick_accessed_last' tests/ShaderRecompilerComputeTests.cpp ``` Length of output: 9055 --- Script executed: ```shell #!/bin/bash set -u printf '%s\n' '--- image discovery and resolve reuse call sites ---' rg -n -C 7 --type cpp '\b(FindImage|Reuse)\s*\(' src/graphics/host_gpu/renderer printf '%s\n' '--- resolve cache outline and implementation ---' ast-grep outline src/graphics/host_gpu/renderer/resolveCache.cpp --items all --view expanded cat -n src/graphics/host_gpu/renderer/resolveCache.cpp | sed -n '1,100p' printf '%s\n' '--- allocation pressure test setup and checks ---' cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '2398,2525p' ``` Length of output: 31866 --- Script executed: ```shell #!/bin/bash set -u ast-grep outline src/graphics/host_gpu/renderer/pipeline/descriptors.cpp --items all --match 'ResolveTexture|Prepare|Discover|BindImage' --view expanded cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '625,770p' cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '900,960p' ``` Length of output: 11466 --- Script executed: ```shell #!/bin/bash set -u printf '%s\n' '--- all ResolveTexture call sites ---' rg -n -C 8 --type cpp '\bResolveTexture\s*\(' src/graphics/host_gpu/renderer printf '%s\n' '--- image heap source files ---' fd -i 'imageheap' src/graphics/host_gpu/renderer printf '%s\n' '--- heap references and binding context ---' rg -n -C 5 --type cpp '\b(heap_refs|HeapChanged|Rebind)\b' src/graphics/host_gpu/renderer/pipeline src/graphics/host_gpu/renderer/cache/textureCache.cpp ``` Length of output: 27506 --- Script executed: ```shell #!/bin/bash set -u printf '%s\n' '--- parent revision ---' git rev-parse 'e315b619dabe4e500ce9d7ccdc4d3edf67697750^' printf '%s\n' '--- descriptor and heap changes in fix commit ---' git diff 'e315b619dabe4e500ce9d7ccdc4d3edf67697750^' e315b619dabe4e500ce9d7ccdc4d3edf67697750 -- src/graphics/host_gpu/renderer/pipeline/descriptors.cpp src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp src/graphics/host_gpu/renderer/resolveCache.cpp printf '%s\n' '--- parent descriptor owner and bind logic ---' git show 'e315b619dabe4e500ce9d7ccdc4d3edf67697750^:src/graphics/host_gpu/renderer/pipeline/descriptors.cpp' | rg -n -C 5 'stencil_association|BindImage\(image\.image_id' printf '%s\n' '--- parent heap pin logic ---' git show 'e315b619dabe4e500ce9d7ccdc4d3edf67697750^:src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp' | rg -n -C 5 'heap_refs\.fetch_add' ``` Length of output: 3003 --- </dd> </dl> </details> `@Nawid3333` Thanks for the guard and test. I need to correct my original finding. `ResolveTexture` replaces the stencil association ID with the depth owner. `PrepareBindings` then binds the owner before it discovers the next image. `ReleaseIdleImages` already skips bound images. The image-heap path also pins the owner. The test checks the new guard directly, but the draw path does not retain the association ID as I claimed. I withdraw the finding. --- > 📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Stencil%20associations%20could%20be%20freed%20mid-draw%20when%20GC%20evicted%20their%20depth%20owner.%20%40coderabbitai%20flagged%20it%3B%20a%20guard%20and%20regression%20test%20now%20protect%20in-use%20images.%20Try%20it!%20%F0%9F%9B%A1%EF%B8%8F&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F2551%23discussion_r4699616061)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> <!-- <review_comment_withdrawn> --> Review thread resolved. <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

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

@@ -205,11 +205,62 @@ TextureCache::BindingType TextureCache::UploadBinding(const Image& image) {
 }
 
 ImageId TextureCache::InsertImage(const ImageInfo& info) {
-	const auto id = m_slot_images.insert(m_graphics, m_scheduler, info);
+	auto id = m_slot_images.insert(m_graphics, m_scheduler, info);
+	while (info.pixel_format != vk::Format::eUndefined &&
+	       m_slot_images[id].backing.image == nullptr) {
+		m_slot_images.erase(id);
+		if (!ReleaseIdleImages(info.data)) {
+			EXIT("failed to create image: extent=%ux%ux%u format=%d layers=%u levels=%u\n",
+			     info.extent.width, info.extent.height, info.extent.depth,
+			     static_cast<int>(info.pixel_format), info.IsVolume() ? 1u : info.resources.layers,
+			     info.resources.levels);
+		}
+		id = m_slot_images.insert(m_graphics, m_scheduler, info);
+	}
 	RegisterImage(id);
 	return id;
 }
 
+bool TextureCache::ReleaseIdleImages(GuestRange requested) {
+	if (!m_scheduler.Active() || m_gc_tick == 0) {
+		return false;
+	}
+	std::vector<ImageId> candidates;
+	m_lru_cache.ForEachItemBelow(m_gc_tick - 1, [&](ImageId id) { candidates.push_back(id); });
+	std::vector<ImageId> released;
+	uint64_t             released_size = 0;
+	for (const auto id: candidates) {
+		if (released_size >= requested.size) {
+			break;
+		}
+		auto* image = m_slot_images.try_get(id);
+		if (image == nullptr || !image->registered || image->depth_id ||
+		    image->backing.image == nullptr || image->tick_accessed_last == m_gc_tick ||
+		    image->heap_refs.load(std::memory_order_relaxed) != 0u || image->binding.is_bound ||
+		    image->binding.is_target || image->usage.video_out ||
+		    image->Overlaps(requested.address, requested.size) ||
+		    std::ranges::any_of(image->stencil_ids, [this](ImageId association) {
+			    return m_slot_images[association].tick_accessed_last == m_gc_tick;
+		    })) {
+			continue;
+		}
+		if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) {
+			continue;
+		}
+		released_size += image->AccountedSize();
+		released.push_back(id);
+		FreeImage(id);
+	}
+	if (released.empty()) {
+		return false;
+	}
+	m_scheduler.Wait(m_scheduler.CurrentTick());

Fixed in e2c82ade0: after m_scheduler.Wait(tick), ReleaseIdleImages now also calls m_scheduler.WaitPriorityOperations(tick) before it destroys the backings, as BufferCache::RunGarbageCollector does. The pressure test now queues a 200 ms priority operation ahead of the download and reads guest memory right after the new image is created. Without the wait it fails with an image was released before its GPU write reached guest memory (5 of 5 runs); with the wait it passes (5 of 5).

**@⁠Nawid3333** on GitHub · 2026-11-25 20:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4700254223) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 257 (outdated): ```diff @@ -205,11 +205,62 @@ TextureCache::BindingType TextureCache::UploadBinding(const Image& image) { } ImageId TextureCache::InsertImage(const ImageInfo& info) { - const auto id = m_slot_images.insert(m_graphics, m_scheduler, info); + auto id = m_slot_images.insert(m_graphics, m_scheduler, info); + while (info.pixel_format != vk::Format::eUndefined && + m_slot_images[id].backing.image == nullptr) { + m_slot_images.erase(id); + if (!ReleaseIdleImages(info.data)) { + EXIT("failed to create image: extent=%ux%ux%u format=%d layers=%u levels=%u\n", + info.extent.width, info.extent.height, info.extent.depth, + static_cast<int>(info.pixel_format), info.IsVolume() ? 1u : info.resources.layers, + info.resources.levels); + } + id = m_slot_images.insert(m_graphics, m_scheduler, info); + } RegisterImage(id); return id; } +bool TextureCache::ReleaseIdleImages(GuestRange requested) { + if (!m_scheduler.Active() || m_gc_tick == 0) { + return false; + } + std::vector<ImageId> candidates; + m_lru_cache.ForEachItemBelow(m_gc_tick - 1, [&](ImageId id) { candidates.push_back(id); }); + std::vector<ImageId> released; + uint64_t released_size = 0; + for (const auto id: candidates) { + if (released_size >= requested.size) { + break; + } + auto* image = m_slot_images.try_get(id); + if (image == nullptr || !image->registered || image->depth_id || + image->backing.image == nullptr || image->tick_accessed_last == m_gc_tick || + image->heap_refs.load(std::memory_order_relaxed) != 0u || image->binding.is_bound || + image->binding.is_target || image->usage.video_out || + image->Overlaps(requested.address, requested.size) || + std::ranges::any_of(image->stencil_ids, [this](ImageId association) { + return m_slot_images[association].tick_accessed_last == m_gc_tick; + })) { + continue; + } + if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) { + continue; + } + released_size += image->AccountedSize(); + released.push_back(id); + FreeImage(id); + } + if (released.empty()) { + return false; + } + m_scheduler.Wait(m_scheduler.CurrentTick()); ``` Fixed in e2c82ade0: after `m_scheduler.Wait(tick)`, `ReleaseIdleImages` now also calls `m_scheduler.WaitPriorityOperations(tick)` before it destroys the backings, as `BufferCache::RunGarbageCollector` does. The pressure test now queues a 200 ms priority operation ahead of the download and reads guest memory right after the new image is created. Without the wait it fails with `an image was released before its GPU write reached guest memory` (5 of 5 runs); with the wait it passes (5 of 5).
@ -213,0 +245,4 @@
TrackImage(id);
image->ResolveMaybeCpuHash(image->HashGuestEdges());
}
if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) {
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-25 20:08 UTC · original · edited 2026-11-25 20:35 UTC

Major · Data Integrity & Integration · Quick win

Resolve maybe-CPU-dirty state before the download check during allocation recovery.

SafeToDownload() returns false when IsCpuDirty() is true, and that includes the maybe-dirty state. A CPU write that touches the tracker page of a GPU-written image, but not the image itself, sets this state (textureCache.cpp:2104-2112). In ReleaseIdleImages, such an image fails the check at line 244. The download is skipped, and FreeImage discards the GPU-written contents. The guest bytes are then stale. A later recreation can upload those stale bytes.

This CPU write does not overlap the image. The guest-edge hash can therefore match the stored hash, which means the image is not CPU-dirty and can be downloaded safely.

Before the eligibility check, resolve the maybe-CPU state for each GPU-modified candidate. After resolution, download the image when it is safe to download. Keep the existing skip for images that remain CPU-dirty, and keep the existing retain-on-failure behavior.

✅ Addressed in commit 9e27d26

**@⁠coderabbitai[bot]** on GitHub · 2026-11-25 20:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4700265917) · edited 2026-11-25 20:35 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** **Resolve maybe-CPU-dirty state before the download check during allocation recovery.** `SafeToDownload()` returns false when `IsCpuDirty()` is true, and that includes the maybe-dirty state. A CPU write that touches the tracker page of a GPU-written image, but not the image itself, sets this state (`textureCache.cpp:2104-2112`). In `ReleaseIdleImages`, such an image fails the check at line 244. The download is skipped, and `FreeImage` discards the GPU-written contents. The guest bytes are then stale. A later recreation can upload those stale bytes. This CPU write does not overlap the image. The guest-edge hash can therefore match the stored hash, which means the image is not CPU-dirty and can be downloaded safely. Before the eligibility check, resolve the maybe-CPU state for each GPU-modified candidate. After resolution, download the image when it is safe to download. Keep the existing skip for images that remain CPU-dirty, and keep the existing retain-on-failure behavior. <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:f131273f4cb2d58cecc9952a --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 9e27d26
@ -2395,0 +2454,4 @@
const VkMemoryRequirements requirements{free - margin, 1, 1u << type};
const VmaAllocationCreateInfo create{.flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT};
if (VmaAllocation filler{}; vmaAllocateMemory(graphics.allocator, &requirements, &create,
&filler, nullptr) == VK_SUCCESS) {
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-25 20:08 UTC · original · edited 2026-11-25 20:34 UTC

Minor · Functional Correctness · Quick win

Report missing allocation pressure instead of a failed eviction.

The fill helper ignores a failed dedicated allocation. At lines 2453-2456, the filler is kept only on VK_SUCCESS, and a failure continues the loop without an error. If both dedicated fills fail, the replacement image can fit in the remaining headroom. The test then creates it without eviction and reports "the new image did not take the memory of the idle one." That message blames eviction for a state where pressure was never created.

A device can reject the dedicated allocation. The Vulkan maximum allocation size is implementation-defined, and the physical heap can have less free memory than the synthetic limit at line 2412 reports.

The test must check this precondition. If the fill does not establish the pressure that the eviction check needs, it must report that pressure was not established, not a failed eviction. Choose the mechanism in the test design.

✅ Addressed in commit 9e27d26

**@⁠coderabbitai[bot]** on GitHub · 2026-11-25 20:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4700265926) · edited 2026-11-25 20:34 UTC <!-- 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** **Report missing allocation pressure instead of a failed eviction.** The fill helper ignores a failed dedicated allocation. At lines 2453-2456, the filler is kept only on `VK_SUCCESS`, and a failure continues the loop without an error. If both dedicated fills fail, the replacement image can fit in the remaining headroom. The test then creates it without eviction and reports "the new image did not take the memory of the idle one." That message blames eviction for a state where pressure was never created. A device can reject the dedicated allocation. The Vulkan maximum allocation size is implementation-defined, and the physical heap can have less free memory than the synthetic limit at line 2412 reports. The test must check this precondition. If the fill does not establish the pressure that the eviction check needs, it must report that pressure was not established, not a failed eviction. Choose the mechanism in the test design. <!-- fingerprinting:phantom:medusa:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:d23da6d55c724f2329dbb890 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 9e27d26
Author
Owner

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

Actionable comments posted: 2

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e315b619dabe4e500ce9d7ccdc4d3edf67697750 and e2c82ade02.

Files selected for processing: 2

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

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-25 20:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#pullrequestreview-6064236544) · **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/93cce66564bdced2fc7054ca9794451dfeef4d9d/.coderabbit.yaml>) - **Commit**: [93cce66](<https://github.com/KytyPS5/KytyPS5/commit/93cce66564bdced2fc7054ca9794451dfeef4d9d>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `bd923a70-be1b-41d6-af3a-5c11a11f1450` </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 e315b619dabe4e500ce9d7ccdc4d3edf67697750 and e2c82ade02d847514992a4610b59f0af9a577ac2. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 2</summary> <dl> <dd> <br> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=200c177a-5598-423a-b3b6-540e2013435c attempt=01ce588c-3423-42ea-bb69-b972a94b6b87 batch=1/1 -->
@ -213,0 +245,4 @@
TrackImage(id);
image->ResolveMaybeCpuHash(image->HashGuestEdges());
}
if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) {
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-25 20:08 UTC · original

Agreed. ResolveTexture replaces a stencil association with its depth owner (descriptors.cpp:646-649), and the owner is bound at :750 and :874 before the next texture is looked up. The depth target paths bind their image right after the lookup (depthRenderTarget.cpp:314, :340 and :342; descriptors.cpp:935). ReleaseIdleImages skips bound and target images, so I dropped e315b619d again. The branch is now 3bde87d24 plus e2c82ade0.

**@⁠Nawid3333** on GitHub · 2026-11-25 20:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4700269578) Agreed. `ResolveTexture` replaces a stencil association with its depth owner (descriptors.cpp:646-649), and the owner is bound at :750 and :874 before the next texture is looked up. The depth target paths bind their image right after the lookup (depthRenderTarget.cpp:314, :340 and :342; descriptors.cpp:935). `ReleaseIdleImages` skips bound and target images, so I dropped e315b619d again. The branch is now 3bde87d24 plus e2c82ade0.
@ -213,0 +245,4 @@
TrackImage(id);
image->ResolveMaybeCpuHash(image->HashGuestEdges());
}
if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) {
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-25 20:09 UTC · original

@⁠Nawid3333 Thanks for confirming.


📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings.

Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-25 20:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4700276145) <!-- coderabbit-ai-generated:v1 --> @⁠Nawid3333 Thanks for confirming. <!-- coderabbit-skip-review-comment-follow-up --> --- > 📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings. <!-- <review_comment_withdrawn> --> Review thread resolved. <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->
@ -2395,0 +2454,4 @@
const VkMemoryRequirements requirements{free - margin, 1, 1u << type};
const VmaAllocationCreateInfo create{.flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT};
if (VmaAllocation filler{}; vmaAllocateMemory(graphics.allocator, &requirements, &create,
&filler, nullptr) == VK_SUCCESS) {
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-25 20:33 UTC · original

Fixed in 9e27d264d: after the fill, the test checks that no heap the image can use (its memoryTypeBits) has room left for an image of its size, and otherwise fails with the fill left room for another image, so the test cannot check a release. With the fill margin raised to four image sizes it fails there; with the normal fill it passes.

**@⁠Nawid3333** on GitHub · 2026-11-25 20:33 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4700539468) Fixed in 9e27d264d: after the fill, the test checks that no heap the image can use (its `memoryTypeBits`) has room left for an image of its size, and otherwise fails with `the fill left room for another image, so the test cannot check a release`. With the fill margin raised to four image sizes it fails there; with the normal fill it passes.
@ -213,0 +245,4 @@
TrackImage(id);
image->ResolveMaybeCpuHash(image->HashGuestEdges());
}
if (image->SafeToDownload() && (image->info.HasStencil() || !DownloadImageMemory(id))) {
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-25 20:35 UTC · original

Fixed in 9e27d264d: before the download check, ReleaseIdleImages now resolves a GPU-written candidate that is maybe CPU-dirty the way RefreshImage does (TrackImage, then ResolveMaybeCpuHash(HashGuestEdges())), so an image whose own bytes the CPU write did not change is downloaded before it is released. The pressure test adds a small GPU-written image that a CPU write next to it on the same tracker page leaves maybe-dirty. Without the change it fails with a maybe-dirty image was released without its GPU write (5 of 5 runs); with it, it passes (5 of 5). The texture GC (RunGarbageCollector) uses the same SafeToDownload check and is unchanged here.

**@⁠Nawid3333** on GitHub · 2026-11-25 20:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2551#discussion_r4700555418) Fixed in 9e27d264d: before the download check, `ReleaseIdleImages` now resolves a GPU-written candidate that is maybe CPU-dirty the way `RefreshImage` does (`TrackImage`, then `ResolveMaybeCpuHash(HashGuestEdges())`), so an image whose own bytes the CPU write did not change is downloaded before it is released. The pressure test adds a small GPU-written image that a CPU write next to it on the same tracker page leaves maybe-dirty. Without the change it fails with `a maybe-dirty image was released without its GPU write` (5 of 5 runs); with it, it passes (5 of 5). The texture GC (`RunGarbageCollector`) uses the same `SafeToDownload` check and is unchanged here.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2551/head:github-bot/gh-2551'
git switch 'github-bot/gh-2551'

Merge

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