Skip to content

perf(shader): leave translated loops after 2^14 passes, not 2^20 - #123

Merged
pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
GDemay:shader/loop-limit-2-14
Nov 25, 2026
Merged

pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
GDemay:shader/loop-limit-2-14

Conversation

@GDemay

@GDemay GDemay commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

A translated loop whose bound is not mirrored yet runs to LOOP_LIMIT in every lane that reaches it, and a dispatch lasts as long as its slowest lane. This lowers the limit from 2^20 to 2^14: one constant, the same change as upstream Marvisak/VIctory#1819 (open there).

Why it should cut on the GPU in the world:

Trade-off: a genuine loop of more than 16,384 passes per lane and entry is now cut short (the existing shortcut:). VICTORY_SHADER_LOOP_LIMIT still overrides the limit in diagnostics builds.

To measure without this branch: current main, diagnostics build, VICTORY_SHADER_LOOP_LIMIT=16384; compare on the GPU and the picture. The shader cache keys on the limit, so the first run translates the shaders again.

Tested: cargo test -p victory-shader native, 151 passed. Windows-target clippy -D warnings is clean with and without all features; no new rustfmt diffs; cargo xtask policy ok. My Wine has no D3D12 device, so the GPU shader tests run only in this PR's CI. Not run in the game.

🤖 Generated with 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>
@pragyaangaur
pragyaangaur merged commit 64a9f49 into pragyaangaur:main Nov 25, 2026
1 check passed
@pragyaangaur

Copy link
Copy Markdown
Owner

Thank you, GDemay. I ran the victory-shader and victory-gpu suites under CrossOver Wine with D3DMetal on an M4 with this limit, since CI has no GPU: 254 and 174 passed, nothing failing. Merged. jjlange and LakshanSivakumar, this one targets the 'on the GPU' share directly; the first run retranslates shaders because the cache keys on the limit, so please compare the second run.

@pragyaangaur pragyaangaur added area:shader Shader translator enhancement New feature or request labels Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:shader Shader translator enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants