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

Manually merged
github merged 1 commit from github-bot/gh-1324 into gh-pr/1324/base 2026-11-26 18:09:58 +00:00 AGit
Owner

@⁠CwWwWwW on GitHub · 2026-11-26 15:23 UTC · original
CwWwWwW:fix/dynamic-slots-heap-identity → main · +75 −19 · 3 files · 1 commits · merged 2026-11-26 18:05 UTC

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** on GitHub · 2026-11-26 15:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/1324) `CwWwWwW:fix/dynamic-slots-heap-identity` → `main` · +75 −19 · 3 files · 1 commits · merged 2026-11-26 18:05 UTC ## 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.)
`State::dynamic` keeps the title heap of each range of dynamic descriptor
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
list may outlive the title heap it recorded slots from: D3D12 keeps an
object alive while a command list names it, so the title can release a
shader-visible heap before the lists that use it are reset. If a later heap
is made at the same address (a `Box<Heap>` of the same size), the old
list's reset then frees slots of the new heap that other lists hold - two
live lists get the same dynamic slots, and one rewrites the other's
descriptors.

Give each host heap an identity (`NEXT_ID`) and record it with the range;
`release` frees only when the identity is the heap's. A stale release now
does nothing (the host heap it named is gone, so its slots are too); a heap
still there takes its own ranges back as before.

Test: `dynamic_slots_are_given_back_only_to_the_heap_that_took_them` (two
host heaps; A's range released with B's identity frees nothing, with A's
frees it). It needs a host device: with `VICTORY_D3D12_WARP=1` and
`--features diagnostics` locally it passes with the change and fails
without it (free slots 262,144 against 262,142); CI runs the gpu tests on
WARP. `cargo test -p victory-gpu --lib`: 218 passed, 0 failed, 6 ignored;
`cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean, and the
same with `--all-features`.

Reachability in the title is not proven - the game cannot be run here - so
this hardens a D3D12 lifetime the layer already relies on.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:24:10 +00:00
Author
Owner

@⁠CwWwWwW on GitHub · 2026-11-26 15:44 UTC · original

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.

**@⁠CwWwWwW** on GitHub · 2026-11-26 15:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/1324#issuecomment-7196689293) 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.
github-bot changed target branch from main to gh-pr/1324/base 2026-11-26 18:09:58 +00:00
github manually merged commit 26090858ea into gh-pr/1324/base 2026-11-26 18:09:58 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.