Shader: the loop limit switch works in every build #1263
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1263
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1263"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@pablogonz12 on GitHub · 2026-11-24 16:56 UTC · original
pablogonz12:up/loop→main· +38 −23 · 3 files · 4 commits · openWhat
loop_limit()now readsVICTORY_SHADER_LOOP_LIMITin every build, not only withdiagnostics: same parse rules (decimal or0xhex, at least 1, unreadable or 0 means the default), same default (2^20), and values abovei32::MAXclamp to it (only a cap: the emitted constant takes anyu32and the compare is unsigned).shader_cachealready 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.ffe310e(656 translate, 10 spirv-val, 0 pipeline) — the default path emits the same code.Not tested
Written with an AI assistant.
@adamdotpy on GitHub · 2026-11-24 17:00 UTC · original
Reviewed on Windows 11 / Rust 1.98.1,
d4ee6a5on currentmain(ffe310e, merges as it stands), isolated target dirs. Verified:cargo test -p victory-shader --lib120 passed / 1 ignored including the extendedthe_loop_limit_switch_parses_or_falls_back;cargo test -p victory-gpu --lib shader_cache2 passed; clippy clean with and without--all-features; release build ofvictoryfine.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 assertsloop_limit() == 8, and ran it withVICTORY_SHADER_LOOP_LIMIT=8 cargo test -p victory-shader --release --lib probe_env— it passes. Onmainthe same run returns2^20, becauseloop_limit()was gated oncfg!(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::MAXis correct, and I checked why.count_iterationemitsself.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 toi32::MAXkeeps the counter from wrapping first. The new parse tests cover0Xhex, tabs/newlines, and the overflow cases (4294967296,0x100000000fall 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()invictory-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
nis cut short, which is the honest caveat for a knob that changes translation output. No code change needed.@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. Theparse_loop_limitdoc comment now gives the clamp's real reason (a cap:Module::i32takes au32and the compare inLower::count_iterationis unsigned), and the description matches. Nothing else is left on the code side. CIcheckpasses ateb9df73.The open question is unchanged.
loop_limit()(crates/victory-shader/src/emit/mod.rs) now readsVICTORY_SHADER_LOOP_LIMITin release builds, but commit15b0091edeliberately 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
@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 emittedi32constant representable.cargo test -p victory-shader --lib118 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 11:27 UTC · original
Done: the doc comment now says the clamp is only a cap (
Module::i32takes au32and 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.