Skip to content

BUILD-1655: per-operation Vulkan DRED breadcrumbs (LEONIDA_DRED=2) - #5314

Draft
AimLogin wants to merge 5 commits into
ItsNotRexed:mainfrom
AimLogin:claim/BUILD-1655-dred-per-op
Draft

AimLogin wants to merge 5 commits into
ItsNotRexed:mainfrom
AimLogin:claim/BUILD-1655-dred-per-op

Conversation

@AimLogin

Copy link
Copy Markdown
Contributor

BUILD-1655 (claim), a follow-up to D3D-264.

Depends on: #3293. This branch is #3293's head abd80129 plus one commit. Until #3293 is merged, the diff below includes it; the BUILD-1655 part alone is abd80129...160a72d6.

Why

#3293 tells which command lists the GPU started and finished. Its *pLastBreadcrumbValue is always 0, because it doesn't know how far a started list got. With a list of thousands of draws, "list X was running" is a weak lead. This PR records progress per D3D12 operation, so a node says how many of the list's operations the GPU finished.

What

Three levels (LEONIDA_DRED, read once):

Level Records GPU cost
unset / anything else nothing; one null check per command in replay none
1 (#3293) a breadcrumb per command list: begin word at TOP_OF_PIPE, end word at BOTTOM_OF_PIPE ≈ none
2 (this PR) level 1, plus a progress marker after every D3D12 operation ≈ 0.4 µs per operation on an RTX 4060 Ti

Level 2 is its own level, not part of =1, because it roughly doubles GPU time for small operations (table below). =1 stays cheap enough to leave on.

How the progress is recorded (vulkan_breadcrumbs.h, vulkan_replay.h emit(), vulkan_backend.h):

  • Op numbers. mark() notes each D3D12 operation of a list together with the index of the IR command it stands for, and gives the list a range of 32-bit op numbers under the ring's lock. Numbers are never 0, and a range never spans 0.
  • Markers. emit() writes first + k into the list's slot word at BOTTOM_OF_PIPE once operation k's command is recorded. The marker goes in at the top of the next loop step, or after the loop, where no rendering scope is open: every draw and clear opens and ends its own.
  • Reading the word. BOTTOM_OF_PIPE writes only after every earlier command of the queue has finished, so the word counts operations finished in order. Only a word in the list's own range counts (word - first < count, unsigned). The initial 0, an older range, or one across the 32-bit wrap reads as "none finished", never as more.
  • Slot reuse. At level 2 a ring slot is taken over only once its previous owner is seen finished, i.e. its end word holds its tag. A finished list writes nothing more, so no older list's marker can land in the new owner's word, however many op numbers were handed out in between. The range check alone wouldn't rule that out: a list stuck on another queue could write after 2^32 op numbers.
  • All slots busy. If all 1024 slots hold lists the GPU hasn't been seen to finish, the new list gets its list markers only, and its progress is reported as unknown. A failed submission frees its slot at once, since it never runs.
  • Memory. The command positions are dropped at submission, so the history keeps one uint32 per operation, as at level 1. The ring is 1024 slots × 16 bytes.

D3D12 outputs (d3d12_dred.h):

  • BreadcrumbCount: the list's operations.
  • pCommandHistory: their D3D12_AUTO_BREADCRUMB_OPs, in order.
  • *pLastBreadcrumbValue: the number the GPU finished, at level 2.
  • NODE and NODE1 share the same arrays.
  • At level 1, or when progress is unknown, *pLastBreadcrumbValue stays 0. D3D12 has no "unknown", so 0 is a lower bound, never a guess.

Report (stderr): a started list reads one of:

  • "K of N operations completed", when observed;
  • "progress inside the list not recorded", at level 1;
  • "GPU progress UNKNOWN", without VK_AMD_buffer_marker.

Docs: docs/d3d12_vulkan.md §4.11.

Tests

Observed on the GPU, with validation and synchronization validation:

  • vk_breadcrumbs:
    • every operation of a finished list reads finished: 3 + 1 operations in one submission, a list reset and recorded again, a held batch, two queues on two threads (800 lists), and a 1026-list ring wrap;
    • op numbers across the 32-bit wrap, starting at 0xfffffffd;
    • with list markers only, no per-op progress is claimed.
  • d3d12_dred_off, d3d12_dred_on and the new d3d12_dred_ops (LEONIDA_DRED=2).

Mocks, with markers counted and not written, and a controlled loss (vk_device_lost):

  • after a loss no list claims an operation finished;
  • the marker count is exactly 2 per list plus 1 per operation;
  • with all 1024 slots held by unfinished lists, the next list gets no per-op marker and its progress is unknown.

Synthetic, not observed on a GPU:

  • the range check: never written, a previous owner, a later owner, the 32-bit wrap, an empty list;
  • a list stopped partway: 2 of 4, 0 of 2, and unknown;
  • BreadcrumbCount, pCommandHistory order and *pLastBreadcrumbValue, node by node in NODE and NODE1;
  • the three report forms.

A list can't be held on the GPU between two of its own operations without risking a hang, so partial progress is only tested this way.

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

Tree LEONIDA_DRED unset =1 =2 VUIDs
#3293 abd80129 173/173 173/173 — 0
this PR 174/174 174/174 174/174 0

The only new test is d3d12_dred_ops, and the validation output matches abd80129's. The same 8 tests skip (no game package, corpus, LEONIDA_FIRST_LIGHT_DIR or RGB9E5 RTVs), and gameinput is disabled by default.

Cost

Lists of N operations, each a 16-byte copy and a copy → copy barrier, best of 7, three runs. These are tiny operations, so the cost per operation dominates. Record is execute() on the CPU; wait is the GPU finishing after it. NVIDIA only so far: other drivers may implement buffer markers differently.

N record: off / level 1 / level 2 (ms) wait: off / level 1 / level 2 (ms)
100 0.04–0.05 / 0.04 / 0.05–0.07 0.08–0.10 / 0.08–0.09 / 0.12–0.14
1,000 0.24–0.26 / 0.25–0.27 / 0.31–0.33 0.43–0.45 / 0.44–0.45 / 0.84–0.89
2,000 0.47–0.49 / 0.49–0.51 / 0.58–0.60 0.82–0.84 / 0.82–0.84 / 1.63–1.71
10,000 2.3–2.6 / 2.4–2.6 / 2.9–3.3 3.9–4.3 / 3.9–4.2 / 8.1–8.7

Limits

  • Bundles. ExecuteBundle copies the bundle's commands into the calling list, so the history lists the bundle's own operations. The host runtime lists one EXECUTEBUNDLE instead. The progress is right, but finer than on the host. Recording the bundle boundary is a possible follow-up.
  • ExecuteIndirect. One operation, whatever its argument buffer holds.
  • Predication. An operation the predicate skipped, or one the layer records as a no-op, counts as finished, as on the host.
  • Marker reuse. The slot guard assumes that a list's earlier marker writes are visible before its end word. Both are written by the same queue, in order, but the Vulkan spec doesn't guarantee the order in which the host sees two marker writes. A late write can only lower the progress shown, never raise it.
  • No real GPU device loss was tested. What a driver leaves in the words after a hang or fault isn't covered. No AMD or Intel results yet.

No game files.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

AimLogin and others added 4 commits November 22, 2026 21:00
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>
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>
LEONIDA_DRED=2 adds a progress marker after every D3D12 operation, on
top of ItsNotRexed#3293's per-list breadcrumbs (LEONIDA_DRED=1), so a device-lost
report and D3D12's *pLastBreadcrumbValue say how many of a started
list's operations the GPU finished.

- Ring: four words per slot (begin, end, progress, padding). mark()
  gives each list a range of 32-bit op numbers (never 0, never spanning
  0) and notes each operation's IR command index; emit() writes
  first + k at BOTTOM_OF_PIPE after operation k, between commands where
  no rendering scope is open. Only a word inside the list's own range
  counts, so anything foreign reads as "none finished", never as more.
- Slot reuse: at level 2 a slot is taken over only once its previous
  owner wrote its end word, so no older list can still write into it
  whatever the op count in between. With every slot held by unfinished
  lists, the new list gets list markers only and its progress is
  unknown. A failed submission frees its slot.
- Unknown is said as such: at level 1, or without a safe slot, a
  started list's progress is "not recorded", not 0 completed;
  *pLastBreadcrumbValue stays 0 there as a lower bound. NODE and NODE1
  share the count, history and value.
- The per-op command positions are dropped at submission; the history
  keeps one uint32 per operation, as before.
- Cost on an RTX 4060 Ti: level 1 about free, level 2 about 0.4 us of
  GPU time per operation (twice the GPU time for 10,000 small copies),
  hence its own level.
- Tests: vk_breadcrumbs (GPU: several operations, reset and reuse,
  held batches, two queues, 1026-list wrap, op numbers across 2^32,
  list markers only; cost table), vk_device_lost (no progress claimed
  after a loss, marker counts, every slot busy), d3d12_dred_test
  (synthetic partial progress, node-by-node NODE/NODE1), and the new
  d3d12_dred_ops (LEONIDA_DRED=2).
- Docs: docs/d3d12_vulkan.md section 4.11.

Depends on ItsNotRexed#3293.

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

@DoubleD17 DoubleD17 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The all-slots-busy fallback can make a later list's per-operation progress unreliable across queues.

At 160a72d66486cf82078ebb6ed60f0818512cd959, BreadcrumbRing::mark() leaves progress_safe false when all slots are busy, but still replaces owner_[m.slot]. The fallback list still writes its end tag via record_end().

Consider a full ring where an earlier list A still holds a slot on queue 1. An overflow list B takes it on queue 2 and writes its end tag. A subsequent list C now sees B's end tag match owner_ and gets progress_safe = true, although A can still write into the slot. When A resumes, its older operation tag can overwrite C's progress word. C's range check then reports zero completed operations even if its first marker was already visible. This needs no sequence wrap.

Can the overflow lists use CPU-only history, leaving the GPU slot owner in place until its actual writer finishes? The regression case needs an overflow list that finishes before the old owner, followed by another reservation. I traced the pinned source and verified the ordering with an independent CPU model of the marker words. I did not build or execute the PR or test this ordering on a GPU.

No game files. AI-assisted.

@AimLogin

Copy link
Copy Markdown
Contributor Author

Thanks @DoubleD17, the trace holds. At 160a72d6, the all-slots-busy branch of BreadcrumbRing::mark() sets progress_safe = false but then still runs owner_[m.slot] = m.tag (line 359). record_begin()/record_end() still write the overflow list's tags, so its end word can make the slot look free while A, the actual writer, is still pending.

The same overwrite also drops A's own entry from snapshot(), because owner_ no longer holds A's tag. An unfinished list can then disappear from the device-lost report.

I'm fixing it along the lines you suggest. An overflow list keeps CPU-only history: it gets no begin, end or per-op markers, owner_ stays with the slot's real owner, and its GPU progress reads as unknown. There will be a deterministic regression test for your A/B/C order. I'll report the test results here once they've run; until then this is a plan, not a fix.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Head 160a72d66. git diff --check clean. Delta reviewed: abd80129..160a72d6 (BUILD-1655, 10 files, +444/-46); the rest of the diff vs main is #3293.

  • Configured with vcvars64 + Ninja and the stated Vulkan 1.4.363 options; built d3d12_dred_test, vk_breadcrumbs_test, vk_device_lost_test.
  • LEONIDA_VK_DEVICE='RTX 5070 Ti' ctest -R "vk_breadcrumbs|vk_device_lost|d3d12_dred" --output-on-failure -> 5/5 passed.
  • Output includes breadcrumbs: per-operation progress over 3 + 1 operations and a reset list ok, ... across the 32-bit wrap of op numbers ok, breadcrumbs: 1026 lists across a ring wrap ok, breadcrumbs: 0 validation errors; d3d12_dred_off/on/ops all passed.
  • python -I tests/test_docs_*.py and test_boot_trace.py OK.

Verdict: approve the BUILD-1655 delta; blocked on #3293, which is open. This branch is #3293's abd80129 + one commit, so it cannot merge on its own without carrying #3293's ~2.1k-line diff. Partial progress inside a list is synthetic only (a real list cannot be held on the GPU between its own ops), as the PR says.

Review of ItsNotRexed#5314 (DoubleD17): with every slot held by an unfinished list,
mark() left progress_safe false but still overwrote owner_[slot], and
the overflow list still recorded its begin and end markers. Its end tag
made the slot look free while the slot's real owner, possibly on another
queue, could still write into it. A later list then took the slot and
read too little progress, and the unfinished owner dropped out of the
device-lost report.

- A list that finds no slot whose owner is seen finished takes none
  (kNoSlot). It records no GPU marker at all, changes no owner_ and no
  next_slot_, and is kept as CPU history with its GPU progress unknown:
  no D3D12 node, and "every breadcrumb slot was busy" in the report,
  counted apart from the lists that did not complete. A slot is used
  again as soon as its owner's end word shows.
- A failed submission frees only a slot it really took.
- History: the oldest list that no longer holds a slot is dropped first.
  A list that still holds its slot, finished or not, stays; up to 64
  others are kept besides.
- The begin marker of a list with per-op markers clears the progress
  word, so the previous owner's last op number does not sit there.
- Tests: vk_breadcrumbs slot_ownership() runs the A/B/C order on a ring
  whose GPU writes are the test's own (it fails at 160a72d), plus failed
  submissions, history and CPU only. Also the marker counts in
  vk_device_lost, and the no-slot entry (no node) and a 0-op node in
  d3d12_dred_test.
- Docs, section 4.11: the fallback, and what the Vulkan spec guarantees
  about marker order (per queue, execution only toward the host).

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

Copy link
Copy Markdown
Contributor Author

@DoubleD17, fixed in fa0c0f17, and reproduced first: your A/B/C order fails at 160a72d6.

  • Fix. A list that finds no slot whose owner is seen finished now takes no slot (kNoSlot). It records no GPU marker at all (no begin, end or per-op one), leaves owner_ and next_slot_ alone, and stays in the history as CPU knowledge with its GPU progress unknown. That means no D3D12 node, and "every breadcrumb slot was busy" in the report, counted apart from the lists that did not complete. A slot is used again once its real owner's end word shows.
  • Same mechanism, two more paths:
    • A failed submission used to free a busy slot it had taken; it now frees only a slot it really took.
    • The history used to push out an unfinished owner after 1024 later lists; it now drops lists that no longer hold a slot first.
    • The begin marker also clears the progress word, so a previous owner's last op number doesn't sit there.
  • Test. vk_breadcrumbs slot_ownership() runs your order deterministically on a ring whose "GPU" writes are the test's own. The checks: B and C change no slot word, A stays in the snapshot, a freed slot is reused by exactly the next list, failed submissions behave, and CPU-only mode never claims progress. It fails at 160a72d6 (B's marker lands in A's slot) and passes now.
  • Results. Full ctest passes 174/174 without LEONIDA_DRED, with =1 and with =2, with 0 VUIDs, under validation and synchronization validation (RTX 4060 Ti, 621.01). The validation output matches D3D-264: opt-in DRED device-loss diagnostics for Vulkan #3293's.
  • Still best effort. The Vulkan spec orders marker writes per queue, as an execution dependency. It doesn't promise that the host sees them in that order without a fence wait, or anything after a device loss. The slot guard therefore relies on the host seeing a list's op markers no later than its end marker. That holds on AMD and NVIDIA in practice, and §4.11 now says so. A late write can only lower the progress shown, never raise it. No real device loss was tested.

Thanks for the careful trace.

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