perf(shader): validate value IR dominance with a dominator tree #9198

Merged
milescoviello merged 1 commit from upstream-pr/9198 into main 2026-11-05 03:59:23 +00:00
milescoviello commented 2026-10-21 15:04:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T15:04:38Z.


What

ValidateProgram checks 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, ValidateProgram was 8.5 % of the samples, 4.9 % of them its own.

It now:

  1. walks the CFG once for a reverse post-order;
  2. builds the dominator tree with the Cooper–Harvey–Kennedy iteration over it;
  3. numbers the tree in one walk;
  4. answers each dominance query by comparing the two blocks' entry and exit numbers.

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 ValidateProgram changes.

The agc_validate_program test gains diamond and loop programs. They cover:

  • uses dominated by their definition;
  • a merge use of one arm's value, and a use from the other arm;
  • a Phi whose incoming value doesn't dominate its edge;
  • a branch condition defined in an arm;
  • a loop body using a value defined after the loop.

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 main 2c4b116da9 (rebased onto cecb540a63 since, which only changes SyncOnAddress.cpp).

  • Tests:

    • agc_validate_program with its new cases passes with main's dataflow as well as with this change.
    • The 43 tests matching ^agc_validate_program$|^shader|^request_serializer$|^agc_shader|^agc_driver_constant|integer_narrowing pass.
  • 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 on main and with this change.

  • Same accepts and rejects: agc_shader_replay --prepare over 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-clock of agc_shader_replay --prepare over 152 Crimson Desert requests, main and this change alternated for 8 rounds:

    Build median min max
    main 17.56 s 17.41 s 17.67 s
    this change 17.38 s 17.28 s 17.40 s

    That is −1.0 %, faster in all 8 rounds.

  • Windows 11 Enterprise 26300, WinLibs GCC 15.2.0 r7 (UCRT), Release: agc_validate_program passes 3 of 3 on main and 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 main d4cb89300f matches that main across all 1,125 agc_ tests with the Khronos validation layer on: 1,117 pass, the same 8 skip, and the same 18 VUID- lines, all of them #11990's. agc_driver_submit_progress timed 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:

  • With ANYPS5_NO_SHADER_CACHE=1, every shader goes through the recompiler.
  • APS5_TRACE_SECONDS=10:60, 90 s runs, pad input, no other switch.
  • Release libraries of main 2816bd2754 and of this PR merged onto it, two rounds interleaved with the other recompiler PR.
  • Linux, RTX 4070 Ti, NVIDIA 615.71.09.

In that window the shader prepare threads are 1-4 % busy, so the frames show no difference, as expected:

presents frame p50
main 2816bd2754, run 1 513 134.2 ms
this PR merged onto it (ab78c88d7d), run 1 470 143.0 ms
main, run 2 459 138.6 ms
this PR, run 2 473 136.6 ms

The measurement of this change is the replay timing under Tested. Traces and digests for all runs are in a release on my fork.

