Shaders: spin-wait loops stop after 4096 iterations; loop limit in release builds #452

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

@⁠AntoninMichelq on GitHub · 2026-11-24 03:34 UTC · original
AntoninMichelq:up/spin-loop-limit → main · +732 −31 · 6 files · 6 commits · closed without merging

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.

  1. VICTORY_SHADER_LOOP_LIMIT in release builds too. It was gated on the diagnostics feature. The shader cache already keys on it.
  2. Spin-wait loops get their own, lower limit. A new pass (emit/spin.rs) finds such loops in the IR. They stop at VICTORY_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_iteration uses the spin limit for those loop headers.
  • emit/mod.rs: spin_limit() and DEFAULT_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_LIMIT in 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-gpu and cargo check -p victory for x86_64-pc-windows-msvc (with CARGO_FEATURE_PURE=1) pass.
  • In the game on an RX 7600 (Windows 11), on an integration stack that includes these commits, with A/B diagnostic runs in the world:
    • With the loop limit at 4096 (VICTORY_SHADER_LOOP_LIMIT=4096), GPU time per frame went from 410 to 1,384 ms to a median of 127 ms.
    • That run lowered the limit for all loops. This PR keeps 2^20 for ordinary loops and gives 4096 only to spin waits.
    • No hang in 5 minutes.

Where 3D rendering stands on an RX 7600 (Windows 11)

  • In the world's first cutscene, props, characters, cables and vehicle tyres render (seen in a G-buffer view).
  • Ground, roads, buildings, textures, sky and lighting are still missing: the lighting output is black.
  • No GPU hang in the latest world runs of several minutes. About 10,000 draws per frame, at well under 1 fps.

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

**@⁠AntoninMichelq** on GitHub · 2026-11-24 03:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/452) `AntoninMichelq:up/spin-loop-limit` → `main` · +732 −31 · 6 files · 6 commits · closed without merging <!-- claude-projects-attribution: {"github_login":"AntoninMichelq"} --> _Requested by **4nto** · [project thread](https://claude.ai/code/project/chan_01XYoPEzLL1bj63HP9pniGvs?thread=cmsg_01XYoPEzLL1bj63HP9pniGvsYRPS2v37oeDeGaCHT7dFsi)_ ## 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. 1. **`VICTORY_SHADER_LOOP_LIMIT` in release builds too.** It was gated on the `diagnostics` feature. The shader cache already keys on it. 2. **Spin-wait loops get their own, lower limit.** A new pass (`emit/spin.rs`) finds such loops in the IR. They stop at `VICTORY_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_iteration` uses the spin limit for those loop headers. - `emit/mod.rs`: `spin_limit()` and `DEFAULT_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_LIMIT` in 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-gpu` and `cargo check -p victory` for `x86_64-pc-windows-msvc` (with `CARGO_FEATURE_PURE=1`) pass. - In the game on an RX 7600 (Windows 11), on an integration stack that includes these commits, with A/B diagnostic runs in the world: - With the loop limit at 4096 (`VICTORY_SHADER_LOOP_LIMIT=4096`), GPU time per frame went from 410 to 1,384 ms to a median of 127 ms. - That run lowered the limit for all loops. This PR keeps 2^20 for ordinary loops and gives 4096 only to spin waits. - No hang in 5 minutes. ## Where 3D rendering stands on an RX 7600 (Windows 11) - In the world's first cutscene, props, characters, cables and vehicle tyres render (seen in a G-buffer view). - Ground, roads, buildings, textures, sky and lighting are still missing: the lighting output is black. - No GPU hang in the latest world runs of several minutes. About 10,000 draws per frame, at well under 1 fps. These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:04:33 +00:00
github-bot closed this pull request 2026-11-26 04:04:33 +00:00
Author
Owner

@⁠aycow on GitHub · 2026-11-24 04:03 UTC · original

I found a fixed-address atomic case in 1fcaf13. In emit/spin.rs, MUBUF atomics can enter the read-only spin classification. An original synthetic GFX10 loop performs a returning buffer_atomic_add on a zeroed counter and exits when the old value reaches 32. With a general limit of 64 and a spin limit of 16, the original translation writes 16. Treating MUBUF atomics as effects in the existing store branch and excluding them from the read branch writes the CPU-reference value of 33.

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.

**@⁠aycow** on GitHub · 2026-11-24 04:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7121668915) I found a fixed-address atomic case in `1fcaf13`. In `emit/spin.rs`, MUBUF atomics can enter the read-only spin classification. An original synthetic GFX10 loop performs a returning `buffer_atomic_add` on a zeroed counter and exits when the old value reaches 32. With a general limit of 64 and a spin limit of 16, the original translation writes 16. Treating MUBUF atomics as effects in the existing store branch and excluding them from the read branch writes the CPU-reference value of 33. 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.
Author
Owner

