Shaders/opt: keep resource handles block-local, clear stale DOUBLES flag, and guard double-latch folding #576

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

@⁠Lewandox on GitHub · 2026-11-25 02:26 UTC · original
Lewandox:fix/shader-opt-latches-flags-handles → main · +159 −5 · 3 files · 1 commits · open

Summary

Fixes three soundness / DXIL validation bugs in the shader clean-up passes (VICTORY_SHADER_OPT, related to #310):

  1. Keep resource handle intrinsics block-local (opt.rs): createHandleFromHeap, createHandleFromBinding, and nnotateHandle were classified as Effect::Pure (Attr::ReadNone), allowing REUSE to share handles across basic blocks (including NonUniformResourceIndex heap handles). Reusing handles across blocks breaks DXIL handle legalisation on GPU drivers (NVIDIA refusals / visual corruption, AMD compiler crashes). Classifying them as Effect::Lanes (and checking wave*/quad* before Attr::ReadNone) prevents cross-block handle reuse while preserving same-block LOADS deduplication and DEAD removal.
  2. Clear stale lags::DOUBLES after DEAD/FOLD (opt.rs, shader.rs): Usage did not track TypeDef::Double, so eliminating the last f64 instruction left SFI0 bit 0 (DOUBLES) set and caused dxil.dll to reject the shader (Flags must match usage).
  3. Guard empty-latch folding against duplicate edges (itcode.rs): When opt empties both arms (latch_a, latch_b) of a CondBr jumping back to loop header head, both latches satisfied !succs(*p).contains(&h) and folded into the same predecessor p, emitting two PHI entries from p with distinct incoming values (invalid LLVM/DXIL bitcode). Also guards against folding into/from an already-folded block.

Verification

  • Added 3 unit/validation tests in emit::bitcode::opt::tests:

esource_handles_are_block_local_and_not_reused_across_blocks

  • dead_double_clears_doubles_flag_and_validates (verified against dxil.dll)
  • wo_empty_latches_from_one_branch_validate_with_dxil (verified against dxil.dll)
    
  • Ran cargo test -p victory-shader --lib -- opt::tests bitcode::tests with VICTORY_DXIL set: 19 passed, 0 failed (1 ignored benchmark).
  • Not run on a retail game build; all tests use synthetic shaders.

AI-assisted.

**@⁠Lewandox** on GitHub · 2026-11-25 02:26 UTC · [original](https://github.com/fxceless/victory-fork/pull/576) `Lewandox:fix/shader-opt-latches-flags-handles` → `main` · +159 −5 · 3 files · 1 commits · open ## Summary Fixes three soundness / DXIL validation bugs in the shader clean-up passes (VICTORY_SHADER_OPT, related to #310): 1. **Keep resource handle intrinsics block-local (opt.rs)**: createHandleFromHeap, createHandleFromBinding, and nnotateHandle were classified as Effect::Pure (Attr::ReadNone), allowing REUSE to share handles across basic blocks (including NonUniformResourceIndex heap handles). Reusing handles across blocks breaks DXIL handle legalisation on GPU drivers (NVIDIA refusals / visual corruption, AMD compiler crashes). Classifying them as Effect::Lanes (and checking wave*/quad* before Attr::ReadNone) prevents cross-block handle reuse while preserving same-block LOADS deduplication and DEAD removal. 2. **Clear stale lags::DOUBLES after DEAD/FOLD (opt.rs, shader.rs)**: Usage did not track TypeDef::Double, so eliminating the last f64 instruction left SFI0 bit 0 (DOUBLES) set and caused dxil.dll to reject the shader (Flags must match usage). 3. **Guard empty-latch folding against duplicate edges (itcode.rs)**: When opt empties both arms (latch_a, latch_b) of a CondBr jumping back to loop header head, both latches satisfied !succs(*p).contains(&h) and folded into the same predecessor p, emitting two PHI entries from p with distinct incoming values (invalid LLVM/DXIL bitcode). Also guards against folding into/from an already-folded block. ## Verification - Added 3 unit/validation tests in emit::bitcode::opt::tests: - esource_handles_are_block_local_and_not_reused_across_blocks - dead_double_clears_doubles_flag_and_validates (verified against dxil.dll) - wo_empty_latches_from_one_branch_validate_with_dxil (verified against dxil.dll) - Ran cargo test -p victory-shader --lib -- opt::tests bitcode::tests with VICTORY_DXIL set: **19 passed, 0 failed** (1 ignored benchmark). - Not run on a retail game build; all tests use synthetic shaders. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:46:42 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-576'
git switch 'github-bot/gh-576'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-576'
git switch 'github-bot/gh-576'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-576'
git switch 'main'
git merge --squash 'github-bot/gh-576'
git switch 'main'
git merge --ff-only 'github-bot/gh-576'
git switch 'main'
git merge 'github-bot/gh-576'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.