shader: fold shift-mask, masked bitwise, associative mul, and complement ops in DXIL opt #2357
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!2357
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2357"
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?
@nidea1 on GitHub · 2026-11-29 12:21 UTC · original
nidea1:perf/dxil-opt-shift-mask-mul→main· +372 −35 · 1 files · 1 commits · merged 2026-11-30 14:12 UTCWhat it changes
Extends the integer peephole and strength-reduction pass in
crates/victory-shader/src/emit/bitcode/opt.rswith sound algebraic folds common in lowered RDNA2 compute and graphics shaders:(x << s) & m,(x >> s) & m,(x & m) << s,(x & m) >> s)(x & m1) & m2,(x | k) & m,(x ^ k) & m, redundant mask elimination)(x * c1) * c2 -> x * (c1.wrapping_mul(c2)))~(~x),x & ~x,x | ~x,x ^ ~x,x & (x | y),x | (x & y))All folds preserve exact 32-bit two's-complement DXIL semantics and run within the existing fixpoint loop without adding extra passes.
How it was tested
bitcode::optfolds all targeted patterns; 27/27 tests invictory-shaderbitcode::opt::pass, includingshift_mask_mul_complement_and_absorption_fold,dxil_opt_hw_gpu_bit_exact_parity_and_validation, and randomized differential testing (every_pass_leaves_what_random_programs_store)cargo testpassed for the crates it touches: yes (cargo test -p victory-shader --lib --locked bitcode::opt::— 27 passed, 0 failed, 1 ignored GPU benchmark)Checked for overlap
@Ondra97 on GitHub · 2026-11-29 14:44 UTC · original
Independent check of exact head
482dce1aapplied as the only source delta to a local Windows diagnostic control. Locked offline build succeeded, and bitcode::opt:: passed 27 tests with one ignored. GPU is an RTX 4070 Ti SUPER on driver 621.40.I isolated one compute recipe that reproduces a long native create. It contains about 29,000 decoded console instructions and uses the exact Wave64 folding path on this host. Control produced 1,808,720 bytes of DXIL and took 67.956 s in the native create. This patch produced 1,808,700 bytes and took 61.256 s in one isolated observation. The two DXIL payloads were distinct and the existing driver cache was left in place.
A separate seven-minute start with empty emulator caches, RT off and FG off reused the same diagnostic binary. This same candidate PSO took 69.311 s in the game. REA sampled its exact calling thread inside the NVIDIA compiler after about 67 s. This test still had a sizeable unresolved pipeline queue at the end and did not verify a playable cold start. The result is specific to this large folded shader and does not measure the broader runtime benefit of the peepholes.
@nidea1 on GitHub · 2026-11-29 16:18 UTC · original · edited 2026-11-29 17:31 UTC
Thanks @Ondra97 for the independent test run and profiling datapoint! That 1,808,720-byte Wave64-folded compute shader breakdown pointed straight to the real driver compile-time bottlenecks (which scalar shift/mul folding alone in this PR barely touches).
Profiling that exact DXIL output under
VICTORY_SAMPLED_MARKS=1showed two dominant bloat sources:SLOT_SAMPLEDmarking diamonds (1,547atomics /+6,184basic blocks /+232 KBDXIL in that shader alone) emitted on every repeated texture sample.guard_select+bitcast+ nestedi1 selectblowup (71,537selects including36,153guard_select, and62,533bitcasts) across Wave64-folded per-half chains and narrowedand(g, inner)guards.We split the fixes into focused follow-up PRs (all clean against
mainand orthogonal to this PR):mark_sampledalong dominated IR pathsknown-And/Or nested select collapsingMeasured on RTX 3060 Ti (same-session idle back-to-back uncached
CreateComputePipelineStateA/B vsmain55d06914on that 1,808,720 B Wave64-folded shader):1,808,720 B->1,316,688 B(-27.2%/-492 KB)8,548->2,822(-67.0%)251,709->184,474(-26.7%; bitcasts-45.4%,guard_select-41.6%,SLOT_SAMPLEDatomics-89.9%)CreateComputePipelineState:29,080 ms->19,078 ms(-34.4%/1.52xfaster; top-3 Wave64 total66.1 s->48.1 s,-27.2%/1.37xfaster).