fix(shader): structurize a 4,750-block graph before Unreal's render thread watchdog fires #9702
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9702"
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 frankea on 2026-10-22T08:57:02Z.
What
Ghostrunner (PPSA03685) dispatches a compute shader, 0x200c520000, that links into 104,136 dwords once #9068 and #8070 resolve its table calls. Its structurization took 173 s on the AGC queue-0 worker, so Unreal aborted after 120 s with
GameThread timed out waiting for RenderThread(5 of 5 runs, Game bring-up #7320). The graph has 4,750 blocks.splitSharedMergeBlocksmakes 1,302 splits, and the graph grows to 10,170 blocks.The time was not in the analyses. I dumped the graph at
Structurizeand replayed it throughStructurizer.cppalone with scoped timers. After each split,splitOneSelectionMergeexamines every selection header again: 1.71 million header checks in all. That loop took 144 of 177 s:FindNearestCommonPostDominatortook 62 s. It intersected the two post-dominator sets, then binary-searched the other common blocks in each candidate's set until one candidate held them all.selectionRegion(34 s) andnaturalLoopBodytested membership withstd::findin the list they were building, andexternalEntryEdges(14 s) did the same in the sorted region.findInnermostContainingLoop(18 s) scanned loop bodies linearly.The dominator sets themselves are small: at the end they average 138 entries over 10,217 blocks.
Three commits on top of #9701, each with the reasoning for why its output is unchanged:
perf(shader): look up the structurizer's sorted block lists instead of scanning them. Loop bodies, construct blocks, regions and SCC members are sorted, so membership is a binary search. The traversals that tested the list they were building test a bitset, andselectionRegionreads its sorted result from the bitset.FindNearestCommonPostDominatorskips a candidate whose post-dominator set is too small to hold the other common blocks and checks the rest in one pass.remapIdssorts only when the map broke the order.perf(shader): build the structurizer's dominator trees instead of iterating dominator sets. Dominators and post-dominators are built with the Cooper-Harvey-Kennedy iteration ("A Simple, Fast Dominance Algorithm", 2001) over a virtual root above the entry, or above every exit for post-dominators. Each block's sorted set is written as its parent's set plus itself. When every block is reachable from the virtual root, the greatest fixpoint of the old equations is the dominance relation of that graph, so the sets are the same. When a block is unreachable from the entry, or cannot reach an exit, the old fixpoint runs. Each block keeps its immediate post-dominator, andFindNearestCommonPostDominatorclimbs the tree when both blocks have one.APS5_NO_PERF_DOMINATOR_TREEturns this commit and the next off. The structurizer and control-flow tests also run with it set, and it has a row indocs/dev/ENVIRONMENT.md.perf(shader): test a selection construct's members by dominance. In some graphssplitSharedMergeBlockcan learn which predecessors of the merge M lie in the header H's construct without walking the construct (dominatedBlocks). The conditions: every block is reachable from the entry, the predecessor lists match the successor lists, and M neither is H nor dominates H. Then the construct is exactly the set of blocks that H dominates and M does not, other than M. The commit message has the argument.splitOneSelectionMergechecks the conditions once per pass and walks as before when they fail.hasStructuredConstructs, the split order and the clone and junction decisions are untouched; #9703 speeds uphasStructuredConstructsseparately.BasicBlockgainsimmediatePostDominator.GraphToStringdoesn't print it, and nothing outside the structurizer reads it.Tested
main0db47b263(head00ed88498, through #9701's refreshed head; no conflicts), RTX 4090 (NVIDIA 616.92, Windows 11): the 11 ctest entries ofagc_structurizer,agc_shader_control_flow,scalar_callandagc_driver_compute_table_callspass 11/11, each test run three times, and 11/11 under the validation layer (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V), with noVUID-line; the layer reports nothing on this head.main0db47b263passes the union of the refreshed sets, 115/115, under the same layer settings with noVUID-line.Ghostrunner 0x200c520000,
agc_shader_replay --prepareon the request the driver dumped when the shader was first used. Both builds aremaind34da5d69+ #9068 + #8070 (the shader doesn't link without them) with local diagnostics that dump the input graph and print timestamps; the second adds these commits. The structurizer files are the same ond34da5d69and on currentmain. Machine: Ryzen 7 5800X, RTX 4090, Windows 11, WinLibs GCC 15.2, Release, otherwise idle:main+ #9068 + #8070splitSharedMergeBlocks--prepareBoth builds then stop on the same #7459 refusal,
GetImageResource dword 0 is not a valid runtime value. In the title with these commits on the same base, the structurization takes 19.3 s (process 192.9 s to 212.2 s) and no watchdog fires. The title then aborts on that refusal, which this PR doesn't touch.Persona 3 Reload (PPSA10872), @zaidhawk's run on an RTX 5090 (NVIDIA 617.42, Windows 11; #9068 comment): on
main9d6adeb55+ #7048 + #9068 + #8070 with a larger local callee window,agc_shader_replay --prepareof compute shader 0x2014960000 (119,922 words) took 355.0 s; with #9703's branch958f3f960added (this PR with #9701 under it and #9703 on top) it took 32.6 s, and 75.7 s withAPS5_NO_PERF_DOMINATOR_TREE=1, all with the same output and the same #7459 refusal. In the title, the base hits the RenderThread watchdog at the Iwatodai Station strip mall; with the stack no watchdog fires and the title goes on to that refusal.No trace summary lines: the only scene that prepares this shader ends before its next present on both builds. On the base the watchdog kills the title during the preparation; with this PR the #7459 refusal aborts it right after the preparation. A trace window that is open when the title exits writes nothing. With warm caches, scenes before that point don't run the structurizer.
Same structured output:
GraphToString, 16 MB) is byte-identical tomain's after each commit.main's and this structurizer on generated graphs and comparedGraphToString, or the exception text when one throws. The graphs:APS5_NO_PERF_DOM_INTERSECTION,APS5_NO_PERF_ITERATION_SELECTION,APS5_FORCE_STRUCTURIZER_FALLBACK, andAPS5_NO_PERF_DOMINATOR_TREEagainstmain's default: 200,000 comparisons. A second batch of 80,000 graphs ran up to 601 blocks (4,176 of 200 blocks or more). No differences.agc_shader_control_flow_tests,agc_structurizer_testsandagc_driver_compute_table_calls_testshand toStructurize, plus 7 Ghostrunner shaders, in 4 modes: 460 comparisons, all identical, including the 34 that throw.Tests on the head,
231be5cc7onmain7e2ba73e4, Windows 11, RTX 4090, NVIDIA 616.92, WinLibs GCC 15.2:agc_structurizer,agc_shader_control_flow,agc_driver_compute_table_callsandscalar_callpass 11/11 with theintersection_off,iteration_selection_off,dominator_tree_offandforced_fallbackvariants, each run three times (ctest --repeat until-fail:3).agc_structurizer_testsalso passes in all five modes built with AppleClang on macOS.Validation: I ran the same focused tests on #9701 (
360682431) and on this head (231be5cc7), both onmain7e2ba73e4, withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Vulkan SDK 1.4.363.0),ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1, usingctest -R "^(agc_structurizer|agc_shader_control_flow|scalar_call|agc_driver_compute_table_calls)" -V. They pass 9/9 and 11/11 (#9701 lacks the twodominator_tree_offvariants). No log haswas not found but was requested by env var VK_INSTANCE_LAYERS, aVUID-line or a validation message. Before the rebase,maina6dcea927also passed 9/9 under the layer with no validation messages, andVK_LOADER_DEBUG=layershowed the loader inserting the layer inagc_driver_compute_table_calls.After the
mainmerge, Windows 11, RTX 4090, NVIDIA 616.92, WinLibs GCC 15.2:969aadab6mergesmain7b32a842f, through #9701's merge.agc_structurizer,agc_shader_control_flow,agc_driver_compute_table_callsandscalar_callpass 11/11 with theintersection_off,iteration_selection_off,dominator_tree_offandforced_fallbackvariants, each run three times (ctest --repeat until-fail:3). UnderVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Vulkan SDK 1.4.363.0),ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1, withctest -V, they pass 11/11; onmain4d57821d4, five commits past the mergedmainand none incore/shader, the nine of them that exist there pass 9/9 (the twodominator_tree_offvariants come with #9702). Neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS, aVUID-line or any other validation message.Checklist
main; no other open PR implements the same functions. No open PR changesStructurizer.cpporControlFlowGraph.cpp;tools/pr_overlap.pyreports no overlap. #9198 uses the same dominator algorithm forValidateProgram's IR dominance and touches no file here.NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-22T08:57:16Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by clairtonmichel on 2026-10-22T09:18:29Z.
Tested on AMD Ryzen 7 9800X3D and AMD Radeon RX 7900 XTX (Fedora Linux, Mesa 26.2.5):
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:17:25Z.
Review: DISMISSED
The implementation and validation report are unusually thorough: I reviewed the sorted membership changes, the tree/fixpoint fallback conditions, the incremental post-dominator lookup, and the selection-construct dominance fast path. The reported differential comparisons and repeated focused/Vulkan-validation runs are useful evidence, though I could not independently run the C++ suite in this Linux checkout because it has no configured product build.
I’m requesting the repository-required performance artifacts before approval. This PR is labeled
perf, but the description does not include theaps5-summary.jsonlline frommainand the matching line from this change for the same title, scene, and machine, the two trace attachments, ortools/trace_digest.pyoutput. The workflow has also markedperf numbers missing. Please add those artifacts, or remove the performance claim/title if the required capture is unavailable, as the performance-report rule specifies.The branch is based on
7e2ba73e4c, 13 commits behind currentmain(8b3a6ba88d8fc74e768f1a7e8e9e36fb69842768). Please rebase/update and rerun the focused checks on the resulting head before requesting another review. The PR is listed as a dependency of #9703, so please preserve that stack and coordinate the resulting heads there.Local checks I ran against the current head:
git diff --checkpassed;tools/check_conventions.pypassed when given the actual PR body. GitHub conventions, eligibility, intake, labels, and report checks pass; product build jobs are skipped by the repository gates. I did not independently reproduce the reported timings, differential fuzzing, or platform/GPU test results.