graphics: keep HTile clear state while its depth surface is bound (PPSA23566) #1743

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

@⁠0xcrstn on GitHub · 2026-10-20 01:28 UTC · original
0xcrstn:fix/ufc6-htile-clear-recreate → main · +104 −4 · 3 files · 2 commits · open

Game and problem

EA SPORTS UFC 6 (PPSA23566, 01.004.000), Windows 11, RTX 5090 (driver 617.42). At fighter select (and some fight and menu scenes) the fighters render with black blocks and torn silhouettes, and the screen flashes.

A RenderDoc capture of fighter select shows why. The fighter depth pass begins (vkCmdBeginRendering) on a 3200x1800 D32S8 image with depth and stencil loadOp = LOAD. Kyty created that image in the same frame and filled it from guest memory (vkCmdCopyBufferToImage). Before the first draw it holds a repeating stripe pattern, not a cleared value. The draws use GreaterEqual (reverse Z), so fighter fragments only land where they beat that garbage, and the depth-tested lighting fails wherever the silhouette is missing.

Cause

I logged the HTile state on every depth-target bind, every guest HTile clear (TextureCache::ClearMeta), and every depth image recreate and delete:

  • The game binds one depth surface (guest 0x11c48d0000, 3200x1800) alternately as D32 with HTile 0x11c6040000 and as D32S8 with HTile 0x11c66c0000. It fast-clears each HTile while the other variant is bound.
  • Each switch makes ResolveDepthOverlap recreate the native image (stencil mismatch), about 200 times each way in one session.
  • DeleteImage erases the old image's m_surface_metas entry. When the game then clears that HTile, ClearMeta finds no entry and drops the clear (known=false).
  • The next bind recreates the image with htile_initial_clear = false, finds no pending clear, and AcquireRenderTargets loads stale memory instead of clearing. 423 of 430 binds of this surface had no clear.
  • Two more surfaces (1776x1000 and 3216x1808) follow the same pattern with their own HTile pairs. They show up in other scenes.

The bug is on main; nothing else is needed to reach fighter select.

Change

  • MetaDataInfo::depth_address records the depth surface (the native image base) each HTile was last bound with. FindDepthTarget sets it. When an HTile moves to another surface, its clear state restarts from that surface's htile_initial_clear.
  • DeleteImage keeps a surface's HTile state while another registered HTile depth image of the same surface remains. Otherwise it erases every entry that surface owns, and only those. An HTile another surface has rebound stays with that surface.

All the erase points stay tied to the guest depth surface: the last HTile depth image of the surface is deleted, a non-depth replacement, unmap, or color metadata reuse.

Relation to d8c4a9af / c3e7ec82 / 2c730e58

d8c4a9af made HTile state belong to guest memory and never erased it on image deletion. c3e7ec82 fixed a Jusant regression from it, and 2c730e58 reverted both together with opt-in ZMask. I found no stated reason for the revert. Two things I took from them:

  • An HTile entry that outlives its surface is a real hazard. renderCompute.cpp treats a compute dispatch writing a known metadata address as a clear and skips it, and FillBuffer records a clear too. That is why this change never keeps an entry without a live HTile depth image of its surface.
  • The Jusant case is kept as on main. There, depth is replaced by an R32 storage image, the HTile is cleared, and depth is recreated. A non-depth replacement drops the state, so a clear recorded while the surface was storage does not apply.

Please check whether this also fits whatever prompted the revert.

Testing

  • New checks in CheckUnifiedTextureCacheFlow (--htile-clear-only):

    • alternate D32 (HTile A) and D32S8 (HTile B) bindings of one surface; a clear of A while D32S8 is bound reaches the next D32 bind, and the reverse;
    • a non-depth (storage) replacement drops both;
    • the state survives while one variant remains and is erased with the last depth image;
    • an HTile rebound by another surface does not inherit the old surface's pending clear, and is not erased when the old surface goes away.

    The first check fails on main ("the D32 HTile was forgotten when its depth surface switched to D32S8"). The surface-change and rebinding checks fail without their parts of the change.

  • shader_recompiler_compute_tests: all cases pass (Windows, clang-cl, RTX 5090).

  • UFC 6 on my integration build (this change plus my open topics): fighter select and other screens render correctly. A RenderDoc capture shows the 3200x1800 depth passes begin with CLEAR, and that surface's binds that applied a clear went from 7 of 430 to 41 of 69.

AI use

