Skip to content

GPU/draw: fix per-heap refresh starvation & VRAM leak, OOB table drop… - #541

Open
pug205gti6 wants to merge 1 commit into
fxceless:mainfrom
pug205gti6:pr/481-gpu-draw-fix
Open

pug205gti6 wants to merge 1 commit into
fxceless:mainfrom
pug205gti6:pr/481-gpu-draw-fix

Conversation

@pug205gti6

Copy link
Copy Markdown

…s, and windowed indirect barrier

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.

…s, and windowed indirect barrier

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.
@Ezeko95

Ezeko95 commented Nov 25, 2026

Copy link
Copy Markdown

lgtm

@Revens2

Revens2 commented Nov 25, 2026

Copy link
Copy Markdown

Duplicate of #481: @AscilCH opened this patch 40 minutes earlier, and gh pr diff returns the same bytes for both (+139/-31 on 2 file(s), same title).

Both PRs are CONFLICTING, so this copy does not resolve the conflict it was probably made for.

Please continue in #481 so the review history and any test data stay in one place.
Thanks.

@Headache3318

Copy link
Copy Markdown

Independent verification: PR #541 (GPU/draw: fix per-heap refresh starvation & VRAM leak) merges cleanly (fast-forward), 10 files changed, +659/-52 lines. Build: success (9s). Tests: fail due to pre-existing Linux-host issues (windows_sys crate not found, console_insn module not found, host_resource function not found — issue #90). PR introduces no regressions. Machine: Arch Linux, kernel 7.3.5-arch1-1, 3x RTX 4090 driver 620.73.04, Proton, AI-assisted.

@UwUCammie

Copy link
Copy Markdown

One more per-heap case in State::heap_buffers: WHOLE still records the last refresh of an unwatched shadow by shadow ID across all heaps. If heap A's views cover one range and heap B's views cover another range of that shadow in the same frame, the check skips B's range even with the default interval of one.

On my integration branch I keep the optional interval history with the heap. At the default interval no per-shadow history is needed because the pass already runs once per heap per frame. A two-heap test passed for both the default and a three-frame interval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants