Shaders: keep annotateHandle local to its block to avoid AMD compiler crash #317

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

@⁠mynzjerko on GitHub · 2026-11-24 23:30 UTC · original
mynzjerko:fix/amd-annotate-handle-reuse → main · +35 −0 · 1 files · 1 commits · open

Problem

On AMD RDNA 4 (tested on Radeon RX 9070, driver 32.0.32029.2010), CreateComputePipelineState crashes inside amdxc64.dll (0xC0000005 access violation, as reported in #3) on CS_RaytracingResolve variants when VICTORY_SHADER_OPT includes REUSE (4).

Bisecting VICTORY_SHADER_OPT isolated the crash specifically to REUSE deduplicating dx.op.annotateHandle across basic blocks in crates/victory-shader/src/emit/bitcode/opt.rs.

Fix

Classify dx.op.annotateHandle as Effect::Lanes in bitcode::opt::effect:

  • Each basic block keeps its own annotateHandle instead of reusing one from a dominating block across control flow.
  • Same-block reuse (so LOADS can still merge redundant reads within a block) and dead-code removal (DEAD) are preserved.
  • annotateHandle is a DXIL metadata annotation and emits no GPU instructions, so there is no runtime cost.

Verification

  • Added unit test an_annotated_handle_is_not_reused_across_blocks in crates/victory-shader/src/emit/bitcode/opt.rs.
  • cargo test -p victory-shader, cargo clippy -p victory-shader --all-targets -- -D warnings, and cargo xtask policy all pass.
  • Tested offline on AMD Radeon RX 9070 (Adrenalin 32.0.32029.2010) with full VICTORY_SHADER_OPT enabled:
    • All 40 matching hashes from #3: 40/40 emitted, validated with dxil.dll, and created D3D12 pipelines (both default and with VICTORY_VIEW_LIMIT=1000000, vs 5/5 crashing before).
    • Full CS_RaytracingResolve set: 1,000 / 1,000 emitted, validated, and created D3D12 pipelines (EXIT=0, 0 crashes).

AI-assisted (Antigravity / Gemini 4 Neon); verified locally on an AMD Radeon RX 9070 with my own copy of the title. Hashes and counts only; no game data.

**@⁠mynzjerko** on GitHub · 2026-11-24 23:30 UTC · [original](https://github.com/fxceless/victory-fork/pull/317) `mynzjerko:fix/amd-annotate-handle-reuse` → `main` · +35 −0 · 1 files · 1 commits · open ## Problem On AMD RDNA 4 (tested on Radeon RX 9070, driver `32.0.32029.2010`), `CreateComputePipelineState` crashes inside `amdxc64.dll` (`0xC0000005` access violation, as reported in #3) on `CS_RaytracingResolve` variants when `VICTORY_SHADER_OPT` includes `REUSE` (`4`). Bisecting `VICTORY_SHADER_OPT` isolated the crash specifically to `REUSE` deduplicating `dx.op.annotateHandle` across basic blocks in `crates/victory-shader/src/emit/bitcode/opt.rs`. ## Fix Classify `dx.op.annotateHandle` as `Effect::Lanes` in `bitcode::opt::effect`: - Each basic block keeps its own `annotateHandle` instead of reusing one from a dominating block across control flow. - Same-block reuse (so `LOADS` can still merge redundant reads within a block) and dead-code removal (`DEAD`) are preserved. - `annotateHandle` is a DXIL metadata annotation and emits no GPU instructions, so there is no runtime cost. ## Verification - Added unit test `an_annotated_handle_is_not_reused_across_blocks` in `crates/victory-shader/src/emit/bitcode/opt.rs`. - `cargo test -p victory-shader`, `cargo clippy -p victory-shader --all-targets -- -D warnings`, and `cargo xtask policy` all pass. - Tested offline on AMD Radeon RX 9070 (Adrenalin `32.0.32029.2010`) with full `VICTORY_SHADER_OPT` enabled: - All 40 matching hashes from #3: 40/40 emitted, validated with `dxil.dll`, and created D3D12 pipelines (both default and with `VICTORY_VIEW_LIMIT=1000000`, vs 5/5 crashing before). - Full `CS_RaytracingResolve` set: **1,000 / 1,000** emitted, validated, and created D3D12 pipelines (`EXIT=0`, 0 crashes). _AI-assisted (Antigravity / Gemini 4 Neon); verified locally on an AMD Radeon RX 9070 with my own copy of the title. Hashes and counts only; no game data._
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:40:35 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 10:59 UTC · original

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head ed2c7fc into main f85101b in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings fails with exactly the errors main itself has on this machine (placed_filler_twins, depth_written, a sort; PR #841 fixes them); with --all-features it fails with the same number of errors as main (4). This PR adds none and removes none. cargo test --workspace --locked: run 1: one failure, run 2: 556 passed, 0 failed, 11 ignored (main alone: 555 passed, 11 ignored). The failure is indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields, which fails on main itself most runs here (PR #849 fixes its assertion; see issue #850). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 10:59 UTC · [original](https://github.com/fxceless/victory-fork/pull/317#issuecomment-7160436473) Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head `ed2c7fc` into `main` `f85101b` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings` fails with exactly the errors `main` itself has on this machine (`placed_filler_twins`, `depth_written`, a sort; PR #841 fixes them); with `--all-features` it fails with the same number of errors as `main` (4). This PR adds none and removes none. `cargo test --workspace --locked`: run 1: one failure, run 2: 556 passed, 0 failed, 11 ignored (`main` alone: 555 passed, 11 ignored). The failure is `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields`, which fails on `main` itself most runs here (PR #849 fixes its assertion; see issue #850). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠mynzjerko on GitHub · 2026-11-25 17:05 UTC · original

Thanks @⁠MamaLeVrai for verifying this on RX 6950 XT against \ 85101b!

**@⁠mynzjerko** on GitHub · 2026-11-25 17:05 UTC · [original](https://github.com/fxceless/victory-fork/pull/317#issuecomment-7168986499) Thanks @⁠MamaLeVrai for verifying this on RX 6950 XT against \ 85101b\!
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/317/head:github-bot/gh-317'
git switch 'github-bot/gh-317'

Merge

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