{"commit":"2816bd275452","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"10:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA31162","title":"Super Meat Boy 3D","content_version":"02.000.001","resolution":"3840x2160","window":{"spec":"seconds 10:60","first_present":24,"ms":60058.966},"presents":513,"frame_ms":{"p50":134.233,"p90":165.070,"p99":217.141,"max":2955.273},"gpu_busy_ms_per_present":89.154,"worker_busy_pct":{"queue worker 0x0":95.177,"queue worker 0x20":93.562},"top_phases_ms_per_frame":{"Driver.Packet":220.791,"Driver.Packet.memory_wait":106.956,"Driver.Packet.dispatch":63.396,"Driver.Dispatch":62.994,"Recorder.Sync":44.242,"GpuMutex.wait.hook":40.453,"Graphics.Draw":32.101,"Graphics.Draw.draw_and_resource_release":29.659},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":28.862,"events_lost":450991,"totals_full":false}},"trace":"aps5-trace-2816bd275452-3.json.gz"}
{"commit":"ab78c88d7dfd","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"10:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA31162","title":"Super Meat Boy 3D","content_version":"02.000.001","resolution":"3840x2160","window":{"spec":"seconds 10:60","first_present":25,"ms":60123.073},"presents":470,"frame_ms":{"p50":142.981,"p90":179.712,"p99":290.007,"max":2875.445},"gpu_busy_ms_per_present":95.820,"worker_busy_pct":{"queue worker 0x0":95.348,"queue worker 0x20":94.127},"top_phases_ms_per_frame":{"Driver.Packet":242.322,"Driver.Packet.memory_wait":118.551,"Driver.Packet.dispatch":62.927,"Driver.Dispatch":62.630,"Recorder.Sync":43.322,"Graphics.Draw":41.600,"Graphics.Draw.draw_and_resource_release":38.966,"Driver.Packet.pipeline_drain":35.181},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":28.707,"events_lost":428371,"totals_full":false}},"trace":"aps5-trace-ab78c88d7dfd-3.json.gz"}

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: none needed (shader recompiler validation only; replay on the CPU)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4953756484 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9198). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T15:04:38Z. --- ### What `ValidateProgram` checks 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, `ValidateProgram` was 8.5 % of the samples, 4.9 % of them its own. It now: 1. walks the CFG once for a reverse post-order; 2. builds the dominator tree with the Cooper–Harvey–Kennedy iteration over it; 3. numbers the tree in one walk; 4. answers each dominance query by comparing the two blocks' entry and exit numbers. 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 `ValidateProgram` changes. The `agc_validate_program` test gains diamond and loop programs. They cover: - uses dominated by their definition; - a merge use of one arm's value, and a use from the other arm; - a Phi whose incoming value doesn't dominate its edge; - a branch condition defined in an arm; - a loop body using a value defined after the loop. 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 `main` 2c4b116da9 (rebased onto cecb540a63 since, which only changes `SyncOnAddress.cpp`). - **Tests:** - `agc_validate_program` with its new cases passes with `main`'s dataflow as well as with this change. - The 43 tests matching `^agc_validate_program$|^shader|^request_serializer$|^agc_shader|^agc_driver_constant|integer_narrowing` pass. - **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 on `main` and with this change. - **Same accepts and rejects:** `agc_shader_replay --prepare` over 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-clock` of `agc_shader_replay --prepare` over 152 Crimson Desert requests, `main` and this change alternated for 8 rounds: | Build | median | min | max | |---|---|---|---| | `main` | 17.56 s | 17.41 s | 17.67 s | | this change | 17.38 s | 17.28 s | 17.40 s | That is −1.0 %, faster in all 8 rounds. - Windows 11 Enterprise 26300, WinLibs GCC 15.2.0 r7 (UCRT), Release: `agc_validate_program` passes 3 of 3 on `main` and 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](https://github.com/boykopovar/AnyPS5/pull/9198#issuecomment-6473137324)): this head merged onto `main` `d4cb89300f` matches that `main` across all 1,125 `agc_` tests with the Khronos validation layer on: 1,117 pass, the same 8 skip, and the same 18 `VUID-` lines, all of them #11990's. `agc_driver_submit_progress` timed 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: - With `ANYPS5_NO_SHADER_CACHE=1`, every shader goes through the recompiler. - `APS5_TRACE_SECONDS=10:60`, 90 s runs, pad input, no other switch. - Release libraries of `main` 2816bd2754 and of this PR merged onto it, two rounds interleaved with the other recompiler PR. - Linux, RTX 4070 Ti, NVIDIA 615.71.09. In that window the shader prepare threads are 1-4 % busy, so the frames show no difference, as expected: | | presents | frame p50 | |---|---|---| | `main` 2816bd2754, run 1 | 513 | 134.2 ms | | this PR merged onto it (ab78c88d7d), run 1 | 470 | 143.0 ms | | `main`, run 2 | 459 | 138.6 ms | | this PR, run 2 | 473 | 136.6 ms | The measurement of this change is the replay timing under Tested. Traces and digests for all runs are in a [release on my fork](https://github.com/milescoviello/AnyPS5/releases/tag/traces-recompiler-perf-smb3d). ```json {"commit":"2816bd275452","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"10:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA31162","title":"Super Meat Boy 3D","content_version":"02.000.001","resolution":"3840x2160","window":{"spec":"seconds 10:60","first_present":24,"ms":60058.966},"presents":513,"frame_ms":{"p50":134.233,"p90":165.070,"p99":217.141,"max":2955.273},"gpu_busy_ms_per_present":89.154,"worker_busy_pct":{"queue worker 0x0":95.177,"queue worker 0x20":93.562},"top_phases_ms_per_frame":{"Driver.Packet":220.791,"Driver.Packet.memory_wait":106.956,"Driver.Packet.dispatch":63.396,"Driver.Dispatch":62.994,"Recorder.Sync":44.242,"GpuMutex.wait.hook":40.453,"Graphics.Draw":32.101,"Graphics.Draw.draw_and_resource_release":29.659},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":28.862,"events_lost":450991,"totals_full":false}},"trace":"aps5-trace-2816bd275452-3.json.gz"} ``` ```json {"commit":"ab78c88d7dfd","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"10:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA31162","title":"Super Meat Boy 3D","content_version":"02.000.001","resolution":"3840x2160","window":{"spec":"seconds 10:60","first_present":25,"ms":60123.073},"presents":470,"frame_ms":{"p50":142.981,"p90":179.712,"p99":290.007,"max":2875.445},"gpu_busy_ms_per_present":95.820,"worker_busy_pct":{"queue worker 0x0":95.348,"queue worker 0x20":94.127},"top_phases_ms_per_frame":{"Driver.Packet":242.322,"Driver.Packet.memory_wait":118.551,"Driver.Packet.dispatch":62.927,"Driver.Dispatch":62.630,"Recorder.Sync":43.322,"Graphics.Draw":41.600,"Graphics.Draw.draw_and_resource_release":38.966,"Driver.Packet.pipeline_drain":35.181},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":28.707,"events_lost":428371,"totals_full":false}},"trace":"aps5-trace-ab78c88d7dfd-3.json.gz"} ``` ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: none needed (shader recompiler validation only; replay on the CPU) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-21 15:04:55 +00:00 (Migrated from github.com)

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 on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6319279026 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9198#issuecomment-6319279026). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T15:04:55Z. --- <!-- pr-labels-perf --> This pull request is labeled `perf`, so it needs the summary line of a capture on `main` and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both `aps5-summary.jsonl` lines, attach the two traces and add the output of `tools/trace_digest.py`.
milescoviello commented 2026-10-21 15:05:12 +00:00 (Migrated from github.com)

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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6319283513 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9198#issuecomment-6319283513). Originally posted by [milescoviello](https://github.com/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)
XairRrR commented 2026-10-29 11:21:17 +00:00 (Migrated from github.com)

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 ValidateProgram gives the same accept and reject result as brute-force dominance on 53,752 random def/use pairs, irreducible graphs included. The focused tests pass on main and on this change with the Khronos validation layer, and I reproduced the scaling claim on a second machine.

