diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index 21f0ba5..e24be3b 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -610,6 +610,13 @@ fn create() -> windows::core::Result { dred.SetAutoBreadcrumbsEnablement(D3D12_DRED_ENABLEMENT_FORCED_ON); } dred.SetPageFaultEnablement(D3D12_DRED_ENABLEMENT_FORCED_ON); + tracing::info!( + breadcrumbs = dred_on() || dred_light(), + markers = dred_on(), + "crash tracing on (device-removed data)" + ); + } else { + tracing::warn!("crash tracing asked for and not there: no device-removed data settings"); } } let mut device: Option = None; @@ -5293,7 +5300,12 @@ impl Host { let _ = fault_va; if done > 0 { text.push_str(&in_flight(history, &markers, done as usize)); - } else if let Some(bound) = bound { + } + // (Without markers a list that stopped midway says what + // it may have been at only by what it binds.) + if (done == 0 || markers.is_empty()) + && let Some(bound) = bound + { let pipelines = bound.lock().unwrap_or_else(|e| e.into_inner()); text.push_str(&format!(", its pipelines {pipelines:?}")); } diff --git a/crates/victory-gpu/src/pipeline/library.rs b/crates/victory-gpu/src/pipeline/library.rs index 1c04848..fa22cf8 100644 --- a/crates/victory-gpu/src/pipeline/library.rs +++ b/crates/victory-gpu/src/pipeline/library.rs @@ -435,7 +435,7 @@ const LIBRARY_FILE: &str = "host-pipelines.bin"; const NEXT_FILE: &str = "host-pipelines.next"; const EARLY_FILE: &str = "early-pipelines.txt"; /// Title pipelines listed for an early start, at most. -const EARLY_MAX: usize = 8192; +const EARLY_MAX: usize = 100_000; fn library() -> Option<&'static Library> { static LIBRARY: OnceLock> = OnceLock::new(); diff --git a/crates/victory-gpu/src/shadow.rs b/crates/victory-gpu/src/shadow.rs index ec17b9e..8b127df 100644 --- a/crates/victory-gpu/src/shadow.rs +++ b/crates/victory-gpu/src/shadow.rs @@ -573,8 +573,8 @@ pub(crate) fn card_dirty(sent_as: u64) -> Vec<(Arc, Vec<(usize, usize)>) /// memory's). Returns the bytes compared. pub(crate) fn stale_pages(most: usize, say: &mut dyn FnMut(&Shadow, usize, usize, (usize, u32, u32))) -> usize { static NEXT: AtomicU64 = AtomicU64::new(0); - let mut all: Vec> = buffers().values().filter_map(|e| e.shadow.clone()).collect(); - all.extend(LOOSE.lock().unwrap_or_else(|e| e.into_inner()).values().cloned()); + let mut all: Vec> = buffers_read().values().filter_map(|e| e.shadow.clone()).collect(); + all.extend(LOOSE.write().unwrap_or_else(|e| e.into_inner()).values().cloned()); all.retain(|s| s.place.is_none() && s.watched.load(Ordering::Relaxed) == 1); all.sort_by_key(|s| s.id); let next = NEXT.load(Ordering::Relaxed); @@ -2397,7 +2397,7 @@ static LET_GO: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; #[cfg(feature = "diagnostics")] pub(crate) fn windows() -> [u64; 3] { let asked: u64 = { - let loose = LOOSE.lock().unwrap_or_else(|e| e.into_inner()); + let loose = LOOSE.write().unwrap_or_else(|e| e.into_inner()); loose .values() .map(|s| { @@ -2421,7 +2421,7 @@ pub(crate) fn windows() -> [u64; 3] { #[cfg(feature = "diagnostics")] pub(crate) fn window_use() -> [u64; 8] { let mut out = [0u64; 8]; - let loose = LOOSE.lock().unwrap_or_else(|e| e.into_inner()); + let loose = LOOSE.write().unwrap_or_else(|e| e.into_inner()); for s in loose.values() { let copied = s.copied.lock().unwrap_or_else(|e| e.into_inner()); let pages = copied.iter().filter(|&&at| at != 0).count() as u64; @@ -2462,7 +2462,7 @@ pub(crate) fn let_go_idle() { let gone: Vec> = { // Held from the look to the removal: `loose` hands a copy out // under the same lock, so none is handed out in between. - let mut map = LOOSE.lock().unwrap_or_else(|e| e.into_inner()); + let mut map = LOOSE.write().unwrap_or_else(|e| e.into_inner()); if map.is_empty() { return; } @@ -2499,7 +2499,7 @@ pub(crate) fn let_go_idle() { #[cfg(feature = "diagnostics")] pub(crate) fn memory() -> [u64; 6] { let (windows, window_bytes) = { - let loose = LOOSE.lock().unwrap_or_else(|e| e.into_inner()); + let loose = LOOSE.write().unwrap_or_else(|e| e.into_inner()); // Each copy once: a window may stand under several keys. let mut seen = std::collections::HashSet::new(); let bytes: u64 = loose @@ -4211,10 +4211,17 @@ struct Entry { } /// Title buffers by (start address, resource), with their copy once made. -static BUFFERS: Mutex> = Mutex::new(BTreeMap::new()); +/// +/// Read by every view a draw names, on all recording threads at once, and +/// written when a buffer comes, goes or gets its copy: readers share it. +static BUFFERS: std::sync::RwLock> = std::sync::RwLock::new(BTreeMap::new()); -fn buffers() -> std::sync::MutexGuard<'static, BTreeMap<(u64, usize), Entry>> { - BUFFERS.lock().unwrap_or_else(|e| e.into_inner()) +fn buffers() -> std::sync::RwLockWriteGuard<'static, BTreeMap<(u64, usize), Entry>> { + BUFFERS.write().unwrap_or_else(|e| e.into_inner()) +} + +fn buffers_read() -> std::sync::RwLockReadGuard<'static, BTreeMap<(u64, usize), Entry>> { + BUFFERS.read().unwrap_or_else(|e| e.into_inner()) } /// A title buffer exists at `start` (`len` bytes). @@ -4253,7 +4260,7 @@ pub(crate) fn in_place_let_go(at: u64, len: u64) -> u64 { let end = at.saturating_add(len); let mut gone: Vec> = Vec::new(); { - let mut map = LOOSE.lock().unwrap_or_else(|e| e.into_inner()); + let mut map = LOOSE.write().unwrap_or_else(|e| e.into_inner()); let keys: Vec<(u64, u64)> = map .range((at.saturating_sub(WINDOW), 0)..(end, 0)) .filter(|(key, shadow)| shadow.place.is_some() && key.0 + key.1 > at) @@ -4281,8 +4288,8 @@ pub(crate) fn in_place_let_go(at: u64, len: u64) -> u64 { /// bytes, false) and the windows outside buffers that have a copy (start, /// bytes, true). pub(crate) fn spans() -> Vec<(u64, u64, bool)> { - let mut spans: Vec<(u64, u64, bool)> = buffers().iter().map(|(key, entry)| (key.0, entry.end - key.0, false)).collect(); - let loose = LOOSE.lock().unwrap_or_else(|e| e.into_inner()); + let mut spans: Vec<(u64, u64, bool)> = buffers_read().iter().map(|(key, entry)| (key.0, entry.end - key.0, false)).collect(); + let loose = LOOSE.write().unwrap_or_else(|e| e.into_inner()); spans.extend(loose.keys().map(|&(start, len)| (start, len, true))); spans } @@ -4322,11 +4329,23 @@ pub(crate) fn find_any(address: u64, len: u64) -> Option> { /// The copy [`find`] gives for a range inside a title buffer, if it was made. pub(crate) fn peek(address: u64, len: u64) -> Option> { let end = address.checked_add(len.max(1))?; - buffers().range(..=(address, usize::MAX)).rev().take(64).find(|(_, e)| e.end >= end).and_then(|(_, e)| e.shadow.clone()) + buffers_read().range(..=(address, usize::MAX)).rev().take(64).find(|(_, e)| e.end >= end).and_then(|(_, e)| e.shadow.clone()) } fn lookup(address: u64, len: u64, any: bool) -> Option> { let end = address.checked_add(len.max(1))?; + { + let map = buffers_read(); + match map.range(..=(address, usize::MAX)).rev().take(64).find(|(_, e)| e.end >= end) { + // The copy is made already (nearly always). + Some((_, Entry { shadow: Some(shadow), .. })) => return Some(shadow.clone()), + Some(_) => {} + None => { + drop(map); + return loose(address, end, len <= 1, any); + } + } + } let mut map = buffers(); let key = map .range(..=(address, usize::MAX)) @@ -4505,7 +4524,7 @@ fn fine() -> bool { /// which is copied once for each. #[cfg(feature = "diagnostics")] pub(crate) fn window_cover() -> u64 { - let loose = LOOSE.lock().unwrap_or_else(|e| e.into_inner()); + let loose = LOOSE.write().unwrap_or_else(|e| e.into_inner()); cover(loose.keys().copied()) } @@ -4536,12 +4555,29 @@ fn longest_tail(windows: impl Iterator, address: u64, end: u6 } /// Copies of title memory outside buffers, by (start, length). -static LOOSE: Mutex>> = Mutex::new(BTreeMap::new()); +static LOOSE: std::sync::RwLock>> = std::sync::RwLock::new(BTreeMap::new()); fn loose(address: u64, end: u64, unsized_ask: bool, any: bool) -> Option> { - let mut map = LOOSE.lock().unwrap_or_else(|e| e.into_inner()); let (cell, _) = window_of(address, end, WINDOW); let named = window_of(address, end, if unsized_ask { WINDOW } else { window() }); + // Under the lock, with the handing out: see `let_go_idle`. + let note = |shadow: &Shadow| { + shadow.used.store(crate::host::moment(), Ordering::Relaxed); + shadow.asked[0].fetch_min(address, Ordering::Relaxed); + shadow.asked[1].fetch_max(end, Ordering::Relaxed); + if unsized_ask { + shadow.unsized_asks.fetch_add(1, Ordering::Relaxed); + } + }; + // The window is there already (nearly always): readers share the lock. + if !(unsized_ask && tails()) && !(any && fine() && !unsized_ask) { + let map = LOOSE.read().unwrap_or_else(|e| e.into_inner()); + if let Some(shadow) = map.get(&named) { + note(shadow); + return Some(shadow.clone()); + } + } + let mut map = LOOSE.write().unwrap_or_else(|e| e.into_inner()); let (start, len) = if unsized_ask && tails() { let there = map.range((cell, 0)..=(address, u64::MAX)).map(|(key, _)| *key); longest_tail(there, address, end).unwrap_or_else(|| tail_of(address, end)) @@ -4554,15 +4590,6 @@ fn loose(address: u64, end: u64, unsized_ask: bool, any: bool) -> Option String { .collect(); all.extend( LOOSE - .lock() + .read() .unwrap_or_else(|e| e.into_inner()) .values() .map(|s| (s.gpu, s.start, s.len)),