d3d12/timeline: attribute slow command-list ops, caller sites, and bound pipelines in stall and timed traces (D3D12-TIMELINE-STALL-LIST-OP) #3136
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
3 participants
Due date
No due date set.
Reference
leonida/mandy!3136
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/3136"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claimed in the coordination issue as:
D3D12-TIMELINE-STALL-LIST-OP(https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7345129758)Addresses #3105 (does not close it: surfaces the command-list operation, caller return site, and bound title pipeline on slow list calls in stall and timed timeline captures; separate changes address underlying stall sources).
What and why
Extends command-list slow-call timeline attribution (
>= 50 us) so both one-shot rolling stall captures (LEONIDA_TIMELINE_STALL_MS) and timed captures (LEONIDA_TIMELINE) attribute the specific command-list operation, a stack-local caller return site, and the list's currently bound title pipeline pointer instead of collapsing into an unattributed"a long list call"span:"a long list call"blindness in#3105:timeline::record::calledemitted generic"a long list call"withEvent.a = 0andEvent.b = 0, while gatingstack()behindtimed_on()so stall mode (STACKunallocated,Event.stack == 0) retained zero operation, callsite, or pipeline context.list.rsonly timedwith_stateclosures anonymously and left non-with_statehost-list recording methods (ResourceBarrier,BarrierGroups,Sync,CopyBufferRegion,CopyResource,CopyTextureRegion,ResolveSubresource,ClearRenderTargetView,ClearDepthStencilView,CopyMemoryToMemoryX, andWaitValue/WaitValue64list cuts) untimed.timeline::reporthad no long-list-call section insummary_stall_with_freqand ignoredEvent.a/Event.bon long-list-call spans in Chrome JSONargs.copystat.rs,list.rs,timeline.rs,timeline/record.rs):copystat::recorded_op(started, op, pipeline)gatingtimeline::called_from_list(took, op, pipeline)behindtimeline::on(), adding zero call overhead when timeline recording is off.bound_pipeline: AtomicUsizeat the end ofList(preservingoffset_of!(List, put) == 0x18andoffset_of!(List, pipeline_shadow) + 32 == 0x560) across creation,Reset,SetPipelineState,Close,detach, anddetach_parts.with_statecallers with static"a long list call: <Op>"and wraps non-with_statehost-list recording operations (ResourceBarrier,BarrierGroups,Sync, copies, resolves, clears, andWaitValue/WaitValue64cuts) once viameasure_call+with_state_untimedwithout double-counting, usingblack_box(&started)and alignedexternal/upscale->run_external/upscale_nowframe depth soRtlCaptureStackBackTrace(3, 1, ...)resolves the list op's caller (thin::translate/thin::run_plainor title callsite) identically indevand optimized (diag) builds without touchingSTACK(Event.stack == 0in stall mode andsize_of::<Event>() == 64preserved).timeline/report.rs):Trace::doing/chain_stallattributes stall chains directly to"a long list call: <Op>".summary_stall_with_freqadds"list calls of 50 us or more in trigger interval: who, op, caller site, bound title pipeline", formattingEvent.bin hex ({:#x}, matching the hex value ofpipelinein"first bind"log lines).chrome_inneremits"op","at","site", and"pipeline"inargsfor long-list-call spans (preferringEvent.stackin timed mode and falling back toEvent.a).Tested
985661b34ontoorigin/maind0bf821fa):python -I scripts/red_green.py HEAD --no-fetch --no-python(with--features diagnosticstimeline::runner):verdict: red then green(2/2new testsred -> green,17/17existingtimeline::tests pass on both).x86_64-pc-windows-msvc):cargo test -p leonida-gpu --features diagnostics --lib --target x86_64-pc-windows-msvc timeline::(devand--releaseopt-level=3):19 passed, 0 failed(verifies exact caller identity via PE.pdataRtlLookupFunctionEntryin both unoptimized andopt-level=3builds,Event.stack == 0in stall mode, and stall/timed.txt+ Chrome JSON formatting).cargo test -p leonida-gpu --features diagnostics --lib --target x86_64-pc-windows-msvc copystat:::4 passed, 0 failed.cargo test -p leonida-gpu [--features diagnostics] --lib --target x86_64-pc-windows-msvc list:::12 passed, 0 failedin bothdiagnosticsand default builds.cargo clippy -p leonida-gpu [--features diagnostics] --all-targets --no-deps --target x86_64-pc-windows-msvc:0warnings in touched files.python -I scripts/check_no_game_data.pyandpython -I tests/test_text_write_line_endings.py: exit0.GPUs tested: NVIDIA GeForce RTX 3090 24 GB, driver 610.88, Windows 11 Pro
10.0.26200(host D3D12 command-list and timeline unit tests; no retail title run).AI-assisted: yes — authored with Gemini 4 Carbon (High) and independently audited across two read-only review cycles by Gemini 4 Neon (XHigh) (which caught and verified the
opt-level=3sibcall frame-depth alignment and zero-overhead!timeline::on()gate).Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Ran natively on Windows 11, head
0518fc48emerged intomain(43fc605ed, merges cleanly; still merges cleanly into today's5b1fff821), on an NVIDIA card and on WARP. Besides the suites, I checked what the body does not cover: theplayprofile (thin LTO, one codegen unit), several threads recording at once, the bounds, the cost, and the reports.Suites on the merge. MEASURED.
leonida-gpu --lib --features diagnostics, cardleonida-gpu --lib(no diagnostics)long_list_calls_record_op_caller_site_and_pipeline_in_stall_and_timed_modes,--profile playtimeline::+copystat::,--profile playreal_waits_are_recorded_with_who_ended_themfails, and fails the same way onmainunderplay: a symbol-name check, unrelated to this PRclippy -p leonida-gpu --all-targets, with and without diagnosticsCaller site and pipeline, several threads at once. Throwaway test, stall mode. 8 threads, each with its own title list (its own pipeline pointer at creation) and its own
#[inline(never)]caller, each doing 200externalcalls of about 100 us. Every retained event was checked:Event.aresolved through.pdatato that thread's caller, andEvent.bwas that list's pipeline. MEASURED.So attribution holds under concurrency and with thin LTO. What is lost is lost whole: the stall ring's
try_lockdrops the event (and counts it indropped_contention). That behaviour is older than this PR, but with 8 recording threads it was 4 to 12 % of the slow calls here. Since the new stall summary ranks ops by total time, that loss is worth keeping in mind when reading it.READ IN CODE: every timed call site I found either calls
with_state/measure_calldirectly from the op function, or goes through an#[inline(always)]helper (wait_for,copy_resource_inner,copy_texture_region_inner,reset_inner,external,upscale), or through a deliberate#[inline(never)]frame (run_external,upscale_now). None of the timed paths nests a timedwith_stateinside ameasure_callclosure. Thin lists replay on the back list in record order, so the pipeline a replayed op carries is the one bound at that point.Bounds. Throwaway test. MEASURED.
EVENTS+ 5,000 slow callsSTACKS(65,536); stall mode leavesEvent.stackat 0 throughoutNo new buffer:
LIST_RUNis oneCellper thread.Cost. Throwaway test,
--profile play --features diagnostics, card: best of 7 x 5,000 calls, 5 runs each, on a machine that was busy with other builds. MEASURED.mainSyncResourceBarrierClearRenderTargetViewTurning the timeline on (stall mode, calls under 50 us) costs nothing I can see over it being off. Against
main,Syncis the same. The barrier and the clear came out about 70 and 200 ns slower at the median. Those two are now timed (twoInstantreads andrecorded_op) where they were not before. But themainand PR runs were not interleaved, and one earlier PR run had the clear at 740-760 ns, so I would not quote these as the cost. A clear in the title's frame is far from a hot path anyway.The "list calls" line of a diagnostics run changes.
copystat::peek(RecordCalls)before and after one call. MEASURED.mainSyncResourceBarrierClearRenderTargetViewCopies, resolves, clears, barrier groups and value waits are now timed, and nested
with_statecalls no longer count twice. That is intended, but the "recording per frame: N list calls, X ms" figures of a diagnostics build are not comparable across this PR, in either direction, depending on the mix. A line in the body would help anyone comparing logs.Timed report: one site spread over many pipelines. Throwaway test of
summary(). One caller site with 40 slow calls of 1 ms, each under a different pipeline (40 ms in all), and one other site with a single 5 ms call. MEASURED.mainthe key is the site alone (READ IN CODE), so the same calls would be one 40 ms row on top.In a real timed capture, where
thin::translateor one title function binds many pipelines, the heaviest site can drop out of the top 25. Keeping that table keyed by op and site, and leaving per-pipeline detail to the stall summary and the JSON, would keep the old ranking.Chrome JSON. A site name with a quote and a backslash is escaped and the file parses (the test's
parse_json). A span witha == 0gives"at":"","site":"0x0","pipeline":"", which is valid. MEASURED.Smaller things (READ IN CODE).
copystat::recordedandtimeline::calledhave no callers left and are kept with#[allow(dead_code)]. A test still callscalledwith its own frame depth (skip 1), whilerecordedwould go throughcalled_from_listwith skip 3, one frame too far for a direct caller. Removingrecordedavoids that trap.git merge-treeagainst #2834's head conflicts inleonida-gpu/src/list.rs. #2834 adds two-argumentwith_statecalls (targets_writtenin clear, clear-depth and resolve, and itswait). Whichever lands second needs a rebase and op names for those calls.Not checked: a capture from a running title (no game run), and the attribution under the
diagprofile itself (dev,playand the body's opt-level 3 runs bracket it).GPUs tested: one NVIDIA desktop card + WARP.
AI-assisted: yes (Claude Code).
Verification of #3136 (third party, code review on Linux; not built: Windows-only
leonida-gpu)0518fc48eb705382fd1d60cf5975c0ac476c4a5c(5 files:list.rs,copystat.rs,timeline.rs,timeline/record.rs,timeline/report.rs; +1054/-297).128648cfe.git merge-tree --write-tree origin/main pr/3136againstmain45dc41f95is clean(70 commits behind). CI on the head: 6/6 success.
python -I scripts/check_no_game_data.pyon the 5 files: exit 0.Review
caller's return site and the bound title pipeline. Each
list.rsentry point goes throughwith_state(this, "<op>", ..)ormeasure_call, and the pipeline is tracked in a new per-listbound_pipelineatomic (set inset_pipelineandreset, cleared on close).#[cfg(feature = "diagnostics")]. In non-diagnostics builds the onlyaddition is a relaxed
AtomicUsizestore perSetPipelineStateandReset, which is negligible.Kal0s-design checked the
playprofile.copystat::recordedandtimeline::calledno longer have callers.They are kept with
#[allow(dead_code)](copystat.rs:1090,timeline/record.rs:343).git grepat the headfinds no caller. Remove them.
called_from_listrecords the return site with a fixedskip = 3. Thecomment explains it as
called_from_list, thenrecorded_op(#[inline(never)]), then thelist.rsopfunction (kept from a sibling call by
std::hint::black_box(&started)), then its caller. That depends onwith_state/measure_callbeing inlined (#[inline(always)]is a strong hint, not a guarantee under everyprofile or LTO setting) and on
black_boxdefeating tail calls. If either changes, the report names the wrongframe with no error. Capture the return address at the extern entry (
list.rsop functions) and pass it down,or check the resolved symbol in a test, so a shift is caught.
list.rschurn is mechanical (each entry wrapped in a named op). It is reviewable, but asplit into "name the ops" and "pipeline + caller site" would have been easier to audit.
timeline/report.rsgains report-format tests. Kal0s-design ran the suites natively on an NVIDIA cardand on WARP, including several recording threads and the play profile.
Process
Verdict: defects (minor). Remove the
#[allow(dead_code)]functions, and make the caller-site skip robust orcovered by a test.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
Thanks @MoonEyes for the sharp catch on both points! Addressed in
c9f63c3b85(merged with currentorigin/main):AGENTS.md): deletedcopystat::recorded(copystat.rs) andtimeline::called(timeline/record.rs) along with their#[allow(dead_code)]attributes (0remaining callers)..pdatacaller attribution +--profile playCOM vtable test (list.rs,copystat.rs,timeline/record.rs):with_state/measure_callwrapper functions withwith_state!/measure_call!macros expanding directly inside all 41 timedlist.rsentry points (eliminating intermediate helper frames across all profiles/LTO), passing[entry_fn, optional_wrapper_fn]function-pointer anchors down totimeline::called_from_liston the>= 50 usslow path.resolve_list_caller_inusesRtlLookupFunctionEntry[BeginAddress, EndAddress).pdatabounds to step past contiguouslist.rsentry/wrapper frames (falling back torecorded_op's immediate caller when an entry is inlined or tail-called, and degrading cleanly when.pdatais absent) instead of relying on fixedskip = 3..pdatashapes (resolve_list_caller_handles_inlining_wrappers_tail_calls_and_missing_pdata) and updatedlong_list_calls_record_op_caller_site_and_pipeline_in_stall_and_timed_modesto invoke real COM vtableextern "system"slots (SetPipelineState, tail-positionOMSetStencilRef, andResourceBarrier) plusexternalfrom#[inline(never)]callers, verifyingEvent.a.saturating_sub(1)resolves inside each caller's.pdata[BeginAddress, EndAddress)in bothdev(20/20timeline::,4/4copystat::) and--profile play(13/13timeline::record::,4/4copystat::,12/12list::).This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).
Could you, or anyone with a working setup, post a run report on the current head merged onto current
main:mainSHA it was merged onto;mainalone for comparison, if you can.Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.
AI-assisted (Claude Code).
VERIFY-3136 — Windows nativo: 41 pruebas de
listy el control muerde el resolutor; el módulo pidediagnostics985661b34,c9f63c3b8—list.rs(+752/−…),timeline/{record,report}.rs,copystat.rs74bd1bcd4(the branch also mergesmain)Ran
The trap again, third time tonight:
timeline::recordandtimeline::reportare#[cfg(all(windows, feature = "diagnostics"))]. Without the feature the resolve test does not exist, andcargo test -p leonida-gpu --lib resolve_list_calleranswers0 passed; 762 filtered outwith exit 0 — "no test" for a test that is there.Negative control, and my first attempt was wrong: I disabled the Win32
.pdatalookup (RtlLookupFunctionEntry) and the test still passed — because the test drivesresolve_list_caller_in, the pure resolver, with synthetic ranges; the Win32 call is not on its path. A control that does not change what the test exercises proves nothing. Moved into the resolver:It bites.
What the change is: on a list call deeper than
DEEP, the runtime now captures a short stack walk and resolves the caller structurally through.pdatafunction ranges, recording the op, the caller site and the bound pipeline — and the report formats them in both stall and timed modes. The doc comment explains why.pdataand not the stack alone: inlining and wrappers make the frame abovecalled_from_listthe wrong answer, and a tail call can remove it entirely — which is exactly what the resolver's four cases in the test name cover.What I could not test: the attribution in a real slow list call under the title — the resolver and the formatting are unit-tested, the walk itself is not.
Written with an AI assistant.
RUN (in game, batch of nine pull requests), each head merged with
git merge --no-ffonto main81efe4566, in one build: #313674bd1bcd4, #315653c3100ce, #3206d024194b3, #3248efd21d867, #3256e7aad1d4c, #32623643c2879, #2851b83b0b375, #312589bf1d328, #2642164506d01. RTX 4060 8 GB, driver 610.88, Windows 11. Series S,-Resolution 1080, frame generation 2x,-PrecompileUsed, the same walking route as the other runs on this machine, 330 s after reaching the world.For reference, the same machine and route rendered 13.3 to 17.2 fps on other batches in the last day. These fps are a check that nothing fell over, not a measurement of a gain.
Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch, on the heads listed above. If one of these pull requests changes its head, this run no longer covers it.
Limits: one run; arrival in the world was driven by keys and not checked on pictures;
-PrecompileUsedwas used, so the default start (every known pipeline precompiled) was not exercised. The precompile before the world took 619 s, against 157 s for the previous batch; the shader-side changes in this batch (#3156, #3262) probably left the pipeline cache cold (not checked). Switches that are off by default (for example #2851'sLEONIDA_TITLE_MEMORY_SCALE, #3136's timeline attribution) were not turned on: this run covers their default path only. #2642 targets Wine and was run on Windows only.AI-assisted (Claude Code).
Bundle gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300): #3303
2892951f4, #3136fd16493ac, #30103ca5765acand #3005b3a1a8f57(the current heads) merged together intomain04a838fc4without conflict, diag profile withdiagnostics,dlss,mimalloc, msvc target. These four were judged to have no effect on the picture, so they share one run. Reference:main04a838fc4built the same way, run the same day with the same frame-timing capture on. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data.main(-0.6, inside the run-to-run spread of this recipe); median frame 29.27 ms, p99 48.8 against 48.9 ms. From 210 to 300 s the 30 s slices are the same as the reference (34.4-35.0 against 34.5-34.7). The 150-210 s slices are lower: a slower climb, plus a short CPU burst from a monitoring query on this PC at 173 s.mainrun; none after 150 s.Verdict: PASS, no cost, for the four PRs together.
GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40.
AI-assisted: run and report by Claude Code (Claude Opus 5.5).
a55837545into #3136 (tree tested by local CI) 0501d1e961Merged by OreoFR (agent) at MoonEyes' request. His judge accepted it, and it is part of enlighted's G1 pack, which passed a 300 s run on an RTX 3090: no cost, 0 lost, 0 crash, 0 ERROR.
Local CI (normal mode) on head
fd16493acmerged into maina55837545: PASS.make_game.py --help.leonida,leonida-gpuandleonida-hle, 163 s.-D warnings, 50 s.The forge refused the merge while the head was behind main.
main(a55837545) was then merged into the head as0501d1e96, which has the same tree the CI tested. Merged asab6dab7cf.