shader: VICTORY_SHADER_LOOP_LIMIT to find what makes world frames slow #46

Manually merged
github merged 1 commit from gh-pr/46/head into gh-pr/46/base 2026-11-26 03:48:03 +00:00
Owner

@⁠9hvn9yt2vk-netizen on GitHub · 2026-11-23 23:45 UTC · original
9hvn9yt2vk-netizen:shader-loop-limit → main · +74 −9 · 4 files · 1 commits · merged 2026-11-24 00:42 UTC

Translated loops stop after 2^20 iterations per lane so that a loop over not yet mirrored data (zeros) cannot run four billion times. A pass where every lane reaches that limit still takes seconds, though: 2^20 iterations times a 4K screen's 8 million pixels is about 10^13 loop bodies. The world's frames now take 1.5-3 s, and loops spinning to the limit on data that reads as zeros are one candidate.

A diagnostics build now reads VICTORY_SHADER_LOOP_LIMIT (decimal or 0x hex, at least 1). If a low value such as 4096 makes world frames much faster, loops hitting the limit are what makes them slow. If not, they are ruled out. The limit is part of the translation, so the shader cache keys on it, and a run that overrides it logs a warning. Release builds always use 2^20.

**@⁠9hvn9yt2vk-netizen** on GitHub · 2026-11-23 23:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/46) `9hvn9yt2vk-netizen:shader-loop-limit` → `main` · +74 −9 · 4 files · 1 commits · merged 2026-11-24 00:42 UTC Translated loops stop after 2^20 iterations per lane so that a loop over not yet mirrored data (zeros) cannot run four billion times. A pass where every lane reaches that limit still takes seconds, though: 2^20 iterations times a 4K screen's 8 million pixels is about 10^13 loop bodies. The world's frames now take 1.5-3 s, and loops spinning to the limit on data that reads as zeros are one candidate. A diagnostics build now reads VICTORY_SHADER_LOOP_LIMIT (decimal or 0x hex, at least 1). If a low value such as 4096 makes world frames much faster, loops hitting the limit are what makes them slow. If not, they are ruled out. The limit is part of the translation, so the shader cache keys on it, and a run that overrides it logs a warning. Release builds always use 2^20.
Translated loops stop after 2^20 iterations per lane so that a loop
over not yet mirrored data (zeros) cannot run four billion times. A pass
where every lane reaches that limit still takes seconds, though: 2^20
iterations times a 4K screen's 8 million pixels is about 10^13 loop
bodies. The world's frames now take 1.5-3 s, and loops spinning to the
limit on data that reads as zeros are one candidate.

A diagnostics build now reads VICTORY_SHADER_LOOP_LIMIT (decimal or 0x
hex, at least 1). If a low value such as 4096 makes world frames much
faster, loops hitting the limit are what makes them slow. If not, they
are ruled out. The limit is part of the translation, so the shader cache
keys on it, and a run that overrides it logs a warning. Release builds
always use 2^20.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:48:03 +00:00
github manually merged commit 15b0091e87 into gh-pr/46/base 2026-11-26 03:48:03 +00:00
Author
Owner

@⁠kleinerleuge-eng on GitHub · 2026-11-23 23:57 UTC · original

Tested on NVIDIA: RTX 5070 Ti, driver 621.01, Windows 11. Diag build of 15b0091 (this PR on 97c78d1), VICTORY_SHADER_LOOP_LIMIT=4096 VICTORY_D3D12_DRED=1, no input.

Result: with a limit of 4096, loops are ruled out for this card's world hang, and world frames are not faster.

  • The warning VICTORY_SHADER_LOOP_LIMIT: translated loops stop sooner is logged, so the limit was active. All shaders were translated again (new cache key).
  • World frames are about as slow as without the limit: 0.2–5.4 fps, 180–620 ms/frame most of the time, of which 80–240 ms is preparing (copies).
  • The world hang is unchanged. About 55 s after the menus there is one slow host submission ms=4820 lists=32, then 0x887A0006 (DEVICE_HUNG), and DRED reports no page fault. On 97c78d1 without this PR the hang came about 20 s after the menus. Here it came later, likely because every shader had to be translated again.
  • DRED stops at the same place as in my earlier run without a limit (#16): a list stopped at command 138 of 155 (op 42), commands 107..155 between its barriers. The listed commands are again only the mesh dispatches with mesh 6b57e37fe499c6e7 / pixel 573d1857e903fab5, mesh 1921f28ef78e3a4b / pixel 80b3065a4477c8c4, mesh 0f73a9ae763e96e2 / pixel ce1481325c93bb70. The earlier run stopped at command 148 of 175 in the same pattern.

Side note: four of the six hung submissions on this card since 8c26061 took 4.82–4.83 s (4828, 4832, 4833, 4820 ms; the other two took 5990 and 6578 ms). That looks like the TDR's own timing, so the work there never finishes, rather than slowly completing. Since bounded loops don't change it, something in those mesh passes that a loop limit can't bound (for example a group barrier in divergent flow, or a wave-size assumption in a mesh shader running at 32 lanes on NVIDIA) seems more likely. That is a guess. I have not checked those shaders.

AI-assisted (Claude Code); no game files attached.

**@⁠kleinerleuge-eng** on GitHub · 2026-11-23 23:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/46#issuecomment-7117546039) Tested on NVIDIA: RTX 5070 Ti, driver 621.01, Windows 11. Diag build of `15b0091` (this PR on `97c78d1`), `VICTORY_SHADER_LOOP_LIMIT=4096 VICTORY_D3D12_DRED=1`, no input. **Result: with a limit of 4096, loops are ruled out for this card's world hang, and world frames are not faster.** - The warning `VICTORY_SHADER_LOOP_LIMIT: translated loops stop sooner` is logged, so the limit was active. All shaders were translated again (new cache key). - World frames are about as slow as without the limit: 0.2–5.4 fps, 180–620 ms/frame most of the time, of which 80–240 ms is `preparing` (copies). - The world hang is unchanged. About 55 s after the menus there is one `slow host submission ms=4820 lists=32`, then `0x887A0006` (DEVICE_HUNG), and DRED reports no page fault. On `97c78d1` without this PR the hang came about 20 s after the menus. Here it came later, likely because every shader had to be translated again. - DRED stops at the **same place as in my earlier run without a limit** (#16): `a list stopped at command 138 of 155 (op 42), commands 107..155 between its barriers`. The listed commands are again only the mesh dispatches with `mesh 6b57e37fe499c6e7 / pixel 573d1857e903fab5`, `mesh 1921f28ef78e3a4b / pixel 80b3065a4477c8c4`, `mesh 0f73a9ae763e96e2 / pixel ce1481325c93bb70`. The earlier run stopped at command 148 of 175 in the same pattern. Side note: four of the six hung submissions on this card since `8c26061` took 4.82–4.83 s (4828, 4832, 4833, 4820 ms; the other two took 5990 and 6578 ms). That looks like the TDR's own timing, so the work there never finishes, rather than slowly completing. Since bounded loops don't change it, something in those mesh passes that a loop limit can't bound (for example a group barrier in divergent flow, or a wave-size assumption in a mesh shader running at 32 lanes on NVIDIA) seems more likely. That is a guess. I have not checked those shaders. AI-assisted (Claude Code); no game files attached.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-23 23:59 UTC · original

Tested 15b0091 stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.

  • main alone does not build on Linux (E0425 in victory-gpu), so the check uses #39 as the base; the merge is clean.
  • cargo test --workspace: 155 passed, 0 failed, 3 ignored — the loop-limit switch does not change any test result.
  • No game data used.

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

**@⁠DaviTostes** on GitHub · 2026-11-23 23:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/46#issuecomment-7117591103) Tested `15b0091` stacked on **#39** on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `main` alone does not build on Linux (E0425 in `victory-gpu`), so the check uses #39 as the base; the merge is clean. - `cargo test --workspace`: **155 passed, 0 failed, 3 ignored** — the loop-limit switch does not change any test result. - No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠HenriqueSBueno on GitHub · 2026-11-24 00:29 UTC · original · edited 2026-11-24 00:45 UTC

Tested with VICTORY_SHADER_LOOP_LIMIT=4096 on NVIDIA. Windows 11, RTX 3080 (driver 616.92), retail title.

  • Base: main at 97c78d1 + #45 + #89 + #54 + this PR, diagnostics build, with a fresh translation under the new limit.
  • Result: the world's frames still take 0.8–1.0 s. About 20 s into the world, one submission takes 11.6 s and Windows resets the driver: slow host submission ms=11564 lists=30, all compute pipelines, then device removed (0x887A0004).
  • Without this PR, with the default limit, it happens the same way in two runs: 11.6 s submissions of 11 and 32 compute lists.

So on this GPU, loops running to the limit don't explain the hang or the slow frames, at least not with a limit of 4096. I can run DRED (VICTORY_D3D12_DRED=1) on the next one if it helps narrow the submission down.

AI-assisted (Claude Code)

**@⁠HenriqueSBueno** on GitHub · 2026-11-24 00:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/46#issuecomment-7118116744) · edited 2026-11-24 00:45 UTC Tested with `VICTORY_SHADER_LOOP_LIMIT=4096` on NVIDIA. Windows 11, RTX 3080 (driver 616.92), retail title. - **Base:** `main` at 97c78d1 + #45 + #89 + #54 + this PR, diagnostics build, with a fresh translation under the new limit. - **Result:** the world's frames still take 0.8–1.0 s. About 20 s into the world, one submission takes 11.6 s and Windows resets the driver: `slow host submission ms=11564 lists=30`, all compute pipelines, then `device removed (0x887A0004)`. - **Without this PR**, with the default limit, it happens the same way in two runs: 11.6 s submissions of 11 and 32 compute lists. So on this GPU, loops running to the limit don't explain the hang or the slow frames, at least not with a limit of 4096. I can run DRED (`VICTORY_D3D12_DRED=1`) on the next one if it helps narrow the submission down. AI-assisted (Claude Code)
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!46
No description provided.