D3D12.X: alloc_reset frees UMA/sparse shader argument tables while alloc_pool keeps a busy allocator aside #1358

Open
opened 2026-11-26 04:51:57 +00:00 by github-bot · 0 comments
Owner

@⁠microwave805 on GitHub · 2026-11-24 15:12 UTC · original

Checked on main (930e8b4).

Problem

bind::bind_abi (bind.rs:862-881) and bind::allocate_upload_memory (bind.rs:818-842) allocate per-draw translated shader io/root-argument tables and AllocateUploadMemory buffers into State.uma, tracked against the title allocator pointer. When a command list is reset onto another allocator, split, or released, bind::reset/forget moves those blocks into console_list::PENDING[title_alloc].

When the title calls ID3D12CommandAllocator::Reset(), alloc_pool::title_reset(this) (alloc_pool.rs:195-259) intentionally puts the busy PC allocator aside and returns Some(0) (S_OK) specifically because recordings on it are still held by lists or still executing on the GPU. However, real::alloc_reset (crates/xcl/src/hle/d3d12x/real.rs:4997-5008) treats hr >= 0 as meaning the GPU is done and immediately frees PENDING[this]:

unsafe extern "system" fn alloc_reset(this: *mut c_void) -> HRESULT {
    // (lists may still hold recordings on it that the title submits again: `alloc_pool`)
    let hr = match super::alloc_pool::title_reset(this) {
        Some(hr) => hr,
        None => reset_pc_allocator(this),
    };
    if hr >= 0 {
        // the GPU is done with what lists recorded from this allocator used
        super::console_list::allocator_reset(this);
    }
    hr
}

console_list::allocator_reset immediately runs u.free(b) (pushing coherent Arena blocks onto Uma.pool's LIFO stack at gpu/uma.rs:583, where the very next draw pops and overwrites them) or sparse::free(b) (decommitted + VirtualFree(MEM_DECOMMIT) + u.sparse_release for large AllocateUploadMemory blocks).

Minimal trigger

  1. Record translated draws/dispatches (or AllocateUploadMemory) on list L with title allocator A, close and submit L.
  2. Reset L onto allocator A2 (or release L) while L's GPU submission is still in flight — bind::reset moves L's UMA/sparse blocks into PENDING[A].
  3. Title calls A->Reset() before L finishes on the GPU (or while another list L2 still holds a recording on A). alloc_pool::title_reset(A) swaps cur[A] = B and returns Some(0).
  4. real::alloc_reset immediately frees PENDING[A]; the next translated draw reuses the same LIFO block and overwrites in-flight GPU shader arguments (or sparse::free decommits the upload buffer).

Suggested fix

Key console_list::PENDING by the actual PC backing allocator (alloc_pool::current(alloc)) instead of the title allocator pointer, and free a backing's pending UMA/sparse blocks only when alloc_pool actually resets or retires that PC backing after Backing::free() is true.


AI use: Antigravity (Gemini 4 Neon) performed the read-only source audit and drafted this issue; checked and verified on 930e8b4 before opening.

**@⁠microwave805** on GitHub · 2026-11-24 15:12 UTC · [original](https://github.com/xcl-dev/xcl/issues/1358) Checked on `main` (`930e8b4`). ### Problem `bind::bind_abi` (`bind.rs:862-881`) and `bind::allocate_upload_memory` (`bind.rs:818-842`) allocate per-draw translated shader `io`/root-argument tables and `AllocateUploadMemory` buffers into `State.uma`, tracked against the **title** allocator pointer. When a command list is reset onto another allocator, split, or released, `bind::reset`/`forget` moves those blocks into `console_list::PENDING[title_alloc]`. When the title calls `ID3D12CommandAllocator::Reset()`, `alloc_pool::title_reset(this)` (`alloc_pool.rs:195-259`) intentionally puts the busy PC allocator aside and returns `Some(0)` (`S_OK`) specifically because recordings on it are still held by lists or still executing on the GPU. However, `real::alloc_reset` (`crates/xcl/src/hle/d3d12x/real.rs:4997-5008`) treats `hr >= 0` as meaning the GPU is done and immediately frees `PENDING[this]`: ```rust unsafe extern "system" fn alloc_reset(this: *mut c_void) -> HRESULT { // (lists may still hold recordings on it that the title submits again: `alloc_pool`) let hr = match super::alloc_pool::title_reset(this) { Some(hr) => hr, None => reset_pc_allocator(this), }; if hr >= 0 { // the GPU is done with what lists recorded from this allocator used super::console_list::allocator_reset(this); } hr } ``` `console_list::allocator_reset` immediately runs `u.free(b)` (pushing coherent `Arena` blocks onto `Uma.pool`'s LIFO stack at `gpu/uma.rs:583`, where the very next draw pops and overwrites them) or `sparse::free(b)` (`decommitted` + `VirtualFree(MEM_DECOMMIT)` + `u.sparse_release` for large `AllocateUploadMemory` blocks). ### Minimal trigger 1. Record translated draws/dispatches (or `AllocateUploadMemory`) on list `L` with title allocator `A`, close and submit `L`. 2. Reset `L` onto allocator `A2` (or release `L`) while `L`'s GPU submission is still in flight — `bind::reset` moves `L`'s UMA/sparse blocks into `PENDING[A]`. 3. Title calls `A->Reset()` before `L` finishes on the GPU (or while another list `L2` still holds a recording on `A`). `alloc_pool::title_reset(A)` swaps `cur[A] = B` and returns `Some(0)`. 4. `real::alloc_reset` immediately frees `PENDING[A]`; the next translated draw reuses the same LIFO block and overwrites in-flight GPU shader arguments (or `sparse::free` decommits the upload buffer). ### Suggested fix Key `console_list::PENDING` by the actual **PC backing allocator** (`alloc_pool::current(alloc)`) instead of the title allocator pointer, and free a backing's pending UMA/sparse blocks only when `alloc_pool` actually resets or retires that PC backing after `Backing::free()` is true. --- **AI use:** Antigravity (Gemini 4 Neon) performed the read-only source audit and drafted this issue; checked and verified on `930e8b4` before opening.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:51:57 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.