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

Open
AscilCH wants to merge 1 commit from upstream-pr/589 into main
AscilCH commented 2026-11-25 02:35:43 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T02:35:43Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6595882155 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/589). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T02:35:43Z. --- ## 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.)*
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/589:upstream-pr/589'
git switch 'upstream-pr/589'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/589'
git switch 'upstream-pr/589'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/589'
git switch 'upstream-pr/589'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/589'
git switch 'main'
git merge --squash 'upstream-pr/589'
git switch 'main'
git merge --ff-only 'upstream-pr/589'
git switch 'main'
git merge 'upstream-pr/589'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!589
No description provided.