graphics: sample depth copies without attachment feedback loops #2191

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

@⁠theantipopau on GitHub · 2026-11-10 03:11 UTC · original
theantipopau:fix/depth-feedback-copy-fallback → main · +1019 −76 · 8 files · 2 commits · open

Summary

Some draws sample the depth attachment they also write. Vulkan only permits that through VK_EXT_attachment_feedback_loop_layout and VK_EXT_attachment_feedback_loop_dynamic_state; when either is missing, main disables feedback and falls back to eGeneral, where the draw still cannot legally sample the depth image it is writing and only logs the condition once. This adds a copy fallback for those hosts, porting the approach from the closed #1241 with stronger test assertions.

Change

  • TextureCache::CopyDepthForFeedback copies the sampled mips, layers and aspects into an image of its own, outside the render pass. The copy has the depth image's layout but no guest memory, so it is never registered or tracked.
  • AcquireRenderTargets builds the union of depth/stencil subresources sampled by the draw, copies them before the draw, and rebinds overlapping texture and mip-view bindings to the copy. Resident image-heap entries that sample the same subresources are redirected too, and the heap epoch is invalidated so the next draw rediscovers the original depth image. Disjoint or read-only views keep the original image.
  • A pending load clear is applied to the copy for the attachment's effective render area and layer count, so the first feedback draw sees the clear value without overwriting layers the draw does not clear.
  • The copy is refreshed for each draw, recreated if the depth image's shape changes, and released when the depth image is deleted (deferred while queued work may still sample it).
  • Hosts with feedback loops keep sampling the attachment directly.
  • CheckRasterizationWithoutFeedbackLoops runs the existing depth read/write case with feedback disabled and asserts that the depth attachment is not in the feedback layout, the sampled image is a different host-only depth image, and repeated draws still see prior depth writes.
  • Rasterization selectors skip cleanly when the host lacks depth clamping, matching the production pipeline's feature requirement.
  • The test harness treats feedback dynamic state as optional for rasterization support, matching vulkanWindow.cpp: it enables the layout and other rasterization features, chains/enables the dynamic-state extension only when the device has it, and gates vkCmdSetAttachmentFeedbackLoopEnableEXT accordingly. This lets the case run on hosts that expose only the layout extension.

Relation to #1187

#1187 handles hosts that have VK_EXT_attachment_feedback_loop_layout but not the dynamic-state extension by baking the feedback flag into the pipeline. This PR is the copy fallback for hosts where feedback loops are unavailable; the two are complementary and can coexist. #2213 is the rebased replacement for #1187.

Testing

  • Release clang-cl/Ninja build of shader_recompiler_compute_tests on Windows 11 against current main.
  • shader_recompiler_compute_tests --depth-feedback-copy-only passes: LeastRecentlyUsedCache, DepthAttachmentFeedback.
  • shader_recompiler_compute_tests --image-rebind-only passes: LeastRecentlyUsedCache, RenderExecutorStencilBindingDiscovery.
  • GPU runs on an RX 9070 XT (RADV, Vulkan 1.4). No GTA V/RDR2 installation here, so there is no in-game run.

AI assistance

Codebuff helped implement and test the change. I reviewed the code and the results.

**@⁠theantipopau** on GitHub · 2026-11-10 03:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191) `theantipopau:fix/depth-feedback-copy-fallback` → `main` · +1019 −76 · 8 files · 2 commits · open ## Summary Some draws sample the depth attachment they also write. Vulkan only permits that through `VK_EXT_attachment_feedback_loop_layout` and `VK_EXT_attachment_feedback_loop_dynamic_state`; when either is missing, `main` disables feedback and falls back to `eGeneral`, where the draw still cannot legally sample the depth image it is writing and only logs the condition once. This adds a copy fallback for those hosts, porting the approach from the closed #1241 with stronger test assertions. ## Change - `TextureCache::CopyDepthForFeedback` copies the sampled mips, layers and aspects into an image of its own, outside the render pass. The copy has the depth image's layout but no guest memory, so it is never registered or tracked. - `AcquireRenderTargets` builds the union of depth/stencil subresources sampled by the draw, copies them before the draw, and rebinds overlapping texture and mip-view bindings to the copy. Resident image-heap entries that sample the same subresources are redirected too, and the heap epoch is invalidated so the next draw rediscovers the original depth image. Disjoint or read-only views keep the original image. - A pending load clear is applied to the copy for the attachment's effective render area and layer count, so the first feedback draw sees the clear value without overwriting layers the draw does not clear. - The copy is refreshed for each draw, recreated if the depth image's shape changes, and released when the depth image is deleted (deferred while queued work may still sample it). - Hosts with feedback loops keep sampling the attachment directly. - `CheckRasterizationWithoutFeedbackLoops` runs the existing depth read/write case with feedback disabled and asserts that the depth attachment is not in the feedback layout, the sampled image is a different host-only depth image, and repeated draws still see prior depth writes. - Rasterization selectors skip cleanly when the host lacks depth clamping, matching the production pipeline's feature requirement. - The test harness treats feedback dynamic state as optional for rasterization support, matching `vulkanWindow.cpp`: it enables the layout and other rasterization features, chains/enables the dynamic-state extension only when the device has it, and gates `vkCmdSetAttachmentFeedbackLoopEnableEXT` accordingly. This lets the case run on hosts that expose only the layout extension. ## Relation to #1187 #1187 handles hosts that have `VK_EXT_attachment_feedback_loop_layout` but not the dynamic-state extension by baking the feedback flag into the pipeline. This PR is the copy fallback for hosts where feedback loops are unavailable; the two are complementary and can coexist. #2213 is the rebased replacement for #1187. ## Testing - Release `clang-cl`/Ninja build of `shader_recompiler_compute_tests` on Windows 11 against current `main`. - `shader_recompiler_compute_tests --depth-feedback-copy-only` passes: `LeastRecentlyUsedCache`, `DepthAttachmentFeedback`. - `shader_recompiler_compute_tests --image-rebind-only` passes: `LeastRecentlyUsedCache`, `RenderExecutorStencilBindingDiscovery`. - GPU runs on an RX 9070 XT (RADV, Vulkan 1.4). No GTA V/RDR2 installation here, so there is no in-game run. ## AI assistance Codebuff helped implement and test the change. I reviewed the code and the results.
Hosts without Vulkan attachment feedback loops could not sample a depth
attachment they also wrote. Copy the sampled depth subresources before the
draw, redirect overlapping texture and image-heap bindings to that copy, and
preserve pending clears and heap synchronization.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <[email protected]>
A draw without pixel images made the rasterization test read element zero of an empty binding list instead of reporting a clean failure.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:16:40 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-10 03:14 UTC · original · edited 2026-11-23 00:08 UTC

Explain Change →

Note

Reviews paused

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

  • Last reviewed commit: 48ca227ab3d49a517d23993cf6caf371caf70605
  • Latest commit, not reviewed: 55ebbc584c

Use the following commands to manage reviews:

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

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

When attachment feedback loops are unavailable, the renderer copies overlapping sampled depth subresources and redirects matching texture bindings to the copy. The texture cache reuses copies when their backing properties match and releases them when the depth image is deleted. Rasterization tests cover the fallback and configure dynamic feedback-state support separately.

Suggested reviewers: nmzik

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Moderate · previous review 48ca2

The depth-copy fallback can produce wrong sampled depth values in multi-draw and multi-layer cases on hosts without feedback loops. Some test selectors can also reach unsupported rasterization setup. These should be addressed before merge, or the limits explicitly accepted.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: using depth copies when Vulkan attachment feedback loops are unavailable.
Linked Issues check Passed Issue #1241 is closed and provides historical context only. No active directly linked issue remains. Therefore, no linked-issue coding requirements apply.
Out of Scope Changes check Passed The changes remain within the stated depth-feedback fallback scope. Texture-cache copy handling, render-target rebinding, image-heap redirection, copy lifetime handling, and rasterization harness cove…
Description check Passed The description explains a depth-copy fallback for hosts without attachment feedback loop support. It names the changed pieces: TextureCache::CopyDepthForFeedback, AcquireRenderTargets rebinding, copy…
Full details: Out of Scope Changes check

Explanation

The changes remain within the stated depth-feedback fallback scope. Texture-cache copy handling, render-target rebinding, image-heap redirection, copy lifetime handling, and rasterization harness coverage all support the fallback or its tests. No unrelated change is demonstrated.

Full details: Description check

Explanation

The description explains a depth-copy fallback for hosts without attachment feedback loop support. It names the changed pieces: TextureCache::CopyDepthForFeedback, AcquireRenderTargets rebinding, copy refresh and release, the test harness changes, and CheckRasterizationWithoutFeedbackLoops. It also lists build and test runs. This is clearly related to the changeset, so the check passes.

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-10 03:14 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#issuecomment-6757926331) · edited 2026-11-23 00:08 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/2191?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > - Last reviewed commit: 48ca227ab3d49a517d23993cf6caf371caf70605 > - Latest commit, not reviewed: 55ebbc584cf528d89984711479efd1131ee8ea52 > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> When attachment feedback loops are unavailable, the renderer copies overlapping sampled depth subresources and redirects matching texture bindings to the copy. The texture cache reuses copies when their backing properties match and releases them when the depth image is deleted. Rasterization tests cover the fallback and configure dynamic feedback-state support separately. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"48ca227ab3d49a517d23993cf6caf371caf70605" --> <!-- 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-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Moderate</strong> · previous review <code>48ca2</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🟡 Moderate** · up to `48ca2` --> <!-- final_review_risk_coverage:{"sourceCommitId":"48ca227ab3d49a517d23993cf6caf371caf70605","coveredCommitId":"48ca227ab3d49a517d23993cf6caf371caf70605","kind":"reviewed"} --> The depth-copy fallback can produce wrong sampled depth values in multi-draw and multi-layer cases on hosts without feedback loops. Some test selectors can also reach unsupported rasterization setup. These should be addressed before merge, or the limits explicitly accepted. <!-- 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 clearly and concisely describes the main change: using depth copies when Vulkan attachment feedback loops are unavailable. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Issue `#1241` is closed and provides historical context only. No active directly linked issue remains. Therefore, no linked-issue coding requirements apply. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The changes remain within the stated depth-feedback fallback scope. Texture-cache copy handling, render-target rebinding, image-heap redirection, copy lifetime handling, and rasterization harness cove… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description explains a depth-copy fallback for hosts without attachment feedback loop support. It names the changed pieces: TextureCache::CopyDepthForFeedback, AcquireRenderTargets rebinding, copy… | <details> <summary><strong>Full details: Out of Scope Changes check</strong></summary> <dl> <dd> <br> **Explanation** The changes remain within the stated depth-feedback fallback scope. Texture-cache copy handling, render-target rebinding, image-heap redirection, copy lifetime handling, and rasterization harness coverage all support the fallback or its tests. No unrelated change is demonstrated. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description explains a depth-copy fallback for hosts without attachment feedback loop support. It names the changed pieces: TextureCache::CopyDepthForFeedback, AcquireRenderTargets rebinding, copy refresh and release, the test harness changes, and CheckRasterizationWithoutFeedbackLoops. It also lists build and test runs. This is clearly related to the changeset, so the check passes. </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=2191)! 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 -->
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-10 14:47 UTC · original

Tested on Windows 11, AMD Radeon RX 9070 XT (RDNA4), AMD proprietary driver 26.10.1 (LLPC), Vulkan 1.4.359, clang-cl Release build of 9d365ccff. The driver exposes VK_EXT_attachment_feedback_loop_layout (attachmentFeedbackLoopLayout = true) but not VK_EXT_attachment_feedback_loop_dynamic_state; the Ryzen 7600X iGPU (RDNA2, same driver, proprietary shader compiler) shows the same pair. So main takes the eGeneral fallback on both, and this host runs the copy path.

Results on the RX 9070 XT:

  • The unmodified harness of 9d365ccff still stops before any rasterization check, at VulkanHarness failed at dispatch: byte-granular per-pipeline robustBufferAccess2 is not supported (same as your RADV note). With only a local change that makes the robust-buffer cases optional (plus two unrelated local workarounds for AMD driver issues), the harness starts, and your optional dynamic-state handling is enough. The local feedback-optional change we used on main is no longer needed.
  • --depth-feedback-copy-only: [gpu] DepthAttachmentFeedback ok, no failed check. --sampled-depth-resource-only: all ok, both DepthAttachmentFeedback runs included. "depth attachment feedback loop is not supported by the host" is never printed.
  • The new check does exercise the copy here. With the copies.push_back(region) line in CopyDepthForFeedback removed (no copy regions recorded), the same selector fails at sampled and stored depth (64 failed checks in that run).
  • --polygon-mode-only and the full suite crash with an access violation (read of 0x0) in CheckRasterization(false). See note 1.
  • Full suite with that line guarded, compared with main 782a85c62 under the same local changes plus the feedback-optional one: 19 failed checks instead of 22. The three DepthAttachmentFeedback ... failed at per-draw depth feedback failures are gone, and no new failure appears. The four RenderExecutorStencilBindingDiscovery failures stay (note 2).

Notes, most important first:

  1. Test crash: CheckRasterization now reads bindings.pixel.images[0].image_id for every draw (ShaderRecompilerComputeTests.cpp:20293). The polygon-mode and packed-vertex-color draws have no pixel images, so this reads element 0 of an empty vector. Before, the read was behind !depth_feedback ||. On this host it is a null read, and --polygon-mode-only and the full run stop there. const ImageId sampled_id = depth_feedback ? bindings.pixel.images[0].image_id : ImageId{}; fixes it: after that change, --polygon-mode-only passes (PolygonModeRasterization, PackedFloatVertexColor, PackedUscaledVertexColor ok). CI does not show it: the workflow builds shader_recompiler_compute_tests but its Test step runs only the CPU test list (build.yml:127).

  2. On hosts with only the layout extension, CheckRenderExecutorStencilBindingDiscovery (which main reached here only with our local feedback-optional change, and which fails there too) still requires eAttachmentFeedbackLoopOptimalEXT (ShaderRecompilerComputeTests.cpp:17353 and :17396, and the deferred-clear and stencil parts). Here it fails 4 times (disjoint depth sampling during depth writes, overlapping and disjoint depth views, deferred clear with sampled depth bounds, sampled depth and stencil attachment layout). A run without keep-going stops at the first one. Since this PR lets these hosts run the rasterization checks without that change, those expectations (the layout, and also the feedback aspects and original-image identities the same parts check) could follow attachment_feedback_loop_enabled the way CheckRasterization now does, or the check could be skipped there.

  3. A pending depth or stencil clear is not in the copy. AcquireRenderTargets turns an HTile clear (or depth_clear_enable / stencil_clear_enable) into load_clear_aspects (renderDraw.cpp:486-498), and the clear only happens at the load op of the next BeginRendering (context.cpp:62-71). CopyDepthForFeedback runs before that (renderDraw.cpp:555), so a draw that samples an aspect it also clears reads the values from before the clear, while on a host with feedback loops the same draw samples the cleared attachment. When load_clear_aspects & copy_aspects is set, the copy's subresources in the attachment view's range could be cleared to depth_clear_value / stencil_clear_value after the copy, with the pending clear's aspects, layers and render area. The load op clears only the render area, which is the smallest extent of all bound attachments (renderDraw.cpp:474-476 and :609-611, context.cpp:76) and can be smaller than the depth mip, so clearDepthStencilImage on the copy (outside the pass, with a transition to a transfer layout and back, since the copy is already in its read layout) matches only a full-area clear; a smaller area needs a rectangle clear.

  4. The overlap test looks only at the native view, which can miss a mip the draw writes. MakeDepthTargetDesc sets level 0, but FindImage(r.desc) remaps view_info.base_level when the target resolves to a mip of a larger cached image (textureCache.cpp:924-927, :1398-1399). For a binding with dynamic mip selection the native view is mip_views.front(), a single level at the binding's base level (descriptors.cpp:867-876). If the target is level k of the image and the binding's base level is below k while its mip_views reach k, the native view is disjoint, so no copy is made and the binding samples the level being written. Checking DepthFeedbackAspects per mip view would close it, both where the copy is decided (renderDraw.cpp:521) and where bindings are rebound (renderDraw.cpp:569-570): the rebind uses the same native-only test, so a copy decided per mip view would otherwise not be bound.

  5. Copies are never registered, so they have no LRU entry of their own and are not in registration-based memory accounting. Each depth target that ever had a copied draw keeps a same-size second image until the depth image itself is deleted. When the device reports memory usage, RunGarbageCollector refreshes m_total_used_memory from it (textureCache.cpp:2101-2102), so the total includes these copies; otherwise it does not.

  6. Cost per copied draw: the open render pass ends (textureCache.cpp:310), there are up to three barrier batches (depth to transfer source, copy to transfer destination, copy to read layout), plus a copy of the bounding mip/layer range of the sampled views (which can include combinations no view samples), and the attachment goes back to its layout (renderDraw.cpp:605). Refreshing on every read/write draw is needed for correctness. A frame-time number from a game that hits this path would show whether the cost matters.

