Skip to content

D3D12.X: report debug layer messages by id, and gate new ids in smoke - #2039

Open
brandostrong wants to merge 2 commits into
xcl-dev:mainfrom
brandostrong:d3d12x-debug-layer-report
Open

brandostrong wants to merge 2 commits into
xcl-dev:mainfrom
brandostrong:d3d12x-debug-layer-report

Conversation

@brandostrong

@brandostrong brandostrong commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The debug layer's messages reach XCL's log, but only the first 8 of each message id are printed: a run that hit one 5 151 times looked like eight hits. report.json now carries d3d12.debug_layer – every message counted, by id, with the first text of each id – smoke.ps1 -DebugLayer prints debug layer messages: 538x5151 745x5307 from it, and pr_check.py refuses a PR whose run shows ids main's run did not: new validation errors, which frames and peak commit say nothing about. Ids main's run showed and the PR's no longer shows are a fix, not a problem.

Part of the validation line claimed on #1269.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: the per-id counts, already in the callback but a local static nothing could read, become a module static; every message is counted, the first text of each id is kept, and both reach report.json as d3d12.debug_layer. debug_layer_counts_from turns a map into the report form, so the report test works on its own map and never touches the global one. Two unit tests (counted past the cap, ids in order with the first text cut to 200 characters).
  • scripts/smoke.ps1: a -DebugLayer switch and the debug layer messages: line – n/a when the layer was off, none when there were none. The caller's own XCL_D3D12_DEBUG is restored after the run, not deleted.
  • scripts/pr_check.py: smoke_ids and the new-id comparison, only between blocks that both report them.
  • scripts/test_pr_check.py: new ids fail; same, fewer, n/a and no line all pass.

Tested

  • NVIDIA GeForce RTX 4090 (driver 32.0.16.1664), i9-13900K, Windows 11 Pro 26200, rustc 1.100.0, debug and release
  • on the head 1039318: cargo build --workspace then cargo test --workspace -- --test-threads=4: 1156 passed, 0 failed, 46 ignored; 24 GPU tests skipped (20 no wave64, 1 no heap windows, 3 refused on the gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics)
  • python scripts/test_pr_check.py: OK, 15 tests; pwsh scripts/smoke-title.tests.ps1: smoke-title: ok
  • the switch is a switch: with a fixture xcl, XCL_D3D12_DEBUG is set only when -DebugLayer is passed and does not leak after the run; the line renders from a fixture report.json as 538x5151, n/a and none
  • a 150 s debug-layer run of a retail title, release build of this branch (before the switch and the first-text field were added, so its report.json has the counts and not the texts): 13 273 messages counted against 57 lines in the log – 538×5 151 resource-state errors, 745×5 307 GetGPUVirtualAddress on non-buffer resources, 1047×1 618 simultaneous-access hazards across queues, 677×491, 679×252, 680×45, 1422×9. 745 is XCL's own address probe in res_gpu_va_x (it asks the PC method, gets 0, substitutes the title's address), so it is expected in any debug-layer run, on both sides of a pair.

Regression run

Both runs have the debug layer on – main's through XCL_D3D12_DEBUG=1 in the environment, because the -DebugLayer switch is this PR's – so the two sides pay the same cost. Main's block has no debug layer messages: line, so the new-id comparison is skipped for this pair.

main cbc296a:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 4090
title: 3c290c16
seconds: 180
exit: 0x0
frames shown: 1758 (PresentX 1758)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 35960 MB

this PR's head 1039318 (-DebugLayer):

xcl-smoke v1
commit: 1039318fce8565e8298b5fea211f23f524a59bf1
gpu: NVIDIA GeForce RTX 4090
title: 3c290c16
seconds: 180
exit: 0x0
frames shown: 1552 (PresentX 1552)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 36313 MB
debug layer messages: 538x4580 677x491 679x257 680x46 745x5454 1047x1428 1422x12

Not tested

  • AMD, WARP, and machines without the Graphics Tools optional feature – there the layer is unavailable, XCL logs that once, and the line stays n/a, which is why -DebugLayer is a switch and not the default (D3D12.X: say why no GPU made a device with the debug layer on #1444 is about device creation failing in exactly that case)
  • D3D12.X: debug layer messages reach the log without ID3D12InfoQueue1 #1008's polled ID3D12InfoQueue path for Windows 10 does not feed this counter yet: it needs the same note_debug_message call when that PR lands, or Windows 10 runs will log messages the report does not count
  • the id comparison against a main block that itself has the line: main has no -DebugLayer switch, so this pair exercises only the head side (the tests cover same / fewer / n/a / no line)

AI use

  • Claude Code, Claude Opus 5.5: wrote the code, the tests and this description, ran both suites and the 150 s game run; the user reviewed the diff.
  • Claude Code, Claude Fable 5: the two review fixes (debug_layer_counts_from, restoring the caller's XCL_D3D12_DEBUG), the rebase onto cbc296a, the suite rerun and both regression runs.

🤖 Generated with Claude Code

@raylitebull

Copy link
Copy Markdown
Member

Code review on 60f8fc5:

  • Counting debug-layer messages per ID into DEBUG_MSGS (BTreeMap<i32, (u32, String)>) while keeping DEBUG_MSG_LOG_LIMIT = 8 on log output, exposing D3d12Stats.debug_layer, and gating newly introduced IDs in scripts/pr_check.py / scripts/smoke.ps1 -DebugLayer is very clean and practical.
  • Two minor notes:
    1. debug_layer_report_tests::the_report_lists_ids_in_order_with_full_counts (crates/xcl/src/hle/d3d12x/real.rs) mutates the process-global DEBUG_MSGS static and asserts exact contents (vec![(541, 1), (725, 3)]). If another GPU test runs concurrently in the same binary with XCL_D3D12_DEBUG=1 (e.g., --test-threads=4), real debug-layer callbacks can race into DEBUG_MSGS and break that assertion. Extracting a debug_layer_counts_from(msgs: &BTreeMap<...>) helper lets the test stay isolated.
    2. In scripts/smoke.ps1, if ($DebugLayer) { Remove-Item Env:XCL_D3D12_DEBUG } unconditionally deletes Env:XCL_D3D12_DEBUG even if the calling shell had it set beforehand (similar to #521).
  • Build and test (Windows, no GPU) is green.

Remaining before merge: Addressing PR description (and the global-state test isolation note above) plus AMD and NVIDIA verification on the updated head.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

brandostrong and others added 2 commits November 24, 2026 20:45
The debug layer's messages reach XCL's log but only the first 8 of each id are
printed, so a run that hit one 5 151 times looked like eight hits in the report.
The per-id counts already existed in the callback; they were a local static
nothing could read. Hoist them to a module static, count every message, keep
the first text of each id and expose them in report.json as d3d12.debug_layer,
sorted by id.

Measured on a 150 s debug-layer run of a retail title: 13 273 messages in the
report against 57 lines in the log – 5 307 GetGPUVirtualAddress-on-non-buffer
warnings (XCL's own address probes), 5 151 resource-state errors, 1 618
simultaneous-access hazards across queues and 9 render targets created
CREATE_NOT_ZEROED and never initialized before use.

The log caps are unchanged: printing still stops at 8 per id and 3 000 in all.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…ssage ids

A run that picked up new validation errors looked clean in the block: frames
and peak commit say nothing about them, and the log's per-id cap hides how
often each one fired. smoke.ps1 prints `debug layer messages: 538x5151 745x5307`
from report.json (n/a when the layer was off, none when there were none) and
pr_check.py refuses a PR whose run shows ids main's run did not; ids main's run
showed and the PR's no longer shows are a fix, not a problem.

-DebugLayer turns the layer on for the run so the line has ids in it. It is a
switch and not the default: with the layer requested and no Graphics Tools
device creation can fail outright (xcl-dev#1444), so forcing it would break smoke runs
there. Both runs of a pair get it; blocks without the line still pass.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@brandostrong
brandostrong force-pushed the d3d12x-debug-layer-report branch from 60f8fc5 to 1039318 Compare November 25, 2026 05:04
@brandostrong
brandostrong marked this pull request as ready for review November 25, 2026 05:05
@brandostrong

Copy link
Copy Markdown
Contributor Author

Both notes are addressed at the current head 1039318f (the review was on 60f8fc5):

  1. the_report_lists_ids_in_order_with_full_counts no longer touches the global: it fills a local BTreeMap and asserts through the extracted debug_layer_counts_from(&msgs) (crates/xcl/src/hle/d3d12x/real.rs:176 for the helper, :7220 for the test), with a comment naming the race you spotted — a concurrent GPU test with XCL_D3D12_DEBUG=1 feeds the global map. counts_every_message_and_caps_only_the_printing was already local-map only.
  2. scripts/smoke.ps1 now saves the caller's value first (:57) and restores it after the run (:70-72): with -DebugLayer it sets 1 for the child and puts back what the shell had, removing the variable only if the shell had none.

Tested on the current head: cargo test --release --offline --workspace -- --test-threads=4 on an RTX 4090 — 1155 passed, 0 failed, 46 ignored, 23 SKIPPED (no wave64 and the direct path's refused f16 / f32 forms). AMD and a second NVIDIA card are still the gap, as you say.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

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