Shaders: evaluate non-active mask_number chains iteratively with cycle guard (#815) #2405
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2407"
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?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T13:05:16Z.
Summary
In
crates/victory-shader/src/emit/lower.rs,Lower::mask_dwordguarded the active-mask ballot path (self.boolean(m, at)) withself.balloting, while delegating non-active masks (!self.x.st.active.contains(&lo)) directly to recursiveLower::mask_numbercalls without tracking in-flight frames or bounding call-stack depth:0xC00000FD) on deep non-active scalar mask chains: Each recursivemask_dword -> mask_number -> word -> i32_of -> get -> mask_dwordstep consumes >1 KiB of host stack. On Windows's default 1 MiB thread stack, a chain of 1,000 non-active scalar mask operations (s_not_b32+ chaineds_xor_b32) deterministically overflows the stack (STATUS_STACK_OVERFLOW).self.ballotingguard on non-active masks: Any cyclic dependency reaching a non-active mask bypassedself.ballotinguntil hitting an active mask or exhausting the stack.Changes
mask_number/mask_number_walk/unballoted_mask/mask_number_inst/mask_number_one) in the exact same(dword_half, src_idx)order as before.self.ballotingbefore descending into its dependencies, returningErr("a lane mask whose lanes depend on its own value")on any cycle and cleaning up all pushed frames fromself.ballotingon both normal completion and error return.emit::lower::tests:deep_scalar_mask_chain_does_not_overflow_the_stack: lowers a 4,000-instruction non-actives_xor_b32chain on an explicit 1 MiB thread stack.non_active_mask_cycle_returns_error: verifies direct and nested cycle rejection andself.ballotingcleanup on error.Refs #815
Verification
cargo test -p victory-shader --lib --locked -- emit::lower::tests emit::tests::an_exec_high_write_does_not_overflow_the_stack(24 passed)cargo clippy -p victory-shader --all-targets --no-default-features --locked -- -D warningscargo clippy -p victory-shader --all-targets --all-features --locked -- -D warningscargo xtask policyImported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:25:22Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 146 passed, 0 failed, 2 ignored (+2 tests) (Windows-gated hardware execution tests not run here). Approving — non-active mask_number chains evaluated iteratively, no recursion blow-up.Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T13:34:35Z.
WARP verification
Tested: PR head
fcbf76bec21456a0fe25a714c09b0801d350c7b4, onorigin/main940d32f69b22265690a0b5a15d6ded572ba33baf(the PR is one commit on that base, so the merge was a no-op).Environment:
VICTORY_D3D12_WARP=1(software WARP), Windows 11 Pro 10.0.26200, rustc 1.98.1, DXC 1.9.0.5512 (dxcompiler), dxil.dll 1.8.2502.11 onPATH.cargo test -p victory-shader --lib --lockeddefect_test, all ignored on main too)cargo clippy -p victory-shader --all-targets --locked -- -D warningscargo xtask policyasset policy: 182 files ok, exit 0New tests
emit::lower::tests::deep_scalar_mask_chain_does_not_overflow_the_stack(4000-link chain on a 1 MiB-stack thread) andemit::lower::tests::non_active_mask_cycle_returns_errorboth ran and passed (not skipped).Diff review (
emit/lower.rsonly):mask_numbernow walks the chain iteratively with an explicit stack and aballotingset, so a cycle returns an error and a deep chain cannot overflow the stack. Entries are removed on every exit path. There are no process, network or filesystem actions.Limits: WARP only, no physical hardware GPU, no game files or dumps. The tests build their shaders from synthetic instruction words only.
AI use: Claude Code (Claude Sonnet 5.5)
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T14:18:25Z.
Review: APPROVED
Verified against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:mask_numberchains with an explicit cycle guard (#815) prevents stack overflows on deep scalar mask chains and cleanly rejects cycles.cargo test -p victory-shader emit::lower::tests: 23/23 passed on RTX 5090, 23/23 passed on WARP (includingdeep_scalar_mask_chain_does_not_overflow_the_stackandnon_active_mask_cycle_returns_error).cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:31:35Z.
Automated triage for the maintainers.
Needs work. This rewrites
Lower::mask_number(crates/victory-shader/src/emit/lower.rs) as an iterative walk with its ownballotingframes. Three concerns:mask_numberfollows the operands of the scalar instruction defining a value; a phi is not such an instruction and returnsELSEWHERE, so in SSA a chain of non-active masks cannot loop back on itself. Any loop passes through an active mask, whichmask_dwordalready guards withballoting.non_active_mask_cycle_returns_errorreaches the error only by puttinglo0intoballotingby hand, a state real lowering never produces.s_xor_b32. Please show a compiled program (or a translation run over the shader pack) that overflows; otherwise this is about 170 lines of churn in a hot lowering path.What would change the verdict: evidence of a real overflow, and dropping the cycle part. CI: passing.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T15:40:14Z.
Closing per triage feedback:
mask_numberstops at phis (ELSEWHERE), so non-active scalar chains cannot form a cycle in SSA without crossing an active mask thatmask_dwordalready guards, and we have no title shader reproducing a stack overflow here.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T16:54:45Z.
The rewrite preserves the original recursive algorithm as an explicit post-order stack:
(Value, next_dep)resume indices,ballotingset as the recursion-guard equivalent, deps bounded at(1 + wave64) * count ≤ 4. A cycle now returns a proper error instead of recursing forever, anddeep_scalar_mask_chain+non_active_mask_cyclepin both failure modes the recursion had. CI green. Correct approach for #815.Pull request closed