graphics: cut per-draw CPU cost on the GPU command thread #1211
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!1211
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1211/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?
@NeySlim on GitHub · 2026-10-08 13:17 UTC · original
NeySlim:perf/gpu-command-thread→main· +123 −104 · 3 files · 4 commits · closed without mergingProblem
In God of War Ragnarök (PPSA08332, 05.005) the frame rate is bound by the GPU command thread (
GuestGpu::ThreadRun). On main, aperfprofile of that thread during the opening cutscene shows two per-draw costs that do no useful work:RenderExecutor::CommitBindingswalks the bound images and looks each one up in the texture cache again for every scalar read of every bound shader, to collect the ranges those images write. The list is the same for the whole draw.MaterializeResources) spends a large share of its time in tinyIR::Value/IR::Instaccessors (Resolve,Arg,IsIdentity,U32,operator==, ...). They are defined inValue.cpp, so they cannot be inlined into the walker without LTO.MaterializeResources(inclusive)IR::Value/IR::Instaccessors (self)CommitBindings(inclusive)Change
CommitBindingscollects the ranges written by bound images once per draw, then checks every scalar read against that list. Same checks, same EXIT messages.IR::Value/IR::Instaccessors andValue::operator==move inline intoValue.h.Resolvefollows identity chains in a loop instead of recursing (same result).ResolveInstructionstill fails fast when an identity resolves to something that is not an instruction.No behavior change intended.
Test
shader_recompiler_compute_tests, one case per process: 775 cases, the same 50 failures as main on this RADV setup, no new failure.resource_tracking_tests,resource_materialization_tests,scalar_provenance_tests: pass.Validation
Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.4.
Main (
d58aefde4) against this branch, both with #1165 merged: without it main stops in this game shortly after the opening cutscene, on the short file read that #1165 fixes. New game from the menu, same inputs, frame rate from a uprobe onGuestGpu::SuspendPoint, warm pipeline cache, runs alternated main / PR three times:The sled numbers leave out a stall of about 130 s that both builds hit at the same point while a compute shader is translated (
FoldWorklist::QueueUsers); it is not related to this change. A fourth pair withperfattached gives the same picture (8.40 / 7.62 / 6.51 against 9.15 / 8.82 / 7.26 fps).GPU thread profile in that fourth pair (20 s, cutscene):
MaterializeResources(inclusive)IR::Value/IR::Instaccessors (self)CommitBindings(inclusive)In the Freya fight the same counters go from 18.5 to 3.2 ms (accessors) and from 17.5 to 6.8 ms (
CommitBindings). No new error or device loss in the logs on either side.Not tested on Windows/macOS; the changes are platform-independent.
AI use
I used Claude Code (AI agent) to profile the emulator, write the changes, measure the frame rate and run the tests above on my machine. I reviewed the diff and the results before updating this PR.
@coderabbitai[bot] on GitHub · 2026-10-08 13:23 UTC · original · edited 2026-10-17 07:55 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
af756038-1d41-4994-b67d-54b243d52b23📥 Commits
Reviewing files that changed from the base of the PR and between 3468a996cc2f1b1b269c2b8619d729e14760e1e5 and 05ed8da90cdc516ed3b154825f87f4f69b296907.
📒 Files selected for processing: 5
CMakeLists.txtsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/shader/recompiler/ir/Value.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.
📝 Walkthrough
MemoryTracker tracks CPU-dirty generation changes. BufferCache uses the generation and registration epoch when deciding whether to scan upload ranges. RenderContext can skip a mapped-range sweep when its synchronization key and mapping epoch are unchanged. CommitBindings gathers image write ranges once per call. Value and Inst accessors are now defined inline in Value.h. Tests cover generation changes and BDA synchronization after remapping.
Suggested reviewers:
nmzikPriority: ⬆️ High
Change: Refactor
Merge Risk: ⚪ Minimal · up to
05ed8No identified synchronization or accessor issue remains that should block merging after normal checks.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 8.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 10 files. (2 skipped: 1 unsupported, 1 too large.)
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.@coderabbitai[bot] on GitHub · 2026-10-08 13:23 UTC · original · edited 2026-10-08 13:26 UTC
On
src/graphics/shader/recompiler/ir/Value.hline 212 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 17272
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41650
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41810
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11914
Check the resolved value before reading instruction storage.
Inst::SetArgdoes not enforce theIdentityoperand type.ReplaceUsesWithcan create anIdentitywhose operand is an immediate. The currentResolveInstruction()then reads that immediate's union storage asInst*.The base implementation rejected this path through
EXIT_IF. Do not returnnullptr:ReadLaneEliminationdereferences the result without a null check. Preserve the existing fail-fast contract while validating the resolved value:Suggested fix
📝 Committable suggestion
✅ Confirmed as addressed by @NeySlim
@coderabbitai[bot] on GitHub · 2026-10-08 13:23 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
6adcf627-6b0e-4d24-ac9b-13addfe01f18📥 Commits
Reviewing files that changed from the base of the PR and between
4865dd92caand 5a359cf4222e003e3c746728b4d9f8bdd67a5b9a.📒 Files selected for processing (11)
src/graphics/host_gpu/memoryTracker.cppsrc/graphics/host_gpu/memoryTracker.hsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/cache/streamBuffer.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/host_gpu/renderer/renderContext.hsrc/graphics/shader/recompiler/ir/Value.cppsrc/graphics/shader/recompiler/ir/Value.htests/MemoryTrackerTests.cpp💤 Files with no reviewable changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@NeySlim on GitHub · 2026-10-08 13:26 UTC · original
On
src/graphics/shader/recompiler/ir/Value.hline 212 (outdated):Agreed, fixed in cecf901:
ResolveInstructionchecks the resolved value again and keeps the fail-fastEXIT_IFof the recursive version when an identity forwards a non-instruction, instead of reading the union asInst*.resource_materializationandresource_trackingpass.@coderabbitai[bot] on GitHub · 2026-10-08 13:27 UTC · original
On
src/graphics/shader/recompiler/ir/Value.hline 212 (outdated):@NeySlimThanks for the fix incecf901. The resolved-value check preserves the fail-fast contract and prevents reading an immediate asInst*. Thanks for confirming thatresource_materializationandresource_trackingpass.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@NeySlim on GitHub · 2026-10-09 07:23 UTC · original
I added a commit,
gpu: sweep BDA buffers after memory is mapped again(378f66f3), for a case the skip inPrepareBdamissed.Gap: the skip compared the CPU-dirty generation and the buffer registration epoch, but the sweep only visits mapped ranges.
UnmapMemoryleaves a range CPU-dirty and unprotected, and the sweep after it skips these pages. If the guest then writes them (no fault, they are unprotected) and maps the range again, nothing in the key changes: the next sweep is skipped and a shader reads the buffer's stale copy through its device address. Before this PR the sweep ran before every draw, so this could not happen.Fix:
MapMemoryadvances a mapping epoch after adding the range, andPrepareBdacompares it too before skipping. It is read before the sweep like the rest of the key, so a mapping that lands during a sweep makes the next one run. Unmapping needs nothing more: it invalidates the range, which already advances the generation. Mappings are rare compared to draws, so the skip keeps its gain.Test: new
BdaSweepAfterRemap(--bda-remap-only, ctestbuffer_cache_bda_remap, also in the default run). A buffer over mapped memory is uploaded by a first sweep; part of it is unmapped and swept, written without a fault and mapped again; the next sweep must upload the new word. Without the fix it fails at "mapped again" (the GPU copy keeps the old word).Validation: Linux, Radeon 8060S, Mesa RADV 26.2.3.
memory_tracker,buffer_cache_dirty_gcand the new test pass (buffer_cache_rangesfails on main too on this setup).shader_recompiler_compute_tests, one case per process: 594 of 603 cases pass, the same 9 failures as on main.As for the rest of this PR, I used Claude Code (AI agent) to find the gap, write the fix and the test, and run the tests; I reviewed the change and the results.
@ZrDaniel07 on GitHub · 2026-10-26 20:35 UTC · original
@NeySlim Windows/NVIDIA data point for this PR. Setup: RTX 5090, Windows 11, ASTRO BOT's Garden level, on
mainf90a8b15+ #838 + a local mesh slicing patch. Details are in the #745 report.CommitBindings, becausemainnow usesm_slot_images[id]instead oftry_get(id). Keepingmain's access plus your gather-once loop builds fine, and the other three commits apply as-is.AI use: Claude Code rebased the commits and compared the overlay numbers with me; I ran the game.
Pull request closed