Skip to content

D3D12.X: debug layer messages reach the log without ID3D12InfoQueue1 - #1008

Draft
madaraXor wants to merge 1 commit into
xcl-dev:mainfrom
madaraXor:d3d12-debug-messages-without-infoqueue1
Draft

madaraXor wants to merge 1 commit into
xcl-dev:mainfrom
madaraXor:d3d12-debug-messages-without-infoqueue1

Conversation

@madaraXor

Copy link
Copy Markdown

With XCL_D3D12_DEBUG=1, the debug layer's messages reached xcl.log only through an ID3D12InfoQueue1 message callback. Windows 10 has no ID3D12InfoQueue1: the cast fails with E_NOINTERFACE (measured on 19045 with the Agility SDK 1.620.2), the failure was ignored, and the log got no message at all. The debug layer was on but silent there, and test_title_draws_with_a_root_signature_under_the_debug_layer passed without seeing a single message.

Without ID3D12InfoQueue1, XCL now keeps the device's ID3D12InfoQueue, logs its stored messages with the same caps (8 per id, 3 000 in all) and clears it, at every submission and present (stop_if_device_removed). The messages that led to a device removal are logged before the removal. With ID3D12InfoQueue1 nothing changes.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: the fallback to ID3D12InfoQueue (poll_debug_messages, called first in stop_if_device_removed). The callback and the poll share log_debug_message.
  • crates/xcl/tests/debug_layer_log.rs (its own process): adds an application message to the debug layer's queue and expects it in the log after stop_if_device_removed. Skipped without the debug layer.

Tested

Regression run
main:

xcl-smoke v1
commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323
gpu: AMD Radeon RX 6700 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 1203 (PresentX 1204)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 11659 MB

This PR:

xcl-smoke v1
commit: 8dde8ff7ee96fa78068191a384f5467fe2108ca2
gpu: AMD Radeon RX 6700 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 1116 (PresentX 1117)
presents per 2 s (last 3): 60 60 34
device removals: 0
crashes: 0
peak commit: 13738 MB

The smoke runs do not turn the debug layer on: without it the new code is a lock on an empty slot.

Not tested

  • A system with ID3D12InfoQueue1 (Windows 11): the callback path is unchanged, but the new test was not run there (it should pass through the callback).
  • NVIDIA, Intel, Linux / Wine.
  • Messages added while the stored ones are read are cleared with them (the queue only empties as a whole); not measured how often that happens.

AI use

  • Claude Code, Claude Opus 5.5: found the missing messages while tracing the retail title on Windows 10, wrote the fix, the test and this description, and ran the tests and the runs above on my PC.

🤖 Generated with Claude Code

With XCL_D3D12_DEBUG=1, the debug layer's messages went to the log only
through an ID3D12InfoQueue1 message callback. Windows 10 has no
ID3D12InfoQueue1 (the cast fails with E_NOINTERFACE, measured on 19045
with the Agility SDK 1.620.2), the failure was ignored, and the log got no
message at all. test_title_draws_with_a_root_signature_under_the_debug_layer
passed there without seeing any.

Without ID3D12InfoQueue1 the device's ID3D12InfoQueue is kept, and its
stored messages are logged (same caps) and cleared at every submission and
present, in stop_if_device_removed, before a removal is reported.

The test adds an application message to the debug layer's queue and
expects it in the log after stop_if_device_removed. It fails on main on
Windows 10. On the retail title, the log now shows the debug layer's
errors (e.g. ids 538 and 1422) where it showed none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification, merged onto current main 384f7f7 locally (clean merge).

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

  • cargo test -p xcl --test debug_layer_log: 1 passed — debug_layer_messages_reach_the_log (the new integration test).

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

@jmal423

jmal423 commented Nov 24, 2026 •

Copy link
Copy Markdown

Windows 11 callback timing and per-ID cap on head 8dde8ff, RX 9070 XT (32.0.32029.2010), Windows Graphics Tools installed. I extended the integration test locally: required ID3D12InfoQueue1 on the real device, added the same application error 12 times, flushed the XCL log before the first stop_if_device_removed call, then called it twice and flushed again. Matching log lines: 8 before either call, 8 after both. This verifies immediate callback delivery and the 8-per-ID cap on this setup. The cap could also suppress duplicates, so the final count alone cannot establish whether polling was internally attempted. The Windows 10 fallback and concurrent writers were outside this test. AI use: Codex wrote and ran the scratch test and prepared this report.

Follow-up below the per-ID cap: I injected three identical application errors in fresh processes using the same scratch binary. Matching log lines before polling / after one poll / after a second poll: native callback 3/3/3; forced fallback 0/3/3. The only runtime instrumentation was a short-circuit around callback registration; the device, queue and polling implementation were real. This verifies deferred delivery and no duplicate on a second empty poll in this single-writer Windows 11 test. It does not simulate concurrent insertion or Windows 10 interface discovery.

Concurrent-writer measurement on the forced polling path (same Windows 11 setup): seven distinct text markers sharing one application message ID, below the cap of eight. Each AddApplicationMessage succeeded. In 12 fresh processes where the poller waited for the writer to finish, the log retained 84/84 markers. In 12 fresh processes where the poller called stop_if_device_removed in a tight loop alongside the writer, followed by a final poll after join, it retained 35/84 (per trial: 1,1,1,1,1,7,5,4,1,7,5,1). This measures the snapshot/clear limitation already disclosed in the PR under synthetic contention; it is not an estimate of retail message loss. No game files or device removal involved.

Reproducer patch for 8dde8ff (test instrumentation only)

Save the diff as queue.patch and run the following in PowerShell from the repository root. Change the adapter selector for other hardware. Run each mode in fresh processes several times because the concurrent case can pass. Count a run only if it prints observed=N/7. Without a real GPU backend or debug queue this integration test can return early and Cargo can still report success. The sequential control should print observed=7/7.

git apply queue.patch
$env:XCL_ADAPTER = '9070'
$env:XCL_LOCAL_TEST_POLL = '1'
Remove-Item Env:XCL_LOCAL_RACE -ErrorAction SilentlyContinue
cargo test --locked -p xcl --test debug_layer_log -- --nocapture
$env:XCL_LOCAL_RACE = '1'
cargo test --locked -p xcl --test debug_layer_log -- --nocapture
--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -529,7 +529,7 @@
             // through a callback where the system has ID3D12InfoQueue1; Windows 10 does not, and
             // there they are read from the device's message queue (`poll_debug_messages`)
             let mut cookie = 0u32;
-            let callback = device
+            let callback = std::env::var_os("XCL_LOCAL_TEST_POLL").is_none() && device
                 .cast::<ID3D12InfoQueue1>()
                 .is_ok_and(|q| q.RegisterMessageCallback(Some(debug_message), D3D12_MESSAGE_CALLBACK_FLAG_NONE, std::ptr::null_mut(), &mut cookie).is_ok());
             if !callback {
--- a/crates/xcl/tests/debug_layer_log.rs
+++ b/crates/xcl/tests/debug_layer_log.rs
@@ -26,13 +26,30 @@
         println!("SKIPPED debug_layer_messages_reach_the_log: no D3D12 debug layer");
         return;
     };
-    let text = "xcl test: a debug layer message";
-    let c = std::ffi::CString::new(text).unwrap();
-    unsafe { queue.AddApplicationMessage(D3D12_MESSAGE_SEVERITY_ERROR, PCSTR(c.as_ptr() as *const u8)) }.expect("AddApplicationMessage");
+    let racing = std::env::var_os("XCL_LOCAL_RACE").is_some();
+    let gate = std::sync::Arc::new(std::sync::Barrier::new(2));
+    let writer_gate = gate.clone();
+    let writer = std::thread::spawn(move || {
+        writer_gate.wait();
+        for i in 0..7 {
+            let text = std::ffi::CString::new(format!("xcl-local-race-{i}-end")).unwrap();
+            unsafe { queue.AddApplicationMessage(D3D12_MESSAGE_SEVERITY_ERROR, PCSTR(text.as_ptr().cast())) }.unwrap();
+            std::thread::yield_now();
+        }
+    });
+    gate.wait();
+    if racing {
+        while !writer.is_finished() {
+            real::stop_if_device_removed();
+        }
+    }
+    writer.join().unwrap();
     real::stop_if_device_removed();
     xcl::log::flush();
-    let log = std::fs::read_to_string(&path).unwrap_or_default();
+    let log = std::fs::read_to_string(&path).unwrap();
+    let observed = (0..7).filter(|i| log.contains(&format!("xcl-local-race-{i}-end"))).count();
+    println!("observed={observed}/7");
+    assert!(log.contains("D3D12: debug layer enabled"));
     let _ = std::fs::remove_dir_all(&dir);
-    assert!(log.contains("D3D12: debug layer enabled"), "the debug layer did not come up:\n{log}");
-    assert!(log.lines().any(|l| l.contains("D3D12 debug layer (error") && l.contains(text)), "the debug layer's message is not in the log:\n{log}");
+    assert_eq!(observed, 7, "messages lost before final poll");
 }

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.

3 participants