Skip to content

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

Open
AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-memory-evict-dropped-host-heaps
Open

AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-memory-evict-dropped-host-heaps

Conversation

@AscilCH

@AscilCH AscilCH commented Nov 25, 2026

Copy link
Copy Markdown

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 GPU: keep clippy green without the diagnostics feature #491)

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

…eap::drop

- 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`.
triippywhale added a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
- memory.rs (fxceless#589's test): ready() here takes the builder flag too.
- draw.rs (310c6eb): sort_unstable_by_key with Reverse, as clippy asks.
- indirect.rs (310c6eb's bare_command_cost bench): the stored
  depth_written handle is never read; allowed with a reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBA8CxPD68KngjiMeJb
PiloteCode added a commit to PiloteCode/victory-fork that referenced this pull request Nov 25, 2026
…celess#24/fxceless#104), null CBVs (fxceless#304), tables at list cuts (fxceless#742), heap entries (fxceless#589), barriers (fxceless#787), depth-stencil UAV barriers (fxceless#214), windows ending at recorded writes (fxceless#663), sRGB views (fxceless#644), wide accesses across pages (fxceless#846), view-guard costs (fxceless#812/fxceless#853), the fill latch (fxceless#860), pipeline waits (fxceless#709), robustness; opt-in fxceless#868/fxceless#845
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.

1 participant