From 2aeec61c045fe315ae3f0ed6e6d4f1e03b05417b Mon Sep 17 00:00:00 2001 From: Nico <53304086+thisguyStan@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:25:54 +0100 Subject: [PATCH] D3D12.X: with XCL_LOOK_STATS=2 split a present's time on the submitter On a 16 GB NVIDIA card in the world, presents took 93 % of the submitting thread's time (#2688), but a present was one entry with only its wait for the copy of the frame before apart, so where that time goes could not be told. Four more entries, timed with XCL_LOOK_STATS=2 only, as that wait is: - the wait for the present before it (PresentX's lock, the presenter's), - the copy (or composite) of the frame recorded and submitted, from the allocator's reset to its Signal, - the swap chain's Present, which DXGI holds while the frames before it are queued (a GPU-bound frame waits there), - the wait for a frame dump's copy (XCL_FRAME_DUMP, XCL_DUMP_TARGETS), up to 2 s each. With XCL_ACTIVITY they appear in "calls of the submitting thread (2 s)" next to "presents"; what a present spends besides them is the rest (the plane checks, the frame-rate line, the device-removal check). No change with the switch off. When the fallback presents on a submission (a title that does not call PresentX), its parts are timed inside ExecuteCommandLists rather than inside presents, as the copy wait already was. They are sub-calls (is_sub_call, #2729), as the copy wait is, so the line's "completed" total counts each present once. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/api_cost.rs | 44 ++++++++++++++++++++++++++-- crates/xcl/src/hle/d3d12x/present.rs | 16 ++++++++-- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/crates/xcl/src/hle/api_cost.rs b/crates/xcl/src/hle/api_cost.rs index dc7bf549ba..3f0cb03fe2 100644 --- a/crates/xcl/src/hle/api_cost.rs +++ b/crates/xcl/src/hle/api_cost.rs @@ -22,8 +22,17 @@ pub enum Call { Submit, /// PresentX, or a present of the fallback's at a console method Present, - /// a present's wait for the copy of the frame before + /// a present's wait for the copy of the frame before (this one and the parts below run + /// inside `Present`, or inside `Submit` when the fallback presents on a submission) PresentCopyWait, + /// a present's wait for the one before it (`PresentX`'s lock and the presenter's) + PresentLockWait, + /// a present's copy (or composite) of the frame, recorded and submitted + PresentRecord, + /// the swap chain's Present (DXGI holds it while the frames before it are queued) + PresentSwap, + /// a present's wait for the copy of a frame dump (`XCL_FRAME_DUMP`, `XCL_DUMP_TARGETS`) + PresentDumpWait, WaitFrameEvent, /// the title's blocking waits for a fence (SetEventOnCompletion without an event) FenceWait, @@ -48,7 +57,7 @@ pub enum Call { ListLifecycle, } -pub const CALLS: [(Call, &str); 20] = [ +pub const CALLS: [(Call, &str); 24] = [ (Call::PlacedTexture, "placed textures"), (Call::PlacedBuffer, "placed buffers"), (Call::PhysicalPages, "physical page calls"), @@ -58,6 +67,10 @@ pub const CALLS: [(Call, &str); 20] = [ (Call::Submit, "ExecuteCommandLists"), (Call::Present, "presents"), (Call::PresentCopyWait, "waits of a present for the last frame's copy"), + (Call::PresentLockWait, "waits of a present for the one before"), + (Call::PresentRecord, "copies of a present recorded and submitted"), + (Call::PresentSwap, "swap chain Presents"), + (Call::PresentDumpWait, "waits of a present for a frame dump's copy"), (Call::WaitFrameEvent, "WaitFrameEventX"), (Call::FenceWait, "blocking fence waits"), (Call::FenceSettle, "copies back settled at fence looks"), @@ -74,7 +87,16 @@ pub const CALLS: [(Call, &str); 20] = [ /// Calls that nest inside another timed call and must not be added into the submitting thread's /// non-overlapping completed-call total. pub const fn is_sub_call(call: Call) -> bool { - matches!(call, Call::PresentCopyWait | Call::PipelineWait | Call::ViewWant) + matches!( + call, + Call::PresentCopyWait + | Call::PresentLockWait + | Call::PresentRecord + | Call::PresentSwap + | Call::PresentDumpWait + | Call::PipelineWait + | Call::ViewWant + ) } /// Coherent single-writer `(count, ns)` counter pair protected by a seqlock generation @@ -319,6 +341,22 @@ mod tests { assert!(!is_sub_call(Call::Submit) && !is_sub_call(Call::DrawRecord) && !is_sub_call(Call::FenceWait)); } + #[test] + fn the_parts_of_a_present_are_not_counted_twice() { + // (they run inside `Present`, or inside `Submit` on the fallback's presents) + let before = [(0u64, 0u64); CALLS.len()]; + let mut now = before; + now[Call::Present as usize] = (60, 50_000); + now[Call::PresentLockWait as usize] = (120, 1_000); + now[Call::PresentRecord as usize] = (60, 20_000); + now[Call::PresentSwap as usize] = (60, 25_000); + now[Call::PresentDumpWait as usize] = (1, 2_000); + let line = submitter_summary_line(&now, &before, 2000).unwrap(); + assert!(line.contains("60 copies of a present recorded and submitted in 20 ms"), "{line}"); + assert!(line.contains("60 swap chain Presents in 25 ms"), "{line}"); + assert!(line.ends_with("; completed 50 ms (window 2000 ms)"), "{line}"); + } + #[test] fn summary_retains_nonzero_duration_delta_when_count_delta_is_zero() { // Deterministic torn-snapshot sequence `(0,0) -> (1,0) -> (1,400_000)` on a top-level diff --git a/crates/xcl/src/hle/d3d12x/present.rs b/crates/xcl/src/hle/d3d12x/present.rs index 3c09818662..cf37a356d8 100644 --- a/crates/xcl/src/hle/d3d12x/present.rs +++ b/crates/xcl/src/hle/d3d12x/present.rs @@ -58,7 +58,10 @@ pub unsafe extern "system" fn present_x(queue: *mut c_void, plane_count: u32, pl return 0; } let token = (planes as *const u64).read_unaligned(); - let _present = PRESENTX_LOCK.lock().unwrap(); + let _present = { + let _cost = super::look_stats::deep().then(|| crate::hle::api_cost::time(crate::hle::api_cost::Call::PresentLockWait)); + PRESENTX_LOCK.lock().unwrap() + }; present_x_frame(queue, plane_count, planes); // The title can use flip statistics to decide when to reuse its buffer. // Queue our copy before reporting the flip. @@ -1422,6 +1425,7 @@ unsafe fn present_now(min_interval: Duration, frame: Option<(usize, Vec<(usize, let _reset = Reset; let is_frame = frame.is_some(); let (queue, raw_planes, mut guard) = if let Some((queue, planes)) = frame { + let _cost = super::look_stats::deep().then(|| crate::hle::api_cost::time(crate::hle::api_cost::Call::PresentLockWait)); (queue, planes, PRESENTER.lock().unwrap()) } else { let Ok(guard) = PRESENTER.try_lock() else { return }; @@ -1494,6 +1498,8 @@ unsafe fn present_now(min_interval: Duration, frame: Option<(usize, Vec<(usize, } let Some(sc) = p.sc.clone() else { return }; let Ok(bb) = sc.GetBuffer::(sc.GetCurrentBackBufferIndex()) else { return }; + // (up to its Signal: what is left of a present besides the waits and the swap chain's call) + let recording = super::look_stats::deep().then(|| crate::hle::api_cost::time(crate::hle::api_cost::Call::PresentRecord)); if p.alloc.Reset().is_err() || p.list.Reset(&p.alloc, None).is_err() { return; } @@ -1644,11 +1650,13 @@ unsafe fn present_now(min_interval: Duration, frame: Option<(usize, Vec<(usize, crate::xlog_error!("present: submit copy: {e}"); return; } + drop(recording); if dumping_targets { super::targets::submitted(); } let presented = { let _stall = crate::stall::span(crate::stall::StallKind::Present); + let _cost = super::look_stats::deep().then(|| crate::hle::api_cost::time(crate::hle::api_cost::Call::PresentSwap)); let _in_driver = super::watch::in_driver(super::watch::Call::Present); sc.Present(0, DXGI_PRESENT(0)).ok() }; @@ -1660,7 +1668,11 @@ unsafe fn present_now(min_interval: Duration, frame: Option<(usize, Vec<(usize, } p.last = Instant::now(); if !p.dumps.is_empty() { - match fence::wait(&p.fence, p.value, &p.dev, Some(p.event), 2000) { + let copied = { + let _cost = super::look_stats::deep().then(|| crate::hle::api_cost::time(crate::hle::api_cost::Call::PresentDumpWait)); + fence::wait(&p.fence, p.value, &p.dev, Some(p.event), 2000) + }; + match copied { Ok(()) => { for dump in p.dumps.drain(..) { if dump.tag.starts_with("twin") {