D3D12.X: share dispatch-chain root signatures per device and key compute blobs on NodeMask #2723

Open
github-bot wants to merge 1 commit from github-bot/gh-2723 into main AGit
Owner

@⁠ZekkJJ on GitHub · 2026-11-26 08:30 UTC · original
ZekkJJ:fix/dispatch-chain-rs-cache → main · +786 −40 · 5 files · 1 commits · draft

Caches dispatch_chain D3D12 root signatures per (device, static_samplers) instead of allocating a fresh root signature per split compute program, isolates per-device ABI root signatures, and includes NodeMask in COMPUTE_BLOBS cache keys.

Part of #2688 (Workstream 7) and relates to #2088. Based on main (b49be183).

What is in it

  • crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs:
    • Cache dispatch-chain ID3D12RootSignature handles in SIGNATURES keyed by (device_raw, sampler_words) so split compute programs on the same device share one COM root signature (outside the lock during CreateRootSignature and distinct across multiple D3D12 devices).
    • Because compute_container keys COMPUTE_BLOBS on the pipeline's rs handle, sharing the root signature allows split compute programs that share identical pieces (or rebuild a released split PSO) to reuse compiled driver blobs from COMPUTE_BLOBS via CachedPSO instead of allocating redundant root signatures and storing duplicate driver blobs.
    • Added GPU tests verifying root-signature reuse per device, device/sampler cache partitioning, and in-memory COMPUTE_BLOBS hits without duplicate entries across distinct split programs sharing a >= 16 KB cs_6_0 piece and across release/rebuild.
  • crates/xcl/src/hle/d3d12x/real.rs:
    • Track the owning device pointer for ABI_RS (ABI_RS_DEV / ABI_RS_BY_DEV) in abi_rs_raw, abi_rs_cached, and abi_root_signature so a second ID3D12Device in the same process never receives another device's ID3D12RootSignature.
    • Include copy.NodeMask in compute_blob_key_for (used by compute_container) while preserving compute_blob_key(..., 0) semantics for existing callers, plus unit and GPU tests.

Tested

  • Hardware: Windows 11, AMD Ryzen 7 8845HS, NVIDIA GeForce RTX 4060 Laptop GPU (driver 32.0.16.1656) + Microsoft Basic Render Driver (WARP), rustc 1.98.1, DXC 1.8.2502.11.
  • cargo build --locked --workspace -j 2: passed (0 errors).
  • cargo test --locked -j 2 -p xcl --lib hle::d3d12x::real::dispatch_chain::tests -- --test-threads=1: 4 passed; 0 failed; 0 ignored (1.23s; 0 skipped, verified on RTX 4060 + WARP).
  • cargo test --locked -j 2 -p xcl --lib hle::d3d12x::real::compute_blob_tests -- --test-threads=1: 3 passed; 0 failed; 0 ignored (0.16s; recorded_split_selects_cached_whole_or_pieces returned early without XCL_SAMPLE_RUNTIME_COMPUTE; abi_rs_raw_isolates_distinct_devices passed on RTX 4060 + WARP).
  • cargo test --locked -j 2 -p xcl --lib hle::d3d12x:: -- --test-threads=1: 257 passed; 0 failed; 2 ignored (16.36s; ignored timing benchmarks early_commit_timing and churn_update_tile_mappings_timing).
  • cargo test --locked -j 2 -p xcl --test gpu_compute_e2e -- --test-threads=1: 7 passed; 0 failed; 0 ignored (8.61s; SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows).
  • cargo test --locked -j 2 -p xcl --test e2e -- --test-threads=1: 4 passed; 0 failed; 0 ignored (19.14s).
  • git diff --check: passed (0 errors).

Regression run

  • Draft PR pending paired scripts/smoke.ps1 execution on an unpacked retail build and full workspace test sweep before marking ready for review.

Not tested

  • Full cargo test --workspace outside hle::d3d12x::, gpu_compute_e2e, and e2e; paired scripts/smoke.ps1 (no unpacked retail title directory on this machine); AMD / Intel hardware; Linux / Wine.

AI use

  • Google Antigravity (Gemini); assisted with root-cause analysis, implementation, hardware GPU tests, and PR preparation under author direction.
