graphics: sample a copy of depth targets on hosts without feedback loops (GTA V on Intel Arc) #2397

Open
github-bot wants to merge 2 commits from github-bot/gh-2397 into main AGit
Owner

@⁠oguzhanozfe on GitHub · 2026-11-18 22:45 UTC · original
oguzhanozfe:fix/depth-feedback-copy → main · +139 −18 · 4 files · 2 commits · open

Summary

Grand Theft Auto V (PPSA04264) samples its depth target in some cutscenes while the same draw writes it. On hosts without VK_EXT_attachment_feedback_loop_layout, such as the Intel Arc B580 in #1123, this used to exit with depth attachment feedback loop is not supported by the host.

Since b8997179 it no longer exits. It logs once and keeps the attachment in VK_IMAGE_LAYOUT_GENERAL while sampling it. Vulkan leaves that read/write feedback undefined, so those hosts get undefined results instead of a crash.

This is a port of TheCruZ's closed #1241 onto current main.

Change

On a host without feedback loops, a binding that samples the depth attachment the draw writes is redirected to a copy of the depth image, taken before the draw (TextureCache::CopyDepthForFeedback).

How the copy is handled:

  • It has the depth image's layout but no guest memory, so it is never registered or tracked.
  • There is one copy per depth image. It is recreated when the image's format, extent, mips, layers or samples change.
  • It is released together with the depth image. The release is deferred while queued work may still sample it.

Hosts with feedback loops keep the existing feedback-layout path unchanged.

Port notes:

  • main's log-once fallback is removed, because the copy path replaces it.
  • DeleteImage releases the copy before main's new stencil-association handling.
  • The test uses PreparedBindings::pixel as a value, matching main.

Testing

Windows 11, Ryzen 9 5950X, RTX 3090, clang-cl (LLVM 23), Release.

  • shader_recompiler_compute_tests --sampled-depth-resource-only runs the new CheckRasterizationWithoutFeedbackLoops. It runs the depth read/write draw with feedback loops disabled. It then checks that the attachment does not use the feedback layout, and that the pixel shader samples a different image (the copy).
    • Without the change (main's renderDraw.cpp): DepthAttachmentFeedback failed at per-draw depth feedback: feedback was not selected only for an overlapping fragment depth read/write
    • With the change: passes.
  • The default full run of shader_recompiler_compute_tests passes.
  • In-game: I have no Intel Arc (or other no-feedback-loop) GPU, so I could not reproduce the #1123 cutscene. Testers on Arc are welcome. TheCruZ ran GTA V with the original change on an RTX 3090, where the existing path is unchanged.

AI usage

AI (Claude Opus 5.5) was used to port the change onto main and resolve its conflicts, run the tests above, and draft this description. The original fix is TheCruZ's (#1241), credited with Co-authored-by.

🤖 Generated with Claude Code

**@⁠oguzhanozfe** on GitHub · 2026-11-18 22:45 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2397) `oguzhanozfe:fix/depth-feedback-copy` → `main` · +139 −18 · 4 files · 2 commits · open ## Summary **Grand Theft Auto V** (PPSA04264) samples its depth target in some cutscenes while the same draw writes it. On hosts without `VK_EXT_attachment_feedback_loop_layout`, such as the Intel Arc B580 in #1123, this used to exit with `depth attachment feedback loop is not supported by the host`. Since b8997179 it no longer exits. It logs once and keeps the attachment in `VK_IMAGE_LAYOUT_GENERAL` while sampling it. Vulkan leaves that read/write feedback undefined, so those hosts get undefined results instead of a crash. This is a port of TheCruZ's closed #1241 onto current `main`. ## Change On a host without feedback loops, a binding that samples the depth attachment the draw writes is redirected to a copy of the depth image, taken before the draw (`TextureCache::CopyDepthForFeedback`). How the copy is handled: - It has the depth image's layout but no guest memory, so it is never registered or tracked. - There is one copy per depth image. It is recreated when the image's format, extent, mips, layers or samples change. - It is released together with the depth image. The release is deferred while queued work may still sample it. Hosts with feedback loops keep the existing feedback-layout path unchanged. Port notes: - `main`'s log-once fallback is removed, because the copy path replaces it. - `DeleteImage` releases the copy before `main`'s new stencil-association handling. - The test uses `PreparedBindings::pixel` as a value, matching `main`. ## Testing Windows 11, Ryzen 9 5950X, RTX 3090, clang-cl (LLVM 23), Release. - `shader_recompiler_compute_tests --sampled-depth-resource-only` runs the new `CheckRasterizationWithoutFeedbackLoops`. It runs the depth read/write draw with feedback loops disabled. It then checks that the attachment does not use the feedback layout, and that the pixel shader samples a different image (the copy). - Without the change (`main`'s `renderDraw.cpp`): `DepthAttachmentFeedback failed at per-draw depth feedback: feedback was not selected only for an overlapping fragment depth read/write` - With the change: passes. - The default full run of `shader_recompiler_compute_tests` passes. - **In-game:** I have no Intel Arc (or other no-feedback-loop) GPU, so I could not reproduce the #1123 cutscene. Testers on Arc are welcome. TheCruZ ran GTA V with the original change on an RTX 3090, where the existing path is unchanged. ## AI usage AI (Claude Opus 5.5) was used to port the change onto `main` and resolve its conflicts, run the tests above, and draft this description. The original fix is TheCruZ's (#1241), credited with `Co-authored-by`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Grand Theft Auto V (PPSA04264) samples its depth target in cutscenes
while the same draw writes it. On hosts without
VK_EXT_attachment_feedback_loop_layout (Intel Arc B580, #1123) this
used to exit with "depth attachment feedback loop is not supported by
the host"; since b8997179 it only logs once and renders the attachment
in VK_IMAGE_LAYOUT_GENERAL while it is sampled, which Vulkan leaves
undefined for a read/write feedback.

When the host has no feedback loops, sample a copy of the depth image
taken before the draw instead. The copy has the depth image's layout
but no guest memory, so it is never registered or tracked; it is kept
per depth image, recreated when the image's shape changes and released
with it (deferred while queued work may still sample it).

Ported from TheCruZ's closed #1241 onto current main.

Co-authored-by: TheCruZ <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review on #2397: CopyDepthForFeedback inserted into (and could
erase from) m_slot_images without m_lock, while InvalidateMemory reads
the slot containers under it. Hold m_lock for the reuse check, the
erase and the insertion, as FindImage does for its insertion; the copy
commands still run outside the lock.

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

@⁠coderabbitai[bot] on GitHub · 2026-11-18 22:52 UTC · original · edited 2026-11-18 23:07 UTC

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

TextureCache now creates, reuses, and releases cached copies of depth images. When a draw samples depth aspects that it also writes and attachment feedback loops are unavailable, RenderExecutor copies the relevant view and redirects the texture and mip-view bindings to that copy. The rasterization tests now exercise this path with feedback loops disabled and check the feedback aspects and sampled image.

Suggested reviewers: thecruz

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 89c21

This change avoids undefined depth read/write feedback in Grand Theft Auto V on hosts without Vulkan feedback-loop support. It samples a pre-draw copy of the depth target instead. No actionable merge-blocking risk remains in the reviewed material. The fallback path has not been run in-game on such hardware, so a quick check there would still be useful.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: sampling a copy of depth targets on hosts without Vulkan feedback loops, for the GTA V on Intel Arc case. The raw summary confirms the copy path (CopyDepthForFeedback)…
Description check Passed The description explains the crash on GTA V depth sampling without VK_EXT_attachment_feedback_loop_layout, the redirect to a depth copy taken before the draw, copy lifetime and recreation rules, port …
Linked Issues check Passed The only linked issue is #1241. It is closed, so it supplies background only. No active directly linked target remains, so no linked-issue coding requirements apply. The PR objectives state the same. …
Out of Scope Changes check Passed The changes match the PR description and the reported objective, a port of #1241 to current main. textureCache.h declares CopyDepthForFeedback and ReleaseDepthFeedbackCopy. textureCache.cpp implements…
Full details: Title check

Explanation

The title names the main change: sampling a copy of depth targets on hosts without Vulkan feedback loops, for the GTA V on Intel Arc case. The raw summary confirms the copy path (CopyDepthForFeedback) in renderDraw.cpp, the texture cache, and the test update, so the title matches the changeset.

Full details: Description check

Explanation

The description explains the crash on GTA V depth sampling without VK_EXT_attachment_feedback_loop_layout, the redirect to a depth copy taken before the draw, copy lifetime and recreation rules, port notes, and test results. It matches the raw summary's texture cache, renderDraw, and test changes.

Full details: Linked Issues check

Explanation

The only linked issue is #1241. It is closed, so it supplies background only. No active directly linked target remains, so no linked-issue coding requirements apply. The PR objectives state the same. The PR text describes a port of #1241 onto current main. That port is not a requirement for this PR.

Full details: Out of Scope Changes check

Explanation

The changes match the PR description and the reported objective, a port of #1241 to current main. textureCache.h declares CopyDepthForFeedback and ReleaseDepthFeedbackCopy. textureCache.cpp implements the per-depth-image copy, its recreation on format, extent, mip, layer, or sample change, and its deferred release in DeleteImage. renderDraw.cpp redirects a sampled depth binding to the copy only when feedback loops are unavailable and the draw writes the sampled aspects. It also removes the log-once fallback. ShaderRecompilerComputeTests.cpp adds CheckRasterizationWithoutFeedbackLoops and tightens the per-draw depth-feedback assertion. The PR objectives also describe a commit that holds m_lock during the copy reuse check, erase, and insertion. That lock change applies to the copy path, so it is in scope. No unrelated change was identified. This verdict relies on the summaries and PR objectives. Line-level code was not inspected in this pass, so the lock change and the copy logic are not independently verified.

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 4673480c4d and 89c214082b.

Files selected for processing: 2

  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
Files skipped from review as they are similar to previous changes: 1

  • src/graphics/host_gpu/renderer/cache/textureCache.h

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-18 22:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2397#issuecomment-6993992065) · edited 2026-11-18 23:07 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/2397?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> TextureCache now creates, reuses, and releases cached copies of depth images. When a draw samples depth aspects that it also writes and attachment feedback loops are unavailable, RenderExecutor copies the relevant view and redirects the texture and mip-view bindings to that copy. The rasterization tests now exercise this path with feedback loops disabled and check the feedback aspects and sampled image. **Suggested reviewers:** `thecruz` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"89c214082b8c379a13b86e3f079905f205a1354c" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix · **Severity of issue fixed:** Medium <!-- 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>89c21</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `89c21` --> <!-- final_review_risk_coverage:{"sourceCommitId":"89c214082b8c379a13b86e3f079905f205a1354c","coveredCommitId":"89c214082b8c379a13b86e3f079905f205a1354c","kind":"reviewed"} --> This change avoids undefined depth read/write feedback in Grand Theft Auto V on hosts without Vulkan feedback-loop support. It samples a pre-draw copy of the depth target instead. No actionable merge-blocking risk remains in the reviewed material. The fallback path has not been run in-game on such hardware, so a quick check there would still be useful. <!-- 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: sampling a copy of depth targets on hosts without Vulkan feedback loops, for the GTA V on Intel Arc case. The raw summary confirms the copy path (CopyDepthForFeedback)… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description explains the crash on GTA V depth sampling without VK_EXT_attachment_feedback_loop_layout, the redirect to a depth copy taken before the draw, copy lifetime and recreation rules, port … | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The only linked issue is `#1241`. It is closed, so it supplies background only. No active directly linked target remains, so no linked-issue coding requirements apply. The PR objectives state the same. … | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The changes match the PR description and the reported objective, a port of `#1241` to current main. textureCache.h declares CopyDepthForFeedback and ReleaseDepthFeedbackCopy. textureCache.cpp implements… | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title names the main change: sampling a copy of depth targets on hosts without Vulkan feedback loops, for the GTA V on Intel Arc case. The raw summary confirms the copy path (CopyDepthForFeedback) in renderDraw.cpp, the texture cache, and the test update, so the title matches the changeset. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description explains the crash on GTA V depth sampling without VK_EXT_attachment_feedback_loop_layout, the redirect to a depth copy taken before the draw, copy lifetime and recreation rules, port notes, and test results. It matches the raw summary's texture cache, renderDraw, and test changes. </dd> </dl> </details> <details> <summary><strong>Full details: Linked Issues check</strong></summary> <dl> <dd> <br> **Explanation** The only linked issue is `#1241`. It is closed, so it supplies background only. No active directly linked target remains, so no linked-issue coding requirements apply. The PR objectives state the same. The PR text describes a port of `#1241` onto current main. That port is not a requirement for this PR. </dd> </dl> </details> <details> <summary><strong>Full details: Out of Scope Changes check</strong></summary> <dl> <dd> <br> **Explanation** The changes match the PR description and the reported objective, a port of `#1241` to current main. textureCache.h declares CopyDepthForFeedback and ReleaseDepthFeedbackCopy. textureCache.cpp implements the per-depth-image copy, its recreation on format, extent, mip, layer, or sample change, and its deferred release in DeleteImage. renderDraw.cpp redirects a sampled depth binding to the copy only when feedback loops are unavailable and the draw writes the sampled aspects. It also removes the log-once fallback. ShaderRecompilerComputeTests.cpp adds CheckRasterizationWithoutFeedbackLoops and tightens the per-draw depth-feedback assertion. The PR objectives also describe a commit that holds m_lock during the copy reuse check, erase, and insertion. That lock change applies to the copy path, so it is in scope. No unrelated change was identified. This verdict relies on the summaries and PR objectives. Line-level code was not inspected in this pass, so the lock change and the copy logic are not independently verified. </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=2397)! 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/a90be8dd7304640cf4176a975871d51443710292/.coderabbit.yaml>) - **Commit**: [a90be8d](<https://github.com/KytyPS5/KytyPS5/commit/a90be8dd7304640cf4176a975871d51443710292>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `2e02ce35-3c4d-48e8-9c2a-e559217d5244` </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 4673480c4d268fc544773fa824a8ab76110bed35 and 89c214082b8c379a13b86e3f079905f205a1354c. </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` * `src/graphics/host_gpu/renderer/cache/textureCache.h` </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-similar-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-similar.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files skipped from review as they are similar to previous changes: 1</strong></summary> <dl> <dd> <br> * src/graphics/host_gpu/renderer/cache/textureCache.h </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
Author
Owner

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

@@ -276,6 +277,76 @@ void TextureCache::DeleteImage(ImageId id) {
 	}
 }
 
