perf(shader): opt-in empty-edge CFG elimination with exact execution coverage #647

Open
github-bot wants to merge 9 commits from github-bot/gh-647 into main AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-05 23:16 UTC · original
tommiehansen:perf/empty-edge-20261206 → main · +588 −0 · 6 files · 9 commits · open

Why

Empty control-flow blocks can add work to shader graph construction and lowering without performing useful instructions. Removing them may simplify shader preparation, provided phi predecessors, critical edges and divergent EXEC behavior remain intact.

What changes

A worklist contracts proven empty edges and revisits affected candidates. Small shared unconditional fan-in blocks are eligible only if the target has no phi; critical edges are excluded. The pass is independently switchable with a separate v2 shader cache identity. It does not change loop-abort semantics. Inspired by cool_fox / CNF-Larp #247.

Benchmark results — Windows shader preparation

CI 47586760732, 31a4163, eight paired blocks per shape (192 exact arms, two divergent dispatches per arm). Total is translation + validation + WARP PSO creation; absolute times are medians of block medians.

Guest wave / diamonds Before After Paired time change
32 / 1 1118.40 µs 1090.28 µs −0.17%
32 / 8 1449.90 µs 1395.43 µs −4.67%
32 / 32 2433.13 µs 2428.38 µs −1.69%
64 / 1 1182.53 µs 1172.50 µs −1.28%
64 / 8 1571.75 µs 1498.63 µs −1.77%
64 / 32 2687.65 µs 2538.88 µs −2.56%

33/48 blocks faster in total; lowering alone varies from −3.06% to +7.62%, and DXIL size reductions are 0.19–4.73%. Offline ACO, 24 matched four-arm cases, reports identical final AMD ISA, register allocation, spill/scratch and occupancy. The GFX1200 profile is compiler-only. No physical GPU speedup established.

Why this should be merged

A bounded graph simplification could reduce preparation overhead for eligible complex shaders. The improved pass has repeatable scoped CPU preparation savings on the larger generated CFGs, with an inexpensive no-candidate return. Ready for review as an opt-in CPU preparation optimization; retain default off. No runtime GPU benefit or general shader-corpus speedup is claimed.

Validation and compatibility

Initial exact cases: 56/56 translated WARP outputs, both wave widths and divergent cutoffs; structural coverage, Linux and Windows production compilation. Full Windows suite has the existing descriptor PSO failure, also with the option off. Shared join controls and latest four CI jobs pass.
Reproduce: cargo test --locked --release -p victory-shader --lib empty_edge_full_translation_cost -- --ignored --nocapture --test-threads=1. Representative title CFGs and physical AMD execution remain useful follow-up coverage, not prerequisites for review of this scoped CPU benefit.

Final implementation and paired validation — ef0dd14

Avoid all graph allocation when no candidate exists; build predecessors during the reachability walk and take rather than clone the removed edge's predecessor vector. Preserve existing legality checks. All four final CI jobs pass, including structural parity with the preceding implementation and 192 exact Windows full-preparation arms. The prior run 47597015971 independently produced exact Windows output; its Linux log-count gate (not the tests) was fixed at final head.

Graph / nodes Previous pass µs Improved pass µs Paired time change Wins
No empty / 128 6.800 0.134 −98.03% 8/8
No empty / 1024 54.350 2.530 −95.31% 8/8
Chain / 128 15.753 14.496 −8.11% 8/8
Chain / 1024 82.346 66.553 −19.27% 8/8
Sparse / 128 7.414 6.738 −5.64% 8/8
Sparse / 1024 56.342 51.263 −9.01% 8/8
Diamonds / 128 25.764 24.309 −6.20% 7/8
Diamonds / 1024 200.102 182.791 −8.62% 7/8

This compares pass cost with the preceding implementation, not switch off. Full preparation (translation + validation + WARP PSO) independently compares switch off/on:

Wave / diamonds Before µs After µs Paired time change Wins
32 / 1 1191.10 1175.60 −1.44% 5/8
32 / 8 1552.83 1534.88 −2.12% 5/8
32 / 32 2528.75 2439.38 −2.91% 6/8
64 / 1 1196.60 1197.65 +0.24% 4/8
64 / 8 1500.03 1487.08 −2.24% 5/8
64 / 32 2594.85 2512.00 −4.16% 6/8

Medians of block medians; negative paired time change means faster. 31/48 full-preparation blocks improved; lowering alone is mixed. The prior run independently showed larger-graph reductions, but the magnitude varies. No final AMD ISA or elapsed GPU gain established. Review as scoped opt-in; no default activation.

