Shader: backward dead-code elimination in DXIL bitcode emission #697
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/697"
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 Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T07:00:19Z.
Summary
Replaces fixed-point phi-only liveness in
victory-shaderModule::writewith a single-pass backward worklist over reachable reverse-postorder blocks seeded from side-effecting roots (stores, atomics, barriers, void/non-pure calls,dx.op.atomic*) and branch conditions:dx.opdeclarations from emitted DXIL bitcode.VecduringFUNCTION_BLOCKserialization.ShaderFlags(TYPED_UAV_LOADS,WAVE_OPS,INT64,RESOURCE_HEAP,SAMPLER_HEAP) viaModule::active_flagsinShader::finishso declared flags andSFI0match live post-DCE usage.Verification
cargo clippy --workspace --all-targets— passed (zero new warnings)cargo clippy -p victory --features diagnostics --all-targets— passedcargo test --workspace— passed (victory-shader: 72/72 including 3 new bitcode/DCE/dxil.dllvalidation tests)cargo xtask policy— passed (151 files ok)Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T07:09:01Z.
Review: APPROVED
Tested on Windows 11 MSVC (rustc 1.98.1):
Backward worklist DCE correctly eliminates dead non-phi opcodes, cyclic dead phis, and prunes unused ShaderFlags before DXIL container bitcode emission.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T08:48:16Z.
Review: COMMENTED
Heads-up: no longer merges cleanly with current main (
2005e35a) — conflict incrates/victory-shader/src/emit/bitcode.rs. Needs a rebase.For the record, the head alone passes on macOS 26 arm64 / rustc 1.98.1:
cargo test -p victory-shader --locked→ 58 passed / 0 failed (against its own base). The backward-DCE worklist replaces fixed-point phi-only liveness inModule::write— the DXIL bitcode emission path, so the Windows shader run is the real check for output equivalence.Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T08:27:47Z.
Measured offline against main
c2e7254withvictory translate --list --validateover the title'sshaders.rpf+ executable (26,096 programs), dxil.dll 1.9.2602.17, comparing outcomes program by program: no outcome changes. All 25,902 programs translate, fail, validate or get rejected exactly as on main: 21,983 validated, 185 rejected, 3,734 failed. So the dead-code elimination doesn't break validation anywhere in this corpus. (I didn't measure the size or compile-time effect.)AI-assisted.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:27:31Z.
Review: APPROVED
Tested
2eea8e2on Windows 11, RTX 5070, MSVC:cargo test -p victory-shader -- --test-threads=172 passed, including the GPU VALU tests.cargo clippy -p victory-shader --all-targetsis clean. I also ranvictory translate --validate --pipelineson the local title executable at the merge base (d2a4bae) and at this head. Both give 12 of 12 vertex/pixel programs emitted, 12 validated and 12 pipelines, with identical I/O counts.is_root: I checked every non-voidAttr::NoUnwindop the lowerer emits (wavePrefixOp,waveActiveOp,waveActiveBit,waveActiveBallot,waveReadLaneFirst,waveReadLaneAt,quadReadLaneAt,atomicBinOp,atomicCompareExchange). Only the atomics have side effects, and thedx.op.atomicprefix keeps those live. Void calls (storeOutput,textureStore,emitIndices,discard, …) are always roots. So dropping an unused wave op is the only new removal among calls, and that is safe.NoUnwind(for examplebufferUpdateCounter, if it is ever lowered) would be silently removed when its result is unused. A short comment onis_root, or an explicit allow-list next to thedx.op.atomicprefix, would make that rule visible to whoever adds the next op.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by molodayamama on 2026-11-24T14:01:10Z.
Independent Windows check of
2eea8e2e817032c7574c64b2adb8fa870504d75a(Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).cargo test -p victory-shader --locked --lib dead_instructions_and_unused_declarations_are_eliminated -- --test-threads=1 --nocapture: 1 passed.cargo test -p victory-shader --locked --lib side_effecting_atomics_with_unused_results_stay_live -- --test-threads=1 --nocapture: 1 passed.cargo test -p victory-shader --locked --lib post_dce_shader_flags_validate_with_dxil -- --test-threads=1 --nocapture: 1 passed.The focused tests cover removal of dead instructions and unused declarations, keeping a side-effecting atomic with an unused result, and DXIL shader flags. This checks the emitted module and the local validator, without submitting a dispatch.
Only source-built synthetic fixtures were used. AI-assisted verification.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:16:56Z.
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/bitcode.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.