gpu: report bound textures in GET_LOD_STATS mip statistics (KYTY_LOD_STATS=1) #1631
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!1631
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1631/head"
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?
@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 mergingProblem
PS5 texture descriptors can turn on the texture units' mip statistics.
MIP_STATS_CNT_EN(word 5 bit 25) enables counting, andMIP_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, andREPORT_AND_RESET/FORCE_RESETclear 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(newsrc/graphics/guest_gpu/mipStats.*),RenderExecutor::ResolveTexturenotes the counter of every non-storage texture a draw or dispatch binds with counting enabled.GET_LOD_STATSreports those counters as sampled at mip 0 and all the others as not sampled, and resets them onREPORT_AND_RESETorFORCE_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-zmaskif you prefer.Testing
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.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). WithKYTY_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.
@coderabbitai[bot] on GitHub · 2026-10-18 04:25 UTC · original
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
1a6d8a7f-0cdf-46df-a321-f31257b808d6📥 Commits
Reviewing files that changed from the base of the PR and between
37df7f3278andb5e855beae.📒 Files selected for processing: 7
.github/workflows/build.ymlCMakeLists.txtsrc/graphics/guest_gpu/command_processor/pm4Handlers.cppsrc/graphics/guest_gpu/mipStats.cppsrc/graphics/guest_gpu/mipStats.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cpptests/MipStatsTests.cppIncluded 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,nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
b5e85The optional mip-statistics change has no identified issue that needs resolution before merge; normal checks remain appropriate.
Pre-merge checks:
4 ·
1
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.
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.@Nmzik on GitHub · 2026-11-05 07:30 UTC · original
Credited
Pull request closed