Skip to content

D3D-264: opt-in DRED device-loss diagnostics for Vulkan - #3293

Open
AimLogin wants to merge 3 commits into
ItsNotRexed:mainfrom
AimLogin:claim/D3D-dred-breadcrumbs
Open

AimLogin wants to merge 3 commits into
ItsNotRexed:mainfrom
AimLogin:claim/D3D-dred-breadcrumbs

Conversation

@AimLogin

@AimLogin AimLogin commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

D3D-264 (claim, correction after measuring the host runtime). No dependencies. Written on main 16282101, merged with main f847748c and then 3faac557 (merge commits, no rebase).

Why

When the GPU faults or hangs, the Vulkan layer has only VK_ERROR_DEVICE_LOST / DXGI_ERROR_DEVICE_REMOVED. It can't tell which command list was running or which address faulted, and that's the first question on a boot crash. Nothing on main implements DRED.

What

Everything is opt-in with LEONIDA_DRED=1. Unset, no extension is enabled, no ring exists, and the hot paths only pay a null check.

  • GPU breadcrumbs per command list (runtime/src/vulkan_breadcrumbs.h). execute() writes two vkCmdWriteBufferMarkerAMD markers around each list's commands, at TOP_OF_PIPE and BOTTOM_OF_PIPE, into a host-visible ring of 1024 slots. Each list gets a unique non-zero tag, so slots need no clearing and an older tag never passes for progress. The states are:

    • submitted: vkQueueSubmit succeeded, which is CPU knowledge only;
    • started: the GPU wrote the begin word;
    • completed: the GPU wrote the end word.

    Replay and emit() are unchanged.

  • CPU fallback. Without VK_AMD_buffer_marker, or without host-visible memory for it, the ring keeps only the submitted lists and their queues, and every state is UNKNOWN. Nothing is reported as started or completed.

  • VK_EXT_device_fault (with deviceFault) is read once after the loss for the description and addresses. Vendor binary data is never requested.

  • One report on the loss (stderr), whichever path sees it first: mark_device_lost() (after notify_device_lost()), or is_device_lost() after the fence waiter set the flag.

    • With GPU breadcrumbs it lists the lists that did not complete, plus the last one that did.
    • In CPU-only mode it lists the last 16 submitted.
    • Each entry shows its queue, debug names and up to 8 operations.
    • The fault data follows, or "no device fault information".
  • ID3D12DeviceRemovedExtendedData, …1, …2 (runtime/shims/d3d12_dred.h): a tear-off of the device, with the device's identity and reference count. It follows the host runtime as measured on WARP and an RTX 4060 Ti; both behave the same.

    DRED off DRED on
    QueryInterface for the three succeeds succeeds
    outputs, device not removed DXGI_ERROR_UNSUPPORTED DXGI_ERROR_NOT_CURRENTLY_AVAILABLE
    outputs after RemoveDevice DXGI_ERROR_UNSUPPORTED S_OK, no node, PageFaultVA 0
    GetDeviceState UNKNOWN UNKNOWN

    After a real loss the outputs are taken once and stay valid for the device's lifetime:

    • one node per list the GPU did not complete, with its D3D12_AUTO_BREADCRUMB_OPs and *pLastBreadcrumbValue 0 (list granularity);
    • PageFaultVA is the first invalid-access address minus the arena's device address, the same way GetGPUVirtualAddress computes VAs.
  • Debug names. ExecuteCommandLists copies the list's and queue's SetName names into the ring, only when DRED is on. They're read from the WKPDID_D3DDebugObjectNameW private data, under the object's lock. They show up in the report and in the nodes' pCommand{List,Queue}DebugName{W,A}. pCommandList and pCommandQueue stay null, because nothing keeps those objects alive after the call.

    • A batch that main holds on the CPU behind an unsignalled Wait copies the names when it is held. When it's released, it is marked under the application's list address, which is only shown as an id and never dereferenced or looked up.
    • It gets a ring entry only once it reaches vkQueueSubmit.
  • Xbox-ABI device proxy: unchanged. It answers only the Xbox device chain it models. DRED isn't in that chain and its Xbox layout hasn't been measured, so the game's device still refuses the three interfaces. The stderr report doesn't depend on them.

  • Docs: docs/d3d12_vulkan.md §4.11, and the stub-table row.

Tests

  • vk_breadcrumbs:

    • the state logic and the report format;
    • a list held behind an unsignalled fence has no entry until the Signal releases it, then reads completed under its own id and name;
    • held batches keep their names after a rename or when the list's address is reused, and when released out of order;
    • a destroyed queue's name doesn't pass to a later queue at the same address, and a failed submission leaves no entry;
    • a 1026-list ring wrap;
    • two queues on two threads, 800 lists, ordered and recycled;
    • CPU-only mode with names;
    • fallbacks.
  • vk_device_lost: a controlled loss on an idle device. vkQueueSubmit returns VK_ERROR_DEVICE_LOST without reaching the driver, the marker call is counted, and vkGetDeviceFaultInfoEXT is a mock. It checks:

    • one report, in GPU and CPU-only mode;
    • fault data;
    • no fault information when the extension is off, the driver reports nothing, or either query fails;
    • no submission, marker or fault query after the loss;
    • eight threads seeing the loss at once, with one report and no deadlock.
  • d3d12_dred_off / d3d12_dred_on compare the host runtime on WARP and the first hardware adapter with the Vulkan device:

    • QueryInterface and its identity;
    • the outputs live, after ExecuteCommandLists and after RemoveDevice;
    • DRED is refused behind the Xbox-ABI proxy;
    • conversion to D3D12 nodes on synthetic data;
    • in on, a controlled loss through D3D12: the named list comes back as a node with its queue's name, and PageFaultVA is the buffer's VA + 0x40.

    d3d12_dred_off also passes with LEONIDA_DRED=1 set globally.

Full ctest, RelWithDebInfo (MSVC), LEONIDA_VK_VALIDATION=1 plus synchronization validation, implicit layers off. RTX 4060 Ti, driver 621.01, Windows 11 26200:

Tree Result VUIDs
main 3faac557 169/169 0
this PR (merged with 3faac557) 173/173 0
this PR, LEONIDA_DRED=1 for every test 173/173 0

The only difference from main is the four new tests. In the validation output, the only new lines are their two "0 validation errors". The same 8 tests skip in all three runs, and gameinput is disabled by default, as on main:

  • six need the game package or the translated shader corpus: shader_library_corpus, bink_decode, bink_play_headless, fsr_dispatch, bvh_builder, bink_audio;
  • d3d12_first_light needs LEONIDA_FIRST_LIGHT_DIR;
  • d3d12_rgb9e5_rtv skips because the adapter has no RGB9E5 render targets.

Earlier bases, same setup:

  • f847748c: main 132/132, this PR 136/136;
  • 16282101: 121/121 and 125/125;
  • 0 VUIDs on both.

On AMD, @crastinator ran db77d45 on an RX 6700 XT (RADV, Linux): ctest 43/43 and run_gpu_tests.py as on main. That covers the normal path; whether the GPU-marker part of vk_breadcrumbs ran there hasn't been confirmed.

Merge with 3faac557.

  • The only textual conflict is the device-function list in vulkan_backend.h: main's pipeline-cache functions and the two DRED functions both stay.
  • Two changes on main needed adapting:
    • SetName went back to private data (55a07318), so the names are read through GetPrivateData;
    • batches held on the CPU are marked under the application's list, with the names they had when held.

