Copies in the card's memory: the changed runs sorted once and stably, piece runs joined while built; steps on the card: slots made on several threads
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
a69eb0cacb
commit
80d95bcd41
3 files changed
+57
-24
No files matched your search
@@ -4140,7 +4140,9 @@ impl Host {
|
|||||||
}
|
}
|
||||||
None => 0,
|
None => 0,
|
||||||
};
|
};
|
||||||
|
let gathering = crate::timeline::span("copies in the card's memory: what changed");
|
||||||
let mut dirty = crate::shadow::card_dirty(sent_as);
|
let mut dirty = crate::shadow::card_dirty(sent_as);
|
||||||
|
gathering.end();
|
||||||
if declared.is_empty() && dirty.is_empty() && looked.is_empty() {
|
if declared.is_empty() && dirty.is_empty() && looked.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -4164,11 +4166,14 @@ impl Host {
|
|||||||
let mut used: Vec<(bool, Prelude)> = Vec::new();
|
let mut used: Vec<(bool, Prelude)> = Vec::new();
|
||||||
let mut looks = None;
|
let mut looks = None;
|
||||||
// The bytes as they are now, whatever later submissions put there.
|
// The bytes as they are now, whatever later submissions put there.
|
||||||
|
let taking = crate::timeline::span("copies in the card's memory: taken");
|
||||||
let own = if send::own() { send::take(self, &dirty) } else { None };
|
let own = if send::own() { send::take(self, &dirty) } else { None };
|
||||||
|
taking.end();
|
||||||
if !dirty.is_empty() {
|
if !dirty.is_empty() {
|
||||||
let Some(sync) = work.sync.pop().or_else(|| self.make_prelude()) else {
|
let Some(sync) = work.sync.pop().or_else(|| self.make_prelude()) else {
|
||||||
fail(format_args!("no host list to bring host copies in the card's memory up to date"));
|
fail(format_args!("no host list to bring host copies in the card's memory up to date"));
|
||||||
};
|
};
|
||||||
|
let _recording = crate::timeline::span("copies in the card's memory: the list");
|
||||||
let (allocator, list) = &sync;
|
let (allocator, list) = &sync;
|
||||||
// SAFETY: the list's last run finished (it ran ahead of a
|
// SAFETY: the list's last run finished (it ran ahead of a
|
||||||
// submission that was waited for, and came back after that);
|
// submission that was waited for, and came back after that);
|
||||||
@@ -4191,12 +4196,13 @@ impl Host {
|
|||||||
let Some((staging, before, _)) = shadow.card_sides() else {
|
let Some((staging, before, _)) = shadow.card_sides() else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
for &(a, b) in ranges {
|
|
||||||
if own.is_none() {
|
if own.is_none() {
|
||||||
|
for &(a, b) in ranges {
|
||||||
list.CopyBufferRegion(&shadow.buffer, a as u64, staging, a as u64, (b - a) as u64);
|
list.CopyBufferRegion(&shadow.buffer, a as u64, staging, a as u64, (b - a) as u64);
|
||||||
}
|
}
|
||||||
crate::shadow::CARD_STATS[0].fetch_add((b - a) as u64, Ordering::Relaxed);
|
|
||||||
}
|
}
|
||||||
|
let bytes: u64 = ranges.iter().map(|&(a, b)| (b - a) as u64).sum();
|
||||||
|
crate::shadow::CARD_STATS[0].fetch_add(bytes, Ordering::Relaxed);
|
||||||
crate::shadow::CARD_STATS[1].fetch_add(ranges.len() as u64, Ordering::Relaxed);
|
crate::shadow::CARD_STATS[1].fetch_add(ranges.len() as u64, Ordering::Relaxed);
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
traffic::moved(traffic::UP, shadow.span(), ranges.iter().copied());
|
traffic::moved(traffic::UP, shadow.span(), ranges.iter().copied());
|
||||||
@@ -4226,13 +4232,23 @@ impl Host {
|
|||||||
// pieces and flags those whose hash is another.
|
// pieces and flags those whose hash is another.
|
||||||
list.SetComputeRootShaderResourceView(1, shadow.buffer.GetGPUVirtualAddress());
|
list.SetComputeRootShaderResourceView(1, shadow.buffer.GetGPUVirtualAddress());
|
||||||
list.SetComputeRootUnorderedAccessView(2, before.GetGPUVirtualAddress());
|
list.SetComputeRootUnorderedAccessView(2, before.GetGPUVirtualAddress());
|
||||||
|
let joins = rehash_runs() || own.is_some();
|
||||||
let runs: Vec<crate::shadow::CardSpan> = if whole.iter().any(|s| Arc::ptr_eq(s, shadow)) {
|
let runs: Vec<crate::shadow::CardSpan> = if whole.iter().any(|s| Arc::ptr_eq(s, shadow)) {
|
||||||
vec![shadow.card_run(0, usize::MAX)]
|
vec![shadow.card_run(0, usize::MAX)]
|
||||||
} else {
|
} else {
|
||||||
ranges.iter().map(|&(a, b)| shadow.card_run(a, b)).collect()
|
// (In order: the next of the same piece, of the
|
||||||
|
// tens of thousands there are, says nothing.)
|
||||||
|
let mut runs: Vec<crate::shadow::CardSpan> = Vec::new();
|
||||||
|
for run in ranges.iter().map(|&(a, b)| shadow.card_run(a, b)) {
|
||||||
|
match runs.last_mut() {
|
||||||
|
Some(last) if joins && (last.first, last.pieces) == (run.first, run.pieces) => last.to = last.to.max(run.to),
|
||||||
|
_ => runs.push(run),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
runs
|
||||||
};
|
};
|
||||||
// The same pieces in fewer passes (`rehash_runs`).
|
// The same pieces in fewer passes (`rehash_runs`).
|
||||||
let runs = if rehash_runs() || own.is_some() { crate::shadow::joined_piece_runs(runs) } else { runs };
|
let runs = if joins { crate::shadow::joined_piece_runs(runs) } else { runs };
|
||||||
CARD_PASSES[0].fetch_add(runs.len() as u64, Ordering::Relaxed);
|
CARD_PASSES[0].fetch_add(runs.len() as u64, Ordering::Relaxed);
|
||||||
CARD_PASSES[1].fetch_add(runs.iter().map(|r| u64::from(r.pieces)).sum::<u64>(), Ordering::Relaxed);
|
CARD_PASSES[1].fetch_add(runs.iter().map(|r| u64::from(r.pieces)).sum::<u64>(), Ordering::Relaxed);
|
||||||
for run in runs {
|
for run in runs {
|
||||||
|
|||||||
@@ -674,11 +674,13 @@ impl Host {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn take_steps(&self, written: &[(usize, usize)], runs: &[&HostList]) -> Result<Option<Taken>, &'static str> {
|
fn take_steps(&self, written: &[(usize, usize)], runs: &[&HostList]) -> Result<Option<Taken>, &'static str> {
|
||||||
|
let mut spent = crate::timeline::span("steps on the card: chosen");
|
||||||
let (does, steps) = does_of(written, runs);
|
let (does, steps) = does_of(written, runs);
|
||||||
let chosen = plan(&does, stage(), placed_order(), &mut None)?;
|
let chosen = plan(&does, stage(), placed_order(), &mut None)?;
|
||||||
if chosen.is_empty() {
|
if chosen.is_empty() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
spent.next("steps on the card: what holds their bytes");
|
||||||
let mut writers = {
|
let mut writers = {
|
||||||
let line = line();
|
let line = line();
|
||||||
let mut all = writers(&line.line);
|
let mut all = writers(&line.line);
|
||||||
@@ -765,6 +767,7 @@ impl Host {
|
|||||||
to,
|
to,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
spent.next("steps on the card: the list");
|
||||||
let Some(own) = self.own_list() else {
|
let Some(own) = self.own_list() else {
|
||||||
return Err("no host list or buffer for it");
|
return Err("no host list or buffer for it");
|
||||||
};
|
};
|
||||||
@@ -817,24 +820,28 @@ impl Host {
|
|||||||
own.list.close();
|
own.list.close();
|
||||||
// SAFETY: a live buffer.
|
// SAFETY: a live buffer.
|
||||||
let gpu = unsafe { own.between.GetGPUVirtualAddress() };
|
let gpu = unsafe { own.between.GetGPUVirtualAddress() };
|
||||||
|
spent.next("steps on the card: the slots");
|
||||||
|
// (11,000 slots a frame in a street, two descriptors each: on
|
||||||
|
// several threads, a slot always on the same one, in the steps'
|
||||||
|
// order.)
|
||||||
|
let parts = if ops.len() < 256 { 1 } else { 8 };
|
||||||
|
crate::land::each_under(parts, &|part| {
|
||||||
for op in &ops {
|
for op in &ops {
|
||||||
DONE[2].fetch_add(op.len as u64, Ordering::Relaxed);
|
if let To::Slot(heap, index) = &op.to
|
||||||
match &op.to {
|
&& *index as usize / 4 % parts == part
|
||||||
To::Slot(heap, index) => {
|
{
|
||||||
DONE[0].fetch_add(1, Ordering::Relaxed);
|
|
||||||
// (A heap that is gone: nothing can read the slot.)
|
// (A heap that is gone: nothing can read the slot.)
|
||||||
crate::descriptor::constant_slot(*heap, *index, &own.between, gpu + op.at, op.len as u32);
|
crate::descriptor::constant_slot(*heap, *index, &own.between, gpu + op.at, op.len as u32);
|
||||||
}
|
}
|
||||||
To::Buffer(_) => {
|
|
||||||
DONE[0].fetch_add(1, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
To::Copy(..) => {
|
|
||||||
DONE[1].fetch_add(1, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
let copies = ops.iter().filter(|op| matches!(op.to, To::Copy(..))).count();
|
||||||
|
DONE[0].fetch_add((ops.len() - copies) as u64, Ordering::Relaxed);
|
||||||
|
DONE[1].fetch_add(copies as u64, Ordering::Relaxed);
|
||||||
|
DONE[2].fetch_add(ops.iter().map(|op| op.len as u64).sum(), Ordering::Relaxed);
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
noted(op);
|
noted(&ops);
|
||||||
}
|
spent.end();
|
||||||
Ok(Some(Taken {
|
Ok(Some(Taken {
|
||||||
own,
|
own,
|
||||||
steps: chosen.iter().map(|&(i, _)| steps[i]).collect(),
|
steps: chosen.iter().map(|&(i, _)| steps[i]).collect(),
|
||||||
@@ -865,15 +872,18 @@ type Noted = std::collections::HashMap<(usize, (u64, u64), (u64, u64)), (u64, us
|
|||||||
static NOTED: Mutex<Option<Noted>> = Mutex::new(None);
|
static NOTED: Mutex<Option<Noted>> = Mutex::new(None);
|
||||||
|
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
fn noted(op: &Op) {
|
fn noted(ops: &[Op]) {
|
||||||
|
let mut noted = NOTED.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let noted = noted.get_or_insert_with(Default::default);
|
||||||
|
for op in ops {
|
||||||
let (to, dst) = match &op.to {
|
let (to, dst) = match &op.to {
|
||||||
To::Copy(to, dst) => (to.span(), *dst),
|
To::Copy(to, dst) => (to.span(), *dst),
|
||||||
To::Slot(..) | To::Buffer(_) => ((0, 0), 0),
|
To::Slot(..) | To::Buffer(_) => ((0, 0), 0),
|
||||||
};
|
};
|
||||||
let mut noted = NOTED.lock().unwrap_or_else(|e| e.into_inner());
|
let e = noted.entry((op.len, op.from.0.span(), to)).or_default();
|
||||||
let e = noted.get_or_insert_with(Default::default).entry((op.len, op.from.0.span(), to)).or_default();
|
|
||||||
*e = (e.0 + 1, op.from.1, dst);
|
*e = (e.0 + 1, op.from.1, dst);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// For the frame-rate line.
|
/// For the frame-rate line.
|
||||||
pub(super) fn log(frames: f64) {
|
pub(super) fn log(frames: f64) {
|
||||||
|
|||||||
@@ -549,11 +549,16 @@ fn window_room_for(size: u64) -> Option<ID3D12Resource> {
|
|||||||
struct SentRuns(Vec<(u64, Vec<(usize, usize)>)>);
|
struct SentRuns(Vec<(u64, Vec<(usize, usize)>)>);
|
||||||
|
|
||||||
impl SentRuns {
|
impl SentRuns {
|
||||||
|
#[cfg(test)]
|
||||||
fn note(&mut self, number: u64, ranges: Vec<(usize, usize)>) {
|
fn note(&mut self, number: u64, ranges: Vec<(usize, usize)>) {
|
||||||
|
self.note_joined(number, joined(ranges));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `ranges` are in order and joined.
|
||||||
|
fn note_joined(&mut self, number: u64, ranges: Vec<(usize, usize)>) {
|
||||||
if ranges.is_empty() {
|
if ranges.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let ranges = joined(ranges);
|
|
||||||
match self.0.iter_mut().find(|s| s.0 == number) {
|
match self.0.iter_mut().find(|s| s.0 == number) {
|
||||||
Some((_, all)) => *all = joined([std::mem::take(all), ranges].concat()),
|
Some((_, all)) => *all = joined([std::mem::take(all), ranges].concat()),
|
||||||
None => self.0.push((number, ranges)),
|
None => self.0.push((number, ranges)),
|
||||||
@@ -608,17 +613,17 @@ pub(crate) fn card_dirty(sent_as: u64) -> Vec<(Arc<Shadow>, Vec<(usize, usize)>)
|
|||||||
.filter(|c| c.touched.swap(false, Ordering::AcqRel))
|
.filter(|c| c.touched.swap(false, Ordering::AcqRel))
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
let mut dirty = c.dirty.lock().unwrap_or_else(|e| e.into_inner());
|
let mut dirty = c.dirty.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
let ranges = std::mem::take(&mut *dirty);
|
let ranges = joined(std::mem::take(&mut *dirty));
|
||||||
if relay() {
|
if relay() {
|
||||||
let mut sent = c.sent.lock().unwrap_or_else(|e| e.into_inner());
|
let mut sent = c.sent.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
sent.forget(fetched);
|
sent.forget(fetched);
|
||||||
sent.note(sent_as, ranges.clone());
|
sent.note_joined(sent_as, ranges.clone());
|
||||||
}
|
}
|
||||||
ranges
|
ranges
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
if !ranges.is_empty() {
|
if !ranges.is_empty() {
|
||||||
out.push((shadow, joined(ranges)));
|
out.push((shadow, ranges));
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
@@ -724,7 +729,9 @@ pub(crate) fn carded_copies() -> Vec<Arc<Shadow>> {
|
|||||||
|
|
||||||
/// Ranges in order, those that overlap or touch as one.
|
/// Ranges in order, those that overlap or touch as one.
|
||||||
fn joined(mut ranges: Vec<(usize, usize)>) -> Vec<(usize, usize)> {
|
fn joined(mut ranges: Vec<(usize, usize)>) -> Vec<(usize, usize)> {
|
||||||
ranges.sort_unstable();
|
// (The sort that finds what is in order already: they come as a few
|
||||||
|
// stretches of tens of thousands in order, put behind one another.)
|
||||||
|
ranges.sort();
|
||||||
let mut out: Vec<(usize, usize)> = Vec::with_capacity(ranges.len());
|
let mut out: Vec<(usize, usize)> = Vec::with_capacity(ranges.len());
|
||||||
for (from, to) in ranges {
|
for (from, to) in ranges {
|
||||||
match out.last_mut() {
|
match out.last_mut() {
|
||||||
|
|||||||
Reference in new issue
Block a user