shader: add opt-in whole-function DXIL exec-mask, known-bits, and bitfield dataflow pass #281
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!281
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-281"
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?
@Vladimir-Human on GitHub · 2026-11-27 13:33 UTC · original
Vladimir-Human:perf/dxil-dataflow-exec-known-bits→main· +6243 −26 · 6 files · 2 commits · openCurrent switch values use bit
4096for DATAFLOW. SetVICTORY_SHADER_OPT=4159with the default passes, or4223to include WIDE. The test notes below use the previous switch values.Summary
Adds an opt-in whole-function DXIL bitcode dataflow optimizer (
bitcode::opt::DATAFLOW = 512, enabled viaVICTORY_SHADER_OPT=575alongside the default passes or639withWIDE) incrates/victory-shader/src/emit/bitcode/dataflow.rs.Default
VICTORY_SHADER_OPTremains63(opt::DEFAULT = ALL & !(WIDE | DATAFLOW)) andTRANSLATOR_VERSIONremains atmain's9, preserving a matched baseline for A/B testing via the existingshader_opt()shader-cache key (crates/victory-gpu/src/shader_cache.rs:139). Pass bits128and256remain free for#193.Optimization Phases
KnownBits { width, zero, one }across PHIs, loops, exact ripple-carryAdd/Sub, exact small-mask shifts,Mul, guardedUDiv/URem/SDiv,ZExt/SExt/Trunc/Bitcast,Select, exact(1 << w) - 1bitfield masks (v_bfe_*/s_bfm), integer comparisons, and pure DXIL bit intrinsics (UMin/UMax/IMin/IMax,Bfrev,Countbits,FirstbitLo,FirstbitHi,legacyF32ToF16).sub(shl(..), 1)andbitcast(bitcast(..))so loop backedge widening always re-enqueues dependent instructions.PathEnvForward Rewrite:exec-guard /v_cndmaskselectchains viaeval_assuming(select(g, a, select(g & h, b, c)) -> select(g, a, c)).lshr(shl)/ashr(shl)/shl(lshr)fromv_mul_u32_u24, SDWA, andv_bfe_*),v_bfi_b32same-value idioms,zext/sext/truncroundtrips, redundantUMin/UMax/IMin/IMax, and sequential per-use bit-demand bypass (strip_unused_bits).KnownBits, eliminating dead upper-bit packs and narrowingashr/sexttolshr/zext.Soundness Guarantees
addrspace(3)) LDS store-to-load forwarding: wave-ordered barrierless LDS reads remain untouched (space3_lds_store_is_never_forwarded_to_load+ HWwave_ordered_barrierless_lds_soundness_hw_parity).dx.op.getDimensions*orTag::Clampcoalescing/reuse (crediting Belobug/VIctory-Belobug-AMD#324):Module::tagrecordsTag::Clampunconditionally,opt.rs::keyexcludes bothTag::Clampanddx.op.getDimensions*, anddataflow.rsnever folds aTag::Clamponto another clamp/UMin(requiring strictly smaller non-clamp provenance).fcmp one(pred::ONE) emission, zero float arithmetic folding, undef-safe checks.Verification (
VICTORY_D3D12_DEBUG=1,--test-threads=1)cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default &--all-features): 0 warningscargo run -p xtask --locked -- policy(315 files ok) &cargo test -p xtask --locked: 11/11 passedemit::bitcode::dataflow::12/12 passed:KnownBitstransfer proof across all81 x 81 = 6,561abstract pairs x all concrete valuesDATAFLOW,DATAFLOW | DEAD,FOLD | DATAFLOW | DEAD,DEFAULT | DATAFLOW,ALL)sub(shl)&bitcast(bitcast)), symmetricand/ormask stripping, space-3 LDS non-forwarding,getDimensionsnon-coalescing, RDNA4Tag::Clampnon-merging, and 64-bitzext/truncINT64eliminationemit::dataflow_tests::4/4 passed (HW RTX 4070 SUPER + WARP +dxil.dllvalidation,0D3D12 debug errors)emit::bitcode::opt::tests::11/11,the_clean_up_switch_parses_or_runs_every_pass1/1,VICTORY_SHADER_OPT=575emit::lower::tests::19/19 (1 ignored),VICTORY_SHADER_OPT=639wide-load 1/1victory-shadersuite: 338/338 passed (5 ignored,0D3D12 debug errors)Hardware GPU Benchmark (
NVIDIA GeForce RTX 4070 SUPER,ID3D12QueryHeaptimestamps + bit-exact readback parity)Command:
cargo test --release -p victory-shader --locked bench_dataflow_hw_gpu -- --ignored --nocapture --test-threads=14096 x 64, 512 iters)opt=63) Instsopt=575) Instsus)u24loop (v_bfe/v_mul_u24)exec+v_cndmaskloopi64pack +execINT64cleared)@TaynanGT on GitHub · 2026-11-27 13:37 UTC · original
@Vladimir-Human The opt-in bit gives us a baseline for the dataflow pass. Please reconcile with main’s translator version 9 and keep the emitted output and cache key paired. The useful correctness checks are loop backedges, inactive lanes and joins where information becomes less precise.
1bb16f90dbto54a9348247@Vladimir-Human on GitHub · 2026-11-27 13:57 UTC · original
@TaynanGT Rebased cleanly onto
main(2532474,TRANSLATOR_VERSION = 9incrates/victory-shader/src/lib.rs:29) and updated to54a9348(all 4 CI checks green):lib.rsis untouched (TRANSLATOR_VERSIONstays9) andopt::DEFAULTremains63(ALL & !(WIDE | DATAFLOW)), so the default output stays byte-identical. Opting in viaVICTORY_SHADER_OPT=575(or639) flows directly throughemit::shader_opt()into bothemit::options_hash()(crates/victory-shader/src/emit/mod.rs:338) and the disk shader cache key (crates/victory-gpu/src/shader_cache.rs:139), keeping63and575entries paired with their emitted code.sckp_2hop_sub_shl_loop_widening_does_not_miscompile(crates/victory-shader/src/emit/bitcode/dataflow.rs:4347),sckp_2hop_bitcast_roundtrip_loop_widening_does_not_miscompile(dataflow.rs:4403, covering 2-hop SSA dependency edges when loop PHIs widen across backedges),sccp_kills_unreachable_loop_backedge_phi_cycle(dataflow.rs:4283), and HW+WARP loop parity testsrdna2_bitfield_and_u24_loop_hw_parity(crates/victory-shader/src/emit/dataflow_tests.rs:741) anddxil_whole_function_bitfield_clamp_exec_hw_parity(dataflow_tests.rs:895).exec/v_cndmask):exec_mask_nested_select_and_cross_block_bitfield_collapse(dataflow.rs:4141, exercisingeval_assumingatdataflow.rs:2234) and HW+WARP divergent-EXEC+v_cndmaskloop parityrdna2_exec_mask_and_cndmask_loop_hw_parity(dataflow_tests.rs:789).KnownBits::joinkeeps only bits agreed across all incoming edges,learn_multi_pred(dataflow.rs:2144) intersects facts across every executable predecessor only for strictly dominating values, andrandomized_equivalence_oracle_across_500_programs_and_pass_combos(dataflow.rs:5065) checks 500 multi-block CFG/diamond/loop/PHI programs bit-exact across 6 input vectors and 5 pass combinations (DATAFLOW,DATAFLOW | DEAD,FOLD | DATAFLOW | DEAD,DEFAULT | DATAFLOW,ALL).@TaynanGT on GitHub · 2026-11-27 14:12 UTC · original
@Vladimir-Human The backedge, inactive-lane and join tests cover the cases I was concerned about. I moved DATAFLOW to bit 4096 in
c5ab09bbecause #193 uses bit 512 for LICM. UseVICTORY_SHADER_OPT=4159for the comparison against63, or4223with WIDE. This gives dataflow its own cache entry.c5ab09ba76toeed4f42caaView 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.