**@⁠ZekkJJ** on GitHub · 2026-11-26 08:30 UTC · [original](https://github.com/xcl-dev/xcl/pull/2723) `ZekkJJ:fix/dispatch-chain-rs-cache` → `main` · +786 −40 · 5 files · 1 commits · draft Caches `dispatch_chain` D3D12 root signatures per `(device, static_samplers)` instead of allocating a fresh root signature per split compute program, isolates per-device ABI root signatures, and includes `NodeMask` in `COMPUTE_BLOBS` cache keys. Part of #2688 (Workstream 7) and relates to #2088. Based on `main` (`b49be183`). **What is in it** - `crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs`: - Cache dispatch-chain `ID3D12RootSignature` handles in `SIGNATURES` keyed by `(device_raw, sampler_words)` so split compute programs on the same device share one COM root signature (outside the lock during `CreateRootSignature` and distinct across multiple D3D12 devices). - Because `compute_container` keys `COMPUTE_BLOBS` on the pipeline's `rs` handle, sharing the root signature allows split compute programs that share identical pieces (or rebuild a released split PSO) to reuse compiled driver blobs from `COMPUTE_BLOBS` via `CachedPSO` instead of allocating redundant root signatures and storing duplicate driver blobs. - Added GPU tests verifying root-signature reuse per device, device/sampler cache partitioning, and in-memory `COMPUTE_BLOBS` hits without duplicate entries across distinct split programs sharing a `>= 16 KB` `cs_6_0` piece and across release/rebuild. - `crates/xcl/src/hle/d3d12x/real.rs`: - Track the owning device pointer for `ABI_RS` (`ABI_RS_DEV` / `ABI_RS_BY_DEV`) in `abi_rs_raw`, `abi_rs_cached`, and `abi_root_signature` so a second `ID3D12Device` in the same process never receives another device's `ID3D12RootSignature`. - Include `copy.NodeMask` in `compute_blob_key_for` (used by `compute_container`) while preserving `compute_blob_key(..., 0)` semantics for existing callers, plus unit and GPU tests. **Tested** - Hardware: Windows 11, AMD Ryzen 7 8845HS, NVIDIA GeForce RTX 4060 Laptop GPU (driver `32.0.16.1656`) + Microsoft Basic Render Driver (WARP), `rustc 1.98.1`, DXC `1.8.2502.11`. - `cargo build --locked --workspace -j 2`: passed (`0` errors). - `cargo test --locked -j 2 -p xcl --lib hle::d3d12x::real::dispatch_chain::tests -- --test-threads=1`: `4 passed; 0 failed; 0 ignored` (`1.23s`; `0` skipped, verified on RTX 4060 + WARP). - `cargo test --locked -j 2 -p xcl --lib hle::d3d12x::real::compute_blob_tests -- --test-threads=1`: `3 passed; 0 failed; 0 ignored` (`0.16s`; `recorded_split_selects_cached_whole_or_pieces` returned early without `XCL_SAMPLE_RUNTIME_COMPUTE`; `abi_rs_raw_isolates_distinct_devices` passed on RTX 4060 + WARP). - `cargo test --locked -j 2 -p xcl --lib hle::d3d12x:: -- --test-threads=1`: `257 passed; 0 failed; 2 ignored` (`16.36s`; ignored timing benchmarks `early_commit_timing` and `churn_update_tile_mappings_timing`). - `cargo test --locked -j 2 -p xcl --test gpu_compute_e2e -- --test-threads=1`: `7 passed; 0 failed; 0 ignored` (`8.61s`; `SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows`). - `cargo test --locked -j 2 -p xcl --test e2e -- --test-threads=1`: `4 passed; 0 failed; 0 ignored` (`19.14s`). - `git diff --check`: passed (`0` errors). **Regression run** - Draft PR pending paired `scripts/smoke.ps1` execution on an unpacked retail build and full workspace test sweep before marking ready for review. **Not tested** - Full `cargo test --workspace` outside `hle::d3d12x::`, `gpu_compute_e2e`, and `e2e`; paired `scripts/smoke.ps1` (no unpacked retail title directory on this machine); AMD / Intel hardware; Linux / Wine. **AI use** - Google Antigravity (`Gemini`); assisted with root-cause analysis, implementation, hardware GPU tests, and PR preparation under author direction.
Part of #2688 (Workstream 7); relates to #2088. Cache dispatch_chain ID3D12RootSignature handles per (device, static_samplers) so split compute programs sharing pieces or rebuilding released PSOs hit COMPUTE_BLOBS instead of allocating per-program root signatures and duplicate driver blobs. Also isolate ABI_RS per device pointer and include NodeMask in compute_blob_key_for.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:35:21 +00:00
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 08:37 UTC · original · reviewed

At exact head 859da94 on current main b49be18, the new per-device ABI signature cache is not used by the command-list fallback for a second device. This is a source-derived review; I did not run a two-device title replay.

abi_rs_raw(this) now correctly stores a signature for each device, but abi_rs_cached() chooses using the process-wide device_raw() instead of the device that owns the list. console_list::close already has the actual PC list, yet obtains its fallback signature from that global lookup; bind.rs uses the same fallback. If device A is global and a translated PSO/list belongs to device B, a B signature can exist in ABI_RS_BY_DEV while the list receives A's signature, or close can report no XCL ABI root signature when A has none. The added abi_rs_raw_isolates_distinct_devices test checks cache creation and a B PSO, but never binds the fallback on B's command list.

Could the fallback lookup accept the owning device (for example from the list's GetDevice) and use that in both replay/bind paths? A two-device test with global A and a B list using a translated PSO with no own/static-sampler signature would exercise the new behavior end to end.

AI assistance: GPT-6.2 Sol found the missing device context; GPT-6.2 Astra independently checked the exact-head call sites and wording.

**@⁠luckyteagirl** on GitHub · 2026-11-26 08:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/2723#pullrequestreview-6070812537) · **reviewed** At exact head `859da94` on current main `b49be18`, the new per-device ABI signature cache is not used by the command-list fallback for a second device. This is a source-derived review; I did not run a two-device title replay. `abi_rs_raw(this)` now correctly stores a signature for each device, but `abi_rs_cached()` chooses using the process-wide `device_raw()` instead of the device that owns the list. `console_list::close` already has the actual PC list, yet obtains its fallback signature from that global lookup; `bind.rs` uses the same fallback. If device A is global and a translated PSO/list belongs to device B, a B signature can exist in `ABI_RS_BY_DEV` while the list receives A's signature, or `close` can report `no XCL ABI root signature` when A has none. The added `abi_rs_raw_isolates_distinct_devices` test checks cache creation and a B PSO, but never binds the fallback on B's command list. Could the fallback lookup accept the owning device (for example from the list's `GetDevice`) and use that in both replay/bind paths? A two-device test with global A and a B list using a translated PSO with no own/static-sampler signature would exercise the new behavior end to end. AI assistance: GPT-6.2 Sol found the missing device context; GPT-6.2 Astra independently checked the exact-head call sites and wording.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 08:43 UTC · original

Independent focused Windows check of exact PR head 859da94ed2ba8300719bf9ec9027f2f7eba4d6a6 in a clean detached checkout. Upstream main was b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7.

Tested

  • Windows 11 Home build 26200 on a Ryzen 9 5980HX laptop with Radeon RX 6800M (driver 30.0.13002.13003), Rust 1.99.0 MSVC; debug build with an isolated Cargo target.
  • With XCL_ADAPTER=6800M and XCL_REQUIRE_GPU=1 in the environment, ran cargo test --locked -p xcl --lib abi_rs_raw_isolates_distinct_devices -j 1 -- --test-threads=1 --nocapture: 1 passed, 0 failed, 0 ignored, no SKIPPED notice, 1,338 filtered out. The test creates a default hardware device and a WARP device, verifies separate cached ABI signatures, and creates a PSO on the second device.

Limitations

  • The test calls create_device(None) for its hardware device and does not print its adapter. The environment value alone does not prove that device was the RX 6800M. This check does not exercise the command-list fallback discussed in my review, the full workspace suite, or a retail title.

AI use

  • OpenAI Codex (GPT-6.2 Astra) ran the exact-head test, verified the test source and log, and wrote this report.
**@⁠luckyteagirl** on GitHub · 2026-11-26 08:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/2723#issuecomment-7186950410) Independent focused Windows check of exact PR head `859da94ed2ba8300719bf9ec9027f2f7eba4d6a6` in a clean detached checkout. Upstream main was `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7`. **Tested** - Windows 11 Home build 26200 on a Ryzen 9 5980HX laptop with Radeon RX 6800M (driver `30.0.13002.13003`), Rust 1.99.0 MSVC; debug build with an isolated Cargo target. - With `XCL_ADAPTER=6800M` and `XCL_REQUIRE_GPU=1` in the environment, ran `cargo test --locked -p xcl --lib abi_rs_raw_isolates_distinct_devices -j 1 -- --test-threads=1 --nocapture`: **1 passed, 0 failed, 0 ignored, no `SKIPPED` notice**, 1,338 filtered out. The test creates a default hardware device and a WARP device, verifies separate cached ABI signatures, and creates a PSO on the second device. **Limitations** - The test calls `create_device(None)` for its hardware device and does not print its adapter. The environment value alone does not prove that device was the RX 6800M. This check does not exercise the command-list fallback discussed in my review, the full workspace suite, or a retail title. **AI use** - OpenAI Codex (GPT-6.2 Astra) ran the exact-head test, verified the test source and log, and wrote this report.
Author
Owner

@⁠Lum7nt on GitHub · 2026-11-26 09:03 UTC · original

Tested on \859da94ed2\ (\859da94e, clean PR head):

  • Hardware / OS / Toolchain: NVIDIA GeForce RTX 3060 12 GB (driver \32.0.15.8142\ / 581.42, wave32), Intel Core i5-10400, Windows 11 (NT \10.0.22631.0),
    ustc 1.100.0\ (\x86_64-pc-windows-msvc), DXC \1.8.2502.11\ (Windows SDK \10.0.26100.0), debug profile, \XCL_ADAPTER=nvidia, Windows Developer Mode off.
  • Focused runs:
    • \cargo test -p xcl --lib hle::d3d12x::real::compute_blob_tests -- --test-threads=1 --nocapture: 3 passed, 0 failed, 0 ignored (\bi_rs_raw_isolates_distinct_devices\ passed on RTX 3060 + WARP;
      ecorded_split_selects_cached_whole_or_pieces\ returned early without \XCL_SAMPLE_RUNTIME_COMPUTE).
    • \cargo test -p xcl --lib hle::d3d12x::real::dispatch_chain::tests -- --test-threads=1 --nocapture: 3 passed, 1 failed, 0 ignored — \split_programs_sharing_large_piece_hit_compute_blobs_and_reuse_root_signature\ panicked at \crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs:436:13\ (\shared piece driver blob should be stored once in COMPUTE_BLOBS: left: 0, right: 1). On this driver (\581.42), \ID3D12PipelineState::GetCachedBlob()\ fails (\
**@⁠Lum7nt** on GitHub · 2026-11-26 09:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/2723#issuecomment-7187350930) **Tested** on \859da94ed2ba8300719bf9ec9027f2f7eba4d6a6\ (\859da94e\, clean PR head): - **Hardware / OS / Toolchain:** NVIDIA GeForce RTX 3060 12 GB (driver \32.0.15.8142\ / 581.42, wave32), Intel Core i5-10400, Windows 11 (NT \10.0.22631.0\), \ ustc 1.100.0\ (\x86_64-pc-windows-msvc\), DXC \1.8.2502.11\ (Windows SDK \10.0.26100.0\), debug profile, \XCL_ADAPTER=nvidia\, Windows Developer Mode off. - **Focused runs:** - \cargo test -p xcl --lib hle::d3d12x::real::compute_blob_tests -- --test-threads=1 --nocapture\: **3 passed, 0 failed, 0 ignored** (\bi_rs_raw_isolates_distinct_devices\ passed on RTX 3060 + WARP; \ ecorded_split_selects_cached_whole_or_pieces\ returned early without \XCL_SAMPLE_RUNTIME_COMPUTE\). - \cargo test -p xcl --lib hle::d3d12x::real::dispatch_chain::tests -- --test-threads=1 --nocapture\: **3 passed, 1 failed, 0 ignored** — \split_programs_sharing_large_piece_hit_compute_blobs_and_reuse_root_signature\ panicked at \crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs:436:13\ (\shared piece driver blob should be stored once in COMPUTE_BLOBS: left: 0, right: 1\). On this driver (\581.42\), \ID3D12PipelineState::GetCachedBlob()\ fails (\
Author
Owner

@⁠ZekkJJ on GitHub · 2026-11-26 09:04 UTC · original

Updated PR head to cfbaaace (cfbaaace9b2a0bffd433512b80163e2370a9c9b1) addressing all review items, including @⁠luckyteagirl's multi-device command-list fallback finding:

  • Command-list owning device lookup (abi_rs_cached_for_list): Added abi_rs_cached_for_list(&ID3D12GraphicsCommandList) in crates/xcl/src/hle/d3d12x/real.rs using list.GetDevice(&mut dev) (with readable and non-null vtable slot 7 guards for synthetic unit mocks) so real command lists use their owning device exclusively and never fall back to global device_raw() / ABI_RS. Updated both console_list::close (console_list.rs:743) and bind::bind_abi (bind.rs:1045) to call abi_rs_cached_for_list.
  • Two-device command-list fallback E2E test: Added hle::d3d12x::bind::tests::two_device_command_list_fallback_isolates_bind_abi_and_console_list in crates/xcl/src/hle/d3d12x/bind.rs, exercising global Device A + real Device B command lists and a translated compute PSO without PSO_RS across both phases (None / "no XCL ABI root signature" refusal before Device B caches an ABI RS, and binding Device B's rs_b onto Device B's lists in both bind_abi and console_list::close).
  • COM device normalization, samplers, child lifetime, NodeMask, and panic safety: Normalized canonical_device_key across interfaces (IUnknown cast with mock vtable guards), isolated ABI_RS_SAMPLERS per (dev_key, sampler_words), validated SIGNATURES hits via GetDevice with signature_retention_and_device_child_lifetime, added driver_cache::name_for_node / path_for_node for non-zero NodeMask in compute_container (keeping NodeMask == 0 filenames unchanged), and replaced test fixture cleanup in dispatch_chain.rs with RAII FixtureCleanup.

Remaining Draft blocker: PR #2723 remains Draft until paired scripts/smoke.ps1 runs on main (b49be183) and cfbaaace9b2a on a host with an unpacked retail title.

**@⁠ZekkJJ** on GitHub · 2026-11-26 09:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/2723#issuecomment-7187391510) Updated PR head to `cfbaaace` (`cfbaaace9b2a0bffd433512b80163e2370a9c9b1`) addressing all review items, including @⁠luckyteagirl's multi-device command-list fallback finding: - **Command-list owning device lookup (`abi_rs_cached_for_list`)**: Added `abi_rs_cached_for_list(&ID3D12GraphicsCommandList)` in `crates/xcl/src/hle/d3d12x/real.rs` using `list.GetDevice(&mut dev)` (with readable and non-null vtable slot 7 guards for synthetic unit mocks) so real command lists use their owning device exclusively and never fall back to global `device_raw()` / `ABI_RS`. Updated both `console_list::close` (`console_list.rs:743`) and `bind::bind_abi` (`bind.rs:1045`) to call `abi_rs_cached_for_list`. - **Two-device command-list fallback E2E test**: Added `hle::d3d12x::bind::tests::two_device_command_list_fallback_isolates_bind_abi_and_console_list` in `crates/xcl/src/hle/d3d12x/bind.rs`, exercising global Device A + real Device B command lists and a translated compute PSO without `PSO_RS` across both phases (`None` / `"no XCL ABI root signature"` refusal before Device B caches an ABI RS, and binding Device B's `rs_b` onto Device B's lists in both `bind_abi` and `console_list::close`). - **COM device normalization, samplers, child lifetime, `NodeMask`, and panic safety**: Normalized `canonical_device_key` across interfaces (`IUnknown` cast with mock vtable guards), isolated `ABI_RS_SAMPLERS` per `(dev_key, sampler_words)`, validated `SIGNATURES` hits via `GetDevice` with `signature_retention_and_device_child_lifetime`, added `driver_cache::name_for_node` / `path_for_node` for non-zero `NodeMask` in `compute_container` (keeping `NodeMask == 0` filenames unchanged), and replaced test fixture cleanup in `dispatch_chain.rs` with RAII `FixtureCleanup`. Remaining Draft blocker: PR #2723 remains Draft until paired `scripts/smoke.ps1` runs on `main` (`b49be183`) and `cfbaaace9b2a` on a host with an unpacked retail title.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2723/head:github-bot/gh-2723'
git switch 'github-bot/gh-2723'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2723'
git switch 'github-bot/gh-2723'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2723'
git switch 'github-bot/gh-2723'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2723'
git switch 'main'
git merge --squash 'github-bot/gh-2723'
git switch 'main'
git merge --ff-only 'github-bot/gh-2723'
git switch 'main'
git merge 'github-bot/gh-2723'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.