perf(recompiler): look up dominance by binary search and track visited blocks in a bitmap #2276
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2276"
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 hugodearaujo on 2026-10-09T14:17:18Z.
What
Two lookups inside
Structurizesearched vectors linearly:ControlFlowGraph::DominatesandPostDominatesusedstd::findon a block'sdominators/postDominators. Those vectors are always sorted: both analyses end every update withsortUniqueorintersectSorted, andapplyBlockOrderre-sorts them throughremapIdsafter renumbering. They now usestd::binary_search.dominatedBlockschecked whether a block was already visited withcontains(blocks, id)on the growing result vector, so each call was quadratic in the region size. It now keeps astd::vector<bool>indexed by block id. The result is still sorted withsortUniquebefore it is returned.Nothing else changes, and the structured graph is identical (see below).
This does not get any title further. It only makes the structurizer faster. I found it while investigating Hades (PPSA03355), which still crashes at the same place with this change. It is a separate problem: the title's own texture upload pool fills up, which I am still investigating.
Measured
Hades (PPSA03355 v01.003) on Linux, Ryzen 7 7800X3D. On
mainit stops earlier (#1798, then #861), so the runs below are onmain+ #1798 + #861. Most of the time is spent inStructurizefor one pixel shader (code0x3d0087300, 258 blocks, 511 aftersplitSharedMergeBlocks), on the game's render thread at registration. This is the same path that #2105 speeds up from another side.main+ #1798 + #861Two runs per row, timed around
StructurizeinPrepareResourceProgram(local instrumentation, not part of this PR). Without #2105, the post-dominator iteration that #2105 fixes takes most of the time, so the gain here is small. With #2105, the lookups changed here are the largest remaining cost: before this change,dominatedBlocksalone took ~735 ms of 1.6 s, over 32 386 calls.The text dump of the structured graph (
GraphToString, 688 843 bytes) has the same FNV-1a hash (0782e3d419460587) in all four configurations.Tested
On
mainf6af6d11dwith this commit:ctest678/678, includingagc_structurizerandagc_shader_control_flow.agc_driver_prepared_shaders_deferred_undecodable, which stops atvkCreateInstance: Vulkan result -9because the VM has no Vulkan device. The other Vulkan tests skip in that case; this one does not.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)computePostDominatorsin the same file; the two merge without conflict.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:01:23Z.
Review: CHANGES_REQUESTED
Thanks, the idea is sound: the
dominators/postDominatorsvectors are always sorted (sortUnique/intersectSorted, andremapIdsre-sorts), sobinary_searchis equivalent, and the bitmap indominatedBlockskeeps the result identical.One blocker: the PR doesn't link.
core/shader/recompiler/ControlFlow/src/ControlFlowGraph.cpp:17: removingcontainsis wrong, it is still declared inControlFlow/ControlFlowHelpers.hpp:12and used about 20 times inStructurizer.cpp(e.g. lines 182, 278, 296, 359, 465, 608, 743). On the PR merged onto currentmain,agc_structurizer_testsand the other test executables fail withundefined reference to ShaderRecompiler::contains(std::vector<unsigned int> const&, unsigned int).Please keep
contains(or move all its callers to something else), rebuild, and rerun ctest; the "513/513" in Tested can't hold with this diff. Happy to look again once it builds.Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-10T08:32:51Z.
Thanks, you're right.
containsbecame a shared helper declared inControlFlowHelpers.hppafter this branch was cut, and removing it breaks the link on currentmain. Rebased ontomainf6af6d11dwithcontainskept as it is there, so the diff is now only thebinary_searchinDominates/PostDominatesand the bitmap indominatedBlocks(head82853352).ctest678/678 on Linux,agc_structurizerincluded. The Tested section is updated.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:43:45Z.
Review: APPROVED
Checked the rebased head:
dominators/postDominatorsare always sorted (allBlockIds,intersectSorted,remapIds), sobinary_searchis equivalent, and the bitmap indominatedBlockskeeps the result identical. Build + ctest of libSceAgc/libSceAgcDriver (includingagc_structurizer) green on the PR merged onto currentmain; conventions CI green. Merging.