Shader: the loop limit switch works in every build #1263

Open
github-bot wants to merge 4 commits from github-bot/gh-1263 into main AGit
Owner

@⁠pablogonz12 on GitHub · 2026-11-24 16:56 UTC · original
pablogonz12:up/loop → main · +38 −23 · 3 files · 4 commits · open

What

loop_limit() now reads VICTORY_SHADER_LOOP_LIMIT in every build, not only with diagnostics: same parse rules (decimal or 0x hex, at least 1, unreadable or 0 means the default), same default (2^20), and values above i32::MAX clamp to it (only a cap: the emitted constant takes any u32 and the compare is unsigned). shader_cache already hashes the limit into its key, so translations made with different limits never mix, and the warning says so.

No behaviour change by default.

Why

The limit is the switch to test whether spin-wait loops are what makes a frame slow (the ~6x GPU-time report from another fork), and a release build is the build one runs the game with. #452 changes what the default budget means; this only makes the override reachable, so it should stay useful whichever default lands.

Worth documenting: 32 is unsafe (a real loop of 33 iterations, or a long decal pass, gets cut and the picture breaks in ways that look like a title bug), 256 is cautious, 1024 is the value the report used. That is the advice I would put next to the variable.

How tested

  • cargo test -p victory-shader --lib (Linux): 96 passed, 0 failed, 1 ignored, including the new parse tests (decimal, hex, 0, junk, over the clamp).
  • cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings, with and without --all-features: clean.
  • Offline four-stage check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped): unchanged from main ffe310e (656 translate, 10 spirv-val, 0 pipeline) — the default path emits the same code.

Not tested

  • Any in-game run with a non-default limit; the numbers for 256/1024 come from other testers' reports, not from me.

Written with an AI assistant.

**@⁠pablogonz12** on GitHub · 2026-11-24 16:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/1263) `pablogonz12:up/loop` → `main` · +38 −23 · 3 files · 4 commits · open ## What `loop_limit()` now reads `VICTORY_SHADER_LOOP_LIMIT` in every build, not only with `diagnostics`: same parse rules (decimal or `0x` hex, at least 1, unreadable or 0 means the default), same default (`2^20`), and values above `i32::MAX` clamp to it (only a cap: the emitted constant takes any `u32` and the compare is unsigned). `shader_cache` already hashes the limit into its key, so translations made with different limits never mix, and the warning says so. No behaviour change by default. ## Why The limit is the switch to test whether spin-wait loops are what makes a frame slow (the ~6x GPU-time report from another fork), and a release build is the build one runs the game with. #452 changes what the default budget means; this only makes the override reachable, so it should stay useful whichever default lands. Worth documenting: 32 is unsafe (a real loop of 33 iterations, or a long decal pass, gets cut and the picture breaks in ways that look like a title bug), 256 is cautious, 1024 is the value the report used. That is the advice I would put next to the variable. ## How tested - `cargo test -p victory-shader --lib` (Linux): 96 passed, 0 failed, 1 ignored, including the new parse tests (decimal, hex, 0, junk, over the clamp). - `cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings`, with and without `--all-features`: clean. - Offline four-stage check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped): unchanged from main ffe310e (656 translate, 10 spirv-val, 0 pipeline) — the default path emits the same code. ## Not tested - Any in-game run with a non-default limit; the numbers for 256/1024 come from other testers' reports, not from me. Written with an AI assistant.
VICTORY_SHADER_LOOP_LIMIT was read only with the diagnostics feature, so a
release build could not run the experiment another VIctory fork reports as a
~6x GPU time win. It is now honoured in every build, with the default (2^20)
unchanged, values from 2^31 clamped to i32::MAX (the emitted counter is an i32
compared unsigned, so a bigger constant would act as no limit), and the same
parse rules. The shader cache already hashes the limit into its key, so
translations made with different limits never mix; the warning says so.

The 256/1024 advice and the risk of 32 are in xcl-bin/notes/loop.md.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:25:33 +00:00
Author
Owner

@⁠adamdotpy on GitHub · 2026-11-24 17:00 UTC · original

Reviewed on Windows 11 / Rust 1.98.1, d4ee6a5 on current main (ffe310e, merges as it stands), isolated target dirs. Verified: cargo test -p victory-shader --lib 120 passed / 1 ignored including the extended the_loop_limit_switch_parses_or_falls_back; cargo test -p victory-gpu --lib shader_cache 2 passed; clippy clean with and without --all-features; release build of victory fine.

The headline claim is proven in a release build, not just by reading the diff. I appended a throwaway probe to emit/mod.rs (reverted after, tree clean) that asserts loop_limit() == 8, and ran it with VICTORY_SHADER_LOOP_LIMIT=8 cargo test -p victory-shader --release --lib probe_env — it passes. On main the same run returns 2^20, because loop_limit() was gated on cfg!(feature = "diagnostics"). Removing that gate is the whole fix, and it is now demonstrated end to end in the build type that previously ignored the switch.

The clamp to i32::MAX is correct, and I checked why. count_iteration emits self.s.m.i32(super::loop_limit()) and compares the i32 counter against it (lower.rs:6840), so a limit at or above 2^31 would wrap the counter before the comparison ever fires — two billion iterations, the hang the limit exists to prevent. Clamping to i32::MAX keeps the counter from wrapping first. The new parse tests cover 0X hex, tabs/newlines, and the overflow cases (4294967296, 0x100000000 fall back to the default rather than wrapping).

Interaction with our #1094 branch, so it is on record: this PR edits the doc comment of build() in victory-gpu/src/shader_cache.rs, the same file our refusal-cache branch changes. The edit is comment-only and our change is the entry format, so the merge is trivial, but the two branches will touch the same lines — worth merging one first. The substance agrees: the loop limit is part of the translation, so it belongs in the cache key, and now that the switch works in every build, a release build that changes it gets its own cache entries rather than serving translations made with the default — which is exactly the correctness property #1094 depends on.

One doc nit. The README row now says "32 is a diagnostic value, 256-1024 a safer probe" — useful, and it also warns that a real loop longer than n is cut short, which is the honest caveat for a knob that changes translation output. No code change needed.

**@⁠adamdotpy** on GitHub · 2026-11-24 17:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1263#issuecomment-7138539730) Reviewed on Windows 11 / Rust 1.98.1, `d4ee6a5` on current `main` (`ffe310e`, merges as it stands), isolated target dirs. Verified: `cargo test -p victory-shader --lib` 120 passed / 1 ignored including the extended `the_loop_limit_switch_parses_or_falls_back`; `cargo test -p victory-gpu --lib shader_cache` 2 passed; clippy clean with and without `--all-features`; release build of `victory` fine. **The headline claim is proven in a release build, not just by reading the diff.** I appended a throwaway probe to `emit/mod.rs` (reverted after, tree clean) that asserts `loop_limit() == 8`, and ran it with `VICTORY_SHADER_LOOP_LIMIT=8 cargo test -p victory-shader --release --lib probe_env` — it passes. On `main` the same run returns `2^20`, because `loop_limit()` was gated on `cfg!(feature = "diagnostics")`. Removing that gate is the whole fix, and it is now demonstrated end to end in the build type that previously ignored the switch. **The clamp to `i32::MAX` is correct, and I checked why.** `count_iteration` emits `self.s.m.i32(super::loop_limit())` and compares the i32 counter against it (`lower.rs:6840`), so a limit at or above 2^31 would wrap the counter before the comparison ever fires — two billion iterations, the hang the limit exists to prevent. Clamping to `i32::MAX` keeps the counter from wrapping first. The new parse tests cover `0X` hex, tabs/newlines, and the overflow cases (`4294967296`, `0x100000000` fall back to the default rather than wrapping). **Interaction with our #1094 branch, so it is on record:** this PR edits the doc comment of `build()` in `victory-gpu/src/shader_cache.rs`, the same file our refusal-cache branch changes. The edit is comment-only and our change is the entry format, so the merge is trivial, but the two branches will touch the same lines — worth merging one first. The substance agrees: the loop limit is part of the translation, so it belongs in the cache key, and now that the switch works in every build, a release build that changes it gets its own cache entries rather than serving translations made with the default — which is exactly the correctness property #1094 depends on. **One doc nit.** The README row now says "32 is a diagnostic value, 256-1024 a safer probe" — useful, and it also warns that a real loop longer than `n` is cut short, which is the honest caveat for a knob that changes translation output. No code change needed.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:27 UTC · original · edited 2026-11-25 12:23 UTC

