Shader: backward dead-code elimination in DXIL bitcode emission #697

Open
github-bot wants to merge 1 commit from github-bot/gh-697 into main AGit
Owner

@⁠wbkepler on GitHub · 2026-11-24 07:00 UTC · original
wbkepler:shader/dxil-dead-code-elimination → main · +521 −94 · 2 files · 1 commits · open

Summary

Replaces fixed-point phi-only liveness in victory-shader Module::write with 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:

  • Omits dead non-phi instructions, cyclic dead phis, unreachable blocks, and unreferenced dx.op declarations from emitted DXIL bitcode.
  • Folds loop latches left empty by DCE and reuses a single record scratch Vec during FUNCTION_BLOCK serialization.
  • Prunes instruction-driven ShaderFlags (TYPED_UAV_LOADS, WAVE_OPS, INT64, RESOURCE_HEAP, SAMPLER_HEAP) via Module::active_flags in Shader::finish so declared flags and SFI0 match live post-DCE usage.

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (victory-shader: 72/72 including 3 new bitcode/DCE/dxil.dll validation tests)
  • cargo xtask policy — passed (151 files ok)
**@⁠wbkepler** on GitHub · 2026-11-24 07:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/697) `wbkepler:shader/dxil-dead-code-elimination` → `main` · +521 −94 · 2 files · 1 commits · open ## Summary Replaces fixed-point phi-only liveness in `victory-shader` `Module::write` with 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: - Omits dead non-phi instructions, cyclic dead phis, unreachable blocks, and unreferenced `dx.op` declarations from emitted DXIL bitcode. - Folds loop latches left empty by DCE and reuses a single record scratch `Vec` during `FUNCTION_BLOCK` serialization. - Prunes instruction-driven `ShaderFlags` (`TYPED_UAV_LOADS`, `WAVE_OPS`, `INT64`, `RESOURCE_HEAP`, `SAMPLER_HEAP`) via `Module::active_flags` in `Shader::finish` so declared flags and `SFI0` match live post-DCE usage. ## Verification - `cargo clippy --workspace --all-targets` — passed (zero new warnings) - `cargo clippy -p victory --features diagnostics --all-targets` — passed - `cargo test --workspace` — passed (`victory-shader`: 72/72 including 3 new bitcode/DCE/`dxil.dll` validation tests) - `cargo xtask policy` — passed (151 files ok)
- Replace fixed-point phi-only liveness in Module::write with a single-pass backward worklist seeded from side-effecting roots (stores, atomics, barriers, void/non-pure calls) and branch conditions across reachable reverse-postorder blocks.

- Omit dead non-phi instructions, cyclic dead phis, unreachable blocks, and unreferenced dx.op declarations from the emitted DXIL module, fold loop latches left empty by DCE, and reuse one record scratch Vec during FUNCTION_BLOCK serialization.

- Prune instruction-driven ShaderFlags (TYPED_UAV_LOADS, WAVE_OPS, INT64, RESOURCE_HEAP, SAMPLER_HEAP) in Shader::finish to those used by surviving instructions so declared flags and SFI0 always match live module usage.

- Add unit and dxil.dll validation tests covering dead instruction/declaration elimination, latch folding, side-effecting atomic preservation, and post-DCE ShaderFlags pruning.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:27 +00:00
Author
Owner

@⁠iurysf on GitHub · 2026-11-24 08:27 UTC · original

Measured offline against main c2e7254 with victory translate --list --validate over the title's shaders.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.

**@⁠iurysf** on GitHub · 2026-11-24 08:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/697#issuecomment-7126164211) Measured offline against main `c2e7254` with `victory translate --list --validate` over the title's `shaders.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.
Author
Owner

@⁠molodayamama on GitHub · 2026-11-24 14:01 UTC · original

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.

**@⁠molodayamama** on GitHub · 2026-11-24 14:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/697#issuecomment-7133703093) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:16 UTC · original

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 current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/697#issuecomment-7149388153) <!-- victory-triage v1 head=fa8d0845f7a4de09e913638acbad983591f50bdf verdict=needs-rebase at=2026-11-25T01:16:55Z --> 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 current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/bitcode.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/697/head:github-bot/gh-697'
git switch 'github-bot/gh-697'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-697'
git switch 'github-bot/gh-697'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-697'
git switch 'github-bot/gh-697'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-697'
git switch 'main'
git merge --squash 'github-bot/gh-697'
git switch 'main'
git merge --ff-only 'github-bot/gh-697'
git switch 'main'
git merge 'github-bot/gh-697'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!697
No description provided.