Claude Code did the investigation:

  • RenderDoc capture analysis by script;
  • diagnostic logging of HTile state;
  • reading the upstream history.

It wrote the change and the tests, ran the test suite, and ran the Claude, Codex and CodeRabbit reviews. The reviews found the owner-key, surface-change and rebinding cases, now fixed and tested.

I reviewed the evidence and the change, captured the frames in RenderDoc, and played the game on the integration build to confirm the rendering.

🤖 Generated with Claude Code

**@⁠0xcrstn** on GitHub · 2026-10-20 01:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1743) `0xcrstn:fix/ufc6-htile-clear-recreate` → `main` · +104 −4 · 3 files · 2 commits · open ## Game and problem EA SPORTS UFC 6 (PPSA23566, 01.004.000), Windows 11, RTX 5090 (driver 617.42). At fighter select (and some fight and menu scenes) the fighters render with black blocks and torn silhouettes, and the screen flashes. A RenderDoc capture of fighter select shows why. The fighter depth pass begins (`vkCmdBeginRendering`) on a 3200x1800 D32S8 image with depth and stencil `loadOp = LOAD`. Kyty created that image in the same frame and filled it from guest memory (`vkCmdCopyBufferToImage`). Before the first draw it holds a repeating stripe pattern, not a cleared value. The draws use `GreaterEqual` (reverse Z), so fighter fragments only land where they beat that garbage, and the depth-tested lighting fails wherever the silhouette is missing. ## Cause I logged the HTile state on every depth-target bind, every guest HTile clear (`TextureCache::ClearMeta`), and every depth image recreate and delete: - The game binds one depth surface (guest 0x11c48d0000, 3200x1800) alternately as D32 with HTile 0x11c6040000 and as D32S8 with HTile 0x11c66c0000. It fast-clears each HTile while the other variant is bound. - Each switch makes `ResolveDepthOverlap` recreate the native image (stencil mismatch), about 200 times each way in one session. - `DeleteImage` erases the old image's `m_surface_metas` entry. When the game then clears that HTile, `ClearMeta` finds no entry and drops the clear (`known=false`). - The next bind recreates the image with `htile_initial_clear = false`, finds no pending clear, and `AcquireRenderTargets` loads stale memory instead of clearing. 423 of 430 binds of this surface had no clear. - Two more surfaces (1776x1000 and 3216x1808) follow the same pattern with their own HTile pairs. They show up in other scenes. The bug is on `main`; nothing else is needed to reach fighter select. ## Change - `MetaDataInfo::depth_address` records the depth surface (the native image base) each HTile was last bound with. `FindDepthTarget` sets it. When an HTile moves to another surface, its clear state restarts from that surface's `htile_initial_clear`. - `DeleteImage` keeps a surface's HTile state while another registered HTile depth image of the same surface remains. Otherwise it erases every entry that surface owns, and only those. An HTile another surface has rebound stays with that surface. All the erase points stay tied to the guest depth surface: the last HTile depth image of the surface is deleted, a non-depth replacement, unmap, or color metadata reuse. ## Relation to d8c4a9af / c3e7ec82 / 2c730e58 d8c4a9af made HTile state belong to guest memory and never erased it on image deletion. c3e7ec82 fixed a Jusant regression from it, and 2c730e58 reverted both together with opt-in ZMask. I found no stated reason for the revert. Two things I took from them: - An HTile entry that outlives its surface is a real hazard. `renderCompute.cpp` treats a compute dispatch writing a known metadata address as a clear and skips it, and `FillBuffer` records a clear too. That is why this change never keeps an entry without a live HTile depth image of its surface. - The Jusant case is kept as on `main`. There, depth is replaced by an R32 storage image, the HTile is cleared, and depth is recreated. A non-depth replacement drops the state, so a clear recorded while the surface was storage does not apply. Please check whether this also fits whatever prompted the revert. ## Testing - New checks in `CheckUnifiedTextureCacheFlow` (`--htile-clear-only`): - alternate D32 (HTile A) and D32S8 (HTile B) bindings of one surface; a clear of A while D32S8 is bound reaches the next D32 bind, and the reverse; - a non-depth (storage) replacement drops both; - the state survives while one variant remains and is erased with the last depth image; - an HTile rebound by another surface does not inherit the old surface's pending clear, and is not erased when the old surface goes away. The first check fails on `main` ("the D32 HTile was forgotten when its depth surface switched to D32S8"). The surface-change and rebinding checks fail without their parts of the change. - `shader_recompiler_compute_tests`: all cases pass (Windows, clang-cl, RTX 5090). - UFC 6 on my integration build (this change plus my open topics): fighter select and other screens render correctly. A RenderDoc capture shows the 3200x1800 depth passes begin with `CLEAR`, and that surface's binds that applied a clear went from 7 of 430 to 41 of 69. ## AI use Claude Code did the investigation: - RenderDoc capture analysis by script; - diagnostic logging of HTile state; - reading the upstream history. It wrote the change and the tests, ran the test suite, and ran the Claude, Codex and CodeRabbit reviews. The reviews found the owner-key, surface-change and rebinding cases, now fixed and tested. I reviewed the evidence and the change, captured the frames in RenderDoc, and played the game on the integration build to confirm the rendering. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
EA SPORTS UFC 6 binds one depth surface alternately as D32 with one HTile and
as D32S8 with another, and fast-clears each HTile while the other variant is
bound. Every switch replaces the native depth image, and deleting the old image
erased its HTile clear state, so the guest clear found no metadata and was
dropped. The next binding loaded stale guest memory instead of clearing
(loadOp LOAD in RenderDoc), which tore the fighter depth and blacked out the
depth-tested lighting at fighter select.