**@⁠tommiehansen** on GitHub · 2026-12-05 23:16 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/647) `tommiehansen:perf/empty-edge-20261206` → `main` · +588 −0 · 6 files · 9 commits · open ## Why Empty control-flow blocks can add work to shader graph construction and lowering without performing useful instructions. Removing them may simplify shader preparation, provided phi predecessors, critical edges and divergent EXEC behavior remain intact. ## What changes A worklist contracts proven empty edges and revisits affected candidates. Small shared unconditional fan-in blocks are eligible only if the target has no phi; critical edges are excluded. The pass is independently switchable with a separate v2 shader cache identity. It does not change loop-abort semantics. Inspired by cool_fox / CNF-Larp #247. ## Benchmark results — Windows shader preparation [CI 47586760732](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47586760732), `31a4163`, eight paired blocks per shape (192 exact arms, two divergent dispatches per arm). Total is translation + validation + WARP PSO creation; absolute times are medians of block medians. | Guest wave / diamonds | Before | After | Paired time change | |---|---:|---:|---:| | 32 / 1 | 1118.40 µs | 1090.28 µs | −0.17% | | 32 / 8 | 1449.90 µs | 1395.43 µs | −4.67% | | 32 / 32 | 2433.13 µs | 2428.38 µs | −1.69% | | 64 / 1 | 1182.53 µs | 1172.50 µs | −1.28% | | 64 / 8 | 1571.75 µs | 1498.63 µs | −1.77% | | 64 / 32 | 2687.65 µs | 2538.88 µs | −2.56% | 33/48 blocks faster in total; lowering alone varies from −3.06% to +7.62%, and DXIL size reductions are 0.19–4.73%. [Offline ACO](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47581970446), 24 matched four-arm cases, reports identical final AMD ISA, register allocation, spill/scratch and occupancy. The GFX1200 profile is compiler-only. No physical GPU speedup established. ## Why this should be merged A bounded graph simplification could reduce preparation overhead for eligible complex shaders. The improved pass has repeatable scoped CPU preparation savings on the larger generated CFGs, with an inexpensive no-candidate return. Ready for review as an opt-in CPU preparation optimization; retain default off. No runtime GPU benefit or general shader-corpus speedup is claimed. ## Validation and compatibility [Initial exact cases](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47580599519): 56/56 translated WARP outputs, both wave widths and divergent cutoffs; structural coverage, Linux and Windows production compilation. Full Windows suite has the existing descriptor PSO failure, also with the option off. [Shared join controls](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47584529941) and latest four CI jobs pass. Reproduce: `cargo test --locked --release -p victory-shader --lib empty_edge_full_translation_cost -- --ignored --nocapture --test-threads=1`. Representative title CFGs and physical AMD execution remain useful follow-up coverage, not prerequisites for review of this scoped CPU benefit. ### Final implementation and paired validation — ef0dd14 Avoid all graph allocation when no candidate exists; build predecessors during the reachability walk and take rather than clone the removed edge's predecessor vector. Preserve existing legality checks. [All four final CI jobs](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47597329356) pass, including structural parity with the preceding implementation and 192 exact Windows full-preparation arms. The prior run [47597015971](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47597015971) independently produced exact Windows output; its Linux log-count gate (not the tests) was fixed at final head. | Graph / nodes | Previous pass µs | Improved pass µs | Paired time change | Wins | |---|---:|---:|---:|---:| | No empty / 128 | 6.800 | 0.134 | −98.03% | 8/8 | | No empty / 1024 | 54.350 | 2.530 | −95.31% | 8/8 | | Chain / 128 | 15.753 | 14.496 | −8.11% | 8/8 | | Chain / 1024 | 82.346 | 66.553 | −19.27% | 8/8 | | Sparse / 128 | 7.414 | 6.738 | −5.64% | 8/8 | | Sparse / 1024 | 56.342 | 51.263 | −9.01% | 8/8 | | Diamonds / 128 | 25.764 | 24.309 | −6.20% | 7/8 | | Diamonds / 1024 | 200.102 | 182.791 | −8.62% | 7/8 | This compares pass cost with the preceding implementation, not switch off. Full preparation (translation + validation + WARP PSO) independently compares switch off/on: | Wave / diamonds | Before µs | After µs | Paired time change | Wins | |---|---:|---:|---:|---:| | 32 / 1 | 1191.10 | 1175.60 | −1.44% | 5/8 | | 32 / 8 | 1552.83 | 1534.88 | −2.12% | 5/8 | | 32 / 32 | 2528.75 | 2439.38 | −2.91% | 6/8 | | 64 / 1 | 1196.60 | 1197.65 | +0.24% | 4/8 | | 64 / 8 | 1500.03 | 1487.08 | −2.24% | 5/8 | | 64 / 32 | 2594.85 | 2512.00 | −4.16% | 6/8 | Medians of block medians; negative paired time change means faster. 31/48 full-preparation blocks improved; lowering alone is mixed. The prior run independently showed larger-graph reductions, but the magnitude varies. No final AMD ISA or elapsed GPU gain established. Review as scoped opt-in; no default activation.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 23:19:06 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/647/head:github-bot/gh-647'
git switch 'github-bot/gh-647'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-647'
git switch 'github-bot/gh-647'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-647'
git switch 'github-bot/gh-647'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-647'
git switch 'main'
git merge --squash 'github-bot/gh-647'
git switch 'main'
git merge --ff-only 'github-bot/gh-647'
git switch 'main'
git merge 'github-bot/gh-647'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.