perf(shader): isolate structural tables and dominator reuse #545

Manually merged
github merged 2 commits from github-bot/gh-545 into main 2026-12-05 17:30:38 +00:00 AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-05 02:41 UTC · original
tommiehansen:review-split/402-mechanical → main · +420 −201 · 1 files · 2 commits · merged 2026-12-05 17:28 UTC

Review split from #402, based on current upstream main. The diff contains this one slice.

Linux shader suite: 298 passed and 2 ignored. The audit job failed the inherited launcher-switch documentation check tracked in #528.

Exact pinned CI evidence

No hardware timing or gameplay results. The original PR remains available until maintainers choose the integration order.

Post-review follow-up — 2026-12-05

Head: ccfd8463fef495ec0629b4814cb9fa0dce324765.

The follow-up preserves separate instruction and phi namespaces through a sparse lookup fallback for programs with unreachable blocks or a NONE value. Normal reachable SSA retains the dense table. Added regressions for a dead-write/live-phi collision and the NONE sentinel. This does not require #546 to be merged first, though #546 removes the underlying unreachable-block issue.

Fresh pinned debug/release CI started; new test and performance results must be reported at this head. Previous validation is retained at its original revision.

Standard CI raw-artifact follow-up (2026-12-05)

Synthetic CPU workload Base (ms) Candidate (ms) Paired time change
Guard-run structurisation 17.9165 17.4830 −2.57%

Identical output digest; reported 95% CI −2.90% to −2.24%. Four complete ABBA blocks, eight runs per arm. Independently checked all 16 raw checkpoint revisions, per-run sample concatenation, medians and digests against results.json. The Python review gate incorrectly interprets rounds=8 (runs per arm) as eight ABBA blocks; its automatic verdict remains inconclusive pending a harness fix. The CIs above, where stated, are the Rust report's per-workload estimates. Generic software Vulkan control passed with identical SPIR-V, not activation of this PR. No physical GPU or gameplay FPS claim. Pinned CI/artifacts.

**@⁠tommiehansen** on GitHub · 2026-12-05 02:41 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/545) `tommiehansen:review-split/402-mechanical` → `main` · +420 −201 · 1 files · 2 commits · merged 2026-12-05 17:28 UTC Review split from #402, based on current upstream main. The diff contains this one slice. Linux shader suite: 298 passed and 2 ignored. The audit job failed the inherited launcher-switch documentation check tracked in #528. [Exact pinned CI evidence](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47466412636/job/145504218704) No hardware timing or gameplay results. The original PR remains available until maintainers choose the integration order. ### Post-review follow-up — 2026-12-05 Head: `ccfd8463fef495ec0629b4814cb9fa0dce324765`. The follow-up preserves separate instruction and phi namespaces through a sparse lookup fallback for programs with unreachable blocks or a NONE value. Normal reachable SSA retains the dense table. Added regressions for a dead-write/live-phi collision and the NONE sentinel. This does not require #546 to be merged first, though #546 removes the underlying unreachable-block issue. [Fresh pinned debug/release CI](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47499397549) started; new test and performance results must be reported at this head. Previous validation is retained at its original revision. ### Standard CI raw-artifact follow-up (2026-12-05) | Synthetic CPU workload | Base (ms) | Candidate (ms) | Paired time change | |---|---:|---:|---:| | Guard-run structurisation | 17.9165 | 17.4830 | −2.57% | Identical output digest; reported 95% CI −2.90% to −2.24%. Four complete ABBA blocks, eight runs per arm. Independently checked all 16 raw checkpoint revisions, per-run sample concatenation, medians and digests against results.json. The Python review gate incorrectly interprets `rounds=8` (runs per arm) as eight ABBA blocks; its automatic verdict remains inconclusive pending a harness fix. The CIs above, where stated, are the Rust report's per-workload estimates. Generic software Vulkan control passed with identical SPIR-V, not activation of this PR. No physical GPU or gameplay FPS claim. [Pinned CI/artifacts](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47512649200/job/145651188797).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 02:41:29 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 06:34 UTC · original

Checked a6ca7d3 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). Merge base is b581f7e, current main.

I went through every changed function and it reads as a straight refactor to me. The inline reducibility check in Lanes::new (structure.rs:1034) is the same loop as ir::irreducible_edge, same edge order and same from block, so the error offset doesn't change, and the idom table is now computed once instead of twice. ir::idoms works from preds where the old compute_idoms worked from the exits, which is only the same thing if preds is current. Every place that rewrites exits in ir.rs calls link after it, so it holds. Unreachable blocks come back as usize::MAX instead of None, and dominates and the dominator-chain walk in the owner pass check for that explicitly. The expect/unwrap that became debug_assert_ne! (structure.rs:1202, 3357) still panic in release, because the next index[] lookup with usize::MAX is out of bounds, so a broken invariant doesn't go quiet. Moving the WQM discovery into structure_wide (structure.rs:864) does the same work main's helped() did on its own Lanes, then rebuilds a fresh one, so the BDD table starts clean as before. In helped_now and check_joins the clones became index loops. That's fine because mask only appends to joins/phi_joins while the loop runs and reset can't be reached from there, and the short-circuit order (and so the BDD node order) is the same.

