Skip to content

D3D12.X: retain pRootSignature in device_x::Base until forgotten - #1619

Open
oni-swr wants to merge 1 commit into
xcl-dev:mainfrom
oni-swr:d3d12x/retain-base-root-signature
Open

oni-swr wants to merge 1 commit into
xcl-dev:mainfrom
oni-swr:d3d12x/retain-base-root-signature

Conversation

@oni-swr

@oni-swr oni-swr commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

device_x::note_base copied raw D3D12_GRAPHICS_PIPELINE_STATE_DESC bytes into BASES without retaining pRootSignature. In D3D12 a title may release its ID3D12RootSignature immediately after CreateGraphicsPipelineState; later calls to CreateDerivedPipelineStateX or the RSSetDepthBiasX patched-PSO fallback would then pass a dangling pointer into CreateGraphicsPipelineState. Retain non-null pRootSignature in Base via ID3D12RootSignature::from_raw_borrowed().cloned() and release replaced or removed Base entries outside the BASES mutex lock. Part of #1488 (XCL-BT-005).

What is in it

Tested

  • Head d94caf384eb7b4dff9fb35a040e8fdfa419c3f57 on Windows 11 build 26200, Ryzen 7 5700X3D, Radeon RX 7800 XT (driver 32.0.31035.1003), Rust 1.100.0 MSVC, debug profile. The focused tests ran on the CPU.
  • cargo test -j 4 -p xcl --lib 'hle::d3d12x::device_x::tests::base_' -- --nocapture ran the root-signature and shader-bytecode lifetime tests. 2 passed, 0 failed, 0 ignored, 0 skipped, 2564 filtered out.

Regression run

  • The paired real-title smoke runs are pending for this head.

Not tested

  • Full workspace suite on GPU and real-title regression on main and this head.

AI use

@futurepro62

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 8cc8b6c (on its base 9e3831e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form: 776 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: base_retains_root_signature_until_forgotten.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 777 passed, 0 failed, 41 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • heap_window_out_of_memory_falls_back_to_the_switch_form was skipped with --skip. It fails on main 9e3831e too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWS unset). Reported as Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored.

Thanks!

@JJAutoCompare

Copy link
Copy Markdown

XCL PR #1619 focused Windows verification

Tested head 8cc8b6ce2b18e8bdbb6f3df577ab842ef0bd9cf0 on STOR-WINLAB from a clean detached checkout. The PR changes only crates/xcl/src/hle/d3d12x/device_x.rs.

Tested

  • Windows 11 Enterprise Evaluation x64, build 26200. AMD64 Family 23 Model 113 Stepping 0 (12 logical processors visible). Intel Arc A770 installed with driver 32.0.101.9175. DXC 1.9.2609.5 from the configured XCL tool directory. rustc 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc).
  • cargo build --workspace succeeded. cargo test --workspace --no-run compiled the workspace test binaries. Both ran outside the Arc lock with incremental compilation and debug info disabled.
  • cargo test -p xcl --lib hle::d3d12x::device_x::tests::base_retains_root_signature_until_forgotten -- --exact ran outside the Arc lock with XCL_ADAPTER=NONE_CPU_ONLY. Parsed pr1619-focused.log counts were 1 passed, 0 failed, 0 ignored, 0 skipped, with 748 filtered out.
  • The CPU fixture verified the descriptor field offset and used a fake COM object to check AddRef on registration, survival after the caller releases its reference and the base is forgotten while an Arc<Base> is held, final release after that Arc is dropped, and release on replacement. It also checked null root signatures and stream-output exclusion.

Not tested

Coverage was limited to full-workspace compilation and the focused PR test. The full GPU workspace suite, real D3D12 pipeline creation and retail-title smoke runs were omitted.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1619-focused.log and published.

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows run on 8cc8b6c. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11.

cargo build --workspace --offline --locked -j 4 passed. cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4 finished with 777 passed, 0 failed, 41 ignored, including three runtime skips in Cargo’s pass count. The stock root-signature ownership test passed.

With the D3D12 debug layer enabled and asynchronous PSO creation off, the scratch fixture verified that XCL kept its own root-signature reference. After dropping the caller's reference, both CreateDerivedPipelineStateX and the patched depth-bias pipeline helper created native pipelines. A repeat request returned the cached variant. The device stayed healthy, and releasing both base entries cleared their metadata and the cached variant.

cargo test --offline --locked -j 4 -p xcl --lib local_retained_root_signature_supports_native_derived_pipelines -- --nocapture --test-threads=1 passed 1 of 1 without skips. Synthetic pipeline creation and cleanup coverage.

AI use: Codex (GPT-6, exact variant unspecified) wrote the scratch fixture, ran the tests and drafted this report.

@oni-swr
oni-swr force-pushed the d3d12x/retain-base-root-signature branch 2 times, most recently from 3aa4690 to 717b198 Compare November 25, 2026 18:47
@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto origin/main and force-pushed (--force-with-lease).

Tested (CPU only, no GPU touched; debug build, Windows 11)

  • cargo build --workspace: finished, 0 errors (3 existing warnings in xcl lib)
  • XCL_ADAPTER=NONE_CPU_ONLY cargo test -p xcl --lib hle::d3d12x::device_x::tests::base_retains_root_signature_until_forgotten -- --exact: 1 passed, 0 failed, 0 ignored

Not tested

  • Full GPU workspace suite, release build, scripts/smoke.ps1 (no xcl-smoke blocks for this head), retail title

AI use: Claude Code (Claude Sonnet 5.5): resolved the rebase conflict and ran the build and test above.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

@oni-swr
oni-swr force-pushed the d3d12x/retain-base-root-signature branch from 717b198 to cec364b Compare November 28, 2026 03:32
@oni-swr

oni-swr commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (e429936, after #3085 and the #2959–#2962 stack). The only conflict was two additive test blocks in device_x.rs; both are kept and the PR's code is unchanged. New head: cec364b.

Tested (CPU/WARP only, XCL_WARP=1, no retail title, no smoke run): cargo test -p xcl --lib -j 4 d3d12x::device_x: 19 passed, 0 failed, 0 ignored, 0 skipped (includes base_retains_root_signature_until_forgotten). The full suite and a regression run were not repeated after this rebase.

AI use: Claude Code, Claude Sonnet 5.5 (rebase and targeted test run).

device_x::note_base copied the raw D3D12_GRAPHICS_PIPELINE_STATE_DESC bytes into BASES without retaining pRootSignature. In D3D12 a title may release a root signature right after CreateGraphicsPipelineState; later calls to CreateDerivedPipelineStateX or the RSSetDepthBiasX patched-PSO fallback would then pass a dangling pointer into CreateGraphicsPipelineState.

Retain a non-null pRootSignature via ID3D12RootSignature::from_raw_borrowed().cloned() inside Base and drop replaced or removed Base entries outside the BASES mutex lock.

Part of xcl-dev#1488 (XCL-BT-005).
Assisted-by: Antigravity (Gemini 4 Neon)

Rebased onto main and re-verified with Claude Code (Claude Sonnet 5.5).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Assisted-by: Codex (gpt-6.2-sol)
@oni-swr
oni-swr force-pushed the d3d12x/retain-base-root-signature branch from cec364b to d94caf3 Compare November 29, 2026 13:33
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head d94caf3

#1634 makes the same change: device_x::Base holds an ID3D12RootSignature taken from the desc's pRootSignature and releases it when the base is forgotten. This PR was opened first, is mergeable, and its test also covers a replaced entry and an in-flight Arc<Base>. It also drops the old base outside the BASES lock.
The Build and test check fails on this head. The log was not available, so it is not clear whether this change causes it.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@throny throny closed this Dec 1, 2026
@throny throny reopened this Dec 1, 2026
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants