shader: queue transitive fold users once per round #1585
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!1585
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1585/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-17 08:01 UTC · original
NeySlim:perf/fold-worklist→main· +60 −8 · 3 files · 1 commits · closed without mergingProblem
In God of War Ragnarök (PPSA08332, 05.005) the game stops rendering for about 135 s during the sled sequence. The GPU command thread is busy translating compute shaders, and almost all of that time is in
ConstantPropagationPass, inFoldWorklist::QueueUsers.Since
df08b8328, every fold that changes an instruction walks the whole transitive closure of its users. The walk runs once per change, even when nearly every visited instruction is already queued. In a large shader one fold near the top revisits the rest of the program, and there are thousands of folds, so the pass is quadratic in practice. The stall is not one shader: about 50 compute shader translations of 1 to 4.4 s each (each hash is translated 9 times), plus pixel shaders.Change
A change now only records its direct users. Once the current round of the worklist (what was queued when the round started) has been processed, a single walk queues the transitive users of all of that round's changes, visiting each instruction once.
Coverage is unchanged: every transitive user of a change is still revisited, including cyclic Phi edges, and nothing is capped or depth-limited. Only the number of walks changes, from one per change to one per round.
Test
TestConstantPropagationSharedUsersinshaderCfgTests.cpp: a chain of 4096 dynamic XORs where each link has an identity fold, so every fold has the rest of the chain as transitive users. It checks the folded chain and that the pass revisits at most 2 users per link (ConstantPropagationStats::revisited_users, returned by the pass). With this change it revisits 1 per link; without it the check fails.ctest:shader_cfgpasses; the other failures (GPU tests on this RADV setup) are the same as on main.shader_recompiler_compute_tests, one case per process: 779 cases, the same 52 failures as main, no new failure.Validation
Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.4.
Translation output: I dumped the translation inputs (code, user data, stage input info) of every shader translated during a run from the menu to the Freya fight (1913 translations, CS/PS/VS) and replayed them offline with main and with this branch. The IR dump after translation and the SPIR-V are byte-identical for all of them. Same result on a second, shorter set of 345 translations.
Translation time, same replay, single thread:
In game: new game from the menu, same scripted inputs, frame count from a uprobe on
GuestGpu::SuspendPoint. Main and this branch both have #1165 merged (main alone stops earlier in this game).The opening cutscene is unchanged (8.6 against 8.8 fps). With this change, a few stalls of 3 to 12 s remain later in the run; a profile of the GPU thread puts them in
TrackResourcesandMaterializeResources, not in constant propagation.Not tested on Windows/macOS; the change is platform-independent.
AI use
I used Claude Code (AI agent) to profile the stall, write the change and the test, build the dump/replay check and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
@coderabbitai[bot] on GitHub · 2026-10-17 08:05 UTC · original · edited 2026-10-17 08:38 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
afc10a0d-4698-4916-afca-87ad5983980f📥 Commits
Reviewing files that changed from the base of the PR and between d4abdf5f37773c66003e9ddb37baf1baa02b6258 and
8dafd56455.📒 Files selected for processing: 3
src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cppsrc/graphics/shader/recompiler/ir/passes/ConstantPropagation.htests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
📝 Walkthrough
The constant propagation pass now processes pending instructions in rounds and queues affected consumers at round boundaries. It returns a
ConstantPropagationStatsvalue with the count of revisited users. A regression test checks dependencies in a 4,096-link XOR chain and asserts that the revisit count is at most twice the chain length.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
8dafdThe slow-runner test failure has been removed, and no remaining issue is established. The change is mergeable after normal checks.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 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-17 08:05 UTC · original · edited 2026-10-17 08:39 UTC
On
tests/shaderCfgTests.cppline 12927 (outdated):🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 45669
Keep the performance limit out of the required correctness test.
TestConstantPropagationSharedUsers()runs frommain, andCheckaborts the test process when elapsed time exceeds two seconds. A slower or instrumented runner can therefore failshader_cfgeven when the fold assertions pass. Keep the correctness checks in this test. Move the timing threshold to a separate performance test with an appropriate platform-specific threshold.✅ Confirmed as addressed by @NeySlim
@coderabbitai[bot] on GitHub · 2026-10-17 08:05 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
aaba6ba6-4149-4a38-81ee-407f1811dadf📥 Commits
Reviewing files that changed from the base of the PR and between
b82512be06and d4abdf5f37773c66003e9ddb37baf1baa02b6258.📒 Files selected for processing: 2
src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@NeySlim on GitHub · 2026-10-17 08:32 UTC · original
On
tests/shaderCfgTests.cppline 12927 (outdated):Fair point. Replaced the time limit with a count: the pass now returns how many users it revisited, and the test checks it's at most 2 per link. It's 1 per link with this change and quadratic without it, so the test still fails on main. The chain is down to 4096 links, so it's cheap too.
@coderabbitai[bot] on GitHub · 2026-10-17 08:39 UTC · original
On
tests/shaderCfgTests.cppline 12927 (outdated):@NeySlim Thanks for the update. The revised test removes the runner-speed dependency and retains the fold assertions. The revisit-count limit checks algorithmic work without a wall-clock threshold. This addresses my concern.
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-17 10:34 UTC · original
Closing:
f6f1ac8b4on main does the same thing (one walk over the union of affected users per drain instead of one per change). The deterministic test from this PR passes on main as well, so there's nothing left here.Pull request closed