Skip to content

D3D12.X: release the interface returned by QueryInterface - #1156

Open
gloger2003 wants to merge 1 commit into
xcl-dev:mainfrom
gloger2003:fix/d3d12-release-queried-interface
Open

gloger2003 wants to merge 1 commit into
xcl-dev:mainfrom
gloger2003:fix/d3d12-release-queried-interface

Conversation

@gloger2003

Copy link
Copy Markdown

D3D12 interface discovery now releases the reference through the interface returned by QueryInterface. In the DRED and debug-layer configuration, that pointer can belong to a different wrapper.

What is in it

  • Dispatch Release through the returned interface while keeping native dispatch when querying the same object.
  • Verify the call using two distinct interface tables.

Tested

  • Windows 11 26300.9974, RX 7800 XT (32.0.32029.2010), Ryzen 7 5700X, Rust 1.100.0 MSVC and DXC 1.9.2602.17.
  • The focused test failed before the change and passed after it. Workspace build and four-thread suite: 742 passed, 0 failed, 41 ignored, no explicit GPU capability skips.
  • With DRED and the D3D12 debug layer both enabled and identical 1x game settings, the baseline ended at startup. This exact head ran for 20 seconds, rendered 1,029 frames and exited cleanly. Resource-state warnings remain.

Regression run
Minecraft Preview 1.18.3064.0, normal D3D12 mode with identical 1x game profiles.

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 7800 XT
title: Xbox-Series-1.18.3064.0
seconds: 60
exit: 0x0
frames shown: 3463 (PresentX 3463)
presents per 2 s (last 3): 120 120 120
device removals: 0
crashes: 0
peak commit: 3342 MB

PR:

xcl-smoke v1
commit: 256b3f2929e58a466b51ae8ca4fa6dcffabdbe14
gpu: AMD Radeon RX 7800 XT
title: Xbox-Series-1.18.3064.0
seconds: 60
exit: 0x0
frames shown: 3469 (PresentX 3469)
presents per 2 s (last 3): 120 120 121
device removals: 0
crashes: 0
peak commit: 3359 MB

Not tested

  • Other GPU vendors, gameplay beyond the menu, and tests requiring external XCL_SAMPLE_* files.

AI use

  • OpenAI Codex (GPT-6, exact variant unavailable) investigated the startup, implemented the change and regression test, ran the tests, and drafted this description.

The DRED wrapper can return a different interface pointer. Dispatch Release through that pointer so the debug layer receives the matching interface.

Assisted-by: OpenAI Codex (GPT-6)
@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification on current main 384f7f7 (branch already contains it — clean).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.

  • cargo test -p xcl --lib d3d12x::real: 19 passed, 0 failed — the QueryInterface release fix doesn't disturb the existing real-backend tests.
  • The change releases the extra reference on the interface returned by QueryInterface when the caller's contract doesn't need it — matches the README note; refcount tests in gameinput::tests::query_interface_validates_iids_and_refcounts also pass.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

@JoaoPauluu

Copy link
Copy Markdown

A regression run under Wine on Linux, on a retail title.

Tested

Regression run

main (first run):

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1384 (PresentX 1384)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

this PR:

xcl-smoke v1
commit: 256b3f2929e58a466b51ae8ca4fa6dcffabdbe14
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1393 (PresentX 1393)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

The last main run: 1425 frames, exit: 0x0, no device removal, no crash. Under Wine, peak commit reads 0 MB, so these blocks do not check memory.

Not tested

  • the test suite on this head; native Windows; AMD.

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the runs and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…vall#1142, ivall#1150, ivall#1156, ivall#1182, ivall#1191, ivall#1195, ivall#1221

Integrate 10 high-impact open upstream PRs on top of upstream/main (930e8b4):
- ivall#1182: share video memory across render targets aliased onto one physical page (~1.85-2.1 GB VRAM saved)
- ivall#1142: declare tiled texture pools texture-only (D3D12_HEAP_FLAG_DENY_BUFFERS) for vkd3d-proton
- ivall#1097: report process memory under Wine via PagefileUsage fallback
- ivall#1078: bound BCPack record scratch memory to 2 KiB stack batches
- ivall#1150: convert console clear-value formats in CreatePlacedResource
- ivall#1156: release the interface returned by QueryInterface in class_for
- ivall#1139: check pointer alignment in is_adopted before dereferencing
- ivall#1195: skip ExecuteIndirect dispatch of untranslated console compute pipelines
- ivall#1191: VirtualProtect commits lazy pages in its range first
- ivall#1221: unmark lazy away mappings in FreeTitlePhysicalPages

Assisted-by: Antigravity (Google DeepMind)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…ll#1221, and updated Linux PRs

Update fork README for upstream/main 930e8b4 (BCPack BC1-BC7, XCL_PSO_WAIT_MS, low-VA ASLR < 2^40, alloc_pool, sparse tile parking/pool reuse, direct page moves, write-watch merge), newly integrated PRs (ivall#1078, ivall#1097, ivall#1139, ivall#1142, ivall#1150, ivall#1156, ivall#1182, ivall#1191, ivall#1195, ivall#1221), and updated Linux PRs (ivall#867, ivall#871, ivall#877).

Assisted-by: Antigravity (Google DeepMind)
@wondercrash

Copy link
Copy Markdown
Contributor

Tested on main 6020a33 + this PR (256b3f2 cherry-picked; same tree as the merge). With the D3D12 debug layer and DRED both on, main crashes at the first CreateCommandList, and this PR fixes it. Your unit test fails on main and passes here. The suite shows no regression.

Setup: RTX 5090 32 GB, NVIDIA 621.14 (32.0.16.2114), Ryzen 7 9800X3D, Windows 11 23H2 (10.0.22631.6199), inbox D3D12Core.dll and d3d12SDKLayers.dll 10.0.22621.5415 (no Agility SDK), DXC 1.8.2502.11 from Windows SDK 10.0.26100, Rust 1.96.0 MSVC, debug.

Tested

  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 6020a33 + this PR: 1149 passed, 6 failed, 46 ignored (not counting the scratch GPU check below, which ran in the same suite and passed).
    • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 fail with CreateComputePipelineState: ... (0x8007000E) (seeds 70, 545, 1019, 1507). The same four fail the same way on plain 6020a33, so they do not come from this PR.
    • frame::tests::origin_events_issue_tokens_and_flips_have_statistics ("4 origins at 60 Hz took 249 ms") and kernelx::tests::fine_timer_makes_short_sleeps_short ("Sleep(1) took 83 ms") are timing tests. Another heavy GPU/CPU job was running on the machine during the suite. Rerun in a filtered run of only these six tests, both pass on this PR and on 6020a33.
    • SKIPPED (24): 20 no wave64 (gpu::recomp::lower, lower_dxil, recomp::tests), 3 lower_dxil per-lane f16 forms refused (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.
  • class_probe_tests::class_probe_releases_the_queried_interface (your unit test, added alone to 6020a33): fails on main at real.rs:6578 and passes with the fix.
  • GPU check with the real debug layer and DRED, from a scratch integration test (below): XCL_D3D12_DEBUG=1 + XCL_DRED=1, D3D12.X real backend, then CreateCommandAllocator, CreateCommandList, Close, Reset and Close again.
    • 6020a33: the test process ends with 0xc0000005 STATUS_ACCESS_VIOLATION right after XCL wraps the command allocator, during CreateCommandList.
    • This PR: it passes. The log shows XCL adopting an ID3D12Resource2 with PC vtable D3D12Core.dll+0x14c238 (DRED's breadcrumb buffer, made through XCL's CreatePlacedResource hook and released through the debug layer's object) before the command list.

On the out == obj branch: we had made the same change on our side, but without that branch. Yours is better: in readopt the object already carries XCL's extended table, and its slot 2 is XCL's Release override (cl_release and the like), not the native one.

If you want the GPU check in the PR, here it is (crates/xcl/tests/debug_layer_dred.rs). It skips without a GPU or without the debug layer (Graphics Tools):

//! The D3D12 debug layer (`XCL_D3D12_DEBUG=1`) with DRED (`XCL_DRED=1`): making a command list,
//! the runtime makes DRED's breadcrumb buffer through the device's CreatePlacedResource – XCL's
//! hook – and gets back its own inner resource, which XCL adopts. Its QueryInterface answers
//! with the debug layer's object, which must be released through its own vtable.

use windows::core::Interface;
use windows::Win32::Graphics::Direct3D12::*;

use xcl::gpu::recomp::runner;
use xcl::hle::d3d12x::real;

#[test]
fn command_list_with_debug_layer_and_dred() {
    std::env::set_var("XCL_UMA_MB", "64");
    std::env::set_var("XCL_D3D12_DEBUG", "1");
    std::env::set_var("XCL_DRED", "1");
    if xcl::hle::d3d12x::backend() != xcl::hle::d3d12x::Backend::Real {
        return runner::skip_test("no GPU");
    }
    let raw = real::device_raw();
    let dev = unsafe { ID3D12Device::from_raw_borrowed(&raw) }.expect("backend device").clone();
    if dev.cast::<ID3D12InfoQueue>().is_err() {
        return runner::skip_test("no D3D12 debug layer (Graphics Tools)");
    }
    unsafe {
        let alloc: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).expect("allocator");
        let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &alloc, None).expect("command list");
        list.Close().expect("Close");
        alloc.Reset().expect("allocator Reset");
        list.Reset(&alloc, None).expect("list Reset");
        list.Close().expect("second Close");
    }
}

Not tested

  • A title run (smoke) on 6020a33 + this PR, with or without the debug layer.
  • The Agility SDK debug layer, AMD, Wine.
  • The readopt path (DMA lists) under the debug layer.

AI use: omp with Claude Opus 5.5 ran the tests above on the machine named, wrote the GPU check and this report; no code changes to this PR.

@jessenic

Copy link
Copy Markdown
Contributor

Test report: this PR fixes the start-up crash with XCL_DRED=1 and XCL_D3D12_DEBUG=1 together on an RTX 5070 Ti too. Under a debugger, the crash without it is the path this PR changes.

Setup: RTX 5070 Ti 16 GB (driver 610.88), Ryzen 7 9700X, Windows 11 Pro 26300, rustc 1.97.0, release. A retail title, on a local integration branch based on main 8f5fca5. This PR's 256b3f2 was cherry-picked on top cleanly.

  • Without this PR: 2 of 2 runs crashed at 3.9 s with 0xc0000005 in D3D12Core.dll+0x6047b (a read at 0x0), at the title's first CreateCommandListX. cdb (-o, D3D12 symbols from the Microsoft symbol server) gives this stack, outermost call at the bottom:
    D3D12Core!CLayeredObject<CBackingCommandAllocator>::CContainedObject::Release+0xb
    xcl!xcl::hle::d3d12x::real::class_for+0x1e5
    xcl!xcl::hle::d3d12x::real::dev_create_placed_resource+0x53f
    D3D12Core!Dred::CBreadcrumbBuffer::CBreadcrumbBuffer+0x1f3
    D3D12Core!CDevice::AllocateBreadcrumbBuffer+0x3f3
    D3D12Core!CGraphicsCommandList::FinalConstruct+0x153
    ...
    D3D12SDKLayers!NDebug::CDevice::CreateCommandList+0xeb
    xcl!xcl::hle::d3d12x::real::dev_create_command_list+0x96
    xcl!xcl::hle::d3d12x::device_x::create_command_list_x+0x49
    
    With DRED on, D3D12Core makes each list's breadcrumb buffer through the hooked CreatePlacedResource. class_for then probes the new object and calls Release through the original object's vtable on the interface QueryInterface returned, as the PR description says. The same build without XCL_D3D12_DEBUG started normally.
  • With this PR: the same setup (DRED and the debug layer both on) started and ran 158 s into the world. It ended at a device removal this title also has without DRED or the debug layer (Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505), not at start-up.
  • cargo test -p xcl --lib -- class_probe sparse on this tree: 23 passed, 0 failed, 1 ignored, including class_probe_releases_the_queried_interface.

Not tested: main alone; AMD; the full suite on this tree; not a scripts/smoke.ps1 regression run.

AI use: Claude Code (Claude Opus 5.5) ran the runs and cdb on the machine above and wrote this report.

@Swagi-REDACTED

Swagi-REDACTED commented Nov 25, 2026 •

Copy link
Copy Markdown

NVIDIA startup validation of this fix, encountered while diagnosing A newer retail game.

Hardware: Ryzen 7 9800X3D, RTX 3060 12 GB (621.14), approximately 16 GB RAM, Windows 11 Home 26200; Rust 1.95.0 MSVC, DXC/DXIL 1.9.2602.17.

Before: local integration cd3719f313a38e25fd45cf593145683a2922599a (#2057 reference plus #2046 and #541). With XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_UMA_SHADOW=1 XCL_DRED=1 XCL_D3D12_DEBUG=1 XCL_PSO_TRACE=1 XCL_COHERENT_MB=4095 XCL_NETWORK=0, xcl run <owned-title-folder> ended during startup with 0xc0000005, a null read in D3D12Core. Symbolicating the matching XCL/PDB located real::class_for and real::dev_create_placed_resource on the stack.

After: cherry-picked only 256b3f2929e58a466b51ae8ca4fa6dcffabdbe14 as local head 46ce479. The same configuration passes that startup point, adopts both native and debug-layer resource interfaces, visibly reaches profile selection, and advances into loading. It subsequently ended during world setup with a GPU hang (0x887a0006) and the title's error breakpoint. The startup access violation did not recur. Resource-state/command-list validation errors and a separate mesh-pipeline rejection remain; this does not establish world rendering or prologue completion.

Validation on the integrated tree:

  • cargo test --locked -p xcl --lib class_probe_releases_the_queried_interface -- --test-threads=1: 1 passed, 0 failed, 0 ignored; no explicit skips.
  • cargo test --locked --workspace -- --test-threads=4, direct/heap/shadow off: 1,202 passed, 0 failed, 46 ignored, 21 result blocks; 25 explicit skip events (20 native-wave64, 3 unsupported per-lane f16, 1 heap-window-disabled case, 1 PSO measurement requiring Developer Mode).
  • cargo test --locked -p xcl --lib gpu_ -- --test-threads=4, direct/heap/shadow on: 143 passed, 0 failed, 1 ignored; two native-wave64 skip events.
  • cargo build --locked --release --workspace: passed, 46.34 s.

This is not a clean main/PR-head smoke pair. Both sides also contained the same optional local input harness and a wrapping-arithmetic correction in the reference branch's texture-upload test-data generator. No assertions were weakened. No game data, dumps or screenshots are attached.

AI use: Codex, GPT-6 (exact serving variant not exposed), investigated the failure, integrated the existing patch, ran these commands and wrote this report. The interface fix remains its original author's work.

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.

6 participants