Skip to content

GPU diagnostics: breadcrumbs name the command a hung submission is stuck in (VICTORY_GPU_BREADCRUMBS) - #2310

Open
desplmfao wants to merge 11 commits into
Marvisak:mainfrom
desplmfao:diag/gpu-breadcrumbs-main
Open

desplmfao wants to merge 11 commits into
Marvisak:mainfrom
desplmfao:diag/gpu-breadcrumbs-main

Conversation

@desplmfao

@desplmfao desplmfao commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When a submission hangs the GPU (on NVIDIA: Xid 109 CTX SWITCH TIMEOUT, then device removed), VIctory can say which submission it was and list every pipeline in it, but not which command the GPU was running. vkd3d-proton's VKD3D_CONFIG=breadcrumbs printed nothing on NVIDIA here. Bisecting the submission's pipelines with VICTORY_SKIP_PIPELINES found nothing, because three of them were involved together.

Change

Diagnostics feature only. Opt-in with VICTORY_GPU_BREADCRUMBS=1. When the switch is off, the cost is one flag load per command and no GPU writes.

  • Recording: each draw, dispatch, ExecuteIndirect, copy, clear, resolve and texture upload VIctory records gets a sequence id. Our own commands (indirect clamp, depth twins, present) get one too. On the CPU each list keeps the id, the kind of command, the frame and the bound pipeline's shaders.

  • GPU markers: WriteBufferImmediate writes the id before the command (MARKER_IN) and after it (MARKER_OUT) into the list's slot of a mapped READBACK buffer (16384 slots of 8 bytes). The buffer can still be read after the device is lost.

  • When it reports: a submission still running after 3 s logs at 3, 6, 9 and 12 s while the GPU is busy. On device removal it logs once, before the existing error. The report gives:

    • each list's state (done, waiting, stuck);
    • for a stuck list, the first command that started but didn't finish, and the three before it.

    Lines stay under 900 bytes, because Wine aborts longer log lines.

  • The buffer is skipped with a warning if the device lacks WriteBufferImmediate on the direct queue.

What it found

In Grand Theft Auto VI on an RTX 5080 (Linux, Proton, vkd3d-proton 3.2.0), the "hang" at world load turned out to be no hang at all. It is one list of 7,031 commands that the GPU works through steadily:

GPU breadcrumbs (still running after 9 s, submission 2657): list 521 (1 of 1) started #38248 finished #38219 of 7031 commands; first not finished: #38220 dispatch [compute 28918b7150a7aad5] frame 880 (command 3648 of the list, 29 started); ...

At 3, 6, 9 and 12 s the list had reached commands 2,502, 3,035, 3,648 and 4,305. Almost all are direct dispatches of three programs from Microsoft's XboxBvhBuilder.dll (shipped with the title), which rehydrate streamed ray-tracing acceleration structures: Box32Rehydration 28918b7150a7aad5, Box16Rehydration caa78b8ca62bc3d6 and DecompressHeader 4ddd6f9702fab2a7. The submission takes longer than the driver allows. With those three skipped, the run goes 5 minutes in the world without a timeout. Why they are this slow under VIctory is the next question.

Since then it located two more problems, and each led to a fix:

  1. The BVH list. With Shaders: guard memory_dirty atomics with test-before-or and coalesce page-table loads (FIND-12) #2167 (guarded dirty-mark atomics) merged on our stack, the same list finishes. The breadcrumbs stopped pointing at those passes, so the change could be confirmed in the title (reported on Shaders: guard memory_dirty atomics with test-before-or and coalesce page-table loads (FIND-12) #2167).
  2. A real hang in the hair system. The GPU's "finished" id stood still for 3, 6 and 9 s on a dispatch of smh_pose_1:CS_UpdatePosePosition d3e44e754b3eb6aa. Skipping that pass moved the stuck point to smh_pose_1:CS_PreSkinSimNodes 0e45e59e93b736e4 (the first command of its list), and then to smh_pose_0:CS_UpdatePosePosition da1656ad2910e4c7. So it was the whole strand-hair family, not one program. With vkd3d-proton's VK_NV_raw_access_chains disabled, all of them run, and the title went 10 minutes with no timeout. Bisecting by VICTORY_SKIP_PIPELINES without the breadcrumbs had given a wrong answer for the earlier hang, because several programs were involved.

Each marker after a command waits for that command to finish, so the GPU is serialised while this is on. That slows it down, and could in principle hide a timing-dependent hang. It is a tool for finding a hang, not for playing.

Tested

AI-assisted (Claude Code).

🤖 Generated with Claude Code

Diagnostics builds, VICTORY_GPU_BREADCRUMBS=1. Each draw, dispatch,
mesh dispatch, ExecuteIndirect, copy, clear and resolve recorded on a
host list gets an id, kept on the CPU with its kind, the bound
pipeline's shaders and the frame. Around it the list writes the id into
its slot of a mapped read-back buffer with WriteBufferImmediate
(MARKER_IN before, MARKER_OUT after). A submission still running after
3 s, or a removed device, logs per list the last started and finished
ids and the first command started but not finished, with the three
before it. Off: no writes, one flag load per command.

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

@DenRakEiw DenRakEiw 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.

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Clean, feature-gated (diagnostics) GPU breadcrumb implementation (crumbs.rs) with WriteBufferImmediate markers around draws, dispatches, copies, resolves, and clears, plus structured hang reporting.
  • cargo test -p victory-gpu --features diagnostics crumbs::: 8/8 passed on RTX 5090, 8/8 passed on WARP (including live GPU execution test executed_list_writes_its_slot).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (both default and --features diagnostics): 0 warnings.
  • cargo xtask policy: 184 files ok.

AI-assisted (Gemini 4 Neon).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
…ak#2310

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

@catminou4 catminou4 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.

GPU breadcrumbs (new crumbs.rs, 411 lines): WriteBufferImmediate markers around each command, per-list progress dumped when a submission runs 3s+ or the device is lost. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Well-designed hang-diagnosis tool; README documents the perf cost honestly.

@desplmfao

Copy link
Copy Markdown
Contributor Author

Added to the description: since opening this, the breadcrumbs have located two more problems in the title, and each led to a fix. They confirmed that #2167 clears the BVH rehydration list. They also found a real hang across the strand-hair passes (smh_pose_*, the "finished" id frozen for 3/6/9 s), which turned out to be vkd3d-proton's VK_NV_raw_access_chains on NVIDIA. Bisecting with VICTORY_SKIP_PIPELINES alone gave a wrong answer for the earlier hang, so these would have been hard to find without it.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. Since the last review only the tests in descriptor/host.rs changed: the merge of #2946 was reverted and the branch now carries #2585's per-thread WHILE_PREPARING hook. The breadcrumbs code (crumbs.rs, wait_crumbed, report_crumbs, HostList::crumbed) is unchanged and stays off unless VICTORY_GPU_BREADCRUMBS is set. This PR and #2585 carry the same test-only commit, so whichever lands second drops it.

CI: passing.


Generated by Claude Code

desplmfao and others added 3 commits November 25, 2026 10:40
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What was wrong: `descriptor::host::tests::WHILE_PREPARING`, the hook that
runs work while a view's texture is prepared, was one global for the
test process. Every test that binds a view prepares one, and the suite
runs tests in parallel, so the hook ran in whichever test prepared
first, or another test replaced it before its own test's prepare ran.
`a_slot_rewritten_while_its_view_is_prepared_views_the_new_record` then
failed with "the slot views the record written last" (the rewrite never
happened) and `views_bound_while_another_slot_gets_its_texture_do_not_wait`
with "both made" (the other slot was never bound).

What changed: the hook is thread-local. `prepare` runs on the thread
that binds the view (`HostHeap::mirror`), so a test's hook runs in its
own prepare and in no other test's. Test code only.

Evidence: the full `cargo test -p victory-gpu --lib` binary, 200 runs
each on Windows 10 (19045) and an RTX 3080: main 67e8ae1 had a failure
of one of the two in 22 runs (13 and 11); with this change, none.
desplmfao and others added 2 commits November 25, 2026 19:50
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	README.md
#	crates/victory-gpu/src/host.rs
Two descriptor tests set a global hook that runs while a view's texture
is prepared, and any test preparing a view took it. With tests running in
parallel, one test could take or replace the other's hook: the work then
never ran where it was meant to, and views_bound_while_another_slot_gets_
its_texture_do_not_wait failed with "both made". It failed that way in CI
on three unrelated pull requests (Marvisak#2310 and two others) within a day. The
hook is now thread-local: set and taken on the test's own thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… this branch hit

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

Copy link
Copy Markdown
Contributor Author

The red CI run (views_bound_while_another_slot_gets_its_texture_do_not_wait, "both made") was a race in main's tests, not this branch, which doesn't touch descriptor/. Two descriptor tests share a global hook that any test running in parallel can take, and it failed the same way on two unrelated branches the same day. #2946 makes the hook per thread. 51f0e57 merges #2946 here so CI runs with it; this PR is stacked on #2946 for that one test-only commit, and drops it once #2946 is in main.

desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
GPU diagnostics: breadcrumbs name the command a hung submission is stuck in (VICTORY_GPU_BREADCRUMBS)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
Upstream main merged Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906 and Marvisak#1152 and took up what
Marvisak#1769 (LDS bounds, Marvisak#1949) and Marvisak#1763 (typed UAV formats, Marvisak#2462) did; main's
code is kept for those.
- emit/lower.rs: ds_bpermute within each half (main's Marvisak#573, same as
  Marvisak#439's); LDS bounds as main's Marvisak#1949 (Marvisak#1769's test-only counter kept, its
  and_guard dropped); title-memory marks: main's straddling-write lookup
  (Marvisak#2484) with Marvisak#2167's current head (3cb308d, rebased on 63bcca4): guarded
  dirty atomics, raw_dword2, memory_null, synthetic_mark_dxil in
  lower/mark_tests.rs; the old Marvisak#2167 head taken out first.
- emit/host.rs: main's shared WARP device and lock (Marvisak#244) with Marvisak#439's
  adapter list and Host::on (create_device takes an optional adapter).
- descriptor/host.rs: main's Marvisak#2462 format checks; Marvisak#1763's tests kept.
- gpu host.rs: main's multi-plane present with Marvisak#2310's crumbed copy.
- pipeline.rs: Marvisak#2118/Marvisak#2311's builder and BVH checks with main's skip
  hashes (Marvisak#1320); draw.rs, shadow.rs, main.rs: both sides.
- Tests main added since get Marvisak#439's Parts fields and emit's Target.
- README: base 63bcca4; rows of PRs merged upstream, superseded or closed
  taken out, with a note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
The previous renderer (old upstream base 940d32f) is the first parent and
is also kept as the branch renderer-2026-11-25-oldbase; the second parent
is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with
the renderer stack merged on it: Marvisak#439 (on main: update/439-main's
resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292,
Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small
windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes.
Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by
main: Marvisak#1769, Marvisak#1763, Marvisak#2366.

The picture on this base still shows the overlay that plain upstream main
shows too; that is being looked into.

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

Copy link
Copy Markdown
Contributor Author

Correction to the note above: the test-race fix is #2585, which came first. #2946 duplicated it and is closed. The 51f0e57 merge here carries the same change, and it goes away once #2585 is in main.

desplmfao and others added 2 commits November 25, 2026 22:30
…est race this branch hit"

This reverts commit 51f0e57, reversing
changes made to 9c9d507.
…own thread

The CI test race fix this branch hit; it replaces Marvisak#2946, which duplicated it.

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

@fuzeofficlal fuzeofficlal 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.

Reviewed and verified 9ac40934 (based on origin/main 63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 and WARP, Rust 1.98.1 MSVC, Windows SDK 10.0.26100.0 dxil.dll; synthetic tests only, no game files).

Verification

  • cargo xtask policy: 192 files ok.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features): 0 warnings; cargo check --locked --release -p victory-gpu (non-diagnostics): clean.
  • RTX 5090 & WARP (VICTORY_D3D12_DEBUG=1, --features diagnostics): crumbs::tests 8/8 passed, and with VICTORY_GPU_BREADCRUMBS=1, crumbs::tests + draw::tests 28/28 passed on both adapters.
  • Drained D3D12 InfoQueue probe around make(&host.device) and WriteBufferImmediate (MARKER_IN / MARKER_OUT): 0 Debug Layer warnings/errors on both RTX 5090 and WARP.

Blocking Issue: Out-of-bounds panic in progress() / report_list() when finished > last

In crates/victory-gpu/src/crumbs.rs:256-270:

    if finished == last {
        return Progress::Done;
    }
    if started < first || started > last {
        return Progress::NotStarted;
    }
    // The first not finished: after `finished` if it is one of ours.
    let first = if finished >= first { ids.partition_point(|&id| id <= finished) } else { 0 };

Line 267 checks finished >= first without checking finished < last.

Because list slots alias modulo SLOTS = 16384 (crates/victory-gpu/src/crumbs.rs:115), if a long-lived list A (for example p.copy or an older reused list) shares slot = id % 16384 with a newer list B (id + 16384), and A records/executes a higher command id a1 > B.last after B was recorded (writing (a1, a1) to the slot), then when B starts executing and hangs inside its first command before MARKER_OUT runs, the slot holds (started = B.first, finished = a1 > B.last) (the same condition can also occur across u32 id wraparound).

In that state:

  1. finished >= first is true, so ids.partition_point(|&id| id <= finished) returns ids.len().
  2. progress() returns Progress::Stuck { first: ids.len(), in_flight: 0 }.
  3. report_list() (crates/victory-gpu/src/crumbs.rs:309) indexes &trail.entries[first], panicking with index out of bounds right inside report_crumbs — before fail(...) (crates/victory-gpu/src/host.rs:1350) can even emit the DRED/device-removal report.

Live GPU reproduction (RTX 5090 and WARP):
Using two real command lists sharing slot 7777 via WriteBufferImmediate (list_b with ids = [1, 2] recording only MARKER_IN(1); list_a recording MARKER_IN(3) + MARKER_OUT(3) and executing first, followed by list_b):

  • Slot readback on both RTX 5090 and WARP: ids=[1, 2] started=1 finished=3
  • progress(&ids, 1, 3) returned Stuck { first: 2, in_flight: 0 } with entries.len() == 2
  • report_list(...) panicked at crates/victory-gpu/src/crumbs.rs:309:31: index out of bounds: the len is 2 but the index is 2

Fix: constrain crates/victory-gpu/src/crumbs.rs:267 to if finished >= first && finished < last (matching the comment on line 266) and add a unit test covering finished > last (e.g. progress(&[10, 12, 15], 10, 20) == Progress::Stuck { first: 0, in_flight: 1 }).

Non-blocking Notes

  • crates/victory-gpu/src/crumbs.rs:232-233: make() calls std::ptr::write_bytes on a D3D12_HEAP_TYPE_READBACK mapping. Although D3D12 Debug Layer reported no messages on RTX 5090 or WARP, CPU writes to READBACK heaps are disallowed by the D3D12 specification and unnecessary because CreateCommittedResource zero-initializes committed buffers. Removing the write_bytes call is cleaner and avoids dirty cache-line writeback hazards.
  • crates/victory-gpu/src/host.rs:1350 / crates/victory-gpu/src/crumbs.rs:312: if Signal/SetEventOnCompletion fails on an already-lost device and wait_crumbed is skipped, trail.submission still holds its previous submission number; passing submission from report_crumbs into report_list would keep the logged submission id accurate in that path too.

…ist's

progress() took any finished word at or after the list's first id as one
of its own. Slots repeat every SLOTS ids, so a long-lived list sharing the
slot (or ids that wrapped) can leave a finished word past this list's last
id; then the first unfinished command was ids.len(), and report_list
indexed past the entries and panicked before the device-removal report.
Now such a word counts as nothing of this list finished.

Found and reproduced by fuzeofficlal's review of Marvisak#2310 (RTX 5090 and WARP,
two lists sharing slot 7777).

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

Copy link
Copy Markdown
Contributor Author

@fuzeofficlal thanks, that's a real one, and the live repro with two lists sharing a slot makes it clear. Fixed in f55f635 as you suggested: progress() takes finished as this list's only when finished >= first && finished < last. Otherwise nothing of the list counts as finished, and the first command is the stuck one. The new test a_finished_word_past_the_last_id_is_not_ours covers your case (progress(&[10, 12, 15], 10, 20) is Stuck { first: 0, in_flight: 1 }) and the slot-7777 shape (&[1, 2], 1, 3). It fails with the old condition and passes now. crumbs:: gives 9 passed under Wine with --features diagnostics, and clippy is clean with and without diagnostics.

desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@fuzeofficlal fuzeofficlal 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.

Re-reviewed and re-verified f55f6355 (based on origin/main 63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 and WARP, Rust 1.98.1 MSVC, Windows SDK 10.0.26100.0 dxil.dll; synthetic tests only, no game files).

The out-of-bounds panic in progress() / report_list() is cleanly resolved:

  • crates/victory-gpu/src/crumbs.rs:270 now checks finished >= first && finished < last, guaranteeing first < ids.len() for every Progress::Stuck result so report_list() (crates/victory-gpu/src/crumbs.rs:312) cannot index past trail.entries.
  • Live GPU slot-collision reproducer re-run (RTX 5090 & WARP, VICTORY_D3D12_DEBUG=1): two real command lists sharing slot 7777 via WriteBufferImmediate (ids=[1, 2], started=1, finished=3) no longer panic on either adapter; report_list() returns Progress::Stuck { first: 0, in_flight: 1 } and logs command #1 (list_b_cmd_1) cleanly.
  • New unit test a_finished_word_past_the_last_id_is_not_ours (crates/victory-gpu/src/crumbs.rs:364-367) covers both cases.

Verification

  • cargo xtask policy: 192 files ok.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features): 0 warnings; cargo check --locked --release -p victory-gpu (non-diagnostics): clean.
  • RTX 5090 & WARP (VICTORY_D3D12_DEBUG=1, --features diagnostics): crumbs::tests 9/9 passed, and with VICTORY_GPU_BREADCRUMBS=1, crumbs::tests + draw::tests 29/29 passed on both adapters.

Approved.

BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants