GPU/draw: fix per-heap refresh starvation & VRAM leak, OOB table drops, and windowed indirect barrier #481

Open
github-bot wants to merge 1 commit from github-bot/gh-481 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 01:23 UTC · original
AscilCH:fix/gpu-draw-heap-buffers-tables-and-indirect-barrier → main · +139 −31 · 2 files · 1 commits · open

Problem

Three defects in crates/victory-gpu/src/draw.rs (and crates/victory-gpu/src/descriptor/host.rs):

  1. Dynamic-resource heap starvation & Arc<Shadow> VRAM leak (State::heap_buffers):
    • A single process-global static FRAME: AtomicU64 gated the entire mirror/refresh/texture pass across all view heaps, starving any second view heap bound in the same frame. Similarly, list.first_use(ONCE) used a single constant key per list rather than per host heap.
    • static RANGES was keyed by raw HostHeap pointer and never removed entries when a HostHeap was dropped, permanently leaking Arc<Shadow> GPU buffers and risking stale range aliasing if a new HostHeap reused a freed address.
  2. Un-dropped out-of-bounds descriptor tables (State::tables):
    • Tables reaching past host.count() were added to fresh because the host heap has no direct slots for them. If relocation failed (n > DYNAMIC, misaligned table, or last outside the heap), tables() executed continue without pushing (slot, u32::MAX) to made, so bind() did not drop the draw and instead handed the un-relocated OOB title offset to the GPU.
  3. Mismatched INDIRECT_ARGUMENT -> COMMON barrier on failed windowed execute_indirect:
    • When VICTORY_INDIRECT_WINDOW=1 hit an existing window (hit.is_some()), bounded was already in COMMON (left by the prior draw's indirect::done). If prepare failed (!ran), ExecuteIndirect never ran (no implicit promotion), yet line 2438 unconditionally called indirect::done(list, &bounded), emitting an invalid INDIRECT_ARGUMENT -> COMMON barrier on a COMMON buffer.

Fix

  • Add a unique monotonic HostHeap::id() and impl Drop for HostHeap calling draw::forget_heap(self.id).
  • Key HEAP_RANGES by host.id() storing per-heap last_frame, passes, and ranges, and key list.first_use by host heap pointer.
  • Track oob table slots in State::tables and push (slot, u32::MAX) when relocation of an out-of-bounds table fails.
  • Only call indirect::done(list, &bounded) on !ran when !hit_window.
  • Add synthetic unit test heap_ranges_tracks_frames_per_heap_and_cleans_up_on_forget.

Verification

  • cargo test -p victory-gpu --locked draw::tests -- --test-threads=1: 1 passed, 0 failed
  • cargo test -p victory-gpu --locked descriptor -- --test-threads=1: 15 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 01:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/481) `AscilCH:fix/gpu-draw-heap-buffers-tables-and-indirect-barrier` → `main` · +139 −31 · 2 files · 1 commits · open ## Problem Three defects in `crates/victory-gpu/src/draw.rs` (and `crates/victory-gpu/src/descriptor/host.rs`): 1. **Dynamic-resource heap starvation & `Arc<Shadow>` VRAM leak (`State::heap_buffers`)**: - A single process-global `static FRAME: AtomicU64` gated the entire mirror/refresh/texture pass across all view heaps, starving any second view heap bound in the same frame. Similarly, `list.first_use(ONCE)` used a single constant key per list rather than per host heap. - `static RANGES` was keyed by raw `HostHeap` pointer and never removed entries when a `HostHeap` was dropped, permanently leaking `Arc<Shadow>` GPU buffers and risking stale range aliasing if a new `HostHeap` reused a freed address. 2. **Un-dropped out-of-bounds descriptor tables (`State::tables`)**: - Tables reaching past `host.count()` were added to `fresh` because the host heap has no direct slots for them. If relocation failed (`n > DYNAMIC`, misaligned table, or `last` outside the heap), `tables()` executed `continue` without pushing `(slot, u32::MAX)` to `made`, so `bind()` did not drop the draw and instead handed the un-relocated OOB title offset to the GPU. 3. **Mismatched `INDIRECT_ARGUMENT -> COMMON` barrier on failed windowed `execute_indirect`**: - When `VICTORY_INDIRECT_WINDOW=1` hit an existing window (`hit.is_some()`), `bounded` was already in `COMMON` (left by the prior draw's `indirect::done`). If `prepare` failed (`!ran`), `ExecuteIndirect` never ran (no implicit promotion), yet line 2438 unconditionally called `indirect::done(list, &bounded)`, emitting an invalid `INDIRECT_ARGUMENT -> COMMON` barrier on a `COMMON` buffer. ## Fix - Add a unique monotonic `HostHeap::id()` and `impl Drop for HostHeap` calling `draw::forget_heap(self.id)`. - Key `HEAP_RANGES` by `host.id()` storing per-heap `last_frame`, `passes`, and `ranges`, and key `list.first_use` by host heap pointer. - Track `oob` table slots in `State::tables` and push `(slot, u32::MAX)` when relocation of an out-of-bounds table fails. - Only call `indirect::done(list, &bounded)` on `!ran` when `!hit_window`. - Add synthetic unit test `heap_ranges_tracks_frames_per_heap_and_cleans_up_on_forget`. ## Verification - `cargo test -p victory-gpu --locked draw::tests -- --test-threads=1`: 1 passed, 0 failed - `cargo test -p victory-gpu --locked descriptor -- --test-threads=1`: 15 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic unit tests only, no game data.)*
Fix three defects in `crates/victory-gpu/src/draw.rs` and `crates/victory-gpu/src/descriptor/host.rs`:
1. `State::heap_buffers` & `HostHeap`: replace the process-global `static FRAME` and raw-pointer-keyed `static RANGES` (which starved a second view heap bound in the same frame and leaked `Arc<Shadow>` buffers forever without cleanup on heap destruction) with per-heap `last_frame`/`passes`/`ranges` keyed by a unique monotonic `HostHeap::id()`, cleaned up in `impl Drop for HostHeap` via `draw::forget_heap(self.id)`. Key `list.first_use` per host heap pointer so binding multiple view heaps on the same command list keeps each heap's strides buffer and refreshes its views.
2. `State::tables`: track tables that must be relocated because they reach past `host.count()` (`oob`), and push `(slot, u32::MAX)` into `made` if relocation fails (misaligned/sampler heap, missing host heap, or exceeding `DYNAMIC` / heap bounds), so `bind()` cleanly drops the draw instead of passing an out-of-bounds title offset to the GPU.
3. `State::execute_indirect`: record `hit_window = hit.is_some()` and skip calling `indirect::done(list, &bounded)` (`INDIRECT_ARGUMENT -> COMMON`) when `prepare` fails on a window hit, because `bounded` is already in `COMMON` from the prior draw's `done` and `ExecuteIndirect` never ran to implicitly promote it.

Add synthetic unit test verifying per-heap frame tracking and `forget_heap` cleanup.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:44:21 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/draw.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-481'
git switch 'github-bot/gh-481'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-481'
git switch 'github-bot/gh-481'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-481'
git switch 'main'
git merge --squash 'github-bot/gh-481'
git switch 'main'
git merge --ff-only 'github-bot/gh-481'
git switch 'main'
git merge 'github-bot/gh-481'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.