Track the depth surface each HTile was bound with, and keep its clear state
while another native depth image of that surface is registered. A non-depth
replacement or the last depth image still drops it, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-ups for the UFC 6 (PPSA23566) HTile fix:
- Record the owning surface by the native image base, which DeleteImage
  compares against; a layered binding can start at a later slice.
- Only an HTile depth image keeps a surface's state alive, so cleanup still
  runs when that image is replaced by one without HTile.
- When an HTile is bound by another surface, start from that surface's own
  state instead of inheriting the previous surface's pending clear.
- Deleting a surface erases only the entries it owns, not an HTile another
  surface has rebound, and cleanup runs for every depth image deletion.

Tests cover the surface change, the rebinding owner surviving the old
surface, and retirement with the last depth image.

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:19 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-20 01:32 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: f838e6c6-9a60-4f3d-9c0b-7a21728c6f57
📥 Commits

Reviewing files that changed from the base of the PR and between f186b35706 and 6d60824c6b.

📒 Files selected for processing: 3
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
  • tests/ShaderRecompilerComputeTests.cpp

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

📝 Walkthrough

The change adds a depth address to HTile metadata. FindDepthTarget resets and reapplies initial clear state when the native depth image address changes. DeleteImage retains metadata while another registered primary depth image remains for the same surface address. A new test covers clear-state retention, metadata reuse, and retirement during rebinding and unmapping.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 6d608

The reviewed HTile lifecycle changes are ready to merge after normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 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
Description check Passed The description clearly explains the HTile clear-state bug, the ownership and cleanup changes, and the associated tests and validation results.
Title check Passed The title clearly and concisely identifies the primary change: preserving HTile clear state while its depth surface remains bound.
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 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 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 01:32 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1743#issuecomment-6281222347) <!-- 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/1743?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**: `f838e6c6-9a60-4f3d-9c0b-7a21728c6f57` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between f186b35706ddbc3faf5513f326e2335d224802f7 and 6d60824c6b015a93487e8e56db5b2c72e9db3277. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 3</strong></summary> <dl> <dd> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.h` * `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; 7 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The change adds a depth address to HTile metadata. `FindDepthTarget` resets and reapplies initial clear state when the native depth image address changes. `DeleteImage` retains metadata while another registered primary depth image remains for the same surface address. A new test covers clear-state retention, metadata reuse, and retirement during rebinding and unmapping. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"6d60824c6b015a93487e8e56db5b2c72e9db3277" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>6d608</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `6d608` --> <!-- final_review_risk_coverage:{"sourceCommitId":"6d60824c6b015a93487e8e56db5b2c72e9db3277","coveredCommitId":"6d60824c6b015a93487e8e56db5b2c72e9db3277","kind":"reviewed"} --> The reviewed HTile lifecycle changes are ready to merge after normal checks. <!-- 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 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 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 | | :------------------------ | :--------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------- | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description clearly explains the HTile clear-state bug, the ownership and cleanup changes, and the associated tests and validation results. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely identifies the primary change: preserving HTile clear state while its depth surface remains bound. | | 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 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 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=1743)! 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
  • src/graphics/host_gpu/renderer/cache/textureCache.h
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/1743/head:github-bot/gh-1743'
git switch 'github-bot/gh-1743'

Merge

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