perf(recompiler): compute post-dominators visiting successors first #2105
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2105"
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?
Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-09T08:40:37Z.
What
Structurizer::computePostDominatorsiterates the post-dominator sets to a fixed point, visiting the blocks in id order. Post-dominance flows from a block's successors back to the block, and successors mostly have higher ids, so each pass moved the sets back by about one block. A long program needed about as many passes as it has blocks, each pass costing O(blocks²).recomputeAnalysesruns it again after every split insplitSharedMergeBlocks, which allows up to four splits per block.PPSA36082
After the main menu, loading a level shows a black screen for about 20 s while the game prepares a shader through
sceAgcCreateInterpolantMapping→Driver::ResolveShaderAbi→Structurize. All 12 thread stacks I sampled during it were insplitSharedMergeBlocks→recomputeAnalyses→computePostDominators. With this change the black screen lasts about 5 s.Tested
Linux (CachyOS), x86-64, GCC, 7800X3D / RTX 4090.
agc_structurizer(new check): afterStructurize, every block's post-dominator set must equal a brute-force one (B post-dominates A when no path from A reaches an exit without passing B). Runs on the existing graphs and a 151-block chain of 50 selections. Starting from the wrong initial sets fails it.splitSharedMergeBlockssplits, and four of the existing test graphs) gives identical output, 412 lines.Structurizetime, main → this change: a chain of 400 selections (1201 blocks) 3181 ms → 20 ms; 60 branches to one shared block (122 blocks, 181 after splitting) 104 ms → 27 ms.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-09T08:58:02Z.
The linux and windows failures here are main's own build break, not this change:
ShaderFusion.cppcan't findspirv/unified1/spirv.hpp(missing SPIRV-Headers include), and the build stops before anything from this PR is tested. Main's own CI on6cc0503dfails the same way. #2093 / #2099 fix it, and I'll rebase once one of them lands.Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-09T09:15:30Z.
Rebased on main
d9484c71(with #2099), so the SPIRV-Headers build break is gone. Ran the linux job from build.yml locally on the new head (SPIRV tools on, test registration check, build, libs): ctest 504/504 pass.Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-09T10:24:53Z.
Another title where this is the bottleneck: Rise of the Ronin (PPSA04540), on AMD.
Setup: RX 9070 XT (RADV / Mesa 26.2.4), Ryzen 7 7800X3D, Linux, GCC. Base is
main43972e69+ #1836 + #1837 + #2153, plus local throwing placeholders for a few imports the title never called in these runs. Scripted and headless.Without this PR (warm shader disk cache):
sceAgcCreateShader→Driver::RegisterShader→PrepareRegistered→PrepareShader→PrepareResourceProgram→Structurize→splitSharedMergeBlocks→recomputeAnalyses→computePostDominators→intersectSorted.Structurizestill runs before the cache lookup.With this PR (cold cache, since the source version changed):
AGC driver: unsupported registered shader type, #1893).So on this title it goes from stuck at registration to getting through its shader loading.
Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T12:39:23Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/tests/Structurizer.cppL112core/libs/prx/libSceAgcDriver/tests/Structurizer.cppL76, L112Imported from boykopovar/AnyPS5. Originally posted by mrk1987 on 2026-10-09T14:46:02Z.
Independent confirmation from a different title and platform (Windows 11, MinGW-w64 GCC 15.2.0, RTX 5090). I hit the same problem and made the same change (postorder visit, unreachable blocks appended in id order) before finding this PR.
Equivalence on real shaders. I dumped the
RecompileRequestof every shader a retail Unreal Engine title registered: 608 compute, pixel and vertex programs. I ranGraphBuilder::Build+Structurizer::Structurizeon each with the old and new visit order. I then hashed the result: every block's successors, terminator kind/merge/continue/loop-header,dominatorsandpostDominators. 0 of 608 differ. Total structurize time over the corpus went from 21.7 s to 1.5 s.Worst cases. These were three ~4,800-instruction compute shaders (589 → 793 blocks after splitting): 6.2–6.3 s → 0.31–0.35 s per
Structurize. Per-phase timing put 5.7 s of the 6.2 s insplitSharedMergeBlocks. Over ~200recomputeAnalysescalls,computePostDominatorstook 5,866 ms against 119 ms forcomputeDominatorTree.Why it matters beyond load time.
Driver::RegisterShaderholdsShaderPreparationTransaction's process-wide lock while it runs. In this title each of those shaders goes throughStructurizethree times per registration: the registration pre-check inPrepareRegistered, thengetSource'sResourceProgramfor each of the two compute variants. That is ~18.5 s under the lock per shader, three shaders back to back, with every UE worker blocked in theShaderPreparationTransactionconstructor. UE's heartbeat hang detector then kills the process. With this change the longest registration in that run drops to 0.8 s.Tested and written by Claude (Claude Code) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:13:04Z.
Checked on current main: build + ctest green (agc_structurizer included). The change only reorders the fixed-point iteration (same equations, same initial sets), so the result is unchanged, as the new brute-force post-dominator check and mrk1987's 608-shader equivalence dump confirm. Timings are confirmed independently by EdouardSence and mrk1987. Merging.
Note: #2201 touches the same spot in
tests/Structurizer.cpp; whoever lands second will need a rebase.