perf(shader): add DXIL pure LICM, canonical ptr-path LDS forwarding, and barrier dedup #41
No reviewers
Labels
No labels
accessibility
bench-bm-v1
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/PastiiJay--klbf-lab!41
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-41"
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-25 21:01 UTC · original
Vladimir-Human:shader/dxil-opt-licm-alloca→beta· +4645 −89 · 2 files · 2 commits · openAI-assisted clean-room contribution (
victory-shader, synthetic DXIL bitcode tests + hardware GPU parity only — no title files used).Summary
Ports four sound DXIL bitcode optimization passes onto
crates/victory-shader/src/emit/bitcode/opt.rs(and exposes pass-mask test control incrates/victory-shader/src/emit/mod.rswhile preservingtranslation_fingerprint()and all upstream additions):FACTS): folds redundant compares/selects along dominating branches without emitting AMDfcmp one(NaN-safe).LICM = 64): hoists loop-invariant pure value-only DXIL math calls, loads on non-escaping invariant slots, and bounded GEPs across split loop preheaders (split_preheader, keeping dominators/SSA/outer loops coherent), while strictly gating non-guaranteed blocks and tracking per-instructionWriteKind::All/dx.op.discardcutoffs.LOADS = 16): unboundedtrace_ptr/escaped_globalscanonicalization with signed indices, strict per-level bounds, and scalar-leaf type matching, forwarding intra-blockSharedGloballoads/DSE across disjoint pointers.BARRIERS = 128): eliminates provably redundant adjacent barriers via(prev & m) == mwithout accumulating hazard state across unrelated regions.crates/victory-shader/src/emit/bitcode/opt.rsandcrates/victory-shader/src/emit/mod.rs(git merge-treeclean againstbeta).Verification (
betae328c88, RTX 4070 SUPER / i5-13400F)cargo clippy -p victory-shader --all-targets -- -D warnings(default &--all-features): 0 warnings.cargo test -p victory-shader --lib: 235 passed, 0 failed (4 ignored).VICTORY_D3D12_DEBUG=1 VICTORY_REQUIRE_HW_GPU=1 cargo test -p victory-shader --lib dxil_opt_hw_gpu_bit_exact_parity_and_validation: passed on hardware GPU (opt=0vsold_bitsvsALLbit-exact).bench_dxil_opt_hw_gpu(during parallel build load; uncontested benchmark follow-up planned): loop body-85.7%(42 -> 6insts), GPU median109.57 us -> 95.23 us(1.15x), LDS+barrier loop164.86 us -> 111.62 us(1.48x), real GFX10 loop99.33 us -> 83.97 us(1.18x).@PastiiJay on GitHub · 2026-11-25 21:07 UTC · original
Thanks a lot @Vladimir-Human! We test one change at a time on the RX 9070 XT (same save, same 7-minute run, fps and picture compared with our reference build), so this one goes into that queue on its own. Results will be posted here, then we merge or report back what we saw.
@HandshakeHackin on GitHub · 2026-11-25 21:09 UTC · original
On
ba88ab0, the optimized and unoptimized shaders gave byte-identical output on Microsoft’s D3D12 software adapter (WARP) for the loop, shared-memory/barrier and translated GFX10 fixtures. The translated loop also matched the expected value for every output lane. I required WARP initialization and made a missing Windows SDK DXIL validator fail the test, so neither check could silently skip. Windows parity test and logI also tested this revision with the eight queued beta fixes and the maintainer’s WARP test correction. Both strict workspace Clippy checks passed, the asset check passed for 190 files, and the Windows suite finished with 596 passed, 0 failed and 13 ignored. The RX 9070 XT run will give the in-game picture and frame-rate comparison. Integration run
@PastiiJay on GitHub · 2026-11-25 21:10 UTC · original
Thank you @HandshakeHackin, byte-identical output on WARP for all three fixtures, with WARP and the DXIL validator made mandatory so nothing can skip, is exactly the safety net a shader optimizer needs. And 596 passed / 0 failed with the eight queued beta fixes on top is great. The RX 9070 XT picture and frame-rate comparison is next on our side.
@Proudnoob4 on GitHub · 2026-11-26 07:11 UTC · original
Live-tested this PR on an RTX 4080 16 GB / i5-13600K / Windows 10 (GTA 6
--console series-s,render_scale=0.6666667, RT off,release, ported ontoVIctory-NVIDIAwithLICM=128,BARRIERS=256,DEFAULT=447preservingWIDE=64):Results
bitcode::opttests pass on RTX 4080, includingdxil_opt_hw_gpu_bit_exact_parity_and_validationandevery_pass_leaves_what_random_programs_store.making==0):VICTORY_SHADER_OPT=63): median 25.40 fps (39.3 ms/frame), p9027.0 fps, max27.2 fps(n=405s intervals).#41(+ LICM + BARRIERS + canonical ptr-path LOADS/DSE + FOLD/FACTS): median 27.20 fps (36.7 ms/frame), p9027.8 fps, max28.6 fps(35.0 ms) acrossn=96settled 5s intervals (8 minutes continuous, 0 stutters >55 ms).+1.80 fps(-2.6 ms/frame) with native-looking visuals and zero artifacts!n=50):P0, 2,805 MHz,99.8 W,99%GPU util,7%VRAM util, max12,809 MiBVRAM.Two Practical Notes
VICTORY_PIPELINE_WORKERS=16withVICTORY_PIPELINE_LOWEST=0starved the submitting thread (that thread workedjumped 24 ms → 41 ms). SettingVICTORY_PIPELINE_WORKERS=6+VICTORY_PIPELINE_LOWEST=1completely avoided starvation once the cache populated.BARRIERSon Wave32 (NVIDIA): Inlower.rs(split_lds), adx.op.barrieris emitted before everyds_readandds_writein all-lane blocks — so consecutiveds_reads have loads standing between the barriers, preventing#41's adjacentBARRIERSpass from dropping them. Coalescing Read-after-Read (or tracking read-only phase between barriers inlower.rs/opt.rs) looks like another big win on NVIDIA!@PastiiJay on GitHub · 2026-11-26 07:11 UTC · original
Thanks @Proudnoob4, a 10-minute A/B in the same scene with frame-time percentiles is exactly what this PR needed. Noted: +1.8 fps median on the RTX 4080, the
PIPELINE_WORKERS=6/LOWEST=1setting for cold caches, and the read-after-read barrier idea insplit_ldsas a follow-up.@HandshakeHackin on GitHub · 2026-11-26 08:35 UTC · original
I tried the read-after-read suggestion on top of
ba88ab0. With the PR’sBARRIERSbit enabled, two adjacent, unguardedds_read_b32instructions in the same all-lane block share one group barrier. In the test shader (write, read, read, overwrite, read), the Wave32 DXIL went from five barriers to four. The barriers before and after the overwrite stayed in place. Inserting one instruction between the two reads kept all five barriers. The unmodified PR emitted five in both cases.The Windows SDK validated the Wave32 binaries. For WARP execution, the harness omitted the wave-width declaration and checked that the entry-point instructions were identical to each validated version. Both fixtures matched all 192 expected output dwords with the pass off and on. Strict shader Clippy passed, and the Windows shader suite passed 236 tests with four ignored using the maintainer’s WARP runner correction. Physical Wave32 execution and frame timing are still open. Patch and runnable fixture · Windows comparison and readback
@Vladimir-Human on GitHub · 2026-11-26 09:56 UTC · original
Thanks @Proudnoob4 for the 10-minute RTX 4080 A/B run (
+1.80 fpsmedian /-2.6 ms/frame) and for spotting the Wave32split_ldsread-after-read barrier opportunity, @HandshakeHackin for prototyping and validating thewrite -> read -> read -> overwrite -> read(5 -> 4barriers) fixture, and @PastiiJay!Pushed
690b4b2implementing bounded read-after-read LDS barrier coalescing directly inbitcode::optunderBARRIERS(128), keeping this PR confined toopt.rsandmod.rs:BarrierState/RarState): Drops an intra-block middledx.op.barrier(80, mode)between consecutive non-escapingaddrspace(3)(LDS) read phases only when bounded on both sides:(anchor_mode & 9) == 9and(anchor_mode & mid_mode) == mid_mode), so every thread in the group has converged and fenced shared memory before the first read.B_next, assplit_ldsemits before anyds_write/ds_atomic), orTerm::Ret(for group/TGSM-only barrier modes followed only by non-atomic UAV/output sink stores). Requiring the right bound guarantees a read-to-write (WAR) barrier is never dropped before a branch into an un-barriered LDS store.ReadNoneintrinsics, and non-escapingspace 0/ constant loads betweends_read*operations coalesce cleanly (N -> 1barrier acrossNconsecutive reads:BWBRBRBWBR->BWBRRBWBR, andBWBRBR->BWBRRbefores_endpgm).Op::Store, LDS or UAV atomic (AtomicRmw,CmpXchg,atomicBinOp), resource load/store call (bufferLoad,rawBufferLoad,bufferStore),ReadOnlycall, wave/quad/deriv op, fence-onlybarrier(8), or control-flow edge strictly resets tracking and preserves all barriers.690b4b2(physical Wave32 RTX 4070 SUPER + D3D12 WARP + Windows SDKdxil.dll&dxc -dumpbin):read_after_read_barrier_coalescing_and_soundness_negatives(IR unit suite) andhw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity(RDNA2 Wave32split_ldspositive + soundness-negative fixtures).BWBRBRBWBR -> BWBRRBWBR(5 -> 4) andBWBRBR -> BWBRR(3 -> 2), with all 192 output dwords matching analytically and bit-for-bit acrossopt=0,BARRIERS, andALLon both physical Wave32 (RTX 4070 SUPER,VICTORY_REQUIRE_HW_GPU=1) and D3D12 WARP.cargo test -p victory-shader --all-targets --locked: 237 passed; 0 failed; 4 ignoredcargo clippy -p victory-shader --all-targets --locked -- -D warnings: 0 warningscargo run --locked -p xtask -- policy --staged: asset policy: 2 files ok@PastiiJay on GitHub · 2026-11-26 10:42 UTC · original
Thanks, nice to see the read-after-read idea land so quickly. It's on our list for an in-game pass on AMD.
@Kal0s-design on GitHub · 2026-11-26 15:47 UTC · original
Independent check of
690b4b2on Windows (CPU only, no game files), focused on the memory passes and the new read-after-read barrier coalescing.every_pass_leaves_what_random_programs_storeis a good net for the scalar passes, but its generator never emits a load, a store or a barrier, and its interpreter panics on them. SoLOADS, the load half ofLICMandBARRIERSwere only covered by the hand-written cases and the three WARP fixtures. I wrote a local harness (not pushed) to fill that in:Gen(branches, short loops, joins), plus two private arrays and two LDS arrays, constant and masked dynamic indices, anddx.op.barrierat the top level only, so it stays uniform. Half the phases are straight-line, so several barriers land in one block, which is where the read-after-read rule works;tid + 4k), touched only at own slots, or read anywhere;DEAD,FOLD,REUSE,FACTS,LOADS,LICM,BARRIERS, the memory pairs, andALL), andwrite()has to go through.Result on
690b4b2: 30,000 programs, 5.94 million checks, no difference.ALLremoved 24,899 barriers and 161,853 loads/stores across them, so the passes had real work.To make sure the harness can fail, I planted three bugs one at a time and each was caught within the first few dozen seeds:
BarrierState::resetno longer clearingrar, so a middle barrier is dropped across an own-slot LDS store (caught underBARRIERS; a hand-built anchor / read / barrier / store / read / barrier case goes from 3 to 2 barriers and two threads then see different values);LOADS);can_hoistaccepting any load (caught underLICM).What this does not cover:
(prev & m) == mand(m & 9) == 9checks read right to me, but this harness doesn't test them;AI-assisted: yes (Claude Code). The numbers are from runs on my machine.
@PastiiJay on GitHub · 2026-11-26 15:56 UTC · original
Thanks @Kal0s-design, a random-program harness that actually emits loads, stores and barriers is the coverage the existing net was missing. If you are willing to push it as a test-only PR on top of #41, it would keep guarding these passes after merge.
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.