texture cache: queue a heap change when a stencil association adopts an image #2407

Open
github-bot wants to merge 1 commit from github-bot/gh-2407 into main AGit
Owner

@⁠Mcm190 on GitHub · 2026-11-19 12:17 UTC · original
Mcm190:texture-cache-stencil-heap-change → main · +50 −0 · 2 files · 1 commits · open

Fixes #2297.

Problem

TextureCache::AssociateStencil can reuse any registered image whose range and extent match the stencil memory, for example an R8 texture that a resident image heap sampled before the depth image was associated. It then rewrites record.info and sets record.depth_id without calling HeapChanged(). The heap keeps sampling the old R8 backing while stencil writes go to the depth image, until some other change of that record queues it.

Change

AssociateStencil calls record.HeapChanged() right before the rewrite. The record's heap_refs still belong to the pinned image, so the change is queued. For an image no heap references (a stencil plane that was just inserted, or one found by FindStencilPlane), HeapChanged() does nothing.

Tests

shader_recompiler_compute_tests --image-overlap-only, UnifiedTextureCacheFlow, two new checks: an R8 image that exactly matches a stencil range and extent, with a heap reference held, is adopted as the depth target's stencil plane ("stencil plane adopts an exact R8 image"), and the adoption queues exactly one heap change for that image ("adopted stencil plane queues a heap change"). The test removes its heap reference and queued changes afterwards.

On an RX 9070 XT (Linux, RADV, clang), the harness does not reach these checks as written: device setup needs the relaxed robustness check from #2036, and UnifiedTextureCacheFlow then stops earlier at a 2x D24S8 image (format=129) that RADV does not support. With the robustness check relaxed and a copy of the two checks run right after the flow's setup, they pass with this change and fail without it (failed at adopted stencil plane queues a heap change). The checks have not run in their place in the flow; CI is their first full run. Not tested in a game.

AI Assistance: Claude Opus 5.5.

**@⁠Mcm190** on GitHub · 2026-11-19 12:17 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2407) `Mcm190:texture-cache-stencil-heap-change` → `main` · +50 −0 · 2 files · 1 commits · open Fixes #2297. ## Problem `TextureCache::AssociateStencil` can reuse any registered image whose range and extent match the stencil memory, for example an R8 texture that a resident image heap sampled before the depth image was associated. It then rewrites `record.info` and sets `record.depth_id` without calling `HeapChanged()`. The heap keeps sampling the old R8 backing while stencil writes go to the depth image, until some other change of that record queues it. ## Change `AssociateStencil` calls `record.HeapChanged()` right before the rewrite. The record's `heap_refs` still belong to the pinned image, so the change is queued. For an image no heap references (a stencil plane that was just inserted, or one found by `FindStencilPlane`), `HeapChanged()` does nothing. ## Tests `shader_recompiler_compute_tests --image-overlap-only`, `UnifiedTextureCacheFlow`, two new checks: an R8 image that exactly matches a stencil range and extent, with a heap reference held, is adopted as the depth target's stencil plane ("stencil plane adopts an exact R8 image"), and the adoption queues exactly one heap change for that image ("adopted stencil plane queues a heap change"). The test removes its heap reference and queued changes afterwards. On an RX 9070 XT (Linux, RADV, clang), the harness does not reach these checks as written: device setup needs the relaxed robustness check from #2036, and `UnifiedTextureCacheFlow` then stops earlier at a 2x D24S8 image (`format=129`) that RADV does not support. With the robustness check relaxed and a copy of the two checks run right after the flow's setup, they pass with this change and fail without it (`failed at adopted stencil plane queues a heap change`). The checks have not run in their place in the flow; CI is their first full run. Not tested in a game. AI Assistance: Claude Opus 5.5.
AssociateStencil can reuse any registered image whose range and extent
match the stencil memory, for example an R8 texture that a resident
image heap sampled before the depth image was associated. It rewrote
the record's info and depth_id without queuing a heap change, so the
heap kept sampling the old R8 backing while stencil writes went to the
depth image. The record's heap_refs still belong to the pinned image,
so calling HeapChanged() before the rewrite queues the change.

