d3d12x: implement KickoffX, Wait32/64BitValueX, and RSSetDepthBiasX #23

Manually merged
github merged 1 commit from gh-pr/23/head into gh-pr/23/base 2026-11-26 04:04:46 +00:00
Owner

@⁠raylitebull on GitHub · 2026-11-21 21:59 UTC · original
raylitebull:list-x-extensions → main · +1942 −100 · 5 files · 1 commits · merged 2026-11-22 10:15 UTC

Implements three D3D12.X command list extensions in crates/xcl/src/hle/d3d12x/:

Summary

  1. KickoffX (command list slot #93):

    • Tracks per-list allocator, command list type, bound PSO, index buffer, depth bounds, occlusion queries, and live command queues per (device, list_type) (with Release cleanup on lists, queues, and allocators).
    • Flushes recorded work early by ending any active PC occlusion query early, closing the list, refreshing title textures, satisfying pending waits, submitting to a compatible live queue via ExecuteCommandLists, resetting the list on the same allocator (preserving XCL's vtable on copy lists), and restoring tracked state.
    • If no compatible queue or allocator is known yet (or for bundles), logs once and defers safely to Close + ExecuteCommandLists.
  2. Wait32BitValueX (#71) and Wait64BitValueX (#72):

    • Implements (va, comparison, value, mask, flags) with D3D12_COMPARISON_FUNC (1..=8) and (mem & mask) <op> value semantics.
    • Validates alignment and UMA membership; treats ALWAYS as a no-op and logs/skips NEVER to prevent hangs.
    • Tracks per-list written UMA ranges so same-list write-then-wait does not deadlock before submission; evaluates external waits in execute_with_waits (splitting multi-list ExecuteCommandLists batches before an unsatisfied list, with spin+sleep polling and a 2 s timeout cap).
  3. RSSetDepthBiasX (command list slot #94):

    • Implements (depthBias: f32, depthBiasClamp: f32, slopeScaledDepthBias: f32) with non-finite sanitization and an atomic fast-path guard.
    • Derives and caches a patched PSO from the bound base PSO (device_x::depth_bias_pso, patching RasterizerState.{DepthBias, DepthBiasClamp, SlopeScaledDepthBias} at verified offsets 0x1D0..0x1DC, capped at 1024 entries and COM-released outside locks in forget_base).
    • Applies the override on draw calls (DrawInstanced, DrawIndexedInstanced, DrawIndexedX, ExecuteIndirect) and restores the base PSO when reset to (0, 0, 0) (or on Reset / ClearState).

Testing

  • Added 7 unit tests across device_x.rs and list_x.rs covering DepthBias desc patching/offsets, compare_u64, 32/64-bit masked cross-thread waits + timeout, written-range overlap, execute_with_waits batch splitting, queue picking/release, and depth-bias state transitions.
  • Added GPU e2e tests in tests/testtitle/src/gpu.rs covering KickoffX (verifying GPU write completes before Close() and post-kickoff recording succeeds), cross-thread Wait32BitValueX/Wait64BitValueX, and RSSetDepthBiasX on a real depth buffer.
  • cargo build --workspace: 0 new warnings.
  • cargo test --workspace -- --test-threads=4: all tests passed (xcl lib 247 passed, console_dlls_e2e 12 passed, console_shaders 1 passed, e2e 1 passed, gpu_pso_e2e 6 passed, xg_oracle 3 passed).
**@⁠raylitebull** on GitHub · 2026-11-21 21:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/23) `raylitebull:list-x-extensions` → `main` · +1942 −100 · 5 files · 1 commits · merged 2026-11-22 10:15 UTC Implements three D3D12.X command list extensions in `crates/xcl/src/hle/d3d12x/`: ### Summary 1. **`KickoffX` (command list slot #93)**: - Tracks per-list allocator, command list type, bound PSO, index buffer, depth bounds, occlusion queries, and live command queues per `(device, list_type)` (with `Release` cleanup on lists, queues, and allocators). - Flushes recorded work early by ending any active PC occlusion query early, closing the list, refreshing title textures, satisfying pending waits, submitting to a compatible live queue via `ExecuteCommandLists`, resetting the list on the same allocator (preserving XCL's vtable on copy lists), and restoring tracked state. - If no compatible queue or allocator is known yet (or for bundles), logs once and defers safely to `Close` + `ExecuteCommandLists`. 2. **`Wait32BitValueX` (#71) and `Wait64BitValueX` (#72)**: - Implements `(va, comparison, value, mask, flags)` with `D3D12_COMPARISON_FUNC` (1..=8) and `(mem & mask) <op> value` semantics. - Validates alignment and UMA membership; treats `ALWAYS` as a no-op and logs/skips `NEVER` to prevent hangs. - Tracks per-list written UMA ranges so same-list write-then-wait does not deadlock before submission; evaluates external waits in `execute_with_waits` (splitting multi-list `ExecuteCommandLists` batches before an unsatisfied list, with spin+sleep polling and a 2 s timeout cap). 3. **`RSSetDepthBiasX` (command list slot #94)**: - Implements `(depthBias: f32, depthBiasClamp: f32, slopeScaledDepthBias: f32)` with non-finite sanitization and an atomic fast-path guard. - Derives and caches a patched PSO from the bound base PSO (`device_x::depth_bias_pso`, patching `RasterizerState.{DepthBias, DepthBiasClamp, SlopeScaledDepthBias}` at verified offsets `0x1D0..0x1DC`, capped at 1024 entries and COM-released outside locks in `forget_base`). - Applies the override on draw calls (`DrawInstanced`, `DrawIndexedInstanced`, `DrawIndexedX`, `ExecuteIndirect`) and restores the base PSO when reset to `(0, 0, 0)` (or on `Reset` / `ClearState`). ### Testing - Added 7 unit tests across `device_x.rs` and `list_x.rs` covering `DepthBias` desc patching/offsets, `compare_u64`, 32/64-bit masked cross-thread waits + timeout, written-range overlap, `execute_with_waits` batch splitting, queue picking/release, and depth-bias state transitions. - Added GPU e2e tests in `tests/testtitle/src/gpu.rs` covering `KickoffX` (verifying GPU write completes before `Close()` and post-kickoff recording succeeds), cross-thread `Wait32BitValueX`/`Wait64BitValueX`, and `RSSetDepthBiasX` on a real depth buffer. - `cargo build --workspace`: 0 new warnings. - `cargo test --workspace -- --test-threads=4`: all tests passed (`xcl` lib 247 passed, `console_dlls_e2e` 12 passed, `console_shaders` 1 passed, `e2e` 1 passed, `gpu_pso_e2e` 6 passed, `xg_oracle` 3 passed).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:04:44 +00:00
github manually merged commit 3dfbcfbde7 into gh-pr/23/base 2026-11-26 04:04:46 +00:00
Author
Owner

@⁠raylitebull on GitHub · 2026-11-21 22:04 UTC · original

Transparency note on what is grounded vs. inferred in this PR, since this touches the D3D12.X submission path and was written without a real console executable or live capture:

What is grounded in the repo

  • The four console command-list slot indices (#71 Wait32BitValueX, #72 Wait64BitValueX, #93 KickoffX, #94 depth bias X) match what is already documented in HANDOFF.md.
  • D3D12_GRAPHICS_PIPELINE_STATE_DESC RasterizerState depth-bias offsets (0x1D0..0x1DC) match standard PC D3D12 layout.

What was inferred and needs verification against real title call sites

  1. Method signatures & enum values (unverified against a console binary):
    • Wait32BitValueX (#71) / Wait64BitValueX (#72) assume (va: u64, comparison: u32, value: u32/u64, mask: u32/u64, flags: u32) with D3D12_COMPARISON_FUNC (1..=8) and (mem & mask) <op> value. Argument order, parameter count, and enum numbering (1-based D3D12_COMPARISON_FUNC vs. 0-based PM4) should be checked against an actual call site.
    • RSSetDepthBiasX (#94) assumes (depthBias: f32, depthBiasClamp: f32, slopeScaledDepthBias: f32) (rounding depthBias to i32 for D3D12_RASTERIZER_DESC::DepthBias); the console ABI may pass i32 or a different parameter layout.
    • KickoffX (#93) assumes 0 arguments (fn(this)).
  2. KickoffX (#93) PC state-loss & queue-ordering caveats:
    • Calling Close() -> ExecuteCommandLists() -> Reset() on a PC command list clears all D3D12 dynamic state. Currently this only restores bound_pso, index_buffer, and depth_bounds — it does not restore descriptor heaps, root signatures/arguments, render targets, viewports, scissors, vertex buffers, primitive topology, blend factor, or stencil ref. Any draw recorded after KickoffX that relies on previously bound state will drop it unless those are also tracked and rebound.
    • When last_queue is unknown, pick_queue picks the most recently active compatible live queue, which can guess wrong if a title uses multiple queues of the same type or submits batches in a specific order across lists.
  3. Wait32BitValueX / Wait64BitValueX (#71/#72) CPU wait in ExecuteCommandLists vs. GPU CP wait:
    • Waits are not executed during recording (they are deferred to ExecuteCommandLists, and same-list list_x memory writes skip waiting), so recording itself won't deadlock.
    • However, polling synchronously on the CPU thread inside ExecuteCommandLists (with a 2 s timeout cap) is still an approximation of a GPU command-processor stall: it will time out if (a) a shader/UAV write earlier in the same unsubmitted list is the producer (not tracked in written_ranges), or (b) the title submits a wait on Queue A before submitting the producer on Queue B from the same thread.

Happy to adjust any signatures once checked against a real trace, keep parts behind a flag/opt-in, or trim this down if you'd rather keep these slots as logged no-ops until real call sites are observed.

**@⁠raylitebull** on GitHub · 2026-11-21 22:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/23#issuecomment-7069924849) Transparency note on what is grounded vs. inferred in this PR, since this touches the D3D12.X submission path and was written without a real console executable or live capture: ### What is grounded in the repo - The four console command-list slot indices (`#71` `Wait32BitValueX`, `#72` `Wait64BitValueX`, `#93` `KickoffX`, `#94` depth bias X) match what is already documented in `HANDOFF.md`. - `D3D12_GRAPHICS_PIPELINE_STATE_DESC` `RasterizerState` depth-bias offsets (`0x1D0..0x1DC`) match standard PC D3D12 layout. ### What was inferred and needs verification against real title call sites 1. **Method signatures & enum values (unverified against a console binary):** - `Wait32BitValueX` (#71) / `Wait64BitValueX` (#72) assume `(va: u64, comparison: u32, value: u32/u64, mask: u32/u64, flags: u32)` with `D3D12_COMPARISON_FUNC` (`1..=8`) and `(mem & mask) <op> value`. Argument order, parameter count, and enum numbering (1-based `D3D12_COMPARISON_FUNC` vs. 0-based PM4) should be checked against an actual call site. - `RSSetDepthBiasX` (#94) assumes `(depthBias: f32, depthBiasClamp: f32, slopeScaledDepthBias: f32)` (rounding `depthBias` to `i32` for `D3D12_RASTERIZER_DESC::DepthBias`); the console ABI may pass `i32` or a different parameter layout. - `KickoffX` (#93) assumes 0 arguments (`fn(this)`). 2. **`KickoffX` (#93) PC state-loss & queue-ordering caveats:** - Calling `Close()` -> `ExecuteCommandLists()` -> `Reset()` on a PC command list clears all D3D12 dynamic state. Currently this only restores `bound_pso`, `index_buffer`, and `depth_bounds` — it does **not** restore descriptor heaps, root signatures/arguments, render targets, viewports, scissors, vertex buffers, primitive topology, blend factor, or stencil ref. Any draw recorded after `KickoffX` that relies on previously bound state will drop it unless those are also tracked and rebound. - When `last_queue` is unknown, `pick_queue` picks the most recently active compatible live queue, which can guess wrong if a title uses multiple queues of the same type or submits batches in a specific order across lists. 3. **`Wait32BitValueX` / `Wait64BitValueX` (#71/#72) CPU wait in `ExecuteCommandLists` vs. GPU CP wait:** - Waits are **not** executed during recording (they are deferred to `ExecuteCommandLists`, and same-list `list_x` memory writes skip waiting), so recording itself won't deadlock. - However, polling synchronously on the CPU thread inside `ExecuteCommandLists` (with a 2 s timeout cap) is still an approximation of a GPU command-processor stall: it will time out if (a) a shader/UAV write earlier in the same unsubmitted list is the producer (not tracked in `written_ranges`), or (b) the title submits a wait on Queue A before submitting the producer on Queue B from the same thread. Happy to adjust any signatures once checked against a real trace, keep parts behind a flag/opt-in, or trim this down if you'd rather keep these slots as logged no-ops until real call sites are observed.
Author
Owner

@⁠oskpzme on GitHub · 2026-11-21 22:20 UTC · original

you're amazing man, keep it up just don't burn yourself out 😭

**@⁠oskpzme** on GitHub · 2026-11-21 22:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/23#issuecomment-7070114729) you're amazing man, keep it up just don't burn yourself out 😭
Author
Owner

@⁠ivall on GitHub · 2026-11-22 10:15 UTC · original

Merged in 7e74038 (conflicts with main resolved by hand), thanks.

One change on top: KickoffX resets the PC list mid-recording, and the Reset also clears state the title had set and keeps using afterwards - descriptor heaps, topology, viewports, scissors, blend factor, stencil ref, vertex buffers, render targets. On the console a kickoff leaves the list as it was. Without the heaps, a translated draw or dispatch after a kickoff indexes whatever heap is bound (garbage descriptors). That state is now tracked per list (console #20-#24, #32, #48, OMSetRenderTargets) and set again right after the Reset (restore_bindings in list_x.rs). Your test-title checks (KickoffX, Wait32/64, depth bias across KickoffX) all pass with it.

**@⁠ivall** on GitHub · 2026-11-22 10:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/23#issuecomment-7077675484) Merged in 7e74038 (conflicts with main resolved by hand), thanks. One change on top: KickoffX resets the PC list mid-recording, and the Reset also clears state the title had set and keeps using afterwards - descriptor heaps, topology, viewports, scissors, blend factor, stencil ref, vertex buffers, render targets. On the console a kickoff leaves the list as it was. Without the heaps, a translated draw or dispatch after a kickoff indexes whatever heap is bound (garbage descriptors). That state is now tracked per list (console #20-#24, #32, #48, OMSetRenderTargets) and set again right after the Reset (`restore_bindings` in list_x.rs). Your test-title checks (KickoffX, Wait32/64, depth bias across KickoffX) all pass with it.
This discussion has been locked. Commenting is limited to contributors.
No description provided.