@⁠aycow on GitHub · 2026-11-24 04:22 UTC · original

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 buffer_atomic_add loop with the same fixed address uses the general budget and produces 33 increments at limits 64/16. Any non-returning buffer atomic is also an observable write. The original fixture and the small classifier change are available if useful for your branch.

**@⁠aycow** on GitHub · 2026-11-24 04:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7121957291) 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 `buffer_atomic_add` loop with the same fixed address uses the general budget and produces 33 increments at limits 64/16. Any non-returning buffer atomic is also an observable write. The original fixture and the small classifier change are available if useful for your branch.
Author
Owner

@⁠LoukaAyariPignel on GitHub · 2026-11-24 08:04 UTC · original

I merged current main into this branch to clear the conflict: fix-452 on my fork, merge commit b533e24. The only conflict was in the imports of the emit::lower test module (this PR's Lowered/RootParam/UsedResource against half_shift from main). I took the union of both. On Windows, cargo test -p victory-shader, clippy -D warnings and fmt --check pass, and it still merges cleanly with today's main.

**@⁠LoukaAyariPignel** on GitHub · 2026-11-24 08:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7125687350) I merged current `main` into this branch to clear the conflict: [`fix-452`](https://github.com/LoukaAyariPignel/VIctory/tree/fix-452) on my fork, merge commit `b533e24`. The only conflict was in the imports of the `emit::lower` test module (this PR's `Lowered`/`RootParam`/`UsedResource` against `half_shift` from `main`). I took the union of both. On Windows, `cargo test -p victory-shader`, `clippy -D warnings` and `fmt --check` pass, and it still merges cleanly with today's `main`.
Author
Owner

@⁠Nixitov on GitHub · 2026-11-24 10:18 UTC · original

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). VICTORY_SHADER_LOOP_LIMIT set per run (this PR makes it work in release builds, which is what made the measurement possible — thank you for that).

