Shaders: cap BDD memo table and bail out early on overflow #288
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/288"
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 Yaekai on 2026-11-24T02:03:34Z.
Problem
During live GTA VI world loading (with concurrent background pipeline compilation in
pipeline::make),victory_shader::structure::Bools::memo(HashMap<(Bool, Bool, Bool), Bool>) can grow unbounded and trigger a 35.6 MB (2^21buckets)HashMap::reserve_rehashallocation failure:Two issues cause this in
crates/victory-shader/src/structure.rs:Bools::nodesis capped atMAX_NODES, butBools::memohad no cap and can grow quadratically/cubically in the number of nodes.mk()setsself.overflow = true,ite()andforget()did not bail out early and continued recursing and inserting intoself.memo.Changes
MAX_MEMO = 1 << 18(~4.5 MB max) and clearself.memowhen it reachesMAX_MEMO(it is purely a cache).Bool::FALSEimmediately at the top ofBools::ite()andBools::forget()whenself.overflowis set, and skipself.memo.inserton overflow.Verification
cargo test -p victory-shader— 71/71 passed.rustfmt --edition 2024 --check crates/victory-shader/src/structure.rs— clean.victory translateonshaders.rpf(26,084 programs): all 26,084 programs structure identically with 0 regressions.Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:17:08Z.
Tested PR #288 at head
176c766ab1814ab4be0602709f2f80abb466fd84(state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at176c766ab1814ab4be0602709f2f80abb466fd84.cargo test --locked -p victory-shader structure— passed (ok. 5 passed; 0 failed; 0 ignored; 0 measured; 64 filtered out; finished in 0.00s ); cases: structure::tests::divergent_if_becomes_a_lane_branch, structure::tests::exec_narrowed_without_a_branch_leaves_a_guard, structure::tests::divergent_loop_exits_per_lane, structure::tests::scalar_branches_stay_uniform, and 1 more.Behavior covered: Exercises shader control-flow structure analysis after bounding the BDD ite memo table; no dedicated new test was added in this PR.
Code: crates/victory-shader/src/structure.rs
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T07:26:59Z.
Review: APPROVED
Tested
176c766on Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (264 passed, 0 failed).victory translate <title exe> --validate --pipelinesgives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines.Bool::FALSEfromite/forgetonceoverflowis set is safe. Both consumers checkself.b.overflowand returnTOO_LARGE(structure.rs:575and:1017), so a result computed after overflow is never used, the same asmk's existingFALSEreturn.memoatMAX_MEMOis sound because it's only a cache:uniqueandnodeshold the canonical BDD, so a cleared memo costs recomputation, never correctness. The 2^18 cap bounds the table at a few MB.memoafter the node cap was hit, which is likely where most of the growth came from.No issues found. I can't reproduce the 35 MB allocation failure without a game package.
AI-assisted (Claude Code).