Skip to content

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

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
9hvn9yt2vk-netizen:shader-loop-limit
Nov 24, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
9hvn9yt2vk-netizen:shader-loop-limit

Conversation

@9hvn9yt2vk-netizen

Copy link
Copy Markdown
Contributor

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.
@kleinerleuge-eng

Copy link
Copy Markdown

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 (RTX 5070 Ti: menus at 30 fps, then TDR (DEVICE_HUNG); DRED output + 1M shader-visible heap cap on NVIDIA #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.

@DaviTostes

Copy link
Copy Markdown

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 Build: make workspace tests run on Linux #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).

@HenriqueSBueno

HenriqueSBueno commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

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)

@Marvisak
Marvisak merged commit 91e9bc9 into Marvisak:main Nov 24, 2026
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
shader: VICTORY_SHADER_LOOP_LIMIT to find what makes world frames slow
geiyiliyabumo added a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants