Host heaps' slots are made under locks of their own; the heaps' records and the buffer views picked by index are made on several threads (VICTORY_VIEW_THREADS)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 12:36:58 -06:00
1 parent 4fa965582f
commit 4d4d9bcee6
5 files changed
+206 -107

No files matched your search

+49 -31
View File
@@ -761,48 +761,66 @@ fn heap_buffer_pass(heap: &crate::descriptor::Heap, host: &crate::descriptor::ho
// Whether the device was there before the pass: a view that removes
// it is named below.
static GONE: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
let mut alive = !GONE.load(Ordering::Relaxed) && crate::descriptor::host::device_removed().is_none();
let alive = !GONE.load(Ordering::Relaxed) && crate::descriptor::host::device_removed().is_none();
let mut unordered = Vec::new();
for (n, &index) in slots.iter().enumerate() {
ranges.set(index, None);
/// The title's heap, for the threads that look.
struct Shared<'a>(&'a crate::descriptor::Heap);
// SAFETY: a heap is free-threaded (its methods are called by any thread of
// the title's), and it lives until all of them have looked.
unsafe impl Sync for Shared<'_> {}
impl Shared<'_> {
fn handle(&self, index: u32) -> Option<u64> {
self.0.handle(index)
}
}
let heap = Shared(heap);
// What a slot of the title's shows: its copy and range, and whether it is
// an unordered view.
let look = |index: u32| {
// A draw's table's: the draw brings what it reads up to date.
if host.copied_tabled(index, frame) {
continue;
}
let Some(handle) = heap.handle(index) else {
continue;
};
let Some(view) = host.mirror(index, handle, true) else {
continue;
};
// Every 64 views while the device lives (a cheap query).
if alive
&& n % 64 == 63
&& let Some(why) = crate::descriptor::host::device_removed()
{
alive = false;
GONE.store(true, Ordering::Relaxed);
let last: Vec<String> = slots[n - 63..=n]
.iter()
.filter_map(|&i| crate::descriptor::view(heap.handle(i)?).map(|v| format!("{i}: {v:?}")))
.map(|s| s.chars().take(200).collect())
.collect();
tracing::error!(why, slot = index, "the host device went while buffer views of the heap were made; one of: {last:#?}");
crate::host::log_removal_context();
return None;
}
let view = host.mirror(index, heap.handle(index)?, true)?;
// The copy the slot shows (`buffer_copy`), not the one the
// view's range alone would find.
let Some((shadow, address, len)) = crate::descriptor::host::buffer_copy(&view) else {
continue;
};
let (shadow, address, len) = crate::descriptor::host::buffer_copy(&view)?;
#[cfg(feature = "diagnostics")]
if host.shows(index, &shadow.buffer) == Some(false) {
HEAP_VIEWS_ELSEWHERE.fetch_add(1, Ordering::Relaxed);
}
if crate::picked::on() && view_kind(&view) == Some(ResourceType::Uav) {
unordered.push((shadow.clone(), address, address + len));
let written = crate::picked::on() && view_kind(&view) == Some(ResourceType::Uav);
Some(((shadow, address, address + len), written))
};
// Some slots at a time, on several threads.
const AT_A_TIME: usize = 256;
let parts: Vec<&[u32]> = slots.chunks(AT_A_TIME).collect();
let found: Vec<std::sync::OnceLock<Vec<_>>> = parts.iter().map(|_| Default::default()).collect();
crate::land::each_view(parts.len(), &|n| {
let looked: Vec<_> = parts[n].iter().map(|&index| (index, look(index))).collect();
// (After each piece while the device lives: a cheap query.)
if alive
&& let Some(why) = crate::descriptor::host::device_removed()
&& !GONE.swap(true, Ordering::Relaxed)
{
let last: Vec<String> = parts[n]
.iter()
.filter_map(|&i| crate::descriptor::view(heap.handle(i)?).map(|v| format!("{i}: {v:?}")))
.map(|s| s.chars().take(200).collect())
.collect();
tracing::error!(why, "the host device went while buffer views of the heap were made; perhaps one of: {last:#?}");
crate::host::log_removal_context();
}
ranges.set(index, Some((shadow, address, address + len)));
let _ = found[n].set(looked);
});
for (index, shows) in found.into_iter().filter_map(std::sync::OnceLock::into_inner).flatten() {
let range = shows.map(|(range, written)| {
if written {
unordered.push(range.clone());
}
range
});
ranges.set(index, range);
}
if crate::picked::on() {
crate::picked::shown(unordered, all);