feat(shader/lower): honor constant-trip loop bounds past per-stage caps #266

Closed
github-bot wants to merge 2 commits from gh-pr/266/head into gh-pr/266/base
Owner

@⁠Androtim on GitHub · 2026-11-30 22:13 UTC · original
Androtim:feat/iter259-shader-constant-trip-loop-cap → main · +400 −6 · 3 files · 2 commits · closed without merging

Summary

  • Add static constant-trip loop detection in crates/victory-shader/src/emit/lower/trips.rs (supporting up/down counting, swapped and signed compares, s_cmp_*/s_cmpk_*, s_add/s_sub/s_addk_i32, s_mov_b32/s_movk_i32 up to TRIP_CEILING = 65,536 iterations).
  • Exempt single-latch statically bounded loops in crates/victory-shader/src/emit/lower.rs (via find_trips and loop_cap) from the per-stage loop iteration cap so fixed 256/512-sample pixel shaders (such as BRDF integration LUTs) complete all iterations instead of truncating at 128, while keeping the stage cap intact for data-driven or huge loops.
  • Add unit tests in crates/victory-shader/src/emit/lower_tests.rs covering 512-iteration constant loops, countdown/swapped/signed loops, dynamic bounds, overwritten counters, and bounds above TRIP_CEILING.

