test(recompiler): check seeded structurizer outputs for exact equivalence #4964
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4964"
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-13T06:39:51Z.
What
#4926 makes
Structurizer::Structurizestructure every graph built from branch, conditional branch and return blocks: the existing ladder runs first, and a reach-flag construction takes over when the ladder refuses. The in-tree tests check hand-picked graphs (agc_structurizer) and RDNA programs (agc_shader_control_flow). The evidence that both paths keep every execution of the input came from an oracle outside the repository. This PR adds a condensed version of that oracle as a test, so every CI run checks the same properties on 2000 graphs.agc_structurizer_equivalencebuilds its graphs from fixed seeds (no clock, norandom_device). Each graph has 2 to 24 blocks:Structurizemust succeed on a copy of each graph. The output must then pass three checks, none of which reuses structurizer code:after decisions "--F-T" through original blocks 9 13 8 5 6 15: the input runs original block 15 but the structured graph runs block 32 with instructions [22, 24).ANYPS5_ENABLE_SPIRV_TOOLS, the same switch under whichRecompilevalidates the modules ofagc_shader_control_flow). The test emits a skeleton module with the blocks laid out the waySpirvFlowEmitteremits them: the two-block entry prologue,OpLoopMergeon loop headers,OpSelectionMergeon the other conditional branches that have a merge,OpBranchConditionalonOpUndefbooleans, andOpReturnfor returns. The module must validate for SPIR-V 1.3 (Vulkan 1.1) and 1.4. Since #4580 the emitter writesOpBranchfor a conditional branch whose two targets are the same block, and the skeleton does the same. The SPIR-V 1.6 rule against equal labels therefore cannot fire, and 1.6 is not checked separately.agc_structurizer_equivalence_forced_fallbackruns the same graphs withAPS5_FORCE_STRUCTURIZER_FALLBACK=1. Both tests are registered like the neighbouring structurizer tests:ANYPS5_NO_SHADER_CACHE=1, the source tree as working directory, andlibconPATHon Windows. SPIRV-Tools is linked only when it is enabled.The corpus has limits that keep the default run at about 2 s:
Without these limits, the ladder can spend tens of seconds on a single graph of 11 to 24 blocks before it accepts or refuses it (42 s on one 20-block graph). That is the ladder runtime limit #4926 lists, and this test does not measure it. GraphBuilder shapes (jump-table compare chains, the empty end block) stay covered by
agc_shader_control_flow.Tested
WSL2 Ubuntu 26.04 with GCC 15.2.0, configured like CI (Release, SPIRV-Tools ON, ccache), on top of #4926. Native Windows 11 with WinLibs GCC 15.2.0, SPIRV-Tools OFF as in the Windows CI job. No title.
ctest -R 'structurizer|control_flow': 10 of 10 pass in three runs.agc_structurizer_equivalencetakes 2.0 s andagc_structurizer_equivalence_forced_fallback1.0 s, with the same times under--parallel 4.tools/check_test_registration.pypasses on both build trees.tools/check_conventions.py --base origin/mainpasses, with both the branch's checker andmain's.hasStructuredConstructsrejects and SPIRV-Tools accepts.Structurizer.cppand ran both tests on it. The counts are failing graphs out of 2000. On the same outputs I also ran the contract, the equivalence search and SPIR-V validation one at a time, to show which check catches which mutant.Structurizer.cppagc_structurizer_equivalence..._forced_fallbackappendJunctionhasStructuredConstructsalways returns trueorderByDominancenever reordersorderByDominance"Self-check off" means
hasStructuredConstructsalso returns true. Without that, the structurizer rejects its own output,Structurizethrows, and the test fails on that instead.The last mutant survives because it changes nothing: the fallback already emits blocks in dominance order, and
orderByDominancereturns early on such graphs. WhenorderByDominancenever reorders, 500 outputs keep their entry at another block than block 0; the equivalence search starts at block 0, as the translator does, and catches all of them.Four outputs of the
hasStructuredConstructsmutant break construct rules that only SPIRV-Tools checks: a branch into a selection construct that bypasses its header, and a loop exit that is not a structured exit. Builds without SPIRV-Tools, such as the Windows CI job, do not check these two rules. In the other direction, the contract rejects one output that SPIRV-Tools accepts: a conditional branch without a merge that does not leave its loop.Of 21 further mutants (edge redirection, clone edges, reuse and clearing of route variables, the fallback's again flags, guards and loop heads, and single
hasStructuredConstructsrules), 17 fail the test. The other 4 change no behaviour: the oracle accepts all of their outputs too. On the outputs of 12 of these mutants and of the last six mutants in the table, the oracle rejects no output that the test accepts.main4bb2c7f39and #4926: the structurizer, control-flow and shader tests pass (20 of 20),agc_structurizer_equivalencein 2.0 s and its forced variant in 1.0 s.Rebased with #4926 onto
main30f961266. The conflicts were indocs/dev/debt/shader.md, wheremainadded entries next to #4926's, and earlier the test list incore/libs/prx/libSceAgcDriver/CMakeLists.txt; both sides are kept and the changed lines are identical. WSL2 Ubuntu 26.04, lavapipe (Mesa 26.0.8), CI configuration: the structurizer, control-flow and shader tests 20 of 20, fullctest1087 of 1087.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-13T23:26:03Z.
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.mdL116core/libs/prx/libSceAgcDriver/CMakeLists.txtL1280docs/dev/debt/shader.mdL116docs/dev/debt/shader.mdL116docs/dev/debt/shader.mdL116Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-14T07:13:44Z.
Closing this together with #4926, which it builds on, following the request there to hold off on pull requests that do not name a title needing the change while the queue is this long. The branch stays; if a title stops on refused control flow on current
main, I will reopen with the title ID and the log line.Pull request closed