renderer: do not adopt a depth image as a stencil association #1751

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

@⁠0xcrstn on GitHub · 2026-10-20 04:21 UTC · original
0xcrstn:fix/ufc6-slot-freed → main · +67 −1 · 2 files · 1 commits · open

Game and problem

EA SPORTS UFC 6 (PPSA23566, 01.004.000), Windows 11, RTX 5090 (driver 617.42). After a few minutes in the menus (main menu, Fight Now, Select Corner, fighter select, back and forth) Kyty exits with condition (!is_allocated(id)) is true in slotVector.h:41. Seen on several builds, after 6 to 8 minutes. The game reaches this point with #1738 applied; the bug is in main.

Cause

The host backtrace goes TextureCache::DeleteImage <- ResolveOverlap (one run) or <- TextureCache::UnmapMemory (another run). In both, the failing access is m_slot_images[image->depth_id]: a registered stencil association whose depth owner's slot has already been erased.

I logged AssociateStencil and DeleteImage. In the crashing run:

  • Depth target 5164 (32x32 D32S8, data 0x12c9d70000, stencil 0x12c9d80000+0x10000) got image 6621 as its stencil association. 6621 was a registered 32x32 D32S8 depth image at exactly 0x12c9d80000+0x10000, and it had a stencil association of its own (3964, at 0x12c9d90000).
  • Later, association 3964 was deleted while its owner 6621 was already erased, and Kyty exited.

Small tiled depth and stencil planes are one 64 KiB block each (TileGetDepthSize(32, 32, ...) gives 0x10000 for both), so a pooled depth surface can sit exactly on another target's stencil plane. AssociateStencil reuses any image with the same range and extent, so it turned the depth image into an S8 stencil record (info replaced, depth_id set) and kept its stencil_ids. DeleteImage frees stencil_ids only for images without depth_id, so deleting the adopted image leaves its old association registered with a depth_id that is erased afterwards. The next deletion of that association indexes the erased slot.

Change

AssociateStencil no longer reuses an image that IsDepth(); it inserts a separate association instead, as it already does when the extent differs. One condition in textureCache.cpp.

This also removes an HTile side effect with #1743 applied. There, DeleteImage drops a surface's HTile clear state (the m_surface_metas entries whose depth_address is the image's address) only for an image that IsDepth() and has no depth_id. An adopted depth image has its info replaced by the S8 plane and depth_id set, so deleting it would have left those entries behind.

Not changed: the depth image and the new association now both cover the stencil range, and stencil writes do not invalidate the depth image. This is the same coexistence AssociateStencil already has with other images at a reused stencil range (see the existing "stencil address reuse preserves color" check). A CPU read of that range could still publish the stale depth image instead of the stencil. I have not seen that happen in UFC 6.

Also a consequence of the two images at one range: a compute fill of that stencil plane is no longer turned into a native stencil clear. ClearImageFromBuffer sees two owners and returns false, so the shader's own dispatch runs, as it already does for other ambiguous ranges. I have not checked that the cached stencil picks up a fill made that way.

Testing

  • CheckUnifiedTextureCacheFlow (--htile-clear-only) gets a case where a depth image's range equals another depth target's stencil range (same extent). The case also checks that small depth and stencil footprints are both 0x10000. On main it fails with "a depth image was adopted as another target's stencil association". With that check disabled, the rest of the case (unmap the depth range, flush, unmap its stencil range) exits with the same slotVector.h:41 error and exit code as the game. With the change, both checks pass.
  • shader_recompiler_compute_tests: all cases pass on this branch rebased onto main 1a053f9e (Windows, clang-cl, RTX 5090). The Claude, Codex and CodeRabbit reviews ran on the same commit before the rebase (98e6912b on f186b357); git range-diff shows the commit unchanged.
  • UFC 6, --redzone, my main-menu save. Without this change, the menu loop above exited with slotVector.h:41 after 356 s on one build and after about 7 minutes on another (the logged run above).
    • Integration build with this branch (main f186b357 + #1738 + #1748 + #1743 + this branch), same menu loop plus a local fight: no slotVector.h:41 for 856 s. That run then ended in a separate, known crash in PthreadGetprio (a joined thread's stale winpthread handle), which is being fixed separately.
    • A diagnostic build on that integration build ran about 7,500 frames (381 s) with no slotVector.h:41.

AI use

Claude Code did the investigation (rebuilt the crashing commit to map the backtrace to the failing access, added diagnostic logging, analysed the play-run log), wrote the change and the test, ran the tests, and ran the Claude, Codex and CodeRabbit reviews. CodeRabbit found nothing. Codex's finding is the stale-depth point under "Not changed". I reviewed the evidence and the change and played the game for the diagnostic run.

🤖 Generated with Claude Code

**@⁠0xcrstn** on GitHub · 2026-10-20 04:21 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1751) `0xcrstn:fix/ufc6-slot-freed` → `main` · +67 −1 · 2 files · 1 commits · open ## Game and problem EA SPORTS UFC 6 (PPSA23566, 01.004.000), Windows 11, RTX 5090 (driver 617.42). After a few minutes in the menus (main menu, Fight Now, Select Corner, fighter select, back and forth) Kyty exits with `condition (!is_allocated(id)) is true in slotVector.h:41`. Seen on several builds, after 6 to 8 minutes. The game reaches this point with #1738 applied; the bug is in `main`. ## Cause The host backtrace goes `TextureCache::DeleteImage` <- `ResolveOverlap` (one run) or <- `TextureCache::UnmapMemory` (another run). In both, the failing access is `m_slot_images[image->depth_id]`: a registered stencil association whose depth owner's slot has already been erased. I logged `AssociateStencil` and `DeleteImage`. In the crashing run: - Depth target 5164 (32x32 D32S8, data 0x12c9d70000, stencil 0x12c9d80000+0x10000) got image 6621 as its stencil association. 6621 was a registered 32x32 D32S8 depth image at exactly 0x12c9d80000+0x10000, and it had a stencil association of its own (3964, at 0x12c9d90000). - Later, association 3964 was deleted while its owner 6621 was already erased, and Kyty exited. Small tiled depth and stencil planes are one 64 KiB block each (`TileGetDepthSize(32, 32, ...)` gives 0x10000 for both), so a pooled depth surface can sit exactly on another target's stencil plane. `AssociateStencil` reuses any image with the same range and extent, so it turned the depth image into an S8 stencil record (`info` replaced, `depth_id` set) and kept its `stencil_ids`. `DeleteImage` frees `stencil_ids` only for images without `depth_id`, so deleting the adopted image leaves its old association registered with a `depth_id` that is erased afterwards. The next deletion of that association indexes the erased slot. ## Change `AssociateStencil` no longer reuses an image that `IsDepth()`; it inserts a separate association instead, as it already does when the extent differs. One condition in `textureCache.cpp`. This also removes an HTile side effect with [#1743](https://git.gtahub.st/github/KytyPS5--KytyPS5/pulls/1743) applied. There, `DeleteImage` drops a surface's HTile clear state (the `m_surface_metas` entries whose `depth_address` is the image's address) only for an image that `IsDepth()` and has no `depth_id`. An adopted depth image has its `info` replaced by the S8 plane and `depth_id` set, so deleting it would have left those entries behind. Not changed: the depth image and the new association now both cover the stencil range, and stencil writes do not invalidate the depth image. This is the same coexistence `AssociateStencil` already has with other images at a reused stencil range (see the existing "stencil address reuse preserves color" check). A CPU read of that range could still publish the stale depth image instead of the stencil. I have not seen that happen in UFC 6. Also a consequence of the two images at one range: a compute fill of that stencil plane is no longer turned into a native stencil clear. `ClearImageFromBuffer` sees two owners and returns false, so the shader's own dispatch runs, as it already does for other ambiguous ranges. I have not checked that the cached stencil picks up a fill made that way. ## Testing - `CheckUnifiedTextureCacheFlow` (`--htile-clear-only`) gets a case where a depth image's range equals another depth target's stencil range (same extent). The case also checks that small depth and stencil footprints are both 0x10000. On `main` it fails with "a depth image was adopted as another target's stencil association". With that check disabled, the rest of the case (unmap the depth range, flush, unmap its stencil range) exits with the same `slotVector.h:41` error and exit code as the game. With the change, both checks pass. - `shader_recompiler_compute_tests`: all cases pass on this branch rebased onto `main` 1a053f9e (Windows, clang-cl, RTX 5090). The Claude, Codex and CodeRabbit reviews ran on the same commit before the rebase (98e6912b on f186b357); `git range-diff` shows the commit unchanged. - UFC 6, `--redzone`, my main-menu save. Without this change, the menu loop above exited with `slotVector.h:41` after 356 s on one build and after about 7 minutes on another (the logged run above). - Integration build with this branch (main f186b357 + #1738 + #1748 + #1743 + this branch), same menu loop plus a local fight: no `slotVector.h:41` for 856 s. That run then ended in a separate, known crash in `PthreadGetprio` (a joined thread's stale winpthread handle), which is being fixed separately. - A diagnostic build on that integration build ran about 7,500 frames (381 s) with no `slotVector.h:41`. ## AI use Claude Code did the investigation (rebuilt the crashing commit to map the backtrace to the failing access, added diagnostic logging, analysed the play-run log), wrote the change and the test, ran the tests, and ran the Claude, Codex and CodeRabbit reviews. CodeRabbit found nothing. Codex's finding is the stale-depth point under "Not changed". I reviewed the evidence and the change and played the game for the diagnostic run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
EA SPORTS UFC 6 (PPSA23566) exits with "condition (!is_allocated(id))
is true in slotVector.h:41" after a few minutes of menu navigation.

Small tiled depth and stencil planes are one 64 KiB block each, so the
game can place a 32x32 D32S8 target's stencil plane exactly on another
32x32 D32S8 surface. AssociateStencil reused any image with the same
range and extent, so it turned that depth image into an S8 stencil
record and kept the image's own stencil associations. DeleteImage frees
stencil_ids only for depth owners, so deleting the adopted image left
its old association registered with an erased depth_id, and the next
deletion of that association (overlap cleanup or unmap) indexed the
erased slot.

Logging in the game showed the adoption of a registered D32S8 image
with one association at the stencil range of another 32x32 target,
then the deletion of that association after its owner was erased,
then the exit. Never adopt a depth image; insert a separate
association instead.

The new UnifiedTextureCacheFlow check fails without this change, and
past it the same sequence ends in the same slotVector.h:41 exit.

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

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

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: feae1a10-d7b2-4a06-95c2-3feb0b5bb6d8
📥 Commits

Reviewing files that changed from the base of the PR and between 1a053f9e13 and bd50bc74fb.

📒 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 8 included reviews per hour; 5 remain after this review.

📝 Walkthrough

AssociateStencil now excludes depth-image candidates when it reuses a stencil association. The regression test covers overlapping depth and stencil ranges, verifies that each depth target retains the expected association, and checks that unmapping removes the orphaned association without removing the second depth target.

Suggested reviewers: nmzik

Priority: ⬆️ High

Change: Bug fix

Merge Risk: ⚪ Minimal · up to bd50b

The change prevents a depth image from being adopted as a stencil association, which caused the reported orphaned-slot exit. No actionable merge-blocking risk was found in the supplied context.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing a depth image from being reused as a stencil association.
Description check Passed The description is directly related to the changes. It explains the UFC 6 failure, the cause, the code change, known limitations, and validation results.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-20 04:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1751#issuecomment-6283339463) <!-- 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/1751?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-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `feae1a10-d7b2-4a06-95c2-3feb0b5bb6d8` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 1a053f9e13405bf34171a47aae9f2b9a6e7afd7d and bd50bc74fb12867401f3c7344849d19d790519ec. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 2</strong></summary> <dl> <dd> * `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 8 included reviews per hour; 5 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> `AssociateStencil` now excludes depth-image candidates when it reuses a stencil association. The regression test covers overlapping depth and stencil ranges, verifies that each depth target retains the expected association, and checks that unmapping removes the orphaned association without removing the second depth target. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬆️ High <!-- change_assessment_commit:"bd50bc74fb12867401f3c7344849d19d790519ec" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>bd50b</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `bd50b` --> <!-- final_review_risk_coverage:{"sourceCommitId":"bd50bc74fb12867401f3c7344849d19d790519ec","coveredCommitId":"bd50bc74fb12867401f3c7344849d19d790519ec","kind":"reviewed"} --> The change prevents a depth image from being adopted as a stencil association, which caused the reported orphaned-slot exit. No actionable merge-blocking risk was found in the supplied context. <!-- 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 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><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> Passed checks: 4 passed</strong></summary> <dl> <dd> | 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: preventing a depth image from being reused as a stencil association. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description is directly related to the changes. It explains the UFC 6 failure, the cause, the code change, known limitations, and validation results. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1751)! 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> - [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> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
This pull request has changes conflicting with the target branch.
  • src/graphics/host_gpu/renderer/cache/textureCache.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/1751/head:github-bot/gh-1751'
git switch 'github-bot/gh-1751'

Merge

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