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

  • crates/xcl/src/hle/d3d12x/device_x.rs: retain pRootSignature in Base on note_base, drop old Base entries outside the BASES lock in note_base / forget_base / register_test_base, and add unit test base_retains_root_signature_until_forgotten. Rebased onto main 379725a; the only conflict was the end of the tests module, where both tests were kept.

Tested

  • Head 3aa4690173e1651d4d51a5681e927f88b01edb88, no uncommitted changes.
  • AMD Radeon RX 7800 XT, Windows 11 Pro build 26200, Rust 1.100.0 MSVC. Tests in debug, smoke runs in release.
  • cargo test -p xcl --lib hle::d3d12x::device_x::tests::base_retains_root_signature_until_forgotten -- --exact: 1 passed / 0 failed.
  • cargo build --workspace and cargo build --release -p xcl: passed.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1254 passed / 1 failed / 46 ignored. The one failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722, res[30] = 0x1, CPU 0x7fffffff). It fails the same way on clean main 379725a on this GPU (run separately: 0 passed / 1 failed), so it is not caused by this PR.
  • SKIPPED (7 lines, not coverage): f16_programs_on_the_gpu x4 and f32_programs_on_the_gpu x2 (unsupported V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32, gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426), and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

Regression run

same title, 60 s, release, same GPU; first main, then this PR's head

xcl-smoke v1
commit: 379725aefffe3023696f2f8c784315f7a6fbc318
gpu: AMD Radeon RX 7800 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1375 (PresentX 1376)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15784 MB
xcl-smoke v1
commit: 3aa4690173e1651d4d51a5681e927f88b01edb88
gpu: AMD Radeon RX 7800 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1570 (PresentX 1570)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15871 MB

Not tested

  • NVIDIA, Intel, Wine. The retail title smoke run checks the runtime for regressions; it does not exercise a title releasing a root signature before CreateDerivedPipelineStateX or the patched-PSO RSSetDepthBiasX fallback. No claim of title performance improvement.
  • One workspace test fails on this GPU, on main too (see above).

AI use

  • T3 Code / Antigravity (Gemini 4 Neon): original fix, unit test and description.
  • Claude Code (Claude Sonnet 5.5): rebased onto main, resolved the conflict, reran the build, test suite and both smoke runs, and rewrote this description.

🤖 Generated with Claude Code

@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

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 from 8cc8b6c to 3aa4690 Compare November 25, 2026 13:32
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>
@oni-swr
oni-swr force-pushed the d3d12x/retain-base-root-signature branch 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.

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.

5 participants