shader(ir): keep empty-EXEC skip guards around potentially non-terminating loops #255

Merged
Androtim merged 1 commit from upstream-pr/255 into main 2026-11-30 15:25:23 +00:00
Androtim commented 2026-11-30 12:29:30 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-30T12:29:30Z.


Summary

  • Strengthen without_skips's stall analysis (crates/victory-shader/src/ir.rs) so empty-EXEC skip guards stay in place whenever any reachable path inside the skipped region can cycle without a proven exit.
  • Generalize none_left into empty_mask(inst, &facts, low) covering both EXEC and VCC, propagate empty results from all v_cmp* instructions when EXEC is empty, and resolve s_cbranch_vccz / s_cbranch_vccnz in Exit::Branch.
  • Replace the linear seen/chain trace with a cycle-detecting DFS (visiting/finished) returning true on cycle or budget exhaustion so loops spinning on inactive lanes cannot reach the loop watchdog after skip removal.
  • Add unit test an_empty_wave_keeps_its_skip_around_a_loop_that_can_reach_the_watchdog covering both deep = false and deep = true.

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy -> asset policy: 313 files ok
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib ir:: -> 13 passed; 0 failed (includes new test)
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader -> 344 passed; 3 failed; 6 ignored (all 3 failures are pre-existing host dxil.dll Pipeline State Validation checks verified failing identically on origin/main: emit::barycentric_tests::first_half_values_render_on_hardware_and_warp, emit::rect::tests::the_rectangle_stage_is_a_geometry_shader, emit::rect::tests::rectangles_are_drawn_whole)
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings -> clean
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics -- -D warnings -> clean
<!-- greyfinch-sync:Androtim/MiniVI:issue:5565304026 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/255). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-30T12:29:30Z. --- ## Summary - Strengthen `without_skips`'s stall analysis (`crates/victory-shader/src/ir.rs`) so empty-`EXEC` skip guards stay in place whenever any reachable path inside the skipped region can cycle without a proven exit. - Generalize `none_left` into `empty_mask(inst, &facts, low)` covering both `EXEC` and `VCC`, propagate empty results from all `v_cmp*` instructions when `EXEC` is empty, and resolve `s_cbranch_vccz` / `s_cbranch_vccnz` in `Exit::Branch`. - Replace the linear `seen`/`chain` trace with a cycle-detecting DFS (`visiting`/`finished`) returning `true` on cycle or budget exhaustion so loops spinning on inactive lanes cannot reach the loop watchdog after skip removal. - Add unit test `an_empty_wave_keeps_its_skip_around_a_loop_that_can_reach_the_watchdog` covering both `deep = false` and `deep = true`. ## Verification - `cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy` -> `asset policy: 313 files ok` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib ir::` -> `13 passed; 0 failed` (includes new test) - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader` -> `344 passed; 3 failed; 6 ignored` (all 3 failures are pre-existing host `dxil.dll` Pipeline State Validation checks verified failing identically on `origin/main`: `emit::barycentric_tests::first_half_values_render_on_hardware_and_warp`, `emit::rect::tests::the_rectangle_stage_is_a_geometry_shader`, `emit::rect::tests::rectangles_are_drawn_whole`) - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings` -> clean - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics -- -D warnings` -> clean
Androtim commented 2026-11-30 13:04:27 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-30T13:04:27Z.


Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

Logic and safety in crates/victory-shader/src/ir.rs look solid, and CI is passing. Because this changes shader IR skip-guard elimination (without_skips) for shaders containing loops, it warrants a local real-GPU smoke test before merging.

What Looks Good

  • Generalized mask tracking (empty_mask): Extending none_left to empty_mask(inst, &facts, low) cleanly covers both EXEC (126..=127) and VCC (106..=107), with dwords.peek().is_some() preventing vacuous matches.
  • Vector compare propagation (v_cmp* + s_cbranch_vccz/vccnz): Treating all v_cmp* results as empty when EXEC is empty is sound on GFX10/RDNA (inactive lanes write 0 bits to the destination lane mask), allowing while (any_lane) loops (s_cbranch_vccnz) to remain provably terminating while until (any_lane) loops (s_cbranch_vccz) keep their skip guard.
  • Cycle-detecting DFS (visiting / finished): Replacing the decided-only linear chain check with a 3-color iterative DFS correctly catches cycles through undecided scalar/vector branches (such as loops reading inactive lanes via v_readfirstlane_b32) without false positives on DAG diamonds, and safely defaults to keeping the skip guard (return true) on budget exhaustion (20_000 states).
  • Test coverage: an_empty_wave_keeps_its_skip_around_a_loop_that_can_reach_the_watchdog exercises all three cases (until_any_lane, from_inactive_lane, while_any_lane) for both deep = false and deep = true.