Checked and fine:

  • Hosts with feedback loops take the old path unchanged: the copy loop only runs when attachment_feedback_loop_enabled is false. Bindings that are not copied still add to sampled_aspects/feedback_aspects as before.
  • Disjoint or read-only views keep the original image.
  • The copy keeps the depth image's pixel_format (only data, stencil and metadata are cleared), so stencil-aspect copies have a stencil plane. Stencil association bindings resolve to the depth image id (descriptors.cpp:642-645), so they are covered.
  • MSAA: copyImage between images with the same sample count is valid. MSAA images have one level.
  • The rebound copy_id does not leak into the next draw: PrepareBindings resolves every binding again (descriptors.cpp:727-737).
  • CopyDepthForFeedback and AcquireRenderTargets record into the same command buffer (the scheduler's single m_command).
  • The test proves the copy is refreshed per draw: each draw writes sampled depth + 0.125, so after three read/write draws the read-only draw reads initial + 0.375 only if every copy saw the previous draw's write. It does not cover stencil-aspect copies, the level/layer union, a disjoint view staying on the original image, or the release on DeleteImage.

With #1187 merged, the renderer on layout-only hosts like these two would use the static feedback pipeline instead, and its copy fallback would only run on hosts without the layout extension (the new test forces the copy path either way).

**@⁠Nawid3333** on GitHub · 2026-11-10 14:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#issuecomment-6770413819) Tested on Windows 11, AMD Radeon RX 9070 XT (RDNA4), AMD proprietary driver 26.10.1 (LLPC), Vulkan 1.4.359, clang-cl Release build of 9d365ccff. The driver exposes `VK_EXT_attachment_feedback_loop_layout` (`attachmentFeedbackLoopLayout = true`) but not `VK_EXT_attachment_feedback_loop_dynamic_state`; the Ryzen 7600X iGPU (RDNA2, same driver, proprietary shader compiler) shows the same pair. So `main` takes the `eGeneral` fallback on both, and this host runs the copy path. Results on the RX 9070 XT: - The unmodified harness of 9d365ccff still stops before any rasterization check, at `VulkanHarness failed at dispatch: byte-granular per-pipeline robustBufferAccess2 is not supported` (same as your RADV note). With only a local change that makes the robust-buffer cases optional (plus two unrelated local workarounds for AMD driver issues), the harness starts, and your optional dynamic-state handling is enough. The local feedback-optional change we used on `main` is no longer needed. - `--depth-feedback-copy-only`: `[gpu] DepthAttachmentFeedback ok`, no failed check. `--sampled-depth-resource-only`: all ok, both `DepthAttachmentFeedback` runs included. "depth attachment feedback loop is not supported by the host" is never printed. - The new check does exercise the copy here. With the `copies.push_back(region)` line in `CopyDepthForFeedback` removed (no copy regions recorded), the same selector fails at `sampled and stored depth` (64 failed checks in that run). - `--polygon-mode-only` and the full suite crash with an access violation (read of 0x0) in `CheckRasterization(false)`. See note 1. - Full suite with that line guarded, compared with `main` 782a85c62 under the same local changes plus the feedback-optional one: 19 failed checks instead of 22. The three `DepthAttachmentFeedback ... failed at per-draw depth feedback` failures are gone, and no new failure appears. The four `RenderExecutorStencilBindingDiscovery` failures stay (note 2). Notes, most important first: 1. Test crash: `CheckRasterization` now reads `bindings.pixel.images[0].image_id` for every draw (ShaderRecompilerComputeTests.cpp:20293). The polygon-mode and packed-vertex-color draws have no pixel images, so this reads element 0 of an empty vector. Before, the read was behind `!depth_feedback ||`. On this host it is a null read, and `--polygon-mode-only` and the full run stop there. `const ImageId sampled_id = depth_feedback ? bindings.pixel.images[0].image_id : ImageId{};` fixes it: after that change, `--polygon-mode-only` passes (`PolygonModeRasterization`, `PackedFloatVertexColor`, `PackedUscaledVertexColor` ok). CI does not show it: the workflow builds `shader_recompiler_compute_tests` but its Test step runs only the CPU test list (build.yml:127). 2. On hosts with only the layout extension, `CheckRenderExecutorStencilBindingDiscovery` (which `main` reached here only with our local feedback-optional change, and which fails there too) still requires `eAttachmentFeedbackLoopOptimalEXT` (ShaderRecompilerComputeTests.cpp:17353 and :17396, and the deferred-clear and stencil parts). Here it fails 4 times (`disjoint depth sampling during depth writes`, `overlapping and disjoint depth views`, `deferred clear with sampled depth bounds`, `sampled depth and stencil attachment layout`). A run without keep-going stops at the first one. Since this PR lets these hosts run the rasterization checks without that change, those expectations (the layout, and also the feedback aspects and original-image identities the same parts check) could follow `attachment_feedback_loop_enabled` the way `CheckRasterization` now does, or the check could be skipped there. 3. A pending depth or stencil clear is not in the copy. `AcquireRenderTargets` turns an HTile clear (or `depth_clear_enable` / `stencil_clear_enable`) into `load_clear_aspects` (renderDraw.cpp:486-498), and the clear only happens at the load op of the next `BeginRendering` (context.cpp:62-71). `CopyDepthForFeedback` runs before that (renderDraw.cpp:555), so a draw that samples an aspect it also clears reads the values from before the clear, while on a host with feedback loops the same draw samples the cleared attachment. When `load_clear_aspects & copy_aspects` is set, the copy's subresources in the attachment view's range could be cleared to `depth_clear_value` / `stencil_clear_value` after the copy, with the pending clear's aspects, layers and render area. The load op clears only the render area, which is the smallest extent of all bound attachments (renderDraw.cpp:474-476 and :609-611, context.cpp:76) and can be smaller than the depth mip, so `clearDepthStencilImage` on the copy (outside the pass, with a transition to a transfer layout and back, since the copy is already in its read layout) matches only a full-area clear; a smaller area needs a rectangle clear. 4. The overlap test looks only at the native view, which can miss a mip the draw writes. `MakeDepthTargetDesc` sets level 0, but `FindImage(r.desc)` remaps `view_info.base_level` when the target resolves to a mip of a larger cached image (textureCache.cpp:924-927, :1398-1399). For a binding with dynamic mip selection the native view is `mip_views.front()`, a single level at the binding's base level (descriptors.cpp:867-876). If the target is level k of the image and the binding's base level is below k while its `mip_views` reach k, the native view is disjoint, so no copy is made and the binding samples the level being written. Checking `DepthFeedbackAspects` per mip view would close it, both where the copy is decided (renderDraw.cpp:521) and where bindings are rebound (renderDraw.cpp:569-570): the rebind uses the same native-only test, so a copy decided per mip view would otherwise not be bound. 5. Copies are never registered, so they have no LRU entry of their own and are not in registration-based memory accounting. Each depth target that ever had a copied draw keeps a same-size second image until the depth image itself is deleted. When the device reports memory usage, `RunGarbageCollector` refreshes `m_total_used_memory` from it (textureCache.cpp:2101-2102), so the total includes these copies; otherwise it does not. 6. Cost per copied draw: the open render pass ends (textureCache.cpp:310), there are up to three barrier batches (depth to transfer source, copy to transfer destination, copy to read layout), plus a copy of the bounding mip/layer range of the sampled views (which can include combinations no view samples), and the attachment goes back to its layout (renderDraw.cpp:605). Refreshing on every read/write draw is needed for correctness. A frame-time number from a game that hits this path would show whether the cost matters. Checked and fine: - Hosts with feedback loops take the old path unchanged: the copy loop only runs when `attachment_feedback_loop_enabled` is false. Bindings that are not copied still add to `sampled_aspects`/`feedback_aspects` as before. - Disjoint or read-only views keep the original image. - The copy keeps the depth image's `pixel_format` (only `data`, `stencil` and `metadata` are cleared), so stencil-aspect copies have a stencil plane. Stencil association bindings resolve to the depth image id (descriptors.cpp:642-645), so they are covered. - MSAA: `copyImage` between images with the same sample count is valid. MSAA images have one level. - The rebound `copy_id` does not leak into the next draw: `PrepareBindings` resolves every binding again (descriptors.cpp:727-737). - `CopyDepthForFeedback` and `AcquireRenderTargets` record into the same command buffer (the scheduler's single `m_command`). - The test proves the copy is refreshed per draw: each draw writes sampled depth + 0.125, so after three read/write draws the read-only draw reads initial + 0.375 only if every copy saw the previous draw's write. It does not cover stencil-aspect copies, the level/layer union, a disjoint view staying on the original image, or the release on `DeleteImage`. With #1187 merged, the renderer on layout-only hosts like these two would use the static feedback pipeline instead, and its copy fallback would only run on hosts without the layout extension (the new test forces the copy path either way).
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 10:51 UTC · original · reviewed

Actionable comments posted: 1

Additional comments: 1

tests/ShaderRecompilerComputeTests.cpp-23733-23733: 1

23733-23733: Major · Functional Correctness · Heavy lift

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Allow the copy test to run without the feedback-layout feature.

If the host lacks attachmentFeedbackLoopLayout, this condition disables all rasterization features. --depth-feedback-copy-only still runs the rasterization test, but it cannot test the fallback on that host with a valid device setup. Separate feedback-layout support from rasterization support and make the feature chain conditional. (raw.githubusercontent.com)

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9d365ccff49a9e35408ec8e886adc18f658800e8 and afff2b8bb8e09daf5203e9e04ffa71c680a87294.

Files selected for processing: 1

  • 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-11 10:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#pullrequestreview-5857590952) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/message-square-off-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/message-square-off.svg" width="16" height="16" align="absmiddle" alt=""></picture> Additional comments: 1</summary><blockquote> <dl> <dd> <br> <details> <summary>tests/ShaderRecompilerComputeTests.cpp-23733-23733: 1</summary><blockquote> <dl> <dd> <br> `23733-23733`: **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Heavy lift** <picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg" width="20" height="20" align="absmiddle" alt=""></picture> **Unverified finding** Verification ran but could not confirm this finding. It is shown for review, not as a verified issue. **Allow the copy test to run without the feedback-layout feature.** If the host lacks `attachmentFeedbackLoopLayout`, this condition disables all rasterization features. `--depth-feedback-copy-only` still runs the rasterization test, but it cannot test the fallback on that host with a valid device setup. Separate feedback-layout support from rasterization support and make the feature chain conditional. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/afff2b8bb8e09daf5203e9e04ffa71c680a87294/tests/ShaderRecompilerComputeTests.cpp)) <!-- cr-comment:v1:90e9ecf0620c038743bcf1a6 --> </dd> </dl> </blockquote></details> </dd> </dl> </blockquote></details> <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/782a85c621bd849762599a6a0e790596be119505/.coderabbit.yaml>) - **Commit**: [782a85c](<https://github.com/KytyPS5/KytyPS5/commit/782a85c621bd849762599a6a0e790596be119505>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `ed9faf3f-d165-4fd7-9d87-d1e71aa54b0b` </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 9d365ccff49a9e35408ec8e886adc18f658800e8 and afff2b8bb8e09daf5203e9e04ffa71c680a87294. </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: 1</summary> <dl> <dd> <br> * `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=252a66dd-efe1-470d-a621-df306edf789d attempt=d068856c-0a2e-48bb-9fa7-9107b1a5e43e batch=1/1 -->
@ -24277,0 +24750,4 @@
#if !defined(__APPLE__)
// The production pipeline enables depth clamping on non-Apple platforms.
m_rasterization_supported =
m_rasterization_supported && available_features.depthClamp;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 10:51 UTC · original

Major · Stability & Availability · Quick win

Supported by static analysis

Script executed:

rg -n 'm_rasterization_supported|m_feedback_dynamic|depthClamp|depthClampEnable|SetAttachmentFeedbackLoopEnable|CmdSetAttachmentFeedbackLoopEnable' tests/ShaderRecompilerComputeTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 1609


Script executed:

rg -n -F -e 'CheckShaderStore' -e 'CheckRasterization' -e 'RasterizationSupported' -e 'depthClampEnable' -e 'depth-feedback-copy-only' -e 'm_feedback_dynamic_supported' -e 'createGraphicsPipeline' -e 'CreateGraphicsPipeline' -- tests/ShaderRecompilerComputeTests.cpp
cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '2190,2215p;20335,20375p;23480,23515p;23690,23890p'
git diff 782a85c621bd849762599a6a0e790596be119505 afff2b8bb8e09daf5203e9e04ffa71c680a87294 -- tests/ShaderRecompilerComputeTests.cpp | rg -n -C 4 'depthClamp|Rasterization|ShaderStore|feedback_dynamic|depth-feedback-copy-only'

Repository: KytyPS5/KytyPS5

Length of output: 27174


Script executed:

rg -n -F -e 'depthClampEnable' -e 'CreateGraphicsPipeline(' -- src tests/ShaderRecompilerComputeTests.cpp
cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '2280,2370p;20055,20165p;20230,20340p;24355,24405p;49480,49570p;55800,55840p;56725,56795p;56855,56890p;56970,57012p;57015,57040p;57095,57155p'

Repository: KytyPS5/KytyPS5

Length of output: 39102


Script executed:

rg -n -F -e 'GetGraphicsPipeline(' -e 'CreateGraphicsPipeline(' -e 'rasterizer.depthClampEnable' -e 'available_feedback_dynamic' -- src/graphics/host_gpu/renderer/pipeline tests/ShaderRecompilerComputeTests.cpp
cat -n src/graphics/host_gpu/renderer/pipeline/shaders.cpp | sed -n '190,260p'
cat -n src/graphics/host_gpu/renderer/pipeline/pipelineSerialization.cpp | sed -n '305,380p'
cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '23570,23690p;49565,49660p'

Repository: KytyPS5/KytyPS5

Length of output: 20775


Script executed:

cat -n src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp | sed -n '875,960p'
rg -n -F -e 'CreatePipelineInternal' -e 'createGraphicsPipeline' -- src/graphics/host_gpu/renderer/pipeline/shaders.cpp src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
cat -n src/graphics/host_gpu/renderer/pipeline/shaders.cpp | sed -n '100,155p;300,395p'

Repository: KytyPS5/KytyPS5

Length of output: 14393


Web query:

Vulkan VkPipelineRasterizationStateCreateInfo depthClampEnable depthClamp feature VUID enabled must VK_FALSE

Result:

Sources consulted:
- VkPipelineRasterizationStateCreateInfo(3) :: Vulkan Documentation Project — https://docs.vulkan.org/refpages/latest/refpages/source/VkPipelineRasterizationStateCreateInfo.html
- Rasterization :: Vulkan Documentation Project — https://docs.vulkan.org/spec/latest/chapters/primsrast.html
- Features :: Vulkan Documentation Project — https://docs.vulkan.org/spec/latest/chapters/features.html
- VkPhysicalDeviceFeatures(3) :: Vulkan Documentation Project — https://github.khronos.org/Vulkan-Site/refpages/latest/refpages/source/VkPhysicalDeviceFeatures.html
- vkCmdSetDepthClampEnableEXT(3) :: Vulkan Documentation Project — https://docs.vulkan.org/refpages/latest/refpages/source/vkCmdSetDepthClampEnableEXT.html

Script executed:

cat -n src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp | sed -n '1035,1075p'

Repository: KytyPS5/KytyPS5

Length of output: 1966


Guard rasterization callers when depth clamp is unavailable.

On a non-Apple host without depthClamp, the copy selector and CheckShaderStore can create a graphics pipeline with depth clamping enabled on a device without that feature. If the draw proceeds and the physical device supports feedback dynamic state, it can also call the command without enabling its extension.

Guard these callers or report the unsupported configuration before they run.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 10:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4536975121) <!-- 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** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details.svg" width="16" height="16" align="absmiddle" alt=""></picture> Supported by static analysis</summary> <dl> <dd> <br> Script executed: ```bash rg -n 'm_rasterization_supported|m_feedback_dynamic|depthClamp|depthClampEnable|SetAttachmentFeedbackLoopEnable|CmdSetAttachmentFeedbackLoopEnable' tests/ShaderRecompilerComputeTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 1609 --- Script executed: ```bash rg -n -F -e 'CheckShaderStore' -e 'CheckRasterization' -e 'RasterizationSupported' -e 'depthClampEnable' -e 'depth-feedback-copy-only' -e 'm_feedback_dynamic_supported' -e 'createGraphicsPipeline' -e 'CreateGraphicsPipeline' -- tests/ShaderRecompilerComputeTests.cpp cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '2190,2215p;20335,20375p;23480,23515p;23690,23890p' git diff 782a85c621bd849762599a6a0e790596be119505 afff2b8bb8e09daf5203e9e04ffa71c680a87294 -- tests/ShaderRecompilerComputeTests.cpp | rg -n -C 4 'depthClamp|Rasterization|ShaderStore|feedback_dynamic|depth-feedback-copy-only' ``` Repository: KytyPS5/KytyPS5 Length of output: 27174 --- Script executed: ```bash rg -n -F -e 'depthClampEnable' -e 'CreateGraphicsPipeline(' -- src tests/ShaderRecompilerComputeTests.cpp cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '2280,2370p;20055,20165p;20230,20340p;24355,24405p;49480,49570p;55800,55840p;56725,56795p;56855,56890p;56970,57012p;57015,57040p;57095,57155p' ``` Repository: KytyPS5/KytyPS5 Length of output: 39102 --- Script executed: ```bash rg -n -F -e 'GetGraphicsPipeline(' -e 'CreateGraphicsPipeline(' -e 'rasterizer.depthClampEnable' -e 'available_feedback_dynamic' -- src/graphics/host_gpu/renderer/pipeline tests/ShaderRecompilerComputeTests.cpp cat -n src/graphics/host_gpu/renderer/pipeline/shaders.cpp | sed -n '190,260p' cat -n src/graphics/host_gpu/renderer/pipeline/pipelineSerialization.cpp | sed -n '305,380p' cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '23570,23690p;49565,49660p' ``` Repository: KytyPS5/KytyPS5 Length of output: 20775 --- Script executed: ```bash cat -n src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp | sed -n '875,960p' rg -n -F -e 'CreatePipelineInternal' -e 'createGraphicsPipeline' -- src/graphics/host_gpu/renderer/pipeline/shaders.cpp src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp cat -n src/graphics/host_gpu/renderer/pipeline/shaders.cpp | sed -n '100,155p;300,395p' ``` Repository: KytyPS5/KytyPS5 Length of output: 14393 --- Web query: `Vulkan VkPipelineRasterizationStateCreateInfo depthClampEnable depthClamp feature VUID enabled must VK_FALSE` Result: ``` Sources consulted: - VkPipelineRasterizationStateCreateInfo(3) :: Vulkan Documentation Project — https://docs.vulkan.org/refpages/latest/refpages/source/VkPipelineRasterizationStateCreateInfo.html - Rasterization :: Vulkan Documentation Project — https://docs.vulkan.org/spec/latest/chapters/primsrast.html - Features :: Vulkan Documentation Project — https://docs.vulkan.org/spec/latest/chapters/features.html - VkPhysicalDeviceFeatures(3) :: Vulkan Documentation Project — https://github.khronos.org/Vulkan-Site/refpages/latest/refpages/source/VkPhysicalDeviceFeatures.html - vkCmdSetDepthClampEnableEXT(3) :: Vulkan Documentation Project — https://docs.vulkan.org/refpages/latest/refpages/source/vkCmdSetDepthClampEnableEXT.html ``` --- Script executed: ```bash cat -n src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp | sed -n '1035,1075p' ``` Repository: KytyPS5/KytyPS5 Length of output: 1966 --- </dd> </dl> </details> **Guard rasterization callers when depth clamp is unavailable.** On a non-Apple host without `depthClamp`, the copy selector and `CheckShaderStore` can create a graphics pipeline with depth clamping enabled on a device without that feature. If the draw proceeds and the physical device supports feedback dynamic state, it can also call the command without enabling its extension. Guard these callers or report the unsupported configuration before they run. <!-- fingerprinting:phantom:medusa:beignet55 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:014cce270f9bf9d0b7e5f572 --> <!-- This is an auto-generated comment by CodeRabbit -->
@ -279,0 +322,4 @@
info.data = {};
info.stencil = {};
info.metadata = {};
entry->second = m_slot_images.insert(m_graphics, m_scheduler, info);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 10:58 UTC · original · edited 2026-11-11 20:16 UTC

Major · Stability & Availability · Heavy lift

Account for feedback-copy memory when device reporting is unavailable.

If CanReportMemoryUsage() is false, this unregistered copy does not increase m_total_used_memory. Its cleared info.data also makes Image::AccountedSize() return zero. A cache with large, retained depth copies can therefore remain below its pressure threshold while actual device memory fills. Account for the backing allocation and release that accounting when the copy is destroyed. (raw.githubusercontent.com)

✅ Addressed in commit c67f319

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 10:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4537043105) · edited 2026-11-11 20:16 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** · **Stability & Availability** · **Heavy lift** **Account for feedback-copy memory when device reporting is unavailable.** If `CanReportMemoryUsage()` is false, this unregistered copy does not increase `m_total_used_memory`. Its cleared `info.data` also makes `Image::AccountedSize()` return zero. A cache with large, retained depth copies can therefore remain below its pressure threshold while actual device memory fills. Account for the backing allocation and release that accounting when the copy is destroyed. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/90a16c1619df7aa630f5e1b23714376badb2fa74/src/graphics/host_gpu/renderer/cache/textureCache.cpp)) <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:d4c0a230c3937706780bb61d --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit c67f319
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 10:58 UTC · original · edited 2026-11-11 20:42 UTC
On src/graphics/host_gpu/renderer/renderDraw.cpp line 517 (outdated):

@@ -492,23 +492,95 @@ RenderState RenderExecutor::AcquireRenderTargets(CommandBuffer& buffer, RenderCo
 		    !cache.TouchMeta(metadata.range.address, depth.desc.view_info.base_layer, false)) {
 			EXIT("failed to consume HTile clear state\n");
 		}
-		auto& image = cache.GetImage(depth.image_id);
-		EXIT_IF(image_view == nullptr || image.backing.samples != depth.desc.info.samples);
-		const auto draw_writes = depth.AttachmentWriteAspects();
+		EXIT_IF(image_view == nullptr ||
+		        cache.GetImage(depth.image_id).backing.samples != depth.desc.info.samples);
+		const auto draw_writes   = depth.AttachmentWriteAspects();
+		const bool feedback_loops = m_context.GetGraphics().attachment_feedback_loop_enabled;
 		vk::ImageAspectFlags sampled_aspects;
-		for (const auto* stage: stages) {
-			for (const auto& binding: stage->images) {
+		ImageId              copy_id {};
+		if (!feedback_loops) {
+			// Copy the sampled subresources before the draw so the shader reads the depth values
+			// from before this draw instead of sampling a written attachment.
+			ImageSubresourceRange copy_range;
+			bool                  copy_range_set = false;
+			vk::ImageAspectFlags  copy_aspects;
+			for (const auto* stage: stages) {
+				for (const auto& binding: stage->images) {
+					if (binding.image_id != depth.image_id ||
+					    binding.desc.type != TextureCache::BindingType::Texture) {
+						continue;
+					}
+					const auto& views = cache.GetImage(depth.image_id).views;
+					const auto  native =
+					    std::ranges::find(views, binding.image_view, &CachedImageView::view);
+					EXIT_IF(native == views.end());
+					if (!DepthFeedbackAspects(draw_writes, depth.desc.view_info, native->info)) {

Major · Functional Correctness · Quick win

Check every bound mip view for feedback overlap.

For dynamic mips, binding preparation sets image_view to mip_views.front(). If that first mip is disjoint from the attachment but a later mip overlaps, this check skips the binding. The redirection pass also checks only image_view, so the overlapping mip remains on the writable attachment. Determine overlap from all bound mip views in both passes. (raw.githubusercontent.com)

✅ Addressed in commit 48ca227

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 10:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4537043116) · edited 2026-11-11 20:42 UTC On `src/graphics/host_gpu/renderer/renderDraw.cpp` line 517 (outdated): ```diff @@ -492,23 +492,95 @@ RenderState RenderExecutor::AcquireRenderTargets(CommandBuffer& buffer, RenderCo !cache.TouchMeta(metadata.range.address, depth.desc.view_info.base_layer, false)) { EXIT("failed to consume HTile clear state\n"); } - auto& image = cache.GetImage(depth.image_id); - EXIT_IF(image_view == nullptr || image.backing.samples != depth.desc.info.samples); - const auto draw_writes = depth.AttachmentWriteAspects(); + EXIT_IF(image_view == nullptr || + cache.GetImage(depth.image_id).backing.samples != depth.desc.info.samples); + const auto draw_writes = depth.AttachmentWriteAspects(); + const bool feedback_loops = m_context.GetGraphics().attachment_feedback_loop_enabled; vk::ImageAspectFlags sampled_aspects; - for (const auto* stage: stages) { - for (const auto& binding: stage->images) { + ImageId copy_id {}; + if (!feedback_loops) { + // Copy the sampled subresources before the draw so the shader reads the depth values + // from before this draw instead of sampling a written attachment. + ImageSubresourceRange copy_range; + bool copy_range_set = false; + vk::ImageAspectFlags copy_aspects; + for (const auto* stage: stages) { + for (const auto& binding: stage->images) { + if (binding.image_id != depth.image_id || + binding.desc.type != TextureCache::BindingType::Texture) { + continue; + } + const auto& views = cache.GetImage(depth.image_id).views; + const auto native = + std::ranges::find(views, binding.image_view, &CachedImageView::view); + EXIT_IF(native == views.end()); + if (!DepthFeedbackAspects(draw_writes, depth.desc.view_info, native->info)) { ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Quick win** **Check every bound mip view for feedback overlap.** For dynamic mips, binding preparation sets `image_view` to `mip_views.front()`. If that first mip is disjoint from the attachment but a later mip overlaps, this check skips the binding. The redirection pass also checks only `image_view`, so the overlapping mip remains on the writable attachment. Determine overlap from all bound mip views in both passes. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/90a16c1619df7aa630f5e1b23714376badb2fa74/src/graphics/host_gpu/renderer/pipeline/descriptors.cpp)) <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:e0040c6e0c98f291fa1577ce --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 48ca227
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 10:58 UTC · original
On src/graphics/host_gpu/renderer/renderDraw.cpp line 551 (outdated):

@@ -492,23 +492,95 @@ RenderState RenderExecutor::AcquireRenderTargets(CommandBuffer& buffer, RenderCo
 		    !cache.TouchMeta(metadata.range.address, depth.desc.view_info.base_layer, false)) {
 			EXIT("failed to consume HTile clear state\n");
 		}
-		auto& image = cache.GetImage(depth.image_id);
-		EXIT_IF(image_view == nullptr || image.backing.samples != depth.desc.info.samples);
-		const auto draw_writes = depth.AttachmentWriteAspects();
+		EXIT_IF(image_view == nullptr ||
+		        cache.GetImage(depth.image_id).backing.samples != depth.desc.info.samples);
+		const auto draw_writes   = depth.AttachmentWriteAspects();
+		const bool feedback_loops = m_context.GetGraphics().attachment_feedback_loop_enabled;
 		vk::ImageAspectFlags sampled_aspects;
-		for (const auto* stage: stages) {
-			for (const auto& binding: stage->images) {
+		ImageId              copy_id {};
+		if (!feedback_loops) {
+			// Copy the sampled subresources before the draw so the shader reads the depth values
+			// from before this draw instead of sampling a written attachment.
+			ImageSubresourceRange copy_range;
+			bool                  copy_range_set = false;
+			vk::ImageAspectFlags  copy_aspects;
+			for (const auto* stage: stages) {
+				for (const auto& binding: stage->images) {
+					if (binding.image_id != depth.image_id ||
+					    binding.desc.type != TextureCache::BindingType::Texture) {
+						continue;
+					}
+					const auto& views = cache.GetImage(depth.image_id).views;
+					const auto  native =
+					    std::ranges::find(views, binding.image_view, &CachedImageView::view);
+					EXIT_IF(native == views.end());
+					if (!DepthFeedbackAspects(draw_writes, depth.desc.view_info, native->info)) {
+						continue;
+					}
+					const auto include = [&](const ImageViewInfo& info) {
+						copy_aspects |= info.aspect;
+						if (!copy_range_set) {
+							copy_range     = {info.base_level, info.level_count, info.base_layer,
+							                  info.layer_count};
+							copy_range_set = true;
+							return;
+						}
+						const auto level_end =
+						    std::max(copy_range.base_level + copy_range.level_count,
+						             info.base_level + info.level_count);
+						copy_range.base_level =
+						    std::min(copy_range.base_level, info.base_level);
+						copy_range.level_count = level_end - copy_range.base_level;
+						const auto layer_end =
+						    std::max(copy_range.base_layer + copy_range.layer_count,
+						             info.base_layer + info.layer_count);
+						copy_range.base_layer =
+						    std::min(copy_range.base_layer, info.base_layer);
+						copy_range.layer_count = layer_end - copy_range.base_layer;
+					};
+					include(native->info);
+					for (const auto mip_view: binding.mip_views) {
+						const auto mip =
+						    std::ranges::find(views, mip_view, &CachedImageView::view);
+						EXIT_IF(mip == views.end());
+						include(mip->info);
+					}
+				}
+			}
+			if (copy_range_set) {
+				copy_id = cache.CopyDepthForFeedback(depth.image_id, copy_range, copy_aspects);

Major · Functional Correctness · Heavy lift

Apply pending attachment clears before copying sampled depth.

If depth.load_clear_aspects is set, CopyDepthForFeedback copies the old image contents. BeginRendering applies the load clear only afterward. The first feedback draw therefore samples stale depth or stencil instead of the clear value. Apply the pending clear to the sampled copy for the affected aspects, layers, and render area before the draw. (raw.githubusercontent.com)

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 10:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4537043124) On `src/graphics/host_gpu/renderer/renderDraw.cpp` line 551 (outdated): ```diff @@ -492,23 +492,95 @@ RenderState RenderExecutor::AcquireRenderTargets(CommandBuffer& buffer, RenderCo !cache.TouchMeta(metadata.range.address, depth.desc.view_info.base_layer, false)) { EXIT("failed to consume HTile clear state\n"); } - auto& image = cache.GetImage(depth.image_id); - EXIT_IF(image_view == nullptr || image.backing.samples != depth.desc.info.samples); - const auto draw_writes = depth.AttachmentWriteAspects(); + EXIT_IF(image_view == nullptr || + cache.GetImage(depth.image_id).backing.samples != depth.desc.info.samples); + const auto draw_writes = depth.AttachmentWriteAspects(); + const bool feedback_loops = m_context.GetGraphics().attachment_feedback_loop_enabled; vk::ImageAspectFlags sampled_aspects; - for (const auto* stage: stages) { - for (const auto& binding: stage->images) { + ImageId copy_id {}; + if (!feedback_loops) { + // Copy the sampled subresources before the draw so the shader reads the depth values + // from before this draw instead of sampling a written attachment. + ImageSubresourceRange copy_range; + bool copy_range_set = false; + vk::ImageAspectFlags copy_aspects; + for (const auto* stage: stages) { + for (const auto& binding: stage->images) { + if (binding.image_id != depth.image_id || + binding.desc.type != TextureCache::BindingType::Texture) { + continue; + } + const auto& views = cache.GetImage(depth.image_id).views; + const auto native = + std::ranges::find(views, binding.image_view, &CachedImageView::view); + EXIT_IF(native == views.end()); + if (!DepthFeedbackAspects(draw_writes, depth.desc.view_info, native->info)) { + continue; + } + const auto include = [&](const ImageViewInfo& info) { + copy_aspects |= info.aspect; + if (!copy_range_set) { + copy_range = {info.base_level, info.level_count, info.base_layer, + info.layer_count}; + copy_range_set = true; + return; + } + const auto level_end = + std::max(copy_range.base_level + copy_range.level_count, + info.base_level + info.level_count); + copy_range.base_level = + std::min(copy_range.base_level, info.base_level); + copy_range.level_count = level_end - copy_range.base_level; + const auto layer_end = + std::max(copy_range.base_layer + copy_range.layer_count, + info.base_layer + info.layer_count); + copy_range.base_layer = + std::min(copy_range.base_layer, info.base_layer); + copy_range.layer_count = layer_end - copy_range.base_layer; + }; + include(native->info); + for (const auto mip_view: binding.mip_views) { + const auto mip = + std::ranges::find(views, mip_view, &CachedImageView::view); + EXIT_IF(mip == views.end()); + include(mip->info); + } + } + } + if (copy_range_set) { + copy_id = cache.CopyDepthForFeedback(depth.image_id, copy_range, copy_aspects); ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Heavy lift** **Apply pending attachment clears before copying sampled depth.** If `depth.load_clear_aspects` is set, `CopyDepthForFeedback` copies the old image contents. `BeginRendering` applies the load clear only afterward. The first feedback draw therefore samples stale depth or stencil instead of the clear value. Apply the pending clear to the sampled copy for the affected aspects, layers, and render area before the draw. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/90a16c1619df7aa630f5e1b23714376badb2fa74/src/graphics/host_gpu/renderer/renderDraw.cpp)) <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:a1fae64a58c20f2d51f29e6c --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 10:58 UTC · original · edited 2026-11-11 20:17 UTC
On tests/ShaderRecompilerComputeTests.cpp line 20401 (outdated):

@@ -20376,12 +20397,22 @@ class VulkanHarness {
           executor, command, &color, 1, depth, stages, &feedback_aspects);
       const bool feedback_enabled = rendering.depth_stencil_attachment.image_layout ==
                                     vk::ImageLayout::eAttachmentFeedbackLoopOptimalEXT;
+      const bool depth_read_write = depth_feedback && depth.depth_write_enable;
+      const ImageId sampled_id = bindings.pixel.images[0].image_id;

Major · Stability & Availability · Quick win

Guard the sampled-image read with depth_feedback.

For CheckRasterization(false), the fragment shader has no sampled images. This unconditional access reads an empty vector. It introduces undefined behavior into --polygon-mode-only and the full GPU suite. The earlier identity assertion correctly short-circuits this access. Move sampled_id into the copy-only branch or guard its initialization with depth_feedback. (raw.githubusercontent.com)

✅ Addressed in commit c67f319

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 10:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4537043129) · edited 2026-11-11 20:17 UTC On `tests/ShaderRecompilerComputeTests.cpp` line 20401 (outdated): ```diff @@ -20376,12 +20397,22 @@ class VulkanHarness { executor, command, &color, 1, depth, stages, &feedback_aspects); const bool feedback_enabled = rendering.depth_stencil_attachment.image_layout == vk::ImageLayout::eAttachmentFeedbackLoopOptimalEXT; + const bool depth_read_write = depth_feedback && depth.depth_write_enable; + const ImageId sampled_id = bindings.pixel.images[0].image_id; ``` <!-- 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** **Guard the sampled-image read with `depth_feedback`.** For `CheckRasterization(false)`, the fragment shader has no sampled images. This unconditional access reads an empty vector. It introduces undefined behavior into `--polygon-mode-only` and the full GPU suite. The earlier identity assertion correctly short-circuits this access. Move `sampled_id` into the copy-only branch or guard its initialization with `depth_feedback`. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/90a16c1619df7aa630f5e1b23714376badb2fa74/tests/ShaderRecompilerComputeTests.cpp)) <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:c39cafce7ca6caa157151e37 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit c67f319
@ -24037,0 +24503,4 @@
// Attachment feedback needs both the layout and the dynamic-state command; the
// copy fallback covers hosts that only expose the layout.
m_runtime_context.attachment_feedback_loop_enabled =
m_rasterization_supported && m_feedback_dynamic_supported;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 10:58 UTC · original

Major · Functional Correctness · Quick win

Update the discovery assertions for feedback-disabled hosts.

On layout-only hosts, this assignment disables feedback loops. However, CheckRenderExecutorStencilBindingDiscovery still requires feedback layouts and nonzero feedback aspects in its overlapping-view checks. Those assertions reject the fallback and abort selectors such as --image-rebind-only. Make the expected layouts, aspects, and sampled-image identities conditional on attachment_feedback_loop_enabled. Keep this capability assignment. (raw.githubusercontent.com)

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 10:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4537043135) <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Quick win** **Update the discovery assertions for feedback-disabled hosts.** On layout-only hosts, this assignment disables feedback loops. However, `CheckRenderExecutorStencilBindingDiscovery` still requires feedback layouts and nonzero feedback aspects in its overlapping-view checks. Those assertions reject the fallback and abort selectors such as `--image-rebind-only`. Make the expected layouts, aspects, and sampled-image identities conditional on `attachment_feedback_loop_enabled`. Keep this capability assignment. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/90a16c1619df7aa630f5e1b23714376badb2fa74/tests/ShaderRecompilerComputeTests.cpp)) <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:d2c41e27a87686064731d368 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 10:58 UTC · original · reviewed

Actionable comments posted: 5

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between afff2b8bb8e09daf5203e9e04ffa71c680a87294 and 90a16c1619df7aa630f5e1b23714376badb2fa74.

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; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 10:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#pullrequestreview-5857676683) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 5** <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/bc934ef03410b760fbf8e49db1d79485e7e5f887/.coderabbit.yaml>) - **Commit**: [bc934ef](<https://github.com/KytyPS5/KytyPS5/commit/bc934ef03410b760fbf8e49db1d79485e7e5f887>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `2aeaff6a-4dde-4126-8a72-45ccdbd153bb` </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 afff2b8bb8e09daf5203e9e04ffa71c680a87294 and 90a16c1619df7aa630f5e1b23714376badb2fa74. </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; 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=4dcf7e39-61ec-4ece-aead-a6371ff647a1 attempt=626831e6-2034-4992-b1e8-0c8ba4732542 batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 20:24 UTC · original
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 369 (outdated):

@@ -276,6 +277,101 @@ 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);
+	const auto copy_bytes =
+	    m_graphics.CanReportMemoryUsage() ? 0 : m_slot_images[copy_id].BackingSize();
+	// The copy is never registered: queued work may still sample it.
+	if (m_scheduler.Active()) {
+		m_scheduler.DeferOperation([this, copy_id, copy_bytes] {
+			m_total_used_memory -= copy_bytes;
+			m_slot_images.erase(copy_id);
+		});
+	} else {
+		m_total_used_memory -= copy_bytes;
+		m_slot_images.erase(copy_id);
+	}
+}
+
+ImageId TextureCache::CopyDepthForFeedback(ImageId depth_id, const ImageSubresourceRange& range,
+                                           vk::ImageAspectFlags aspects,
+                                           vk::ImageAspectFlags clear_aspects,
+                                           const vk::ClearDepthStencilValue& clear) {
+	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);
+		if (!m_graphics.CanReportMemoryUsage()) {
+			m_total_used_memory += m_slot_images[entry->second].BackingSize();
+		}
+	}
+	// References after the insertion: it may allocate a new image chunk.
+	auto& depth = m_slot_images[depth_id];
+	auto& copy  = m_slot_images[entry->second];
+	EXIT_IF(range.level_count == 0 || range.layer_count == 0 ||
+	        range.base_level + range.level_count > depth.backing.mip_levels ||
+	        range.base_layer + range.layer_count > depth.backing.layers);
+	m_scheduler.EndRendering();
+	const auto command = m_scheduler.Current().Handle();
+	depth.Transit(vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead, range,
+	              command);
+	copy.Transit(vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite, range,
+	             command);
+	std::vector<vk::ImageCopy> copies;
+	for (const auto aspect: {vk::ImageAspectFlagBits::eDepth, vk::ImageAspectFlagBits::eStencil}) {
+		if (!(aspects & aspect)) {
+			continue;
+		}
+		for (uint32_t level = range.base_level; level < range.base_level + range.level_count;
+		     level++) {
+			vk::ImageCopy region {};
+			region.srcSubresource = {aspect, level, range.base_layer, range.layer_count};
+			region.dstSubresource = region.srcSubresource;
+			region.extent = vk::Extent3D {std::max(depth.backing.extent.width >> level, 1u),
+			                              std::max(depth.backing.extent.height >> level, 1u), 1u};
+			copies.push_back(region);
+		}
+	}
+	if (!copies.empty()) {
+		command.copyImage(depth.backing.image, vk::ImageLayout::eTransferSrcOptimal,
+		                  copy.backing.image, vk::ImageLayout::eTransferDstOptimal,
+		                  static_cast<uint32_t>(copies.size()), copies.data());
+	}
+	// The draw's pending loadOp clear has not run yet, so apply it to the copy before the
+	// shader reads it; otherwise the first feedback draw samples the previous contents.
+	const auto cleared_aspects = clear_aspects & aspects;
+	if (cleared_aspects) {
+		copy.Transit(vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite,
+		             range, command);
+		const vk::ImageSubresourceRange clear_range {cleared_aspects, range.base_level,
+		                                             range.level_count, range.base_layer,
+		                                             range.layer_count};
+		command.clearDepthStencilImage(copy.backing.image, vk::ImageLayout::eTransferDstOptimal,
+		                               &clear, 1, &clear_range);

Major · Functional Correctness · Heavy lift

Limit the copy clear to attachment subresources.

If the attachment selects layer 0 but a feedback texture view selects layers 0 and 1, copyImage preserves both layers in the copy. This clear then replaces both layers with the pending load-clear value. The draw clears only the attachment layer, so a shader read of layer 1 returns the wrong value. Intersect the clear range with the attachment’s mip and layer range; retain the copied values elsewhere. (docs.vulkan.org)

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 20:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4542892427) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 369 (outdated): ```diff @@ -276,6 +277,101 @@ 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); + const auto copy_bytes = + m_graphics.CanReportMemoryUsage() ? 0 : m_slot_images[copy_id].BackingSize(); + // The copy is never registered: queued work may still sample it. + if (m_scheduler.Active()) { + m_scheduler.DeferOperation([this, copy_id, copy_bytes] { + m_total_used_memory -= copy_bytes; + m_slot_images.erase(copy_id); + }); + } else { + m_total_used_memory -= copy_bytes; + m_slot_images.erase(copy_id); + } +} + +ImageId TextureCache::CopyDepthForFeedback(ImageId depth_id, const ImageSubresourceRange& range, + vk::ImageAspectFlags aspects, + vk::ImageAspectFlags clear_aspects, + const vk::ClearDepthStencilValue& clear) { + 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); + if (!m_graphics.CanReportMemoryUsage()) { + m_total_used_memory += m_slot_images[entry->second].BackingSize(); + } + } + // References after the insertion: it may allocate a new image chunk. + auto& depth = m_slot_images[depth_id]; + auto& copy = m_slot_images[entry->second]; + EXIT_IF(range.level_count == 0 || range.layer_count == 0 || + range.base_level + range.level_count > depth.backing.mip_levels || + range.base_layer + range.layer_count > depth.backing.layers); + m_scheduler.EndRendering(); + const auto command = m_scheduler.Current().Handle(); + depth.Transit(vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead, range, + command); + copy.Transit(vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite, range, + command); + std::vector<vk::ImageCopy> copies; + for (const auto aspect: {vk::ImageAspectFlagBits::eDepth, vk::ImageAspectFlagBits::eStencil}) { + if (!(aspects & aspect)) { + continue; + } + for (uint32_t level = range.base_level; level < range.base_level + range.level_count; + level++) { + vk::ImageCopy region {}; + region.srcSubresource = {aspect, level, range.base_layer, range.layer_count}; + region.dstSubresource = region.srcSubresource; + region.extent = vk::Extent3D {std::max(depth.backing.extent.width >> level, 1u), + std::max(depth.backing.extent.height >> level, 1u), 1u}; + copies.push_back(region); + } + } + if (!copies.empty()) { + command.copyImage(depth.backing.image, vk::ImageLayout::eTransferSrcOptimal, + copy.backing.image, vk::ImageLayout::eTransferDstOptimal, + static_cast<uint32_t>(copies.size()), copies.data()); + } + // The draw's pending loadOp clear has not run yet, so apply it to the copy before the + // shader reads it; otherwise the first feedback draw samples the previous contents. + const auto cleared_aspects = clear_aspects & aspects; + if (cleared_aspects) { + copy.Transit(vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite, + range, command); + const vk::ImageSubresourceRange clear_range {cleared_aspects, range.base_level, + range.level_count, range.base_layer, + range.layer_count}; + command.clearDepthStencilImage(copy.backing.image, vk::ImageLayout::eTransferDstOptimal, + &clear, 1, &clear_range); ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Heavy lift** **Limit the copy clear to attachment subresources.** If the attachment selects layer 0 but a feedback texture view selects layers 0 and 1, `copyImage` preserves both layers in the copy. This clear then replaces both layers with the pending load-clear value. The draw clears only the attachment layer, so a shader read of layer 1 returns the wrong value. Intersect the clear range with the attachment’s mip and layer range; retain the copied values elsewhere. ([docs.vulkan.org](https://docs.vulkan.org/spec/latest/chapters/clears.html?utm_source=openai)) <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:29d6f867060ec782528557a4 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 20:24 UTC · original · edited 2026-11-11 20:43 UTC
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 369 (outdated):

@@ -276,6 +277,101 @@ 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);
+	const auto copy_bytes =
+	    m_graphics.CanReportMemoryUsage() ? 0 : m_slot_images[copy_id].BackingSize();
+	// The copy is never registered: queued work may still sample it.
+	if (m_scheduler.Active()) {
+		m_scheduler.DeferOperation([this, copy_id, copy_bytes] {
+			m_total_used_memory -= copy_bytes;
+			m_slot_images.erase(copy_id);
+		});
+	} else {
+		m_total_used_memory -= copy_bytes;
+		m_slot_images.erase(copy_id);
+	}
+}
+
+ImageId TextureCache::CopyDepthForFeedback(ImageId depth_id, const ImageSubresourceRange& range,
+                                           vk::ImageAspectFlags aspects,
+                                           vk::ImageAspectFlags clear_aspects,
+                                           const vk::ClearDepthStencilValue& clear) {
+	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);
+		if (!m_graphics.CanReportMemoryUsage()) {
+			m_total_used_memory += m_slot_images[entry->second].BackingSize();
+		}
+	}
+	// References after the insertion: it may allocate a new image chunk.
+	auto& depth = m_slot_images[depth_id];
+	auto& copy  = m_slot_images[entry->second];
+	EXIT_IF(range.level_count == 0 || range.layer_count == 0 ||
+	        range.base_level + range.level_count > depth.backing.mip_levels ||
+	        range.base_layer + range.layer_count > depth.backing.layers);
+	m_scheduler.EndRendering();
+	const auto command = m_scheduler.Current().Handle();
+	depth.Transit(vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead, range,
+	              command);
+	copy.Transit(vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite, range,
+	             command);
+	std::vector<vk::ImageCopy> copies;
+	for (const auto aspect: {vk::ImageAspectFlagBits::eDepth, vk::ImageAspectFlagBits::eStencil}) {
+		if (!(aspects & aspect)) {
+			continue;
+		}
+		for (uint32_t level = range.base_level; level < range.base_level + range.level_count;
+		     level++) {
+			vk::ImageCopy region {};
+			region.srcSubresource = {aspect, level, range.base_layer, range.layer_count};
+			region.dstSubresource = region.srcSubresource;
+			region.extent = vk::Extent3D {std::max(depth.backing.extent.width >> level, 1u),
+			                              std::max(depth.backing.extent.height >> level, 1u), 1u};
+			copies.push_back(region);
+		}
+	}
+	if (!copies.empty()) {
+		command.copyImage(depth.backing.image, vk::ImageLayout::eTransferSrcOptimal,
+		                  copy.backing.image, vk::ImageLayout::eTransferDstOptimal,
+		                  static_cast<uint32_t>(copies.size()), copies.data());
+	}
+	// The draw's pending loadOp clear has not run yet, so apply it to the copy before the
+	// shader reads it; otherwise the first feedback draw samples the previous contents.
+	const auto cleared_aspects = clear_aspects & aspects;
+	if (cleared_aspects) {
+		copy.Transit(vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite,
+		             range, command);
+		const vk::ImageSubresourceRange clear_range {cleared_aspects, range.base_level,
+		                                             range.level_count, range.base_layer,
+		                                             range.layer_count};
+		command.clearDepthStencilImage(copy.backing.image, vk::ImageLayout::eTransferDstOptimal,
+		                               &clear, 1, &clear_range);

Major · Functional Correctness · Heavy lift

Preserve copied pixels outside the render area.

If a color target reduces RenderState.width or RenderState.height below the depth image extent, the attachment load clear affects only the smaller render area. clearDepthStencilImage instead clears every pixel in the selected copy subresources. A feedback shader that samples outside that render area reads the clear value instead of the prior depth value. Apply the pending clear to the copy only within the render area. (docs.vulkan.org)

✅ Addressed in commit 48ca227

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 20:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4542892440) · edited 2026-11-11 20:43 UTC On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 369 (outdated): ```diff @@ -276,6 +277,101 @@ 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); + const auto copy_bytes = + m_graphics.CanReportMemoryUsage() ? 0 : m_slot_images[copy_id].BackingSize(); + // The copy is never registered: queued work may still sample it. + if (m_scheduler.Active()) { + m_scheduler.DeferOperation([this, copy_id, copy_bytes] { + m_total_used_memory -= copy_bytes; + m_slot_images.erase(copy_id); + }); + } else { + m_total_used_memory -= copy_bytes; + m_slot_images.erase(copy_id); + } +} + +ImageId TextureCache::CopyDepthForFeedback(ImageId depth_id, const ImageSubresourceRange& range, + vk::ImageAspectFlags aspects, + vk::ImageAspectFlags clear_aspects, + const vk::ClearDepthStencilValue& clear) { + 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); + if (!m_graphics.CanReportMemoryUsage()) { + m_total_used_memory += m_slot_images[entry->second].BackingSize(); + } + } + // References after the insertion: it may allocate a new image chunk. + auto& depth = m_slot_images[depth_id]; + auto& copy = m_slot_images[entry->second]; + EXIT_IF(range.level_count == 0 || range.layer_count == 0 || + range.base_level + range.level_count > depth.backing.mip_levels || + range.base_layer + range.layer_count > depth.backing.layers); + m_scheduler.EndRendering(); + const auto command = m_scheduler.Current().Handle(); + depth.Transit(vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead, range, + command); + copy.Transit(vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite, range, + command); + std::vector<vk::ImageCopy> copies; + for (const auto aspect: {vk::ImageAspectFlagBits::eDepth, vk::ImageAspectFlagBits::eStencil}) { + if (!(aspects & aspect)) { + continue; + } + for (uint32_t level = range.base_level; level < range.base_level + range.level_count; + level++) { + vk::ImageCopy region {}; + region.srcSubresource = {aspect, level, range.base_layer, range.layer_count}; + region.dstSubresource = region.srcSubresource; + region.extent = vk::Extent3D {std::max(depth.backing.extent.width >> level, 1u), + std::max(depth.backing.extent.height >> level, 1u), 1u}; + copies.push_back(region); + } + } + if (!copies.empty()) { + command.copyImage(depth.backing.image, vk::ImageLayout::eTransferSrcOptimal, + copy.backing.image, vk::ImageLayout::eTransferDstOptimal, + static_cast<uint32_t>(copies.size()), copies.data()); + } + // The draw's pending loadOp clear has not run yet, so apply it to the copy before the + // shader reads it; otherwise the first feedback draw samples the previous contents. + const auto cleared_aspects = clear_aspects & aspects; + if (cleared_aspects) { + copy.Transit(vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite, + range, command); + const vk::ImageSubresourceRange clear_range {cleared_aspects, range.base_level, + range.level_count, range.base_layer, + range.layer_count}; + command.clearDepthStencilImage(copy.backing.image, vk::ImageLayout::eTransferDstOptimal, + &clear, 1, &clear_range); ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Heavy lift** **Preserve copied pixels outside the render area.** If a color target reduces `RenderState.width` or `RenderState.height` below the depth image extent, the attachment load clear affects only the smaller render area. `clearDepthStencilImage` instead clears every pixel in the selected copy subresources. A feedback shader that samples outside that render area reads the clear value instead of the prior depth value. Apply the pending clear to the copy only within the render area. ([docs.vulkan.org](https://docs.vulkan.org/spec/latest/chapters/renderpass.html?utm_source=openai)) <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:006c47aa893134f51910dee6 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 48ca227
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 20:24 UTC · original
On src/graphics/host_gpu/renderer/renderDraw.cpp line 560 (outdated):

@@ -492,23 +492,114 @@ RenderState RenderExecutor::AcquireRenderTargets(CommandBuffer& buffer, RenderCo
 		    !cache.TouchMeta(metadata.range.address, depth.desc.view_info.base_layer, false)) {
 			EXIT("failed to consume HTile clear state\n");
 		}
-		auto& image = cache.GetImage(depth.image_id);
-		EXIT_IF(image_view == nullptr || image.backing.samples != depth.desc.info.samples);
-		const auto draw_writes = depth.AttachmentWriteAspects();
+		EXIT_IF(image_view == nullptr ||
+		        cache.GetImage(depth.image_id).backing.samples != depth.desc.info.samples);
+		const auto draw_writes   = depth.AttachmentWriteAspects();
+		const bool feedback_loops = m_context.GetGraphics().attachment_feedback_loop_enabled;
 		vk::ImageAspectFlags sampled_aspects;
-		for (const auto* stage: stages) {
-			for (const auto& binding: stage->images) {
+		ImageId              copy_id {};
+		if (!feedback_loops) {
+			// Copy the sampled subresources before the draw so the shader reads the depth values
+			// from before this draw instead of sampling a written attachment.
+			ImageSubresourceRange copy_range;
+			bool                  copy_range_set = false;
+			vk::ImageAspectFlags  copy_aspects;
+			for (const auto* stage: stages) {
+				for (const auto& binding: stage->images) {
+					if (binding.image_id != depth.image_id ||
+					    binding.desc.type != TextureCache::BindingType::Texture) {
+						continue;
+					}
+					const auto& views = cache.GetImage(depth.image_id).views;
+					const auto  native =
+					    std::ranges::find(views, binding.image_view, &CachedImageView::view);
+					EXIT_IF(native == views.end());
+					std::vector<const CachedImageView*> feedback_views {&*native};
+					for (const auto mip_view: binding.mip_views) {
+						const auto mip =
+						    std::ranges::find(views, mip_view, &CachedImageView::view);
+						EXIT_IF(mip == views.end());
+						feedback_views.push_back(&*mip);
+					}
+					if (std::ranges::none_of(feedback_views, [&](const auto* view) {
+						    return static_cast<bool>(DepthFeedbackAspects(
+						        draw_writes, depth.desc.view_info, view->info));
+					    })) {
+						continue;
+					}
+					const auto include = [&](const ImageViewInfo& info) {
+						copy_aspects |= info.aspect;
+						if (!copy_range_set) {
+							copy_range     = {info.base_level, info.level_count, info.base_layer,
+							                  info.layer_count};
+							copy_range_set = true;
+							return;
+						}
+						const auto level_end =
+						    std::max(copy_range.base_level + copy_range.level_count,
+						             info.base_level + info.level_count);
+						copy_range.base_level =
+						    std::min(copy_range.base_level, info.base_level);
+						copy_range.level_count = level_end - copy_range.base_level;
+						const auto layer_end =
+						    std::max(copy_range.base_layer + copy_range.layer_count,
+						             info.base_layer + info.layer_count);
+						copy_range.base_layer =
+						    std::min(copy_range.base_layer, info.base_layer);
+						copy_range.layer_count = layer_end - copy_range.base_layer;
+					};
+					for (const auto* view: feedback_views) {
+						include(view->info);
+					}
+				}
+			}
+			if (copy_range_set) {
+				const vk::ClearDepthStencilValue clear {depth.depth_clear_value,
+				                                        depth.stencil_clear_value};
+				copy_id = cache.CopyDepthForFeedback(depth.image_id, copy_range, copy_aspects,
+				                                    depth.load_clear_aspects, clear);

Major · Functional Correctness · Heavy lift

Supported by static analysis

Script executed:

#!/bin/bash
set -euo pipefail
fd -i 'imageheap' . | while IFS= read -r file; do
  ast-grep outline "$file" --match 'ImageHeap|Rebind|Commit' --view expanded
  rg -n -C 5 'ImageHeap::(Rebind|Commit)|ResolveTexture\(|depth|image_id' "$file" || true
done
rg -n -C 4 'program\.info\.images\[i\]\.heap|GetImageHeap\(\)\.Commit' \
  src/graphics/host_gpu/renderer/pipeline/descriptors.cpp

Repository: KytyPS5/KytyPS5

Length of output: 7570


Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- depth feedback and surrounding render flow ---'
cat -n src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '370,660p'
printf '%s\n' '--- heap rebind and commit ---'
cat -n src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp | sed -n '133,246p;446,592p'
printf '%s\n' '--- prepare and commit bindings ---'
cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '680,770p;880,970p'
printf '%s\n' '--- heap activation, rebinding and resource access ---'
rg -n -F -e 'GetImageHeap().Rebind' -e 'GetImageHeap().Acquire' -e 'ImageHeapResource' -e 'uses_image_heap' -- src/graphics/host_gpu src/shader_recompiler || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 40381


Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- heap planning and sampling references ---'
rg -n -F -e 'ImageHeapResource' -e 'ImageHeapRequest' -e '.heap =' -e 'uses_image_heap' -- src/graphics/shader/recompiler src/graphics/host_gpu/renderer tests || test "$?" -eq 1
printf '%s\n' '--- draw call ordering ---'
rg -n -F -e 'PrepareGraphicsBindings(' -e 'AcquireRenderTargets(' -e 'CommitBindings(' -e 'BindRenderTarget(' -- src/graphics/host_gpu/renderer/renderDraw.cpp
printf '%s\n' '--- texture resolution definitions ---'
rg -n -F -e 'RenderExecutor::ResolveTexture' -e 'ImageHeapResource(' -- src/graphics/host_gpu/renderer/pipeline src/graphics/shader/recompiler/ir

Repository: KytyPS5/KytyPS5

Length of output: 6032


Script executed:

#!/bin/bash
set -e
cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '630,720p;1790,1845p'
cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '470,645p'
cat -n src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '1140,1265p'
cat -n tests/ResourceTrackingTests.cpp | sed -n '450,575p'

Repository: KytyPS5/KytyPS5

Length of output: 33942


Script executed:

#!/bin/bash
set -e
rg -n -F -e 'TextureCache::FindImage(' -e 'desc.heap' -e 'info.heap' -- src/graphics/host_gpu/renderer/image
cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '630,678p'
rg -n -F -e 'ImageHeapKind(' -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp

Repository: KytyPS5/KytyPS5

Length of output: 153


Script executed:

#!/bin/bash
rg -n -F -e 'TextureCache::FindImage(' -e 'desc.heap' -- src/graphics/host_gpu || test "$?" -eq 1
cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '630,678p'
rg -n -F -e 'ImageHeapKind(' -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 3358


Script executed:

#!/bin/bash
cat -n src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '1320,1435p'
rg -n -F -- 'ValidateSampledDepthBinding' src/graphics/host_gpu/renderer

Repository: KytyPS5/KytyPS5

Length of output: 5670


Handle depth feedback through image-heap bindings.

When a heap entry samples the writable depth attachment on a host without feedback-loop support, AcquireRenderTargets cannot see that entry. The heap still binds the original image, so the draw can sample the attachment it writes instead of the copy, producing incorrect rendering. Include overlapping heap entries in the fallback and redirect them to the copied image.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 20:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4542892447) On `src/graphics/host_gpu/renderer/renderDraw.cpp` line 560 (outdated): ```diff @@ -492,23 +492,114 @@ RenderState RenderExecutor::AcquireRenderTargets(CommandBuffer& buffer, RenderCo !cache.TouchMeta(metadata.range.address, depth.desc.view_info.base_layer, false)) { EXIT("failed to consume HTile clear state\n"); } - auto& image = cache.GetImage(depth.image_id); - EXIT_IF(image_view == nullptr || image.backing.samples != depth.desc.info.samples); - const auto draw_writes = depth.AttachmentWriteAspects(); + EXIT_IF(image_view == nullptr || + cache.GetImage(depth.image_id).backing.samples != depth.desc.info.samples); + const auto draw_writes = depth.AttachmentWriteAspects(); + const bool feedback_loops = m_context.GetGraphics().attachment_feedback_loop_enabled; vk::ImageAspectFlags sampled_aspects; - for (const auto* stage: stages) { - for (const auto& binding: stage->images) { + ImageId copy_id {}; + if (!feedback_loops) { + // Copy the sampled subresources before the draw so the shader reads the depth values + // from before this draw instead of sampling a written attachment. + ImageSubresourceRange copy_range; + bool copy_range_set = false; + vk::ImageAspectFlags copy_aspects; + for (const auto* stage: stages) { + for (const auto& binding: stage->images) { + if (binding.image_id != depth.image_id || + binding.desc.type != TextureCache::BindingType::Texture) { + continue; + } + const auto& views = cache.GetImage(depth.image_id).views; + const auto native = + std::ranges::find(views, binding.image_view, &CachedImageView::view); + EXIT_IF(native == views.end()); + std::vector<const CachedImageView*> feedback_views {&*native}; + for (const auto mip_view: binding.mip_views) { + const auto mip = + std::ranges::find(views, mip_view, &CachedImageView::view); + EXIT_IF(mip == views.end()); + feedback_views.push_back(&*mip); + } + if (std::ranges::none_of(feedback_views, [&](const auto* view) { + return static_cast<bool>(DepthFeedbackAspects( + draw_writes, depth.desc.view_info, view->info)); + })) { + continue; + } + const auto include = [&](const ImageViewInfo& info) { + copy_aspects |= info.aspect; + if (!copy_range_set) { + copy_range = {info.base_level, info.level_count, info.base_layer, + info.layer_count}; + copy_range_set = true; + return; + } + const auto level_end = + std::max(copy_range.base_level + copy_range.level_count, + info.base_level + info.level_count); + copy_range.base_level = + std::min(copy_range.base_level, info.base_level); + copy_range.level_count = level_end - copy_range.base_level; + const auto layer_end = + std::max(copy_range.base_layer + copy_range.layer_count, + info.base_layer + info.layer_count); + copy_range.base_layer = + std::min(copy_range.base_layer, info.base_layer); + copy_range.layer_count = layer_end - copy_range.base_layer; + }; + for (const auto* view: feedback_views) { + include(view->info); + } + } + } + if (copy_range_set) { + const vk::ClearDepthStencilValue clear {depth.depth_clear_value, + depth.stencil_clear_value}; + copy_id = cache.CopyDepthForFeedback(depth.image_id, copy_range, copy_aspects, + depth.load_clear_aspects, clear); ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Heavy lift** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details.svg" width="16" height="16" align="absmiddle" alt=""></picture> Supported by static analysis</summary> <dl> <dd> <br> Script executed: ```bash #!/bin/bash set -euo pipefail fd -i 'imageheap' . | while IFS= read -r file; do ast-grep outline "$file" --match 'ImageHeap|Rebind|Commit' --view expanded rg -n -C 5 'ImageHeap::(Rebind|Commit)|ResolveTexture\(|depth|image_id' "$file" || true done rg -n -C 4 'program\.info\.images\[i\]\.heap|GetImageHeap\(\)\.Commit' \ src/graphics/host_gpu/renderer/pipeline/descriptors.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 7570 --- Script executed: ```bash #!/bin/bash set -e printf '%s\n' '--- depth feedback and surrounding render flow ---' cat -n src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '370,660p' printf '%s\n' '--- heap rebind and commit ---' cat -n src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp | sed -n '133,246p;446,592p' printf '%s\n' '--- prepare and commit bindings ---' cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '680,770p;880,970p' printf '%s\n' '--- heap activation, rebinding and resource access ---' rg -n -F -e 'GetImageHeap().Rebind' -e 'GetImageHeap().Acquire' -e 'ImageHeapResource' -e 'uses_image_heap' -- src/graphics/host_gpu src/shader_recompiler || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 40381 --- Script executed: ```bash #!/bin/bash set -e printf '%s\n' '--- heap planning and sampling references ---' rg -n -F -e 'ImageHeapResource' -e 'ImageHeapRequest' -e '.heap =' -e 'uses_image_heap' -- src/graphics/shader/recompiler src/graphics/host_gpu/renderer tests || test "$?" -eq 1 printf '%s\n' '--- draw call ordering ---' rg -n -F -e 'PrepareGraphicsBindings(' -e 'AcquireRenderTargets(' -e 'CommitBindings(' -e 'BindRenderTarget(' -- src/graphics/host_gpu/renderer/renderDraw.cpp printf '%s\n' '--- texture resolution definitions ---' rg -n -F -e 'RenderExecutor::ResolveTexture' -e 'ImageHeapResource(' -- src/graphics/host_gpu/renderer/pipeline src/graphics/shader/recompiler/ir ``` Repository: KytyPS5/KytyPS5 Length of output: 6032 --- Script executed: ```bash #!/bin/bash set -e cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '630,720p;1790,1845p' cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '470,645p' cat -n src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '1140,1265p' cat -n tests/ResourceTrackingTests.cpp | sed -n '450,575p' ``` Repository: KytyPS5/KytyPS5 Length of output: 33942 --- Script executed: ```bash #!/bin/bash set -e rg -n -F -e 'TextureCache::FindImage(' -e 'desc.heap' -e 'info.heap' -- src/graphics/host_gpu/renderer/image cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '630,678p' rg -n -F -e 'ImageHeapKind(' -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 153 --- Script executed: ```bash #!/bin/bash rg -n -F -e 'TextureCache::FindImage(' -e 'desc.heap' -- src/graphics/host_gpu || test "$?" -eq 1 cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '630,678p' rg -n -F -e 'ImageHeapKind(' -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 3358 --- Script executed: ```bash #!/bin/bash cat -n src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '1320,1435p' rg -n -F -- 'ValidateSampledDepthBinding' src/graphics/host_gpu/renderer ``` Repository: KytyPS5/KytyPS5 Length of output: 5670 --- </dd> </dl> </details> **Handle depth feedback through image-heap bindings.** When a heap entry samples the writable depth attachment on a host without feedback-loop support, `AcquireRenderTargets` cannot see that entry. The heap still binds the original image, so the draw can sample the attachment it writes instead of the copy, producing incorrect rendering. Include overlapping heap entries in the fallback and redirect them to the copied image. <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:4b7afdfaf2cd230773e6e173 --> <!-- This is an auto-generated comment by CodeRabbit -->
@ -18278,0 +18688,4 @@
: expected_layout;
const auto expected_image_id = bounds_copied
? bounds_bindings.pixel.images[0].image_id
: depth_only.image_id;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 20:24 UTC · original · edited 2026-11-11 20:43 UTC

Minor · Functional Correctness · Quick win

Assert that each copied binding uses a different image.

When bounds_copied or copied is true, the expected image ID comes from the pixel binding under test. The subsequent pixel-image equality therefore accepts the original attachment ID as well as a copy ID. In the bounds check, both stages can retain the original ID and still satisfy these identity assertions.

Add explicit inequalities against depth_only.image_id and shared_depth.image_id, respectively. Keep the existing stage-sharing and view checks. This prevents these fallback checks from accepting a binding that still samples the attachment.

Also applies to: 18369-18371

✅ Addressed in commit 48ca227

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 20:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4542892456) · edited 2026-11-11 20:43 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** **Assert that each copied binding uses a different image.** When `bounds_copied` or `copied` is true, the expected image ID comes from the pixel binding under test. The subsequent pixel-image equality therefore accepts the original attachment ID as well as a copy ID. In the bounds check, both stages can retain the original ID and still satisfy these identity assertions. Add explicit inequalities against `depth_only.image_id` and `shared_depth.image_id`, respectively. Keep the existing stage-sharing and view checks. This prevents these fallback checks from accepting a binding that still samples the attachment. Also applies to: 18369-18371 <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:d06bd505066d6d383603f040 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 48ca227
Author
Owner

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

Actionable comments posted: 4

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 90a16c1619df7aa630f5e1b23714376badb2fa74 and c67f319825ff288cfeddb3843f20fd5d3c5ee3e6.

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.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; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 20:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#pullrequestreview-5864945100) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 4** <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/bc934ef03410b760fbf8e49db1d79485e7e5f887/.coderabbit.yaml>) - **Commit**: [bc934ef](<https://github.com/KytyPS5/KytyPS5/commit/bc934ef03410b760fbf8e49db1d79485e7e5f887>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `b26daf79-54cd-4336-9701-7c03a295fc5b` </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 90a16c1619df7aa630f5e1b23714376badb2fa74 and c67f319825ff288cfeddb3843f20fd5d3c5ee3e6. </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.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; 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=0298f653-14d8-4dac-bad8-75a0a80cf041 attempt=eb980430-8890-42a5-a6a4-082087918229 batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 20:48 UTC · original
On src/graphics/host_gpu/renderer/cache/textureCache.cpp line 372 (outdated):

@@ -276,6 +277,119 @@ 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);
+	const auto copy_bytes =
+	    m_graphics.CanReportMemoryUsage() ? 0 : m_slot_images[copy_id].BackingSize();
+	// The copy is never registered: queued work may still sample it.
+	if (m_scheduler.Active()) {
+		m_scheduler.DeferOperation([this, copy_id, copy_bytes] {
+			m_total_used_memory -= copy_bytes;
+			m_slot_images.erase(copy_id);
+		});
+	} else {
+		m_total_used_memory -= copy_bytes;
+		m_slot_images.erase(copy_id);
+	}
+}
+
+ImageId TextureCache::CopyDepthForFeedback(ImageId depth_id, const ImageSubresourceRange& range,
+                                           vk::ImageAspectFlags aspects,
+                                           vk::ImageAspectFlags clear_aspects,
+                                           const vk::ClearDepthStencilValue& clear,
+                                           const ImageViewInfo& attachment_view,
+                                           vk::Extent2D render_area) {
+	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);
+		if (!m_graphics.CanReportMemoryUsage()) {
+			m_total_used_memory += m_slot_images[entry->second].BackingSize();
+		}
+	}
+	// References after the insertion: it may allocate a new image chunk.
+	auto& depth = m_slot_images[depth_id];
+	auto& copy  = m_slot_images[entry->second];
+	EXIT_IF(range.level_count == 0 || range.layer_count == 0 ||
+	        range.base_level + range.level_count > depth.backing.mip_levels ||
+	        range.base_layer + range.layer_count > depth.backing.layers);
+	m_scheduler.EndRendering();
+	const auto command = m_scheduler.Current().Handle();
+	depth.Transit(vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead, range,
+	              command);
+	copy.Transit(vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite, range,
+	             command);
+	std::vector<vk::ImageCopy> copies;
+	for (const auto aspect: {vk::ImageAspectFlagBits::eDepth, vk::ImageAspectFlagBits::eStencil}) {
+		if (!(aspects & aspect)) {
+			continue;
+		}
+		for (uint32_t level = range.base_level; level < range.base_level + range.level_count;
+		     level++) {
+			vk::ImageCopy region {};
+			region.srcSubresource = {aspect, level, range.base_layer, range.layer_count};
+			region.dstSubresource = region.srcSubresource;
+			region.extent = vk::Extent3D {std::max(depth.backing.extent.width >> level, 1u),
+			                              std::max(depth.backing.extent.height >> level, 1u), 1u};
+			copies.push_back(region);
+		}
+	}
+	if (!copies.empty()) {
+		command.copyImage(depth.backing.image, vk::ImageLayout::eTransferSrcOptimal,
+		                  copy.backing.image, vk::ImageLayout::eTransferDstOptimal,
+		                  static_cast<uint32_t>(copies.size()), copies.data());
+	}
+	// The draw's pending loadOp clear has not run yet, so apply it to the copy before the
+	// shader reads it; otherwise the first feedback draw samples the previous contents.
+	// The clear uses the attachment view and render area, so copied samples outside the
+	// attachment subresources or render area keep their copied values.
+	const auto cleared_aspects = clear_aspects & aspects & attachment_view.aspect;
+	if (cleared_aspects && render_area.width != 0 && render_area.height != 0) {
+		copy.Transit(vk::ImageLayout::eDepthStencilAttachmentOptimal,
+		             vk::AccessFlagBits2::eDepthStencilAttachmentWrite, {}, command);
+		RenderState state {};
+		state.width              = render_area.width;
+		state.height             = render_area.height;
+		state.num_layers         = attachment_view.layer_count;

Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

rg -n -F -e 'CopyDepthForFeedback' -e 'AcquireRenderTargets' -e 'num_layers' -- src/graphics/host_gpu/renderer
git diff bc934ef03410b760fbf8e49db1d79485e7e5f887 48ca227ab3d49a517d23993cf6caf371caf70605 -- src/graphics/host_gpu/renderer/cache/textureCache.cpp

Repository: KytyPS5/KytyPS5

Length of output: 8614


Script executed:

cat -n src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '430,690p'
cat -n src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '295,400p'
cat -n src/graphics/host_gpu/renderer/cache/textureCache.h | sed -n '45,80p'
cat -n src/graphics/host_gpu/renderer/context.cpp | sed -n '30,140p'

Repository: KytyPS5/KytyPS5

Length of output: 25241


Script executed:

rg -n -F -e 'DepthFeedbackAspects' -e 'ResolveRenderColorTarget' -e 'ResolveRenderDepthTarget' -e 'view_info.layer_count' -- src/graphics/host_gpu/renderer
rg -n -F -e 'struct ImageViewInfo' -e 'layer_count =' -e 'layer_count  =' -- src/graphics/host_gpu | sed -n '1,220p'

Repository: KytyPS5/KytyPS5

Length of output: 5021


Web query:

Vulkan specification dynamic rendering loadOp clear layerCount VkRenderingInfo viewMask zero attachment layers clearAttachments VkClearRect layerCount

Result:

Sources consulted:
- Render Pass :: Vulkan Documentation Project — https://docs.vulkan.org/spec/latest/chapters/renderpass.html
- VkRenderingInfo(3) :: Vulkan Documentation Project — https://docs.vulkan.org/refpages/latest/refpages/source/VkRenderingInfo.html
- VK_KHR_dynamic_rendering :: Vulkan Documentation Project — https://docs.vulkan.org/features/latest/features/proposals/VK_KHR_dynamic_rendering.html
- Vulkan® 1.3.264 - A Specification (with all registered extensions) — https://kiwitree.net/~lina/vulkan/specs/VK_EXT_present_timing/latest/html/chap8.html
- proposals/VK_KHR_dynamic_rendering.adoc at main · KhronosGroup/Vulkan-Docs — https://github.com/KhronosGroup/Vulkan-Docs/blob/main/proposals/VK_KHR_dynamic_rendering.adoc

Script executed:

cat -n src/graphics/host_gpu/renderer/colorRenderTarget.cpp | sed -n '35,115p;180,255p'
cat -n src/graphics/host_gpu/renderer/depthRenderTarget.cpp | sed -n '150,325p'
cat -n src/graphics/host_gpu/renderer/depthRenderTarget.h | sed -n '1,95p'
cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '335,430p'
cat -n src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '930,980p;1220,1265p'
cat -n src/graphics/host_gpu/renderer/image/imageView.cpp | sed -n '1,75p;330,365p'

Repository: KytyPS5/KytyPS5

Length of output: 39669


Script executed:

rg -n -F -e 'AttachmentWriteAspects() const' -e 'BeginRendering(rendering)' -e 'ResolveTargetViewInfo(' -- src/graphics/host_gpu/renderer
cat -n src/graphics/host_gpu/renderer/depthRenderTarget.cpp | sed -n '20,100p;310,360p'
cat -n src/graphics/host_gpu/renderer/renderTarget.h | sed -n '1,105p'
cat -n src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '1260,1325p'

Repository: KytyPS5/KytyPS5

Length of output: 13618


Script executed:

cat -n src/graphics/host_gpu/renderer/depthRenderTarget.cpp | sed -n '410,445p'

Repository: KytyPS5/KytyPS5

Length of output: 1632


Limit the copied clear to the draw's render layers.

If a color attachment has fewer layers than the depth view, the copy clear can overwrite layers that the draw's load clear does not touch. A feedback sample can then read the wrong value. Pass the effective layer count to the copy and use it for both clear counts.

Suggested fix

--- a/src/graphics/host_gpu/renderer/renderDraw.cpp
+++ b/src/graphics/host_gpu/renderer/renderDraw.cpp
@@
 				copy_id = cache.CopyDepthForFeedback(
 				    depth.image_id, copy_range, copy_aspects, depth.load_clear_aspects, clear,
-				    depth.desc.view_info, {feedback_width, feedback_height});
+				    depth.desc.view_info, {feedback_width, feedback_height},
+				    std::min(state.num_layers, depth.desc.view_info.layer_count));
--- a/src/graphics/host_gpu/renderer/cache/textureCache.h
+++ b/src/graphics/host_gpu/renderer/cache/textureCache.h
@@
 	                                           const ImageViewInfo& attachment_view,
-	                                           vk::Extent2D render_area);
+	                                           vk::Extent2D render_area, uint32_t render_layers);
--- a/src/graphics/host_gpu/renderer/cache/textureCache.cpp
+++ b/src/graphics/host_gpu/renderer/cache/textureCache.cpp
@@
                                            const ImageViewInfo& attachment_view,
-                                           vk::Extent2D render_area) {
+                                           vk::Extent2D render_area, uint32_t render_layers) {
@@
-		state.num_layers         = attachment_view.layer_count;
+		state.num_layers         = render_layers;
@@
-		clear_rect.layerCount  = attachment_view.layer_count;
+		clear_rect.layerCount  = render_layers;
**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 20:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4543068713) On `src/graphics/host_gpu/renderer/cache/textureCache.cpp` line 372 (outdated): ```diff @@ -276,6 +277,119 @@ 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); + const auto copy_bytes = + m_graphics.CanReportMemoryUsage() ? 0 : m_slot_images[copy_id].BackingSize(); + // The copy is never registered: queued work may still sample it. + if (m_scheduler.Active()) { + m_scheduler.DeferOperation([this, copy_id, copy_bytes] { + m_total_used_memory -= copy_bytes; + m_slot_images.erase(copy_id); + }); + } else { + m_total_used_memory -= copy_bytes; + m_slot_images.erase(copy_id); + } +} + +ImageId TextureCache::CopyDepthForFeedback(ImageId depth_id, const ImageSubresourceRange& range, + vk::ImageAspectFlags aspects, + vk::ImageAspectFlags clear_aspects, + const vk::ClearDepthStencilValue& clear, + const ImageViewInfo& attachment_view, + vk::Extent2D render_area) { + 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); + if (!m_graphics.CanReportMemoryUsage()) { + m_total_used_memory += m_slot_images[entry->second].BackingSize(); + } + } + // References after the insertion: it may allocate a new image chunk. + auto& depth = m_slot_images[depth_id]; + auto& copy = m_slot_images[entry->second]; + EXIT_IF(range.level_count == 0 || range.layer_count == 0 || + range.base_level + range.level_count > depth.backing.mip_levels || + range.base_layer + range.layer_count > depth.backing.layers); + m_scheduler.EndRendering(); + const auto command = m_scheduler.Current().Handle(); + depth.Transit(vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead, range, + command); + copy.Transit(vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite, range, + command); + std::vector<vk::ImageCopy> copies; + for (const auto aspect: {vk::ImageAspectFlagBits::eDepth, vk::ImageAspectFlagBits::eStencil}) { + if (!(aspects & aspect)) { + continue; + } + for (uint32_t level = range.base_level; level < range.base_level + range.level_count; + level++) { + vk::ImageCopy region {}; + region.srcSubresource = {aspect, level, range.base_layer, range.layer_count}; + region.dstSubresource = region.srcSubresource; + region.extent = vk::Extent3D {std::max(depth.backing.extent.width >> level, 1u), + std::max(depth.backing.extent.height >> level, 1u), 1u}; + copies.push_back(region); + } + } + if (!copies.empty()) { + command.copyImage(depth.backing.image, vk::ImageLayout::eTransferSrcOptimal, + copy.backing.image, vk::ImageLayout::eTransferDstOptimal, + static_cast<uint32_t>(copies.size()), copies.data()); + } + // The draw's pending loadOp clear has not run yet, so apply it to the copy before the + // shader reads it; otherwise the first feedback draw samples the previous contents. + // The clear uses the attachment view and render area, so copied samples outside the + // attachment subresources or render area keep their copied values. + const auto cleared_aspects = clear_aspects & aspects & attachment_view.aspect; + if (cleared_aspects && render_area.width != 0 && render_area.height != 0) { + copy.Transit(vk::ImageLayout::eDepthStencilAttachmentOptimal, + vk::AccessFlagBits2::eDepthStencilAttachmentWrite, {}, command); + RenderState state {}; + state.width = render_area.width; + state.height = render_area.height; + state.num_layers = attachment_view.layer_count; ``` <!-- 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** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details.svg" width="16" height="16" align="absmiddle" alt=""></picture> Supported by static analysis</summary> <dl> <dd> <br> Script executed: ```bash rg -n -F -e 'CopyDepthForFeedback' -e 'AcquireRenderTargets' -e 'num_layers' -- src/graphics/host_gpu/renderer git diff bc934ef03410b760fbf8e49db1d79485e7e5f887 48ca227ab3d49a517d23993cf6caf371caf70605 -- src/graphics/host_gpu/renderer/cache/textureCache.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 8614 --- Script executed: ```bash cat -n src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '430,690p' cat -n src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '295,400p' cat -n src/graphics/host_gpu/renderer/cache/textureCache.h | sed -n '45,80p' cat -n src/graphics/host_gpu/renderer/context.cpp | sed -n '30,140p' ``` Repository: KytyPS5/KytyPS5 Length of output: 25241 --- Script executed: ```bash rg -n -F -e 'DepthFeedbackAspects' -e 'ResolveRenderColorTarget' -e 'ResolveRenderDepthTarget' -e 'view_info.layer_count' -- src/graphics/host_gpu/renderer rg -n -F -e 'struct ImageViewInfo' -e 'layer_count =' -e 'layer_count =' -- src/graphics/host_gpu | sed -n '1,220p' ``` Repository: KytyPS5/KytyPS5 Length of output: 5021 --- Web query: `Vulkan specification dynamic rendering loadOp clear layerCount VkRenderingInfo viewMask zero attachment layers clearAttachments VkClearRect layerCount` Result: ``` Sources consulted: - Render Pass :: Vulkan Documentation Project — https://docs.vulkan.org/spec/latest/chapters/renderpass.html - VkRenderingInfo(3) :: Vulkan Documentation Project — https://docs.vulkan.org/refpages/latest/refpages/source/VkRenderingInfo.html - VK_KHR_dynamic_rendering :: Vulkan Documentation Project — https://docs.vulkan.org/features/latest/features/proposals/VK_KHR_dynamic_rendering.html - Vulkan® 1.3.264 - A Specification (with all registered extensions) — https://kiwitree.net/~lina/vulkan/specs/VK_EXT_present_timing/latest/html/chap8.html - proposals/VK_KHR_dynamic_rendering.adoc at main · KhronosGroup/Vulkan-Docs — https://github.com/KhronosGroup/Vulkan-Docs/blob/main/proposals/VK_KHR_dynamic_rendering.adoc ``` --- Script executed: ```bash cat -n src/graphics/host_gpu/renderer/colorRenderTarget.cpp | sed -n '35,115p;180,255p' cat -n src/graphics/host_gpu/renderer/depthRenderTarget.cpp | sed -n '150,325p' cat -n src/graphics/host_gpu/renderer/depthRenderTarget.h | sed -n '1,95p' cat -n src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '335,430p' cat -n src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '930,980p;1220,1265p' cat -n src/graphics/host_gpu/renderer/image/imageView.cpp | sed -n '1,75p;330,365p' ``` Repository: KytyPS5/KytyPS5 Length of output: 39669 --- Script executed: ```bash rg -n -F -e 'AttachmentWriteAspects() const' -e 'BeginRendering(rendering)' -e 'ResolveTargetViewInfo(' -- src/graphics/host_gpu/renderer cat -n src/graphics/host_gpu/renderer/depthRenderTarget.cpp | sed -n '20,100p;310,360p' cat -n src/graphics/host_gpu/renderer/renderTarget.h | sed -n '1,105p' cat -n src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '1260,1325p' ``` Repository: KytyPS5/KytyPS5 Length of output: 13618 --- Script executed: ```bash cat -n src/graphics/host_gpu/renderer/depthRenderTarget.cpp | sed -n '410,445p' ``` Repository: KytyPS5/KytyPS5 Length of output: 1632 --- </dd> </dl> </details> **Limit the copied clear to the draw's render layers.** If a color attachment has fewer layers than the depth view, the copy clear can overwrite layers that the draw's load clear does not touch. A feedback sample can then read the wrong value. Pass the effective layer count to the copy and use it for both clear counts. <details> <summary>Suggested fix</summary> <dl> <dd> <br> ```diff --- a/src/graphics/host_gpu/renderer/renderDraw.cpp +++ b/src/graphics/host_gpu/renderer/renderDraw.cpp @@ copy_id = cache.CopyDepthForFeedback( depth.image_id, copy_range, copy_aspects, depth.load_clear_aspects, clear, - depth.desc.view_info, {feedback_width, feedback_height}); + depth.desc.view_info, {feedback_width, feedback_height}, + std::min(state.num_layers, depth.desc.view_info.layer_count)); --- a/src/graphics/host_gpu/renderer/cache/textureCache.h +++ b/src/graphics/host_gpu/renderer/cache/textureCache.h @@ const ImageViewInfo& attachment_view, - vk::Extent2D render_area); + vk::Extent2D render_area, uint32_t render_layers); --- a/src/graphics/host_gpu/renderer/cache/textureCache.cpp +++ b/src/graphics/host_gpu/renderer/cache/textureCache.cpp @@ const ImageViewInfo& attachment_view, - vk::Extent2D render_area) { + vk::Extent2D render_area, uint32_t render_layers) { @@ - state.num_layers = attachment_view.layer_count; + state.num_layers = render_layers; @@ - clear_rect.layerCount = attachment_view.layer_count; + clear_rect.layerCount = render_layers; ``` </dd> </dl> </details> <!-- fingerprinting:phantom:medusa:beignet55 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:62b3e3ca56478bbdc778039d --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 20:48 UTC · original
On src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp line 588 (outdated):