One difference only shows up on programs with dead blocks. Main kept defs and phis in two maps, and locs (structure.rs:1069) puts both in one slot per value. Dead blocks keep the stale value ids from the program they were cloned from, and rename never visits them. If such a stale write reuses the id of a live phi, the phi lookup now misses where main still found it. #546 prunes those blocks before rename, so with that merged nothing like this reaches structure. The one suite program that does hit structure with a dead block had no such collision. Also, the max_val scan at structure.rs:1054 has no NONE guard, while #547 adds one to the same kind of scan. I couldn't find a way for a NONE phi or write value to reach structure, but if one ever did, vec![DefLoc::None; max_val] would try to allocate tens of GB and abort instead of panicking.

cargo test -p victory-shader --lib -- --test-threads=4 (debug) gave 423 passed, 1 failed, 4 ignored. Main gave 419 passed, 1 failed, 4 ignored. The failure is size_tests::a_reused_descriptor_register_read_only_behind_its_flag on both, and it already fails on main. Apart from the four new tests, the set of passing tests is the same. The four new tests also pass on main, so they pin behaviour and don't reproduce a bug. Clippy with --lib --tests --examples gives the same 12 warnings as main. rustfmt wants one change, the structure_wide(&p, &HashSet::from([999]))... line in kept_wqm_with_empty_helped_uses_fresh_bdd_state (structure.rs:4748) needs wrapping.

For the output I hashed every DXIL container the test suite produces, and all 840 of 840 are byte-identical to main. With a throwaway check inside Lanes::new during that run, all 1108 Lanes::new calls the suite makes got an idom table identical to main's compute_idoms. preds matched the exits every time, and no value was both a phi and an instruction result. One of those calls had unreachable blocks (in a_far_early_out_is_left_out_and_the_gate_counts_the_lanes_of_both_halves), so the usize::MAX path ran once in the suite. To cover more of it I fuzzed 200k random CFGs, about 166k with unreachable blocks and about 15k irreducible. ir::idoms matched main's compute_idoms on every block of every graph. Lanes::new rejected exactly the graphs irreducible_edge flags, with the same offset, and dominates answered no for unreachable blocks as main does.

On speed I couldn't measure a gain. I collected the 1046 distinct ir::build inputs the suite uses and replayed build plus structure in release, interleaving main and PR over several rounds. On the 1044 small programs the medians were within about 3% of each other, and run-to-run noise was bigger than that. That timed region includes build, which this PR doesn't touch and which is over half of it, so a gain in structure alone could be bigger than the total shows. I didn't time structure separately. The two large programs (the 4096-layer diamond chains from reverse_order_diamond_chain_eliminates_trivial_phis) take most of the structure time, and there the noise was also bigger than any difference. The test programs are tiny compared to real shaders, so this says little about the game. A run over a real shader cache would answer it better.

