victory-shader: RO-SRV/SLOT_STRIDES GVN+LICM, SLOT_SAMPLED dedup, branchless PORT_CBV, Wave32/BFE/RCP codegen & faster translation #3501
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!3501
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3501"
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?
@Rulemore on GitHub · 2026-11-30 00:08 UTC · original
Rulemore:pr/shader-opt→main· +980 −202 · 9 files · 10 commits · closed without mergingSummary
This PR collects self-contained
victory-shaderDXIL optimization, codegen, and translation-speed improvements targeting both GPU execution time and cold shader compilation latency, with zero changes outsidecrates/victory-shader/.Key Changes
SLOT_STRIDES& Read-Only SRV GVN/LICM + BranchlessPORT_CBV(crates/victory-shader/src/emit/bitcode/opt.rs,lower.rs,mod.rs)SLOT_STRIDESraw loads and read-only SRV buffer loads eligible for GVN and LICM, and ignores telemetry UAV writes (SLOT_SAMPLED/SLOT_FAULTS) plus wave/quad ops inhas_resource_writesso enablingVICTORY_SAMPLED_MARKS=1no longer disables RO-SRV GVN/LICM.PORT_CBVs_buffer_load/ diamond dispatch and addsLEGACY_PLAIN(bit 16) /TRIG_PLAIN(bit 32) flags underVICTORY_RDNA_FLOAT.SLOT_SAMPLEDDominator Deduplication & IR-Block Handle Reuse (crates/victory-shader/src/emit/lower.rs,lower/tests.rs)self.curinsidemark_sampledpreviously invalidatedself.handles(keyed by DXIL block) and re-emittedcreateHandleFromHeap+rawBufferLoad(SLOT_SAMPLED)+atomicBinOpon every texture tap — reaching up to 1,547 duplicate atomics in a single shader and 160+ inCS_lightAtlas_Sprite.ir_handles(keyed by IR block whenguard_depth == 0) andmarked_at+ir_dominatesdeduplication so each descriptor/index is marked at most once per dominating IR block while leavingper_lanewaterfall handles free of wave ops.Ibfe/Ubfe&fdiv arcpHardware Reciprocal (lower.rs,valu_tests.rs)v_bfe/s_bfedirectly to DXILIbfe/Ubfeintrinsics instead of shift/mask sequences.fdiv arcpforv_rcp_f32/f16so DXC compiles to native hardware reciprocal instructions (MUFU.RCPon NVIDIA).lower.rs)waveIsFirstLanefor uniform LDS stores, stridedzero_meet_slots, fusedexchange_halves_two, and leaner Wave32 ballots.bitcode.rs,opt.rs,shader.rs,structure.rs)FxHashin hot compiler tables, cachesModulemetadata, uses allocation-freedx.oplookups, and removes unnecessary clones inoptandtrace_ptr.Measurements (RTX 4070 SUPER, 2560×1440, release build)
PORT_CBV: −2.74 ms GPU overall (CS_Gather−44%).SLOT_SAMPLEDdominator deduplication (VICTORY_SAMPLED_MARKS=1):CS_lightAtlas_Sprite(2561af9577c47289) dropped from 105 ms → 2.12 ms (~50×); giant shaders dropped from 1,547 → ~140atomicBinOpcalls.Verification
cargo test -p victory-shader --lib(includingemit::lower::tests,emit::waterfall_tests,emit::bitcode::opt::tests,bfe_signed_and_unsigned_match_rdna2,rcp_arcp_matches_rdna2_accuracy_and_specials, and new unit testsampled_marks_dedup_across_dominating_blocks): 62 passed, 0 failed.cargo xtask policy --staged: passed on all modified files.@davemathews12 on GitHub · 2026-11-30 05:11 UTC · original · edited 2026-11-30 05:41 UTC
I read the riskiest parts for correctness and found no bug:
v_bfe/s_bfe→Ubfe/Ibfe(7b2ee617):s_bfewidths ≥ 32 (bits 22:16) keep the shift-only result through thefullselect, so DXIL's 5-bit width masking never applies to them.Ubfegivessrc >> offwhenw + off ≥ 32, which equals the masked hardware result.32 − offtakesIbfe's arithmetic-shift branch, which matches RDNA2 extending from bit 31.fdiv arcpforv_rcp_*(d1c205c0):1 << 4, LLVM 3.7'sAllowReciprocal.SDIVbinop code, which LLVM uses forfdivon float types.fdiv(0x80 | SDiv), so an approximate division is never merged with an exact one.v_rcp_f32,v_rcp_iflag_f32andv_rcp_f16use it.010c12d): constants and types are append-only.pruneand the other passes rewrite control flow and phi inputs but never remove or renumber aV::Constor a type, so the cached ids cannot go stale.dx_opcaching by bare name matches the old full-name lookup.9830be7c):guaranteed(they execute on every loop entry, with the same lanes, before any discard).is_speculatable_pure_calllists only arithmetic, so no speculative descriptor or buffer read can be introduced.Bools::vars: the quadraticVec::containsbecomes sets, and the order of the returned variables is preserved. In a profile of synthetic programs onmain,Bools::varswas among the top self-cost entries, so this is a real fix.Measured by me on synthetic programs only:
main.mainon such programs, SipHash was ≈40% of all translation instructions, almost all of it theopt::Keytables this PR moves toFxMap.Not reviewed: the Wave32 codegen commit (
04d91440) and the SLOT_SAMPLED commits (2d113517,c2ab0192).@ExoCalibra on GitHub · 2026-11-30 11:00 UTC · original
Found an NVIDIA D3D12 PSO compilation regression in
d1c205c0when testing#3501against full in-game shaders on an RTX 3080 Ti (SM 6.8 Wave32), and opened a fix PR directly againstRulemore/VIctory-NVIDIA:pr/shader-opt:Symptom & Bisection
With this branch enabled (
VICTORY_SHADER_OPT=255),dxil.dll/dxv.exevalidates cleanly, but NVIDIA's D3D12 compiler rejects all 15 simulated hair strand interpolation compute shaders (smh_gen_{129,130,132,144,193,194,196,208,385,386,388,400,449,450,464}:CS_InterpolateStrands_94d04887_Wrapped, e.g.#8080af82aaac33df,#f7c4f227a2a4c4b2,#a68c4b8fc7bc4b5c) insideCreateComputePipelineStatewithE_OUTOFMEMORY(0x8007000E), silently dropping dynamic hair simulation in-game.Bisected with
victory.exe translate --validate --pipelines:VICTORY_SHADER_OPT=127(LICMoff): 15 / 15CS_InterpolateStrandspipelines created.VICTORY_SHADER_OPT=255(LICMon): 0 / 15 created (0x8007000Eon all 15).Root Cause & Fix
In
crates/victory-shader/src/emit/bitcode/opt.rs,d1c205c0added| Op::FDivArcp(..)to the unconditionaltruearm ofopt::Module::can_hoist(). Previously,v_rcp_*lowered viaOp::Bin(Bin::SDiv, ..), whosecan_hoistcheck (self.int_k(*rhs).is_some_and(...)) always returnedfalsefor floats, soLICMnever hoisted float divisions. AllowingOp::FDivArcpincan_hoistletsLICMspeculatively hoistfdiv arcp float 1.0, %xout of a guardedfcmp oeq float 0.0, %xbranch inside a loop into the loop preheader, which triggers NVIDIA's0x8007000Efailure on those large compute shaders.Returning
falseforOp::FDivArcp(..)incan_hoist()keepsfdiv arcp→MUFU.RCPlowering and GVN (REUSE) intact while restoring pre-d1c205c0LICM behavior:Verification (with https://github.com/Rulemore/VIctory-NVIDIA/pull/1)
cargo test -p victory-shader --locked opt::tests -- --test-threads=1: 28 passed, 0 failed (including newlicm_does_not_hoist_fdiv_arcp_out_of_loop).cargo test -p victory-shader --locked rcp_arcp -- --test-threads=1: 1 passed, 0 failed.--validate --pipelines,VICTORY_SHADER_OPT=255): 15 / 15CS_InterpolateStrandspipelines created, 3,945 / 3,945 in-game shaders (779/779 compute, 1,134/1,134 mesh, 2,032/2,032 vertex/pixel) compiled with 0 refusals; verified in-game with intact hair simulation and 0 refused PSOs.@davemathews12 on GitHub · 2026-11-30 15:46 UTC · original
Good catch @ExoCalibra. I checked
fdiv arcpand the LICM guards separately and missed how they combine (FDivArcphoisted bycan_hoist). Your fix and the in-game check (3,945/3,945 shaders, 0 refused PSOs) cover it. Thanks.Pull request closed