perf(shader): validate value IR dominance with a dominator tree #9198
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9198"
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 milescoviello on 2026-10-21T15:04:38Z.
What
ValidateProgramchecks that every definition in value IR dominates its uses. It computed dominance as a full dominator-set dataflow: a blocks × blocks bit matrix iterated to a fixed point, allocating a new row for every block on every pass. That is quadratic in the block count in time and memory. In the Crimson Desert preparation profile behind #9132,ValidateProgramwas 8.5 % of the samples, 4.9 % of them its own.It now:
The checks before this point already reject unreachable blocks, foreign or duplicated edges, and an entry block with predecessors. So the graph meets the algorithm's assumptions, and the dominance relation is the same as before: a block still dominates itself, and every accept and reject is unchanged. Nothing outside
ValidateProgramchanges.The
agc_validate_programtest gains diamond and loop programs. They cover:The new cases also pass with
main's dataflow, which they should, since only the algorithm changes.Tested
Ubuntu 24.04, GCC 13.3, i7-13700K, on
main2c4b116da9(rebased ontocecb540a63since, which only changesSyncOnAddress.cpp).Tests:
agc_validate_programwith its new cases passes withmain's dataflow as well as with this change.^agc_validate_program$|^shader|^request_serializer$|^agc_shader|^agc_driver_constant|integer_narrowingpass.Same output:
agc_shader_replay --spv(release build, SPIRV-Tools off) over 409 dumped requests (MXGP 26 and Super Meat Boy 3D) writes byte-identical SPIR-V onmainand with this change.Same accepts and rejects:
agc_shader_replay --prepareover all 6,065 dumped Crimson Desert requests exits 0 on both. Both logs have 12,338 lines and no value IR validation error, and their error and failure lines are the same.Time:
perf stat -e task-clockofagc_shader_replay --prepareover 152 Crimson Desert requests,mainand this change alternated for 8 rounds:mainThat is −1.0 %, faster in all 8 rounds.
Windows 11 Enterprise 26300, WinLibs GCC 15.2.0 r7 (UCRT), Release:
agc_validate_programpasses 3 of 3 onmainand 3 of 3 with this change.Windows 11 Home 10.0.26200, NVIDIA GeForce RTX 4070 Laptop GPU (driver 616.92), WinLibs GCC 15.2.0 r7, Release, run by JulesB40 (results): this head merged onto
maind4cb89300fmatches thatmainacross all 1,125agc_tests with the Khronos validation layer on: 1,117 pass, the same 8 skip, and the same 18VUID-lines, all of them #11990's.agc_driver_submit_progresstimed out once in the first parallel run, then passed 40 of 40 alone and in a second full run.Not tested: Clang.
Performance captures
The form asks for summary lines, so here are two from a title, with a caveat: this change speeds up shader compilation, and that doesn't show in frame time. The title whose start-up is compile-bound here, Crimson Desert, presents almost no frames then (2 in its first 600 s on 10-21), so it has no window to compare. These are from Super Meat Boy 3D (PPSA31162) start-up:
ANYPS5_NO_SHADER_CACHE=1, every shader goes through the recompiler.APS5_TRACE_SECONDS=10:60, 90 s runs, pad input, no other switch.main2816bd2754and of this PR merged onto it, two rounds interleaved with the other recompiler PR.In that window the shader prepare threads are 1-4 % busy, so the frames show no difference, as expected:
main2816bd2754, run 1main, run 2The measurement of this change is the replay timing under Tested. Traces and digests for all runs are in a release on my fork.
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-21T15:04:55Z.
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 milescoviello on 2026-10-21T15:05:12Z.
About the perf label's capture request: this change only affects how long the shader recompiler's value IR validation takes on the CPU. A frame capture would show it only as part of a title's start-up stalls, mixed with everything else that varies there. So it is measured where it applies: the replay of 152 Crimson Desert registration requests, task-clock over 8 interleaved runs per build (median 17.56 → 17.38 s, faster in every round, ranges not overlapping). The 409 draw-time requests give byte-identical SPIR-V, and all 6,065 Crimson Desert requests prepare with the same error lines. If the maintainers want a title capture anyway, I can record Crimson Desert's start-up on both builds.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T11:21:17Z.
Review: APPROVED
Reviewed — approved
The dominator-tree rewrite of the dominance check in
ValidateProgramgives the same accept and reject result as brute-force dominance on 53,752 random def/use pairs, irreducible graphs included. The focused tests pass onmainand on this change with the Khronos validation layer, and I reproduced the scaling claim on a second machine.What I ran
c1c2e00446d4f18ce00fbb96e202252c274924dcmain:9181b371371a9baaa2ba82acb47d2036d14fb97c(merged with--no-ff, no conflicts)Results
maingit diff --checkcheck_conventions.pyAll conventions checks passed.libs(merged, thenmain)main)main)NVIDIA GeForce RTX 4070 Ti SUPERVUID-lines (merged /main)adding layers "VK_LAYER_KHRONOS_validation")was not found but was requested by env var VK_INSTANCE_LAYERSagc_validate_programruntimemain)Diamond-chain benchmark, median ms of 5 ValidateProgram calls, 3 alternated rounds
mainr1 / r2 / r3Each 4x in blocks costs
mainabout 15x, the B x B bit-set dataflow. This change costs 3-6x per step. The benchmark builds the same CFG as the author's (entry → (head → left/right → join) × N, the entry value used in every join), withrequireSsa = true.Fuzz construction
The fuzz builds a random spanning tree from block 0, so every block is reachable and the entry has no predecessor, then adds up to 2N random extra edges, never into block 0. Self-loops are allowed, and back and cross edges make irreducible graphs. Block numbers are then shuffled, so
blockOrderis not a topological order. Out-degree 0, 1, 2 and 3 or more useReturn,Branch,ConditionalBranchandIndirectBranch. For every ordered pair (def, use), def != use, it putsIAdd32in def and a use of it in use, then expectsValidateProgramto accept exactly when use is unreachable from the entry once def is removed. Any other rejection message would have aborted the run.Negative control
IrProgram.cpprestored frommain,agc_validate_programstill passes. This is expected: the change replaces the algorithm and keeps the relation, and the description says so.dominatestoenterNumber[def] <= enterNumber[use], dropping the exit-number half. The test then fails:diamond use of one arm's definition at the mergeanddiamond use of one arm's definition in the other armare accepted where a rejection is expected.Findings
Blocking
None.
Non-blocking
GPUs testedline. The checklist saysnone needed (shader recompiler validation only; replay on the CPU). CONTRIBUTING.md L72 asks shader recompiler changes to name each GPU the GPU tests ran on, on that line. The evidence already exists: JulesB40's RTX 4070 Laptop run, cited under Tested, the NVIDIA CI comment on an RTX 2000 Ada, and this run on an RTX 4070 Ti SUPER. Suggested fix: list at least the GPU from the author's or JulesB40's run there, with vendor, model, driver and OS.Timetable under Tested still shows −1.0 % on2c4b116da9. The later re-measures in the comments show −0.6 % with overlapping ranges, then no difference beyond noise on single large MXGP shaders. Suggested fix: replace the table with the current numbers and the diamond-chain scaling result, so the description matches the evidence the merge decision rests on. Whether this goes in asperfor as a scaling fix is the maintainer's open question in the thread. I add no evidence for a title-level gain; the benchmark above only confirms the scaling side.intersect(IrProgram.cpp L774-L780) walks partly settled dominators. The fuzz above found no mismatch there, so this is about coverage, not a bug. Suggested fix: add one irreducible case where a value defined in A is rejected in B, and one defined in the entry is accepted in both.Not verified
agc_shader_replayover title shader dumps: I have no dumps, so the byte-identical SPIR-V claim and the replay timings are the author's.agc_suite. The NVIDIA CI comment and JulesB40's run cover the wider set, on the earlier head8fb5e96582.