@@ -547,6 +547,65 @@ void ImageHeap::WriteDescriptors() {
 	m_writes.clear();
 }
 
+void ImageHeap::DepthViews(ImageId image_id, std::vector<ImageViewInfo>& views) const {
+	for (const auto* view: m_active) {
+		for (const auto& [value, index]: view->elements) {
+			const auto& binding = m_elements[index].binding;
+			if (binding.image_id != image_id) continue;
+			views.push_back(binding.desc.view_info);
+			for (uint32_t mip = 0; mip < binding.mip_views.size(); ++mip) {
+				auto info          = binding.desc.view_info;
+				info.base_level   += mip;
+				info.level_count   = 1;
+				info.min_lod       = 0;
+				views.push_back(info);
+			}
+		}
+	}
+}
+
+void ImageHeap::RedirectDepth(ImageId image_id, ImageId copy_id,
+                              const ImageSubresourceRange& range,
+                              vk::ImageAspectFlags aspects) {
+	auto& textures = m_context.GetTextureCache();
+	auto& copy     = textures.GetImage(copy_id);
+	for (auto* view: m_active) {
+		for (const auto& [value, index]: view->elements) {
+			auto&      element = m_elements[index];
+			auto&      binding = element.binding;
+			const auto& info   = binding.desc.view_info;
+			if (binding.image_id != image_id || !(aspects & info.aspect) ||
+			    info.base_level >= range.base_level + range.level_count ||
+			    range.base_level >= info.base_level + info.level_count ||
+			    info.base_layer >= range.base_layer + range.layer_count ||
+			    range.base_layer >= info.base_layer + info.layer_count) {
+				continue;
+			}
+			if (auto* old = ImageOf(element)) {
+				old->heap_refs.fetch_sub(1u, std::memory_order_relaxed);
+			}
+			binding.image_id = copy_id;
+			binding.layout   = copy.ReadLayout();

Major · Functional Correctness · Heavy lift

Restore heap bindings before the next draw.

After redirection, the retained element identifies copy_id. If the depth image was already in an attachment layout, its transition to transfer source need not increment Image::heap_epoch. On the next draw, Rebind can retain the copy element. DepthViews(depth.image_id, ...) then misses it, so a heap-only feedback draw can sample the previous draw's copy without refreshing it. Make redirection draw-local, or explicitly make the element stale before the next draw's discovery. Image::GetBarriers increments the epoch only when a transition leaves its shader-read state. (raw.githubusercontent.com)

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 20:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4543068722) On `src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp` line 588 (outdated): ```diff @@ -547,6 +547,65 @@ void ImageHeap::WriteDescriptors() { m_writes.clear(); } +void ImageHeap::DepthViews(ImageId image_id, std::vector<ImageViewInfo>& views) const { + for (const auto* view: m_active) { + for (const auto& [value, index]: view->elements) { + const auto& binding = m_elements[index].binding; + if (binding.image_id != image_id) continue; + views.push_back(binding.desc.view_info); + for (uint32_t mip = 0; mip < binding.mip_views.size(); ++mip) { + auto info = binding.desc.view_info; + info.base_level += mip; + info.level_count = 1; + info.min_lod = 0; + views.push_back(info); + } + } + } +} + +void ImageHeap::RedirectDepth(ImageId image_id, ImageId copy_id, + const ImageSubresourceRange& range, + vk::ImageAspectFlags aspects) { + auto& textures = m_context.GetTextureCache(); + auto& copy = textures.GetImage(copy_id); + for (auto* view: m_active) { + for (const auto& [value, index]: view->elements) { + auto& element = m_elements[index]; + auto& binding = element.binding; + const auto& info = binding.desc.view_info; + if (binding.image_id != image_id || !(aspects & info.aspect) || + info.base_level >= range.base_level + range.level_count || + range.base_level >= info.base_level + info.level_count || + info.base_layer >= range.base_layer + range.layer_count || + range.base_layer >= info.base_layer + info.layer_count) { + continue; + } + if (auto* old = ImageOf(element)) { + old->heap_refs.fetch_sub(1u, std::memory_order_relaxed); + } + binding.image_id = copy_id; + binding.layout = copy.ReadLayout(); ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Heavy lift** **Restore heap bindings before the next draw.** After redirection, the retained element identifies `copy_id`. If the depth image was already in an attachment layout, its transition to transfer source need not increment `Image::heap_epoch`. On the next draw, `Rebind` can retain the copy element. `DepthViews(depth.image_id, ...)` then misses it, so a heap-only feedback draw can sample the previous draw's copy without refreshing it. Make redirection draw-local, or explicitly make the element stale before the next draw's discovery. `Image::GetBarriers` increments the epoch only when a transition leaves its shader-read state. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/48ca227ab3d49a517d23993cf6caf371caf70605/src/graphics/host_gpu/renderer/image/image.cpp)) <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:3c4ec2c3d51f1765255e5b3c --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 20:48 UTC · original
On src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp line 606 (outdated):

@@ -547,6 +547,65 @@ void ImageHeap::WriteDescriptors() {
 	m_writes.clear();
 }
 
+void ImageHeap::DepthViews(ImageId image_id, std::vector<ImageViewInfo>& views) const {
+	for (const auto* view: m_active) {
+		for (const auto& [value, index]: view->elements) {
+			const auto& binding = m_elements[index].binding;
+			if (binding.image_id != image_id) continue;
+			views.push_back(binding.desc.view_info);
+			for (uint32_t mip = 0; mip < binding.mip_views.size(); ++mip) {
+				auto info          = binding.desc.view_info;
+				info.base_level   += mip;
+				info.level_count   = 1;
+				info.min_lod       = 0;
+				views.push_back(info);
+			}
+		}
+	}
+}
+
+void ImageHeap::RedirectDepth(ImageId image_id, ImageId copy_id,
+                              const ImageSubresourceRange& range,
+                              vk::ImageAspectFlags aspects) {
+	auto& textures = m_context.GetTextureCache();
+	auto& copy     = textures.GetImage(copy_id);
+	for (auto* view: m_active) {
+		for (const auto& [value, index]: view->elements) {
+			auto&      element = m_elements[index];
+			auto&      binding = element.binding;
+			const auto& info   = binding.desc.view_info;
+			if (binding.image_id != image_id || !(aspects & info.aspect) ||
+			    info.base_level >= range.base_level + range.level_count ||
+			    range.base_level >= info.base_level + info.level_count ||
+			    info.base_layer >= range.base_layer + range.layer_count ||
+			    range.base_layer >= info.base_layer + info.layer_count) {
+				continue;
+			}
+			if (auto* old = ImageOf(element)) {
+				old->heap_refs.fetch_sub(1u, std::memory_order_relaxed);
+			}
+			binding.image_id = copy_id;
+			binding.layout   = copy.ReadLayout();
+			if (!binding.mip_views.empty()) {
+				for (uint32_t mip = 0; mip < binding.mip_views.size(); ++mip) {
+					auto mip_info        = info;
+					mip_info.base_level += mip;
+					mip_info.level_count = 1;
+					mip_info.min_lod     = 0;
+					binding.mip_views[mip] = copy.FindView(mip_info);
+				}
+				binding.image_view = binding.mip_views.front();
+			} else {
+				binding.image_view = copy.FindView(info);
+			}
+			element.serial = copy.serial;
+			copy.heap_refs.fetch_add(1u, std::memory_order_relaxed);
+			m_writes.push_back(index);
+		}
+	}
+	WriteDescriptors();

Major · Functional Correctness · Heavy lift

Do not overwrite a descriptor used by an earlier recorded draw.

A draw can first sample the original depth image without feedback. A later draw can reuse the same heap element and redirect it here before the command buffer is submitted. WriteDescriptors then replaces the earlier draw's descriptor with the copy view. With update-after-bind, submission uses the latest descriptor; the earlier draw can access the copy before its copy command runs. Allocate a new element for the redirected binding and retain the old descriptor until earlier uses finish. (docs.vulkan.org)

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 20:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#discussion_r4543068729) On `src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp` line 606 (outdated): ```diff @@ -547,6 +547,65 @@ void ImageHeap::WriteDescriptors() { m_writes.clear(); } +void ImageHeap::DepthViews(ImageId image_id, std::vector<ImageViewInfo>& views) const { + for (const auto* view: m_active) { + for (const auto& [value, index]: view->elements) { + const auto& binding = m_elements[index].binding; + if (binding.image_id != image_id) continue; + views.push_back(binding.desc.view_info); + for (uint32_t mip = 0; mip < binding.mip_views.size(); ++mip) { + auto info = binding.desc.view_info; + info.base_level += mip; + info.level_count = 1; + info.min_lod = 0; + views.push_back(info); + } + } + } +} + +void ImageHeap::RedirectDepth(ImageId image_id, ImageId copy_id, + const ImageSubresourceRange& range, + vk::ImageAspectFlags aspects) { + auto& textures = m_context.GetTextureCache(); + auto& copy = textures.GetImage(copy_id); + for (auto* view: m_active) { + for (const auto& [value, index]: view->elements) { + auto& element = m_elements[index]; + auto& binding = element.binding; + const auto& info = binding.desc.view_info; + if (binding.image_id != image_id || !(aspects & info.aspect) || + info.base_level >= range.base_level + range.level_count || + range.base_level >= info.base_level + info.level_count || + info.base_layer >= range.base_layer + range.layer_count || + range.base_layer >= info.base_layer + info.layer_count) { + continue; + } + if (auto* old = ImageOf(element)) { + old->heap_refs.fetch_sub(1u, std::memory_order_relaxed); + } + binding.image_id = copy_id; + binding.layout = copy.ReadLayout(); + if (!binding.mip_views.empty()) { + for (uint32_t mip = 0; mip < binding.mip_views.size(); ++mip) { + auto mip_info = info; + mip_info.base_level += mip; + mip_info.level_count = 1; + mip_info.min_lod = 0; + binding.mip_views[mip] = copy.FindView(mip_info); + } + binding.image_view = binding.mip_views.front(); + } else { + binding.image_view = copy.FindView(info); + } + element.serial = copy.serial; + copy.heap_refs.fetch_add(1u, std::memory_order_relaxed); + m_writes.push_back(index); + } + } + WriteDescriptors(); ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Heavy lift** **Do not overwrite a descriptor used by an earlier recorded draw.** A draw can first sample the original depth image without feedback. A later draw can reuse the same heap element and redirect it here before the command buffer is submitted. `WriteDescriptors` then replaces the earlier draw's descriptor with the copy view. With update-after-bind, submission uses the latest descriptor; the earlier draw can access the copy before its copy command runs. Allocate a new element for the redirected binding and retain the old descriptor until earlier uses finish. ([docs.vulkan.org](https://docs.vulkan.org/refpages/latest/refpages/source/VkDescriptorBindingFlagBits.html?utm_source=openai)) <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:4a8ba2c3b5dba15dc65955a4 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

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

Actionable comments posted: 3

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c67f319825ff288cfeddb3843f20fd5d3c5ee3e6 and 48ca227ab3d49a517d23993cf6caf371caf70605.

Files selected for processing: 6

  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
  • src/graphics/host_gpu/renderer/pipeline/imageHeap.cpp
  • src/graphics/host_gpu/renderer/pipeline/imageHeap.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; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 20:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#pullrequestreview-5865150412) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 3** <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/bc934ef03410b760fbf8e49db1d79485e7e5f887/.coderabbit.yaml>) - **Commit**: [bc934ef](<https://github.com/KytyPS5/KytyPS5/commit/bc934ef03410b760fbf8e49db1d79485e7e5f887>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `730af3d8-5b00-4653-89ac-0fa18bc5defd` </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 c67f319825ff288cfeddb3843f20fd5d3c5ee3e6 and 48ca227ab3d49a517d23993cf6caf371caf70605. </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: 6</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/pipeline/imageHeap.cpp` * `src/graphics/host_gpu/renderer/pipeline/imageHeap.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; 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=21011972-8d96-4375-92de-2780a84a4ebb attempt=ce32f64f-e7e5-47cd-98fb-c9718097e835 batch=1/1 -->
Author
Owner

@⁠theantipopau on GitHub · 2026-11-13 20:40 UTC · original

Status: rebased onto current main. Local --depth-feedback-copy-only and --image-rebind-only selectors pass, and Windows/macOS/Linux CI is green. The PR is CLEAN/MERGEABLE. The fork account cannot merge it (GitHub rejects MergePullRequest for lack of permission), so a maintainer needs to merge.

**@⁠theantipopau** on GitHub · 2026-11-13 20:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#issuecomment-6864374596) Status: rebased onto current `main`. Local `--depth-feedback-copy-only` and `--image-rebind-only` selectors pass, and Windows/macOS/Linux CI is green. The PR is CLEAN/MERGEABLE. The fork account cannot merge it (GitHub rejects `MergePullRequest` for lack of permission), so a maintainer needs to merge.
Author
Owner

@⁠theantipopau on GitHub · 2026-11-13 22:08 UTC · original

Latest head 7b468b55 makes the image-heap depth redirect safe. The bindless heap set is shared by every recorded draw, so the in-place element rewrite could let an earlier draw sample the feedback copy. RedirectDepth now collects the affected elements, submits and waits for the preceding recording, then rewrites the descriptors; the current draw continues in a fresh command buffer. This matters for the no-feedback path GTA V (PPSA04264, #1123) takes on Arc B580 when its tables sample depth. Local --depth-feedback-copy-only and --image-rebind-only selectors pass; CI is running.

**@⁠theantipopau** on GitHub · 2026-11-13 22:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#issuecomment-6866125307) Latest head `7b468b55` makes the image-heap depth redirect safe. The bindless heap set is shared by every recorded draw, so the in-place element rewrite could let an earlier draw sample the feedback copy. `RedirectDepth` now collects the affected elements, submits and waits for the preceding recording, then rewrites the descriptors; the current draw continues in a fresh command buffer. This matters for the no-feedback path GTA V (PPSA04264, #1123) takes on Arc B580 when its tables sample depth. Local `--depth-feedback-copy-only` and `--image-rebind-only` selectors pass; CI is running.
Author
Owner

@⁠theantipopau on GitHub · 2026-11-13 22:25 UTC · original

Head 7b468b55: Windows, macOS and Linux CI are green, the PR is CLEAN/MERGEABLE, and the local copy/rebind selectors pass. The fork account still cannot merge; a maintainer needs to land it. --sampled-depth-resource-only still stops on this host at the pre-existing per-pipeline robustBufferAccess2 check, so the targeted selectors are the local evidence.

**@⁠theantipopau** on GitHub · 2026-11-13 22:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#issuecomment-6866433470) Head `7b468b55`: Windows, macOS and Linux CI are green, the PR is CLEAN/MERGEABLE, and the local copy/rebind selectors pass. The fork account still cannot merge; a maintainer needs to land it. `--sampled-depth-resource-only` still stops on this host at the pre-existing per-pipeline `robustBufferAccess2` check, so the targeted selectors are the local evidence.
Author
Owner

@⁠theantipopau on GitHub · 2026-11-14 02:47 UTC · original

Head eabb9de6 narrows the heap redirect synchronization. Each heap element now records the last draw and scheduler tick that committed it; RedirectDepth only flushes a recording when an affected element was used in that recording, and only waits for ticks that are still in flight. New elements and completed draws skip the stall. Added heap-test checks that a new element starts unused and records its commit. Build, --depth-feedback-copy-only, --image-rebind-only, and the ResidentImageHeap case pass locally; Windows/macOS/Linux CI is green.

**@⁠theantipopau** on GitHub · 2026-11-14 02:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#issuecomment-6870456297) Head `eabb9de6` narrows the heap redirect synchronization. Each heap element now records the last draw and scheduler tick that committed it; `RedirectDepth` only flushes a recording when an affected element was used in that recording, and only waits for ticks that are still in flight. New elements and completed draws skip the stall. Added heap-test checks that a new element starts unused and records its commit. Build, `--depth-feedback-copy-only`, `--image-rebind-only`, and the `ResidentImageHeap` case pass locally; Windows/macOS/Linux CI is green.
Author
Owner

@⁠theantipopau on GitHub · 2026-11-14 03:25 UTC · original

Added the two-draw heap-depth regression in HeapDepthRedirect (commit 2b8ac4d3). It draws once with a bindless heap element sampling the original D32 depth, then redirects that element to a feedback copy cleared to a different depth and draws again. Readback asserts the first draw still returns the original depth and the second returns the copy.

Local checks: --heap-depth-redirect-only, --depth-feedback-copy-only, and --image-rebind-only pass. CI is queued for the new head.

**@⁠theantipopau** on GitHub · 2026-11-14 03:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#issuecomment-6870929873) Added the two-draw heap-depth regression in `HeapDepthRedirect` (commit `2b8ac4d3`). It draws once with a bindless heap element sampling the original D32 depth, then redirects that element to a feedback copy cleared to a different depth and draws again. Readback asserts the first draw still returns the original depth and the second returns the copy. Local checks: `--heap-depth-redirect-only`, `--depth-feedback-copy-only`, and `--image-rebind-only` pass. CI is queued for the new head.
Author
Owner

@⁠theantipopau on GitHub · 2026-11-14 08:10 UTC · original

Head 4c50f89a closes the remaining heap mip gap. DepthViews now keeps each resident entry's base and dynamic-mip views grouped; if any mip overlaps the written depth, the copy covers the entry's whole base/mip range and RedirectDepth matches mips instead of only the base view. Also removed the redundant semaphore refresh and extended HeapDepthRedirect to apply the pending load clear through CopyDepthForFeedback and to leave an acquired-but-uncommitted view active before the redirect.

Local checks: build passes; --heap-depth-redirect-only, --depth-feedback-copy-only, and --image-rebind-only pass. A validation-layer run of --heap-depth-redirect-only exited 0 with no VUIDs observed. No Arc B580 or GTA V available here, so this still needs the reporter run.

**@⁠theantipopau** on GitHub · 2026-11-14 08:10 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#issuecomment-6874340179) Head `4c50f89a` closes the remaining heap mip gap. `DepthViews` now keeps each resident entry's base and dynamic-mip views grouped; if any mip overlaps the written depth, the copy covers the entry's whole base/mip range and `RedirectDepth` matches mips instead of only the base view. Also removed the redundant semaphore refresh and extended `HeapDepthRedirect` to apply the pending load clear through `CopyDepthForFeedback` and to leave an acquired-but-uncommitted view active before the redirect. Local checks: build passes; `--heap-depth-redirect-only`, `--depth-feedback-copy-only`, and `--image-rebind-only` pass. A validation-layer run of `--heap-depth-redirect-only` exited 0 with no VUIDs observed. No Arc B580 or GTA V available here, so this still needs the reporter run.
Author
Owner

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

Head 55ebbc58 fixes the test-side crash reported above: CheckRasterization read bindings.pixel.images[0] on draws with no pixel images. It now computes an empty-safe samples_native_depth first and keeps the same assertion: a feedback draw must sample the native depth image.

Rebuilt the Release test target and reran:

  • --depth-feedback-copy-only: DepthAttachmentFeedback ok, HeapDepthRedirect ok
  • --heap-depth-redirect-only: HeapDepthRedirect ok
  • --image-rebind-only: RenderExecutorStencilBindingDiscovery ok

--polygon-mode-only still stops before rasterization on this host at the existing byte-granular per-pipeline robustBufferAccess2 is not supported dispatch check, so the crash path itself could not be executed here. I did not weaken that capability check.

No GTA V/Arc B580 run is available here; the in-game copy path still needs the reporter run.

**@⁠theantipopau** on GitHub · 2026-11-23 00:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#issuecomment-7088093034) Head `55ebbc58` fixes the test-side crash reported above: `CheckRasterization` read `bindings.pixel.images[0]` on draws with no pixel images. It now computes an empty-safe `samples_native_depth` first and keeps the same assertion: a feedback draw must sample the native depth image. Rebuilt the Release test target and reran: - `--depth-feedback-copy-only`: `DepthAttachmentFeedback ok`, `HeapDepthRedirect ok` - `--heap-depth-redirect-only`: `HeapDepthRedirect ok` - `--image-rebind-only`: `RenderExecutorStencilBindingDiscovery ok` `--polygon-mode-only` still stops before rasterization on this host at the existing `byte-granular per-pipeline robustBufferAccess2 is not supported` dispatch check, so the crash path itself could not be executed here. I did not weaken that capability check. No GTA V/Arc B580 run is available here; the in-game copy path still needs the reporter run.
Author
Owner

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

CI is green on head 55ebbc58: Windows, macOS and Linux builds all passed. Local Release selectors also pass on the fixed build. The PR remains MERGEABLE; the fork account cannot merge it, so a maintainer still needs to land it.

**@⁠theantipopau** on GitHub · 2026-11-23 00:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2191#issuecomment-7088421210) CI is green on head `55ebbc58`: Windows, macOS and Linux builds all passed. Local Release selectors also pass on the fixed build. The PR remains MERGEABLE; the fork account cannot merge it, so a maintainer still needs to land it.
This pull request has changes conflicting with the target branch.
  • src/graphics/host_gpu/renderer/renderDraw.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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