Skip to content

D3D12.X: retain graphics root signature across bind state - #1925

Open
n-romanovich wants to merge 1 commit into
xcl-dev:mainfrom
n-romanovich:d3d12x/bind-retain-gfx-rootsig
Open

n-romanovich wants to merge 1 commit into
xcl-dev:mainfrom
n-romanovich:d3d12x/bind-retain-gfx-rootsig

Conversation

@n-romanovich

Copy link
Copy Markdown
Contributor

Fixes #1488.

State.rs_gfx previously stored the graphics root signature as an unretained raw usize, causing a COM use-after-free in graphics_bound or execute_indirect if the title released its ID3D12RootSignature reference after SetGraphicsRootSignature. execute_indirect also bound rs_gfx even on COMPUTE command lists.

This PR retains ID3D12RootSignature in State.rs_gfx (when adopted via real::is_adopted) and restricts execute_indirect's graphics root signature binding to non-dispatch indirect signatures on non-COMPUTE command lists.

What is in it

  • crates/xcl/src/hle/d3d12x/bind.rs:
    • Change State::rs_gfx from usize to Option<ID3D12RootSignature>, retaining adopted objects in set_graphics_root_signature, cloning in inherit_for_split, and clearing on reset, clear_state, and forget.
    • In execute_indirect, only bind s.rs_gfx when !signature_dispatches(sig) and list.GetType() != D3D12_COMMAND_LIST_TYPE_COMPUTE (checking s.rs_gfx before calling GetType()).
    • Add unit test graphics_root_signature_is_retained_and_skipped_on_compute_ei.

Tested
Hardware: Windows 11 x64, NVIDIA GeForce RTX 5060 Ti.

  • cargo test -p xcl --lib bind::tests -- --test-threads=4: 7 passed, 0 failed, 0 ignored (945 filtered out)
  • cargo test --workspace -- --test-threads=4: 976 passed, 0 failed, 45 ignored
    • SKIPPED: gpu::recomp wave64 and unsupported per-lane f16 tests (21 skipped: no wave64 / refused per-lane f16), shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode is required, 0x887A002D), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)

Regression run
Main (689f2db477c3c062cf162649781640ef8a977c18):

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 5060 Ti
title: FILES
seconds: 60
exit: 0x0
frames shown: 1483 (PresentX 1483)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17342 MB

PR (cfd026db9ff9ddd9c9cde6ba6d540c492e6543a7):

xcl-smoke v1
commit: cfd026db9ff9ddd9c9cde6ba6d540c492e6543a7
gpu: NVIDIA GeForce RTX 5060 Ti
title: FILES
seconds: 60
exit: 0x0
frames shown: 1564 (PresentX 1564)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17360 MB

Not tested

  • macOS / Linux (crate targets Windows only).
  • AMD / wave64-capable GPU.

AI use

  • Antigravity (model name not provided): implemented the fix and unit test, ran the test suite and smoke.ps1 runs, and audited the diff with an independent subagent.

Addresses xcl-dev#1488.

State.rs_gfx stored the graphics root signature as an unretained raw
usize, causing a COM use-after-free in graphics_bound or execute_indirect
if the title released its reference after SetGraphicsRootSignature.
execute_indirect also bound rs_gfx on COMPUTE command lists.

Store Option<ID3D12RootSignature> in State.rs_gfx (retaining adopted
objects via from_raw_borrowed), and in execute_indirect only bind rs_gfx
for non-dispatch signatures on non-COMPUTE lists.

Tested: cargo test --workspace -- --test-threads=4 (976 passed, 0 failed, 45 ignored).

Assisted-by: Antigravity (model name not provided)
@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head cfd026d (on its base 689f2db).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, 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 --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::dxil::fuzz_tests: 966 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: graphics_root_signature_is_retained_and_skipped_on_compute_ei.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 975 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 62265d3 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (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) and the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

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.

@raylitebull

