Shaders: cap BDD memo table and bail out early on overflow #288

Manually merged
github merged 1 commit from gh-pr/288/head into gh-pr/288/base 2026-11-26 03:58:05 +00:00
Owner

@⁠Yaekai on GitHub · 2026-11-24 02:03 UTC · original
Yaekai:fix/shader-bdd-memo-cap → main · +15 −1 · 1 files · 1 commits · merged 2026-11-25 00:19 UTC

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^21 buckets) HashMap::reserve_rehash allocation failure:

memory allocation of 35651600 bytes failed
  hashbrown::raw::RawTable::reserve_rehash<((Bool, Bool, Bool), Bool), ...>
  victory_gpu::pipeline::make::Pending::make

Two issues cause this in crates/victory-shader/src/structure.rs:

  1. Bools::nodes is capped at MAX_NODES, but Bools::memo had no cap and can grow quadratically/cubically in the number of nodes.
  2. Once mk() sets self.overflow = true, ite() and forget() did not bail out early and continued recursing and inserting into self.memo.

Changes

  • Add MAX_MEMO = 1 << 18 (~4.5 MB max) and clear self.memo when it reaches MAX_MEMO (it is purely a cache).
  • Return Bool::FALSE immediately at the top of Bools::ite() and Bools::forget() when self.overflow is set, and skip self.memo.insert on overflow.

Verification

  • cargo test -p victory-shader — 71/71 passed.
  • rustfmt --edition 2024 --check crates/victory-shader/src/structure.rs — clean.
  • victory translate on shaders.rpf (26,084 programs): all 26,084 programs structure identically with 0 regressions.
**@⁠Yaekai** on GitHub · 2026-11-24 02:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/288) `Yaekai:fix/shader-bdd-memo-cap` → `main` · +15 −1 · 1 files · 1 commits · merged 2026-11-25 00:19 UTC ### 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^21` buckets) `HashMap::reserve_rehash` allocation failure: ```text memory allocation of 35651600 bytes failed hashbrown::raw::RawTable::reserve_rehash<((Bool, Bool, Bool), Bool), ...> victory_gpu::pipeline::make::Pending::make ``` Two issues cause this in `crates/victory-shader/src/structure.rs`: 1. `Bools::nodes` is capped at `MAX_NODES`, but `Bools::memo` had no cap and can grow quadratically/cubically in the number of nodes. 2. Once `mk()` sets `self.overflow = true`, `ite()` and `forget()` did not bail out early and continued recursing and inserting into `self.memo`. ### Changes - Add `MAX_MEMO = 1 << 18` (~4.5 MB max) and clear `self.memo` when it reaches `MAX_MEMO` (it is purely a cache). - Return `Bool::FALSE` immediately at the top of `Bools::ite()` and `Bools::forget()` when `self.overflow` is set, and skip `self.memo.insert` on overflow. ### Verification - `cargo test -p victory-shader` — 71/71 passed. - `rustfmt --edition 2024 --check crates/victory-shader/src/structure.rs` — clean. - `victory translate` on `shaders.rpf` (26,084 programs): all 26,084 programs structure identically with 0 regressions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:03 +00:00
github manually merged commit f177aaeade into gh-pr/288/base 2026-11-26 03:58:05 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:17 UTC · original

Tested PR #288 at head 176c766ab1814ab4be0602709f2f80abb466fd84 (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at 176c766ab1814ab4be0602709f2f80abb466fd84.

  • 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

**@⁠jeremygold02** on GitHub · 2026-11-24 04:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/288#issuecomment-7121878201) Tested PR #288 at head `176c766ab1814ab4be0602709f2f80abb466fd84` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `176c766ab1814ab4be0602709f2f80abb466fd84`. - `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](https://github.com/Marvisak/VIctory/blob/176c766ab1814ab4be0602709f2f80abb466fd84/crates/victory-shader/src/structure.rs)
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!288
No description provided.