shader: fold shift-mask, masked bitwise, associative mul, and complement ops in DXIL opt #2357
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-11-29T12:21:19Z.
What 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
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Ondra97 on 2026-11-29T14:44:10Z.
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.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-11-29T16:18:13Z.
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).