feat(recompiler): structure every control-flow graph the structurizer refuses #4926
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4926"
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 nikowolf123 on 2026-10-13T04:36:26Z.
What
A structurizer refusal stops the title:
Recompilememoizes it per source and the dispatch or draw that needs the shader turns it into a sticky driver failure. The structurizer has grown a ladder of retries (two attempt series of up to four configurations) that each refuse some shapes. Measured onmainwith the oracle described under Tested, on 200,000 random graphs of 2 to 32 blocks: of the 82,743 reducible graphs whose every block reaches a return, 3,041 (3.7%) are refused. Irreducible graphs and graphs with a cycle that never exits are refused by design (114,667 in that corpus).This PR adds a construction that structures every graph built from branch, conditional branch and return blocks, and uses it only when the ladder refuses:
s_barrierkeeps one copy.APS5_FORCE_STRUCTURIZER_FALLBACK=1uses the construction for every graph; it is part of the shader cache key.This is the textbook state-variable construction (Böhm and Jacopini; Ashcroft and Manna) applied to the structurizer's own route variables. It costs about 8 times the input's blocks and one variable per block, which the technical debt entry records with the other limits below.
Limits:
main) it spends more than 10 s before it accepts or refuses, and this PR does not shorten that.No open PR changes
Structurizer.cpp. #2762 concerns ladder outputs that are invalid SPIR-V; this PR does not change ladder outputs.Tested
WSL2 Ubuntu 26.04, GCC 15.2.0, configured like CI (Release, SPIRV-Tools ON, lavapipe), and native Windows 11 with WinLibs GCC 15.2.0 on an RTX 5080 (NVIDIA 616.92). No title.
In-tree:
agc_structurizerstructure eight graphs thatmainrefuses (a duplicate merge, a region that wraps around to its dominator, the merge-splitting budget, a conditional without a structured merge, an irreducible entry and three loops that never exit) and the #2642 two-latch loop, whichmainaccepts. Each must give structured branches, every original block exactly once and the same executions as the input for every branch decision.agc_structurizer_forced_fallbackandagc_shader_control_flow_forced_fallbackrun the in-tree graphs and the 35 RDNA programs through the fallback, throughRecompileand SPIR-V validation before and after spirv-opt, for 32 and 64 lanes.ctestin the CI configuration onmaine51428bf2: 1014 tests, 0 failed.tools/check_skips.pyflags onlyguest_video_out_high_frame_rate, which skips because the WSL display has no 120 Hz mode, as it does onmain.ctest(ANYPS5_REQUIRE_VULKAN=1): 1030 tests, 0 failed, 7 skipped astools/check_skips.py --job windowsexpects.APS5_FORCE_STRUCTURIZER_FALLBACK=1 ANYPS5_NO_SHADER_CACHE=1, so that every shader of every GPU execution test is structured by the fallback and runs on the RTX 5080: 1028 of 1030 pass. The two failures check analysis output, not GPU results.agc_shader_memoryexpects a descriptor phi with two candidates and gets a third from a guarded path that never runs (the planning limit above).agc_scalar_select_maskruns programs through its own evaluator, which does not model route variables.Out of tree, with an oracle that shares no code with the structurizer (outside the repository; I can attach it). For every output it checks the graph contract (dense ids, exact successors and predecessors, reachability, dominator order, one latch per loop, unique merges, synthetic block shapes), runs SPIRV-Tools on a skeleton module emitted exactly as
SpirvFlowEmitterlays out blocks and merges, at SPIR-V 1.3, 1.4 and 1.6, and decides semantic equivalence exactly: a search over pairs of (input block, output block and live route-variable values) that compares the original block reached next for every branch decision, loops included. It was checked against 593,159 mutated outputs and an independent simulator, with no missed difference.main, 200,000 graphs: every one of the 81,072 accepted graphs is valid at 1.3 and 1.4 and equivalent; 30,220 of them contain a conditional with equal targets, which only 1.6 rejects (the #4580 topic). 117,708 graphs are refused, 3,041 of them reducible and terminating, and 1,220 run past 10 s.mainaccepts give byte-identical outputs. Every graphmainrefuses (117,708) gives a valid, equivalent output. No graph is refused.maincac4e9688: fullctestin the CI configuration, with this PR and its follow-up on top, 1032 tests, 0 failed. Then onto4bb2c7f39, where only the technical debt file conflicted: the structurizer, control-flow and shader tests, 18 of 18.Checklist
main; no other open PR implements the same functionsNotImplemented_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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T01:37:49Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/shader.mdL117docs/dev/debt/shader.mdL117docs/dev/debt/shader.mdL117docs/dev/debt/shader.mdL117Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:36:07Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.