What I ran

  • PR head: c1c2e00446d4f18ce00fbb96e202252c274924dc
  • main: 9181b371371a9baaa2ba82acb47d2036d14fb97c (merged with --no-ff, no conflicts)
  • Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08)
git fetch origin main pull/9198/head:refs/review/9198
git checkout --detach origin/main && git merge --no-ff --no-edit refs/review/9198
git diff --check origin/main...refs/review/9198
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 && cmake --build build -j10 --target libs agc_validate_program_tests

# focused set A (62 tests) and control-flow GPU set B (12 tests), merged tree and main
P='^agc_validate_program$|^shader|^request_serializer$|^agc_shader|^agc_driver_constant|integer_narrowing|^agc_structurizer|^agc_ir_reclaim$'
P2='^agc_driver$|^agc_driver_graphics$|^agc_driver_branch_past_endpgm$|^agc_driver_lds_subword_store_branch$|^agc_driver_loop_ending_exits$|^agc_driver_paired_wave_zero_branches$|^agc_driver_subvector_loop$|^agc_driver_user_data_call_after_branch$|^agc_spirv_branch_targets$|^agc_spirv_subvector_loop_begin$|^agc_branch_patch_tests$|^control_flow_graph$'
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \
  ctest --test-dir build -R "$P" -j4 -V --output-on-failure      # and -R "$P2"

