Repository navigation
perf(recompiler): look up dominance by binary search and track visited blocks in a bitmap - #2276
Conversation
adriadam10
left a comment
There was a problem hiding this comment.
Thanks, the idea is sound: the dominators/postDominators vectors are always sorted (sortUnique/intersectSorted, and remapIds re-sorts), so binary_search is equivalent, and the bitmap in dominatedBlocks keeps 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.
…d blocks in a bitmap Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7ec027c to
8285335
Compare
|
Thanks, you're right. |
adriadam10
left a comment
There was a problem hiding this comment.
Checked the rebased head: dominators/postDominators are always sorted (allBlockIds, intersectSorted, remapIds), so binary_search is equivalent, and the bitmap in dominatedBlocks keeps the result identical. Build + ctest of libSceAgc/libSceAgcDriver (including agc_structurizer) green on the PR merged onto current main; conventions CI green. Merging.
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