Shaders/IR: eliminate per-instruction/CFG Vec allocations and O(1) effects dedup #2664
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2664
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@RVZO6 on GitHub · 2026-11-25 17:44 UTC · original
RVZO6:rvzo/ir-decode-zero-alloc→main· +230 −26 · 2 files · 1 commits · openClaimed in #1633: #1633
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)
@kotekompotek on GitHub · 2026-11-25 17:57 UTC · original
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.@oni-swr on GitHub · 2026-11-25 18:21 UTC · original
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.
@oni-swr on GitHub · 2026-11-25 18:23 UTC · original
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.
@fuzeofficlal on GitHub · 2026-11-25 19:27 UTC · original
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.@Marvisak on GitHub · 2026-11-25 22:16 UTC · original · edited 2026-11-26 03:21 UTC
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
@RVZO6 on GitHub · 2026-11-26 00:21 UTC · original
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.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.