Recording: a lock a descriptor slot, a thread's own answers about buffers, tables left as they are when nothing changed
Timeline waits-1 (dorm, 78 ms): the title's render thread stands 20 to 30 ms a frame at one recording job and the rest at others; recording is the critical path, and our list calls are 95 % of it. Profile waits-1, the five recording threads: 21 % contended locks, 11 % HostHeap::keep, 17 % readable, 7 % the look-up of buffers, 8 % clocks and counters of ours. VICTORY_QUICK_FIND=0 and VICTORY_READY_ONCE=0 go back; counters of the diagnostics by thread, a coarse clock for what is noted per texture and slot. VICTORY_AB=<s>,<switches> turns switches on and off while the title runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
7c62f5b707
commit
66c935eac2
9 files changed
+405
-61
No files matched your search
@@ -52,7 +52,11 @@ pub(crate) struct HostHeap {
|
||||
/// index heaps directly, so a slot the title has not rewritten since it
|
||||
/// released the resource may still be read, and a freed host resource
|
||||
/// read there is a GPU page fault (the console reads stale memory).
|
||||
kept: Mutex<Vec<Option<ID3D12Resource>>>,
|
||||
///
|
||||
/// A lock for each slot: one for the heap was what the recording threads
|
||||
/// waited for most (5.6 % of their time, profile waits-1: each descriptor
|
||||
/// made for a draw takes it, and lets go of what the slot held under it).
|
||||
kept: Box<[Mutex<Option<ID3D12Resource>>]>,
|
||||
/// Where the search for free dynamic slots starts, and which are taken
|
||||
/// (by lists not yet reset).
|
||||
next: Mutex<(u32, Vec<bool>)>,
|
||||
@@ -982,7 +986,7 @@ pub(crate) fn slot_story(slot: u32) -> String {
|
||||
if let Some(at) = host.written.get(slot as usize) {
|
||||
text.push_str(&format!(", written last at {:.1} s", f64::from(at.load(Relaxed)) / 1e3));
|
||||
}
|
||||
let kept = host.kept.lock().unwrap_or_else(|e| e.into_inner()).get(index as usize).cloned().flatten();
|
||||
let kept = host.kept_in(index);
|
||||
match kept {
|
||||
None => text.push_str(", holds nothing"),
|
||||
Some(resource) => {
|
||||
@@ -1249,7 +1253,7 @@ impl HostHeap {
|
||||
copied: Mutex::new(Vec::new()),
|
||||
waiting: Mutex::default(),
|
||||
away: Mutex::default(),
|
||||
kept: Mutex::new(vec![None; (count + extra) as usize]),
|
||||
kept: (0..count + extra).map(|_| Mutex::new(None)).collect(),
|
||||
next: Mutex::new((0, vec![false; extra as usize])),
|
||||
free: std::sync::atomic::AtomicU32::new(extra),
|
||||
too_long: std::sync::atomic::AtomicU32::new(u32::MAX),
|
||||
@@ -1644,12 +1648,7 @@ impl HostHeap {
|
||||
// as `mirror` takes them.
|
||||
let made = self.made.lock().unwrap_or_else(|e| e.into_inner());
|
||||
made.get(index as usize).is_some_and(|&made| made != 0 && made == key)
|
||||
&& self
|
||||
.kept
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.get(index as usize)
|
||||
.is_some_and(Option::is_some)
|
||||
&& self.kept_in(index).is_some()
|
||||
}
|
||||
|
||||
/// Levels on demand (`crate::tiles`): makes again the host slots of the
|
||||
@@ -2171,21 +2170,30 @@ impl HostHeap {
|
||||
|
||||
/// Slot `index` now views `resource` (or nothing of the host's).
|
||||
fn keep(&self, index: u32, resource: Option<ID3D12Resource>) {
|
||||
let mut kept = self.kept.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if let Some(slot) = kept.get_mut(index as usize) {
|
||||
let Some(slot) = self.kept.get(index as usize) else {
|
||||
return;
|
||||
};
|
||||
let old = {
|
||||
use windows::core::Interface;
|
||||
let mut slot = slot.lock().unwrap_or_else(|e| e.into_inner());
|
||||
// The same again: nothing to retire.
|
||||
if slot.as_ref().map(Interface::as_raw) == resource.as_ref().map(Interface::as_raw) {
|
||||
return;
|
||||
}
|
||||
// A running submission may still read the old resource through
|
||||
// this slot.
|
||||
if let Some(old) = std::mem::replace(slot, resource) {
|
||||
crate::host::retire(old);
|
||||
}
|
||||
std::mem::replace(&mut *slot, resource)
|
||||
};
|
||||
// A running submission may still read the old resource through
|
||||
// this slot.
|
||||
if let Some(old) = old {
|
||||
crate::host::retire_resource(old);
|
||||
}
|
||||
}
|
||||
|
||||
/// What slot `index` views.
|
||||
fn kept_in(&self, index: u32) -> Option<ID3D12Resource> {
|
||||
self.kept.get(index as usize)?.lock().unwrap_or_else(|e| e.into_inner()).clone()
|
||||
}
|
||||
|
||||
/// Makes slot `index` (a dynamic one) a raw buffer view of `len` bytes
|
||||
/// of `buffer` from byte `offset` (a multiple of 16): a root SRV with a
|
||||
/// size, whose reads past it return zeros instead of reaching whatever
|
||||
@@ -2371,7 +2379,7 @@ impl HostHeap {
|
||||
fn copy_to(&self, to: u32, which: u32) {
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if let Some(written) = self.written.get(to as usize) {
|
||||
written.store(crate::host::now_ms() as u32, std::sync::atomic::Ordering::Relaxed);
|
||||
written.store(crate::host::coarse_ms() as u32, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
let (Some(from), Some(host)) = (staged(self.sampler, which), host()) else {
|
||||
return; // made in place
|
||||
@@ -2593,9 +2601,8 @@ impl HostHeap {
|
||||
/// that is brought up to date for it).
|
||||
#[cfg(feature = "diagnostics")]
|
||||
pub(crate) fn shows(&self, index: u32, buffer: &ID3D12Resource) -> Option<bool> {
|
||||
let kept = self.kept.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let shown = kept.get(index as usize)?.as_ref()?;
|
||||
Some(windows::core::Interface::as_raw(shown) == windows::core::Interface::as_raw(buffer))
|
||||
let shown = self.kept_in(index)?;
|
||||
Some(windows::core::Interface::as_raw(&shown) == windows::core::Interface::as_raw(buffer))
|
||||
}
|
||||
|
||||
/// What the queue of textures picked by index knows of title slot
|
||||
@@ -3060,8 +3067,7 @@ fn buffer_srv(
|
||||
}
|
||||
let (first, count, stride) = (buffer.FirstElement, buffer.NumElements, buffer.StructureByteStride);
|
||||
let raw = buffer.Flags.0 & D3D12_BUFFER_SRV_FLAG_RAW.0 != 0;
|
||||
// SAFETY: a live buffer.
|
||||
let width = unsafe { shadow.buffer.GetDesc() }.Width;
|
||||
let width = shadow.width();
|
||||
if !buffer_view_ok(desc.Format, first, count, stride, raw, width) {
|
||||
REFUSED_VIEWS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
once!(
|
||||
|
||||
Reference in new issue
Block a user