Repository navigation
Conversation
…it time The DXIL module builder pushed an instruction for every bin/cmp/select/ cast even when both operands were already constants, or one operand was the identity (x & -1, x | 0, x + 0, x * 1, x << 0, x / 1). The driver folds those at PSO compile time anyway; folding at emit time keeps the DXIL — and so dxil.dll validation, the on-disk shader cache and the driver's compile — smaller. Folding is conservative where LLVM would not fold: shifts at or past the type width stay instructions (poison), division by zero and the i64::MIN / -1 overflow stay instructions, NaN float operands keep the instruction (the payload could differ), and constants fold per-width with two's-complement wrap (i8 included), sign-extended compares, and full fcmp predicate semantics. select drops to an arm on a constant condition or equal arms; casts of constants fold for width changes and i32<->f32 bitcasts. Tests pin the folds (including the stay-an-instruction cases) and that only the two un-foldable ops in the test module remain instructions; written_bytes_unchanged goldens updated to the folded output. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-shader --lib emit::bitcode::— 9 passed, 0 failed (1 ignored)cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok
Clean emit-time constant folding and algebraic identity simplification for bin/cmp/select/cast ops with thorough unit tests. Looks good.
AI-assisted (Gemini 4 Neon).
|
Verified head
AI-assisted; synthetic tests only, no game files. |
|
Thanks for the independent verification on RDNA4/WARP — 124 passed / 0 failed matches what I measured here (Windows, RX 7900 XT path) when I opened it. The four new tests are |
…nd identity ops at emit time
catminou4
left a comment
There was a problem hiding this comment.
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 100 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows.
Emit-time folding of constant bin/cmp/select/cast ops and identity ops: bits_of/sext_bits/fold_bin/fold_bin_identity with careful bit-width handling. +4 macOS tests (100 total).
|
Measured offline on the title's shaders (as in #1247): merged onto main This looks like folding removing the last use of an operation, while the shader's feature flags (the ones the validator recomputes from the module) still declare it. Recomputing or trimming the flags after folding might cover it. Offline counts only; no program names or data. |
|
Automated triage for the maintainers. This pull request no longer merges cleanly into Generated by Claude Code |
…nd identity ops at emit time
|
Measured on current Triage asked for a census and a benefit. I merged head
What this does not show: GPU time. A driver's compiler folds constants itself, so the likelier gain is pipeline compile time and cache size. I did not measure either. Local title data, offline, CPU only; counts and validator reasons only. The title was not run. AI-assisted |
The DXIL module builder (
emit/bitcode.rs) pushed an instruction for everybin/cmp/select/cast, even when both operands were already constants or one was the identity (x & -1,x | 0,x + 0,x * 1,x << 0,x / 1). The driver folds those at PSO compile time anyway; folding at emit time keeps the DXIL — and with it dxil.dll validation, the on-disk shader cache (#1094) and the driver's compile — smaller.Folding is conservative where LLVM would not fold: shifts at/past the type width stay instructions (poison), division by zero and
i64::MIN / -1stay instructions, NaN float operands keep the instruction (payload could differ). Int constants fold per-width with two's-complement wrap (i8 included), compares fold with signed/unsigned semantics, floats fold Add/Sub/Mul/Div/Rem on non-NaN operands,selectdrops to an arm on a constant condition or equal arms, and casts of constants fold for width changes and i32<->f32 bitcasts.Verified on Windows 11 / Rust 1.98.1:
cargo test -p victory-shader --lib124 passed / 0 failed / 1 ignored (GPU + dxil.dll validation included, so emitted DXIL is still valid and executes identically),cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warningsclean,cargo build --release -p victorybuilds,rustfmt --edition 2024 --checkclean on the changed file. New unit tests pin each fold and the stay-an-instruction cases;written_bytes_unchangedgoldens updated to the folded output (64x64x64: 38916 -> 38920 bytes with a constant where an instruction was).