D3D12.X: dispatch_chain SHARED scratch reuse race across released/recreated lists and silent whole-pipeline fallback on console lists and Wait64 splits #2449

Open
opened 2026-11-25 19:30:18 +00:00 by microwave805 · 3 comments
microwave805 commented 2026-11-25 19:30:18 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by microwave805 on 2026-11-25T19:30:18Z.


Static audit on main @ c7e1799 found two bugs in the newly merged compute dispatch-splitting runtime (crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs, #2080). Part of #1269, Part of #1833.

1. [High] Stale SHARED scratch reuse race across released/recreated command lists, Wait64 split segments, and console lists (GPU scratch corruption)

  • Where:
    • crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs:132-137, 164-175
    • crates/xcl/src/hle/d3d12x/list_x.rs:822, 837-869, 2263-2268
    • crates/xcl/src/hle/d3d12x/console_list.rs:423-439, 751
  • Root cause: dispatch_chain::SHARED maps list_ptr -> (allocator_ptr, Weak<Scratch>), and scratch_for reuses SHARED[list] whenever s.0 == allocator and s.1.upgrade() succeeds (the Arc<Scratch> stays alive in RECORDINGS[allocator] until allocator_reset). dispatch_chain::list_reset(list) is called only from list_x::reset_copy_scratch (list_x.rs:2264), never from:
    1. list_x::on_release(list) or list_x::on_create(list, ...) (list_x.rs:822, 837-853)
    2. list_x::clear_segment_state(list) (list_x.rs:856-869, when Wait64 split segments return to title_list's spare pool)
    3. console_list::cl_reset / console_list::cl_release (console_list.rs:423-439, 751)
  • Trigger: Command list L1 records a split compute dispatch on allocator A (SHARED[L1] = (A, Weak(S1))), closes, submits to Queue 1 (still running on GPU), and is Released. A newly created command list L2 on A reuses freed address L1 and records a split compute dispatch → scratch_for hits SHARED[L2] (s.0 == A, S1 upgrades) and hands L2 the exact same scratch buffer S1 that L1 is actively executing on Queue 1, with zero cross-list/cross-queue synchronization. (Same hazard on console_list reset under XCL_ALLOC_SWAP=0.)
  • Fix: Call real::dispatch_chain::list_reset(list) in list_x::on_create, list_x::on_release, list_x::clear_segment_state, and console_list::cl_reset / cl_release.

2. [High] Silent dispatch_chain bypass (falling back to synchronous chain.whole()?) on console lists and Wait64 split segments

  • Where:
    • crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs:204-218
    • crates/xcl/src/hle/d3d12x/real.rs:2834-2841 & crates/xcl/src/hle/d3d12x/console_list.rs:437-438, 915
    • crates/xcl/src/hle/d3d12x/list_x.rs:2690-2747 (note: Wait64 split created_on registration is also addressed in open PR #1071)
  • Root cause: When alloc_pool::enabled() is true (default), dispatch_chain::dispatch (dispatch_chain.rs:204-206) unconditionally replaces the caller's allocator with alloc_pool::recording_backing(list).unwrap_or(0). When recording_backing returns None, allocator becomes 0, scratch becomes None, and lines 214-218 synchronously compile and dispatch chain.whole()? — defeating dispatch splitting (and hitting NVIDIA's driver compile stall / #2403 shader heap limit).
    • In dev_create_command_list_x (real.rs:2834-2841) and console_list::cl_reset (console_list.rs:437-438), console lists' backing PC command lists are never registered with alloc_pool::created_on / alloc_pool::reset_list, so every split compute dispatch from a console list (console_list.rs:915) gets recording_backing == None and forces chain.whole()?.
    • Newly created Wait64 split continuation lists (list_x.rs:2690) hit the same fallback until registered in alloc_pool.
  • Fix: Register console lists' PC command list in alloc_pool (or fall back in dispatch_chain.rs:205 to alloc_pool::current(allocator) instead of .unwrap_or(0) when recording_backing is None), and call alloc_pool::created_on for newly created try_split_for_wait segments.

AI use

  • Antigravity (Gemini 4 Neon): static code audit on main @ c7e1799 and issue drafting.
<!-- greyfinch-sync:ivall/xcl:issue:6612106985 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2459). Originally posted by [microwave805](https://github.com/microwave805) on 2026-11-25T19:30:18Z. --- Static audit on `main @ c7e1799` found two bugs in the newly merged compute dispatch-splitting runtime (`crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs`, #2080). Part of #1269, Part of #1833. ### 1. [High] Stale `SHARED` scratch reuse race across released/recreated command lists, Wait64 split segments, and console lists (GPU scratch corruption) - **Where:** - `crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs:132-137, 164-175` - `crates/xcl/src/hle/d3d12x/list_x.rs:822, 837-869, 2263-2268` - `crates/xcl/src/hle/d3d12x/console_list.rs:423-439, 751` - **Root cause:** `dispatch_chain::SHARED` maps `list_ptr -> (allocator_ptr, Weak<Scratch>)`, and `scratch_for` reuses `SHARED[list]` whenever `s.0 == allocator` and `s.1.upgrade()` succeeds (the `Arc<Scratch>` stays alive in `RECORDINGS[allocator]` until `allocator_reset`). `dispatch_chain::list_reset(list)` is called **only** from `list_x::reset_copy_scratch` (`list_x.rs:2264`), never from: 1. `list_x::on_release(list)` or `list_x::on_create(list, ...)` (`list_x.rs:822, 837-853`) 2. `list_x::clear_segment_state(list)` (`list_x.rs:856-869`, when Wait64 split segments return to `title_list`'s spare pool) 3. `console_list::cl_reset` / `console_list::cl_release` (`console_list.rs:423-439, 751`) - **Trigger:** Command list `L1` records a split compute dispatch on allocator `A` (`SHARED[L1] = (A, Weak(S1))`), closes, submits to Queue 1 (still running on GPU), and is Released. A newly created command list `L2` on `A` reuses freed address `L1` and records a split compute dispatch → `scratch_for` hits `SHARED[L2]` (`s.0 == A`, `S1` upgrades) and hands `L2` the exact same scratch buffer `S1` that `L1` is actively executing on Queue 1, with zero cross-list/cross-queue synchronization. (Same hazard on `console_list` reset under `XCL_ALLOC_SWAP=0`.) - **Fix:** Call `real::dispatch_chain::list_reset(list)` in `list_x::on_create`, `list_x::on_release`, `list_x::clear_segment_state`, and `console_list::cl_reset` / `cl_release`. ### 2. [High] Silent `dispatch_chain` bypass (falling back to synchronous `chain.whole()?`) on console lists and Wait64 split segments - **Where:** - `crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs:204-218` - `crates/xcl/src/hle/d3d12x/real.rs:2834-2841` & `crates/xcl/src/hle/d3d12x/console_list.rs:437-438, 915` - `crates/xcl/src/hle/d3d12x/list_x.rs:2690-2747` *(note: Wait64 split `created_on` registration is also addressed in open PR #1071)* - **Root cause:** When `alloc_pool::enabled()` is true (default), `dispatch_chain::dispatch` (`dispatch_chain.rs:204-206`) unconditionally replaces the caller's `allocator` with `alloc_pool::recording_backing(list).unwrap_or(0)`. When `recording_backing` returns `None`, `allocator` becomes `0`, `scratch` becomes `None`, and lines 214-218 synchronously compile and dispatch `chain.whole()?` — defeating dispatch splitting (and hitting NVIDIA's driver compile stall / #2403 shader heap limit). - In `dev_create_command_list_x` (`real.rs:2834-2841`) and `console_list::cl_reset` (`console_list.rs:437-438`), console lists' backing PC command lists are never registered with `alloc_pool::created_on` / `alloc_pool::reset_list`, so **every** split compute dispatch from a console list (`console_list.rs:915`) gets `recording_backing == None` and forces `chain.whole()?`. - Newly created `Wait64` split continuation lists (`list_x.rs:2690`) hit the same fallback until registered in `alloc_pool`. - **Fix:** Register console lists' PC command list in `alloc_pool` (or fall back in `dispatch_chain.rs:205` to `alloc_pool::current(allocator)` instead of `.unwrap_or(0)` when `recording_backing` is `None`), and call `alloc_pool::created_on` for newly created `try_split_for_wait` segments. ### AI use - Antigravity (Gemini 4 Neon): static code audit on `main @ c7e1799` and issue drafting.
KOLESNiii commented 2026-11-26 01:05:45 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-26T00:52:56Z.


Static follow-up on the whole-form fallback after #2371, at main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7.

  • There are two whole-form cache entries. translated_compute_pso_once checks an ordinary .pso with the ordinary ABI before it builds a chain. After a chain is selected, Chain::whole uses the chain ABI and looks for the whole shader under .chain.pso. The pack precompiler writes only the pieces when the program splits. #2551 adds the whole shader under the chain ABI, which warms the second path. The new #2371 end-to-end test seeds the first path by using a split limit of 12,500 offline and 12 at runtime. A same-settings precompile test should check the exact artifact and runtime consumer it intends to warm. Runtime selection, whole fallback, pack precompile, test setup.
  • The heap-window retry also depends on which thread sees the refusal. driver_pso sets a thread-local flag and the outer wrapper reads it on the parent. A piece that still fails after a helper sees E_OUTOFMEMORY reaches the parent as a zero result, with no HRESULT. If a parent-side attempt hits OOM and a later attempt succeeds, the same flag stays set and the wrapper can rerun the entire build with the same output pointer. One example is a cached whole probe returning OOM followed by a successful chain build. This can replace a successful result and spend another driver compile. An explicit retry reason per build would let the caller retain a successful result and propagate a helper refusal when the overall build fails. Retry wrapper, piece results, helper execution.

On amd-dev at 6a0bb5b, the direct scratch-miss path now queues the whole build and returns an error. The caller counts that invocation as skipped. A failed background build sets whole_failed, which suppresses another enqueue, but this direct path still returns the “still building” message. It also still materializes the one-group-per-slab plan before checking for scratch, the allocation already covered by #2350. A distinct failed status and skipped-producer count would make the new path easier to evaluate. Scratch miss, background failure, skipped count.

A standalone Rust probe using the retry wrapper and simulated outcomes confirmed the two control-flow cases. Windows, driver behavior and title impact remain unmeasured.

AI use — OpenAI Codex (GPT-6, exact serving variant unavailable) traced the code, ran the standalone probe and drafted this comment.

<!-- greyfinch-sync:ivall/xcl:comment:7179208234 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2459#issuecomment-7179208234). Originally posted by [KOLESNiii](https://github.com/KOLESNiii) on 2026-11-26T00:52:56Z. --- Static follow-up on the whole-form fallback after #2371, at main `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7`. - There are two whole-form cache entries. `translated_compute_pso_once` checks an ordinary `.pso` with the ordinary ABI before it builds a chain. After a chain is selected, `Chain::whole` uses the chain ABI and looks for the whole shader under `.chain.pso`. The pack precompiler writes only the pieces when the program splits. #2551 adds the whole shader under the chain ABI, which warms the second path. The new #2371 end-to-end test seeds the first path by using a split limit of 12,500 offline and 12 at runtime. A same-settings precompile test should check the exact artifact and runtime consumer it intends to warm. [Runtime selection](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/hle/d3d12x/real.rs#L4344-L4368), [whole fallback](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs#L41-L68), [pack precompile](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/shaders.rs#L1443-L1476), [test setup](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/tests/gpu_compute_e2e.rs#L153-L164). - The heap-window retry also depends on which thread sees the refusal. `driver_pso` sets a thread-local flag and the outer wrapper reads it on the parent. A piece that still fails after a helper sees `E_OUTOFMEMORY` reaches the parent as a zero result, with no HRESULT. If a parent-side attempt hits OOM and a later attempt succeeds, the same flag stays set and the wrapper can rerun the entire build with the same output pointer. One example is a cached whole probe returning OOM followed by a successful chain build. This can replace a successful result and spend another driver compile. An explicit retry reason per build would let the caller retain a successful result and propagate a helper refusal when the overall build fails. [Retry wrapper](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/hle/d3d12x/real.rs#L3800-L3834), [piece results](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs#L73-L99), [helper execution](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/hle/d3d12x/pso_async.rs#L333-L357). On `amd-dev` at `6a0bb5b`, the direct scratch-miss path now queues the whole build and returns an error. The caller counts that invocation as skipped. A failed background build sets `whole_failed`, which suppresses another enqueue, but this direct path still returns the “still building” message. It also still materializes the one-group-per-slab plan before checking for scratch, the allocation already covered by #2350. A distinct failed status and skipped-producer count would make the new path easier to evaluate. [Scratch miss](https://github.com/xcl-dev/xcl/blob/6a0bb5b/crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs#L525-L555), [background failure](https://github.com/xcl-dev/xcl/blob/6a0bb5b/crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs#L132-L169), [skipped count](https://github.com/xcl-dev/xcl/blob/6a0bb5b/crates/xcl/src/hle/d3d12x/bind.rs#L4368-L4376). A standalone Rust probe using the retry wrapper and simulated outcomes confirmed the two control-flow cases. Windows, driver behavior and title impact remain unmeasured. AI use — OpenAI Codex (GPT-6, exact serving variant unavailable) traced the code, ran the standalone probe and drafted this comment.
KOLESNiii commented 2026-11-26 02:08:16 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-26T01:08:45Z.


A separate split-pipeline reuse point on main at b49be18. XCL calls CreateRootSignature for each chain build, and the chain passes that signature to each piece and to its whole fallback. The compute blob RAM key contains the root signature address. The offline builder already retains chain signatures by sampler set.

Verified: Identical piece DXIL and flags with different root-signature addresses have different RAM keys. If D3D12 returns a distinct live object for each equivalent chain signature, duplicate chain builds will miss each other’s RAM blobs and try disk. This is a plausible source of repeated driver work when disk reuse is unavailable. XCL does a new serialize/create on every chain build. Runtime object identity and title impact remain open. A focused check would create the same split PSO twice, keep the first alive, and compare the two root addresses, RAM hits, disk hits and native create times. Run it with an empty XCL driver cache and then with a warmed one. Runtime chain creation · Signature creation · Serialize and create · RAM key and test · Offline signature reuse

Static review. Windows and title timing remain unmeasured. AI use was OpenAI Codex (GPT-6, exact serving variant unavailable) for review and drafting.

<!-- greyfinch-sync:ivall/xcl:comment:7179477989 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2459#issuecomment-7179477989). Originally posted by [KOLESNiii](https://github.com/KOLESNiii) on 2026-11-26T01:08:45Z. --- A separate split-pipeline reuse point on `main` at `b49be18`. XCL calls `CreateRootSignature` for each chain build, and the chain passes that signature to each piece and to its whole fallback. The compute blob RAM key contains the root signature address. The offline builder already retains chain signatures by sampler set. **Verified:** Identical piece DXIL and flags with different root-signature addresses have different RAM keys. If D3D12 returns a distinct live object for each equivalent chain signature, duplicate chain builds will miss each other’s RAM blobs and try disk. This is a plausible source of repeated driver work when disk reuse is unavailable. XCL does a new serialize/create on every chain build. Runtime object identity and title impact remain open. A focused check would create the same split PSO twice, keep the first alive, and compare the two root addresses, RAM hits, disk hits and native create times. Run it with an empty XCL driver cache and then with a warmed one. [Runtime chain creation](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs#L41-L94) · [Signature creation](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/gpu/recomp/pso.rs#L1331-L1336) · [Serialize and create](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/gpu/recomp/pso.rs#L1380-L1383) · [RAM key and test](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/hle/d3d12x/real.rs#L4757-L4763) · [Offline signature reuse](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/shaders.rs#L1479-L1495) Static review. Windows and title timing remain unmeasured. AI use was OpenAI Codex (GPT-6, exact serving variant unavailable) for review and drafting.
CryingLaughing commented 2026-11-26 13:05:42 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by CryingLaughing on 2026-11-26T13:00:01Z.


I checked the case where the outer creation call has already recovered from a heap-window refusal. On main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, the outer wrapper can still enter the switch-form retry after that success. Fork commit ff2ef9297438f2c81775edb6aeac36c618bbe8cf consumes the refusal flag and retains a successful result with a nonnull pipeline output in compute, graphics, and mesh creation. A final failure with a recorded refusal remains eligible for switch-form retry.

The focused CPU test passed (1/0/0). Its five scripted cases include recovery in one call, final failure, and a successful HRESULT with an empty output slot. The separate synthetic gpu_memory_windows_from_the_heap test passed (1/0/0, zero skips) on the RTX 4080. This exercises normal heap-window readback. Driver-induced refusal and retail impact remain unmeasured.

Exact fork head, Windows 11 25H2 build 26200.9974, Core i5-13600K, RTX 4080 driver 621.01, Rust 1.100.0 x64 MSVC, DXC 1.8.2502.11. cargo build --workspace --locked -j 4 succeeded. cargo test --workspace --locked -j 4 -- --test-threads=4 --show-output reported 1,436 passed, 0 failed, 47 ignored across 37 harnesses. The pass count includes 29 explicit capability skips.

<!-- greyfinch-sync:ivall/xcl:comment:7192738653 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2459#issuecomment-7192738653). Originally posted by [CryingLaughing](https://github.com/CryingLaughing) on 2026-11-26T13:00:01Z. --- I checked the case where the outer creation call has already recovered from a heap-window refusal. On main `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7`, the outer wrapper can still enter the switch-form retry after that success. [Fork commit `ff2ef9297438f2c81775edb6aeac36c618bbe8cf`](https://github.com/CryingLaughing/xcl/commit/ff2ef9297438f2c81775edb6aeac36c618bbe8cf) consumes the refusal flag and retains a successful result with a nonnull pipeline output in compute, graphics, and mesh creation. A final failure with a recorded refusal remains eligible for switch-form retry. The focused CPU test passed (1/0/0). Its five scripted cases include recovery in one call, final failure, and a successful HRESULT with an empty output slot. The separate synthetic `gpu_memory_windows_from_the_heap` test passed (1/0/0, zero skips) on the RTX 4080. This exercises normal heap-window readback. Driver-induced refusal and retail impact remain unmeasured. Exact fork head, Windows 11 25H2 build 26200.9974, Core i5-13600K, RTX 4080 driver 621.01, Rust 1.100.0 x64 MSVC, DXC 1.8.2502.11. `cargo build --workspace --locked -j 4` succeeded. `cargo test --workspace --locked -j 4 -- --test-threads=4 --show-output` reported **1,436 passed, 0 failed, 47 ignored** across 37 harnesses. The pass count includes 29 explicit capability skips.
Sign in to join this conversation.
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
xcl-dev/xcl#2449
No description provided.