perf(shader): add DXIL folds, pure LICM, local/LDS forwarding, and barrier dedup #193
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!193
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-193"
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 07:47 UTC · original
Vladimir-Human:perf/dxil-opt-licm-lds-barriers→main· +5330 −105 · 2 files · 1 commits · openSummary
Extends
crates/victory-shader/src/emit/bitcode/opt.rswith five independent, opt-in, semantics-preserving DXIL IR optimisation passes behind separateVICTORY_SHADER_OPTbits while keepingDEFAULT = 63100% bit-identical tomainand leavingTRANSLATOR_VERSION = 9(crates/victory-shader/src/lib.rs) untouched so warm shader caches stay valid on the baseline control:0..563DEFAULT(DEAD|FOLD|REUSE|FACTS|LOADS|FIRST)maincontrol (bit-identical DXIL output; warm cache unchanged).664WIDEmain).7128EXT_FOLDmul/udiv/uremstrength reduction, IEEE-754 NaN-safe compare negation (avoiding AMDfcmp one),undef-safe booleanselect/zextfolds, and canonicalKey::Cmp/FACTSreuse.8256MEM_FWDaddrspace(0)globals, sharedaddrspace(3)LDS, and DXIL resource memory for private-global forwarding, non-aliasing LDS load-to-load reuse, and intra-block overwritten-store DSE. Groupshared (addrspace(3)) store-to-load forwarding is disabled to preserve barrierless wave-ordered LDS exchange.9512LICMWriteKind::All(dx.op.discard) prefix guards, and explicit blocking ofderiv*,wave*,quad*, andgetDimensionscalls.101024BARRIERSdx.op.barrier(80, mode)calls and coalesces bounded intra-block read-after-read barriers between non-escaping LDS read phases bounded by covering group+TGSM barriers (orTerm::Retwhen no UAV fence bits are set).112048SPEC_LICMLICM; still blocksderiv*,wave*,quad*,getDimensions, traps, and resource reads).VICTORY_SHADER_OPT=63(or unset) = baselinemaincontrol;63 + bitisolates any single pass (e.g.191=DEFAULT|EXT_FOLD,319=DEFAULT|MEM_FWD,575=DEFAULT|LICM,1087=DEFAULT|BARRIERS,2623=DEFAULT|LICM|SPEC_LICM);4031=ALL & !WIDE;4095=ALL.victory-gpu's shader cache already hashesvictory_shader::emit::shader_opt().to_le_bytes(), soDEFAULT = 63stays warm onmain's cache while every opt-in bitmask caches independently.crates/victory-shader/src/emit/mod.rs): updatesVICTORY_SHADER_OPTdocs/tests and adds a test-onlywith_shader_optthread-local override (translation_fingerprint()/VICTORY_SHADER_SWITCHESunchanged).Visual impact
Zero visual change.
DEFAULT = 63emits bit-identical DXIL tomain, and every opt-in pass is strictly semantics-preserving at the DXIL IR level (no fast-math flags, no float arithmetic reassociation, IEEE-754 NaN andundefsemantics preserved, groupshared store-to-load forwarding disabled). Verified withdxil.dllvalidation, random-program interpreter equivalence across 400 seeds (includingSPEC_LICMandLICM | SPEC_LICM), and bit-exact D3D12 hardware GPU + WARP parity.Verification
cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): 0 warningscargo run -p xtask --locked -- policy: asset policy: 313 files ok (opt.rs321,857 B,emit/mod.rs146,437 B)cargo test -p xtask --locked: 11 passed; 0 failedVICTORY_D3D12_DEBUG=1,--test-threads=1,0D3D12 debug errors):emit::bitcode::opt::tests(default and--all-features): 29 passed; 0 failed; 1 ignored (bench)the_clean_up_switch_parses_or_runs_every_pass: 1 passed; 0 failedVICTORY_SHADER_OPT=4031(hw_tests,emit::tests,emit::wave64_tests,emit::size_tests,emit::waterfall_tests): 66 passed; 0 failed; 1 ignoredVICTORY_WARP=1, both withVICTORY_D3D12_DEBUG=1and CI mode without it, default and--all-features):emit::bitcode::opt::tests::hw_tests: 3 passed; 0 failed; 1 ignored (0skips)@TaynanGT on GitHub · 2026-11-27 08:08 UTC · original
@Vladimir-Human I bumped the translator cache version to 8 on this PR. An explicit pass mask can keep the same value while the revised folds emit different DXIL. The version bump makes those runs rebuild their translations. The local pass-mask test passed.
@Vladimir-Human on GitHub · 2026-11-27 08:18 UTC · original
Thanks @TaynanGT — bumping the translator cache version to 8 in
173bde0makes total sense so runs with an explicit pass mask rebuild cached DXIL instead of reusing pre-opt entries. Everything on this PR is clean and ready on our side.@TaynanGT on GitHub · 2026-11-27 08:24 UTC · original
@Vladimir-Human The CI run passed on
173bde0. The remaining runtime check is a matched capture on the default mask, with the same scene, upscaler and frame generation settings. The version bump will give that run a fresh set of translations.@Vladimir-Human on GitHub · 2026-11-27 08:35 UTC · original
Great to hear CI is green on
173bde0— standing by if anything comes up in the matched capture!@TaynanGT on GitHub · 2026-11-27 08:39 UTC · original
@Vladimir-Human Thanks. I’ll post the matched-capture results here with the two build hashes and settings.
@efsebayern on GitHub · 2026-11-27 10:42 UTC · original · reviewed
I reviewed
173bde0against its base70ac49d. I found one correctness concern; the other passes look right to me.Groupshared store-to-load forwarding drops wave-ordered LDS exchange (
crates/victory-shader/src/emit/bitcode/opt.rs~1829-1856 for the load lookup, ~1930-1965 where a store records its value inshared_const/shared_dyn)Within a block,
store lds[p], vfollowed byload lds[p]with no barrier in between is replaced byv. The PR's own test does exactly this (per-lanev1stored tolds0, then forwarded).DXIL allows that, since a cross-thread race without a barrier is undefined there. But the console code relies on LDS being ordered within one wave, and the translator keeps that reliance:
lower.rs(~1872 and ~1912) adds no barrier when the group is ≤ 32 threads, or when it runs natively as wave64 on a 64-lane host.Failure scenario. The "elect a leader per bucket" idiom:
lds[bucket] = laneId; if (lds[bucket] == laneId) { ... }.The DXIL validator can't catch this, because the program stays valid.
Suggestion: don't forward a store to a later load in address space 3. Load-to-load reuse, the LDS dead-store elimination and private (space 0) forwarding are fine. Alternatively, forward only when the stored value is wave-uniform.
Also worth noting: the new passes are on by default (
DEFAULT63 → 447). Because FOLD, FACTS and LOADS changed too,VICTORY_SHADER_OPT=63doesn't give back the old output. A switch that restores the old behaviour would make A/B checks of rendering regressions easier.Checked, nothing found:
canonical_cmpare correct.Offline results:
cargo test -p victory-shader --lib: 334 passed, 0 failed, 5 ignored. Clippy is clean.VICTORY_HOST_WAVE=32 victory translate --list --validateover the title's shaders gives identical validation results for base and PR: VS/PS 14262/14262, CS 2759/2761, MS 8694/8765, with the same failing programs.AI-assisted review (Claude Code).
@Vladimir-Human on GitHub · 2026-11-27 12:27 UTC · original
Thank you @efsebayern for catching the groupshared (
space 3) store-to-load forwarding bug and validating the full shader set offline — pushedef78e6catop173bde0:PtrRoot::SharedGlobal) store-to-load forwarding incrates/victory-shader/src/emit/bitcode/opt.rs(Op::Store:shared_const.remove(&slot)on constant stores instead of insertingval, and omittedshared_dyn.insert(slot, val)on dynamic stores), preserving barrierless wave-ordered LDS exchange (group <= 32or native wave64). Space-3 load-to-load reuse across non-aliasing writes, LDS overwritten-store DSE, and space-0 thread-private forwarding are preserved.local_and_shared_memory_forwarding_non_aliasing_and_dseand thescalar_ldsalias check, and added both IR unit testshared_store_to_load_not_forwarded_wave_leader_election(dynamic bucket + constant slot invalidation/reuse) and D3D12 HW/WARP +dxil.dlltestwave_ordered_lds_leader_election_preserved(verifying bothOp::Loadinstructions remain underDEFAULTand 1-winner-per-bucket/constant-slot parity on hardware).VICTORY_SHADER_OPT=0disables all module passes,63disablesLICM+BARRIERS, and47disablesLOADStoo; @TaynanGT, if you also want the newFOLD/FACTS/LOADSrefinements split behind separate opt-in bits so63is bit-identical tomain, happy to add that cleanly.VICTORY_D3D12_DEBUG=1):clippy -p victory-shader --all-targets --locked -- -D warnings(default &--all-features) 0 warnings;xtask policy303 files ok; HW fullvictory-shader336/336 passed (5 ignored); HW--all-featuresopt::tests26/26 passed (1 ignored); WARPopt::tests::hw_tests3/3 passed (1 ignored).@TaynanGT on GitHub · 2026-11-27 12:32 UTC · original
@Vladimir-Human Yes, please put the new FOLD, FACTS, and LOADS refinements behind separate opt-in bits. That gives us a byte-identical main control for the warm-cache A/B and keeps LICM and barrier dedup independently testable. The LDS leader-election regression covers the behaviour that the forwarding change must preserve.
ef78e6c6f3toac9923d8c0@Vladimir-Human on GitHub · 2026-11-27 14:01 UTC · original
@TaynanGT Done — rebased onto
main(ac9923d) and split all new refinements behind separate opt-inVICTORY_SHADER_OPTbits while keepingDEFAULT = 63bit-identical tomainandTRANSLATOR_VERSION = 9(lib.rs) untouched so warm caches stay valid on the baseline control (victory-gpu's shader cache keys onshader_opt().to_le_bytes()):63(unset)DEFAULT(1|2|4|8|16|32)maincontrol (opt.rs:L98)191(+128)DEFAULT | EXT_FOLDundef-safeselect, canonicalCmp/FACTS(opt.rs:L80)319(+256)DEFAULT | MEM_FWDopt.rs:L83)575(+512)DEFAULT | LICMderiv*/wave*/quad*/getDimensions(opt.rs:L85,L2506)1087(+1024)DEFAULT | BARRIERSopt.rs:L87)2623(+512+2048)DEFAULT | LICM | SPEC_LICMopt.rs:L90)4031/4095ALL & !WIDE/ALLWIDE(64) (opt.rs:L95,emit/mod.rs:L217)crates/victory-shader/src/emit/bitcode/opt.rs,emit/mod.rs):DEFAULT = 63invariance:default_63_leaves_ext_fold_off(L4384),default_63_leaves_all_opt_in_passes_off(L5756),the_clean_up_switch_parses_or_runs_every_pass(emit/mod.rs:L1399)space 3) leader-election preservation:shared_store_to_load_not_forwarded_wave_leader_election(L4597),wave_ordered_lds_leader_election_preserved(L7288)every_pass_leaves_what_random_programs_store(L4026),select_bool_fold_skips_undef_operands(L4328),local_and_shared_memory_forwarding_non_aliasing_and_dse(L4511),licm_hoists_pure_invariants_splits_cond_entry_and_respects_traps(L4927),licm_negative_controls_speculative_resources_uniformity_discard_and_signed_const_gep(L5046),adjacent_redundant_barrier_elimination_and_negative_controls(L5396),read_after_read_barrier_coalescing_and_soundness_negatives(L5460),dxil_opt_hw_gpu_bit_exact_parity_and_validation(L6512),split_lds_wave32_read_after_read_barrier_coalescing_and_parity(L6728)Clippy,Default tests,Diagnostics tests,check),MERGEABLE/CLEAN.@TaynanGT on GitHub · 2026-11-27 14:12 UTC · original
@Vladimir-Human The split switches give us a clean way to measure the passes one at a time. I moved DATAFLOW to bit 4096 in #281 so LICM keeps bit 512 here. Start the
63vs575run in a fresh cache directory if you used the earlier dataflow branch with575. The LDS leader-election tests cover the forwarding guard we needed.ac9923d8c0to1a34e9ca63@Smoodie7 on GitHub · 2026-11-27 21:23 UTC · original
I tried this PR merged on top of
main1d830857(the head I fetched earlier today had two small conflicts withmain; I kept main's clamp andgetDimensionsexclusions inopt.rsand took this PR's test override inemit/mod.rs) withVICTORY_SHADER_OPT=4031, on an RTX 4070 Ti SUPER 16 GB / Ryzen 7 7700, Series S, DLSS Quality + frame generation.Shaders: 25,790 cached, no new translation failures.
warm --used: 3,987 pipelines made, 0 failed.In game it was unplayable in a dialogue cutscene: 3.5 FPS (one sample at 0.2), 224 draws a frame dropped without a host pipeline, and the "being made" count sat at about 1,550 and stopped going down (1,548 → 1,543 in 40 s). The same build without this PR and without
VICTORY_SHADER_OPThad about half as many pipelines in flight at the same point and became playable once they were done. The picture showed white blown-out faces, rectangular stale tiles and ghosting, which matches the dropped passes.The run also had four copy-related opt-ins on (
VICTORY_WATCH_XMEM_ALLOC,VICTORY_WATCH_HEAP,VICTORY_PLACED_FILL_REDIRECT,VICTORY_INPLACE=2), so this does not prove the cause. My guess is that the new translation key leaves the driver's pipeline cache cold for every pipeline outside the warm set, and the different DXIL takes longer to compile. Full report with the screenshot: #212. I'll rerun withVICTORY_SHADER_OPT=4031alone on the same cutscene.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.