diff --git a/README.md b/README.md index ba69407c05..e77ee021fa 100644 --- a/README.md +++ b/README.md @@ -327,10 +327,10 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder With `XCL_STALL_TRACE=1`, `report.json` also contains versioned aggregate counts, total/max time and log2-nanosecond histograms for coarse runtime stalls, plus a bounded list of the newest spans of at least 50 ms. The tracing is off by default. - `XCL_STALL_TRACE_DETAIL=1` includes high-frequency draw, dispatch, binding, barrier, copy and - command-list lifecycle recording costs on the title's first observed submitting thread; it also - enables the coarse trace. Use it only for a diagnostic run because every recorded call reads the - clock and updates counters. + `XCL_STALL_TRACE_DETAIL=1` includes high-frequency draw, dispatch, binding, descriptor/view, + barrier, copy and command-list lifecycle recording costs on the title's first observed submitting + thread; it also enables the coarse trace. Use it only for a diagnostic run because every recorded + call reads the clock and updates counters. - **Diagnostics for a bug report** (all off by default; set them in the environment of `xcl run`): - `XCL_RUN_SECONDS=n`: the title ends itself after `n` seconds, with the GPU drained and `xcl.log` and `report.json` written, so a run of a fixed length can be attached. A value that diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 073edaa48c..5b9b5c0e07 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -2066,6 +2066,7 @@ fn note_buffer_view() { /// (`desc::cbv_words`; unified memory, anything else gets an empty V#). No PC CBV: translated /// shaders read buffers through `mem`. unsafe extern "system" fn dev_create_cbv_x(this: *mut c_void, desc: *const D3D12_CONSTANT_BUFFER_VIEW_DESC, cpu: u64) { + let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailViewDescriptor); let Some(slot) = super::console_heap::slot(cpu).filter(|s| !s.sampler) else { let f: unsafe extern "system" fn(*mut c_void, *const D3D12_CONSTANT_BUFFER_VIEW_DESC, u64) = std::mem::transmute(orig_fn(this, 17)); return f(this, desc, cpu); @@ -2082,6 +2083,7 @@ unsafe extern "system" fn dev_create_cbv_x(this: *mut c_void, desc: *const D3D12 /// #22 CreateSampler: the PC sampler at the slot's index, the S# in XCL ABI form (word 3 /// [11:0] = sampler heap index; the state lives in the PC sampler). pub(super) unsafe extern "system" fn dev_create_sampler_x(this: *mut c_void, desc: *const D3D12_SAMPLER_DESC, cpu: u64) { + let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailViewDescriptor); let f: unsafe extern "system" fn(*mut c_void, *const D3D12_SAMPLER_DESC, u64) = std::mem::transmute(orig_fn(this, 22)); let Some(slot) = super::console_heap::slot(cpu).filter(|s| s.sampler) else { return f(this, desc, cpu) }; f(this, desc, slot.pc_srv); @@ -2129,6 +2131,7 @@ fn note_mixed_copy() { /// #24 CopyDescriptorsSimple(n, dst, src, type) unsafe extern "system" fn dev_copy_descriptors_simple_x(this: *mut c_void, n: u32, dst: u64, src: u64, ty: u32) { + let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailViewDescriptor); let ty = pc_heap_type(ty); note_copy_call("CopyDescriptorsSimple", n, dst, src); if copy_console_slots(this, n, dst, src, ty) { @@ -2145,6 +2148,7 @@ unsafe extern "system" fn dev_copy_descriptors_simple_x(this: *mut c_void, n: u3 /// #23 CopyDescriptors(dst ranges, src ranges, type): range by range over console slots. #[allow(clippy::too_many_arguments)] unsafe extern "system" fn dev_copy_descriptors_x(this: *mut c_void, nd: u32, dsts: *const u64, dsizes: *const u32, ns: u32, srcs: *const u64, ssizes: *const u32, ty: u32) { + let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailViewDescriptor); let ty = pc_heap_type(ty); note_copy_call("CopyDescriptors", nd, if dsts.is_null() { 0 } else { *dsts }, if srcs.is_null() { 0 } else { *srcs }); use super::console_heap::{slot, SAMPLER_SLOT, SLOT}; @@ -2247,6 +2251,7 @@ unsafe extern "system" fn dev_create_uav_checked_x( desc: *const D3D12_UNORDERED_ACCESS_VIEW_DESC, cpu: u64, ) { + let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailViewDescriptor); if let Some(r) = ID3D12Resource::from_raw_borrowed(&res) { let rd = r.GetDesc(); let is_tex = rd.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER; @@ -2291,6 +2296,7 @@ unsafe extern "system" fn dev_create_uav_checked_x( /// #21 CreateDepthStencilView: the console's view formats as the PC's (`pc_view_format`). unsafe extern "system" fn dev_create_dsv_x(this: *mut c_void, res: *mut c_void, desc: *const D3D12_DEPTH_STENCIL_VIEW_DESC, cpu: u64) { + let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailViewDescriptor); let f: unsafe extern "system" fn(*mut c_void, *mut c_void, *const D3D12_DEPTH_STENCIL_VIEW_DESC, u64) = std::mem::transmute(orig_fn(this, 21)); let mut copy = desc.as_ref().copied(); if let Some(c) = copy.as_mut() { @@ -2382,6 +2388,7 @@ fn pc_srv(rd: &D3D12_RESOURCE_DESC, v: Option<&D3D12_SHADER_RESOURCE_VIEW_DESC>) } unsafe extern "system" fn dev_create_srv_x(this: *mut c_void, res: *mut c_void, desc: *const D3D12_SHADER_RESOURCE_VIEW_DESC, cpu: u64) { + let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailViewDescriptor); let f: unsafe extern "system" fn(*mut c_void, *mut c_void, *const D3D12_SHADER_RESOURCE_VIEW_DESC, u64) = std::mem::transmute(orig_fn(this, 18)); let mut copy = desc.as_ref().copied(); if let Some(c) = copy.as_mut() { @@ -2539,6 +2546,7 @@ unsafe extern "system" fn dev_create_srv_at_x(this: *mut c_void, rdesc: *const u let va = (view.add(0x28) as *const u64).read_unaligned(); let v = (view as *const D3D12_SHADER_RESOURCE_VIEW_DESC).read_unaligned(); if v.ViewDimension == D3D12_SRV_DIMENSION_BUFFER { + let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailViewDescriptor); let Some(slot) = super::console_heap::slot(cpu) else { return }; let b = &v.Anonymous.Buffer; let raw = b.Flags.0 & D3D12_BUFFER_SRV_FLAG_RAW.0 != 0; @@ -2556,6 +2564,7 @@ unsafe extern "system" fn dev_create_uav_at_x(this: *mut c_void, rdesc: *const u } let va = (view.add(0x28) as *const u64).read_unaligned(); let v = (view as *const D3D12_UNORDERED_ACCESS_VIEW_DESC).read_unaligned(); + let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailViewDescriptor); if v.ViewDimension == D3D12_UAV_DIMENSION_BUFFER { let Some(slot) = super::console_heap::slot(cpu) else { return }; let b = &v.Anonymous.Buffer; @@ -8626,7 +8635,7 @@ unsafe extern "system" fn dev_create_root_signature(this: *mut c_void, mask: u32 // --------------------------------------------------------------------------------------- unsafe extern "system" fn dev_create_rtv(this: *mut c_void, res: *mut c_void, desc: *const c_void, handle: usize) { - let _detail = crate::stall::detail_span_if(!super::title_textures::is_own_work(), crate::stall::StallKind::DetailBind); + let _detail = crate::stall::detail_span_if(!super::title_textures::is_own_work(), crate::stall::StallKind::DetailViewDescriptor); type F = unsafe extern "system" fn(*mut c_void, *mut c_void, *const c_void, usize); let f: F = std::mem::transmute(orig_fn(this, slot_of(this, "CreateRenderTargetView"))); // a view in a console-only format, or of a target made R8G8B8A8 (`device_x::pc_resource_desc`) diff --git a/crates/xcl/src/report.rs b/crates/xcl/src/report.rs index ec6a29a674..45aa5584ab 100644 --- a/crates/xcl/src/report.rs +++ b/crates/xcl/src/report.rs @@ -101,6 +101,7 @@ fn stall_kind_name(kind: crate::stall::StallKind) -> &'static str { StallKind::DetailDraw => "detail_draw", StallKind::DetailDispatch => "detail_dispatch", StallKind::DetailBind => "detail_bind", + StallKind::DetailViewDescriptor => "detail_view_descriptor", StallKind::DetailBarrier => "detail_barrier", StallKind::DetailCopy => "detail_copy", StallKind::DetailListLifecycle => "detail_list_lifecycle", diff --git a/crates/xcl/src/stall.rs b/crates/xcl/src/stall.rs index c0fc764838..219ce60ba4 100644 --- a/crates/xcl/src/stall.rs +++ b/crates/xcl/src/stall.rs @@ -33,13 +33,14 @@ pub enum StallKind { DetailDraw, DetailDispatch, DetailBind, + DetailViewDescriptor, DetailBarrier, DetailCopy, DetailListLifecycle, } impl StallKind { - pub const ALL: [Self; 20] = [ + pub const ALL: [Self; 21] = [ Self::ShaderTranslation, Self::DxcQueue, Self::DxcCompile, @@ -57,6 +58,7 @@ impl StallKind { Self::DetailDraw, Self::DetailDispatch, Self::DetailBind, + Self::DetailViewDescriptor, Self::DetailBarrier, Self::DetailCopy, Self::DetailListLifecycle, @@ -334,6 +336,20 @@ mod tests { assert_eq!((aggregate.count, aggregate.total_ns), (1, 32)); } + #[test] + fn descriptor_detail_is_attributed_only_to_the_submitter() { + let recorder = Recorder::new(); + recorder.enable_detail(); + recorder.note_submitter(7); + let clock = TestClock::new(100); + assert!(recorder.start_detail_with(StallKind::DetailViewDescriptor, &clock, 8).is_none()); + let span = recorder.start_detail_with(StallKind::DetailViewDescriptor, &clock, 7).unwrap(); + clock.now.store(145, Ordering::Relaxed); + drop(span); + let aggregate = &recorder.snapshot().aggregates[StallKind::DetailViewDescriptor.index()]; + assert_eq!((aggregate.count, aggregate.total_ns), (1, 45)); + } + #[test] fn a_span_updates_its_aggregate_and_log2_bucket() { let recorder = Recorder::new();