gpu: report bound textures in GET_LOD_STATS mip statistics (KYTY_LOD_STATS=1) #1631

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

@⁠devklex on GitHub · 2026-10-18 04:21 UTC · original
devklex:gpu/lod-stats-bound-textures → main · +228 −6 · 7 files · 1 commits · closed without merging

Problem

PS5 texture descriptors can turn on the texture units' mip statistics. MIP_STATS_CNT_EN (word 5 bit 25) enables counting, and MIP_STATS_CNT_ID (word 6 bits 0–7) selects one of 256 counters; Kyty already decodes both (ShaderTextureResource::MipStatsCntEn/MipStatsCntId). GET_LOD_STATS (sceAgcDcbGetLodStats) writes the counters to memory, and REPORT_AND_RESET/FORCE_RESET clear them. Astro Bot reads the block like this: a 64-byte header whose first dword must be nonzero, then one u64 per counter. Bits 56–59 hold the finest mip sampled (15 = not sampled), and bits 0–23 are nonzero once the texture was used.

CpOpGetLodStats (commented "Hack?") answers every report with header 1 and all-zero counters. Astro Bot reads a zero counter as "sampled at mip 0", so every texture looks needed at full resolution.

Astro Bot streams texture mips by these reports. It turns counting on for one group of 256 textures per frame and keeps a texture's top mips while the reports say they're sampled. With these answers it keeps every texture it has loaded at full resolution. Its 4.5 GiB texture pool sits at its 90% budget and drops and reloads the same texture several times a second. After New Game the level load waits for the streamer to go idle, so it can stall in the warp tunnel. 6 of my 31 scripted runs before this change stalled there (3 of the last 5), and one of those ended by itself after about 8 minutes. Possibly related: the loading-tunnel stalls in #745.

Change

With KYTY_LOD_STATS=1 (new src/graphics/guest_gpu/mipStats.*), RenderExecutor::ResolveTexture notes the counter of every non-storage texture a draw or dispatch binds with counting enabled. GET_LOD_STATS reports those counters as sampled at mip 0 and all the others as not sampled, and resets them on REPORT_AND_RESET or FORCE_RESET. Without the variable nothing changes.

This is an approximation. Kyty doesn't see individual samples, so a texture that is drawn still asks for full resolution even when it's small on screen or hidden. Textures that nothing draws now age out, as on hardware. A faithful version would compute the LOD in the recompiled shaders; this one costs one bit per binding.

It's off by default because it changes what every game that reads these counters sees. I used an environment variable to keep the change small, and I can turn it into an option like --support-zmask if you prefer.

Testing

  • New test mip_stats (report format, counters cleared only by a reset, short buffers), added to the Windows, Linux and macOS CI jobs. It's plain C++ with no platform code. I've only built it on Windows.
  • This branch, Windows 11, clang-cl 20.1.8, Release: everything the Windows CI build step builds compiles, and the Windows CI test step passes 14 of 14.
  • Astro Bot, in my local tree: this change on 763d3be, plus local changes this branch doesn't have (a boot fix like #1365, an LDS fix for an NVIDIA device loss (see #1498), a fix for the silent short reads like #838's, diagnostics and performance work). With KYTY_LOD_STATS=1, 23 of 24 New Game runs went through the tunnel into the opening cutscene. The other one crashed earlier, on the short-read bug, in a run without that fix; the last 18 runs, all in a row, had it. During the tunnel the pool settles at about 80% instead of staying at its 90% budget, and the streamer goes idle. The cutscene starts 32–38 s after New Game, as in runs that didn't stall before. A screenshot of the tunnel at the same moment looks as sharp as without the variable.

AI use

Written with Claude Code (AI): it investigated the bug, wrote the change, the test and this description, and ran the builds, tests and game runs above on my PC. I reviewed the diff and this description before opening the PR.

