Shared locks for buffer and window lookups; early pipeline list without a small cap; crash report names what a list binds

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 01:59:21 -06:00
1 parent 1f1a433676
commit ad30f2cb1f
3 files changed
+67 -28

No files matched your search

+13 -1
View File
@@ -610,6 +610,13 @@ fn create() -> windows::core::Result<Host> {
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<ID3D12Device> = 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:?}"));
}
+1 -1
View File
@@ -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<Option<Library>> = OnceLock::new();
+53 -26
View File
@@ -573,8 +573,8 @@ pub(crate) fn card_dirty(sent_as: u64) -> Vec<(Arc<Shadow>, 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<Arc<Shadow>> = 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<Arc<Shadow>> = 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<Arc<Shadow>> = {
// 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<BTreeMap<(u64, usize), Entry>> = 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<BTreeMap<(u64, usize), Entry>> = 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<Arc<Shadow>> = 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<Arc<Shadow>> {
/// The copy [`find`] gives for a range inside a title buffer, if it was made.
pub(crate) fn peek(address: u64, len: u64) -> Option<Arc<Shadow>> {
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<Arc<Shadow>> {
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<Item = (u64, u64)>, address: u64, end: u6
}
/// Copies of title memory outside buffers, by (start, length).
static LOOSE: Mutex<BTreeMap<(u64, u64), Arc<Shadow>>> = Mutex::new(BTreeMap::new());
static LOOSE: std::sync::RwLock<BTreeMap<(u64, u64), Arc<Shadow>>> = std::sync::RwLock::new(BTreeMap::new());
fn loose(address: u64, end: u64, unsized_ask: bool, any: bool) -> Option<Arc<Shadow>> {
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<Arc<Sha
} else {
named
};
// 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);
}
};
if let Some(shadow) = map.get(&(start, len)) {
note(shadow);
return Some(shadow.clone());
@@ -4843,7 +4870,7 @@ pub(crate) fn near(va: u64) -> String {
.collect();
all.extend(
LOOSE
.lock()
.read()
.unwrap_or_else(|e| e.into_inner())
.values()
.map(|s| (s.gpu, s.start, s.len)),