Fixes from an audit, each with a test:

  • a queue that never names itself (the device's staging queue) no longer inherits the debug name of a destroyed queue at the same address. The test failed on db77d45;
  • the DRED output getters read the snapshot under the lock it is built under;
  • a held batch keeps the names it had when it was held, even after the list is renamed or its address is reused by another list, and when batches are released out of order. The test failed before the fix.

The CI failures on db77d45 came from main at the time:

  • windows: d3d12_msaa_draw and d3d12_geometry had no skip without a GPU; main has since added one.
  • linux-gpu-tools: ctest passed 41/41, but a later step failed when llvm-mc rejected ps_sdwa_f16_const.

Not covered / follow-ups

  • No real GPU device loss was tested. The loss path runs with controlled mocks only. What a real driver writes into the marker words and the fault info after a hang or fault isn't covered.
  • No Intel results, and AMD only on Linux (@crastinator, RX 6700 XT, RADV): it is not confirmed that the GPU-marker part ran there. CPU-only mode on hardware without the marker extension hasn't run on real hardware.
  • Breadcrumbs are per list, not per command (a possible follow-up).
  • With CPU-only progress the API returns no nodes, since a node can't say "unknown"; the stderr report has those lists.
  • GetDeviceState stays UNKNOWN, and there are no allocation nodes or breadcrumb contexts.
  • DRED behind the Xbox-ABI proxy would need the Xbox layout measured first.

No game files.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

With LEONIDA_DRED=1 the Vulkan layer records per-command-list breadcrumbs
(VK_AMD_buffer_marker; CPU-only with UNKNOWN progress without it), reads
VK_EXT_device_fault on a loss, prints one report, and answers
ID3D12DeviceRemovedExtendedData/1/2 as the host runtime does. Off by
default; the Xbox-ABI device proxy is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts in runtime/src/vulkan_backend.h: main's event functions and
the two optional DRED functions both stay in the device function list;
after submit(), main's wait clean-up runs first, then the breadcrumbs
keep the marks only if the submission succeeded.

main's SetName now keeps the name apart from the private data
(Object::debug_name()), so ExecuteCommandLists takes the DRED names
from there; the GetPrivateData-based dred_debug_name() is removed.

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

Copy link
Copy Markdown
Contributor

Tested db77d45 merged into main f847748c (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • Whole run_gpu_tests.py: 185/199 native, 185/199 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 43/43 (main has 41; the 2 new tests pass).

No game files. AI-assisted (Claude Code).

@AimLogin

Copy link
Copy Markdown
Contributor Author

Thanks for the independent run on RDNA2/RADV, @crastinator. That's the first non-NVIDIA result for this branch.

For the record: on Linux, the two new tests are vk_breadcrumbs and vk_device_lost. d3d12_dred_off/on only build on Windows. Neither Vulkan test reads LEONIDA_DRED, because they set up the ring directly.

One thing a pass doesn't tell apart: if the device doesn't expose VK_AMD_buffer_marker, vk_breadcrumbs skips its GPU part and still exits 0. Could you post the output of

LEONIDA_VK_VALIDATION=1 ctest --test-dir <build> -R 'vk_breadcrumbs|vk_device_lost' -V

The line I'm after is breadcrumbs: completed / submitted behind an unsignalled fence / completed ok (rather than no VK_AMD_buffer_marker, GPU breadcrumbs skipped), plus the ring-wrap and two-queue lines and the validation error count. That would confirm the RADV marker writes are read back correctly. Nothing in either test loses a real device: vk_device_lost fakes the loss and vkGetDeviceFaultInfoEXT.

@memorypressure

Copy link
Copy Markdown

Verified against main 3faac55: DRED remains a documented stub there (docs table: stubs, verified), so nothing in this PR is superseded; it conflicts only in vulkan_backend.h's device-function list, where both sides extended the same macro — mechanical to rebase, mind the continuation backslashes. Review of the ~2k added lines found no game data and a clean opt-in design, but this host builds no C++, has no GPU and never runs wine, so vk_device_lost_test, vk_breadcrumbs_test and the fault-info capture are unverified here — and CI is currently red on both linux-gpu-tools and windows (re-confirmed today), which should be green or explained before review effort. Also touches d3d12_com.cpp alongside #3298. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@AimLogin

Copy link
Copy Markdown
Contributor Author

Thanks @memorypressure. Here's where each point stands, measured locally.

Conflict. As you say, the only one is the device-function list in vulkan_backend.h. I've merged main 3faac557 locally: main's pipeline-cache entries stay, and our two optional functions follow them. The merge is not pushed yet.

Red CI on db77d45. Neither failure comes from this PR:

  • windows: d3d12_msaa_draw and d3d12_geometry stop at d.create() on the hosted runner, which has no GPU. main has since changed both to return 77 when no Vulkan device is available (e.g. 72fb353f). The four DRED tests pass or skip there.
  • linux-gpu-tools: ctest passes 41/41, including vk_breadcrumbs and vk_device_lost. The step that fails afterwards is llvm-mc rejecting runtime/test/shaders/ps_sdwa_f16_const.asm line 30. This PR doesn't touch that fixture. I can't tell yet whether main passes that step: its recent runs were all cancelled, and I have no llvm-mc locally.

#3298. Merged against the right base (this branch plus main), git merge-tree reports no conflict with #3298's head db674c9e. #3298 changes bundle recording (record_execute_indirect). This PR only adds the include and copies the debug names in ExecuteCommandLists. No new command type is involved; an indirect command in a bundle still shows up as ExecuteIndirect in the breadcrumbs.

What has been run. All runs on an RTX 4060 Ti, driver 621.01, Windows 11, MSVC, LEONIDA_VK_VALIDATION=1 plus synchronization validation, implicit layers off. In every tree the same 8 tests skip (no game package, corpus, LEONIDA_FIRST_LIGHT_DIR or RGB9E5 RTVs), and gameinput is disabled as on main.

Tree Result VUIDs
main 3faac557 169/169 0
this PR merged with it 173/173 0
same, LEONIDA_DRED=1 for every test 173/173 0
  • On AMD/Linux, @crastinator's RX 6700 XT run (RADV) passed ctest 43/43 on db77d45. That covers the normal path; whether the GPU-marker part of vk_breadcrumbs ran there hasn't been confirmed yet.
  • No real device loss has been tested anywhere. vk_device_lost and the fault-info capture use mocks: vkQueueSubmit returns VK_ERROR_DEVICE_LOST, and vkGetDeviceFaultInfoEXT is mocked.

Prepared locally, not pushed yet:

  • Two fixes from an audit:
    • A queue that never names itself, such as the device's staging queue, could inherit the debug name of a destroyed queue at the same address. A new test fails on db77d45 and passes with the fix.
    • The DRED output getters read the snapshot outside the lock it is built under.
  • The integration with main's CPU-held batches: a list held behind an unsignalled Wait is now marked under the application's list, with its name, rather than the internal copy.
  • main's SetName went back to private data (55a07318), so the names are read through GetPrivateData again.

AI-assisted (Claude Code).

Preserve the optional Vulkan DRED hooks alongside main's new device
functions and adapt deferred command-list batches to keep their
original diagnostic names.

Fix stale queue-name reuse and protect DRED snapshots under their
own mutex. Add regression coverage for deferred batches and
reused object addresses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AimLogin
AimLogin marked this pull request as ready for review November 23, 2026 08:45
@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested abd8012 on NVIDIA GeForce RTX 4080, driver 617.42, Windows 11 (clang-cl cross-build): vk_breadcrumbs_test and vk_device_lost_test exit 0 with "0 validation errors" (seven checks ok each, including "1026 lists across a ring wrap" and "eight threads at once, one report, no deadlock"). d3d12_dred_test exits 0 with LEONIDA_DRED unset ("3 backend(s) passed") and with LEONIDA_DRED=1 ("3 backend(s) passed"); the LEONIDA_DRED=1 run prints "page fault VA 0x10040". Real-driver marker and fault contents are not verified here.

AI-assisted.

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.

4 participants