renderer: recreate a depth target that is larger than the cached image #1748
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!1748
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1748"
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?
@0xcrstn on GitHub · 2026-10-20 03:54 UTC · original
0xcrstn:fix/ufc6-depth-target-extent→main· +188 −4 · 5 files · 3 commits · openGame and problem
EA SPORTS UFC 6 (PPSA23566, 01.004.000), Windows 11, RTX 5090 (driver 617.42). On fighter select and in fights the device is lost and Kyty exits in
masterSemaphore.cpp. The NVIDIA driver logs Xid 13, "Graphics Exception on GPC 9: 3D WIDTH ZT Violation", which means depth was written past the width of the depth attachment. The game reaches this point with #1738 applied; the bug is inmain.Cause
I logged every depth-target bind whose render area is larger than the image it got:
ResolveOverlap, same address, same format, same data size, smaller extent.ResolveOverlaptakes its equal-address branch when pitch and height match. Tiled depth pads the pitch, so a 32x32 and a 128x32 surface match there.ResolveDepthOverlapthen returns the cached image for a depth target unless depth, stencil, bytes per block, levels or layers differ. It never checks the extent.AcquireRenderTargetssets the render area from the description, so the draw writes depth past the image.Change
ResolveDepthOverlaprecreates a depth target whose requested width or height is larger than the cached image. The existing recreate path inserts the requested image and copies the cached contents into it.CopyImagemarks the destination current (PrepareImageCopy) after copying only the cached extent. When the target grew, the replacement is now refreshed from guest memory before the copy.Image::CopyImagecopies only depth, and deleting the cached image frees its stencil associations, so the replacement's first bind uploaded the guest stencil over what draws had written. For a same-format recreate with the same stencil range, the newCopyStencilassociates the range with the replacement, uploads it from guest memory, and copies the cached stencil aspect over the old extent (Image::CopyImagegets an opt-in stencil flag; its default is unchanged).Pending HTile clears across a recreate are handled in #1743; this PR does not touch HTile state.
Not changed: a larger depth texture request at the same address still returns the smaller image. That gives wrong sampling past the old extent but no out-of-bounds write, and I have not seen it matter in UFC 6.
Not changed: a multisampled depth target that grows keeps the cached contents in the old extent, but its grown region (depth and stencil) is not initialized from guest memory, because Kyty does not upload multisampled images from guest memory at all (
InitializeImagereturns early forsamples > 1). UFC 6 does not hit this (all logged depth recreates are single-sample).Testing
Unit tests:
CheckUnifiedTextureCacheFlow(--htile-clear-only) gets three cases at a 128-pitch depth surface:main: "a 128x32 depth target bound a 32x32 image");Each case was run before its fix and failed as described.
shader_recompiler_compute_tests: all cases pass (Windows, clang-cl, RTX 5090), on the current base.UFC 6, on integration builds of
main+ #1738 + #1743 + this branch (all three commits unless noted):runtimeLinker.cpp:715). That crash is a CPU-side red-zone issue unrelated to this change: in the crashes of this class I traced, the faulting thread's previous handled fault was a GPU write-tracking fault in the same function at the same stack pointer, and Kyty's existing opt-in--redzoneswitch rewrites the faulting stores, including the one in this function. Two more runs with--redzoneboth reached the 3-minute cap with no error. Neither scripted run lost the device.PthreadGetprio), each tracked separately.Reviews: CodeRabbit (0 findings), Codex (0 findings) and Claude review (5 minor findings: no code change, reasons recorded) ran on these three commits plus a fourth, HTile-related commit that was dropped in favour of #1743; the three commits are unchanged since (range-diff identical).
AI use
Claude Code (an AI coding agent) did the investigation (diagnostic logging of depth binds and cache decisions, the driver's event log, Aftermath dumps), wrote the changes and the tests, ran the tests, the scripted game runs and the CodeRabbit, Codex and Claude reviews, and drafted this description. Changes 2 and 3 address findings from the Codex review of change 1. I directed the work, reviewed the evidence and the change, and played the game sessions on the integration builds.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-20 03:58 UTC · original · edited 2026-10-20 04:05 UTC
📝 Walkthrough
The cache now recreates a depth target when the requested width or height exceeds the cached extent. It refreshes the replacement before copying cached depth data. Compatible replacements also copy stencil data and preserve GPU-write tracking.
Image::CopyImagesupports stencil-only copies while retaining non-stencil copying by default. New tests cover larger-target recreation and depth and stencil preservation across original and expanded regions.Suggested reviewers:
nmzik,claxten10Priority: ⬆️ High
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
8d930Growing a multisampled depth target can leave the newly exposed region with undefined contents, which may cause rendering artifacts. The single-sample fix for the reported device loss looks sound. Resolve or explicitly accept the multisampled gap before merging.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 4 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.@ -703,0 +732,4 @@if (grown_depth_target) {// The copy covers only the cached extent and marks the replacement current, so// upload the rest from guest memory first.RefreshImage(replacement_id);@coderabbitai[bot] on GitHub · 2026-10-20 03:58 UTC · original · edited 2026-10-20 04:05 UTC
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 15535
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 15443
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 15443
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11954
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11572
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 1501
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5255
Initialize the grown region for supported multisampled depth targets.
IsSupportedDepthTargetFormatdoes not restrict the sample count, so multisampled depth targets can reach this path.RefreshImage(replacement_id)cannot initialize a multisampled replacement becauseInitializeImagereturns before uploading guest memory.Image::CopyImagecopies the minimum source and destination width and height, so the grown depth region remains uninitialized.CopyStencilhas the same gap becauseRefreshImageskips multisampled stencil associations.Initialize multisampled depth and stencil replacements through a supported multisample path before copying the cached extent.
@coderabbitai[bot] on GitHub · 2026-10-20 03:58 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
dacdaa7f-bcae-4c94-b233-ecfa31ede1cf📥 Commits
Reviewing files that changed from the base of the PR and between
1a053f9e13and8d9305adc1.📒 Files selected for processing: 5
src/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hsrc/graphics/host_gpu/renderer/image/image.cppsrc/graphics/host_gpu/renderer/image/image.htests/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.
@ -703,0 +732,4 @@if (grown_depth_target) {// The copy covers only the cached extent and marks the replacement current, so// upload the rest from guest memory first.RefreshImage(replacement_id);@0xcrstn on GitHub · 2026-10-20 04:05 UTC · original
@coderabbitai Thanks, the multisampled gap is real. I checked it against the code at
8d9305ad:IsSupportedDepthTargetFormat(image/imageInfo.h:271) checks only format and stencil, so a multisampled depth target can take the grown recreate (textureCache.cpp:685).RefreshImage(replacement_id)(:735) ends inInitializeImage, which returns early forsamples > 1(:1051).CopyImagethen copies only the cached extent, so the grown region of a multisampled replacement is left undefined.CopyStencil,RefreshImageon the stencil association returns early when the depth image is multisampled (:1149), so the grown stencil region is undefined in the same way.This is the state every multisampled depth image is already in, not something this PR introduces.
UploadImagehas a single caller,InitializeImage(:1061), so Kyty never initializes a multisampled image from guest memory anywhere, including a fresh one. Without this PR the grown request reuses the smaller cached image and the draw writes past it. For single-sample targets that is the Xid 13 "3D WIDTH ZT Violation" device loss this PR fixes; I expect the same for multisampled targets, but I have not reproduced that.UFC 6 does not reach this path with MSAA: a diagnostic run that logged sample counts recorded 911 of 911 depth recreates on fighter select and in menus, the grown ones included, as
samples=1->1. I am not aware of a game that hits it.So I'd rather keep this PR to the out-of-bounds fix and accept the gap explicitly. A real multisampled initialization path would have to decode the guest's multisampled depth layout into each sample. I have no game to test that with, so it doesn't belong in this PR. I've added the limitation to the PR description.
On the docstring-coverage check: the files this PR touches (
textureCache.cpp/.h,image.cpp/.h) have no docstrings, and the repository has no docstring convention, so the new functions follow the surrounding code.The analysis and this reply were prepared by Claude Code (an AI agent) at my direction; I reviewed them.
@ -703,0 +732,4 @@if (grown_depth_target) {// The copy covers only the cached extent and marks the replacement current, so// upload the rest from guest memory first.RefreshImage(replacement_id);@coderabbitai[bot] on GitHub · 2026-10-20 04:05 UTC · original
@0xcrstn Thanks for the clarification. I withdraw the request to add multisampled initialization to this PR. The gap is an existing limitation, not a regression introduced by this change. The larger attachment still fixes the extent mismatch.
Your reported
911/911single-sample recreates also support keeping the UFC 6 fix separate from multisampled initialization. That run does not establish behavior for multisampled targets.The new functions follow the surrounding documentation style. A docstring-coverage check alone does not justify introducing a new convention here.
Would you like me to open a follow-up issue for multisampled depth and stencil initialization?
✏️ Learnings added
✅ Review thread resolved.
You are interacting with an AI system.
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.