+void TextureCache::ReleaseDepthFeedbackCopy(ImageId depth_id) {
+	const auto found = m_depth_feedback_copies.find(depth_id);
+	if (found == m_depth_feedback_copies.end()) {
+		return;
+	}
+	const auto copy_id = found->second;
+	m_depth_feedback_copies.erase(found);
+	// The copy is never registered: queued work may still sample it.
+	if (m_scheduler.Active()) {
+		m_scheduler.DeferOperation([this, copy_id] { m_slot_images.erase(copy_id); });
+	} else {
+		m_slot_images.erase(copy_id);
+	}
+}
+
+ImageId TextureCache::CopyDepthForFeedback(ImageId depth_id, const ImageSubresourceRange& range,
+                                           vk::ImageAspectFlags aspects) {
+	if (const auto found = m_depth_feedback_copies.find(depth_id);
+	    found != m_depth_feedback_copies.end()) {
+		const auto& depth = m_slot_images[depth_id].backing;
+		const auto& copy  = m_slot_images[found->second].backing;
+		if (copy.format != depth.format || copy.extent != depth.extent ||
+		    copy.mip_levels != depth.mip_levels || copy.layers != depth.layers ||
+		    copy.samples != depth.samples) {
+			ReleaseDepthFeedbackCopy(depth_id);
+		}
+	}
+	auto [entry, inserted] = m_depth_feedback_copies.try_emplace(depth_id);
+	if (inserted) {
+		// Same layout as the depth image, without guest memory: never registered or tracked.
+		auto info     = m_slot_images[depth_id].info;
+		info.data     = {};
+		info.stencil  = {};
+		info.metadata = {};
+		entry->second = m_slot_images.insert(m_graphics, m_scheduler, info);

Major · Stability & Availability · Quick win

Serialize the depth-feedback copy insertion with m_lock.

CopyDepthForFeedback inserts into m_slot_images without m_lock. When the free list is empty, SlotVector::insert grows m_chunks, m_stored, and m_free_list. A concurrent TextureCache::InvalidateMemory holds m_lock and reads those containers through operator[] and is_allocated. The unlocked growth can therefore race with those reads and reach freed container storage.

The insertion does not relocate existing images, so the stored Image references remain valid. The required change is to serialize the container mutation with InvalidateMemory.

Suggested fix

--- "a/src/graphics/host_gpu/renderer/cache/textureCache.cpp"
+++ "b/src/graphics/host_gpu/renderer/cache/textureCache.cpp"
@@ -305,14 +305,15 @@
 		}
 	}
 	auto [entry, inserted] = m_depth_feedback_copies.try_emplace(depth_id);
 	if (inserted) {
 		// Same layout as the depth image, without guest memory: never registered or tracked.
 		auto info     = m_slot_images[depth_id].info;
 		info.data     = {};
 		info.stencil  = {};
 		info.metadata = {};
-		entry->second = m_slot_images.insert(m_graphics, m_scheduler, info);
+		std::scoped_lock lock {m_lock};
+		entry->second = m_slot_images.insert(m_graphics, m_scheduler, info);
 	}
 	// References after the insertion: it may move the images.
 	auto& depth = m_slot_images[depth_id];
 	auto& copy  = m_slot_images[entry->second];

✅ Confirmed as addressed by @⁠oguzhanozfe