The body says this is split from #402, and the commit title matches. Compared with #402's structure.rs, what's left out is the BDD memo and scratch work (BddWork, the *_with helpers), though I didn't go hunk by hunk. It merges cleanly with #546 and with #547. I didn't run the Linux suite. The body's 298 passed fits one shared baseline plus the four new tests, the same as #546's 298 and #547's 295. I didn't test real game shaders, a shader cache run, gameplay, release-build test behaviour, or AMD and other vendors' drivers.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-05 06:34 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/545#issuecomment-7433449388) Checked a6ca7d3 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). Merge base is b581f7e, current main. I went through every changed function and it reads as a straight refactor to me. The inline reducibility check in `Lanes::new` (structure.rs:1034) is the same loop as `ir::irreducible_edge`, same edge order and same `from` block, so the error offset doesn't change, and the idom table is now computed once instead of twice. `ir::idoms` works from `preds` where the old `compute_idoms` worked from the exits, which is only the same thing if `preds` is current. Every place that rewrites exits in ir.rs calls `link` after it, so it holds. Unreachable blocks come back as `usize::MAX` instead of `None`, and `dominates` and the dominator-chain walk in the owner pass check for that explicitly. The `expect`/`unwrap` that became `debug_assert_ne!` (structure.rs:1202, 3357) still panic in release, because the next `index[]` lookup with `usize::MAX` is out of bounds, so a broken invariant doesn't go quiet. Moving the WQM discovery into `structure_wide` (structure.rs:864) does the same work main's `helped()` did on its own `Lanes`, then rebuilds a fresh one, so the BDD table starts clean as before. In `helped_now` and `check_joins` the clones became index loops. That's fine because `mask` only appends to `joins`/`phi_joins` while the loop runs and `reset` can't be reached from there, and the short-circuit order (and so the BDD node order) is the same. One difference only shows up on programs with dead blocks. Main kept `defs` and `phis` in two maps, and `locs` (structure.rs:1069) puts both in one slot per value. Dead blocks keep the stale value ids from the program they were cloned from, and `rename` never visits them. If such a stale write reuses the id of a live phi, the phi lookup now misses where main still found it. #546 prunes those blocks before rename, so with that merged nothing like this reaches `structure`. The one suite program that does hit `structure` with a dead block had no such collision. Also, the `max_val` scan at structure.rs:1054 has no `NONE` guard, while #547 adds one to the same kind of scan. I couldn't find a way for a `NONE` phi or write value to reach `structure`, but if one ever did, `vec![DefLoc::None; max_val]` would try to allocate tens of GB and abort instead of panicking. `cargo test -p victory-shader --lib -- --test-threads=4` (debug) gave 423 passed, 1 failed, 4 ignored. Main gave 419 passed, 1 failed, 4 ignored. The failure is `size_tests::a_reused_descriptor_register_read_only_behind_its_flag` on both, and it already fails on main. Apart from the four new tests, the set of passing tests is the same. The four new tests also pass on main, so they pin behaviour and don't reproduce a bug. Clippy with `--lib --tests --examples` gives the same 12 warnings as main. rustfmt wants one change, the `structure_wide(&p, &HashSet::from([999]))...` line in `kept_wqm_with_empty_helped_uses_fresh_bdd_state` (structure.rs:4748) needs wrapping. For the output I hashed every DXIL container the test suite produces, and all 840 of 840 are byte-identical to main. With a throwaway check inside `Lanes::new` during that run, all 1108 `Lanes::new` calls the suite makes got an idom table identical to main's `compute_idoms`. `preds` matched the exits every time, and no value was both a phi and an instruction result. One of those calls had unreachable blocks (in `a_far_early_out_is_left_out_and_the_gate_counts_the_lanes_of_both_halves`), so the `usize::MAX` path ran once in the suite. To cover more of it I fuzzed 200k random CFGs, about 166k with unreachable blocks and about 15k irreducible. `ir::idoms` matched main's `compute_idoms` on every block of every graph. `Lanes::new` rejected exactly the graphs `irreducible_edge` flags, with the same offset, and `dominates` answered no for unreachable blocks as main does. On speed I couldn't measure a gain. I collected the 1046 distinct `ir::build` inputs the suite uses and replayed `build` plus `structure` in release, interleaving main and PR over several rounds. On the 1044 small programs the medians were within about 3% of each other, and run-to-run noise was bigger than that. That timed region includes `build`, which this PR doesn't touch and which is over half of it, so a gain in `structure` alone could be bigger than the total shows. I didn't time `structure` separately. The two large programs (the 4096-layer diamond chains from `reverse_order_diamond_chain_eliminates_trivial_phis`) take most of the `structure` time, and there the noise was also bigger than any difference. The test programs are tiny compared to real shaders, so this says little about the game. A run over a real shader cache would answer it better. The body says this is split from #402, and the commit title matches. Compared with #402's structure.rs, what's left out is the BDD memo and scratch work (`BddWork`, the `*_with` helpers), though I didn't go hunk by hunk. It merges cleanly with #546 and with #547. I didn't run the Linux suite. The body's 298 passed fits one shared baseline plus the four new tests, the same as #546's 298 and #547's 295. I didn't test real game shaders, a shader cache run, gameplay, release-build test behaviour, or AMD and other vendors' drivers. AI-assisted: yes
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 10:18 UTC · original

Thanks @⁠Kal0s-design! The stale SSA collision and NONE allocation concern are addressed at ccfd846: unreachable/sentinel cases retain separate sparse definition and phi maps, while ordinary SSA keeps dense lookup. Both new regression tests pass in debug and release. No performance claim beyond the measured data.

**@⁠tommiehansen** on GitHub · 2026-12-05 10:18 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/545#issuecomment-7436351876) Thanks @⁠Kal0s-design! The stale SSA collision and NONE allocation concern are addressed at [ccfd846](https://github.com/tommiehansen/VIctory-xmem/commit/ccfd8463fef495ec0629b4814cb9fa0dce324765): unreachable/sentinel cases retain separate sparse definition and phi maps, while ordinary SSA keeps dense lookup. Both new regression tests pass in [debug and release](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47499397549). No performance claim beyond the measured data.
github manually merged commit 1cc88e0d1e into main 2026-12-05 17:30:38 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.