GPU/memory+descriptor: evict dropped HostHeaps from MEMORY.heaps on Heap::drop #589

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

@⁠AscilCH on GitHub · 2026-11-25 02:35 UTC · original
AscilCH:fix/gpu-memory-evict-dropped-host-heaps → main · +67 −4 · 2 files · 1 commits · open

Problem

In crates/victory-gpu/src/memory.rs, MEMORY.heaps caches (base, made) descriptor-run state keyed by raw HostHeap pointer (std::ptr::from_ref(heap) as usize), where HostHeap is stored inline inside Heap::host: OnceLock<Option<HostHeap>>.

When a title releases a shader-visible view Heap, Heap::drop() (crates/victory-gpu/src/descriptor.rs) removed it from SHADER_HEAPS but never removed its HostHeap address from MEMORY.heaps. If a newly created Heap reused the freed address:

  • MEMORY.heaps.get(&key) hit the stale (base, made) entry, skipping heap.dynamic(COPIES + 1) and leaving the null UAV and copies 0..made unwritten on the new heap.
  • If the new heap had a different count, base could land inside the title's own descriptor slots or past the end of the host descriptor heap.

Fix

  • Add memory::forget_heap(heap: &HostHeap) in crates/victory-gpu/src/memory.rs and call it from Heap::drop() in crates/victory-gpu/src/descriptor.rs after dropping the SHADER_HEAPS lock.
  • Add synthetic D3D12 unit test dropping_a_view_heap_evicts_its_memory_heaps_entry.

Verification

  • cargo test -p victory-gpu --locked memory::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 --all-features --locked -- -D warnings: clean (default-features build on c96b4f2 has only the pre-existing dead_code warning on placed_filler_twins, tracked in #491)

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

**@⁠AscilCH** on GitHub · 2026-11-25 02:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/589) `AscilCH:fix/gpu-memory-evict-dropped-host-heaps` → `main` · +67 −4 · 2 files · 1 commits · open ## Problem In `crates/victory-gpu/src/memory.rs`, `MEMORY.heaps` caches `(base, made)` descriptor-run state keyed by raw `HostHeap` pointer (`std::ptr::from_ref(heap) as usize`), where `HostHeap` is stored inline inside `Heap::host: OnceLock<Option<HostHeap>>`. When a title releases a shader-visible view `Heap`, `Heap::drop()` (`crates/victory-gpu/src/descriptor.rs`) removed it from `SHADER_HEAPS` but never removed its `HostHeap` address from `MEMORY.heaps`. If a newly created `Heap` reused the freed address: - `MEMORY.heaps.get(&key)` hit the stale `(base, made)` entry, skipping `heap.dynamic(COPIES + 1)` and leaving the null UAV and copies `0..made` unwritten on the new heap. - If the new heap had a different `count`, `base` could land inside the title's own descriptor slots or past the end of the host descriptor heap. ## Fix - Add `memory::forget_heap(heap: &HostHeap)` in `crates/victory-gpu/src/memory.rs` and call it from `Heap::drop()` in `crates/victory-gpu/src/descriptor.rs` after dropping the `SHADER_HEAPS` lock. - Add synthetic D3D12 unit test `dropping_a_view_heap_evicts_its_memory_heaps_entry`. ## Verification - `cargo test -p victory-gpu --locked memory::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 --all-features --locked -- -D warnings`: clean (default-features build on `c96b4f2` has only the pre-existing `dead_code` warning on `placed_filler_twins`, tracked in #491) *(AI-assisted; synthetic unit tests only, no game data.)*
- Add `memory::forget_heap(&HostHeap)` and invoke it from `Heap::drop()` in
  `descriptor.rs` (after releasing `SHADER_HEAPS`) whenever the dropped title
  view heap materialized a `HostHeap`.
- Prevents a newly allocated `Heap` reusing the freed `Box<Heap>` address from
  hitting a stale `(base, made)` entry in `MEMORY.heaps`, which skipped
  reserving dynamic slots and could corrupt title descriptors or write OOB
  when the new heap's size differed.
- Add synthetic D3D12 unit test `dropping_a_view_heap_evicts_its_memory_heaps_entry`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:46:57 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor.rs
  • crates/victory-gpu/src/memory.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/589/head:github-bot/gh-589'
git switch 'github-bot/gh-589'

Merge

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