renderer: recreate a depth target that is larger than the cached image #1748

Open
github-bot wants to merge 3 commits from github-bot/gh-1748 into main AGit
Owner

@⁠0xcrstn on GitHub · 2026-10-20 03:54 UTC · original
0xcrstn:fix/ufc6-depth-target-extent → main · +188 −4 · 5 files · 3 commits · open

Game 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 in main.

Cause

I logged every depth-target bind whose render area is larger than the image it got:

  • A depth target described as 128x32 (D32_SFLOAT_S8_UINT) was bound to a 32x32 cache image at the same address. Same for the main fight depth target: described as 3248x1824, bound to a 3240x1824 image. All 33 undersized binds in that run were depth targets, path ResolveOverlap, same address, same format, same data size, smaller extent.
  • ResolveOverlap takes its equal-address branch when pitch and height match. Tiled depth pads the pitch, so a 32x32 and a 128x32 surface match there.
  • ResolveDepthOverlap then returns the cached image for a depth target unless depth, stencil, bytes per block, levels or layers differ. It never checks the extent.
  • AcquireRenderTargets sets the render area from the description, so the draw writes depth past the image.

Change

  1. ResolveDepthOverlap recreates 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.
  2. That recreate path did not initialize the new area: CopyImage marks 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.
  3. It also dropped stencil: Image::CopyImage copies 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 new CopyStencil associates the range with the replacement, uploads it from guest memory, and copies the cached stencil aspect over the old extent (Image::CopyImage gets 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 (InitializeImage returns early for samples > 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:
    • a 32x32 then 128x32 depth target binds a 128x32 image (fails on main: "a 128x32 depth target bound a 32x32 image");
    • the grown image keeps the cached depth in the old extent and the guest values outside it (without change 2, column 32 reads 0.0 instead of 0.5);
    • D32S8: stencil written on the GPU (raw transfer clear, as a draw: the association is not marked) survives, and the grown region comes from guest memory (without change 3, column 0 reads the guest 0x11 instead of 0x35).
      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):

  • Scripted runs (main-menu save, no input, cleared pipeline cache, 3-minute cap): one run reached the cap with no error. The other exited at 138 s with a guest-code write to address 0 (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 --redzone switch rewrites the faulting stores, including the one in this function. Two more runs with --redzone both reached the 3-minute cap with no error. Neither scripted run lost the device.
  • Play sessions (about 05:10-06:50, six sessions, two of them on a build without changes 2 and 3): main menu, select corner, fighter select and local fights. No session lost the device, no Aftermath dump was written, and the Windows System log has no nvlddmkm event after 03:14. Before this change the same path logged Xid 13 "3D WIDTH ZT Violation" at 02:55, 03:09 and 03:14, each with a device loss. The sessions ended normally or in separate, known CPU-side crashes (red zone, a freed cache slot, PthreadGetprio), each tracked separately.
  • Fighter select still shows occasional single-frame green/yellow flashes or a dark band in the 3D scene. They also appear on a build with only change 1 (changes 2 and 3 reverted), and in a logged run the grown-target recreate ran 5 times, with no visible change in the frames recorded around the one inside a capture window. I'm investigating these separately; I have not found a link to this change.

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

**@⁠0xcrstn** on GitHub · 2026-10-20 03:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1748) `0xcrstn:fix/ufc6-depth-target-extent` → `main` · +188 −4 · 5 files · 3 commits · open ## Game 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 in `main`. ## Cause I logged every depth-target bind whose render area is larger than the image it got: - A depth target described as 128x32 (D32_SFLOAT_S8_UINT) was bound to a 32x32 cache image at the same address. Same for the main fight depth target: described as 3248x1824, bound to a 3240x1824 image. All 33 undersized binds in that run were depth targets, path `ResolveOverlap`, same address, same format, same data size, smaller extent. - `ResolveOverlap` takes its equal-address branch when pitch and height match. Tiled depth pads the pitch, so a 32x32 and a 128x32 surface match there. - `ResolveDepthOverlap` then returns the cached image for a depth target unless depth, stencil, bytes per block, levels or layers differ. It never checks the extent. - `AcquireRenderTargets` sets the render area from the description, so the draw writes depth past the image. ## Change 1. `ResolveDepthOverlap` recreates 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. 2. That recreate path did not initialize the new area: `CopyImage` marks 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. 3. It also dropped stencil: `Image::CopyImage` copies 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 new `CopyStencil` associates the range with the replacement, uploads it from guest memory, and copies the cached stencil aspect over the old extent (`Image::CopyImage` gets 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 (`InitializeImage` returns early for `samples > 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: - a 32x32 then 128x32 depth target binds a 128x32 image (fails on `main`: "a 128x32 depth target bound a 32x32 image"); - the grown image keeps the cached depth in the old extent and the guest values outside it (without change 2, column 32 reads 0.0 instead of 0.5); - D32S8: stencil written on the GPU (raw transfer clear, as a draw: the association is not marked) survives, and the grown region comes from guest memory (without change 3, column 0 reads the guest 0x11 instead of 0x35). 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): - Scripted runs (main-menu save, no input, cleared pipeline cache, 3-minute cap): one run reached the cap with no error. The other exited at 138 s with a guest-code write to address 0 (`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 `--redzone` switch rewrites the faulting stores, including the one in this function. Two more runs with `--redzone` both reached the 3-minute cap with no error. Neither scripted run lost the device. - Play sessions (about 05:10-06:50, six sessions, two of them on a build without changes 2 and 3): main menu, select corner, fighter select and local fights. No session lost the device, no Aftermath dump was written, and the Windows System log has no nvlddmkm event after 03:14. Before this change the same path logged Xid 13 "3D WIDTH ZT Violation" at 02:55, 03:09 and 03:14, each with a device loss. The sessions ended normally or in separate, known CPU-side crashes (red zone, a freed cache slot, `PthreadGetprio`), each tracked separately. - Fighter select still shows occasional single-frame green/yellow flashes or a dark band in the 3D scene. They also appear on a build with only change 1 (changes 2 and 3 reverted), and in a logged run the grown-target recreate ran 5 times, with no visible change in the frames recorded around the one inside a capture window. I'm investigating these separately; I have not found a link to this change. 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](https://claude.com/claude-code)
EA SPORTS UFC 6 (PPSA23566) loses the device on fighter select and in
fights. The NVIDIA driver reports "3D WIDTH ZT Violation" (Xid 13) and
Kyty exits in masterSemaphore.cpp. A depth target described as 128x32
(D32_SFLOAT_S8_UINT) was bound to a 32x32 cache image at the same
address, and the main fight depth target (3248x1824) to a 3240x1824
image. AcquireRenderTargets sets the render area from the description,
so depth was written past the image.

ResolveOverlap takes its equal-address branch when the pitch and height
match. Tiled depth pads the pitch, so a 32x32 and a 128x32 surface with
the same data size match there, and ResolveDepthOverlap returned the
cached image for a depth target unless depth, stencil, bytes per block,
levels or layers differed. It now also recreates when the requested
width or height exceeds the cached image; the existing recreate path
inserts the requested image and copies the cached contents into it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When ResolveDepthOverlap recreates a depth target because the requested
extent is larger than the cached image (EA SPORTS UFC 6, PPSA23566:
32x32 -> 128x32, 3240x1824 -> 3248x1824), it inserts the replacement
and copies the cached image into it. TextureCache::CopyImage marks the
destination current (PrepareImageCopy -> RefreshComplete) without
uploading it, so the part of the replacement outside the cached extent
was never filled from guest memory.

Refresh the replacement from guest memory before the copy when the
target grew. The copy then overlays the cached GPU contents on the old
extent.

Test: CheckUnifiedTextureCacheFlow (--htile-clear-only) writes 0.25 to
columns 0..31 and 0.5 to columns 32..127 of a 128-pitch depth surface,
clears the 32x32 image to 0.75, then requests 128x32. Without the fix
column 32 reads 0.0; with it, 0.75 in the old extent and 0.5 outside.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Draws write stencil into the depth image; the stencil association only
records which guest range it belongs to. When ResolveDepthOverlap
recreates a D32S8 depth target for a larger extent (EA SPORTS UFC 6,
PPSA23566: 32x32 -> 128x32 D32_SFLOAT_S8_UINT), Image::CopyImage copies
only the depth aspect and DeleteImage frees the cached image's stencil
associations. The replacement's first FindDepthTarget then created a new
association and uploaded the stale guest stencil over it.

For a same-format recreate with the same stencil range, associate the
stencil range with the replacement, upload it from guest memory (for the
grown region), and copy the cached stencil aspect over the old extent.
Image::CopyImage takes an opt-in stencil flag; its default is unchanged.
A GPU-modified association stays GPU-modified.

Test: CheckUnifiedTextureCacheFlow (--htile-clear-only) fills the guest
stencil with 0x11, binds a 32x32 D32S8 target, clears its stencil to
0x35 with a raw transfer clear (as a draw would, without marking the
association), then binds 128x32. Without the fix column 0 reads 0x11;
with it, 0x35 in the old extent and 0x11 outside.

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

@⁠coderabbitai[bot] on GitHub · 2026-10-20 03:58 UTC · original · edited 2026-10-20 04:05 UTC

Review in Change Stack →

📝 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::CopyImage supports 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, claxten10

Priority: ⬆️ High

Change: Bug fix

Merge Risk: 🟡 Moderate · up to 8d930

Growing 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: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive 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: … 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 summarizes the main change: recreating a depth target when its requested extent exceeds the cached image.
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.
Description check Passed The pull request description directly explains the depth-target resolution changes, stencil preservation, affected UFC 6 device-loss issue, and related tests.
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.

  • 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 03:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1748#issuecomment-6283038231) · edited 2026-10-20 04:05 UTC <!-- 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/1748?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 --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> 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::CopyImage` supports 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`, `claxten10` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬆️ High <!-- change_assessment_commit:"8d9305adc19ca9954e719d02ba73b0a34b67441f" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>🟡 Moderate</strong> · up to <code>8d930</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🟡 Moderate** · up to `8d930` --> <!-- final_review_risk_coverage:{"sourceCommitId":"8d9305adc19ca9954e719d02ba73b0a34b67441f","coveredCommitId":"8d9305adc19ca9954e719d02ba73b0a34b67441f","kind":"reviewed"} --> Growing 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. <!-- 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 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: … | 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 summarizes the main change: recreating a depth target when its requested extent exceeds the cached image. | | 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. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The pull request description directly explains the depth-target resolution changes, stencil preservation, affected UFC 6 device-loss issue, and related tests. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **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. </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=1748)! 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 -->
@ -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);
Author
Owner

@⁠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:

set -eu
printf '%s\n' '--- diff base..head ---'
git diff --find-renames 1a053f9e13405bf34171a47aae9f2b9a6e7afd7d 8d9305adc19ca9954e719d02ba73b0a34b67441f -- src/graphics/host_gpu/renderer/cache/textureCache.cpp
printf '%s\n' '--- support predicate references ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'IsSupportedDepthTargetFormat' -e 'InitializeImage' -e 'RefreshImage' -e 'CopyStencil' src/graphics/host_gpu/renderer
printf '%s\n' '--- relevant source ranges ---'
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '620,780p'

Repository: KytyPS5/KytyPS5

Length of output: 15535


🏁 Script executed:

set -eu
git diff --find-renames 1a053f9e13405bf34171a47aae9f2b9a6e7afd7d 8d9305adc19ca9954e719d02ba73b0a34b67441f -- src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F --glob '*.{cpp,h,hpp}' -e 'IsSupportedDepthTargetFormat' -e 'InitializeImage' -e 'RefreshImage' -e 'CopyStencil' src/graphics/host_gpu/renderer
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '620,780p'

Repository: KytyPS5/KytyPS5

Length of output: 15443


🏁 Script executed:

git diff --find-renames 1a053f9e13405bf34171a47aae9f2b9a6e7afd7d 8d9305adc19ca9954e719d02ba73b0a34b67441f -- src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F --glob '*.{cpp,h,hpp}' -e 'IsSupportedDepthTargetFormat' -e 'InitializeImage' -e 'RefreshImage' -e 'CopyStencil' src/graphics/host_gpu/renderer
nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '620,780p'

Repository: KytyPS5/KytyPS5

Length of output: 15443


🏁 Script executed:

set -eu
git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/image/imageInfo.h | nl -ba | sed -n '250,290p'
printf '%s\n' '--- depth-target entrypoint ---'
git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '430,490p'
printf '%s\n' '--- initialize and refresh ---'
git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '1025,1180p'

Repository: KytyPS5/KytyPS5

Length of output: 11954


🏁 Script executed:

set -eu
printf '%s\n' '--- CopyImage ---'
git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '555,625p'
printf '%s\n' '--- ResolveDepthOverlap callers ---'
git grep -n -F 'ResolveDepthOverlap(' 8d9305adc19ca9954e719d02ba73b0a34b67441f -- src/graphics/host_gpu/renderer
printf '%s\n' '--- insertion and binding flow ---'
git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '1300,1480p'

Repository: KytyPS5/KytyPS5

Length of output: 11572


🏁 Script executed:

set -eu
git grep -n -E '(^|[[:space:]])(void|bool|.*)Image::CopyImage|CopyImage\(' 8d9305adc19ca9954e719d02ba73b0a34b67441f -- src/graphics/host_gpu/renderer | head -80

Repository: KytyPS5/KytyPS5

Length of output: 1501


🏁 Script executed:

set -eu
git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/image/image.cpp | nl -ba | sed -n '325,410p'