Fixes #2297.

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

@⁠coderabbitai[bot] on GitHub · 2026-11-19 12:22 UTC · original · edited 2026-11-20 06:13 UTC

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

AssociateStencil now calls record.HeapChanged() after linking an associated stencil record to the depth image. A new test checks exact-range R8 image lookup, the depth_id association, and that heap-pinned adoption queues exactly one heap change.

Suggested reviewers: claxten10, thecruz

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to ef912

This change queues a heap update when a stencil plane adopts a heap-pinned image, so the heap stops sampling the old backing. No concrete merge-blocking risk was found; CI will provide the first full run of the new test.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a stencil association that adopts a registered image now queues a heap change. It matches the code change, which adds a HeapChanged() call in AssociateStencil. The tit…
Linked Issues check Passed Directly linked issue #2297 requires a call to record.HeapChanged() before AssociateStencil rewrites record.info and record.depth_id for a registered image that a heap may pin. The whole-PR summary st…
Out of Scope Changes check Passed The change set consists of a small addition in TextureCache::AssociateStencil (summary: +3/-0, one HeapChanged() call) and a test addition in tests/ShaderRecompilerComputeTests.cpp (summary: +47/-0). …
Description check Passed The description states the problem (AssociateStencil reuses a registered image and rewrites record.info and record.depth_id without calling HeapChanged()), the change (a HeapChanged() call before the …
Full details: Title check

Explanation

The title names the main change: a stencil association that adopts a registered image now queues a heap change. It matches the code change, which adds a HeapChanged() call in AssociateStencil. The title is specific and concise.

Full details: Linked Issues check

Explanation

Directly linked issue #2297 requires a call to record.HeapChanged() before AssociateStencil rewrites record.info and record.depth_id for a registered image that a heap may pin. The whole-PR summary states that AssociateStencil now calls record.HeapChanged() when it updates the adopted image's plane metadata and ownership. The PR description gives the same mechanism: the call runs right before the rewrite, and the pinned image's heap_refs are queued. The requirement is a single coding change, and the summary shows it. Limits: the textureCache.cpp diff could not be read, and the file read was truncated before AssociateStencil. The exact placement is therefore confirmed only by the summary. That summary says the call runs after linking to the depth image, while the issue says right before the rewrite. The author's test results (failing without the change, passing with it) are reported, not verified here. The new tests ('stencil plane adopts an exact R8 image', 'adopted stencil plane queues a heap change') are consistent with the issue but were not run by this review.

Full details: Out of Scope Changes check

Explanation

The change set consists of a small addition in TextureCache::AssociateStencil (summary: +3/-0, one HeapChanged() call) and a test addition in tests/ShaderRecompilerComputeTests.cpp (summary: +47/-0). The test checks the adoption of an exact-match R8 image and the queued heap change that #2297 describes. Both changes connect directly to #2297. No unrelated files or behavior changes appear in the supplied evidence. The unread diff remains a limit on this verdict: the review could not confirm the full set of changed files beyond the summary.

Full details: Description check

Explanation

The description states the problem (AssociateStencil reuses a registered image and rewrites record.info and record.depth_id without calling HeapChanged()), the change (a HeapChanged() call before the rewrite), and the tests added (two new checks in UnifiedTextureCacheFlow). This matches the changeset, so the description is related to the changes and 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

Recent review info

Run configuration

Commits

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

Files selected for processing: 2

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

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-19 12:22 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2407#issuecomment-7008969344) · edited 2026-11-20 06:13 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/2407?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> `AssociateStencil` now calls `record.HeapChanged()` after linking an associated stencil record to the depth image. A new test checks exact-range R8 image lookup, the `depth_id` association, and that heap-pinned adoption queues exactly one heap change. **Suggested reviewers:** `claxten10`, `thecruz` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"ef91293e9ffd3c728747c5bf4bc6a54aea2b0126" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix · **Severity of issue fixed:** Medium <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>ef912</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `ef912` --> <!-- final_review_risk_coverage:{"sourceCommitId":"ef91293e9ffd3c728747c5bf4bc6a54aea2b0126","coveredCommitId":"ef91293e9ffd3c728747c5bf4bc6a54aea2b0126","kind":"reviewed"} --> This change queues a heap update when a stencil plane adopts a heap-pinned image, so the heap stops sampling the old backing. No concrete merge-blocking risk was found; CI will provide the first full run of the new test. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title names the main change: a stencil association that adopts a registered image now queues a heap change. It matches the code change, which adds a HeapChanged() call in AssociateStencil. The tit… | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Directly linked issue `#2297` requires a call to record.HeapChanged() before AssociateStencil rewrites record.info and record.depth_id for a registered image that a heap may pin. The whole-PR summary st… | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The change set consists of a small addition in TextureCache::AssociateStencil (summary: +3/-0, one HeapChanged() call) and a test addition in tests/ShaderRecompilerComputeTests.cpp (summary: +47/-0). … | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description states the problem (AssociateStencil reuses a registered image and rewrites record.info and record.depth_id without calling HeapChanged()), the change (a HeapChanged() call before the … | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title names the main change: a stencil association that adopts a registered image now queues a heap change. It matches the code change, which adds a HeapChanged() call in AssociateStencil. The title is specific and concise. </dd> </dl> </details> <details> <summary><strong>Full details: Linked Issues check</strong></summary> <dl> <dd> <br> **Explanation** Directly linked issue `#2297` requires a call to record.HeapChanged() before AssociateStencil rewrites record.info and record.depth_id for a registered image that a heap may pin. The whole-PR summary states that AssociateStencil now calls record.HeapChanged() when it updates the adopted image's plane metadata and ownership. The PR description gives the same mechanism: the call runs right before the rewrite, and the pinned image's heap_refs are queued. The requirement is a single coding change, and the summary shows it. Limits: the textureCache.cpp diff could not be read, and the file read was truncated before AssociateStencil. The exact placement is therefore confirmed only by the summary. That summary says the call runs after linking to the depth image, while the issue says right before the rewrite. The author's test results (failing without the change, passing with it) are reported, not verified here. The new tests ('stencil plane adopts an exact R8 image', 'adopted stencil plane queues a heap change') are consistent with the issue but were not run by this review. </dd> </dl> </details> <details> <summary><strong>Full details: Out of Scope Changes check</strong></summary> <dl> <dd> <br> **Explanation** The change set consists of a small addition in TextureCache::AssociateStencil (summary: +3/-0, one HeapChanged() call) and a test addition in tests/ShaderRecompilerComputeTests.cpp (summary: +47/-0). The test checks the adoption of an exact-match R8 image and the queued heap change that `#2297` describes. Both changes connect directly to `#2297`. No unrelated files or behavior changes appear in the supplied evidence. The unread diff remains a limit on this verdict: the review could not confirm the full set of changed files beyond the summary. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description states the problem (AssociateStencil reuses a registered image and rewrites record.info and record.depth_id without calling HeapChanged()), the change (a HeapChanged() call before the rewrite), and the tests added (two new checks in UnifiedTextureCacheFlow). This matches the changeset, so the description is related to the changes and 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=2407)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> <br> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <br> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/a90be8dd7304640cf4176a975871d51443710292/.coderabbit.yaml>) - **Commit**: [a90be8d](<https://github.com/KytyPS5/KytyPS5/commit/a90be8dd7304640cf4176a975871d51443710292>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `51591561-f54f-4319-9deb-4237ff18044a` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between a90be8dd7304640cf4176a975871d51443710292 and ef91293e9ffd3c728747c5bf4bc6a54aea2b0126. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 2</strong></summary> <dl> <dd> <br> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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