**@⁠coderabbitai[bot]** on GitHub · 2026-11-18 22:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2397#discussion_r4621962754) · edited 2026-11-18 23:04 UTC On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 314 (outdated): ```diff @@ -276,6 +277,76 @@ void TextureCache::DeleteImage(ImageId id) { } } +void TextureCache::ReleaseDepthFeedbackCopy(ImageId depth_id) { + const auto found = m_depth_feedback_copies.find(depth_id); + if (found == m_depth_feedback_copies.end()) { + return; + } + const auto copy_id = found->second; + m_depth_feedback_copies.erase(found); + // The copy is never registered: queued work may still sample it. + if (m_scheduler.Active()) { + m_scheduler.DeferOperation([this, copy_id] { m_slot_images.erase(copy_id); }); + } else { + m_slot_images.erase(copy_id); + } +} + +ImageId TextureCache::CopyDepthForFeedback(ImageId depth_id, const ImageSubresourceRange& range, + vk::ImageAspectFlags aspects) { + if (const auto found = m_depth_feedback_copies.find(depth_id); + found != m_depth_feedback_copies.end()) { + const auto& depth = m_slot_images[depth_id].backing; + const auto& copy = m_slot_images[found->second].backing; + if (copy.format != depth.format || copy.extent != depth.extent || + copy.mip_levels != depth.mip_levels || copy.layers != depth.layers || + copy.samples != depth.samples) { + ReleaseDepthFeedbackCopy(depth_id); + } + } + auto [entry, inserted] = m_depth_feedback_copies.try_emplace(depth_id); + if (inserted) { + // Same layout as the depth image, without guest memory: never registered or tracked. + auto info = m_slot_images[depth_id].info; + info.data = {}; + info.stencil = {}; + info.metadata = {}; + entry->second = m_slot_images.insert(m_graphics, m_scheduler, info); ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Stability & Availability** · **Quick win** **Serialize the depth-feedback copy insertion with `m_lock`.** `CopyDepthForFeedback` inserts into `m_slot_images` without `m_lock`. When the free list is empty, `SlotVector::insert` grows `m_chunks`, `m_stored`, and `m_free_list`. A concurrent `TextureCache::InvalidateMemory` holds `m_lock` and reads those containers through `operator[]` and `is_allocated`. The unlocked growth can therefore race with those reads and reach freed container storage. The insertion does not relocate existing images, so the stored `Image` references remain valid. The required change is to serialize the container mutation with `InvalidateMemory`. <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" @@ -305,14 +305,15 @@ } } auto [entry, inserted] = m_depth_feedback_copies.try_emplace(depth_id); if (inserted) { // Same layout as the depth image, without guest memory: never registered or tracked. auto info = m_slot_images[depth_id].info; info.data = {}; info.stencil = {}; info.metadata = {}; - entry->second = m_slot_images.insert(m_graphics, m_scheduler, info); + std::scoped_lock lock {m_lock}; + entry->second = m_slot_images.insert(m_graphics, m_scheduler, info); } // References after the insertion: it may move the images. auto& depth = m_slot_images[depth_id]; auto& copy = m_slot_images[entry->second]; ``` </dd> </dl> </details> <!-- fingerprinting:phantom:medusa:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:94f284ed3320d3aa4833f2e1 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠oguzhanozfe <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a90be8dd73 and 4673480c4d.

Files selected for processing: 4

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

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-18 22:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2397#pullrequestreview-5966486300) · **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/a90be8dd7304640cf4176a975871d51443710292/.coderabbit.yaml>) - **Commit**: [a90be8d](<https://github.com/KytyPS5/KytyPS5/commit/a90be8dd7304640cf4176a975871d51443710292>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `b47d0096-a9ee-434d-bee3-efddf5b5a9bb` </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 a90be8dd7304640cf4176a975871d51443710292 and 4673480c4d268fc544773fa824a8ab76110bed35. </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: 4</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/renderDraw.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; 6 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=a0106e83-6e56-4133-9b4e-435d28c5a7cb attempt=1c336a44-ee53-4162-a655-970de2e3407d batch=1/1 -->
Author
Owner

@⁠oguzhanozfe on GitHub · 2026-11-18 23:03 UTC · original
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 314 (outdated):

@@ -276,6 +277,76 @@ void TextureCache::DeleteImage(ImageId id) {
 	}
 }
 
