fix(shader): find strongly connected components without recursion #9701
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9701"
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:56:51Z.
What
computeStronglyConnectedComponentsvisited blocks recursively, one stack frame per block on the deepest path. WithAPS5_FORCE_STRUCTURIZER_FALLBACK=1, the reach-flag fallback turns Ghostrunner's compute shader 0x200c520000 (PPSA03685, linked with #9068 and #8070) into a graph of 32,490 blocks.tarjanVisitthen overflowedagc_shader_replay's 2 MiB stack after 4 s, and the replay crashed. The recursion is as deep as the longest depth-first path, so any graph that large overflows a thread's stack the same way.The visit now keeps its frames in a vector: block, successor list, next successor. It enters successors in the same order, lowers the parent's lowlink when a child finishes, and closes a component when a block's lowlink equals its index. That is the order the recursion used, so the components, their order, their entry blocks and the irreducibility verdict are the same. The component bookkeeping moves unchanged into
emitComponent.Tested
main0db47b263(head2a70b8026; no conflicts), RTX 4090 (NVIDIA 616.92, Windows 11): the 9 ctest entries ofagc_structurizer,agc_shader_control_flow,scalar_callandagc_driver_compute_table_callspass 9/9, each test run three times, and 9/9 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.Structurizeand replayed natively on macOS withulimit -s 2048:mainsegfaults; with this commit it completes, 4,750 to 32,490 blocks. The rest of the fallback is slow (hasStructuredConstructstests every block for each header); that is a separate change.GraphToString, which lists every component with its entries) is byte-identical tomain's for that shader without the fallback. It is also identical tomain's on 40,000 generated graphs in each of default,APS5_NO_PERF_DOM_INTERSECTION,APS5_NO_PERF_ITERATION_SELECTIONandAPS5_FORCE_STRUCTURIZER_FALLBACK(160,000 comparisons). The generated graphs include irreducible ones, unreachable blocks and exitless loops.360682431onmain7e2ba73e4, Windows 11, RTX 4090, NVIDIA 616.92, WinLibs GCC 15.2:agc_structurizer,agc_shader_control_flow,agc_driver_compute_table_callsandscalar_callpass 9/9 with theintersection_off,iteration_selection_offandforced_fallbackvariants, each run three times (ctest --repeat until-fail:3).agc_structurizer_testsalso passes in all four modes built with AppleClang on macOS.Validation: I ran the same focused tests on this commit (
360682431) 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. The log has nowas not found but was requested by env var VK_INSTANCE_LAYERS, noVUID-line and no validation message. Before the rebase,maina6dcea927and this commit on it also 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:050af89f1mergesmain7b32a842f.agc_structurizer,agc_shader_control_flow,agc_driver_compute_table_callsandscalar_callpass 9/9 with theintersection_off,iteration_selection_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 9/9; onmain4d57821d4, five commits past the mergedmainand none incore/shader, the same tests pass 9/9. 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 clairtonmichel on 2026-10-22T09:20:12Z.
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:56Z.
Review: DISMISSED
I reviewed the iterative Tarjan conversion. The explicit frame stack preserves the recursive successor order; the parent low-link update occurs when its DFS child finishes, and component emission/bookkeeping is unchanged. I found no code defect in this diff. The author-reported 160,000 differential graph comparisons, 9/9 repeated focused tests and Vulkan-validation run are strong, but I could not independently rerun the C++ suite because this checkout has no configured product build.\n\nPlease update this branch to current
mainbefore approval. It is based on7e2ba73e4c, 13 commits behind currentmain(8b3a6ba88d8fc74e768f1a7e8e9e36fb69842768), contrary to the repository rule to keep PRs based on current main. Re-run the focused tests after the update. This is also the declared base dependency for #9702/#9703, so please coordinate the stack and ensure those PRs use the updated head.