Shaders: translated loops are left after 2^14 iterations (was 2^20) #1817

Open
Exopus-0x65f7ad0 wants to merge 2 commits from upstream-pr/1819 into main
Exopus-0x65f7ad0 commented 2026-11-24 22:59:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Exopus-0x65f7ad0 on 2026-11-24T22:59:18Z.


From a tester working with Claude (AI-assisted); measured on my own machine.

Why

A translated loop is cut after LOOP_LIMIT iterations per lane and per entry. At 2^20 that is not short enough to protect the host.

In the opening cutscene, a GPU-driven compute pass walks a parent table, union-find style (v = parent[v] until it stops changing). On my run, the dispatch that fills that table was still dropped (its shader did not translate yet), so the walk followed garbage.

At 2^20 iterations per lane, the submission ran past the NVIDIA driver's timeout. The driver's reset then failed (nvlddmkm event 153, "UCodeReset TDR occurred"), and the whole desktop froze until a hard reboot.

The doc comment on loop_limit() already says 2^20 can take seconds on a full-screen pass. This is the case where it takes the PC down.

What

  • LOOP_LIMIT goes from 1 << 20 to 1 << 14.
  • The doc comments and the README line for VICTORY_SHADER_LOOP_LIMIT are updated. The switch still overrides the limit.

The shader cache already keys on the limit, so nothing else changes.

At 2^14, a runaway loop costs milliseconds per wave instead of seconds. That stays well under the default 2 s TDR. A genuine loop of more than 16,384 iterations per lane would now be cut short (the same shortcut: as before, at a lower bound).

Related, not duplicated: #452 caps spin-wait loops at 4096, and #1263 makes the switch work in every build. Neither changes the default.

Verification

Windows 11, RTX 5060 Ti 8 GB (driver 621.14), Rust 1.98.1.

Check Result
cargo test -p victory-shader --lib loop 11 passed
cargo test -p victory-shader --lib 206 passed, 3 failed
cargo clippy -p victory-shader --lib clean
  • The 3 failures (stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware) fail the same way on main without this change, on this card.
  • translated_shaders_draw_as_pc_ones (which has the runaway-loop case) skips here, because the DXC compilers are not installed. It is not verified on this machine.
  • In game, with the same change on top of the NVIDIA stack, the run that had frozen the PC goes through that dispatch and on into the cutscene.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5481757485 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819). Originally posted by [Exopus-0x65f7ad0](https://github.com/Exopus-0x65f7ad0) on 2026-11-24T22:59:18Z. --- *From a tester working with Claude (AI-assisted); measured on my own machine.* ## Why A translated loop is cut after `LOOP_LIMIT` iterations per lane and per entry. At 2^20 that is not short enough to protect the host. In the opening cutscene, a GPU-driven compute pass walks a parent table, union-find style (`v = parent[v]` until it stops changing). On my run, the dispatch that fills that table was still dropped (its shader did not translate yet), so the walk followed garbage. At 2^20 iterations per lane, the submission ran past the NVIDIA driver's timeout. The driver's reset then **failed** (`nvlddmkm` event 153, "UCodeReset TDR occurred"), and the whole desktop froze until a hard reboot. The doc comment on `loop_limit()` already says 2^20 can take seconds on a full-screen pass. This is the case where it takes the PC down. ## What - `LOOP_LIMIT` goes from `1 << 20` to `1 << 14`. - The doc comments and the README line for `VICTORY_SHADER_LOOP_LIMIT` are updated. The switch still overrides the limit. The shader cache already keys on the limit, so nothing else changes. At 2^14, a runaway loop costs milliseconds per wave instead of seconds. That stays well under the default 2 s TDR. A genuine loop of more than 16,384 iterations per lane would now be cut short (the same `shortcut:` as before, at a lower bound). Related, not duplicated: #452 caps spin-wait loops at 4096, and #1263 makes the switch work in every build. Neither changes the default. ## Verification Windows 11, RTX 5060 Ti 8 GB (driver 621.14), Rust 1.98.1. | Check | Result | |---|---| | `cargo test -p victory-shader --lib loop` | 11 passed | | `cargo test -p victory-shader --lib` | 206 passed, 3 failed | | `cargo clippy -p victory-shader --lib` | clean | - **The 3 failures** (`stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `synthetic_tests::gathers_at_a_level_match_the_hardware`) fail the same way on `main` without this change, on this card. - **`translated_shaders_draw_as_pc_ones`** (which has the runaway-loop case) skips here, because the DXC compilers are not installed. It is not verified on this machine. - **In game**, with the same change on top of the NVIDIA stack, the run that had frozen the PC goes through that dispatch and on into the cutscene. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-24 23:04:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T23:04:24Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae), cargo test -p victory-shader --locked → 118 passed, 0 failed. GPU execution tests (valu_tests/host) are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.

Translated loops left after 2^14 iterations (was 2^20): this re-lands the spin/loop guard I approved in #452 (which the maintainer merged) with the TDR-justified bound. Small diff, consistent with the merged change.

<!-- greyfinch-sync:Marvisak/VIctory:review:6048811157 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#pullrequestreview-6048811157). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T23:04:24Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae), cargo test -p victory-shader --locked → 118 passed, 0 failed. GPU execution tests (valu_tests/host) are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests. Translated loops left after 2^14 iterations (was 2^20): this re-lands the spin/loop guard I approved in #452 (which the maintainer merged) with the TDR-justified bound. Small diff, consistent with the merged change.
Melow-code commented 2026-11-24 23:04:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-24T23:04:39Z.

Review: APPROVED


2^14 is a reasonable default. The union-find hang at 2^20 is a real failure mode — unbounded parent chains in an unfilled table will walk until the limit, and 2^20 iterations on a compute dispatch holds the GPU for seconds.

The env override (VICTORY_SHADER_LOOP_LIMIT) and the cache key inclusion mean users who need 2^20 for a specific title can still get it. The only risk is a title program that legitimately iterates more than 16384 times in a single loop — unlikely for a game shader, but worth noting in the README (which the PR already updates).

<!-- greyfinch-sync:Marvisak/VIctory:review:6048813588 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#pullrequestreview-6048813588). Originally posted by [Melow-code](https://github.com/Melow-code) on 2026-11-24T23:04:39Z. **Review:** APPROVED --- 2^14 is a reasonable default. The union-find hang at 2^20 is a real failure mode — unbounded parent chains in an unfilled table will walk until the limit, and 2^20 iterations on a compute dispatch holds the GPU for seconds. The env override (`VICTORY_SHADER_LOOP_LIMIT`) and the cache key inclusion mean users who need 2^20 for a specific title can still get it. The only risk is a title program that legitimately iterates more than 16384 times in a single loop — unlikely for a game shader, but worth noting in the README (which the PR already updates).
upipibi commented 2026-11-25 00:06:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T23:06:45Z.


For the reviewers, how the other two console-port emulators bound loops (code reading, not a test of this PR):

  • XCL keeps one budget per invocation, shared by every loop in the program: static uint xcl_budget = 1u << 16, decremented at the top of every loop (LOOP_GUARD in gpu/recomp/mod.rs, settable with XCL_LOOP_BUDGET).
  • AnyPS5's guard (APS5_LOOP_GUARD=<exits>) also counts per invocation. When it runs out, it records a LoopLimit fault with the shader hash and the PC of the first loop that ran out, so a cut-short loop shows up in the log instead of only as wrong output.

The difference matters for nested loops. With a limit per loop and per entry, an inner loop gets its full 2^14 on every pass of a runaway outer loop, so the bound for a two-deep nest is 2^28 per lane. A per-invocation budget keeps it at the one figure whatever the nesting. A one-time log line when a loop is cut would also make the "genuine loop of more than 16,384 iterations" case visible.

AI-assisted (Claude Code). No game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7147026730 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#issuecomment-7147026730). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T23:06:45Z. --- For the reviewers, how the other two console-port emulators bound loops (code reading, not a test of this PR): - XCL keeps one budget per invocation, shared by every loop in the program: `static uint xcl_budget = 1u << 16`, decremented at the top of every loop (`LOOP_GUARD` in `gpu/recomp/mod.rs`, settable with `XCL_LOOP_BUDGET`). - AnyPS5's guard (`APS5_LOOP_GUARD=<exits>`) also counts per invocation. When it runs out, it records a `LoopLimit` fault with the shader hash and the PC of the first loop that ran out, so a cut-short loop shows up in the log instead of only as wrong output. The difference matters for nested loops. With a limit per loop and per entry, an inner loop gets its full 2^14 on every pass of a runaway outer loop, so the bound for a two-deep nest is 2^28 per lane. A per-invocation budget keeps it at the one figure whatever the nesting. A one-time log line when a loop is cut would also make the "genuine loop of more than 16,384 iterations" case visible. AI-assisted (Claude Code). No game files.
upipibi commented 2026-11-25 00:06:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T23:11:07Z.


NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, d7a5c3c (on main 70564ae). cargo test -p victory-shader --locked: 206 passed, 3 failed, 2 ignored. The 3 are #1744's NVIDIA heap-cap failures on main, so no test needed more than 2^14 iterations.

AI-assisted (Claude Code). Synthetic tests only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7147111092 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#issuecomment-7147111092). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T23:11:07Z. --- NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, `d7a5c3c` (on `main` `70564ae`). `cargo test -p victory-shader --locked`: 206 passed, 3 failed, 2 ignored. The 3 are #1744's NVIDIA heap-cap failures on `main`, so no test needed more than 2^14 iterations. AI-assisted (Claude Code). Synthetic tests only.
Exopus-0x65f7ad0 commented 2026-11-25 02:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Exopus-0x65f7ad0 on 2026-11-25T01:51:38Z.


Thanks for testing, and for the review.

@upipibi, good point on nests. With a limit per loop and per entry, an inner loop gets the full budget again on every pass of the outer one. That makes 2^28 per lane for a two-deep nest, which is again in seconds-per-dispatch territory.

This PR only lowers the existing per-loop limit, so it stays a one-line, low-risk change. A per-invocation budget like XCL's LOOP_GUARD would be the stronger bound. I'll look at that as a follow-up, and at a fault note in the log, like AnyPS5's LoopLimit, so a loop that was cut short shows up.

The case that froze the PC here was a single loop: a union-find walk over a table nothing had filled. 2^14 is enough to stop that one.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150042146 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#issuecomment-7150042146). Originally posted by [Exopus-0x65f7ad0](https://github.com/Exopus-0x65f7ad0) on 2026-11-25T01:51:38Z. --- Thanks for testing, and for the review. @upipibi, good point on nests. With a limit per loop and per entry, an inner loop gets the full budget again on every pass of the outer one. That makes 2^28 per lane for a two-deep nest, which is again in seconds-per-dispatch territory. This PR only lowers the existing per-loop limit, so it stays a one-line, low-risk change. A per-invocation budget like XCL's `LOOP_GUARD` would be the stronger bound. I'll look at that as a follow-up, and at a fault note in the log, like AnyPS5's `LoopLimit`, so a loop that was cut short shows up. The case that froze the PC here was a single loop: a union-find walk over a table nothing had filled. 2^14 is enough to stop that one. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Exopus-0x65f7ad0 commented 2026-11-25 07:03:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Exopus-0x65f7ad0 on 2026-11-25T06:11:08Z.


Follow-up. Thanks @catminou4 and @Melow-code for the reviews, and @upipibi for the RTX 3070 run.

  • The 2^14 bound has held through about 35 more in-game runs here (RTX 5060 Ti 8 GB), cutscene and first gameplay scene. There were no freezes and no driver resets.
  • That includes the ray-tracing structure builder, which now starts on NVIDIA. It brings in many more translated loops over data other passes write.
  • The per-invocation budget (XCL's LOOP_GUARD, AnyPS5's LoopLimit note) is still the right next step. I'd keep it as a separate PR so this one stays a one-line change. If someone wants to take it first, go ahead.

Broader progress, and where help is wanted (ray tracing memory, frame rate): #1820.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154529331 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#issuecomment-7154529331). Originally posted by [Exopus-0x65f7ad0](https://github.com/Exopus-0x65f7ad0) on 2026-11-25T06:11:08Z. --- **Follow-up.** Thanks @catminou4 and @Melow-code for the reviews, and @upipibi for the RTX 3070 run. - The 2^14 bound has held through about 35 more in-game runs here (RTX 5060 Ti 8 GB), cutscene and first gameplay scene. There were no freezes and no driver resets. - That includes the ray-tracing structure builder, which now starts on NVIDIA. It brings in many more translated loops over data other passes write. - The per-invocation budget (XCL's `LOOP_GUARD`, AnyPS5's `LoopLimit` note) is still the right next step. I'd keep it as a separate PR so this one stays a one-line change. If someone wants to take it first, go ahead. Broader progress, and where help is wanted (ray tracing memory, frame rate): #1820. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Marvisak commented 2026-11-25 07:03:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T06:29:27Z.


Automated triage for the maintainers.

Merge candidate; the default is the maintainer's call. LOOP_LIMIT in crates/victory-shader/src/emit/lower.rs goes from 2^20 to 2^14, with DEFAULT_LOOP_LIMIT's doc and the README line following. VICTORY_SHADER_LOOP_LIMIT still overrides it, and the shader cache already keys on the limit.

What the last triage asked for is now there:

  • Evidence that no legitimate loop reaches 2^14: with #2733's counter (VICTORY_LOOP_CUTS=1) on an RTX 5060 Ti, 0 lanes were cut at 16,383 over boot, menus, loading, the opening cutscene and the first gameplay scene. A control at 64 cut 202,838 lanes, so the counter counts. Together with taovuokko's 8.7 s dispatch at 2^20 on an RTX 2080 Ti (0.34 s at 2^14), that covers both halves. It is one machine and one stretch of the title.
  • The doc comment now says that a lane cut on a conditional back edge leaves by the loop's own exit, and only an unconditional back edge leaves as killed. The history comment is down to one line on the bound.

On your reply: confirmed in the diff. CI: check passing on this head.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154844036 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#issuecomment-7154844036). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T06:29:27Z. --- <!-- victory-triage v1 head=0146a5119febc0a3fe22f209319a82ef00b4d4f5 verdict=merge-candidate at=2026-11-25T22:28:30Z --> Automated triage for the maintainers. **Merge candidate; the default is the maintainer's call.** `LOOP_LIMIT` in `crates/victory-shader/src/emit/lower.rs` goes from 2^20 to 2^14, with `DEFAULT_LOOP_LIMIT`'s doc and the README line following. `VICTORY_SHADER_LOOP_LIMIT` still overrides it, and the shader cache already keys on the limit. What the last triage asked for is now there: - **Evidence that no legitimate loop reaches 2^14:** with #2733's counter (`VICTORY_LOOP_CUTS=1`) on an RTX 5060 Ti, 0 lanes were cut at 16,383 over boot, menus, loading, the opening cutscene and the first gameplay scene. A control at 64 cut 202,838 lanes, so the counter counts. Together with taovuokko's 8.7 s dispatch at 2^20 on an RTX 2080 Ti (0.34 s at 2^14), that covers both halves. It is one machine and one stretch of the title. - **The doc comment** now says that a lane cut on a conditional back edge leaves by the loop's own exit, and only an unconditional back edge leaves as killed. The history comment is down to one line on the bound. On your reply: confirmed in the diff. CI: `check` passing on this head. --- _Generated by [Claude Code](https://claude.ai/code)_
taovuokko commented 2026-11-25 09:06:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by taovuokko on 2026-11-25T08:29:45Z.


Measured data point for the default: one compute program, same build and machine, loop limit 2^20 / 2^14 / 4096 / 256

Setup: RTX 2080 Ti, i9-9900KS, 32 GB, Windows 11, driver 32.0.16.1088 (Turing, 32-lane waves). main 940d32f + #1763, diagnostics build, VICTORY_GPU_TIMING=1. The title's view heap budget is lowered locally so the heap fits the 1,000,000 cap (see #1760) and the title's own hang-watchdog crash is disabled, so runs reach the world and last 2-5 minutes. TdrDelay is 30 s on this machine (not the default 2 s). No game data attached.

The compute program 00167d58cc5a78d7 (dispatch 16x16x16, 4x4x4 threads, i.e. 262,144 lanes) is by far the slowest command in the world on this card. Only the loop limit changes between rows:

VICTORY_SHADER_LOOP_LIMIT slowest dispatch of that program GPU time per world frame slowest submission device removed
default (2^20) 8.7-8.9 s (13.1-13.3 s in two runs) 5.3-9 s 13.3 s; 33.7 and 35.3 s in the two runs that lost the device 2 of 5 runs at the title's default heap budget (none in about 10 runs at the lowered budget, where the slowest submission stayed at 13 s)
16384 (2^14) 0.34 s (1 run) 0.58 s 0.84 s none in 1 run at the lowered budget
4096 0.15-0.24 s (4 runs) 0.33-0.51 s 0.86-0.92 s none in 4 runs at the lowered budget; 1 of 1 at the default budget (see caveats)
256 not in the slow list (slowest command of any kind 0.29 s) 0.40 s 0.89 s none (1 run)

For comparison, dropping the program with VICTORY_SKIP_PIPELINES (2 runs) gives 0.50-0.65 s GPU per frame. So at 2^20 this one program is about 90 % of the GPU time of a world frame, and 4096 removes almost all of it without dropping it.

Why a default of 2^20 is fatal on a default TDR: one dispatch is already 8.7 s, above the 2 s limit. On this machine (30 s TdrDelay) the removals came from a single submission holding about four of these dispatches (33.7 s and 35.3 s, about 4 x 8.8 s; 0x887A0005). Counts per limit are small (one to ten runs each), see below.

What I read from the translated program (counts only): 6 back edges; an outer loop of 3 iterations and two self-looping inner loops reading 60-byte records, whose exit is counter >= a value read from a structured buffer (float bits) or the 2^20 cap. That matches the reading in #1581 (a bound that comes from a buffer the host has not filled, so lanes run to the cap). I did not read the buffer's value; I cannot say who is meant to fill it.

Caveats, so nobody over-reads this:

  • Correctness is not measured. With 4096 (and 256) the final world frame is black, the same as with 2^20 (black or white depending on the run), so I cannot say whether cutting a genuine long loop changes the picture. The question in the triage comment (does any legitimate loop reach the limit?) is not answered by this: I have no counter for how often the limit cuts a lane, only the timings above, and I cannot see the picture yet. A one-line log note when a lane is cut (as proposed in the thread, AnyPS5's LoopLimit-style) would let testers answer it.
  • The limit applies to every shader, so part of the gain could come from other programs. The 16x16x16 dispatch is the one that disappears from the slow list, and the skip runs agree.
  • 2^14 was measured in one run only (0.34 s for the dispatch, vs 0.24 s at 4096 and 8.7 s at 2^20), so the cost grows much more slowly than the limit between 4096 and 2^14: most lanes seem to leave early and only a few run to the cap. This is one run and a guess about why.
  • Frame rate after the fix is still 0.5-0.65 fps, now CPU-bound (prepare about 1.1 s, copies about 0.4 s per frame), so this is not "playable", only "no longer a GPU hang from this program".
  • Not enough to claim a cause for the remaining device removals at the default heap budget: with the limit at 4096 and the heap budget at the title's default, one run still lost the device after a 45 s submission of 24 compute lists (commands not attributable because the device was removed). So the loop limit is one stall source, not the only one.

Suggestion, if useful: a documented lower default (2^14 as in this PR, or 4096 as in #452's spin-wait limit) is supported by this program; I would keep VICTORY_SHADER_LOOP_LIMIT readable in release builds (#1263) so users can raise it when a picture breaks.

Measured on my own machine; analysis AI-assisted (Claude Code). No game data, captures or addresses are attached.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7157094266 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#issuecomment-7157094266). Originally posted by [taovuokko](https://github.com/taovuokko) on 2026-11-25T08:29:45Z. --- **Measured data point for the default: one compute program, same build and machine, loop limit 2^20 / 2^14 / 4096 / 256** Setup: RTX 2080 Ti, i9-9900KS, 32 GB, Windows 11, driver 32.0.16.1088 (Turing, 32-lane waves). `main` `940d32f` + #1763, diagnostics build, `VICTORY_GPU_TIMING=1`. The title's view heap budget is lowered locally so the heap fits the 1,000,000 cap (see #1760) and the title's own hang-watchdog crash is disabled, so runs reach the world and last 2-5 minutes. TdrDelay is 30 s on this machine (not the default 2 s). No game data attached. The compute program `00167d58cc5a78d7` (`dispatch 16x16x16`, 4x4x4 threads, i.e. 262,144 lanes) is by far the slowest command in the world on this card. Only the loop limit changes between rows: | `VICTORY_SHADER_LOOP_LIMIT` | slowest dispatch of that program | GPU time per world frame | slowest submission | device removed | |---|---|---|---|---| | default (2^20) | 8.7-8.9 s (13.1-13.3 s in two runs) | 5.3-9 s | 13.3 s; 33.7 and 35.3 s in the two runs that lost the device | 2 of 5 runs at the title's default heap budget (none in about 10 runs at the lowered budget, where the slowest submission stayed at 13 s) | | 16384 (2^14) | 0.34 s (1 run) | 0.58 s | 0.84 s | none in 1 run at the lowered budget | | 4096 | 0.15-0.24 s (4 runs) | 0.33-0.51 s | 0.86-0.92 s | none in 4 runs at the lowered budget; 1 of 1 at the default budget (see caveats) | | 256 | not in the slow list (slowest command of any kind 0.29 s) | 0.40 s | 0.89 s | none (1 run) | For comparison, dropping the program with `VICTORY_SKIP_PIPELINES` (2 runs) gives 0.50-0.65 s GPU per frame. So at 2^20 this one program is about 90 % of the GPU time of a world frame, and 4096 removes almost all of it without dropping it. Why a default of 2^20 is fatal on a default TDR: one dispatch is already 8.7 s, above the 2 s limit. On this machine (30 s TdrDelay) the removals came from a single submission holding about four of these dispatches (33.7 s and 35.3 s, about 4 x 8.8 s; `0x887A0005`). Counts per limit are small (one to ten runs each), see below. What I read from the translated program (counts only): 6 back edges; an outer loop of 3 iterations and two self-looping inner loops reading 60-byte records, whose exit is `counter >= a value read from a structured buffer (float bits)` or the 2^20 cap. That matches the reading in #1581 (a bound that comes from a buffer the host has not filled, so lanes run to the cap). I did not read the buffer's value; I cannot say who is meant to fill it. Caveats, so nobody over-reads this: - **Correctness is not measured.** With 4096 (and 256) the final world frame is black, the same as with 2^20 (black or white depending on the run), so I cannot say whether cutting a genuine long loop changes the picture. The question in the triage comment (does any legitimate loop reach the limit?) is not answered by this: I have no counter for how often the limit cuts a lane, only the timings above, and I cannot see the picture yet. A one-line log note when a lane is cut (as proposed in the thread, AnyPS5's LoopLimit-style) would let testers answer it. - The limit applies to every shader, so part of the gain could come from other programs. The 16x16x16 dispatch is the one that disappears from the slow list, and the skip runs agree. - 2^14 was measured in one run only (0.34 s for the dispatch, vs 0.24 s at 4096 and 8.7 s at 2^20), so the cost grows much more slowly than the limit between 4096 and 2^14: most lanes seem to leave early and only a few run to the cap. This is one run and a guess about why. - Frame rate after the fix is still 0.5-0.65 fps, now CPU-bound (prepare about 1.1 s, copies about 0.4 s per frame), so this is not "playable", only "no longer a GPU hang from this program". - Not enough to claim a cause for the remaining device removals at the default heap budget: with the limit at 4096 and the heap budget at the title's default, one run still lost the device after a 45 s submission of 24 compute lists (commands not attributable because the device was removed). So the loop limit is one stall source, not the only one. Suggestion, if useful: a documented lower default (2^14 as in this PR, or 4096 as in #452's spin-wait limit) is supported by this program; I would keep `VICTORY_SHADER_LOOP_LIMIT` readable in release builds (#1263) so users can raise it when a picture breaks. Measured on my own machine; analysis AI-assisted (Claude Code). No game data, captures or addresses are attached.
Exopus-0x65f7ad0 commented 2026-11-25 18:02:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Exopus-0x65f7ad0 on 2026-11-25T17:23:15Z.


@taovuokko, thank you: that is the measurement this PR was missing. At the default 2 s TDR, a single 8.7 s dispatch at 2^20 decides the question of the default on its own.

On the triage's request (evidence that no legitimate loop reaches the new limit), here is what I have, and what I don't:

  • Same machine, same scenes (RTX 5060 Ti 8 GB), about 35 runs at 2^14. The opening cutscene and the first gameplay scene render lit and textured, with complete hair. Nothing in the picture changed when going from 2^20 to 2^14. But at 2^20 that scene was not reachable here (the freeze), so this is not a before/after on the same frames.
  • Limit 1024 vs 16384 (one run each, same scene): GPU work per frame did not change (about 270 ms). If a loop in that scene ran past 1024, cutting it there would have shown up as less work. That is indirect evidence that its loops end well under 2^14, but only for that scene.
  • What I can't give yet: a count of lanes actually cut. As taovuokko says, nothing reports it today.

So I'll add the counter rather than argue: a one-time log note when a translated loop leaves at the limit, with a running count in the frame report. That answers the question for any tester on any scene. I'll put it in a separate PR, so this one stays a one-line default change. If the maintainers would rather have both in one PR, say so and I'll stack it here.

On "a fix closer to the cause" (not running a dispatch whose producer was dropped): agreed that this is the better fix for the case that froze the PC. It doesn't replace a bound, though: taovuokko's program reads its loop bound from a buffer, and nothing says who failed to fill it. A low default keeps a bad bound from taking the desktop down while the real producer is found.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169428886 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#issuecomment-7169428886). Originally posted by [Exopus-0x65f7ad0](https://github.com/Exopus-0x65f7ad0) on 2026-11-25T17:23:15Z. --- @taovuokko, thank you: that is the measurement this PR was missing. At the default 2 s TDR, a single 8.7 s dispatch at 2^20 decides the question of the default on its own. On the triage's request (evidence that no legitimate loop reaches the new limit), here is what I have, and what I don't: - **Same machine, same scenes (RTX 5060 Ti 8 GB), about 35 runs at 2^14.** The opening cutscene and the first gameplay scene render lit and textured, with complete hair. Nothing in the picture changed when going from 2^20 to 2^14. But at 2^20 that scene was not reachable here (the freeze), so this is not a before/after on the same frames. - **Limit 1024 vs 16384 (one run each, same scene):** GPU work per frame did not change (about 270 ms). If a loop in that scene ran past 1024, cutting it there would have shown up as less work. That is indirect evidence that its loops end well under 2^14, but only for that scene. - **What I can't give yet:** a count of lanes actually cut. As taovuokko says, nothing reports it today. So I'll add the counter rather than argue: a one-time log note when a translated loop leaves at the limit, with a running count in the frame report. That answers the question for any tester on any scene. I'll put it in a separate PR, so this one stays a one-line default change. If the maintainers would rather have both in one PR, say so and I'll stack it here. On "a fix closer to the cause" (not running a dispatch whose producer was dropped): agreed that this is the better fix for the case that froze the PC. It doesn't replace a bound, though: taovuokko's program reads its loop bound from a buffer, and nothing says who failed to fill it. A low default keeps a bad bound from taking the desktop down while the real producer is found. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Exopus-0x65f7ad0 commented 2026-11-25 20:06:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Exopus-0x65f7ad0 on 2026-11-25T19:20:08Z.


The counter asked for in the triage is now a separate PR: #2733 (VICTORY_LOOP_CUTS=1, diagnostics builds: every lane that leaves a translated loop at the limit is counted, and the frame line reports it). One finding from writing its test: on a conditional back edge, a lane at the limit does not take the "killed" exit; it leaves by the loop's normal exit and runs on. In-game counts at 2^14 and 2^20 will follow on #2733.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172152853 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#issuecomment-7172152853). Originally posted by [Exopus-0x65f7ad0](https://github.com/Exopus-0x65f7ad0) on 2026-11-25T19:20:08Z. --- The counter asked for in the triage is now a separate PR: #2733 (`VICTORY_LOOP_CUTS=1`, diagnostics builds: every lane that leaves a translated loop at the limit is counted, and the frame line reports it). One finding from writing its test: on a conditional back edge, a lane at the limit does not take the "killed" exit; it leaves by the loop's normal exit and runs on. In-game counts at 2^14 and 2^20 will follow on #2733. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Exopus-0x65f7ad0 commented 2026-11-25 22:04:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Exopus-0x65f7ad0 on 2026-11-25T21:42:02Z.


The evidence asked for in the triage, from #2733's counter (VICTORY_LOOP_CUTS=1). RTX 5060 Ti 8 GB, Series S, every stage at 16383:

  • 0 lanes cut over boot, menus, loading, the whole opening cutscene (~155 s) and the first gameplay scene.
  • Control: at a limit of 64, 202,838 lanes were cut before the loading screen, so the counter does count.

The doc comment is fixed in 0146a51, as asked. It now says that a lane cut on a conditional back edge leaves by the loop's own exit, and that only an unconditional back edge leaves as killed. The four-line history is gone; the commit message keeps it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175425566 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#issuecomment-7175425566). Originally posted by [Exopus-0x65f7ad0](https://github.com/Exopus-0x65f7ad0) on 2026-11-25T21:42:02Z. --- The evidence asked for in the triage, from #2733's counter (`VICTORY_LOOP_CUTS=1`). RTX 5060 Ti 8 GB, Series S, every stage at 16383: - **0 lanes cut** over boot, menus, loading, the whole opening cutscene (~155 s) and the first gameplay scene. - **Control:** at a limit of 64, **202,838 lanes** were cut before the loading screen, so the counter does count. The doc comment is fixed in `0146a51`, as asked. It now says that a lane cut on a conditional back edge leaves by the loop's own exit, and that only an unconditional back edge leaves as killed. The four-line history is gone; the commit message keeps it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fuzeofficlal commented 2026-11-26 18:59:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T18:59:29Z.

Review: APPROVED


Verified 0146a5119febc0a3fe22f209319a82ef00b4d4f5 cleanly merged onto main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDK dxil.dll):

  • LOOP_LIMIT = 1 << 14 (crates/victory-shader/src/emit/lower.rs:358), DEFAULT_LOOP_LIMIT (emit/mod.rs:245), README.md:217, and the updated conditional/unconditional exit comment in 0146a51 are consistent, and no victory-shader test requires more than 2^14 iterations per loop entry.
  • emit/lower.rs size: 520,769 B (under 524,288 B); cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed (asset policy: 191 files ok).
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features): clean.
  • emit::tests::the_loop_limit_switch_parses_or_falls_back, emit::flow_tests::control_flow_runs_as_pc_compiles_it, emit::tests::constant_color_validates, and emit::lower::tests:: (33 passed, 0 failed) all pass on both RTX 5090 and WARP.

Tiny doc note: two comments in emit/synthetic_tests.rs:954, 1027 still mention 1 << 20 (tests themselves only exercise 0/1 iterations). Ready to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6079257004 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1819#pullrequestreview-6079257004). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T18:59:29Z. **Review:** APPROVED --- Verified `0146a5119febc0a3fe22f209319a82ef00b4d4f5` cleanly merged onto `main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDK `dxil.dll`): - `LOOP_LIMIT = 1 << 14` (`crates/victory-shader/src/emit/lower.rs:358`), `DEFAULT_LOOP_LIMIT` (`emit/mod.rs:245`), `README.md:217`, and the updated conditional/unconditional exit comment in `0146a51` are consistent, and no `victory-shader` test requires more than `2^14` iterations per loop entry. - `emit/lower.rs` size: **520,769 B** (under 524,288 B); `cargo test -p xtask --locked policy::tests::repository_passes_policy`: `1 passed` (`asset policy: 191 files ok`). - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`): clean. - `emit::tests::the_loop_limit_switch_parses_or_falls_back`, `emit::flow_tests::control_flow_runs_as_pc_compiles_it`, `emit::tests::constant_color_validates`, and `emit::lower::tests::` (`33 passed, 0 failed`) all pass on both RTX 5090 and WARP. Tiny doc note: two comments in `emit/synthetic_tests.rs:954, 1027` still mention `1 << 20` (tests themselves only exercise 0/1 iterations). Ready to merge.
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/1819:upstream-pr/1819'
git switch 'upstream-pr/1819'

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/1819'
git switch 'upstream-pr/1819'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1819'
git switch 'upstream-pr/1819'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1819'
git switch 'main'
git merge --squash 'upstream-pr/1819'
git switch 'main'
git merge --ff-only 'upstream-pr/1819'
git switch 'main'
git merge 'upstream-pr/1819'
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
Marvisak/VIctory!1817
No description provided.