Skip to content

D3D12.X: GPU profilers time a split program's ExecuteIndirect chain - #3698

Open
tiagonleal wants to merge 1 commit into
xcl-dev:mainfrom
tiagonleal:d3d12x/profile-chained-indirect
Open

tiagonleal wants to merge 1 commit into
xcl-dev:mainfrom
tiagonleal:d3d12x/profile-chained-indirect

Conversation

@tiagonleal

@tiagonleal tiagonleal commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

An ExecuteIndirect of a split compute program runs its chain (dispatch_chain::execute_indirect, from #3499): 16 rounds of a UAV barrier, a piece bind and one PC ExecuteIndirect for each piece. That path opened no gpu_profile span, while a direct dispatch's chain gets one (bind::translated_dispatch). XCL_GPU_TIMES starts a call's interval at the previous stamp on the list, so the chain's GPU time went to the next timed call, and XCL_GPU_PROFILE did not time it at all.

How it was found: with XCL_GPU_TIMES on an RTX 5070 Ti, main 1c8b5514 showed two compute programs of the Newer Retail Game at 365 and 193 ms a frame. A frame captured on that commit had 510 chained ExecuteIndirects, with runs of them on the same lists right before those two programs. An estimate from their piece counts (not a measurement) puts those runs at about 402 and 208 ms. So most of that time was very probably the chains, not the two programs.

This changes no title behaviour. #3528 makes the chain rarer (whole form once built), but the chain still runs while a whole form is being built or after it was refused, so the attribution is needed with it too. No open PR or issue covers this (searched gpu_profile indirect, GPU times chain, XCL_GPU_TIMES, execute_indirect_chain; #3528 and #3540 do not touch these lines).

What is in it

  • real/dispatch_chain.rs: execute_indirect opens a gpu_profile span (Kind::IndirectDispatch, the program's pipeline, max count 1) after the slicer pass and the chain's bind, only when the bind succeeded, as bind::translated_dispatch does for a direct chain. It closes the span after the pieces and the restore of the slicer's commands. A call that hands off to the whole form returns before it, so it is not counted twice. A call whose bind fails runs no piece and is counted as skipped, so it gets no span.
    • With XCL_GPU_PROFILE the span leaves out the slicer pass; XCL_GPU_TIMES counts it, because its interval starts at the previous stamp on the list.
    • The chained calls that get bound now also go through watch::note (in gpu_profile::begin), so they show up in its ring of the last draws and dispatches, which XCL logs on a driver error, a device removal or a stall (TDR).
  • gpu_profile.rs: a #[cfg(test)] thread-local log of begin / end calls for the test.
  • Test a_chained_indirect_dispatch_is_timed_as_its_own_call (real/dispatch_chain.rs): on one list, a timed call, a chained ExecuteIndirect through bind::execute_indirect_chain, a timed call; it checks for three spans with the chained program's pipeline in the middle one. Then a chained call whose bind fails, and it checks that this one opens no span.

Tested

  • Windows 11 Pro build 26300, NVIDIA GeForce RTX 5070 Ti (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0, debug
  • New test with the two runtime lines taken out: cargo test -p xcl --lib a_chained_indirect_dispatch_is_timed: 0 passed, 1 failed (two spans, the chain in none). With them: 1 passed.
  • Focused: cargo test -p xcl --lib <filter> -- --test-threads=4 for gpu_times (5 passed), gpu_profile (2 passed), dispatch_chain (44 passed, 1 SKIPPED: no wave64), execute_indirect (12 passed).
  • Head 9f205510 (on main 5eaadb54): the full suite ran on 39fdef43, whose tree differs only in one comment (a /// on the test-only thread_local! became // to drop an unused-doc-comment warning): cargo build --workspace ok; cargo test --workspace --no-fail-fast -- --test-threads=4: 2975 passed, 0 failed, 52 ignored, 24 SKIPPED (22 no wave64, 2 no heap windows). On 9f205510, a_chained_indirect_dispatch_is_timed_as_its_own_call passes.

Regression run
scripts/smoke.ps1 -Seconds 60 -Title 9cc6a39e (Newer Retail Game), release builds in clean trees, XCL_PREPARE=0 and the same warm DXIL cache, one run each. The main block is from earlier today on 1c8b5514.

main (1c8b5514):

xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1563 (PresentX 1563)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14842 MB

This PR (9f205510):

xcl-smoke v1
commit: 9f20551018fa19eb7ddac78cdc54e1f389b90b44
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1700 (PresentX 1700)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16708 MB

Not tested

  • A world run with XCL_GPU_TIMES or XCL_GPU_PROFILE on this head: the numbers above come from main, and the new split of time between the chain and the next call is not measured yet.
  • AMD, other drivers.

AI use

  • Claude Code with Claude Opus 5.5 and Anthropic subagents (Claude Fable 5.2 for the analysis, Claude Opus 5.5) helped developing.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Review (head 3b54c45, diff read, not a merge-check):

  • A chain whose bind fails is still recorded as a timed dispatch. In real/dispatch_chain.rs ~636, gpu_profile::begin runs before bind(...); when bound is an Err no piece is recorded, yet the span is still opened and closed around restore_indirect_commands alone, while the caller counts the call as DISPATCHES_SKIPPED (bind.rs ~3846). XCL_GPU_TIMES then counts a call that never ran and watch::note puts it in the ring of recent dispatches logged on a device removal. bind::translated_dispatch binds first and opens its span only after the bind succeeds (bind.rs ~5071-5075); opening it after bind and only when bound.is_ok() would match.

Fine: every early exit (the Indirect::Whole hand-offs, the bundle case, the ? errors) returns before begin, and nothing returns between begin and end; the span covers the whole-form tail, all rounds of barriers and pieces and the restore; both profilers already skip list types other than direct and compute; unset, the default path adds only watch::note and two cached env checks. #3528 edits the same function two lines away.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

An ExecuteIndirect of a split compute program runs its chain
(dispatch_chain::execute_indirect): 16 rounds of {UAV barrier, piece
bind, ExecuteIndirect} for each piece. No gpu_profile span was opened
around it, while a direct dispatch's chain gets one
(bind::translated_dispatch). XCL_GPU_TIMES starts a call's interval at
the previous stamp on the list, so the chain's GPU time was charged to
the next timed call. On an RTX 5070 Ti, main 1c8b551 showed two compute
programs of the Newer Retail Game at 365 and 193 ms a frame. A frame
captured on that commit had 510 chained ExecuteIndirects, with runs of
them on the same lists right before those two programs.

The span opens after the slicer pass and the chain's bind, only when
the bind succeeded, and closes after the pieces and the restore of the
slicer's commands, as bind::translated_dispatch opens a direct chain's
span once it is bound. A call that hands off to the whole form
(Indirect::Whole) is not counted twice, and one whose bind fails (the
caller counts it in DISPATCHES_SKIPPED) is not counted at all. The test
records a timed call, a chained ExecuteIndirect through
bind::execute_indirect_chain and a timed call on one list, and checks
for three spans with the chained program's pipeline in the middle one;
then a chained call whose bind fails, and checks that it opens no span.
@tiagonleal
tiagonleal force-pushed the d3d12x/profile-chained-indirect branch from 3b54c45 to 9f20551 Compare December 2, 2026 15:59
@tiagonleal

Copy link
Copy Markdown
Contributor Author

Thanks, you were right: in 9f20551 the span now opens after bind and only when it succeeded, and it is closed only if it was opened, so a skipped chained call no longer reaches XCL_GPU_TIMES or the watch::note ring. The test a_chained_indirect_dispatch_is_timed_as_its_own_call now also runs a chained call whose bind fails and checks that it opens no span; that part fails on 3b54c45 and passes on 9f20551.

~Tiago

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 9f20551, since 3b54c45, diff read, not a merge-check):

  • A chain whose bind fails is still recorded as a timed dispatch: fixed. The span opens only when bound.is_ok() (real/dispatch_chain.rs ~636-650), as translated_dispatch does, and the test checks that a chained call whose bind fails records no span.

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@fromthemoonx

fromthemoonx commented Dec 3, 2026 •

Copy link
Copy Markdown

merge-check
base: 395405e
head: 9f20551
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3013 passed, 0 failed, 56 ignored (base: 3012 passed, 0 failed, 56 ignored); SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none
review: read the whole diff (2 files, +92). No finding.

  1. The span is measured on the GPU, not only opened. The existing test a_split_indirect_dispatch_slices_the_counts_the_guard_let_through runs 3 chained calls on a real queue. I ran it with XCL_GPU_PROFILE=1 and printed what the profiler had collected (scratch code):
spans recorded for the 3 chained calls
base 0
merge 3 (IndirectDispatch, all with valid stamps)

The test passes both ways, so the pieces still run the right groups. The D3D12 debug layer gives the same 12 messages on base and on the merge, with the profiler on or off, so the span adds none.
2) The new test passed 30 of 30 runs alone, and its module 30 of 30 at 8 threads. It fails when the span is never opened (two spans instead of three) and when it is opened although the bind failed.
3) Every early return in execute_indirect is before the span opens, and nothing returns between its begin and end.
4) Not tested: real numbers from XCL_GPU_TIMES (it measures frames of a title), a retail title (none on this machine), AMD.
performance: with the profilers off, a chained call adds one watch::note and the two checks whether they are on. Reasoned, not measured.
verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants