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

Open
mynzjerko wants to merge 1 commit from upstream-pr/317 into main
mynzjerko commented 2026-11-24 23:30:53 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by mynzjerko on 2026-11-24T23:30:53Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593544561 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/317). Originally posted by [mynzjerko](https://github.com/mynzjerko) on 2026-11-24T23:30:53Z. --- ## 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._
MamaLeVrai commented 2026-11-25 11:10:40 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by MamaLeVrai on 2026-11-25T10:59:16Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7160436473 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/317#issuecomment-7160436473). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T10:59:16Z. --- 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.
mynzjerko commented 2026-11-25 17:08:05 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by mynzjerko on 2026-11-25T17:05:23Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:comment:7168986499 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/317#issuecomment-7168986499). Originally posted by [mynzjerko](https://github.com/mynzjerko) on 2026-11-25T17:05:23Z. --- Thanks @MamaLeVrai for verifying this on RX 6950 XT against \ 85101b\!
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/317:upstream-pr/317'
git switch 'upstream-pr/317'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/317'
git switch 'upstream-pr/317'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/317'
git switch 'upstream-pr/317'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/317'
git switch 'main'
git merge --squash 'upstream-pr/317'
git switch 'main'
git merge --ff-only 'upstream-pr/317'
git switch 'main'
git merge 'upstream-pr/317'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!317
No description provided.