Shaders/IR: eliminate per-instruction/CFG Vec allocations and O(1) effects dedup #2662
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2664"
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-25T17:44:04Z.
Claimed in #1633: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7158204478
Summary
Eliminates hot per-instruction and per-CFG-edge heap allocations and
O(REGS)/O(n²)scans during GFX10 decoding and SSA IR construction (crates/victory-shader/src/gfx10/fields.rs,crates/victory-shader/src/ir.rs,+319/-53), producing identical SSA IR:gfx10/fields.rs(valu_dwords): parses suffix widths directly withoutsplit('_').collect::<Vec<_>>()and only checks VOP3B forEncoding::Vop3.Exit::succs(): adds zero-allocSuccs { to: [usize; 2], len }used acrossreverse_postorder,link,irreducible_edge,split_irreducible,multi_entry_loop(also borrowingpredswithout cloning), andliveness, keepingpub Exit::successors()intact.RegSet::members(): iterates only set bits viatrailing_zeros()/w &= w - 1instead of scanning allREGSslots.effects()dedup: replacesVec::containsO(n²)dedup with a stackRegSetbitset and writes(Reg, NONE)directly without a secondVecallocation per instruction.Measured (
--release ir::tests::bench_ir_build)main)valu_cfg(2,048 insts, 128 blocks)2,310.3 µs/run1,966.9 µs/runmovrel(64 insts, 128 VGPRs)602.0 µs/run139.3 µs/runNot a duplicate of
gfx10/fields.rsvalu_dwordsorir.rsExit::succs/RegSet/effects.Verification
windows-latestMSVC + WARP SM 6.6 CI (both clippy-D warningsprofiles,xtaskpolicy 6/6,victory-shader281/281 including unit tests verifyingvalu_dwords,RegSet::members, andExit::succs): https://github.com/RVZO6/VIctory/actions/runs/45666985023AI-assisted: T3 Code (Antigravity, gemini-4-neon)
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:57:09Z.
Reviewed: mechanical perf cleanup —
VOP3B.containsis read inline now (same lookup, no hoisted variable), andvalu_dwordsparses viasplit('_')iterator instead of a Vec. No semantic change visible in the hunks read. CI green.Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T18:21:50Z.
Independent verification of #2664 (IR: inline
Succs, no per-instructionVecs, bit-scanRegSet)PR head
e6ab345e7b73be37a0741a54767e061aad35239c, merges cleanly ontoorigin/main13f91caee25f2fdf2c062be5f7a27f058e51cbca.Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1,
VICTORY_WARP=1+VICTORY_D3D12_WARP=1on every run (WARP adapter only, no physical GPU created), DXC/dxil 1.8.2502.11 (Windows SDK 10.0.26100.0, viaVICTORY_DXIL),cargo ... -j 4 --locked.Tests/clippy vs baseline.
origin/main13f91caee25f2fdf2c062be5f7a27f058e51cbca:cargo test -p victory-shader --lib --locked -- --test-threads=1= 267 passed, 3 failed, 3 ignored. The 3 failures are WARP limits and are the same 3 in every variant below:a_mask_joined_with_data_at_a_uniform_loop_is_its_numberandpermutes_read_the_lane_named_and_zero_from_lanes_left_out("no pipeline for a wave of 32"), andgathers_at_a_level_match_the_hardware(WARP gather result differs). Clippy:cargo clippy -p victory-shader --all-targets --locked= 0 warnings.With #2664: 271 passed, 3 failed (same 3), 4 ignored (+4 tests, +1 ignored benchmark). Clippy: 0 warnings.
Equivalence. Full diff read.
Succskeeps the old order and duplicates (a branch withtaken == not_takenstill yields two entries, so the "single predecessor" patterns elsewhere behave the same);members()stops atREGSso padding bits are ignored; the bitset dedup ineffects()keeps first-occurrence order (covered byeffects_dedup_preserves_first_occurrence_order);valu_dwordsis checked against the old split-based version for every VOP1/2/C/3/3P name plus edge strings. Output check with the throwaway hashing patch: 650 containers (476 distinct) byte-identical toorigin/main.Perf (release;
bench_ir_buildadded to base for comparison, combined run).ir::build2048 insts/128 blocks: 2235 / 2290 us (base, 2 rounds) -> 1839 / 1796 us; 64movrelinsts: 426 / 456 us -> 103 / 88 us.Findings: no bugs. Nit only:
Succsstoreslenasusize(au8would shrink it); irrelevant for correctness.Limits: no physical GPU (WARP only), no game files; the 3 WARP-limited tests above are therefore not verified on hardware. Benchmarks are synthetic, release mode, one machine, two back-to-back rounds each for base and combined; they say nothing about real-title shaders.
AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T18:23:06Z.
Composition check: #2662 + #2664 + #2665 together
Heads: #2662
95f56a53f8ff90f700d74d102ad79538bad68771, #2664e6ab345e7b73be37a0741a54767e061aad35239c, #26658105fdcfb68ac99d79ea728847a0f555b7a41521, merged in that order ontoorigin/main13f91caee25f2fdf2c062be5f7a27f058e51cbcaas a local merge commit (31ed3543e4c18b978f7b0a699a71f8d18e52a81b, not pushed). No conflicts: the three touch disjoint files (structure.rs;gfx10/fields.rs+ir.rs;emit/bitcode.rs+emit/shader.rs).Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1,
VICTORY_WARP=1+VICTORY_D3D12_WARP=1(WARP only), dxil 1.8.2502.11 (SDK 10.0.26100.0),-j 4 --locked.cargo test -p victory-shader --lib --locked -- --test-threads=1: 276 passed, 3 failed, 5 ignored. That is exactly baseline 267 + 2 + 4 + 3 new tests; the 3 failures are the same WARP-limited ones as onorigin/main(wave-of-32 x2, WARP gather).cargo clippy -p victory-shader --all-targets --locked: 0 warnings.origin/main, plus one extra from #2665's new test (throwaway hashing patch, not committed).shader::op4096 calls 2.84-2.94 ms -> 0.53-0.56 ms;ir::build2048 insts 2.24-2.29 ms -> 1.80-1.84 ms; 64movrelinsts 426-456 us -> 88-103 us; bitcode writer, 256x512 synthetic module, 8.9-9.8 ms -> 7.0-7.1 ms; BDDgivenn=13 ~465 us -> ~0.45 us (synthetic).Limits: no physical GPU, no game files; synthetic benchmarks only.
AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:27:35Z.
Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP +
dxil.dllverification and code review ofe6ab345e(on13f91ca):Verification (
rustc 1.98.1MSVC, Windows SDK10.0.26100.0dxil.dll)cargo xtask policy: 184 files ok.cargo clippy --locked -p victory-shader --all-targets -- -D warningsand--features host: 0 warnings.victory-shader(gfx10,ir,structure,emit::tests,emit::lower,emit::waterfall_testson RTX 5090 + WARP +dxil.dll,emit::bitcodewith unchanged FNV-1a): 101 passed, 0 failed, 3 ignored.--releaseir::tests::bench_ir_build:valu_cfg(2048 insts, 128 blks) = 1511.6 µs/run,movrel(64 insts, 128 vgprs) = 67.5 µs/run.git merge-treeacross all three PRs.Code Review Notes
VOP3B.containsinside the non-Vop3pVop3arm, allocation-freevalu_dwords(valu_dwords_matches_split_reference_for_all_valu_opcodes), stack-inlineSuccs,membersbit-scan clearing padding bits pastREGS = 385, andRegSet-backedeffects()dedup preserving first-occurrence order are all strictly equivalent with zerounsafe. Clean and ready to merge.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:16:02Z.
Automated triage for the maintainers.
Verdict: merge candidate. I re-reviewed the rebased head
02fb20d. It is a behaviour-preserving performance change:valu_dwords(gfx10/fields.rs) parses without aVec, and a test checks it against the old split-based version for every VALU opcode.VOP3B.containsis only evaluated in the VOP3 arm.Exit::succs()returns an inlineSuccs(same order and duplicates assuccessors(), which is kept).effects()dedups with aRegSetbitset in place ofVec::contains.I checked that every entry in
ris(reg, NONE)at that point, so deduplicating by register alone matches the old tuple compare, and first-occurrence order is kept. TheRegSet::memberspart that already landed onmainhas been dropped. One small point: thebench_ir_buildtest is#[ignore]d, so it adds code to maintain but nothing runs it.CI:
checkpassing.Generated by Claude Code
[PR #2664] Shaders/IR: eliminate per-instruction/CFG Vec allocations and bit-scan RegSetto [PR #2664] Shaders/IR: eliminate per-instruction/CFG Vec allocations and O(1) effects dedupImported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T00:21:01Z.
Rebased onto current
main(63bcca4, head02fb20d). Dropped theRegSet::members()bit-scan andEffectschanges that already landed onmain(63bcca4), keeping zero-allocvalu_dwords+ VOP3B scoping ingfx10/fields.rs, stackExit::succs(), and O(1)RegSetdedup ineffects(). Verified green onwindows-latestMSVC + WARP SM 6.6 CI (clippy, xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45727774760.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:29:05Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-shader --lib ir::tests: 11 passed, 0 failed, 1 ignored (including newexit_succs_matches_successorsandeffects_dedup_preserves_first_occurrence_order).cargo test -p victory-shader --lib gfx10::fields::tests: 1 passed, 0 failed (valu_dwords_matches_split_reference_for_all_valu_opcodes).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:41:28Z.
Review: APPROVED
Reviewed at
02fb20dff69a7ed6f16c5cefa91f65c89e885608— APPROVE.Verification
cargo xtask policy(191 files ok) andcargo clippy -p victory-shader --all-targets --all-features -- -D warningspassed cleanly (with no newrustfmtissues introduced).Succs([usize; 2]) matchesExit's exact 0/1/2-successor invariant and preserves[taken, not_taken]order across all CFG callers, whilepreds,phis,reads, andwritesremain growableVecs with no fixed-capacity truncation risk for multi-dword memory ops or wide relative VGPR ranges.RegSet([u64; 7], 448 bits) covers all 385 register indices (128SGPR +SCC+256VGPR), and because allreadscarry placeholderNONEduringeffects(),Reg-keyed deduplication preserves the exact first-occurrence order of the prior(Reg, Value)Vec::containscheck.gfx10::(17/17),ir::(11/11, 1 benchmark ignored),structure::(13/13, 1 benchmark ignored), andemit::lower::tests(33/33).Non-blocking test notes
exit_succs_matches_successors(crates/victory-shader/src/ir.rs:1528) comparessuccs()againstsuccessors()(which delegates tosuccs()); asserting literal expected slices (including a branch with identical targets) would make it self-contained.effects_dedup_preserves_first_occurrence_order(crates/victory-shader/src/ir.rs:1550) projects toReg; adding a wave64 relative move reachingv255would also cover the upper end of theRegSetbitset and(Reg, Value)pairs.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-29T00:29:01Z.
I checked the exact
02fb20dIR changes together with the packed-storage change in #3813. Combinedc584215keeps both commits as parents. Git merged the changes cleanly.All nine generated packed multiply, FMA and mixed shaders returned byte-identical DXIL against
02fb20din five alternating Windows release comparisons. The Microsoft validator accepted each object. The combined build saved three allocations and 96 requested bytes per packed instruction, with the same reallocation count. The 512-instruction mixed case went from 15,932 to 14,396 allocations.Mixed-chain translation medians were 0.851× at 128 instructions and 0.978× at 512. Pure multiply medians were 1.002–1.048×, and FMA medians were 0.956–1.020×. The VALU width, CFG successor and effects order regressions passed, along with the 33 lowerer tests, both strict Clippy configurations and the asset policy.
The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding the work into another commit.AI-assisted with OpenAI Codex.
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.