Suggested Local GPU Smoke Test

  • Run a gameplay capture/session on real GPU hardware (especially scenes with tiled water/volumetric or loop-heavy compute/pixel shaders) and verify no new shader compilation failures, hangs, or visual regressions (e.g., dark flickering tiles).
  • Optionally run with VICTORY_WAVE_WHY=1 to confirm newly retained WAVE64-SKIP guards match expected loop regions without unexpected perf regressions.

Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7279318045 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/255#issuecomment-7279318045). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-30T13:04:27Z. --- <!-- minivi-triage v1 head=86fdbf5bff65afe9ab92ba998111c8585d5a7a00 verdict=needs-gpu-test ci=passing at=2026-11-30T13:04:56Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic and safety in [crates/victory-shader/src/ir.rs](file:///C:/Users/Androtim/Documents/My%20Games/CopGame/minivi-triage/repo-main/crates/victory-shader/src/ir.rs) look solid, and CI is passing. Because this changes shader IR skip-guard elimination (`without_skips`) for shaders containing loops, it warrants a local real-GPU smoke test before merging. ### What Looks Good - **Generalized mask tracking (`empty_mask`)**: Extending `none_left` to `empty_mask(inst, &facts, low)` cleanly covers both `EXEC` (`126..=127`) and `VCC` (`106..=107`), with `dwords.peek().is_some()` preventing vacuous matches. - **Vector compare propagation (`v_cmp*` + `s_cbranch_vccz`/`vccnz`)**: Treating all `v_cmp*` results as empty when `EXEC` is empty is sound on GFX10/RDNA (inactive lanes write 0 bits to the destination lane mask), allowing `while (any_lane)` loops (`s_cbranch_vccnz`) to remain provably terminating while `until (any_lane)` loops (`s_cbranch_vccz`) keep their skip guard. - **Cycle-detecting DFS (`visiting` / `finished`)**: Replacing the decided-only linear chain check with a 3-color iterative DFS correctly catches cycles through undecided scalar/vector branches (such as loops reading inactive lanes via `v_readfirstlane_b32`) without false positives on DAG diamonds, and safely defaults to keeping the skip guard (`return true`) on budget exhaustion (`20_000` states). - **Test coverage**: `an_empty_wave_keeps_its_skip_around_a_loop_that_can_reach_the_watchdog` exercises all three cases (`until_any_lane`, `from_inactive_lane`, `while_any_lane`) for both `deep = false` and `deep = true`. ### Suggested Local GPU Smoke Test - Run a gameplay capture/session on real GPU hardware (especially scenes with tiled water/volumetric or loop-heavy compute/pixel shaders) and verify no new shader compilation failures, hangs, or visual regressions (e.g., dark flickering tiles). - Optionally run with `VICTORY_WAVE_WHY=1` to confirm newly retained `WAVE64-SKIP` guards match expected loop regions without unexpected perf regressions. --- _Generated with Antigravity CLI (`agy`)._
Androtim commented 2026-11-30 15:25:19 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-30T15:25:19Z.


Hardware-verified on RTX 4060 Ti 8 GB (Series X 1440p -PlayParity, warm shader cache, stacked Wave 9: #237, #240, #241, #247, #250, #255 on origin/main cb2e024):

  • Unit/GPU Tests: victory (37+2) + victory-hle (223) + victory-gpu (625 passed, 0 failed, 39 ignored) — 0 regressions
  • Open-World Verify (verify-wave9-warm): 4.9 fps (11463 draws, GPU=0.3 ms), VRAM 7159/6873 MB (-136 MB vs Wave 8), final_waiting=15641 (-8834 vs Wave 8), 0 crashes/DRED, 0 failed bakes
  • Visuals: clean textured house, stairs, grass, and Jason (luma=84.84, near_black=0.0%, magenta=0.0%)

Merging onto main.

<!-- greyfinch-sync:Androtim/MiniVI:comment:7282968486 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/255#issuecomment-7282968486). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-30T15:25:19Z. --- Hardware-verified on RTX 4060 Ti 8 GB (Series X 1440p `-PlayParity`, warm shader cache, stacked Wave 9: `#237, #240, #241, #247, #250, #255` on `origin/main` `cb2e024`): - **Unit/GPU Tests:** `victory` (`37+2`) + `victory-hle` (`223`) + `victory-gpu` (`625` passed, `0` failed, `39` ignored) — 0 regressions - **Open-World Verify (`verify-wave9-warm`):** `4.9 fps` (`11463` draws, `GPU=0.3 ms`), `VRAM 7159/6873 MB` (`-136 MB` vs Wave 8), `final_waiting=15641` (`-8834` vs Wave 8), `0` crashes/DRED, `0` failed bakes - **Visuals:** clean textured house, stairs, grass, and Jason (`luma=84.84`, `near_black=0.0%`, `magenta=0.0%`) Merging onto `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
Androtim/MiniVI!255
No description provided.