graphics: keep layered depth stencil and HTile ranges for partial views #927

Closed
github-bot wants to merge 1 commit from gh-pr/927/head into gh-pr/927/base
Owner

@⁠TheCruZ on GitHub · 2026-09-29 21:21 UTC · original
pr/layered-depth-ranges → main · +27 −4 · 1 files · 1 commits · closed without merging

Summary

Fixes the emulator exiting with TextureCache: invalid depth upload when Grand Theft Auto V (PPSA04263) enters Story mode.

Problem

The game renders into slice 0 of a six-layer depth/stencil shadow cube. A depth target view that covers only the first slices of a cached layered image describes its stencil and HTile planes only up to its last slice.

FindDepthTarget replaced the cached image's ranges with that shorter range, so the stencil association covered one slice of a six-layer image and the next refresh failed the depth upload check.

Change

This change scales both ranges to the cached image's layer count. It applies only when the view has fewer layers than the cached image, starts at the same address, and the range size is a multiple of the view's layer count; otherwise the range is kept as before.

The invalid depth upload error now also prints the rejected plane geometry, to make similar reports easier to diagnose.

Before After
image image

Testing

  • Grand Theft Auto V (PPSA04263): Game loads into prologue/in-game.
  • Tested on Windows 11 with AMD Ryzen 5900x and RTX 3090.

AI usage

AI (Claude Opus 5.5) was used to investigate the issue and to implement the change. I reviewed the code, understand it, tested it as described above, and wrote this description myself, in general fully tested the game while doing few missions and playing in-game with my GTA V fork, i will be bringing PRs here after test them enough.

**@⁠TheCruZ** on GitHub · 2026-09-29 21:21 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/927) `pr/layered-depth-ranges` → `main` · +27 −4 · 1 files · 1 commits · closed without merging ## Summary Fixes the emulator exiting with `TextureCache: invalid depth upload` when Grand Theft Auto V (PPSA04263) enters Story mode. ## Problem The game renders into slice 0 of a six-layer depth/stencil shadow cube. A depth target view that covers only the first slices of a cached layered image describes its stencil and HTile planes only up to its last slice. `FindDepthTarget` replaced the cached image's ranges with that shorter range, so the stencil association covered one slice of a six-layer image and the next refresh failed the depth upload check. ## Change This change scales both ranges to the cached image's layer count. It applies only when the view has fewer layers than the cached image, starts at the same address, and the range size is a multiple of the view's layer count; otherwise the range is kept as before. The `invalid depth upload` error now also prints the rejected plane geometry, to make similar reports easier to diagnose. | **Before** | **After** | :-------------------------:|:-------------------------: <img width="1103" height="149" alt="image" src="https://github.com/user-attachments/assets/aef53c91-dd14-48af-ba6a-bc8e33187eca" /> | <img width="1286" height="763" alt="image" src="https://github.com/user-attachments/assets/cef0bc1b-f520-4a54-a6a6-2803829e1ef0" /> ## Testing - Grand Theft Auto V (PPSA04263): Game loads into prologue/in-game. - Tested on Windows 11 with AMD Ryzen 5900x and RTX 3090. ## AI usage AI (Claude Opus 5.5) was used to investigate the issue and to implement the change. I reviewed the code, understand it, tested it as described above, and wrote this description myself, in general fully tested the game while doing few missions and playing in-game with my [GTA V fork](https://github.com/TheCruZ/KytyPS5-GTA), i will be bringing PRs here after test them enough.
A depth target view that covers only the first slices of a cached layered
image (GTA V, PPSA04263, draws slice 0 of a six-layer shadow cube)
describes its stencil and HTile planes up to its last slice.
FindDepthTarget replaced the image's ranges with that shorter range, so
the stencil association covered one slice of a six-layer image and the
next refresh failed with "invalid depth upload". Scale both ranges to the
cached image's layer count.

Report the rejected plane geometry in the invalid depth upload error.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:37:03 +00:00
github-bot closed this pull request 2026-11-26 09:37:03 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-29 21:30 UTC · original · edited 2026-09-29 21:32 UTC

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: ba62629b-9a5e-45da-b88a-85d67d4237c0

📥 Commits

Reviewing files that changed from the base of the PR and between 05057c9441 and 4fc3e315c3.

📒 Files selected for processing (1)
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp

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


📝 Walkthrough

Walkthrough

Depth-upload validation now reports image and backing sample details when its existing failure condition is met. FindDepthTarget can scale matching stencil and metadata ranges to the cached image’s layer count under the specified range-size condition. Stencil association uses the stored scaled range.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 4fc3e

The range scaling reconstructs the cached backing range, and the diagnostic change does not alter when uploads fail. No concrete merge-blocking risk was identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 4fc3e

The change is confined to depth-target handling in the renderer. The reviewed paths do not show a new external entrypoint or a demonstrated security boundary bypass. Validation of the expanded ranges is not equally explicit for both planes, so some uncertainty remains.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected exposure is guest-controlled depth state processed within the emulator’s graphics renderer and texture cache, rather than a newly exposed service interface. An invalid stencil association reaches the renderer’s fatal-exit path.

Trust Boundaries and Controls

  • observed — The expanded stencil range is checked against guest-address bounds before association. The changed path does not explicitly revalidate the expanded HTile range; the inspected downstream HTile clear-state operations key on its unchanged address and view slice rather than its size.

Resilience and Maintainability Implications

  • observed — Depth lookup serializes its range update and stencil association with a cache lock. Repeated association searches for an exact guest range and depth extent; dependent stencil images are removed when their depth image is deleted.

Hardening Proposals

  • proposed — Check multiplication overflow and guest-range validity for both scaled planes before storing them. This would make the post-normalization invariant explicit; the inspected paths do not establish an exploitable metadata-size consumer.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving layered depth/stencil and HTile ranges for partial views.
Description check ✅ Passed The description directly explains the GTA V depth-upload failure, the partial-view range issue, the range-scaling fix, diagnostic logging, and testing performed.

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-09-29 21:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/927#issuecomment-5899323653) · edited 2026-09-29 21:32 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/927?cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `ba62629b-9a5e-45da-b88a-85d67d4237c0` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 05057c9441dbf3972d49f9143b90213a43a01a00 and 4fc3e315c3371f337df390e73e5154ffbf28b6ff. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough Depth-upload validation now reports image and backing sample details when its existing failure condition is met. `FindDepthTarget` can scale matching stencil and metadata ranges to the cached image’s layer count under the specified range-size condition. Stencil association uses the stored scaled range. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"4fc3e315c3371f337df390e73e5154ffbf28b6ff" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `4fc3e` <!-- final_review_risk_coverage:{"sourceCommitId":"4fc3e315c3371f337df390e73e5154ffbf28b6ff","coveredCommitId":"4fc3e315c3371f337df390e73e5154ffbf28b6ff","kind":"reviewed"} --> The range scaling reconstructs the cached backing range, and the diagnostic change does not alter when uploads fail. No concrete merge-blocking risk was identified. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `4fc3e` The change is confined to depth-target handling in the renderer. The reviewed paths do not show a new external entrypoint or a demonstrated security boundary bypass. Validation of the expanded ranges is not equally explicit for both planes, so some uncertainty remains. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — The inspected exposure is guest-controlled depth state processed within the emulator’s graphics renderer and texture cache, rather than a newly exposed service interface. An invalid stencil association reaches the renderer’s fatal-exit path. **Trust Boundaries and Controls** - _observed_ — The expanded stencil range is checked against guest-address bounds before association. The changed path does not explicitly revalidate the expanded HTile range; the inspected downstream HTile clear-state operations key on its unchanged address and view slice rather than its size. **Resilience and Maintainability Implications** - _observed_ — Depth lookup serializes its range update and stencil association with a cache lock. Repeated association searches for an exact guest range and depth extent; dependent stencil images are removed when their depth image is deleted. **Hardening Proposals** - _proposed_ — Check multiplication overflow and guest-range validity for both scaled planes before storing them. This would make the post-normalization invariant explicit; the inspected paths do not establish an exploitable metadata-size consumer. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 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. | | Title check | ✅ Passed | The title clearly and concisely describes the main change: preserving layered depth/stencil and HTile ranges for partial views. | | Description check | ✅ Passed | The description directly explains the GTA V depth-upload failure, the partial-view range issue, the range-scaling fix, diagnostic logging, and testing performed. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=927)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [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) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠TheCruZ on GitHub · 2026-10-05 16:33 UTC · original

fixed by github.com/KytyPS5/KytyPS5@068d7621db

**@⁠TheCruZ** on GitHub · 2026-10-05 16:33 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/927#issuecomment-5998728256) fixed by https://github.com/KytyPS5/KytyPS5/commit/068d7621dba9424c710214f727d274783169ee3b

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.