+void TextureCache::ReleaseDepthFeedbackCopy(ImageId depth_id) {
+	const auto found = m_depth_feedback_copies.find(depth_id);
+	if (found == m_depth_feedback_copies.end()) {
+		return;
+	}
+	const auto copy_id = found->second;
+	m_depth_feedback_copies.erase(found);
+	// The copy is never registered: queued work may still sample it.
+	if (m_scheduler.Active()) {
+		m_scheduler.DeferOperation([this, copy_id] { m_slot_images.erase(copy_id); });
+	} else {
+		m_slot_images.erase(copy_id);
+	}
+}
+
+ImageId TextureCache::CopyDepthForFeedback(ImageId depth_id, const ImageSubresourceRange& range,
+                                           vk::ImageAspectFlags aspects) {
+	if (const auto found = m_depth_feedback_copies.find(depth_id);
+	    found != m_depth_feedback_copies.end()) {
+		const auto& depth = m_slot_images[depth_id].backing;
+		const auto& copy  = m_slot_images[found->second].backing;
+		if (copy.format != depth.format || copy.extent != depth.extent ||
+		    copy.mip_levels != depth.mip_levels || copy.layers != depth.layers ||
+		    copy.samples != depth.samples) {
+			ReleaseDepthFeedbackCopy(depth_id);
+		}
+	}
+	auto [entry, inserted] = m_depth_feedback_copies.try_emplace(depth_id);
+	if (inserted) {
+		// Same layout as the depth image, without guest memory: never registered or tracked.
+		auto info     = m_slot_images[depth_id].info;
+		info.data     = {};
+		info.stencil  = {};
+		info.metadata = {};
+		entry->second = m_slot_images.insert(m_graphics, m_scheduler, info);

Fixed in 89c21408. m_lock now covers the reuse check, the release of a stale copy (ReleaseDepthFeedbackCopy erases from m_slot_images too) and the insertion. This matches how FindImage inserts under the lock. The transfer commands still run outside it.

**@⁠oguzhanozfe** on GitHub · 2026-11-18 23:03 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2397#discussion_r4622063336) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 314 (outdated): ```diff @@ -276,6 +277,76 @@ void TextureCache::DeleteImage(ImageId id) { } } +void TextureCache::ReleaseDepthFeedbackCopy(ImageId depth_id) { + const auto found = m_depth_feedback_copies.find(depth_id); + if (found == m_depth_feedback_copies.end()) { + return; + } + const auto copy_id = found->second; + m_depth_feedback_copies.erase(found); + // The copy is never registered: queued work may still sample it. + if (m_scheduler.Active()) { + m_scheduler.DeferOperation([this, copy_id] { m_slot_images.erase(copy_id); }); + } else { + m_slot_images.erase(copy_id); + } +} + +ImageId TextureCache::CopyDepthForFeedback(ImageId depth_id, const ImageSubresourceRange& range, + vk::ImageAspectFlags aspects) { + if (const auto found = m_depth_feedback_copies.find(depth_id); + found != m_depth_feedback_copies.end()) { + const auto& depth = m_slot_images[depth_id].backing; + const auto& copy = m_slot_images[found->second].backing; + if (copy.format != depth.format || copy.extent != depth.extent || + copy.mip_levels != depth.mip_levels || copy.layers != depth.layers || + copy.samples != depth.samples) { + ReleaseDepthFeedbackCopy(depth_id); + } + } + auto [entry, inserted] = m_depth_feedback_copies.try_emplace(depth_id); + if (inserted) { + // Same layout as the depth image, without guest memory: never registered or tracked. + auto info = m_slot_images[depth_id].info; + info.data = {}; + info.stencil = {}; + info.metadata = {}; + entry->second = m_slot_images.insert(m_graphics, m_scheduler, info); ``` Fixed in 89c21408. `m_lock` now covers the reuse check, the release of a stale copy (`ReleaseDepthFeedbackCopy` erases from `m_slot_images` too) and the insertion. This matches how `FindImage` inserts under the lock. The transfer commands still run outside it.
Author
Owner

@⁠theantipopau on GitHub · 2026-11-23 00:09 UTC · original

This overlaps #2191, which is rebased on current main and adds two pieces this port does not: resident image-heap entries that sample the depth target are redirected to the copy, and a pending load clear is applied to the copy before the draw.

One correctness issue in this branch: the new assertion evaluates bindings.pixel.images[0].image_id even when no feedback depth read exists. On a draw without pixel images that indexes an empty vector; #2191's head 55ebbc58 makes the same check empty-safe. Worth comparing the two before either lands.

**@⁠theantipopau** on GitHub · 2026-11-23 00:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2397#issuecomment-7088113554) This overlaps #2191, which is rebased on current `main` and adds two pieces this port does not: resident image-heap entries that sample the depth target are redirected to the copy, and a pending load clear is applied to the copy before the draw. One correctness issue in this branch: the new assertion evaluates `bindings.pixel.images[0].image_id` even when no feedback depth read exists. On a draw without pixel images that indexes an empty vector; #2191's head `55ebbc58` makes the same check empty-safe. Worth comparing the two before either lands.
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/2397/head:github-bot/gh-2397'
git switch 'github-bot/gh-2397'

Merge

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