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 d0941c4ea6..c687b5c696 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. @@ -1402,6 +1405,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 }; @@ -1474,6 +1478,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; } @@ -1624,11 +1630,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() }; @@ -1640,7 +1648,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") {