**@⁠devklex** on GitHub · 2026-10-18 04:21 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1631) `devklex:gpu/lod-stats-bound-textures` → `main` · +228 −6 · 7 files · 1 commits · closed without merging ## Problem PS5 texture descriptors can turn on the texture units' mip statistics. `MIP_STATS_CNT_EN` (word 5 bit 25) enables counting, and `MIP_STATS_CNT_ID` (word 6 bits 0–7) selects one of 256 counters; Kyty already decodes both (`ShaderTextureResource::MipStatsCntEn/MipStatsCntId`). `GET_LOD_STATS` (`sceAgcDcbGetLodStats`) writes the counters to memory, and `REPORT_AND_RESET`/`FORCE_RESET` clear them. Astro Bot reads the block like this: a 64-byte header whose first dword must be nonzero, then one u64 per counter. Bits 56–59 hold the finest mip sampled (15 = not sampled), and bits 0–23 are nonzero once the texture was used. `CpOpGetLodStats` (commented "Hack?") answers every report with header 1 and all-zero counters. Astro Bot reads a zero counter as "sampled at mip 0", so every texture looks needed at full resolution. Astro Bot streams texture mips by these reports. It turns counting on for one group of 256 textures per frame and keeps a texture's top mips while the reports say they're sampled. With these answers it keeps every texture it has loaded at full resolution. Its 4.5 GiB texture pool sits at its 90% budget and drops and reloads the same texture several times a second. After New Game the level load waits for the streamer to go idle, so it can stall in the warp tunnel. 6 of my 31 scripted runs before this change stalled there (3 of the last 5), and one of those ended by itself after about 8 minutes. Possibly related: the loading-tunnel stalls in #745. ## Change With `KYTY_LOD_STATS=1` (new `src/graphics/guest_gpu/mipStats.*`), `RenderExecutor::ResolveTexture` notes the counter of every non-storage texture a draw or dispatch binds with counting enabled. `GET_LOD_STATS` reports those counters as sampled at mip 0 and all the others as not sampled, and resets them on `REPORT_AND_RESET` or `FORCE_RESET`. Without the variable nothing changes. This is an approximation. Kyty doesn't see individual samples, so a texture that is drawn still asks for full resolution even when it's small on screen or hidden. Textures that nothing draws now age out, as on hardware. A faithful version would compute the LOD in the recompiled shaders; this one costs one bit per binding. It's off by default because it changes what every game that reads these counters sees. I used an environment variable to keep the change small, and I can turn it into an option like `--support-zmask` if you prefer. ## Testing - New test `mip_stats` (report format, counters cleared only by a reset, short buffers), added to the Windows, Linux and macOS CI jobs. It's plain C++ with no platform code. I've only built it on Windows. - This branch, Windows 11, clang-cl 20.1.8, Release: everything the Windows CI build step builds compiles, and the Windows CI test step passes 14 of 14. - Astro Bot, in my local tree: this change on 763d3be, plus local changes this branch doesn't have (a boot fix like #1365, an LDS fix for an NVIDIA device loss (see #1498), a fix for the silent short reads like #838's, diagnostics and performance work). With `KYTY_LOD_STATS=1`, 23 of 24 New Game runs went through the tunnel into the opening cutscene. The other one crashed earlier, on the short-read bug, in a run without that fix; the last 18 runs, all in a row, had it. During the tunnel the pool settles at about 80% instead of staying at its 90% budget, and the streamer goes idle. The cutscene starts 32–38 s after New Game, as in runs that didn't stall before. A screenshot of the tunnel at the same moment looks as sharp as without the variable. ## AI use Written with Claude Code (AI): it investigated the bug, wrote the change, the test and this description, and ran the builds, tests and game runs above on my PC. I reviewed the diff and this description before opening the PR.
CpOpGetLodStats answers every GET_LOD_STATS report with all-zero counters,
which Astro Bot reads as every texture sampled at mip 0. Its texture
streamer then keeps everything at full resolution, overfills its pool and
can stall the level load after New Game.

With KYTY_LOD_STATS=1, RenderExecutor::ResolveTexture notes the mip-stats
counter (MIP_STATS_CNT_ID) of every non-storage texture a draw or dispatch
binds with counting enabled. GET_LOD_STATS reports those counters as
sampled at mip 0 and the others as not sampled, and resets them on
REPORT_AND_RESET or FORCE_RESET. Without the variable nothing changes.
Adds the mip_stats test to the CI jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:02:12 +00:00
github-bot closed this pull request 2026-11-26 10:02:12 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-18 04:25 UTC · original

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1a6d8a7f-0cdf-46df-a321-f31257b808d6
📥 Commits

Reviewing files that changed from the base of the PR and between 37df7f3278 and b5e855beae.

📒 Files selected for processing: 7
  • .github/workflows/build.yml
  • CMakeLists.txt
  • src/graphics/guest_gpu/command_processor/pm4Handlers.cpp
  • src/graphics/guest_gpu/mipStats.cpp
  • src/graphics/guest_gpu/mipStats.h
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • tests/MipStatsTests.cpp

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

📝 Walkthrough

The change adds mip-sampling statistics that track eligible texture bindings and report sampled counters through GET_LOD_STATS. The report path supports bounded output and reset controls. Tests cover report contents, buffer bounds, persistence, and reset behavior. CMake and the Windows, macOS, and Linux workflows now build and run the new test.

Suggested reviewers: mehmetcambaz, nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to b5e85

The optional mip-statistics change has no identified issue that needs resolution before merge; normal checks remain appropriate.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 5 files. (2 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 describes the main change: optional reporting of bound textures in GET_LOD_STATS mip statistics.
Description check Passed The description is directly related to the changeset. It explains the problem, implementation, approximation, testing, and observed Astro Bot results.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 5 files. (2 skipped: 2 unsupported.)

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-18 04:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1631#issuecomment-6245632329) <!-- 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/1631?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `1a6d8a7f-0cdf-46df-a321-f31257b808d6` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 37df7f3278a41dde020a10daa74d8ae152ee8fb8 and b5e855beae8107f28e9de4baf10a1e614d483c13. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 7</strong></summary> <dl> <dd> * `.github/workflows/build.yml` * `CMakeLists.txt` * `src/graphics/guest_gpu/command_processor/pm4Handlers.cpp` * `src/graphics/guest_gpu/mipStats.cpp` * `src/graphics/guest_gpu/mipStats.h` * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `tests/MipStatsTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The change adds mip-sampling statistics that track eligible texture bindings and report sampled counters through `GET_LOD_STATS`. The report path supports bounded output and reset controls. Tests cover report contents, buffer bounds, persistence, and reset behavior. CMake and the Windows, macOS, and Linux workflows now build and run the new test. **Suggested reviewers:** `mehmetcambaz`, `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"b5e855beae8107f28e9de4baf10a1e614d483c13" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>b5e85</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `b5e85` --> <!-- final_review_risk_coverage:{"sourceCommitId":"b5e855beae8107f28e9de4baf10a1e614d483c13","coveredCommitId":"b5e855beae8107f28e9de4baf10a1e614d483c13","kind":"reviewed"} --> The optional mip-statistics change has no identified issue that needs resolution before merge; normal checks remain appropriate. <!-- 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-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></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 warning</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 5 files. (2 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 describes the main change: optional reporting of bound textures in GET_LOD_STATS mip statistics. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description is directly related to the changeset. It explains the problem, implementation, approximation, testing, and observed Astro Bot results. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 5 files. (2 skipped: 2 unsupported.) **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=1631)! 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 -->
Author
Owner

@⁠Nmzik on GitHub · 2026-11-05 07:30 UTC · original

Credited

**@⁠Nmzik** on GitHub · 2026-11-05 07:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1631#issuecomment-6652362577) Credited

Pull request closed

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