Shaders: fix duplicate latch folding, unreachable phi edges, and replace_const caching in DXIL bitcode #1145

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

@⁠hamdog0203 on GitHub · 2026-11-24 16:13 UTC · original
hamdog0203:fix/bitcode-latch-phi-const → main · +173 −36 · 2 files · 1 commits · open

Summary

Fixes three bugs in DXIL bitcode emission (crates/victory-shader/src/emit/bitcode.rs) with byte-identical output preserved for existing reachable single-latch shaders (written_bytes_unchanged untouched):

  1. Prevent duplicate incoming blocks when folding empty latches: When two empty back-edge latches share the same single predecessor p and target the same loop header h, folding both merged them into the same predecessor block p, producing duplicate incoming block entries with different values in h's Op::Phi (rejected by dxil.dll). Track (p, h) pairs in folded_edges (and require neither endpoint is already folded) so at most one empty latch folds per (p, h) edge.
  2. Skip unreachable blocks in live() and Op::Phi: Compute reachable() before live(&seen), skip unreachable blocks/phi-edges during liveness propagation, and omit unreachable incoming edges when writing Op::Phi instead of panicking on unnumbered values.
  3. Evict replaced key in Module::replace_const: Remove the old (ty, Const) entry from const_ids when overwriting old with new, preventing subsequent requests for the old constant from aliasing the replacement value.

Verification

Tested on Windows 11 (Build 26200), NVIDIA GeForce RTX 4060 (driver 621.35, 32-lane waves), Rust 1.98.1, Windows SDK dxil.dll (10.0.26100.0), and WARP:

  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass
  • cargo test --workspace --locked (RTX 4060): all tests pass (victory-shader: 123 passed, 0 failed, 1 benchmark ignored; including written_bytes_unchanged, dxil.dll validation, and Host::compute_pipeline on RTX 4060 and WARP)
  • VICTORY_WARP=1 cargo test -p victory-shader --locked: 123 passed, 0 failed, 1 ignored
  • cargo xtask policy: 154 files ok
  • Negative control on main (ffe310e): all 3 new regression tests (replace_const_evicts_old_cache_key, phi_with_unreachable_predecessor_validates, two_empty_latches_to_same_header_validate) fail on unpatched main.

Synthetic tests, dxil.dll, WARP, and RTX 4060 hardware only; no game data. AI-assisted.

**@⁠hamdog0203** on GitHub · 2026-11-24 16:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1145) `hamdog0203:fix/bitcode-latch-phi-const` → `main` · +173 −36 · 2 files · 1 commits · open ## Summary Fixes three bugs in DXIL bitcode emission (`crates/victory-shader/src/emit/bitcode.rs`) with byte-identical output preserved for existing reachable single-latch shaders (`written_bytes_unchanged` untouched): 1. **Prevent duplicate incoming blocks when folding empty latches:** When two empty back-edge latches share the same single predecessor `p` and target the same loop header `h`, folding both merged them into the same predecessor block `p`, producing duplicate incoming block entries with different values in `h`'s `Op::Phi` (rejected by `dxil.dll`). Track `(p, h)` pairs in `folded_edges` (and require neither endpoint is already folded) so at most one empty latch folds per `(p, h)` edge. 2. **Skip unreachable blocks in `live()` and `Op::Phi`:** Compute `reachable()` before `live(&seen)`, skip unreachable blocks/phi-edges during liveness propagation, and omit unreachable incoming edges when writing `Op::Phi` instead of panicking on unnumbered values. 3. **Evict replaced key in `Module::replace_const`:** Remove the old `(ty, Const)` entry from `const_ids` when overwriting `old` with `new`, preventing subsequent requests for the old constant from aliasing the replacement value. ## Verification Tested on Windows 11 (Build 26200), **NVIDIA GeForce RTX 4060** (driver `621.35`, 32-lane waves), Rust `1.98.1`, Windows SDK `dxil.dll` (`10.0.26100.0`), and WARP: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: pass - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: pass - `cargo test --workspace --locked` (RTX 4060): all tests pass (`victory-shader`: 123 passed, 0 failed, 1 benchmark ignored; including `written_bytes_unchanged`, `dxil.dll` validation, and `Host::compute_pipeline` on RTX 4060 and WARP) - `VICTORY_WARP=1 cargo test -p victory-shader --locked`: 123 passed, 0 failed, 1 ignored - `cargo xtask policy`: 154 files ok - Negative control on `main` (`ffe310e`): all 3 new regression tests (`replace_const_evicts_old_cache_key`, `phi_with_unreachable_predecessor_validates`, `two_empty_latches_to_same_header_validate`) fail on unpatched `main`. Synthetic tests, `dxil.dll`, WARP, and RTX 4060 hardware only; no game data. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:21:03 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:01 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at ea633e7: cargo test -p victory-shader passes, 123 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1145#issuecomment-7140042228) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at ea633e7: `cargo test -p victory-shader` passes, 123 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:17 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:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1145#issuecomment-7149400716) <!-- victory-triage v1 head=ea633e723d3c502c777b95780056700c0af71b75 verdict=needs-rebase at=2026-11-25T01:17:40Z --> 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
  • crates/victory-shader/src/emit/shader.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/1145/head:github-bot/gh-1145'
git switch 'github-bot/gh-1145'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1145'
git switch 'github-bot/gh-1145'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1145'
git switch 'github-bot/gh-1145'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1145'
git switch 'main'
git merge --squash 'github-bot/gh-1145'
git switch 'main'
git merge --ff-only 'github-bot/gh-1145'
git switch 'main'
git merge 'github-bot/gh-1145'
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!1145
No description provided.