diff --git a/HANDOFF.md b/HANDOFF.md index 984a45360a..cfebef3a85 100644 --- a/HANDOFF.md +++ b/HANDOFF.md @@ -1810,6 +1810,8 @@ to an outside server at every crash (`hle/netoff.rs`: the title's WinHTTP / Wins translated as the mesh shader they are, the title rendered nothing from then on (black every run). Open: what it expects of them. - `XCL_ACTIVITY` logs the process's commit, local / non-local video memory, target pages, arenas and sparse pools. + And the CPU time of XCL's looks before the title's submits (`looks before submits`): in all and as a share of + the 2 s, the write-watch scan with the MB it watched a look, the copies into sparse video memory, the rest. - Open: arenas for D32S8 targets still take 2.8 GB (one per 256 MB of addresses; a D32S8 → R32 + separate stencil split, or exact-size heaps, would cut it); the debug layer's resource-state errors (538) and sparse simultaneous-access errors (1047); buffer views outside unified memory still get an empty V#. diff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs index 0731890bfc..877fc63eb7 100644 --- a/crates/xcl/src/hle/d3d12x/sparse.rs +++ b/crates/xcl/src/hle/d3d12x/sparse.rs @@ -1443,14 +1443,48 @@ pub fn mapped_ranges() -> Vec<(usize, usize)> { s.runs.clone().unwrap_or_default() } -/// time spent and pages found by the write-watch scans (`refresh_once`), for the timing line -static WATCH: [AtomicU64; 2] = [AtomicU64::new(0), AtomicU64::new(0)]; +/// time spent and pages found by the write-watch scans (`refresh_once`), for the timing line; +/// then the looks, the bytes they watched and the µs of the whole looks (`XCL_ACTIVITY`) +static WATCH: [AtomicU64; 5] = [const { AtomicU64::new(0) }; 5]; /// [lock wait, chunk scan, upload] in µs, runs uploaded static PHASES: [AtomicU64; 4] = [const { AtomicU64::new(0) }; 4]; -pub fn note_watch(t: std::time::Duration, pages: usize) { +/// A look's write-watch scan: `t` long, `pages` found written in `watched` bytes. +pub fn note_watch(t: std::time::Duration, pages: usize, watched: usize) { WATCH[0].fetch_add(t.as_micros() as u64, Ordering::Relaxed); WATCH[1].fetch_add(pages as u64, Ordering::Relaxed); + WATCH[2].fetch_add(1, Ordering::Relaxed); + WATCH[3].fetch_add(watched as u64, Ordering::Relaxed); +} + +/// A whole look before a title's submit (`title_textures::refresh`: the scan, the copies of +/// CPU writes, the textures uploaded again), `t` long. +pub fn note_look(t: std::time::Duration) { + WATCH[4].fetch_add(t.as_micros() as u64, Ordering::Relaxed); +} + +/// What the looks before the title's submits cost so far: [whole looks µs, write-watch µs, +/// pages written, looks, bytes watched, sparse copies µs (lock wait, chunk scan, upload)]. +pub fn look_counters() -> [u64; 6] { + let w = |i: usize| WATCH[i].load(Ordering::Relaxed); + let copies = PHASES[..3].iter().map(|x| x.load(Ordering::Relaxed)).sum(); + [w(4), w(0), w(1), w(2), w(3), copies] +} + +/// The `XCL_ACTIVITY` line for `d`, two `look_counters()` subtracted, `secs` apart: how much +/// of the title's submitting threads' time XCL's looks took, and where it went. +pub fn look_line(d: [u64; 6], secs: u64) -> String { + let [all, watch, pages, looks, watched, copies] = d; + let ms = |us: u64| us / 1000; + format!( + "looks before submits ({secs} s): {looks} looks took {} ms ({:.1} % of the time): write-watch {} ms ({:.1} MB watched a look, {pages} pages written), copies into sparse video memory {} ms, the rest {} ms", + ms(all), + all as f64 / (secs.max(1) * 10_000) as f64, + ms(watch), + watched as f64 / looks.max(1) as f64 / (1 << 20) as f64, + ms(copies), + ms(all.saturating_sub(watch + copies)) + ) } /// Before the title's ExecuteCommandLists on `queue`: the pages the CPU wrote (`dirty`, 4 KiB @@ -1604,6 +1638,18 @@ pub fn forget_buffer(res: usize) { mod tests { use super::*; + /// The `XCL_ACTIVITY` line: the parts of the looks, the share of the 2 s, and no division by + /// zero for a period without a look. + #[test] + fn the_look_line_splits_the_time() { + let line = look_line([830_000, 610_000, 4_800, 240, 240 * 1_641 << 20, 120_000], 2); + assert!(line.contains("240 looks took 830 ms (41.5 % of the time)"), "{line}"); + assert!(line.contains("write-watch 610 ms (1641.0 MB watched a look, 4800 pages written)"), "{line}"); + assert!(line.contains("copies into sparse video memory 120 ms, the rest 100 ms"), "{line}"); + let idle = look_line([0; 6], 2); + assert!(idle.contains("0 looks took 0 ms (0.0 % of the time)") && idle.contains("0.0 MB watched a look"), "{idle}"); + } + /// `queue()` answers while the state's lock is held: a resource's last `Release` asks for /// it (`late_release::drain_known`) from inside a D3D12 call that the lock's holder can be /// waiting for (a list's `Reset` against an upload's allocator `Reset`, with `XCL_DRED=1`). diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs index ada439cbaa..325f0ac606 100644 --- a/crates/xcl/src/hle/d3d12x/title_textures.rs +++ b/crates/xcl/src/hle/d3d12x/title_textures.rs @@ -659,8 +659,10 @@ pub(super) unsafe fn refresh(queue: *mut c_void) { if BUSY.with(|b| b.get()) { return; } + let t0 = std::time::Instant::now(); let _refresh = REFRESH.lock().unwrap(); own_work(|| refresh_once(queue)); + super::sparse::note_look(t0.elapsed()); } /// The pages of `[base, base + size)` written since the last look, added to `dirty` and reset @@ -708,7 +710,7 @@ unsafe fn refresh_once(queue: *mut c_void) { dirty.sort_unstable(); dirty.len() }); - super::sparse::note_watch(watch_t0.elapsed(), dirty_len); + super::sparse::note_watch(watch_t0.elapsed(), dirty_len, ranges.iter().map(|r| r.1).sum()); if super::present::trace_frame() { // every 600th look: what the CPU's view of a few textures holds now (does the title's // data reach the address at all, and is the texture still kept in step?) diff --git a/crates/xcl/src/host.rs b/crates/xcl/src/host.rs index ba5dcb4737..fc693d85f1 100644 --- a/crates/xcl/src/host.rs +++ b/crates/xcl/src/host.rs @@ -40,6 +40,7 @@ pub fn host_main(boot_path: &Path) -> i32 { [p, e, d, x, f[0], f[1], f[2], f[3], r, b >> 20, fail] }; let mut last = snap(); + let mut last_looks = crate::hle::d3d12x::sparse::look_counters(); loop { std::thread::sleep(std::time::Duration::from_secs(2)); let now = snap(); @@ -48,6 +49,10 @@ pub fn host_main(boot_path: &Path) -> i32 { "activity (2 s): {} presents, {} submits, {} draws, {} dispatches, {} frame-event waits ({} timed out), {} frame statistics ({} not flipped); DirectStorage {} requests, {} MB, {} failed", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10] ); + // XCL's own CPU time before the title's submits (on the title's threads) + let looks = crate::hle::d3d12x::sparse::look_counters(); + crate::xlog_info!("{}", crate::hle::d3d12x::sparse::look_line(std::array::from_fn(|i| looks[i] - last_looks[i]), 2)); + last_looks = looks; // where the memory is: the process's commit, video memory, and XCL's parts of it let private = unsafe { use windows_sys::Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS_EX};