Merge night/cpu: processor work, wait instructions patched, submit thread (off)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
commit
55babd1acf
14 files changed
+2287
-240
No files matched your search
+165
-140
@@ -717,6 +717,161 @@ fn set(roots: &mut Vec<Root>, slot: u32, root: Root) {
|
||||
roots[slot] = root;
|
||||
}
|
||||
|
||||
/// The pass over the buffer views of `heap` that shaders pick by index
|
||||
/// ([`State::heap_buffers`]): their host slots are made, and the host copies
|
||||
/// they show are to be refreshed.
|
||||
fn heap_buffer_pass(heap: &crate::descriptor::Heap, host: &crate::descriptor::host::HostHeap, frame: u64) -> Vec<crate::host::aside::Refresh> {
|
||||
let started = std::time::Instant::now();
|
||||
// Per host heap: the host copy and range each slot's buffer view
|
||||
// reads, kept from pass to pass. Only the slots written since the
|
||||
// last pass are looked at again (83,000 slots a pass otherwise, 0.1 s
|
||||
// at best); all of them every 16 passes, because a view of a
|
||||
// released resource goes stale without a write, and a slot written
|
||||
// before its memory had a host copy is only made then.
|
||||
type Ranges = HeapRanges<std::sync::Arc<crate::shadow::Shadow>>;
|
||||
static RANGES: std::sync::Mutex<Option<std::collections::HashMap<usize, (u64, Ranges)>>> =
|
||||
std::sync::Mutex::new(None);
|
||||
let mut kept = RANGES.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let (passes, ranges) = kept
|
||||
.get_or_insert_with(Default::default)
|
||||
.entry(std::ptr::from_ref(host) as usize)
|
||||
.or_insert_with(|| (0, HeapRanges(Vec::new())));
|
||||
let changed = host.buffer_changes();
|
||||
let all = *passes == 0 || (*passes % HEAP_ROUND == 0 && !heap_spread());
|
||||
let slots = if all {
|
||||
ranges.0.clear();
|
||||
host.buffer_slots()
|
||||
} else if heap_spread() {
|
||||
// The written ones, and this pass's part of the others.
|
||||
let (part, parts) = ((*passes % HEAP_ROUND) as u32, HEAP_ROUND as u32);
|
||||
ranges.forget_part(part, parts);
|
||||
let mut slots = host.buffer_slots_of(part, parts);
|
||||
slots.extend(changed);
|
||||
slots
|
||||
} else {
|
||||
changed
|
||||
};
|
||||
*passes += 1;
|
||||
// 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 mut unordered = Vec::new();
|
||||
for (n, &index) in slots.iter().enumerate() {
|
||||
ranges.set(index, None);
|
||||
// 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();
|
||||
}
|
||||
// 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;
|
||||
};
|
||||
#[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));
|
||||
}
|
||||
ranges.set(index, Some((shadow, address, address + len)));
|
||||
}
|
||||
if crate::picked::on() {
|
||||
crate::picked::shown(unordered, all);
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
let looked = std::time::Instant::now();
|
||||
// Per host copy, the span its picked views cover.
|
||||
let mut spans: crate::host::ByCopy<(std::sync::Arc<crate::shadow::Shadow>, u64, u64)> = Default::default();
|
||||
let mut views = 0u32;
|
||||
for (shadow, from, to) in ranges.ranges() {
|
||||
views += 1;
|
||||
let key = std::sync::Arc::as_ptr(shadow) as usize;
|
||||
let span = spans.entry(key).or_insert_with(|| (shadow.clone(), *from, *to));
|
||||
span.1 = span.1.min(*from);
|
||||
span.2 = span.2.max(*to);
|
||||
}
|
||||
drop(kept);
|
||||
let bytes: u64 = spans.values().map(|s| s.2 - s.1).sum();
|
||||
// Memory that is not write-watched is copied whole by every refresh.
|
||||
// It was once refreshed only every 120 frames (unmapped pages read
|
||||
// one by one cost 14 GB a frame in run 11, before they were
|
||||
// remembered): streamed geometry then drew from stale buffers, and
|
||||
// the garbage ended runs (the card stopped answering 14-90 frames
|
||||
// into the opening cutscene; with every frame it ran on). The pass
|
||||
// costs some 30 ms a frame this way.
|
||||
static WHOLE: std::sync::Mutex<Option<std::collections::HashMap<usize, u64>>> = std::sync::Mutex::new(None);
|
||||
let mut whole = WHOLE.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let whole = whole.get_or_insert_with(Default::default);
|
||||
let mut found = Vec::with_capacity(spans.len());
|
||||
for (shadow, from, to) in spans.values() {
|
||||
if shadow.unwatched() {
|
||||
// By the copy's number: a copy made where one let go was
|
||||
// (`shadow::let_go_idle`) has never been refreshed.
|
||||
let key = shadow.id() as usize;
|
||||
// `VICTORY_UNWATCHED_FRAMES` sets the interval (1: every frame).
|
||||
static EVERY: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
|
||||
let every = *EVERY.get_or_init(|| {
|
||||
std::env::var("VICTORY_UNWATCHED_FRAMES")
|
||||
.ok()
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(1)
|
||||
});
|
||||
match whole.get(&key) {
|
||||
Some(&last) if frame < last + every => continue,
|
||||
_ => {
|
||||
whole.insert(key, frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
found.push((shadow.clone(), *from, (*to).min(*from + shadow.left(*from))));
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
let refreshed = std::time::Instant::now();
|
||||
crate::watch::look_at_holes();
|
||||
#[cfg(feature = "diagnostics")]
|
||||
for (sum, time) in HEAP_SPLIT.iter().zip([looked - started, refreshed - looked]) {
|
||||
sum.fetch_add(time.as_nanos() as u64, Ordering::Relaxed);
|
||||
}
|
||||
static LOGGED: AtomicU64 = AtomicU64::new(0);
|
||||
// The first pass and every growth of the set by half.
|
||||
let seen = LOGGED.load(Ordering::Relaxed);
|
||||
if u64::from(views) > seen + seen / 2 {
|
||||
LOGGED.store(u64::from(views), Ordering::Relaxed);
|
||||
tracing::info!(
|
||||
slots = slots.len(),
|
||||
views,
|
||||
copies = spans.len(),
|
||||
mb = bytes >> 20,
|
||||
ms = started.elapsed().as_millis(),
|
||||
"buffer views of the heap made ready for shaders that pick them by index"
|
||||
);
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub(crate) fn reset(&mut self, pipeline: This) {
|
||||
*self = State::default();
|
||||
@@ -1689,155 +1844,25 @@ impl State {
|
||||
return Some(gpu);
|
||||
}
|
||||
let started = std::time::Instant::now();
|
||||
// Per host heap: the host copy and range each slot's buffer view
|
||||
// reads, kept from pass to pass. Only the slots written since the
|
||||
// last pass are looked at again (83,000 slots a pass otherwise, 0.1 s
|
||||
// at best); all of them every 16 passes, because a view of a
|
||||
// released resource goes stale without a write, and a slot written
|
||||
// before its memory had a host copy is only made then.
|
||||
type Ranges = HeapRanges<std::sync::Arc<crate::shadow::Shadow>>;
|
||||
static RANGES: std::sync::Mutex<Option<std::collections::HashMap<usize, (u64, Ranges)>>> =
|
||||
std::sync::Mutex::new(None);
|
||||
let mut kept = RANGES.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let (passes, ranges) = kept
|
||||
.get_or_insert_with(Default::default)
|
||||
.entry(std::ptr::from_ref(host) as usize)
|
||||
.or_insert_with(|| (0, HeapRanges(Vec::new())));
|
||||
let changed = host.buffer_changes();
|
||||
let all = *passes == 0 || (*passes % HEAP_ROUND == 0 && !heap_spread());
|
||||
let slots = if all {
|
||||
ranges.0.clear();
|
||||
host.buffer_slots()
|
||||
} else if heap_spread() {
|
||||
// The written ones, and this pass's part of the others.
|
||||
let (part, parts) = ((*passes % HEAP_ROUND) as u32, HEAP_ROUND as u32);
|
||||
ranges.forget_part(part, parts);
|
||||
let mut slots = host.buffer_slots_of(part, parts);
|
||||
slots.extend(changed);
|
||||
slots
|
||||
if crate::host::aside::on() {
|
||||
let at = std::ptr::from_ref(heap) as usize;
|
||||
list.refreshes_coming(move || {
|
||||
crate::descriptor::with_heap(at, |heap| heap.host().map(|host| heap_buffer_pass(heap, host, frame)))
|
||||
.flatten()
|
||||
.unwrap_or_default()
|
||||
});
|
||||
} else {
|
||||
changed
|
||||
};
|
||||
*passes += 1;
|
||||
// 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 mut unordered = Vec::new();
|
||||
for (n, &index) in slots.iter().enumerate() {
|
||||
ranges.set(index, None);
|
||||
// A draw's table's: the draw brings what it reads up to date.
|
||||
if host.copied_tabled(index, frame) {
|
||||
continue;
|
||||
for (shadow, from, to) in heap_buffer_pass(heap, host, frame) {
|
||||
shadow.refresh(list, from, to - from);
|
||||
}
|
||||
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();
|
||||
}
|
||||
// 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;
|
||||
};
|
||||
#[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));
|
||||
}
|
||||
ranges.set(index, Some((shadow, address, address + len)));
|
||||
}
|
||||
if crate::picked::on() {
|
||||
crate::picked::shown(unordered, all);
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
let looked = std::time::Instant::now();
|
||||
// Per host copy, the span its picked views cover.
|
||||
let mut spans: crate::host::ByCopy<(std::sync::Arc<crate::shadow::Shadow>, u64, u64)> = Default::default();
|
||||
let mut views = 0u32;
|
||||
for (shadow, from, to) in ranges.ranges() {
|
||||
views += 1;
|
||||
let key = std::sync::Arc::as_ptr(shadow) as usize;
|
||||
let span = spans.entry(key).or_insert_with(|| (shadow.clone(), *from, *to));
|
||||
span.1 = span.1.min(*from);
|
||||
span.2 = span.2.max(*to);
|
||||
}
|
||||
drop(kept);
|
||||
let bytes: u64 = spans.values().map(|s| s.2 - s.1).sum();
|
||||
// Memory that is not write-watched is copied whole by every refresh.
|
||||
// It was once refreshed only every 120 frames (unmapped pages read
|
||||
// one by one cost 14 GB a frame in run 11, before they were
|
||||
// remembered): streamed geometry then drew from stale buffers, and
|
||||
// the garbage ended runs (the card stopped answering 14-90 frames
|
||||
// into the opening cutscene; with every frame it ran on). The pass
|
||||
// costs some 30 ms a frame this way.
|
||||
static WHOLE: std::sync::Mutex<Option<std::collections::HashMap<usize, u64>>> = std::sync::Mutex::new(None);
|
||||
let mut whole = WHOLE.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let whole = whole.get_or_insert_with(Default::default);
|
||||
for (shadow, from, to) in spans.values() {
|
||||
if shadow.unwatched() {
|
||||
// By the copy's number: a copy made where one let go was
|
||||
// (`shadow::let_go_idle`) has never been refreshed.
|
||||
let key = shadow.id() as usize;
|
||||
// `VICTORY_UNWATCHED_FRAMES` sets the interval (1: every frame).
|
||||
static EVERY: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
|
||||
let every = *EVERY.get_or_init(|| {
|
||||
std::env::var("VICTORY_UNWATCHED_FRAMES")
|
||||
.ok()
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(1)
|
||||
});
|
||||
match whole.get(&key) {
|
||||
Some(&last) if frame < last + every => continue,
|
||||
_ => {
|
||||
whole.insert(key, frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
shadow.refresh(list, *from, to - from);
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
let refreshed = std::time::Instant::now();
|
||||
crate::watch::look_at_holes();
|
||||
self.heap_textures(list, heap, host);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
for (sum, time) in HEAP_SPLIT.iter().zip([looked - started, refreshed - looked, refreshed.elapsed()]) {
|
||||
sum.fetch_add(time.as_nanos() as u64, Ordering::Relaxed);
|
||||
}
|
||||
HEAP_SPLIT[2].fetch_add(refreshed.elapsed().as_nanos() as u64, Ordering::Relaxed);
|
||||
HEAP_BUFFER_PASSES.fetch_add(1, Ordering::Relaxed);
|
||||
HEAP_BUFFER_MICROS.fetch_add(started.elapsed().as_micros() as u64, Ordering::Relaxed);
|
||||
static LOGGED: AtomicU64 = AtomicU64::new(0);
|
||||
// The first pass and every growth of the set by half.
|
||||
let seen = LOGGED.load(Ordering::Relaxed);
|
||||
if u64::from(views) > seen + seen / 2 {
|
||||
LOGGED.store(u64::from(views), Ordering::Relaxed);
|
||||
tracing::info!(
|
||||
slots = slots.len(),
|
||||
views,
|
||||
copies = spans.len(),
|
||||
mb = bytes >> 20,
|
||||
ms = started.elapsed().as_millis(),
|
||||
"buffer views of the heap made ready for shaders that pick them by index"
|
||||
);
|
||||
}
|
||||
Some(gpu)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user