Repository navigation
Shaders: spin-wait loops stop after 4096 iterations; loop limit in release builds - #452
AntoninMichelq wants to merge 6 commits into
Conversation
|
I found a fixed-address atomic case in I reproduced both outputs on AMD Radeon Graphics, an RTX 5070 Laptop GPU, and WARP with the D3D12 debug layer and full GPU-based validation active. All three reported zero validation warnings or errors. Could you cover this case in the classifier regression suite? I’ve kept the focused correction separate from the runtime census. This test checks observable atomic side effects and does not establish the cause of title polling. |
|
For the next #452 revision, I can rerun the synthetic atomic test on AMD, NVIDIA and WARP. I’d keep paired assertions in the classifier test: a fixed-address load/compare loop still uses the spin budget, while a returning |
|
I merged current |
|
Data point for the spin-wait limit, measured on the machine where the world hang is worst here: the spin limit alone does not stop this title's 10-second host submissions, the general loop limit does. Setup: Windows 11 Pro 26200.9974, RTX 5070, driver 617.14, release build, this PR merged onto a stack of the shader PRs (#298, #585, #383, #259, #302, #307, #539, #571, #569) and the GPU PRs (#493, #483, #581, #595), 110 s in the world each, same scene (first mission intro).
The submissions that take 10 s are not spin waits: with the spin pass in, they are still 10 s, and they stop being a problem only when the general count comes down. Under 2^16 the frame rate is unchanged (2.6-4.4 fps, same draws/frame), so shortening those loops costs nothing visible here. That matters beyond frame time: a submission over the host's ~2 s watchdog removes the device, and twice today a 10 s one took the whole desktop down with it (the machine had to be restarted). At 2^14 the longest submission is 371 ms and a 110 s world run has no removal. Integration notes for landing it on current main (all small, on
No game files; only timings and counts. AI-assisted (DeepSeek V4.1 Flash coding agent). |
|
Thanks a lot for these measurements, the 2^20 / 2^16 / 2^14 comparison on the RTX 5070 makes the case clearly. The default general loop limit is now 2^14 (16,384) in cd6a864. The doc comment on LOOP_LIMIT gives the reason (the ~2 s host watchdog, your numbers) and the trade-off: a legitimate loop of more than 16,384 iterations per lane is cut short, so its result is wrong there. |
|
Data point for
On this card the earlier removal looks like the 2 s TDR: with the loop limits from this PR every world frame stays under it, audio stays in sync, and the run only ends on a separate page fault. Same result on 3 earlier runs without this PR (always ~60 s). Happy to rerun another revision or limit value and post the numbers (on RDNA4 only). |
|
Result on an NVIDIA RTX 3080 Ti (32-lane waves, Windows 11), fork github.com/Machad3x/VIctory branch claude/gta6-shader-translation-crashes-705550 (main + #302 #489 #294 #578 #650 #233 #709 #585 #309 #587 #452): wave64 mesh programs are NOT what hangs the GPU. With #578's mesh refusal switched off (a diagnostics-only switch on the fork, VICTORY_ALLOW_WAVE64_MESH=1): without #452 a world frame costs 4.3 s of GPU and the device is removed (even with #587); with VICTORY_SHADER_LOOP_LIMIT=64 the same run stays up (3731 draws per frame, about 90 ms of GPU per frame, no removal, no slow list); with #452 and its defaults (spin limit 4096, no manual limit) the run stays up for 5 minutes, 3900 draws per frame, 441 ms of GPU per frame. So the TDR was loops running to the 2^20 limit, as #452 measured on an RX 7600, and #578's mesh refusal looks unnecessary once #452 is in; only the frame CPU time (about 600 MB of copies per frame) remains very high. Not yet checked: whether the picture is right (the world was still mostly dark on the RX 7600 per #452). |
catminou4
left a comment
There was a problem hiding this comment.
Two coordinated changes, both well-reasoned:
1. General loop limit 2^20 → 2^14. The justification is measured, not guessed: world runs on an RTX 5070 had submissions up to 10.6 s hitting the ~2 s TDR watchdog (device removal, twice taking the desktop down); 2^14 keeps the longest submission at 371 ms with the same frame rate. The README documents the env var's new default and the diagnostic value of raising it. The // shortcut: comment honestly states the trade-off (a legitimate longer loop is cut short).
2. Spin-wait detection (spin.rs, 4096-iteration limit). The analysis is conservative in the right direction: a loop counts only if it has reads, no Effect accesses (stores/exports/LDS writes/barriers/messages), every memory address invariant, and no loop-carried arithmetic (a counter means real work). The alias resolution for trivial phis and the invariant memoization are careful. The two new lowering tests pin both directions: a table-buffer spin wait gets the spin limit (spin_loops == 1), the same loop with an LDS write inside keeps the general limit (== 0).
The shader-cache build hash now mixes in the spin limit alongside the loop limit, so changing VICTORY_SHADER_SPIN_LIMIT correctly invalidates cached translations — that part is in victory-gpu (Windows-only, not compiled here), but it's a two-line hash input and reads correctly.
Verified locally: test-merge with current main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 102 passed / 0 failed / 1 ignored. The spin-vs-loop runtime behavior (a spin wait actually stopping at 4096 on hardware) is Windows-gated like the rest of valu_tests, so it needs the Windows lane — but the detection logic and its tests are platform-independent and green here.
|
Automated triage for the maintainers. Merge candidate. Recommending a look, not approving.
CI: Generated by Claude Code |
A world frame spends 650-930 ms of GPU time per host submission on an RX 7600, mostly in compute pipelines. Translated loops stop at 2^20 iterations per lane; a loop that waits on memory the host never updates runs that long in every lane. A lower limit shows whether such loops are the cost, and the user runs release builds: the switch is no longer gated on the diagnostics feature. The shader cache already keys on the limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
A loop that only rereads one address until another workgroup, queue or the command processor changes it (decoupled look-back, persistent-thread queues, locks) waits microseconds on the console. On the host the write may never come: the writer's view can be another host resource, null or not yet mirrored, and the host compiler may hoist a load out of a loop that writes nothing (bufferLoad is readonly). The loop then runs to the 2^20 limit in every lane: about a second per wave of uncached reads, the order of the 650-930 ms world submissions spend on an RX 7600. Such loops are found in the IR (emit/spin.rs): no stores, exports, LDS writes, barriers or messages; every memory read and atomic at an address the loop does not change; and nothing loop-carried made by arithmetic, only lane masks, compares and what was read. They stop at VICTORY_SHADER_SPIN_LIMIT (default 4096, never above the loop limit); the shader cache keys on it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
The host GPU watchdog removes the device once a submission runs for about 2 s. Measured on an RTX 5070 over 110 s world runs: with 2^20, 9 slow submissions, the longest 10.6 s (24-457 ms of GPU time per frame), device removed, twice with the desktop; with 2^16, the longest 1.1 s; with 2^14, the longest 371 ms (42-50 ms per frame), no device removal, same frame rate. Those were not spin waits, so only the general limit shortens them. A legitimate loop of more than 16,384 iterations per lane is now cut short and gives a wrong result there; VICTORY_SHADER_LOOP_LIMIT still raises the limit in every build to check. The spin limit (4096) stays at most the loop limit, and the shader cache keys on both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Gate the Windows-only test imports and make the limit check a const assertion, so cargo clippy -D warnings passes on CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
A returning buffer or image atomic was taken as a read, so a loop that counts with one at a fixed address got the spin limit and stopped early (upstream PR 452 review: 16 instead of 33 with limits 64/16). Atomics now count as effects, like stores; tests cover both kinds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
The list's tag covers the translation as the shader cache keys it, but only its loop limit: after a run with another VICTORY_SHADER_SPIN_LIMIT the list still held, though the pipelines it names are not the ones that run makes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I rebased this onto current Conflicts. The four files triage lists are all "keep both" or the same edit against newer text. In One conflict git does not show. Since this branched, main's Checked on Linux (Wine 11.22, vkd3d-proton, RTX 5080):
Not checked: a Windows run of the tests, and the title. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
5bcacf5 to
723bacc
Compare
Requested by 4nto · project thread
Summary
Spin-wait loops now stop after 4096 iterations instead of 2^20. On an RX 7600, a loop limit of 4096 cut GPU time per world frame by a factor of 3 to 10.
Some compute loops only reread one address until another workgroup, queue or the command processor changes it (decoupled look-back, persistent-thread queues, locks). On the console the write comes within microseconds. On the host it may never come: the writer's view can be another host resource, a null view, or not yet mirrored, and the host compiler may hoist the load out of a loop that writes nothing. The loop then runs to the 2^20 limit in every lane, about a second per wave of uncached reads.
VICTORY_SHADER_LOOP_LIMITin release builds too. It was gated on thediagnosticsfeature. The shader cache already keys on it.emit/spin.rs) finds such loops in the IR. They stop atVICTORY_SHADER_SPIN_LIMIT(default 4096, never above the loop limit). Other loops keep the 2^20 limit.What changed
emit/spin.rs(new): a loop is a spin wait when it has no stores, exports, LDS writes, barriers or messages; every memory read and atomic is at an address the loop does not change; and nothing loop-carried is made by arithmetic, only lane masks, compares and what was read.emit/lower.rs:count_iterationuses the spin limit for those loop headers.emit/mod.rs:spin_limit()andDEFAULT_SPIN_LIMIT; the loop limit is read in every build.victory-gpu/src/shader_cache.rs: the cache key includes the spin limit.README.md: the new variable.Open PR #292 also reads
VICTORY_SHADER_LOOP_LIMITin release builds (the same as commit 1), and changes the loop counters to one shared budget per invocation. It has no spin-wait limit. The two touch the same counter code, so whichever lands second needs a small rebase.How it was tested
cargo test -p victory-shader(Linux) passes: 62 tests, including new ones for a spin wait on a table buffer (spin limit), a loop that writes LDS (loop limit), the spin-loop finder and the limit parser.cargo check --tests -p victory-shader -p victory-gpuandcargo check -p victoryforx86_64-pc-windows-msvc(withCARGO_FEATURE_PURE=1) pass.VICTORY_SHADER_LOOP_LIMIT=4096), GPU time per frame went from 410 to 1,384 ms to a median of 127 ms.Where 3D rendering stands on an RX 7600 (Windows 11)
These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66