runtime: log DRED breadcrumbs and page faults when the device is removed (X2W_D3D12_DRED) #3664

Manually merged
github merged 5 commits from github-bot/gh-3662 into main 2026-12-01 03:13:17 +00:00 AGit
Owner

@⁠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 UTC

Change

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, with X2W_D3D12_PERMISSIVE=1:

  • Before D3D12CreateDevice, DRED auto-breadcrumbs, page fault reporting and, where the interface exists, breadcrumb contexts are forced on. x2w-d3d12 DRED enabled or x2w-d3d12 DRED unavailable 0x<hr> is logged.

  • When the device is removed, the existing x2w-d3d12 DEVICE REMOVED line is followed once by x2w-d3d12-dred lines:

    • every unfinished breadcrumb node (at most 256), in chain order;
    • per queue, a summary line (nodes, completed, partial, not started, unknown) and its 8 newest nodes not printed yet;
    • the page fault address with the existing and recently freed allocations (at most 64 per list).

    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 SetMarker text <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 the DEVICE REMOVED line and the DRED lines, the process waits that long (at most 3600) and ends with exit code 0x887a0006.

The report is plain functions over the d3d12.h DRED structures in the new src/startup_stubs/d3d12_dred_report.h. The device side is in src/startup_stubs/d3d12_xs_device.cpp. Both switches are documented in the docs/startup-runtime.md switch table.

Overlap: #3466 also edits the device creation path in d3d12_xs_device.cpp and the same doc table. Neither needs the other to land first.

Verification

Base: main at d59708580. Head: deb2b2f7c.

ctest --preset dev --no-tests=error -R '^startup_(d3d12_dred|local_log)'

Result on deb2b2f7c, clean dev build (Windows, MSVC 19.44): 13/13 passed, including startup_d3d12_dred, startup_d3d12_dred_switch, startup_d3d12_dred_switch_off and startup_d3d12_dred_switch_control; the nine startup_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 four startup_d3d12_dred* tests. The native_compute_deny tests 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_control runs 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.h at this head:

Edit Result
:320 ops window completed > 4 ? completed - 4 : 0 to completed > 3 ? completed - 3 : 0 startup_d3d12_dred fails
:252 line cap detail_ >= limit_ to detail_ > limit_ startup_d3d12_dred fails
:342 op == completed to op + 1 == completed startup_d3d12_dred fails
:126 value[0] == '1' to true startup_d3d12_dred_switch_off and _switch_control fail
:172 case 46 removed startup_d3d12_dred fails
:321-324 partial-node block removed (window stays at 4 before to 4 after) startup_d3d12_dred fails
:414 newest-nodes loop started from the head of the chain startup_d3d12_dred fails
:88 done - 1 to done startup_d3d12_dred fails
:352 DredNodeState::completed test removed startup_d3d12_dred fails
:113-117 not in the journal line removed startup_d3d12_dred fails
src/startup_stubs/d3d12_xs_device.cpp:802 dred_marker: `if (!dred_on

The 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 no SetMarker reaches 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 no SetMarker text, 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:

  • Direct draws get no marker. Only Dispatch, ExecuteIndirect and DispatchMesh are marked.
  • A forwarded graphics ExecuteIndirect (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 under draw_lock.
  • The XG layout device (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.
  • A cs-xlat marker does not say whether the native or the published translation ran.
  • No submission number and no fence value is printed.
  • The device side (naming, markers, the journal and its copy per submission, the stop) has no unit test. The test's journal lookup also ignores which submission is asked for (tests/startup_d3d12_dred_check.cpp:333), so that choice is checked by the local runs only.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include application files, dumps, distribution links or secrets.
**@⁠Leyukaka** on GitHub · 2026-11-30 22:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3662) `Leyukaka:runtime-dred-device-removed-pr` → `main` · +1293 −2 · 8 files · 5 commits · merged 2026-12-01 03:11 UTC ## Change 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`, with `X2W_D3D12_PERMISSIVE=1`: - Before `D3D12CreateDevice`, DRED auto-breadcrumbs, page fault reporting and, where the interface exists, breadcrumb contexts are forced on. `x2w-d3d12 DRED enabled` or `x2w-d3d12 DRED unavailable 0x<hr>` is logged. - When the device is removed, the existing `x2w-d3d12 DEVICE REMOVED` line is followed once by `x2w-d3d12-dred` lines: - every unfinished breadcrumb node (at most 256), in chain order; - per queue, a summary line (nodes, completed, partial, not started, unknown) and its 8 newest nodes not printed yet; - the page fault address with the existing and recently freed allocations (at most 64 per list). 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 `SetMarker` text `<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 the `DEVICE REMOVED` line and the DRED lines, the process waits that long (at most 3600) and ends with exit code `0x887a0006`. The report is plain functions over the `d3d12.h` DRED structures in the new `src/startup_stubs/d3d12_dred_report.h`. The device side is in `src/startup_stubs/d3d12_xs_device.cpp`. Both switches are documented in the `docs/startup-runtime.md` switch table. Overlap: #3466 also edits the device creation path in `d3d12_xs_device.cpp` and the same doc table. Neither needs the other to land first. ## Verification Base: `main` at d59708580. Head: deb2b2f7c. ```text ctest --preset dev --no-tests=error -R '^startup_(d3d12_dred|local_log)' ``` Result on deb2b2f7c, clean `dev` build (Windows, MSVC 19.44): 13/13 passed, including `startup_d3d12_dred`, `startup_d3d12_dred_switch`, `startup_d3d12_dred_switch_off` and `startup_d3d12_dred_switch_control`; the nine `startup_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 four `startup_d3d12_dred*` tests. The `native_compute_deny` tests 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_control` runs 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.h` at this head: | Edit | Result | |---|---| | `:320` ops window `completed > 4 ? completed - 4 : 0` to `completed > 3 ? completed - 3 : 0` | `startup_d3d12_dred` fails | | `:252` line cap `detail_ >= limit_` to `detail_ > limit_` | `startup_d3d12_dred` fails | | `:342` `op == completed` to `op + 1 == completed` | `startup_d3d12_dred` fails | | `:126` `value[0] == '1'` to `true` | `startup_d3d12_dred_switch_off` and `_switch_control` fail | | `:172` `case 46` removed | `startup_d3d12_dred` fails | | `:321-324` partial-node block removed (window stays at 4 before to 4 after) | `startup_d3d12_dred` fails | | `:414` newest-nodes loop started from the head of the chain | `startup_d3d12_dred` fails | | `:88` `done - 1` to `done` | `startup_d3d12_dred` fails | | `:352` `DredNodeState::completed` test removed | `startup_d3d12_dred` fails | | `:113-117` `not in the journal` line removed | `startup_d3d12_dred` fails | | `src/startup_stubs/d3d12_xs_device.cpp:802` `dred_marker`: `if (!dred_on || !list) return;` -> `if (!list) return;` (SetMarker also with `X2W_D3D12_DRED` unset) | still passes | The 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 no `SetMarker` reaches 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 no `SetMarker` text, 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: - Direct draws get no marker. Only Dispatch, ExecuteIndirect and DispatchMesh are marked. - A forwarded graphics ExecuteIndirect (`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 under `draw_lock`. - The XG layout device (`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. - A `cs-xlat` marker does not say whether the native or the published translation ran. - No submission number and no fence value is printed. - The device side (naming, markers, the journal and its copy per submission, the stop) has no unit test. The test's journal lookup also ignores which submission is asked for (`tests/startup_d3d12_dred_check.cpp:333`), so that choice is checked by the local runs only. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include application files, dumps, distribution links or secrets.
X2W_D3D12_DRED=1 forces on DRED auto-breadcrumbs, page fault reporting
and breadcrumb contexts before the desktop device is created, and logs
the breadcrumb nodes and page fault allocations once after the DEVICE
REMOVED line, capped at 64 nodes per list and 2000 lines with skipped
counts. X2W_STOP_AFTER_DEVICE_REMOVED=<seconds> waits that long after
the line and then ends the process with 0x887a0006.

The formatting lives in src/startup_stubs/d3d12_dred_report.h and is
checked without a device by startup_d3d12_dred_check, with a control
for the switch.
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.
With X2W_D3D12_DRED=1 the SetMarker ops show up in the breadcrumbs, but
without breadcrumb contexts their text is not reported, so the shader or
pipeline key in front of an unfinished op stays unknown.

dred_marker now also adds its ASCII text to a journal per desktop list,
keyed by the desktop list pointer, in recording order (the first 512 per
recording, at most 4096 lists). The journal is dropped when the list is
created or named as a replacement, and after each list_reset (the reset
list starts a new recording, or the replaced list is gone).
dred_journal_lock is a leaf: only the map and its strings are touched
under it. dred_marker holds draw_lock on the translated paths,
list_reset clears after allocator_lock is released, and the report
copies a journal out before it logs.

Each unfinished node of the report is followed by a count line (journal
size, SetMarker ops, completed SetMarker ops) and its list's markers by
rank, at most 64 up to 4 past the marker recorded before the first op
that did not complete, marked "<- before first not completed". The
rank is the number of SetMarker ops below the completed count, minus
one. A journal shorter than that rank says so, and a list with no
journal gets a "no CPU journal" line. The matching is a pure function
in d3d12_dred_report.h (dred_marker_lines); without a journal lookup
the report is unchanged.

startup_d3d12_dred_check covers three markers with the first op not
completed after the second, a journal shorter than the SetMarker ops,
an absent journal, a finished node, the marker cap and an unknown
completed count.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 22:21:53 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-01 01:53 UTC · original · approved these changes

Reviewed deb2b2f7 by 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.

  • SHOULD X2W_STOP_AFTER_DEVICE_REMOVED sleeps inside check_device, which runs on whatever thread first sees the removal, with that thread's locks still held. build_stream_pipeline calls check_device (d3d12_xs_device.cpp:3294), and the native mesh PSO builds reach it with draw_lock held (native_mesh57.inl:517, native_mesh86.inl:194; see the note at d3d12_xs_device.cpp:509). On that path the other threads block on draw_lock for 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 and TerminateProcess at a lock-free site such as the end of queue_execute, after :5790; or document that the wait can hold the caller's locks.
  • NIT For slot 57 mesh, the "mesh" marker before ExecuteIndirect (:4954) always carries key 0: dred_pipeline_key knows only mesh86_key and the compute keys, and IndirectGraphicsPipeline has no key. Slot 57 is the P0 path, so this gap deserves a line in the "Not covered" list or the doc row.
  • Checked, no finding: every hook checks dred_on first; the title's own SetMarker/BeginEvent slots (56–58) are no-ops, so the journal ranks match; dred_journal_lock is a leaf; the merge with main is clean, with enable_dred after select_agility_sdk(), so DRED reaches the Agility runtime.

Tests: startup_d3d12_dred pins the node selection, the windows, the caps and the marker rank on hand-written chains; the switch tests and their control pin dred_requested. As the PR body says, the journal fake ignores back and nothing builds the device side, so later[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 the pr preset filter); the only run is the author's local 13/13.

**@⁠lukaslw-lab** on GitHub · 2026-12-01 01:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3662#pullrequestreview-6123788621) · **approved these changes** Reviewed `deb2b2f7` by 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. - **SHOULD** `X2W_STOP_AFTER_DEVICE_REMOVED` sleeps inside `check_device`, which runs on whatever thread first sees the removal, with that thread's locks still held. `build_stream_pipeline` calls `check_device` (`d3d12_xs_device.cpp:3294`), and the native mesh PSO builds reach it with `draw_lock` held (`native_mesh57.inl:517`, `native_mesh86.inl:194`; see the note at `d3d12_xs_device.cpp:509`). On that path the other threads block on `draw_lock` for 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 and `TerminateProcess` at a lock-free site such as the end of `queue_execute`, after `:5790`; or document that the wait can hold the caller's locks. - **NIT** For slot 57 mesh, the `"mesh"` marker before `ExecuteIndirect` (`:4954`) always carries key 0: `dred_pipeline_key` knows only `mesh86_key` and the compute keys, and `IndirectGraphicsPipeline` has no key. Slot 57 is the P0 path, so this gap deserves a line in the "Not covered" list or the doc row. - Checked, no finding: every hook checks `dred_on` first; the title's own `SetMarker`/`BeginEvent` slots (56–58) are no-ops, so the journal ranks match; `dred_journal_lock` is a leaf; the merge with main is clean, with `enable_dred` after `select_agility_sdk()`, so DRED reaches the Agility runtime. Tests: `startup_d3d12_dred` pins the node selection, the windows, the caps and the marker rank on hand-written chains; the switch tests and their control pin `dred_requested`. As the PR body says, the journal fake ignores `back` and nothing builds the device side, so `later[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 the `pr` preset filter); the only run is the author's local 13/13.
github manually merged commit cb0c39c180 into main 2026-12-01 03:13:11 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.