refactor(shader): walk each construct when checking the structured constructs #9703
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9703"
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:10Z.
What
hasStructuredConstructsruns after every structurize attempt. For each merge header it tested every block of the graph, and for each block it searched every block for its innermost loop, with dominator binary searches each time. The work grows with the number of headers times the number of blocks. WithAPS5_FORCE_STRUCTURIZER_FALLBACK=1, Ghostrunner's compute shader 0x200c520000 (PPSA03685, linked with #9068 and #8070) becomes a 32,490-block reach-flag graph with 6,647 merge headers, so the check runs about 216 million member tests.constructsFollowDominance(from #9702) holds for the structural graph, the member checks visit only the blocksdominatedBlocksfinds from the header, stopping at its merge, and for a loop also from its continue block, in block order. Only a block in the header's construct or in the loop's continue construct can fail a member check. A construct block is dominated by the header and not by the merge, so some path from the entry reaches it without the merge; from the last header on that path every block is dominated by the header, so the walk reaches it. A continue-construct block is dominated by the continue block and is reached from it the same way. The blocks the walk skips passed every check, so the result is unchanged.APS5_NO_PERF_DOMINATOR_TREEkeeps the old loop. Its row indocs/dev/ENVIRONMENT.mdsays so.Tested
main0db47b263(head98c6aef28, through #9702'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.This PR makes no speed claim. The repository's speed evidence is a capture of a scene on
mainand on the change, and no scene runs this check on a large graph: the only one known is 0x200c520000 under the forced fallback, and its scene ends before its next present (#9702 explains why).Same result:
APS5_NO_PERF_DOM_INTERSECTION,APS5_NO_PERF_ITERATION_SELECTION,APS5_FORCE_STRUCTURIZER_FALLBACKandAPS5_NO_PERF_DOMINATOR_TREE: 250,000 comparisons ofGraphToString(or the exception text), no differences.Tests on the head,
6ba72890aonmain7e2ba73e4(on top of #9702), 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).Validation: I ran the same focused tests on this head with
VK_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 11/11. The log has nowas not found but was requested by env var VK_INSTANCE_LAYERS, noVUID-line and no validation message.After the
mainmerge, Windows 11, RTX 4090, NVIDIA 616.92, WinLibs GCC 15.2:958f3f960mergesmain7b32a842f, through #9702'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.cpp.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:24Z.
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:16:15Z.
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:35Z.
Review: DISMISSED
I reviewed the construct-walk optimization against the previous
hasStructuredConstructslogic, including the structural graph analysis, the loop/continue member sets, and the fallback path. The optimized walk is guarded byconstructsFollowDominance, which checks reachability and predecessor/successor consistency; the original full scan remains as fallback. The reported differential comparisons and repeated focused/Vulkan-validation runs are meaningful evidence. I found no independent code defect in the reviewed diff. I could not run the C++ suite locally because this checkout has no configured product build.Before approval, please satisfy the repository performance-report rule: this PR is labeled
perf, but the description does not include matchingaps5-summary.jsonllines formainand the change from the same title, scene, and machine, the two trace attachments, ortools/trace_digest.pyoutput. The workflow has markedperf numbers missing. Please add the capture artifacts, or remove the performance claim/title if the required capture is unavailable.This branch is based on
7e2ba73e4c, 13 commits behind currentmain(8b3a6ba88d8fc74e768f1a7e8e9e36fb69842768), and depends on #9702, which has the same base age and needs the same performance-report artifacts. Please keep the declared dependency, coordinate the stack after #9702 is updated, and rebase/retest this head on currentmainbefore requesting another review.Local checks I ran against the head:
git diff --checkpassed;tools/check_conventions.pypassed with 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.