Repository: KytyPS5/KytyPS5

Length of output: 5255


Initialize the grown region for supported multisampled depth targets.

IsSupportedDepthTargetFormat does not restrict the sample count, so multisampled depth targets can reach this path. RefreshImage(replacement_id) cannot initialize a multisampled replacement because InitializeImage returns before uploading guest memory. Image::CopyImage copies the minimum source and destination width and height, so the grown depth region remains uninitialized. CopyStencil has the same gap because RefreshImage skips 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](https://github.com/KytyPS5/KytyPS5/pull/1748#discussion_r4321323545) · edited 2026-10-20 04:05 UTC **🎯 Functional Correctness** | **🟠 Major** | **🏗️ Heavy lift** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash set -eu printf '%s\n' '--- diff base..head ---' git diff --find-renames 1a053f9e13405bf34171a47aae9f2b9a6e7afd7d 8d9305adc19ca9954e719d02ba73b0a34b67441f -- src/graphics/host_gpu/renderer/cache/textureCache.cpp printf '%s\n' '--- support predicate references ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'IsSupportedDepthTargetFormat' -e 'InitializeImage' -e 'RefreshImage' -e 'CopyStencil' src/graphics/host_gpu/renderer printf '%s\n' '--- relevant source ranges ---' nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '620,780p' ``` Repository: KytyPS5/KytyPS5 Length of output: 15535 --- 🏁 Script executed: ```bash set -eu git diff --find-renames 1a053f9e13405bf34171a47aae9f2b9a6e7afd7d 8d9305adc19ca9954e719d02ba73b0a34b67441f -- src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F --glob '*.{cpp,h,hpp}' -e 'IsSupportedDepthTargetFormat' -e 'InitializeImage' -e 'RefreshImage' -e 'CopyStencil' src/graphics/host_gpu/renderer nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '620,780p' ``` Repository: KytyPS5/KytyPS5 Length of output: 15443 --- 🏁 Script executed: ```bash git diff --find-renames 1a053f9e13405bf34171a47aae9f2b9a6e7afd7d 8d9305adc19ca9954e719d02ba73b0a34b67441f -- src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F --glob '*.{cpp,h,hpp}' -e 'IsSupportedDepthTargetFormat' -e 'InitializeImage' -e 'RefreshImage' -e 'CopyStencil' src/graphics/host_gpu/renderer nl -ba src/graphics/host_gpu/renderer/cache/textureCache.cpp | sed -n '620,780p' ``` Repository: KytyPS5/KytyPS5 Length of output: 15443 --- 🏁 Script executed: ```bash set -eu git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/image/imageInfo.h | nl -ba | sed -n '250,290p' printf '%s\n' '--- depth-target entrypoint ---' git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '430,490p' printf '%s\n' '--- initialize and refresh ---' git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '1025,1180p' ``` Repository: KytyPS5/KytyPS5 Length of output: 11954 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- CopyImage ---' git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '555,625p' printf '%s\n' '--- ResolveDepthOverlap callers ---' git grep -n -F 'ResolveDepthOverlap(' 8d9305adc19ca9954e719d02ba73b0a34b67441f -- src/graphics/host_gpu/renderer printf '%s\n' '--- insertion and binding flow ---' git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/cache/textureCache.cpp | nl -ba | sed -n '1300,1480p' ``` Repository: KytyPS5/KytyPS5 Length of output: 11572 --- 🏁 Script executed: ```bash set -eu git grep -n -E '(^|[[:space:]])(void|bool|.*)Image::CopyImage|CopyImage\(' 8d9305adc19ca9954e719d02ba73b0a34b67441f -- src/graphics/host_gpu/renderer | head -80 ``` Repository: KytyPS5/KytyPS5 Length of output: 1501 --- 🏁 Script executed: ```bash set -eu git show 8d9305adc19ca9954e719d02ba73b0a34b67441f:src/graphics/host_gpu/renderer/image/image.cpp | nl -ba | sed -n '325,410p' ``` Repository: KytyPS5/KytyPS5 Length of output: 5255 --- </details> **Initialize the grown region for supported multisampled depth targets.** `IsSupportedDepthTargetFormat` does not restrict the sample count, so multisampled depth targets can reach this path. `RefreshImage(replacement_id)` cannot initialize a multisampled replacement because `InitializeImage` returns before uploading guest memory. `Image::CopyImage` copies the minimum source and destination width and height, so the grown depth region remains uninitialized. `CopyStencil` has the same gap because `RefreshImage` skips multisampled stencil associations. Initialize multisampled depth and stencil replacements through a supported multisample path before copying the cached extent. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:f14b43899a04d8c8d98ba159 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-20 03:58 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dacdaa7f-bcae-4c94-b233-ecfa31ede1cf
📥 Commits

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

📒 Files selected for processing: 5
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
  • src/graphics/host_gpu/renderer/image/image.cpp
  • src/graphics/host_gpu/renderer/image/image.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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-20 03:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1748#pullrequestreview-5580601799) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `dacdaa7f-bcae-4c94-b233-ecfa31ede1cf` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 1a053f9e13405bf34171a47aae9f2b9a6e7afd7d and 8d9305adc19ca9954e719d02ba73b0a34b67441f. </details> <details> <summary>📒 Files selected for processing: 5</summary> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.h` * `src/graphics/host_gpu/renderer/image/image.cpp` * `src/graphics/host_gpu/renderer/image/image.h` * `tests/ShaderRecompilerComputeTests.cpp` </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. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=8f3aa2f9-bca6-4be9-aadb-211d2a6decba attempt=6d534255-fd8a-471b-bc99-5381c38ed596 batch=1/1 -->
@ -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);
Author
Owner

