draw.rs: a list gives its dynamic descriptor slots back to whatever heap now has the old heap's address #392

Open
opened 2026-11-27 00:56:29 +00:00 by github-bot · 1 comment
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-26 22:38 UTC · original

A command list records the dynamic descriptor slots it took by the title heap's address, and gives them back to whatever shader-visible heap is registered at that address when it is reset or released. If the title has released that heap meanwhile and a new one was made at the same address, the old list frees slots of the new heap that another live list holds, so two lists end up sharing slots.

Where

At 126acb3:

crates/victory-gpu/src/draw.rs:499-501: the slots a list holds are kept by heap address:

    /// The dynamic slots the list holds: title heap, first, count; given
    /// back when the list has run, is reset or released.
    dynamic: Vec<(usize, u32, u32)>,

crates/victory-gpu/src/draw.rs:516-521 and 1088-1091: a reset (*self = State::default()) or a release drops the old State, which gives every range back by that address:

impl Drop for State {
    fn drop(&mut self) {
        for &(heap, first, n) in &self.dynamic {
            crate::descriptor::release_dynamic(heap, first, n);
        }
    }
}

crates/victory-gpu/src/descriptor.rs:862-870: release_dynamic frees the range in the heap registered at that address now:

pub(crate) fn release_dynamic(heap: usize, first: u32, n: u32) {
    let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner());
    if heaps.iter().any(|&(_, _, h)| h == heap)
        // SAFETY: registered heaps are live (removed when dropped).
        && let Some(Some(host)) = unsafe { &*(heap as *const Heap) }.host.get()
    {
        host.release(first, n);
    }
}

Heap's Drop (descriptor.rs:908-915) removes the heap from SHADER_HEAPS, and a new heap is a Box<Heap> (descriptor.rs:1740) registered by its address (descriptor.rs:1760-1764), so the allocator can hand a new heap the old one's address.

