gpu: fix vanishing models when freed depth-buffer metadata memory is reused (PPSA09809) #1803
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1803
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1803"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@MrBigBritches on GitHub · 2026-10-21 22:32 UTC · original
MrBigBritches:htile-reuse-dispatch-fix→main· +524 −24 · 4 files · 14 commits · openDepth buffers on the PS5 come with HTILE, a compact metadata block that records per-tile depth information so the GPU can skip work and compress depth. Games often reset HTILE with a small compute shader. Kyty doesn't emulate the HTILE bytes themselves. It recognizes these clear dispatches and replaces them with a logical "clear this depth surface's metadata" operation.
Kyty remembered which memory held HTILE until the memory was unmapped or the depth image was freed. Games free depth targets and reuse that memory for other things. In Octopath Traveler II, battle depth targets are freed and their HTILE memory becomes Unreal Engine's GPUScene buffer, which holds per-object data for every model in the scene. The GPUScene resize and upload shaders wrote to a "known HTILE" address, so Kyty swallowed them as metadata clears. GPUScene then kept stale memory, and after battles and scene changes characters and objects vanished. Sometimes a giant plane cut through the scene instead.
Example

Changes
Recognise only real metadata clears
A compute dispatch is now consumed as a metadata clear only if all of these hold:
Anything else runs as a normal dispatch.
Check and clear in one step
TextureCache::ClearMetaSurfaceschecks every buffer the dispatch binds and marks the written surfaces cleared only if all of them pass, under one lock. A dispatch rejected partway through never leaves some surfaces cleared, and an unmap on another thread can't remove a surface between the check and the clear.Keep the per-dispatch cost low
IsMetaClearShaderCandidateandAddMetaClearTarget, each under 50 lines.Metadata size with shared HTILE
Two live depth images can share an HTILE base. The recorded size stays the larger one, so binding the smaller image doesn't turn away clears of the larger one. A code comment explains why, and a test pins it.
Testing
New tests in
ShaderRecompilerComputeTests, each checked against a deliberately broken classifier:ComputeMetaClearClassificationgains reused-HTILE cases:ComputeMetaClearInputs:MetaClearSurfacesAllOrNothing: a later failing target leaves earlier ones uncleared, for unregistered, oversized and read-as-input targets, and for dispatches writing no surface.ComputeMetaClearShaderGuards: a clear-shaped dispatch is consumed, and the same dispatch with raw-address writes, run-time descriptors or GDS is kept.The full suite passes except
kernel_file_system, which fails the same way onmain.In-game, with a temporary diagnostic (not committed) on the overlay and in the log:
Real clears in both games bind a bounded descriptor exactly the size of the HTILE surface, plus at most one 16-byte constant, and use none of the raw-address, run-time descriptor or GDS features. An earlier 26-minute Octopath Traveler II session ran 95 GPUScene resizes with no dropped dispatches and no missing models.
Known limitations
These predate this PR and are left for follow-ups:
@coderabbitai[bot] on GitHub · 2026-10-21 22:39 UTC · original · edited 2026-10-27 23:56 UTC
No actionable comments were generated in the recent review.
8be49e6b-2fc9-4f56-a93e-7d1a55a26f1eReviewing files that changed from the base of the PR and between
4eae95dd14and6d3ad8f97a.tests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Walkthrough
Texture metadata records now retain the largest registered range size for each address.
TextureCache::ClearMetaSurfacesvalidates all targets under one lock and marks written targets cleared only if validation succeeds. Compute metadata-clear classification screens shader operations and buffer descriptors before submitting targets to the cache. Tests cover metadata range tracking, accepted and rejected dispatches, and all-or-nothing validation.Suggested reviewers:
claxten10Priority:
Normal
Change: Bug fix
Merge Risk:
Moderate · up to
6d3adSome compute dispatches can still be mistaken for metadata clears and skipped, potentially causing missing rendered content. Resolve the outstanding range and overlap checks before merging.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 3 files. (1 skipped: 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
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 helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-21 22:39 UTC · original · edited 2026-10-21 23:08 UTC
On
src/graphics/host_gpu/renderer/renderCompute.cppline 106 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5508
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 18942
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16160
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11942
Reject unbounded write descriptors before consuming the dispatch.
NumRecords() == UINT32_MAXbypasses the write-size check. If the descriptor targets registered metadata, the dispatch can be consumed without proving that its write range fits the metadata surface. Treatmeta_size == 0as unknown and reject it as well.🐛 Suggested fix
📝 Committable suggestion
✅ Confirmed as addressed by @MrBigBritches
@coderabbitai[bot] on GitHub · 2026-10-21 22:39 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
e9f6beaf-1f17-4a9e-803a-a489cffe6afa📥 Commits
Reviewing files that changed from the base of the PR and between
286481889fand cce6676855f69cfa0125eab206d4f411eaf24e16.📒 Files selected for processing: 4
src/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/renderCompute.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@MrBigBritches on GitHub · 2026-10-21 22:57 UTC · original
On
src/graphics/host_gpu/renderer/renderCompute.cppline 106 (outdated):Applied the meta_size == 0 half in 4ca3a181: a write to metadata of unknown size is no longer consumed (registration always records a size in practice; the test fixture now does too, and there’s a new case for it). I kept unbounded descriptors (NumRecords == 0xffffffff) eligible: clear shaders commonly address the whole surface that way, so rejecting them would turn real HTILE clears into native writes the depth path never sees. Such a dispatch is still required to write only metadata and read at most 4 KiB of constants.
@coderabbitai[bot] on GitHub · 2026-10-21 23:08 UTC · original
On
src/graphics/host_gpu/renderer/renderCompute.cppline 106 (outdated):@MrBigBritches Thanks for the fix and clarification. The supplied code rejects
meta_size == 0before consuming the dispatch.I retract the recommendation to reject every unbounded descriptor. That would exclude the full-surface HTILE clears you described. Keeping those descriptors eligible is consistent with this classifier, although the remaining checks are a heuristic rather than proof of the shader’s write extent.
✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-10-25 16:50 UTC · original · reviewed
Actionable comments posted: 1
d27c2402-24a1-4176-a153-c1a3575ad772Reviewing files that changed from the base of the PR and between 4ca3a181de180613f78c43304fc61ac63caa4a01 and fb2dada18e5dd32fe3f76c0915c69b6d27c84e7b.
src/graphics/host_gpu/renderer/renderCompute.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-25 16:50 UTC · original · edited 2026-10-25 17:06 UTC
On
src/graphics/host_gpu/renderer/renderCompute.cppline 72 (outdated):Reject dispatches that also write storage images.
If a shader writes a registered metadata buffer and a storage image, the buffer checks can classify the dispatch as a metadata clear.
DispatchDirectthen returns without executing the storage-image write. Checkprogram.info.imagesfor writes before consuming the dispatch; otherwise, let the dispatch run normally.✅ Addressed in commit d576736
@MrBigBritches on GitHub · 2026-10-26 01:38 UTC · original
@coderabbitai resume
@coderabbitai[bot] on GitHub · 2026-10-26 01:38 UTC · original · edited 2026-10-26 01:45 UTC
✅ Action performed
Reviews resumed and review finished.
@coderabbitai[bot] on GitHub · 2026-10-26 01:45 UTC · original · reviewed
🧹 Nitpick comments: 1
f44b9f13-0d34-42e6-8bac-0b41a7d6e8deReviewing files that changed from the base of the PR and between 56005d2743db0957751801fb07ec925a8a031e25 and fa6905215296d727f0389acfc24abc1f60a37335.
src/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/renderCompute.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@ -1504,1 +1504,4 @@}// Keep the larger size, so binding a smaller image at the same base doesn't turn away// clears of a larger one that is still alive.metadata->second.size = std::max(metadata->second.size, desc.info.metadata.range.size);@coderabbitai[bot] on GitHub · 2026-10-27 23:33 UTC · original · edited 2026-10-27 23:42 UTC
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3059
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41511
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12375
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 28803
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5865
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11251
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4456
Track metadata sizes for each live depth binding.
When
FindImagereuses one cached image for a smaller compatible depth binding,FindDepthTargetreplacesimage.info.metadatabut retains the old maximum inm_surface_metas. A bounded write larger than the new range but no larger than the retained size can passClearMetaSurfaces, soTryConsumeComputeMetaClearmay consume the dispatch and discard that write.Retain the maximum while separate image IDs remain live, but recompute it when a cached image changes its metadata binding or is freed.
@ -1952,0 +1961,4 @@for (const auto& target: targets) {const auto found = m_surface_metas.find(target.address);const bool is_meta = found != m_surface_metas.end();if (!target.written) {@coderabbitai[bot] on GitHub · 2026-10-27 23:33 UTC · original · edited 2026-10-27 23:43 UTC
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7263
Reject read-only bindings that overlap a metadata range, not only ones at its base.
ClearMetaSurfaceschecks read-only targets only withfind(target.address). A read-only binding that starts inside a registered metadata range, but not at its base, is not rejected. If a dispatch reads that data and writes another registered surface, it can be consumed as a clear, and its data-dependent writes are dropped. The exact-base check is correct for written targets, which must be registered surfaces. Read-only targets need an overlap test against the full range they cover.🐛 Suggested fix
@coderabbitai[bot] on GitHub · 2026-10-27 23:33 UTC · original · reviewed
Actionable comments posted: 2
🔇 Additional comments: 1
e022ea55-ebb3-4e66-bbc4-61f63e7ca2a5Reviewing files that changed from the base of the PR and between fa6905215296d727f0389acfc24abc1f60a37335 and
4eae95dd14.src/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/renderCompute.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -1504,1 +1504,4 @@}// Keep the larger size, so binding a smaller image at the same base doesn't turn away// clears of a larger one that is still alive.metadata->second.size = std::max(metadata->second.size, desc.info.metadata.range.size);@MrBigBritches on GitHub · 2026-10-27 23:42 UTC · original
Intentional.
4eae95ddkeeps the largest registered size so a smaller binding at the same base can't turn away clears of a larger surface. Shrinking the entry when one cached image is rebound smaller needs size tracking for each live image, which is the same ownership rework as the "two depth images share an HTILE base" item in Known limitations. Octopath and Astro Bot showed no real clears relying on the slack, so I'm leaving it as a follow-up.@ -1504,1 +1504,4 @@}// Keep the larger size, so binding a smaller image at the same base doesn't turn away// clears of a larger one that is still alive.metadata->second.size = std::max(metadata->second.size, desc.info.metadata.range.size);@coderabbitai[bot] on GitHub · 2026-10-27 23:43 UTC · original
@MrBigBritches Understood. Retaining the maximum preserves clears for larger surfaces at the same HTILE base. Correct shrinking needs per-image ownership tracking, not a smaller-binding assignment.
I accept deferring that rework. The retained-size risk remains a known limitation, so this finding is deferred rather than fixed.
Would you like me to open a follow-up GitHub issue for the ownership tracking and rebind/free regression cases?
🧠 Learnings used
You are interacting with an AI system.
@ -1952,0 +1961,4 @@for (const auto& target: targets) {const auto found = m_surface_metas.find(target.address);const bool is_meta = found != m_surface_metas.end();if (!target.written) {@MrBigBritches on GitHub · 2026-10-27 23:43 UTC · original
Fair gap, but reads are already capped at 4 KiB of bounded constants. With stale entries surviving while their memory stays mapped (Known limitations), an overlap test would also reject real clears whose constants land in reused HTILE memory. I'll measure that before tightening it, and if I do, I'll use an ordered upper_bound lookup rather than a full scan under the lock.
@ -1952,0 +1961,4 @@for (const auto& target: targets) {const auto found = m_surface_metas.find(target.address);const bool is_meta = found != m_surface_metas.end();if (!target.written) {@coderabbitai[bot] on GitHub · 2026-10-27 23:43 UTC · original
@MrBigBritches Agreed. Measure the false-rejection risk before tightening this check. My suggested full scan did not account for stale HTILE entries rejecting valid constant-driven clears.
The 4 KiB bound limits reads, but it does not prove that those reads are constants. The classification gap remains open; your explanation supports deferring the proposed change, not treating the gap as fixed.
For measurement, distinguish reads from live HTILE metadata from constants in reused HTILE memory. That will help determine whether an overlap check improves classification without rejecting real clears.
🧠 Learnings used
You are interacting with an AI system.
@MrBigBritches on GitHub · 2026-10-28 00:09 UTC · original
Done in
6d3ad8f9: the classification test now uses AddMetaClearBuffer. The accepted unbounded-clear case was added in58f03f35(unbounded HTile clear consumed in ComputeMetaClearInputs)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.Merge
Merge the changes and update on Forgejo.