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

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

@⁠pug205gti6 on GitHub · 2026-11-25 02:02 UTC · original
pug205gti6:pr/481-gpu-draw-fix → main · +139 −31 · 2 files · 1 commits · open

…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.

**@⁠pug205gti6** on GitHub · 2026-11-25 02:02 UTC · [original](https://github.com/fxceless/victory-fork/pull/541) `pug205gti6:pr/481-gpu-draw-fix` → `main` · +139 −31 · 2 files · 1 commits · open …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.
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:45:52 +00:00
Author
Owner

@⁠Ezeko95 on GitHub · 2026-11-25 02:04 UTC · original

lgtm

**@⁠Ezeko95** on GitHub · 2026-11-25 02:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/541#issuecomment-7150290322) lgtm
Author
Owner

@⁠Revens2 on GitHub · 2026-11-25 07:37 UTC · original

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.

**@⁠Revens2** on GitHub · 2026-11-25 07:37 UTC · [original](https://github.com/fxceless/victory-fork/pull/541#issuecomment-7156075583) 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.
Author
Owner

@⁠Headache3318 on GitHub · 2026-11-25 08:50 UTC · original

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.

**@⁠Headache3318** on GitHub · 2026-11-25 08:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/541#issuecomment-7157542945) 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.
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-25 22:21 UTC · original

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.

**@⁠UwUCammie** on GitHub · 2026-11-25 22:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/541#issuecomment-7176264574) 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.
This pull request has changes conflicting with the target branch.
  • 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/541/head:github-bot/gh-541'
git switch 'github-bot/gh-541'

Merge

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