Copy link
Copy Markdown
Member

Code review on cfd026d:

  • Changing State.rs_gfx in crates/xcl/src/hle/d3d12x/bind.rs to retain an Option<ID3D12RootSignature> (only when real::is_adopted(rs)), propagating it in inherit_for_split, and guarding execute_indirect with !signature_dispatches(sig) and list.GetType() != D3D12_COMMAND_LIST_TYPE_COMPUTE cleanly prevents dangling raw root-signature pointers and invalid SetGraphicsRootSignature calls on compute command lists.
  • Diff audited and CI workflow approved (running).

Remaining before merge: Build and test finishing green plus AMD verification on cfd026d.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@JJAutoCompare

Copy link
Copy Markdown

PR #1925 compatibility verification

Commit cfd026db9ff9ddd9c9cde6ba6d540c492e6543a7 (detached PR head). The change keeps an owned COM reference to the title's graphics root signature in bind state, clones it when splitting a command list, and clears it on reset or clear-state. The PC fallback for ExecuteIndirect skips the graphics bind for dispatch signatures and compute lists.

Tested

  • STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave sizes 8–32, DoublePrecisionFloatShaderOps=0). Rust 1.100.0 (0ef1bc386), DXC/DXIL 1.9.2609.5, XCL_ADAPTER=A770, unoptimized builds with debug info disabled.
  • cargo build --workspace and cargo test --workspace --no-run both succeeded.
  • cargo test -p xcl hle::d3d12x::bind::tests -- --nocapture reported 7 passed, 0 failed, 0 ignored, and no skips. The new regression exercised retention after caller release, split inheritance, clearing, and the compute-list guard using a mock command list.
  • cargo test -p xcl test_title_draws_with_a_root_signature_under_the_debug_layer -- --nocapture reported 1 skip because d3d12SDKLayers.dll is missing. The harness reported ok after the early return.

Workspace suite

cargo test --workspace --no-fail-fast -- --test-threads=4 ran once under the shared Arc lock and exited 101. Across 20 harness summaries, Cargo reported 951 passed, 25 failed, 45 ignored. The new regression passed again.

  • 24 library failures. Twenty DXIL/recompiler tests failed at CreateComputePipelineState (0x80070057), including FP64 cases. Four showed result mismatches in fused multiply-add, implicit mip LOD, f16 lane packing, or pixel wave reduction.
  • One test-title failure. The title rendered and read back a triangle on the A770, then reported a blue pixel where the dynamic depth-bias check expected green.
  • 22 SKIPPED lines in pr1925-suite.log (17 no wave64, 3 refused wave32 per-lane forms, 1 driver cache could not be disabled, 1 no heap windows). The separate targeted run exposed the debug-layer skip, which Cargo captured in the workspace run. Skip lines can count subcases, and skips provide no coverage.

Not tested

Debug-layer draw assertions, retail-title smoke, release builds, and other adapters. The workspace failures were measured on the PR head only, so their status on main is unverified.

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 pr1925-suite.log and published this report.

@luckyteagirl

Copy link
Copy Markdown

Tested

  • Exact PR head cfd026db9ff9ddd9c9cde6ba6d540c492e6543a7 on Windows 11 build 26200, Ryzen 9 5980HX, AMD Radeon RX 6800M driver 30.0.13002.13003 (plus an AMD integrated GPU), Rust 1.99.0 MSVC, DXC/DXIL 1.9.2609.5. XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=1, and XCL_DIRECT_DXIL=0 were set for the test commands.
  • cargo test --locked -p xcl --lib -j 2 hle::d3d12x::bind::tests::graphics_root_signature_is_retained_and_skipped_on_compute_ei -- --exact --test-threads=1 --nocapture: 1 passed, 0 failed, 0 ignored, no explicit skip. The test creates a D3D12 device using the system default adapter, with a WARP fallback; it does not use XCL_ADAPTER to select its device, and I did not record that device's LUID.
  • The full hle::d3d12x::bind::tests group: 7 passed, 0 failed, 0 ignored. The broader hle::d3d12x:: subset: 156 passed, 0 failed, 2 ignored, with one explicit SKIPPED line because this adapter makes no reserved cube with mips. Both subset runs used one test thread.
  • cargo build --locked --workspace -j 2 and cargo build --locked --release -p xcl -j 2: passed.