Why it matters

  1. List L records draws against shader-visible heap H and takes dynamic slots from H's host heap.
  2. L doesn't run, or its slots aren't given back when it runs. On the default path tables_done gives them back right after a run, so this covers lists that were recorded but never run, and lists that ran through submit_split (VICTORY_CUT_WAITS=0, where tables_done isn't called for the lists run at once).
  3. The title releases H. Its entry leaves SHADER_HEAPS, which is valid once the GPU no longer needs the heap.
  4. The title makes heap H2, and the allocator places its Box<Heap> at H's old address. List M takes dynamic slots from H2.
  5. The title resets or releases L. release_dynamic(H's address, ...) finds H2 and frees ranges of H2 that M holds.
  6. The next list to take dynamic slots from H2 can get M's slots and write its descriptors over them, under M if M is recorded or already submitted. The result is wrong bindings, or a device removal if a view ends up describing the wrong resource.

The same address-for-identity pattern was the cause of #232 (FLIPS and NEW_PENDING keyed by HostHeap), and #265 addresses pending flips when a host heap is dropped. Neither covers the list's dynamic slots. #48 drains a list's ranges once its flight completes, so the list's later drop can't free slots that were handed out again in the same heap. It doesn't apply to a list that never ran and whose heap was replaced at the same address.

Suggestion

  • Give each HostHeap an identity from a process-wide counter, record it next to the heap address in State::dynamic, and free a range in release_dynamic / HostHeap::release only when the identity matches. A release for a heap that is gone, or for a new heap at the old address, then does nothing: the host heap it named, and its slots, no longer exist. This is what fxceless/victory-fork#1324 did (merged there 2026-11-26). Its test is two host heaps, where a range of A released with B's identity stays taken and with A's identity is given back.

Not checked

Found by reading the source at 126acb3. Not reproduced, and I have no game run showing it. I haven't checked how often the title releases a shader-visible heap while lists that used it are still unreset, or whether the allocator reuses the address in practice. If it never does, this is latent. I haven't checked whether a list keeps a reference to the heaps it sets (that would close step 3).

AI use

AI-assisted review (source reading), with Claude Code. No build, no hardware run, no game files.

**@⁠Jesper-Andersson** on GitHub · 2026-11-26 22:38 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/392) A command list records the dynamic descriptor slots it took by the title heap's address, and gives them back to whatever shader-visible heap is registered at that address when it is reset or released. If the title has released that heap meanwhile and a new one was made at the same address, the old list frees slots of the new heap that another live list holds, so two lists end up sharing slots. ## Where At `126acb3`: `crates/victory-gpu/src/draw.rs:499-501`: the slots a list holds are kept by heap address: ```rust /// The dynamic slots the list holds: title heap, first, count; given /// back when the list has run, is reset or released. dynamic: Vec<(usize, u32, u32)>, ``` `crates/victory-gpu/src/draw.rs:516-521` and `1088-1091`: a reset (`*self = State::default()`) or a release drops the old `State`, which gives every range back by that address: ```rust impl Drop for State { fn drop(&mut self) { for &(heap, first, n) in &self.dynamic { crate::descriptor::release_dynamic(heap, first, n); } } } ``` `crates/victory-gpu/src/descriptor.rs:862-870`: `release_dynamic` frees the range in the heap registered at that address now: ```rust pub(crate) fn release_dynamic(heap: usize, first: u32, n: u32) { let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner()); if heaps.iter().any(|&(_, _, h)| h == heap) // SAFETY: registered heaps are live (removed when dropped). && let Some(Some(host)) = unsafe { &*(heap as *const Heap) }.host.get() { host.release(first, n); } } ``` `Heap`'s `Drop` (`descriptor.rs:908-915`) removes the heap from `SHADER_HEAPS`, and a new heap is a `Box<Heap>` (`descriptor.rs:1740`) registered by its address (`descriptor.rs:1760-1764`), so the allocator can hand a new heap the old one's address. ## Why it matters 1. List L records draws against shader-visible heap H and takes dynamic slots from H's host heap. 2. L doesn't run, or its slots aren't given back when it runs. On the default path `tables_done` gives them back right after a run, so this covers lists that were recorded but never run, and lists that ran through `submit_split` (`VICTORY_CUT_WAITS=0`, where `tables_done` isn't called for the lists run at once). 3. The title releases H. Its entry leaves `SHADER_HEAPS`, which is valid once the GPU no longer needs the heap. 4. The title makes heap H2, and the allocator places its `Box<Heap>` at H's old address. List M takes dynamic slots from H2. 5. The title resets or releases L. `release_dynamic(H's address, ...)` finds H2 and frees ranges of H2 that M holds. 6. The next list to take dynamic slots from H2 can get M's slots and write its descriptors over them, under M if M is recorded or already submitted. The result is wrong bindings, or a device removal if a view ends up describing the wrong resource. The same address-for-identity pattern was the cause of #232 (`FLIPS` and `NEW_PENDING` keyed by `HostHeap`), and #265 addresses pending flips when a host heap is dropped. Neither covers the list's dynamic slots. #48 drains a list's ranges once its flight completes, so the list's later drop can't free slots that were handed out again in the same heap. It doesn't apply to a list that never ran and whose heap was replaced at the same address. ## Suggestion - Give each `HostHeap` an identity from a process-wide counter, record it next to the heap address in `State::dynamic`, and free a range in `release_dynamic` / `HostHeap::release` only when the identity matches. A release for a heap that is gone, or for a new heap at the old address, then does nothing: the host heap it named, and its slots, no longer exist. This is what fxceless/victory-fork#1324 did (merged there 2026-11-26). Its test is two host heaps, where a range of A released with B's identity stays taken and with A's identity is given back. ## Not checked Found by reading the source at `126acb3`. Not reproduced, and I have no game run showing it. I haven't checked how often the title releases a shader-visible heap while lists that used it are still unreset, or whether the allocator reuses the address in practice. If it never does, this is latent. I haven't checked whether a list keeps a reference to the heaps it sets (that would close step 3). ## AI use AI-assisted review (source reading), with Claude Code. No build, no hardware run, no game files.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:56:29 +00:00
Author
Owner

@⁠akimfomin on GitHub · 2026-11-26 23:27 UTC · original

The exact heap-lifetime guard is already in fxceless via CwWwWwW’s #1324. I confirmed avatarmanz main 014d52d still releases by address, then tried only the three-file fix, using its actual parent 58de9bf as the base. It conflicts in descriptor.rs, descriptor/host.rs and draw.rs. Fxceless carries the heap ID with each range and rejects a mismatched release.

The smallest follow-up is to port that ID guard along the three existing paths and carry the two-heaps WARP regression as the first check. The wrong-ID release must leave the new heap's range live, while the correct ID still frees it. Source/Git check only on the receiving fork. PortBridge · AI-assisted comparison.

**@⁠akimfomin** on GitHub · 2026-11-26 23:27 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/392#issuecomment-7205556763) The exact heap-lifetime guard is already in fxceless via CwWwWwW’s #1324. I confirmed avatarmanz main `014d52d` still releases by address, then tried [only the three-file fix](https://github.com/fxceless/victory-fork/commit/26090858ea21dbe40650ab011fd4fb4db4d731fc), using its actual parent `58de9bf` as the base. It conflicts in `descriptor.rs`, `descriptor/host.rs` and `draw.rs`. Fxceless carries the heap ID with each range and [rejects a mismatched release](https://github.com/fxceless/victory-fork/blob/a42b627e78476d691042a2a12e8cd5fcf5e49d77/crates/victory-gpu/src/descriptor/host.rs#L2050-L2071). The smallest follow-up is to port that ID guard along the three existing paths and carry [the two-heaps WARP regression](https://github.com/fxceless/victory-fork/pull/1324) as the first check. The wrong-ID release must leave the new heap's range live, while the correct ID still frees it. Source/Git check only on the receiving fork. [PortBridge](https://github.com/akimfomin/PortBridge) · AI-assisted comparison.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/avatarmanz--VIctory-7900XTX#392
No description provided.