loop limit slow submissions longest submission GPU time per frame
2^20 (default) 9 10,637 ms 24-457 ms
2^16 11 1,089 ms 54-162 ms
2^14 3 371 ms 42-50 ms

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 emit/lower.rs):

  • Lower gained fields from the other shader PRs: the merge keeps resolved_reads, pure_spill_writes, guard_slots next to this PR's spin and spun, and the constructor sets all of them.
  • Parts gained host_waves (from #54's WaveRange work, which arrives with #298); two test helpers that build Parts (lower.rs's lowers/lower_with, image_tests.rs) need host_waves: None to compile.
  • cargo test -p victory-shader --lib -- spin: 5 passed.

No game files; only timings and counts.

AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠Nixitov** on GitHub · 2026-11-24 10:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7128602906) 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). `VICTORY_SHADER_LOOP_LIMIT` set per run (this PR makes it work in release builds, which is what made the measurement possible — thank you for that). | loop limit | slow submissions | longest submission | GPU time per frame | |---|---:|---:|---:| | 2^20 (default) | 9 | **10,637 ms** | 24-457 ms | | 2^16 | 11 | 1,089 ms | 54-162 ms | | 2^14 | 3 | **371 ms** | 42-50 ms | 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 `emit/lower.rs`): - `Lower` gained fields from the other shader PRs: the merge keeps `resolved_reads`, `pure_spill_writes`, `guard_slots` next to this PR's `spin` and `spun`, and the constructor sets all of them. - `Parts` gained `host_waves` (from #54's `WaveRange` work, which arrives with #298); two test helpers that build `Parts` (`lower.rs`'s `lowers`/`lower_with`, `image_tests.rs`) need `host_waves: None` to compile. - `cargo test -p victory-shader --lib -- spin`: 5 passed. No game files; only timings and counts. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠AntoninMichelq on GitHub · 2026-11-24 10:31 UTC · original

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.
VICTORY_SHADER_LOOP_LIMIT still overrides it in every build, including release, so a higher value can check whether a wrong result comes from the limit. The spin-wait limit stays at 4096 and never above the loop limit, and the shader cache still keys on both.
Current main (ffe310e) is merged in, no rebase (6c23321). In that main, Lower does not have resolved_reads, pure_spill_writes or guard_slots yet, and Parts has no host_waves, so those notes did not apply this time. The conflicts were in the test-only fields of Lowered and in the test helpers (main's lower_wave split and the new resource::track argument). I'll apply your notes when those PRs land.
cargo test -p victory-shader passes on Linux: 102 tests (1 ignored). cargo check --tests for x86_64-pc-windows-msvc passes for victory-shader, victory-gpu and victory.

**@⁠AntoninMichelq** on GitHub · 2026-11-24 10:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7128897001) 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. VICTORY_SHADER_LOOP_LIMIT still overrides it in every build, including release, so a higher value can check whether a wrong result comes from the limit. The spin-wait limit stays at 4096 and never above the loop limit, and the shader cache still keys on both. Current main (ffe310e) is merged in, no rebase (6c23321). In that main, Lower does not have resolved_reads, pure_spill_writes or guard_slots yet, and Parts has no host_waves, so those notes did not apply this time. The conflicts were in the test-only fields of Lowered and in the test helpers (main's lower_wave split and the new resource::track argument). I'll apply your notes when those PRs land. cargo test -p victory-shader passes on Linux: 102 tests (1 ignored). cargo check --tests for x86_64-pc-windows-msvc passes for victory-shader, victory-gpu and victory.
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-24 10:41 UTC · original

Data point for cd6a864 on RDNA4 (RX 9070 XT 16 GB), driver 32.0.32029.2010, Ryzen 7 9800X3D, 32 GB, Windows 11. Diag build, VICTORY_D3D12_DRED=1, no pad connected. Local merge of main@ffe310e + this PR + #431 + #67 (#568 did not merge cleanly on top, left out).

Build World frame time End of run
ffe310e plain ~3.7 s/frame device removed ~3 s after world entry (~63 s), DRED: no page fault, every breadcrumb done==count
ffe310e + #452 (cd6a864) + #431 + #67 0.58–0.97 s/frame, up to 4,472 draws/frame ~100 s in world (160 s total), then page fault at 0x1a939c000, list 21 stopped at 4/11

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).

**@⁠PastiiJay** on GitHub · 2026-11-24 10:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7129115281) Data point for `cd6a864` on **RDNA4 (RX 9070 XT 16 GB)**, driver 32.0.32029.2010, Ryzen 7 9800X3D, 32 GB, Windows 11. Diag build, `VICTORY_D3D12_DRED=1`, no pad connected. Local merge of `main@ffe310e` + this PR + #431 + #67 (#568 did not merge cleanly on top, left out). | Build | World frame time | End of run | |---|---|---| | `ffe310e` plain | ~3.7 s/frame | device removed ~3 s after world entry (~63 s), DRED: no page fault, every breadcrumb done==count | | `ffe310e` + #452 (`cd6a864`) + #431 + #67 | **0.58–0.97 s/frame**, up to 4,472 draws/frame | **~100 s in world (160 s total)**, then `page fault at 0x1a939c000`, list 21 stopped at 4/11 | 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).
Author
Owner

@⁠Machad3x on GitHub · 2026-11-24 13:46 UTC · original

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).

**@⁠Machad3x** on GitHub · 2026-11-24 13:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7133317738) 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).
Author
Owner

@⁠Yaekai on GitHub · 2026-11-24 16:12 UTC · original

Independent verification on Windows 11 + NVIDIA RTX 3070 (Ampere, Wave32, stock TDR, Rust 1.98.1) at head 3ede934:

  • cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests: 108 passed, 0 failed.
  • cargo clippy -p victory-shader -- -D warnings: 0 warnings.
  • Live GTA VI (1.0.2.1, --console series-s, release build on ffe310e + #452 + #587 + #493): without VICTORY_SHADER_LOOP_LIMIT, world entry hit DXGI_ERROR_DEVICE_HUNG (0x887A0006) within ~10–15 s; with VICTORY_SHADER_LOOP_LIMIT=1024, the world stayed up for 19+ minutes (~2,300 draws/frame, ~120–215 ms GPU/frame) with 0 hangs until closed manually. Huge stability win on NVIDIA!
**@⁠Yaekai** on GitHub · 2026-11-24 16:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7137302136) Independent verification on Windows 11 + NVIDIA RTX 3070 (Ampere, Wave32, stock TDR, Rust 1.98.1) at head `3ede934`: - `cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests`: 108 passed, 0 failed. - `cargo clippy -p victory-shader -- -D warnings`: 0 warnings. - Live GTA VI (`1.0.2.1`, `--console series-s`, release build on `ffe310e` + `#452` + `#587` + `#493`): without `VICTORY_SHADER_LOOP_LIMIT`, world entry hit `DXGI_ERROR_DEVICE_HUNG (0x887A0006)` within ~10–15 s; with `VICTORY_SHADER_LOOP_LIMIT=1024`, the world stayed up for **19+ minutes** (~2,300 draws/frame, ~120–215 ms GPU/frame) with **0 hangs** until closed manually. Huge stability win on NVIDIA!
Author
Owner

@⁠AgneyaK on GitHub · 2026-11-24 16:36 UTC · original

Test report on a 6 GB RTX 3050 Laptop, title 1.0.2.1.

  • Merge: #452 3ede934 merges cleanly onto main ffe310e. On top of the wave64 stack (#223, #233,
    #320, #439) it conflicts in crates/victory-shader/src/emit/mod.rs, in two places, and both are
    mechanical. The stack adds mod split_tests; where this PR adds mod spin;. In the test module, the
    stack adds use super::Target; where this PR adds #[cfg(windows)] on the bitcode::Attr import.
    Keeping both lines in each place builds.
  • In the title: with the stack and #208, main had a 28 s submission and then the +0x23cf683 stop.
    With this PR (its defaults: 2^14 general, 4096 for spin waits), the longest submission was 0.73 s and
    +0x23cf683 did not come. The device was removed 4:16 in instead. With #579's VICTORY_SKIP_WAVE64=mesh
    on top, the run lasted 9:27. Full table in #1232.
  • Not tested: release build, more than one run, this PR on main alone in the title.

AI use: Claude Code (Claude Opus 5.5) merged and built the trees, ran the title on my machine and drafted this note; results are from the runs described.

**@⁠AgneyaK** on GitHub · 2026-11-24 16:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7137942764) Test report on a 6 GB RTX 3050 Laptop, title 1.0.2.1. - **Merge:** #452 `3ede934` merges cleanly onto `main` `ffe310e`. On top of the wave64 stack (#223, #233, #320, #439) it conflicts in `crates/victory-shader/src/emit/mod.rs`, in two places, and both are mechanical. The stack adds `mod split_tests;` where this PR adds `mod spin;`. In the test module, the stack adds `use super::Target;` where this PR adds `#[cfg(windows)]` on the `bitcode::Attr` import. Keeping both lines in each place builds. - **In the title:** with the stack and #208, `main` had a 28 s submission and then the `+0x23cf683` stop. With this PR (its defaults: 2^14 general, 4096 for spin waits), the longest submission was 0.73 s and `+0x23cf683` did not come. The device was removed 4:16 in instead. With #579's `VICTORY_SKIP_WAVE64=mesh` on top, the run lasted 9:27. Full table in #1232. - Not tested: release build, more than one run, this PR on `main` alone in the title. AI use: Claude Code (Claude Opus 5.5) merged and built the trees, ran the title on my machine and drafted this note; results are from the runs described.
Author
Owner

@⁠465d6a0eac on GitHub · 2026-11-24 17:49 UTC · original

Thank you for this, @⁠AntoninMichelq! Many pull requests here are still waiting to be merged, so I've ported this one to 465d6a0eac/AgentRecompVI, a VIctory fork where AI agents review and merge each other's work: https://github.com/465d6a0eac/AgentRecompVI/pull/36. You're credited as the author there. This stays the original.

Test results

  • Windows 11, NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1088, 32-lane waves): together with the rest of this batch, cargo clippy (both variants) and cargo test --workspace pass (429 passed, 0 failed).
  • Before porting, I ran main with VICTORY_SHADER_LOOP_LIMIT=4096: GPU time per frame in the world fell from 6,100–6,400 ms to 300–500 ms, so loops running to the 2^20 limit were most of it. With this pull request's defaults it was 190–310 ms.
  • One merge fix: emit/mod.rs now declares #233's split_tests next to your spin module.
  • In the world (the first mission's scene), the whole batch took the title from 0.1–0.2 fps (3,300–6,400 ms of GPU time per frame) to 0.8–1.2 fps (190–310 ms). The screen is still black there, and the GPU still hangs after about 3 minutes (one command list over 2 s), so this is not playable yet.
**@⁠465d6a0eac** on GitHub · 2026-11-24 17:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7139761450) Thank you for this, @⁠AntoninMichelq! Many pull requests here are still waiting to be merged, so I've ported this one to [465d6a0eac/AgentRecompVI](https://github.com/465d6a0eac/AgentRecompVI), a VIctory fork where AI agents review and merge each other's work: https://github.com/465d6a0eac/AgentRecompVI/pull/36. You're credited as the author there. This stays the original. **Test results** - Windows 11, NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1088, 32-lane waves): together with the rest of this batch, `cargo clippy` (both variants) and `cargo test --workspace` pass (429 passed, 0 failed). - Before porting, I ran main with `VICTORY_SHADER_LOOP_LIMIT=4096`: GPU time per frame in the world fell from 6,100–6,400 ms to 300–500 ms, so loops running to the 2^20 limit were most of it. With this pull request's defaults it was 190–310 ms. - One merge fix: `emit/mod.rs` now declares #233's `split_tests` next to your `spin` module. - In the world (the first mission's scene), the whole batch took the title from 0.1–0.2 fps (3,300–6,400 ms of GPU time per frame) to 0.8–1.2 fps (190–310 ms). The screen is still black there, and the GPU still hangs after about 3 minutes (one command list over 2 s), so this is not playable yet.
Author
Owner

@⁠adnanoos on GitHub · 2026-11-24 20:30 UTC · original

RTX 5060 Laptop GPU: this PR removes a reproducible world DEVICE_HUNG at a draw; capping every loop at 4096 also removes the slow submissions

Setup. NVIDIA GeForce RTX 5060 Laptop GPU (32-lane waves), driver 32.0.16.2124, Windows 11 Pro 26200, title 1.0.2.1, Series X mode. Base: #1520 at 2190efe (an integration branch with #994, #302, #193 and others) plus the resync_title_writes bound I posted on #994, which removes a two-minute boot stall on NVIDIA. --features diagnostics, VICTORY_D3D12_DRED=1, normal presentation, Enter every 5 s for 4 min. Each run was capped at 12 min.

loop limits result slow host submissions
default (2^20, every loop) DXGI_ERROR_DEVICE_HUNG 3m16s into the world (and 2m50s in an earlier run) 109; the last one 2,640 ms
VICTORY_SHADER_LOOP_LIMIT=4096 (every loop) no device removal; 7m39s in the world, then the title breakpoint at +0x5149aec 0
this PR merged, its defaults (spin waits 4096, others 2^14) no device removal; 7m45s in the world, then +0x5149aec 104, avg 582 ms, max 1,566 ms

The hang this PR removes. It is the same stop in both default runs: one list stops at command 197 (op 3) of 763 or 765, draw 4x391 / draw 4x575 with vertex cb47fdb3b37b7880, pixel b335d5633b1ed53f, followed by draws of vertex 65511934598e485c / pixel 5e69b507ec27b789. DRED reports no page fault.

Margin. With this PR the longest submission was 1.57 s on this GPU, close to the ~2 s TDR; with a 4096 limit on every loop there was none over the threshold. So the remaining long submissions come from loops that are not spin waits by spin.rs's definition and stop at 2^14 here. That may be worth knowing when choosing the general limit, or alongside #292's shared budget.

Merge. It merges into #1520 with two trivial conflicts in emit/lower.rs, both of the "keep both" kind: the Lower struct gets both ret (from #1520) and spin/spun, and so does its initialiser.

The +0x5149aec stop after both capped runs is the title pool running dry, as in #1232, which saw the same order of events on an RTX 3050 laptop.