@⁠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 in InitializeImage, which returns early for samples > 1 (:1051). CopyImage then copies only the cached extent, so the grown region of a multisampled replacement is left undefined.
  • In CopyStencil, RefreshImage on 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. UploadImage has 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.

**@⁠0xcrstn** on GitHub · 2026-10-20 04:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1748#discussion_r4321353166) @⁠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 in `InitializeImage`, which returns early for `samples > 1` (`:1051`). `CopyImage` then copies only the cached extent, so the grown region of a multisampled replacement is left undefined. - In `CopyStencil`, `RefreshImage` on 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. `UploadImage` has 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);
Author
Owner

@⁠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/911 single-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
Learnt from: 0xcrstn
Repo: KytyPS5/KytyPS5 PR: 1748
File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:735-735
Timestamp: 2026-10-20T04:05:31.251Z
Learning: In KytyPS5/KytyPS5, TextureCache::InitializeImage in src/graphics/host_gpu/renderer/cache/textureCache.cpp skips guest-memory uploads for multisampled images, including fresh images. TextureCache::RefreshImage also skips stencil associations whose depth owner is multisampled. Treat missing guest-memory initialization for multisampled depth and stencil images as an existing limitation, not as a regression caused by depth-target growth.
Learnt from: 0xcrstn
Repo: KytyPS5/KytyPS5 PR: 1748
File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:735-735
Timestamp: 2026-10-20T04:05:31.251Z
Learning: KytyPS5/KytyPS5 has no repository-wide docstring convention. The C++ files src/graphics/host_gpu/renderer/cache/textureCache.cpp, src/graphics/host_gpu/renderer/cache/textureCache.h, src/graphics/host_gpu/renderer/image/image.cpp, and src/graphics/host_gpu/renderer/image/image.h use no docstrings. New functions may follow the surrounding documentation style.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-20 04:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1748#discussion_r4321356124) @⁠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/911` single-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? --- <details> <summary>✏️ Learnings added</summary> <blockquote> ``` Learnt from: 0xcrstn Repo: KytyPS5/KytyPS5 PR: 1748 File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:735-735 Timestamp: 2026-10-20T04:05:31.251Z Learning: In KytyPS5/KytyPS5, TextureCache::InitializeImage in src/graphics/host_gpu/renderer/cache/textureCache.cpp skips guest-memory uploads for multisampled images, including fresh images. TextureCache::RefreshImage also skips stencil associations whose depth owner is multisampled. Treat missing guest-memory initialization for multisampled depth and stencil images as an existing limitation, not as a regression caused by depth-target growth. ``` ``` Learnt from: 0xcrstn Repo: KytyPS5/KytyPS5 PR: 1748 File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:735-735 Timestamp: 2026-10-20T04:05:31.251Z Learning: KytyPS5/KytyPS5 has no repository-wide docstring convention. The C++ files src/graphics/host_gpu/renderer/cache/textureCache.cpp, src/graphics/host_gpu/renderer/cache/textureCache.h, src/graphics/host_gpu/renderer/image/image.cpp, and src/graphics/host_gpu/renderer/image/image.h use no docstrings. New functions may follow the surrounding documentation style. ``` </blockquote> > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> <!-- <review_comment_withdrawn> --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
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
  • src/graphics/host_gpu/renderer/image/image.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/1748/head:github-bot/gh-1748'
git switch 'github-bot/gh-1748'

Merge

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