Shaders: translated loops are left after 2^14 iterations (was 2^20) #1819
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1819
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1819"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Exopus-0x65f7ad0 on GitHub · 2026-11-24 22:59 UTC · original
Exopus-0x65f7ad0:pr/loop-limit-2-14→main· +10 −7 · 3 files · 2 commits · openFrom a tester working with Claude (AI-assisted); measured on my own machine.
Why
A translated loop is cut after
LOOP_LIMITiterations 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 (
nvlddmkmevent 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_LIMITgoes from1 << 20to1 << 14.VICTORY_SHADER_LOOP_LIMITare 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.
cargo test -p victory-shader --lib loopcargo test -p victory-shader --libcargo clippy -p victory-shader --libstride_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 onmainwithout 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.🤖 Generated with Claude Code
@upipibi on GitHub · 2026-11-24 23:06 UTC · original
For the reviewers, how the other two console-port emulators bound loops (code reading, not a test of this PR):
static uint xcl_budget = 1u << 16, decremented at the top of every loop (LOOP_GUARDingpu/recomp/mod.rs, settable withXCL_LOOP_BUDGET).APS5_LOOP_GUARD=<exits>) also counts per invocation. When it runs out, it records aLoopLimitfault 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 on GitHub · 2026-11-24 23:11 UTC · original
NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug,
d7a5c3c(onmain70564ae).cargo test -p victory-shader --locked: 206 passed, 3 failed, 2 ignored. The 3 are #1744's NVIDIA heap-cap failures onmain, so no test needed more than 2^14 iterations.AI-assisted (Claude Code). Synthetic tests only.
@Exopus-0x65f7ad0 on GitHub · 2026-11-25 01:51 UTC · original
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_GUARDwould be the stronger bound. I'll look at that as a follow-up, and at a fault note in the log, like AnyPS5'sLoopLimit, 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
@Exopus-0x65f7ad0 on GitHub · 2026-11-25 06:11 UTC · original
Follow-up. Thanks @catminou4 and @Melow-code for the reviews, and @upipibi for the RTX 3070 run.
LOOP_GUARD, AnyPS5'sLoopLimitnote) 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
@Marvisak on GitHub · 2026-11-25 06:29 UTC · original · edited 2026-11-25 22:24 UTC
Automated triage for the maintainers.
Merge candidate; the default is the maintainer's call.
LOOP_LIMITincrates/victory-shader/src/emit/lower.rsgoes from 2^20 to 2^14, withDEFAULT_LOOP_LIMIT's doc and the README line following.VICTORY_SHADER_LOOP_LIMITstill overrides it, and the shader cache already keys on the limit.What the last triage asked for is now there:
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.On your reply: confirmed in the diff. CI:
checkpassing on this head.Generated by Claude Code
@Exopus-0x65f7ad0 on GitHub · 2026-11-25 17:23 UTC · original
@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:
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
@Exopus-0x65f7ad0 on GitHub · 2026-11-25 19:20 UTC · original
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
@Exopus-0x65f7ad0 on GitHub · 2026-11-25 21:42 UTC · original
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: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
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.