Smoke attempt

Two monitored 7-second runs of a locally owned title on the RX 6800M reached the first frame. The first logged the XCL_RUN_SECONDS: 7 s end marker; the second was stopped just after its 6-second activity sample. In both, low system commit availability triggered the local memory guard before scripts/smoke.ps1 could write its xcl-smoke v1 summary. Neither attempt is a completed smoke result, and there is no paired main run to compare. I have not counted them as a pass.

Not tested

  • A completed paired title smoke, the full workspace suite, the exact LUID of the focused test's default D3D12 device, longer gameplay, or other drivers and GPUs. The short title attempts logged zero draws, so they did not exercise root-signature binding in game draws.

AI use

OpenAI Codex (GPT-6, exact variant not exposed in this session) inspected the diff, ran the builds and tests, monitored the smoke attempts, reviewed their logs, and drafted this report.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA test of cfd026d merged on main 80f4819 with #684: 10 runs of 100 s of a retail title with it, 5 without. 9 of the 10 with it stopped presenting at 74.7 to 92.2 s (without it: 78.2 to 99.6 s); 1 stopped at 52 s and ended at the title's stall watchdog. I found nothing that ties that stall to the change.

Setup: Fedora 44, Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, RTX 4070 12 GB (driver 615.71.09), 62 GB RAM. Release, cross-compiled to x86_64-pc-windows-gnu (rustc 1.98.0), XCL_PSO_PRELOAD=0. Retail title 1.0.2.1, the first-run screens completed once and no story progress, A pressed when the title presents steadily.

Tested

100 s without (5 runs) with cfd026d (10 runs)
frames 1377, 1405, 1420, 1566, 1357 1325, 1251, 1412, 1416, 1544, 1289, 1307, 1410, 1383, 1312
last 2 s with a present 78.2, 99.6, 90.8, 90.5, 84.1 s 76.2, 52.0, 86.4, 92.2, 84.1, 74.7, 76.1, 78.1, 86.3, 76.6 s
ended at game+0x23cf683 (the stall watchdog) 0 1 (the second, at 93.6 s)
draws skipped, with PC pipelines; dispatches skipped (last count line) 0, 0; 0 in each 0, 0; 0 in each
device removals, NVIDIA kernel messages 0 0
  • The run that stalled: XCL's activity thread logged at 52.0 s and the memory line it prints straight after came at 62.6 s; no later line has a draw or a present. That memory line reads XCL's page, pool and arena tables and DXGI's budget, not the bind state (host.rs:65-68), and it was late without the change too, by 3.3 s and 1.1 s in two runs. The audio thread kept time throughout. No thread dump was taken.
  • The kernel logged nothing during that run, and write errors on its compressed swap during 9 of the 14 others, so low memory does not single it out.

Read

  • bind.rs:177: the reference is kept only for a root signature XCL adopted, and every one the title gets is adopted where it is made (real.rs:5259 at cfd026d). Root signatures have no Release hook of XCL's, so taking and dropping the reference under the bind state's lock waits on nothing of XCL's.

Not tested: the bind the change is for (every run's last count line has 0 draws with PC pipelines); a title that releases its root signature before a draw; Windows; AMD and Intel; past 100 s.

AI use: Claude Code (Claude Fable 5.2) read the diff, built the trees, ran the title and the tests, and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

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.

Tracking & Static Audit: 50 New Source-Level Bugs + 150 Prioritized Backlog Items [Part 1/3]

7 participants