texture cache: copy evicted images without holding the cache lock #1947
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!1947
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1947"
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?
@paulohenriquesn on GitHub · 2026-10-27 22:30 UTC · original
paulohenriquesn:texture-cache-gc-copy-unlocked→main· +27 −10 · 2 files · 1 commits · openGame
Marvel's Wolverine (PPSA03671, 01.001.005). I measured this on the KytyPS5-Frank fork, where the game is playable; on main it still stops after the logo (#1783, #1453). The same change for the fork is mn3ema/KytyPS5-Frank#1.
i9-12900K, RTX 5060 Ti 16 GB (driver 617.42), Windows 11.
Problem
In the jungle the game keeps about 14.5 GB of VRAM in use, so the texture GC runs under pressure and evicts GPU-modified images every frame. RunGarbageCollector holds m_lock for the whole pass, and DownloadImageMemory copies each evicted image's guest bytes into the download buffer (TryReadBacking) inside it. Every guest write fault goes through TextureCache::InvalidateMemory, which takes the same lock, so game threads spin until the copy is done.
I sampled the process from outside (SuspendThread + StackWalk64 with the pdb, around 400 Hz). The two busiest game threads spent 13 to 14% of their samples spinning in InvalidateMemory. With the change it was about 1%.
Change
Testing
shader_recompiler_compute_tests --htile-clear-onlypasses (CheckUnifiedTextureCacheFlow, whose pressure case retires GPU-written images through this path). I haven't run a game on it, because Wolverine doesn't get past the logo here and I don't have another game that fills VRAM. main also skips tiled images in the GC, so the gain is probably smaller here, and I don't have a number for main.AI use
The profiling, the code, the build, the test run and this description were done with Claude Code (an AI coding assistant) at my direction. I played the sessions on the fork that the numbers come from.
@coderabbitai[bot] on GitHub · 2026-10-27 22:38 UTC · original
No actionable comments were generated in the recent review.
ebeaef1e-c074-4f96-8a51-d38970563130Reviewing files that changed from the base of the PR and between
1be1c6c4f9and80bb53c589.src/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Walkthrough
DownloadImageMemorynow supports an unlocked backing-memory read. After the read, it reacquires the lock and checks that the image remains registered, unchanged, and safe to download. The garbage collector uses this mode for safe images and skips eviction if the download fails. The default mode retains the existing locked read path.Suggested reviewers:
nmzikPriority:
Low
Change: Bug fix
Merge Risk:
Minimal · up to
80bb5No confirmed merge-blocking issue remains for the unlocked download path. Complete the normal build and test checks before merging.
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. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 2 files.
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.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.