From dd85383eb9a6162b21856463185a5f420c526850 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. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/api_cost.rs | 17 +++++++++++++++-- crates/xcl/src/hle/d3d12x/present.rs | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/crates/xcl/src/hle/api_cost.rs b/crates/xcl/src/hle/api_cost.rs index 8178e3b93e..dd2771cd70 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, @@ -31,7 +40,7 @@ pub enum Call { FenceSettle, } -pub const CALLS: [(Call, &str); 12] = [ +pub const CALLS: [(Call, &str); 16] = [ (Call::PlacedTexture, "placed textures"), (Call::PlacedBuffer, "placed buffers"), (Call::PhysicalPages, "physical page calls"), @@ -41,6 +50,10 @@ pub const CALLS: [(Call, &str); 12] = [ (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"), diff --git a/crates/xcl/src/hle/d3d12x/present.rs b/crates/xcl/src/hle/d3d12x/present.rs index d6daec1221..ab73084e39 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. @@ -1058,6 +1061,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 }; @@ -1129,6 +1133,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; } @@ -1279,10 +1285,12 @@ 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 _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() }; @@ -1294,7 +1302,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") {