runtime: log DRED breadcrumbs and page faults when the device is removed (X2W_D3D12_DRED) #3664
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3664
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3662"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Leyukaka on GitHub · 2026-11-30 22:16 UTC · original
Leyukaka:runtime-dred-device-removed-pr→main· +1293 −2 · 8 files · 5 commits · merged 2026-12-01 03:11 UTCChange
Two opt-in switches for the start-up stand-in, to find the command the GPU was running when the desktop device is removed. Unset, nothing changes. Refs #870 (the request there to enable DRED before the device is created and report the last completed breadcrumb and the first outstanding command).
X2W_D3D12_DRED=1, withX2W_D3D12_PERMISSIVE=1:Before
D3D12CreateDevice, DRED auto-breadcrumbs, page fault reporting and, where the interface exists, breadcrumb contexts are forced on.x2w-d3d12 DRED enabledorx2w-d3d12 DRED unavailable 0x<hr>is logged.When the device is removed, the existing
x2w-d3d12 DEVICE REMOVEDline is followed once byx2w-d3d12-dredlines:A partly completed node lists its ops up to 4 past the completed count (the last 64). The first op that did not complete is marked
<- first not completed. At most 2000 detail lines are written; the summary lines give the skipped counts.Each desktop queue and command list the stand-in creates gets a debug name through
SetName(x2w direct queue 0,x2w list 17), so the nodes name them.A
SetMarkertext<word> <key>is recorded before each Dispatch, ExecuteIndirect and DispatchMesh the stand-in records. The key is the shader cache key or pipeline hash, 0 when unknown.The stand-in keeps a CPU copy of those marker texts per desktop list, and a copy of it at each submission (the last 8 per list). Each unfinished node is followed by its list's markers by rank, with the one recorded before the first op that did not complete marked
<- before first not completed.X2W_STOP_AFTER_DEVICE_REMOVED=<seconds>: after theDEVICE REMOVEDline and the DRED lines, the process waits that long (at most 3600) and ends with exit code0x887a0006.The report is plain functions over the
d3d12.hDRED structures in the newsrc/startup_stubs/d3d12_dred_report.h. The device side is insrc/startup_stubs/d3d12_xs_device.cpp. Both switches are documented in thedocs/startup-runtime.mdswitch table.Overlap: #3466 also edits the device creation path in
d3d12_xs_device.cppand the same doc table. Neither needs the other to land first.Verification
Base:
mainatd59708580. Head:deb2b2f7c.Result on
deb2b2f7c, cleandevbuild (Windows, MSVC 19.44): 13/13 passed, includingstartup_d3d12_dred,startup_d3d12_dred_switch,startup_d3d12_dred_switch_offandstartup_d3d12_dred_switch_control; the ninestartup_local_log*tests are unchanged.On the same five commits before they were cherry-picked onto this branch, on a local Windows build,
ctest -R '^startup_(d3d12_dred|native_compute_deny|local_log)'passed 16/16, including the fourstartup_d3d12_dred*tests. Thenative_compute_denytests belong to that working branch, not to this PR.The tests fill the DRED structures themselves and need no device or GPU.
startup_d3d12_dred_switch_controlruns the on phase with the switch off and passes only on that phase's FAIL line.Mutations tried, one at a time, each rebuilt and run on the working-branch commits. Lines are in
src/startup_stubs/d3d12_dred_report.hat this head::320ops windowcompleted > 4 ? completed - 4 : 0tocompleted > 3 ? completed - 3 : 0startup_d3d12_dredfails:252line capdetail_ >= limit_todetail_ > limit_startup_d3d12_dredfails:342op == completedtoop + 1 == completedstartup_d3d12_dredfails:126value[0] == '1'totruestartup_d3d12_dred_switch_offand_switch_controlfail:172case 46removedstartup_d3d12_dredfails:321-324partial-node block removed (window stays at 4 before to 4 after)startup_d3d12_dredfails:414newest-nodes loop started from the head of the chainstartup_d3d12_dredfails:88done - 1todonestartup_d3d12_dredfails:352DredNodeState::completedtest removedstartup_d3d12_dredfails:113-117not in the journalline removedstartup_d3d12_dredfailssrc/startup_stubs/d3d12_xs_device.cpp:802dred_marker: `if (!dred_onThe last edit still passes because no test builds
d3d12_xs_device.cpp. A case that would catch it: a run with the switch unset that checks noSetMarkerreaches the desktop list.Evidence and follow-up
The fixtures are DRED structures written by hand in
tests/startup_d3d12_dred_check.cpp. The expected lines are written out in the test, not computed with the header.Local-data result: over several start-up runs that ended with device removal
0x887a0006, the report named one partly completed node, on the direct queue. Its first op that did not complete was a Dispatch, and the marker before it carried the key of a translated compute shader. Without the per-submission copy, the marker lines were empty in these runs: DRED returned noSetMarkertext, and the list had been recorded again or replaced before the report was written. The public fixture verifies the report format, the caps and the marker rank only.Not covered:
ei-draw,ei-drawidx) prints key 0: the marker reads only the keys known without a lock (mesh, compute request, compute trace), and the vertex and pixel translation key is underdraw_lock.src/startup_stubs/xg_xs.cpp:38) has DRED only if it is created after the switch is applied, and its removal is not reported.cs-xlatmarker does not say whether the native or the published translation ran.tests/startup_d3d12_dred_check.cpp:333), so that choice is checked by the local runs only.Checklist
The X2W_D3D12_DRED=1 report capped the breadcrumb chain at its first 64 nodes in all, though the header said per list. The chain runs from older to newer submissions, so the newest ones were cut and no unfinished node needs to be among the first 64. The report now prints every unfinished node first (completed below the op count or unknown, at most 256), then per queue a summary line (nodes, completed, partial, not started, unknown) and its 8 newest nodes not printed yet. A partly completed node lists its ops from the start up to 4 past the completed count (the last 64). Node lines give the position in the chain. The 2000 line cap and the skipped counts stay. Ops 45 and 46 are named Barrier and BeginCommandList, by value for older SDKs. With the switch on, each desktop queue and command list the stand-in creates gets a short debug name ("x2w direct queue 0", "x2w list 17"), logged once with its pointer (the first 256), and a SetMarker with a type word and the shader cache key or pipeline key is recorded before each dispatch, ExecuteIndirect and mesh dispatch the stand-in records, so breadcrumb contexts show it next to the op. No lock is taken. startup_d3d12_dred_check covers the unfinished nodes first, the newest nodes and summary per queue, a partly completed node after 300 completed ones, the op cap of a partial node, the unfinished cap, the names of ops 45 and 46, a context string and the marker text.@lukaslw-lab on GitHub · 2026-12-01 01:53 UTC · original · approved these changes
Reviewed
deb2b2f7by reading the diff; not built or run.Verdict: approve. Both switches are inert when unset, and the report reads the DRED structures correctly. The SHOULD can follow in a later PR. No MUST.
X2W_STOP_AFTER_DEVICE_REMOVEDsleeps insidecheck_device, which runs on whatever thread first sees the removal, with that thread's locks still held.build_stream_pipelinecallscheck_device(d3d12_xs_device.cpp:3294), and the native mesh PSO builds reach it withdraw_lockheld (native_mesh57.inl:517,native_mesh86.inl:194; see the note atd3d12_xs_device.cpp:509). On that path the other threads block ondraw_lockfor the whole wait, so their lines never reach the log, which defeats the switch's stated purpose (:841). Two ways to fix it: record the request and do the sleep andTerminateProcessat a lock-free site such as the end ofqueue_execute, after:5790; or document that the wait can hold the caller's locks."mesh"marker beforeExecuteIndirect(:4954) always carries key 0:dred_pipeline_keyknows onlymesh86_keyand the compute keys, andIndirectGraphicsPipelinehas no key. Slot 57 is the P0 path, so this gap deserves a line in the "Not covered" list or the doc row.dred_onfirst; the title's ownSetMarker/BeginEventslots (56–58) are no-ops, so the journal ranks match;dred_journal_lockis a leaf; the merge with main is clean, withenable_dredafterselect_agility_sdk(), so DRED reaches the Agility runtime.Tests:
startup_d3d12_dredpins the node selection, the windows, the caps and the marker rank on hand-written chains; the switch tests and their control pindred_requested. As the PR body says, the journal fake ignoresbackand nothing builds the device side, solater[i](d3d12_dred_report.h:399) and the markers, naming and stop are untested. CI built the change but did not run these four tests (they are not in theprpreset filter); the only run is the author's local 13/13.