GPU: dynamic descriptor slots go back only to the heap that took them #1321

Merged
CwWwWwW merged 1 commit from upstream-pr/1324 into main 2026-11-26 18:05:17 +00:00
CwWwWwW commented 2026-11-26 15:23:30 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-26T15:23:30Z.


Problem

State::dynamic (crates/victory-gpu/src/draw.rs) keeps the title descriptor heap of each range of dynamic slots by its address, and descriptor::release_dynamic frees the range in whatever host heap is registered at that address when the list is reset.

A command list may outlive the title heap it recorded slots from: D3D12 keeps an object alive while a list names it, so the title can release a shader-visible heap before the lists that use it are reset. If the allocator later places another Box<Heap> at the same address and that heap is registered in SHADER_HEAPS, the old list's reset finds it by address and frees its dynamic slots - slots another live list has taken. Two live lists then hold the same dynamic slots; one rewrites the other's descriptors (wrong bindings, and descriptors rewritten under a list already submitted).

Change

  • HostHeap gets an identity from a process-wide counter (NEXT_ID).
  • State::dynamic records it next to the heap address.
  • HostHeap::release / descriptor::release_dynamic take it and free only when it is the heap's.

A heap that is still there takes its own ranges back exactly as before; a stale release for a heap that is gone (or for a new heap at the old address) does nothing - the host heap it named no longer exists, so there is nothing of it to free.

Tests

  • New descriptor::host::tests::dynamic_slots_are_given_back_only_to_the_heap_that_took_them: two host heaps; a range of A's released with B's identity stays taken, with A's identity is given back.
  • On this machine (no hardware D3D12, WARP): VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics dynamic_slots_are_given_back passes with the change; without it the test fails (free slots 262,144 against 262,142, i.e. B's identity freed A's range).
  • cargo test -p victory-gpu --lib --locked: 218 passed, 0 failed, 6 ignored.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean; likewise with --all-features.
  • No game files or live gameplay were used. Whether the title really releases a shader-visible heap while lists still hold its slots is not proven here (the game cannot be run in this environment); this is hardening of a lifetime the layer already relies on, not a confirmed live failure.

(CI note: as with #1320/#1321, the check job on main is currently red on the asset-policy violation; #1322 fixes that, after which this branch can be rebased.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6629827507 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1324). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-26T15:23:30Z. --- ## Problem `State::dynamic` (`crates/victory-gpu/src/draw.rs`) keeps the title descriptor heap of each range of dynamic slots by its **address**, and `descriptor::release_dynamic` frees the range in whatever host heap is registered at that address when the list is reset. A command list may outlive the title heap it recorded slots from: D3D12 keeps an object alive while a list names it, so the title can release a shader-visible heap before the lists that use it are reset. If the allocator later places another `Box<Heap>` at the same address and that heap is registered in `SHADER_HEAPS`, the old list's reset finds it by address and frees its dynamic slots - slots another live list has taken. Two live lists then hold the same dynamic slots; one rewrites the other's descriptors (wrong bindings, and descriptors rewritten under a list already submitted). ## Change - `HostHeap` gets an identity from a process-wide counter (`NEXT_ID`). - `State::dynamic` records it next to the heap address. - `HostHeap::release` / `descriptor::release_dynamic` take it and free only when it is the heap's. A heap that is still there takes its own ranges back exactly as before; a stale release for a heap that is gone (or for a new heap at the old address) does nothing - the host heap it named no longer exists, so there is nothing of it to free. ## Tests - New `descriptor::host::tests::dynamic_slots_are_given_back_only_to_the_heap_that_took_them`: two host heaps; a range of A's released with B's identity stays taken, with A's identity is given back. - On this machine (no hardware D3D12, WARP): `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics dynamic_slots_are_given_back` passes with the change; without it the test fails (`free slots 262,144 against 262,142`, i.e. B's identity freed A's range). - `cargo test -p victory-gpu --lib --locked`: **218 passed, 0 failed, 6 ignored**. - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean; likewise with `--all-features`. - No game files or live gameplay were used. Whether the title really releases a shader-visible heap while lists still hold its slots is **not proven here** (the game cannot be run in this environment); this is hardening of a lifetime the layer already relies on, not a confirmed live failure. (CI note: as with #1320/#1321, the `check` job on `main` is currently red on the asset-policy violation; #1322 fixes that, after which this branch can be rebased.)
CwWwWwW commented 2026-11-26 16:06:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-26T15:44:39Z.


Overlap note for the maintainer: #589 (AscilCH) is an independent, exact fix for the other half of this change's area - it makes a released view heap drop its page table and edits Heap::drop in descriptor.rs next to the identity used by this PR. Both are needed; if #589 lands first, rebase this branch on it (and vice versa). I checked that #589 is not superseded by this PR.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7196689293 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1324#issuecomment-7196689293). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-26T15:44:39Z. --- Overlap note for the maintainer: #589 (AscilCH) is an independent, exact fix for the other half of this change's area - it makes a released view heap drop its page table and edits `Heap::drop` in `descriptor.rs` next to the identity used by this PR. Both are needed; if #589 lands first, rebase this branch on it (and vice versa). I checked that #589 is not superseded by this PR.
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!1321
No description provided.