Shaders/IR: pruned SSA via bitset IDF + dominator-tree renaming, linear CFG scan, and early dropped-inst skip #2955
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2957"
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 Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T01:30:09Z.
Speed up
victory_shader::ir::buildacross all shaders while producing structurally identical SSA output (crates/victory-shader/src/ir.rs):[u64; 7]bitset IDF + dominator-tree DFS renaming: propagate iterated dominance frontiers for all 385 registers simultaneously in bitset words, gate phi insertion bylive_in, and rename in a single iterative dominator-tree DFS with an undo trail — eliminating maximal-SSA trivial phi creation, per-blockoutsVecallocations, and binary-searchlookup()calls.liveness()and fast-return inremove_trivial_phis_steps(): drop unusedlive_outcomputation fromliveness()and skip extra passes when no phis exist or none are eliminated.is_dropped()skip: assign basic blocks linearly inbuild_bounded()(droppingnext_offsetsand per-instructionleadersbinary searches) and skip scheduling/waitcnt hints beforemachine.fields(wave64)viais_dropped().Exit::succsandeffects()dedup).Measured (
--release, median of 3 runs)bench_ir_build_cfg_and_ssa(102 basic blocks, 40 phis): 613.6 µs → 292.1 µs/run (2.10×, -52.4%)Verification
--tests+--features diagnosticsclippy,xtask policy, full workspace tests): RVZO6/VIctory CI run #45734072839 (green, combined Wave 7 check on63bcca4).ir::testspass, includingpruned_ssa_matches_maximal_ssa_oracle(verifying structural equivalence against the maximal-SSA algorithm) andis_dropped_matches_dropped_names.AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:55:44Z.
Review: COMMENTED
Reviewed and verified against
main(63bcca43) on Windows 11 (RTX 5090 + WARP +dxil.dll) — clean, fast, and ready to merge:build_pruned_ssa(crates/victory-shader/src/ir.rs:236-423) computes idoms/DF aftersplit_irreducible, builds pruned phi shells via[u64; REGS.div_ceil(64)]bitset IDF filtered bylive_in[y], and renames in a single explicit-stack dominator-tree pass with trail rollback.is_dropped(encoding, opcode)skip avoid unnecessarymachine.fields(wave64)work, andis_dropped_matches_dropped_namesguards against opcode drift.emit/lower.rs.Local verification:
cargo test --locked -p victory-shader --lib:ir::11/11,structure::13/13,resource::35/35,emit::tests17/17,emit::lower::tests33/33 (includingpruned_ssa_matches_maximal_ssa_oracleandis_dropped_matches_dropped_names)emit::semantics_tests: 34/34 passed on both RTX 5090 and WARP--releasebench_ir_build_cfg_and_ssa:179.3 us/runcargo clippy(default &--all-features) +cargo xtask policy(191 files ok): 0 warningsImported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:34:32Z.
Review: COMMENTED
Verified: textbook pruned SSA. The parallel bitset IDF inserts phis only at df nodes where the reg is live-in (defs & live_in & !phi_regs), re-queueing on new bits — monotone so it terminates. Renaming is standard Cytron: phi values bound before reads, successor args filled at parent exit with current[], trail undo on Leave. The NONE-arg invariant holds because a reg live-in at a join is either defined on all reaching paths or lands in live_in[0] as an input. The is_dropped opcode table self-validates against DROPPED names via decode, and the linear leader scan replaces binary_search correctly since both lists are offset-sorted. The canonical oracle test comparing against maximal SSA on identical blocks is exactly the right check.
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T02:53:05Z.
@RVZO6 I compared this PR and #2942 individually and together through the public
translate_withentry point, in light of the eight translation workers reported on #2936. Both commits start at63bcca4, affect different compiler stages, and merge cleanly.Median wall time in ms for one batch of 64 distinct compute containers on a Ryzen 7 9850X3D, Windows x64, Rust 1.98.1 MSVC, release build. Lower is faster.
dfa61261569277The buffer batch varies program size and puts one dynamic diamond per eight loads in half of its shaders. The join batch has 4–130 diamonds; all 16 VGPRs feed the final store. The largest emits 2,080 DXIL phi instructions. Half the inputs in each batch enable view marks. Every timed call parses its compressed synthetic container, builds the IR, structures it, tracks resources and emits DXIL. Each row is 15 measurements across five processes with run order rotated and a warm-up outside the timer. The worker threads use the in-memory inputs directly; no shader cache, D3D pipeline creation, validator, file I/O or GPU dispatch is in the timer.
Correctness: I compared the actual DXIL bytes and the remaining
HostShaderbinding metadata for all 128 inputs. All four builds matched, and the Windows SDK DXIL validator accepted every output on each build (512 validations). Output sizes were 2,512–99,264 bytes. The paired change reduced these eight-worker medians by 16% in both batches. #2942 showed the more consistent individual benefit. The small eight-worker difference between #2957 alone and base is within the spread of repeated runs.Reproducible, test-only fixture 29c0e1b applies to the common base or either PR. From PowerShell:
Set
VICTORY_BENCH_OUTPUTto a separate directory for each build and batch to validate and save the binary outputs and binding metadata before timing. No title files were used; the eight-worker cold-cache run of the actual game remains the check for gameplay startup.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:22:02Z.
Automated triage for the maintainers.
Needs work. This replaces the SSA construction in
crates/victory-shader/src/ir.rs(build_pruned_ssa: dominance-frontier phi placement gated bylive_in, dominator-tree renaming with an undo trail), scans leaders linearly inbuild_bounded, and skips dropped instructions before decoding fields. Reading it, the renaming and phi-argument filling look right, andpruned_ssa_matches_maximal_ssa_oraclecompares against the old algorithm, but it rewrites the core of every shader's translation, so the bar is a measured benefit.The 2.1x figure is for
ir::buildalone on one synthetic program. The end-to-end measurement in this thread (steven-seagull27,translate_withover 128 synthetic containers, byte-identical DXIL on all builds) found this PR alone inside run-to-run noise with 8 workers and slower in one 1-worker batch (299.2 -> 307.5 ms), while #2942 gave the more consistent gain. To move this forward: show a whole-titlevictory translatetiming (cold cache, the worker count the loader uses) where this PR measurably helps on its own or on top of #2942, plus a program-by-program comparison showing identical output across the title's shaders. Without that, the risk of a core IR rewrite isn't matched by a demonstrated gain.CI: passing.
Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.