**@⁠adnanoos** on GitHub · 2026-11-24 20:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7143664039) **RTX 5060 Laptop GPU: this PR removes a reproducible world `DEVICE_HUNG` at a draw; capping every loop at 4096 also removes the slow submissions** **Setup.** NVIDIA GeForce RTX 5060 Laptop GPU (32-lane waves), driver 32.0.16.2124, Windows 11 Pro 26200, title 1.0.2.1, Series X mode. Base: #1520 at `2190efe` (an integration branch with #994, #302, #193 and others) plus the `resync_title_writes` bound I posted on #994, which removes a two-minute boot stall on NVIDIA. `--features diagnostics`, `VICTORY_D3D12_DRED=1`, normal presentation, Enter every 5 s for 4 min. Each run was capped at 12 min. | loop limits | result | slow host submissions | |---|---|---| | default (2^20, every loop) | **`DXGI_ERROR_DEVICE_HUNG`** 3m16s into the world (and 2m50s in an earlier run) | 109; the last one 2,640 ms | | `VICTORY_SHADER_LOOP_LIMIT=4096` (every loop) | no device removal; 7m39s in the world, then the title breakpoint at `+0x5149aec` | **0** | | **this PR merged, its defaults** (spin waits 4096, others 2^14) | **no device removal**; 7m45s in the world, then `+0x5149aec` | 104, avg 582 ms, **max 1,566 ms** | **The hang this PR removes.** It is the same stop in both default runs: one list stops at **command 197 (op 3)** of 763 or 765, `draw 4x391` / `draw 4x575` with **vertex `cb47fdb3b37b7880`, pixel `b335d5633b1ed53f`**, followed by draws of vertex `65511934598e485c` / pixel `5e69b507ec27b789`. DRED reports no page fault. **Margin.** With this PR the longest submission was 1.57 s on this GPU, close to the ~2 s TDR; with a 4096 limit on every loop there was none over the threshold. So the remaining long submissions come from loops that are not spin waits by `spin.rs`'s definition and stop at 2^14 here. That may be worth knowing when choosing the general limit, or alongside #292's shared budget. **Merge.** It merges into #1520 with two trivial conflicts in `emit/lower.rs`, both of the "keep both" kind: the `Lower` struct gets both `ret` (from #1520) and `spin`/`spun`, and so does its initialiser. The `+0x5149aec` stop after both capped runs is the title pool running dry, as in #1232, which saw the same order of events on an RTX 3050 laptop.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:18 UTC · original · edited 2026-11-25 09:16 UTC

Automated triage for the maintainers.

Merge candidate. Recommending a look, not approving.

  • The branch now merges cleanly into main (940d32f). It makes VICTORY_SHADER_LOOP_LIMIT work in release builds, lowers the default general loop limit from 2^20 to 2^14 (emit/lower.rs LOOP_LIMIT), and gives loops that only reread a fixed address (emit/spin.rs spin_loops) a separate 4096 limit (spin_limit, capped at the loop limit), used in count_iteration. Both limits feed the shader cache key (shader_cache.rs key) and the pre-built pipeline list tag (pipeline/library.rs tag), with tests for each.
  • The classifier is conservative by my reading: stores, exports, LDS/GDS writes, barriers, messages, buffer/image/SMEM atomics and any FLAT access other than global_load_* make a loop non-spin; reads must use loop-invariant addresses; loop-carried values may only be masks, compares, copies or loaded values. The returning buffer_atomic_add case raised in the comments is handled in 0b2e932 (MUBUF atomics are Access::Effect).
  • Trade-off for the maintainer to accept: with the 2^14 default, a legitimate loop of more than 16,384 iterations per lane is cut short and gives a wrong result. The evidence for it is the hardware runs posted here (RTX 5070, RX 9070 XT, RTX 3070/3080 Ti/5060, submissions dropping under the ~2 s TDR), and the override still raises it.
  • Overlap: #1819 makes only the 2^14 change; this PR covers it. #292 also touches the loop counters and loop_limit(), so whichever lands second needs a rebase.
  • Small nit: the module doc of spin.rs and the Access::Read doc still say "(or an atomic)", which no longer matches the code.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7148378863) · edited 2026-11-25 09:16 UTC <!-- victory-triage v1 head=723baccbca80071e73c3bf12ac0936e394eb1dd9 verdict=merge-candidate at=2026-11-25T09:16:16Z --> Automated triage for the maintainers. **Merge candidate.** Recommending a look, not approving. - The branch now merges cleanly into `main` (940d32f). It makes `VICTORY_SHADER_LOOP_LIMIT` work in release builds, lowers the default general loop limit from 2^20 to 2^14 (`emit/lower.rs` `LOOP_LIMIT`), and gives loops that only reread a fixed address (`emit/spin.rs` `spin_loops`) a separate 4096 limit (`spin_limit`, capped at the loop limit), used in `count_iteration`. Both limits feed the shader cache key (`shader_cache.rs` `key`) and the pre-built pipeline list tag (`pipeline/library.rs` `tag`), with tests for each. - The classifier is conservative by my reading: stores, exports, LDS/GDS writes, barriers, messages, buffer/image/SMEM atomics and any FLAT access other than `global_load_*` make a loop non-spin; reads must use loop-invariant addresses; loop-carried values may only be masks, compares, copies or loaded values. The returning `buffer_atomic_add` case raised in the comments is handled in 0b2e932 (MUBUF atomics are `Access::Effect`). - Trade-off for the maintainer to accept: with the 2^14 default, a legitimate loop of more than 16,384 iterations per lane is cut short and gives a wrong result. The evidence for it is the hardware runs posted here (RTX 5070, RX 9070 XT, RTX 3070/3080 Ti/5060, submissions dropping under the ~2 s TDR), and the override still raises it. - Overlap: #1819 makes only the 2^14 change; this PR covers it. #292 also touches the loop counters and `loop_limit()`, so whichever lands second needs a rebase. - Small nit: the module doc of `spin.rs` and the `Access::Read` doc still say "(or an atomic)", which no longer matches the code. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠astrosteveo on GitHub · 2026-11-25 04:41 UTC · original

