Repository navigation
Shaders: translated loops are left after 2^14 iterations (was 2^20) - #1819
Exopus-0x65f7ad0 wants to merge 2 commits into
Conversation
A loop walking a parent table that a dropped dispatch never filled (a union-find in a GPU-driven compute pass) ran for 2^20 iterations per lane: the submission outlasted the NVIDIA driver's reset, the reset failed and the desktop froze until a hard reboot. 2^14 bounds such a loop to milliseconds per wave; VICTORY_SHADER_LOOP_LIMIT still overrides it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
catminou4
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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).
|
For the reviewers, how the other two console-port emulators bound loops (code reading, not a test of this PR):
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. |
|
NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, AI-assisted (Claude Code). Synthetic tests only. |
Translation speed (compile-storm CPU): Marvisak#1623 inline instruction words (decode -18..-45%), Marvisak#1834 VALU names without heap vector, Marvisak#1833 live-set bit walk, Marvisak#1802 relative shift bounds, Marvisak#1824 dx.op declarations once. Per-draw/per-list CPU: Marvisak#1825 view-stride table once per list, Marvisak#1826 object names only where logged, Marvisak#1800 capped-heap log spam once per 64Ki. Tooling: Marvisak#1809 list pipeline keys without cache init. Locking: Marvisak#1680 pipeline library loads without the global mutex. Held: Marvisak#1819 (2^20->2^14 loop bound) breaks transcendental convergence tests (sin/cos/exp/sqrt) — accuracy-lowering, rejected per policy.
|
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 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 |
…ty-wave * GPU: copy shader writes into write-watched pages under Wine Port upstream #1831: when WriteProcessMemory/NtWriteVirtualMemory refuses an untouched MEM_WRITE_WATCH page under Wine, use the kernel read path into that destination so copy-back still lands. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * GPU: load cached pipelines outside the library lock Port the Wine part of upstream #1722. vkd3d-proton treats a library load as a full compile, so holding the global library lock serialised all workers. Loads of different names can now overlap; same-name loads remain serialised as D3D12 requires. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * GPU: drop unready indirect calls before the argument clamp Port upstream #1635: a call whose host pipeline is not ready cannot run, so do not refresh and clamp records that nothing will read. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * GPU: run indirect mesh dispatches as one-record ExecuteIndirect Port upstream #1749: DispatchMeshX with group counts in GPU memory now uses the host indirect mesh path instead of being dropped. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * Shaders: leave runaway translated loops after 2^14 iterations Port upstream #1819. The previous 2^20 limit could outlast a driver reset; 2^14 bounds runaway loops to milliseconds per wave while VICTORY_SHADER_LOOP_LIMIT remains an override. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * Input: keep the keyboard stand-in while XInput pads are idle Port upstream #1430: virtual or untouched controllers no longer disable keyboard controls; real input outside the XInput deadzones takes over, and fallback keys regain control once host pads are idle. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * GPU: keep pipeline workers competitive and configurable Port upstream #1505 and #1728: workers no longer run below the title's priority, where busy world threads starved them, and VICTORY_PIPELINE_WORKERS can raise the worker count on many-core Linux/Windows hosts. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: stoltembergg <stoltembergg@gmail.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Follow-up. Thanks @catminou4 and @Melow-code for the reviews, and @upipibi for the RTX 3070 run.
Broader progress, and where help is wanted (ray tracing memory, frame rate): #1820. 🤖 Generated with Claude Code |
|
Automated triage for the maintainers. Merge candidate; the default is the maintainer's call. What the last triage asked for is now there:
On your reply: confirmed in the diff. CI: Generated by Claude Code |
A loop whose bound the host has not mirrored yet runs to the limit in every lane that reaches it, and a dispatch lasts as long as its slowest lane. On an Apple M5 GPU one lane's run to 2^20 takes 60 to 195 ms, and to 2^14 takes 1 to 3 ms. Upstream measured one world compute program (00167d58cc5a78d7, up to six runs to the limit per dispatch) at about 90% of a world frame's GPU time on an RTX 2080 Ti (Marvisak/VIctory#1819, the same change). VICTORY_SHADER_LOOP_LIMIT still overrides the limit in diagnostics builds, and the shader cache keys on it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
@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 |
|
The counter asked for in the triage is now a separate PR: #2733 ( 🤖 Generated with Claude Code |
…y why the bound exists Review of Marvisak#1819: on a conditional back edge a lane at the limit leaves by the loop's normal exit (the limit is ANDed into the branch), not as killed; only an unconditional back edge uses the exit block that returns. The history of the change stays in the commit message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The evidence asked for in the triage, from #2733's counter (
The doc comment is fixed in 🤖 Generated with Claude Code |
…eave at the loop limit A diagnostics switch for the question of Marvisak#1819 (is the limit ever reached by a loop that would have ended?). A lane that leaves a loop because of the limit adds one to the first dword of a root UAV, u2 in the memory space: on a conditional back edge where the limit turned the branch, and in the block an unconditional back edge leaves through. While the switch is on, every host root signature declares that UAV and every draw and dispatch binds a counter of ours; the frame line says how many lanes were cut since the last line and since the start. The switch is part of the shader cache key only when on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fuzeofficlal
left a comment
There was a problem hiding this comment.
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 in0146a51are consistent, and novictory-shadertest requires more than2^14iterations per loop entry.emit/lower.rssize: 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, andemit::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.
A loop whose bound the host has not mirrored yet runs to the limit in every lane that reaches it, and a dispatch lasts as long as its slowest lane. On an Apple M5 GPU one lane's run to 2^20 takes 60 to 195 ms, and to 2^14 takes 1 to 3 ms. Upstream measured one world compute program (00167d58cc5a78d7, up to six runs to the limit per dispatch) at about 90% of a world frame's GPU time on an RTX 2080 Ti (Marvisak/VIctory#1819, the same change). VICTORY_SHADER_LOOP_LIMIT still overrides the limit in diagnostics builds, and the shader cache keys on it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
From 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