Automated triage for the maintainers.

Needs work: needs the maintainer's decision. Thanks for eb9df73. The parse_loop_limit doc comment now gives the clamp's real reason (a cap: Module::i32 takes a u32 and the compare in Lower::count_iteration is unsigned), and the description matches. Nothing else is left on the code side. CI check passes at eb9df73.

The open question is unchanged. loop_limit() (crates/victory-shader/src/emit/mod.rs) now reads VICTORY_SHADER_LOOP_LIMIT in release builds, but commit 15b0091e deliberately limited it to diagnostics builds. Whether release builds should get the switch is the maintainer's call. The shader cache key already covers the limit (shader_cache::build). If the maintainer agrees, this is ready. #452 and #1819 touch the same limit.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1263#issuecomment-7149566439) · edited 2026-11-25 12:23 UTC <!-- victory-triage v1 head=eb9df73d11db9141d42afa781745bed2e6a05571 verdict=needs-work at=2026-11-25T12:43:00Z --> Automated triage for the maintainers. **Needs work: needs the maintainer's decision.** Thanks for `eb9df73`. The `parse_loop_limit` doc comment now gives the clamp's real reason (a cap: `Module::i32` takes a `u32` and the compare in `Lower::count_iteration` is unsigned), and the description matches. Nothing else is left on the code side. CI `check` passes at `eb9df73`. The open question is unchanged. `loop_limit()` (`crates/victory-shader/src/emit/mod.rs`) now reads `VICTORY_SHADER_LOOP_LIMIT` in release builds, but commit 15b0091e deliberately limited it to diagnostics builds. Whether release builds should get the switch is the maintainer's call. The shader cache key already covers the limit (`shader_cache::build`). If the maintainer agrees, this is ready. #452 and #1819 touch the same limit. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-25 02:12 UTC · original

Fixed in b7005f41: the doc comment and the test comment now say the compare is unsigned (IULT/IUGE), so 2^31 and up is a large count rather than a negative one, and the clamp only keeps the emitted i32 constant representable. cargo test -p victory-shader --lib 118 pass/1 ignored; xwin clippy workspace clean. Whether the release build reads the switch stays as this PR has it — that one is your call.

**@⁠pablogonz12** on GitHub · 2026-11-25 02:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1263#issuecomment-7150434996) Fixed in b7005f41: the doc comment and the test comment now say the compare is unsigned (`IULT`/`IUGE`), so 2^31 and up is a large count rather than a negative one, and the clamp only keeps the emitted `i32` constant representable. `cargo test -p victory-shader --lib` 118 pass/1 ignored; xwin clippy workspace clean. Whether the release build reads the switch stays as this PR has it — that one is your call.
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-25 11:27 UTC · original

Done: the doc comment now says the clamp is only a cap (Module::i32 takes a u32 and the compare is unsigned), comment-only commit, and the same sentence in the description is fixed. Whether release builds read the switch remains the maintainer's call.

AI-assisted.

**@⁠pablogonz12** on GitHub · 2026-11-25 11:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1263#issuecomment-7161062325) Done: the doc comment now says the clamp is only a cap (`Module::i32` takes a `u32` and the compare is unsigned), comment-only commit, and the same sentence in the description is fixed. Whether release builds read the switch remains the maintainer's call. AI-assisted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1263/head:github-bot/gh-1263'
git switch 'github-bot/gh-1263'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1263'
git switch 'github-bot/gh-1263'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1263'
git switch 'github-bot/gh-1263'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1263'
git switch 'main'
git merge --squash 'github-bot/gh-1263'
git switch 'main'
git merge --ff-only 'github-bot/gh-1263'
git switch 'main'
git merge 'github-bot/gh-1263'
git push origin 'main'
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!1263
No description provided.