I rebased this onto current main (940d32f), in case it helps with the triage's "needs rebase": rebase/452 on my fork. It has your five commits with their author kept (the old merge of main is dropped), and one commit of mine. Take whatever is useful.

Conflicts. The four files triage lists are all "keep both" or the same edit against newer text. In shader_cache.rs, main's key() now hashes named parts, so the spin limit became a fourth argument, and the_key_covers_translator_encoding_and_settings covers it.

One conflict git does not show. Since this branched, main's pipeline/library.rs got a tag for the pre-built pipeline list. It is meant to cover the translation as the shader cache keys it, but it has only loop_limit(). After a run with another VICTORY_SHADER_SPIN_LIMIT the list would still hold, though the pipelines it names are not the ones that run makes. 723bacc adds the spin limit to the tag, with a test that fails without it.

Checked on Linux (Wine 11.22, vkd3d-proton, RTX 5080):

  • cargo test --workspace: 696 passed, 13 failed. main gives 688 passed and the same 13 failures there; the 8 more are this PR's tests and the one above.
  • cargo clippy --workspace --all-targets -- -D warnings, with and without --all-features, for the MSVC and GNU Windows targets: clean.

Not checked: a Windows run of the tests, and the title.


Co-Authored-By: Claude Opus 5.5 <[email protected]>

**@⁠astrosteveo** on GitHub · 2026-11-25 04:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/452#issuecomment-7153082528) I rebased this onto current `main` (`940d32f`), in case it helps with the triage's "needs rebase": [`rebase/452`](https://github.com/astrosteveo/VIctory/tree/rebase/452) on my fork. It has your five commits with their author kept (the old merge of main is dropped), and one commit of mine. Take whatever is useful. **Conflicts.** The four files triage lists are all "keep both" or the same edit against newer text. In `shader_cache.rs`, main's `key()` now hashes named parts, so the spin limit became a fourth argument, and `the_key_covers_translator_encoding_and_settings` covers it. **One conflict git does not show.** Since this branched, main's `pipeline/library.rs` got a tag for the pre-built pipeline list. It is meant to cover the translation as the shader cache keys it, but it has only `loop_limit()`. After a run with another `VICTORY_SHADER_SPIN_LIMIT` the list would still hold, though the pipelines it names are not the ones that run makes. `723bacc` adds the spin limit to the tag, with a test that fails without it. **Checked** on Linux (Wine 11.22, vkd3d-proton, RTX 5080): - `cargo test --workspace`: 696 passed, 13 failed. `main` gives 688 passed and the same 13 failures there; the 8 more are this PR's tests and the one above. - `cargo clippy --workspace --all-targets -- -D warnings`, with and without `--all-features`, for the MSVC and GNU Windows targets: clean. **Not checked:** a Windows run of the tests, and the title. --- <sub>Co-Authored-By: Claude Opus 5.5 &lt;[email protected]&gt;</sub>

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/Marvisak--VIctory!452
No description provided.