Verification

  • xtask policy: passed (316 files ok)
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader lower -- --test-threads=1: passed (23 passed, 0 failed, 1 ignored)
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings: passed (0 warnings)
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --features diagnostics --all-targets -- -D warnings: passed (0 warnings)
**@⁠Androtim** on GitHub · 2026-11-30 22:13 UTC · [original](https://github.com/Androtim/MiniVI/pull/266) `Androtim:feat/iter259-shader-constant-trip-loop-cap` → `main` · +400 −6 · 3 files · 2 commits · closed without merging ### Summary - Add static constant-trip loop detection in `crates/victory-shader/src/emit/lower/trips.rs` (supporting up/down counting, swapped and signed compares, `s_cmp_*`/`s_cmpk_*`, `s_add`/`s_sub`/`s_addk_i32`, `s_mov_b32`/`s_movk_i32` up to `TRIP_CEILING` = 65,536 iterations). - Exempt single-latch statically bounded loops in `crates/victory-shader/src/emit/lower.rs` (via `find_trips` and `loop_cap`) from the per-stage loop iteration cap so fixed 256/512-sample pixel shaders (such as BRDF integration LUTs) complete all iterations instead of truncating at 128, while keeping the stage cap intact for data-driven or huge loops. - Add unit tests in `crates/victory-shader/src/emit/lower_tests.rs` covering 512-iteration constant loops, countdown/swapped/signed loops, dynamic bounds, overwritten counters, and bounds above `TRIP_CEILING`. ### Verification - `xtask policy`: passed (`316 files ok`) - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader lower -- --test-threads=1`: passed (23 passed, 0 failed, 1 ignored) - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings`: passed (0 warnings) - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --features diagnostics --all-targets -- -D warnings`: passed (0 warnings)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:24:15 +00:00
github-bot closed this pull request 2026-12-01 20:24:15 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-30 23:03 UTC · original · edited 2026-12-01 06:04 UTC

Automated triage for the maintainers (not an approval).

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

Review Summary

Logic and unit-test coverage look solid, and CI is passing. Because this changes DXIL loop-cap lowering in victory-shader (where higher caps previously correlated with GPU TDRs in opening-cutscene draws), it warrants a local real-GPU smoke test before merging.

What was verified

  • crates/victory-shader/src/emit/lower.rs:
    • Lower::find_trips runs after counters and RPO tables are populated and only inspects single-latch loops (if let [latch] = back[..]).
    • Lower::loop_cap raises the default per-stage cap (128 pixel, 256 vertex/mesh, 4096 compute) to own.max(stage_cap) for statically bounded loops while preserving explicit VICTORY_SHADER_LOOP_LIMIT overrides (named => named).
    • Off-by-one check: for a loop executing n iterations, the back edge is taken n - 1 times, so count_iteration's next reaches at most n - 1 < n (pred::IULT / pred::IUGE), allowing all n iterations to complete cleanly.
  • crates/victory-shader/src/emit/lower/trips.rs:
    • constant_trip strictly requires a scalar s_cbranch_scc0/s_cbranch_scc1 latch, a single SGPR phi (c < VCC) defined at header h, matching constant start values across all reachable entry edges, and a pure constant-offset add/sub chain (s_add_*, s_sub_*, s_addk_i32) back to that phi without crossing inner phis.
    • Handles s_cmpk_* (sign-extended _i32 vs zero-extended _u32), s_cmp_* (including swapped operands via swapped), inline integer constants (128..=208), and wrapping 32-bit simulation bounded by TRIP_CEILING (65_536).
  • crates/victory-shader/src/emit/lower_tests.rs:
    • Covers 512-iteration constant loops, dynamic user-data bounds, bounds above TRIP_CEILING, countdown loops, swapped compares, signed vs unsigned compares, and in-body counter resets.

Minor non-blocking note

  • s_addk_i32 support in trips::offset is not directly exercised by the new unit tests (only s_add_i32/s_sub_i32 are), though the implementation is straightforward.

Next step

Run a local real-GPU smoke test (especially fixed-sample pixel shaders such as BRDF LUTs and the opening cutscene draws) to confirm no TDR regressions before merging.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-30 23:03 UTC · [original](https://github.com/Androtim/MiniVI/pull/266#issuecomment-7294665694) · edited 2026-12-01 06:04 UTC <!-- minivi-triage v1 head=bfa945bb5ae7cbdefdd086903347fac7072211c9 verdict=needs-gpu-test ci=passing at=2026-12-01T06:04:43Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic and unit-test coverage look solid, and CI is passing. Because this changes DXIL loop-cap lowering in `victory-shader` (where higher caps previously correlated with GPU TDRs in opening-cutscene draws), it warrants a local real-GPU smoke test before merging. #### What was verified - **`crates/victory-shader/src/emit/lower.rs`**: - `Lower::find_trips` runs after `counters` and RPO tables are populated and only inspects single-latch loops (`if let [latch] = back[..]`). - `Lower::loop_cap` raises the default per-stage cap (`128` pixel, `256` vertex/mesh, `4096` compute) to `own.max(stage_cap)` for statically bounded loops while preserving explicit `VICTORY_SHADER_LOOP_LIMIT` overrides (`named => named`). - Off-by-one check: for a loop executing `n` iterations, the back edge is taken `n - 1` times, so `count_iteration`'s `next` reaches at most `n - 1 < n` (`pred::IULT` / `pred::IUGE`), allowing all `n` iterations to complete cleanly. - **`crates/victory-shader/src/emit/lower/trips.rs`**: - `constant_trip` strictly requires a scalar `s_cbranch_scc0`/`s_cbranch_scc1` latch, a single SGPR phi (`c < VCC`) defined at header `h`, matching constant start values across all reachable entry edges, and a pure constant-offset add/sub chain (`s_add_*`, `s_sub_*`, `s_addk_i32`) back to that phi without crossing inner phis. - Handles `s_cmpk_*` (sign-extended `_i32` vs zero-extended `_u32`), `s_cmp_*` (including swapped operands via `swapped`), inline integer constants (`128..=208`), and wrapping 32-bit simulation bounded by `TRIP_CEILING` (`65_536`). - **`crates/victory-shader/src/emit/lower_tests.rs`**: - Covers 512-iteration constant loops, dynamic user-data bounds, bounds above `TRIP_CEILING`, countdown loops, swapped compares, signed vs unsigned compares, and in-body counter resets. #### Minor non-blocking note - `s_addk_i32` support in `trips::offset` is not directly exercised by the new unit tests (only `s_add_i32`/`s_sub_i32` are), though the implementation is straightforward. #### Next step Run a local real-GPU smoke test (especially fixed-sample pixel shaders such as BRDF LUTs and the opening cutscene draws) to confirm no TDR regressions before merging. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-12-01 05:01 UTC · original

Merged origin/main (d79b9432) into feat/iter259-shader-constant-trip-loop-cap to bring host.rs within xtask policy and re-trigger CI past the unrelated descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes runner failure (zero code changes needed to trips.rs / lower.rs).

Local Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu xtask policy (316 files ok)
  • cargo +1.98.1-x86_64-pc-windows-gnu test --locked -p victory-shader --lib constant_trip (2 passed; 0 failed, both default parallel and --test-threads=1)
  • Dual workspace cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings (default and --features diagnostics clean)
**@⁠Androtim** on GitHub · 2026-12-01 05:01 UTC · [original](https://github.com/Androtim/MiniVI/pull/266#issuecomment-7301342285) Merged `origin/main` (`d79b9432`) into `feat/iter259-shader-constant-trip-loop-cap` to bring `host.rs` within `xtask policy` and re-trigger CI past the unrelated `descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes` runner failure (zero code changes needed to `trips.rs` / `lower.rs`). ### Local Verification - `cargo +1.98.1-x86_64-pc-windows-gnu xtask policy` (`316 files ok`) - `cargo +1.98.1-x86_64-pc-windows-gnu test --locked -p victory-shader --lib constant_trip` (`2 passed; 0 failed`, both default parallel and `--test-threads=1`) - Dual workspace `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings` (default and `--features diagnostics` clean)
Author
Owner

@⁠Androtim on GitHub · 2026-12-01 05:20 UTC · original

Maintainer triage (strict merge gate): keeping triage: needs gpu test.

CI is passing on bfa945bb. Because this changes shader loop-bound lowering (victory-shader), please include a paired plain --release A/B against updated main (confirming median fps, preparing ms, copyback ms, final_waiting, untranslated shaders, and 0 crashes) plus a --features diagnostics visual PNG check before merge.

**@⁠Androtim** on GitHub · 2026-12-01 05:20 UTC · [original](https://github.com/Androtim/MiniVI/pull/266#issuecomment-7301660701) Maintainer triage (strict merge gate): keeping `triage: needs gpu test`. CI is passing on `bfa945bb`. Because this changes shader loop-bound lowering (`victory-shader`), please include a paired plain `--release` A/B against updated `main` (confirming `median fps`, `preparing ms`, `copyback ms`, `final_waiting`, `untranslated` shaders, and `0` crashes) plus a `--features diagnostics` visual PNG check before merge.
Author
Owner

@⁠Androtim on GitHub · 2026-12-01 16:14 UTC · original

Closing to keep the queue focused on [USER PRIORITY] core engine throughput, copyback, dynamic 4K VRAM reclaim, and stability (#276). No paired plain --release A/B or confirmed visual defect currently depends on this; we can revisit cleanly if a specific constant-trip shader truncation issue is observed.

**@⁠Androtim** on GitHub · 2026-12-01 16:14 UTC · [original](https://github.com/Androtim/MiniVI/pull/266#issuecomment-7317267071) Closing to keep the queue focused on [USER PRIORITY] core engine throughput, copyback, dynamic 4K VRAM reclaim, and stability (#276). No paired plain --release A/B or confirmed visual defect currently depends on this; we can revisit cleanly if a specific constant-trip shader truncation issue is observed.

Pull request closed

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/Androtim--MiniVI!266
No description provided.