# negative control and mutant
git checkout origin/main -- core/shader/recompiler/IntermediateRepresentation/src/IrProgram.cpp
cmake --build build --target agc_validate_program_tests && build/tests/agc_validate_program_tests
# then dominates() reduced to enterNumber[def] <= enterNumber[use], rebuilt and rerun

# out-of-tree differential fuzz + diamond-chain benchmark (not part of the PR),
# linked against libshader_recompiler_agc_driver.a of each tree
fuzz            # 400 random CFGs of 2-20 blocks, every def/use pair vs. brute-force dominance
fuzz bench      # chain of N diamonds, ValidateProgram x5 per size; 3 rounds alternated main/PR

Results

Check Result
Merge onto main Clean
git diff --check Clean
check_conventions.py All conventions checks passed.
Full build + libs (merged, then main) Built
Set A, 62 tests (merged / main) 62/62 pass / 62/62 pass
Set B, 12 control-flow GPU tests (merged / main) 12/12 pass / 12/12 pass, device NVIDIA GeForce RTX 4070 Ti SUPER
VUID- lines (merged / main) 0 / 0 in both sets; the layer was loaded (adding layers "VK_LAYER_KHRONOS_validation")
was not found but was requested by env var VK_INSTANCE_LAYERS Not present in any of the four logs
agc_validate_program runtime 0.00 s
Differential fuzz vs. brute force (merged / main) 53,752 pairs, 6,166 dominated, 0 mismatches / same
Diamond-chain benchmark About 170x faster at 16,385 blocks; matches the author's table
Diamond-chain benchmark, median ms of 5 ValidateProgram calls, 3 alternated rounds
IR blocks main r1 / r2 / r3 PR r1 / r2 / r3
65 0.035 / 0.034 / 0.035 0.021 / 0.020 / 0.015
257 0.313 / 0.312 / 0.313 0.077 / 0.078 / 0.055
1,025 4.186 / 4.172 / 4.180 0.309 / 0.223 / 0.218
4,097 63.18 / 63.22 / 63.05 1.179 / 0.957 / 0.954
16,385 1004.7 / 1006.3 / 1004.6 5.865 / 5.712 / 5.891

Each 4x in blocks costs main about 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), with requireSsa = 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 blockOrder is not a topological order. Out-degree 0, 1, 2 and 3 or more use Return, Branch, ConditionalBranch and IndirectBranch. For every ordered pair (def, use), def != use, it puts IAdd32 in def and a use of it in use, then expects ValidateProgram to accept exactly when use is unreachable from the entry once def is removed. Any other rejection message would have aborted the run.

Negative control

  • With only IrProgram.cpp restored from main, agc_validate_program still passes. This is expected: the change replaces the algorithm and keeps the relation, and the description says so.
  • To check that the new cases can tell a wrong dominance relation from a right one, I reduced dominates to enterNumber[def] <= enterNumber[use], dropping the exit-number half. The test then fails: diamond use of one arm's definition at the merge and diamond use of one arm's definition in the other arm are accepted where a rejection is expected.
  • The merged file was restored afterwards.

Findings

Blocking

None.

Non-blocking

  1. GPUs tested line. The checklist says none 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.
  2. Stale timing in the description. The Time table under Tested still shows −1.0 % on 2c4b116da9. 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 as perf or 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.
  3. No irreducible case in the new tests. The new cases (ValidateProgram.cpp L202-L262) cover a diamond and a single-block loop. They do not cover an irreducible graph, such as entry → A, entry → B, A ↔ B. On an irreducible graph the Cooper–Harvey–Kennedy iteration needs more than one pass, and 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

  • Clang and Windows builds: not built here. The description and the comments report Windows/GCC runs.
  • agc_shader_replay over title shader dumps: I have no dumps, so the byte-identical SPIR-V claim and the replay timings are the author's.
  • I ran only the 74 focused tests above, not the full agc_ suite. The NVIDIA CI comment and JulesB40's run cover the wider set, on the earlier head 8fb5e96582.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5696856366 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9198#pullrequestreview-5696856366). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T11:21:17Z. **Review:** APPROVED --- # Reviewed — approved The dominator-tree rewrite of the dominance check in `ValidateProgram` gives the same accept and reject result as brute-force dominance on 53,752 random def/use pairs, irreducible graphs included. The focused tests pass on `main` and on this change with the Khronos validation layer, and I reproduced the scaling claim on a second machine. ## What I ran - PR head: `c1c2e00446d4f18ce00fbb96e202252c274924dc` - `main`: `9181b371371a9baaa2ba82acb47d2036d14fb97c` (merged with `--no-ff`, no conflicts) - Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08) ``` git fetch origin main pull/9198/head:refs/review/9198 git checkout --detach origin/main && git merge --no-ff --no-edit refs/review/9198 git diff --check origin/main...refs/review/9198 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 && cmake --build build -j10 --target libs agc_validate_program_tests # focused set A (62 tests) and control-flow GPU set B (12 tests), merged tree and main P='^agc_validate_program$|^shader|^request_serializer$|^agc_shader|^agc_driver_constant|integer_narrowing|^agc_structurizer|^agc_ir_reclaim$' P2='^agc_driver$|^agc_driver_graphics$|^agc_driver_branch_past_endpgm$|^agc_driver_lds_subword_store_branch$|^agc_driver_loop_ending_exits$|^agc_driver_paired_wave_zero_branches$|^agc_driver_subvector_loop$|^agc_driver_user_data_call_after_branch$|^agc_spirv_branch_targets$|^agc_spirv_subvector_loop_begin$|^agc_branch_patch_tests$|^control_flow_graph$' VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \ ctest --test-dir build -R "$P" -j4 -V --output-on-failure # and -R "$P2" # negative control and mutant git checkout origin/main -- core/shader/recompiler/IntermediateRepresentation/src/IrProgram.cpp cmake --build build --target agc_validate_program_tests && build/tests/agc_validate_program_tests # then dominates() reduced to enterNumber[def] <= enterNumber[use], rebuilt and rerun # out-of-tree differential fuzz + diamond-chain benchmark (not part of the PR), # linked against libshader_recompiler_agc_driver.a of each tree fuzz # 400 random CFGs of 2-20 blocks, every def/use pair vs. brute-force dominance fuzz bench # chain of N diamonds, ValidateProgram x5 per size; 3 rounds alternated main/PR ``` ## Results | Check | Result | |---|---| | Merge onto `main` | Clean | | `git diff --check` | Clean | | `check_conventions.py` | `All conventions checks passed.` | | Full build + `libs` (merged, then `main`) | Built | | Set A, 62 tests (merged / `main`) | 62/62 pass / 62/62 pass | | Set B, 12 control-flow GPU tests (merged / `main`) | 12/12 pass / 12/12 pass, device `NVIDIA GeForce RTX 4070 Ti SUPER` | | `VUID-` lines (merged / `main`) | 0 / 0 in both sets; the layer was loaded (`adding layers "VK_LAYER_KHRONOS_validation"`) | | `was not found but was requested by env var VK_INSTANCE_LAYERS` | Not present in any of the four logs | | `agc_validate_program` runtime | 0.00 s | | Differential fuzz vs. brute force (merged / `main`) | 53,752 pairs, 6,166 dominated, 0 mismatches / same | | Diamond-chain benchmark | About 170x faster at 16,385 blocks; matches the author's table | <details><summary>Diamond-chain benchmark, median ms of 5 ValidateProgram calls, 3 alternated rounds</summary> | IR blocks | `main` r1 / r2 / r3 | PR r1 / r2 / r3 | |---|---|---| | 65 | 0.035 / 0.034 / 0.035 | 0.021 / 0.020 / 0.015 | | 257 | 0.313 / 0.312 / 0.313 | 0.077 / 0.078 / 0.055 | | 1,025 | 4.186 / 4.172 / 4.180 | 0.309 / 0.223 / 0.218 | | 4,097 | 63.18 / 63.22 / 63.05 | 1.179 / 0.957 / 0.954 | | 16,385 | 1004.7 / 1006.3 / 1004.6 | 5.865 / 5.712 / 5.891 | Each 4x in blocks costs `main` about 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), with `requireSsa = true`. </details> <details><summary>Fuzz construction</summary> 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 `blockOrder` is not a topological order. Out-degree 0, 1, 2 and 3 or more use `Return`, `Branch`, `ConditionalBranch` and `IndirectBranch`. For every ordered pair (def, use), def != use, it puts `IAdd32` in def and a use of it in use, then expects `ValidateProgram` to accept exactly when use is unreachable from the entry once def is removed. Any other rejection message would have aborted the run. </details> ## Negative control - With only `IrProgram.cpp` restored from `main`, `agc_validate_program` still passes. This is expected: the change replaces the algorithm and keeps the relation, and the description says so. - To check that the new cases can tell a wrong dominance relation from a right one, I reduced `dominates` to `enterNumber[def] <= enterNumber[use]`, dropping the exit-number half. The test then fails: `diamond use of one arm's definition at the merge` and `diamond use of one arm's definition in the other arm` are accepted where a rejection is expected. - The merged file was restored afterwards. ## Findings ### Blocking None. ### Non-blocking 1. **`GPUs tested` line.** The checklist says `none needed (shader recompiler validation only; replay on the CPU)`. [CONTRIBUTING.md L72](https://github.com/boykopovar/AnyPS5/blob/9181b371371a9baaa2ba82acb47d2036d14fb97c/CONTRIBUTING.md#L72-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. 2. **Stale timing in the description.** The `Time` table under Tested still shows −1.0 % on `2c4b116da9`. 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 as `perf` or 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. 3. **No irreducible case in the new tests.** The new cases ([ValidateProgram.cpp L202-L262](https://github.com/boykopovar/AnyPS5/blob/c1c2e00446d4f18ce00fbb96e202252c274924dc/core/libs/prx/libSceAgcDriver/tests/ValidateProgram.cpp#L202-L262)) cover a diamond and a single-block loop. They do not cover an irreducible graph, such as entry → A, entry → B, A ↔ B. On an irreducible graph the Cooper–Harvey–Kennedy iteration needs more than one pass, and `intersect` ([IrProgram.cpp L774-L780](https://github.com/boykopovar/AnyPS5/blob/c1c2e00446d4f18ce00fbb96e202252c274924dc/core/shader/recompiler/IntermediateRepresentation/src/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 - Clang and Windows builds: not built here. The description and the comments report Windows/GCC runs. - `agc_shader_replay` over title shader dumps: I have no dumps, so the byte-identical SPIR-V claim and the replay timings are the author's. - I ran only the 74 focused tests above, not the full `agc_` suite. The NVIDIA CI comment and JulesB40's run cover the wider set, on the earlier head `8fb5e96582`.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9198
No description provided.