Skip to content

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

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
raylitebull:list-x-extensions
Nov 22, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
raylitebull:list-x-extensions

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

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):
  2. KickoffX (Loader: under Wine, PEB.ImageBaseAddress keeps the real main image #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 (GPU tests: run wave64 kernels as two wave32 halves on 32-lane GPUs #71/recomp: f64 abs / neg modifiers on the sign bit #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.

@oskpzme

oskpzme commented Nov 21, 2026

Copy link
Copy Markdown

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

@ivall
ivall merged commit 7e74038 into xcl-dev:main Nov 22, 2026
@ivall

ivall commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

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 added a commit that referenced this pull request Nov 22, 2026
…ads, console heaps and resources, merged ES+GS

- Run from <Game>/Binaries/XSX: the package root is the folder above whose
  MicrosoftGame.config names the exe.
- XMemGetWorkingSetStatistics writes only the limit and the use (the structure
  differs between GDK versions; zeroing 0x78 bytes broke EOSSDK's stack cookie).
- The title's executable takes TLS slot 0, as a process's executable has it
  (code built with /GA reads it without _tls_index); xcl.exe's TLS moves.
- Command queue #23 SignalX.
- Title textures: the first upload waits for the title's next submit and all
  uploads go in batches (one list, one wait); XCL's own submits do not refresh;
  close write-watch ranges are scanned as one. The render thread no longer stalls
  in CreatePlacedResourceX (UE's garbage collector ended the game after 10 s).
- CreateHeap and CreatePlacedResource (#29) with console flags / layouts retried
  the PC's way.
- Merged ES+GS of older kits: an ES program ends with s_setpc_b64 into the GS.
- end_title suspends the title's threads before releasing its fences (a running
  title reset command allocators the GPU still ran: device hang at the end).
- Diagnostics: stack-cookie failures reported with the function, the CRT's
  invalid-parameter handler, first-chance C++ exceptions of title code,
  THREADNAME_INFO, XCL_THREAD_DUMP_AT (unwound stacks), XCL_ACTIVITY.
- HANDOFF: Fortnite's state (splash screen; the login is an Xbox Live sign-in).
raylitebull pushed a commit that referenced this pull request Nov 25, 2026
Part of #480.

Add integration tests comparing D3D12.X runtime wrappers against host
ID3D12Device objects and console ABI contracts across:
- ID3D12Resource Map, Unmap, GetGPUVirtualAddress (including lazy
  TITLE_ADDRESS texture fallback and UMA buffer placement), and
  WriteToSubresource
- ID3D12DescriptorHeap console slot #9/#10 start handles and
  console_heap::start lifecycle on host and console #14 heaps
- ID3D12CommandQueue GetDesc, GetTimestampFrequency,
  GetClockCalibration (host parity and pre/post-QUEUE_OLDER console
  calls), ExecuteCommandLists, Wait, Signal, and SignalX (#23)
- ID3D12Fence slot #12 64-byte-aligned completed-value cell and CPU
  Signal updates, plus ID3D12CommandAllocator::Reset (#8)

Verified on AMD Radeon RX 9070 XT (debug, release, XCL_D3D12_DEBUG=1),
AMD Radeon(TM) Graphics, and WARP.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants