Steps done on the card take along what depends on them (VICTORY_CARD_STEPS)
A buffer copy whose destination another step of the submission read was refused and waited for flights (10 ms a frame in run steps-1). Copies and fills that depend on a taken one, or it on them, are now taken too and done level by level in the steps' order; a fill of a texture's upload buffer as well. Reads on the CPU ahead of the copy are no reason to refuse. The waits for title memory changed under shader writes that came up behind it: pages of the title's constants have more changed runs than the 512 a submission sent up (4096 with the switch), and where it still waits, it waits for the flights that declared the range, not for everything. Diagnostics: refusals name the kind of step, waits under shader writes their reason and the host copy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
65b4c43ec1
commit
007fe55730
4 files changed
+539
-151
No files matched your search
@@ -1677,10 +1677,9 @@ enum Step {
|
||||
/// A copy into title memory (destination, source, bytes): the title's
|
||||
/// buffer copies, which later refreshes must see.
|
||||
Copy(usize, usize, usize),
|
||||
/// A copy of title memory into the list's own upload memory; if a
|
||||
/// descriptor slot shows that memory and nothing else does (a constant
|
||||
/// buffer of a table made for the draw), the title heap and the slot.
|
||||
Fill(usize, usize, usize, Option<(usize, u32)>),
|
||||
/// A copy of title memory into the list's own upload memory, and how
|
||||
/// the card could bring the bytes instead.
|
||||
Fill(usize, usize, usize, Option<card_steps::FillTo>),
|
||||
/// Brings a range (address, bytes) of a buffer's host copy up to date:
|
||||
/// once per submission, whichever lists ask, until a `Copy` or `Run`
|
||||
/// intervenes.
|
||||
@@ -2291,13 +2290,23 @@ fn refused(why: &'static str) {
|
||||
*BLAMED.lock().unwrap_or_else(|e| e.into_inner()) = (None, why);
|
||||
}
|
||||
|
||||
/// The wait that comes next is for these ranges ([`stale_under_flights`]).
|
||||
#[cfg(feature = "diagnostics")]
|
||||
fn blame_stale(stale: &[(std::sync::Arc<crate::shadow::Shadow>, usize, usize)]) {
|
||||
if let Some((shadow, from, _)) = stale.first() {
|
||||
let (start, len) = shadow.span();
|
||||
let key = ("title memory changed under shader writes", crate::shadow::stale_why(), 0, start as usize, len as usize);
|
||||
BLAMED.lock().unwrap_or_else(|e| e.into_inner()).0 = Some((key, *from));
|
||||
}
|
||||
}
|
||||
|
||||
/// The wait for what [`blame`] last named, or a wait of another reason than
|
||||
/// title memory read, took `us`.
|
||||
#[cfg(feature = "diagnostics")]
|
||||
fn blamed(why: usize, us: u64) {
|
||||
let (named, refused) = std::mem::replace(&mut *BLAMED.lock().unwrap_or_else(|e| e.into_inner()), (None, ""));
|
||||
let (key, at) = match (why, named) {
|
||||
(WHY_READ, Some(named)) => named,
|
||||
(WHY_READ | WHY_STALE, Some(named)) => named,
|
||||
(WHY_READ, None) => (("a host copy of what a copy done on the card wrote", refused, 0, 0, 0), 0),
|
||||
_ => {
|
||||
let kind = match why {
|
||||
@@ -2342,7 +2351,11 @@ fn log_blame(frames: f64) {
|
||||
us as f64 / 1e3 / frames,
|
||||
n as f64 / frames,
|
||||
passes.join(", "),
|
||||
if why.is_empty() { "" } else { "; not done on the card: " },
|
||||
match (why.is_empty(), kind) {
|
||||
(true, _) => "",
|
||||
(_, "title memory changed under shader writes") => "; not put in under them: ",
|
||||
_ => "; not done on the card: ",
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2416,7 +2429,7 @@ fn blocked_by(written: &[(usize, usize)], runs: &[&HostList], count: bool) -> Op
|
||||
/// may write and that the title wrote since it was last copied. The
|
||||
/// refresh leaves ranges shaders are writing alone (`Shadow::update`), so
|
||||
/// the title's bytes there would reach the card a submission late.
|
||||
fn stale_under_flights(runs: &[&HostList]) -> bool {
|
||||
fn stale_under_flights(runs: &[&HostList]) -> Vec<(std::sync::Arc<crate::shadow::Shadow>, usize, usize)> {
|
||||
use std::sync::Arc;
|
||||
// Per copy, the span of what is refreshed (a flush brings that much
|
||||
// up to date at most).
|
||||
@@ -2437,11 +2450,15 @@ fn stale_under_flights(runs: &[&HostList]) -> bool {
|
||||
// The title's bytes are put in beside the flights' writes; a
|
||||
// settle is still due where that could not be done. At most this
|
||||
// many changed runs go up to copies in the card's memory, each a
|
||||
// copy of its own there.
|
||||
let mut runs_left = 512;
|
||||
return spans.iter().any(|(shadow, from, to)| shadow.merge_under_writes(*from, *to - *from, &mut runs_left));
|
||||
// copy of its own there. With [`card_steps`] the pages of the
|
||||
// title's ring of constants come here too, which were waited for
|
||||
// before: hundreds of short runs each, at about 1.5 us a run.
|
||||
let mut runs_left = if card_steps::stage() > 0 { 4096 } else { 512 };
|
||||
spans.retain(|(shadow, from, to)| shadow.merge_under_writes(*from, *to - *from, &mut runs_left));
|
||||
return spans;
|
||||
}
|
||||
spans.iter().any(|(shadow, from, to)| shadow.stale_under_writes(*from, *to - *from))
|
||||
spans.retain(|(shadow, from, to)| shadow.stale_under_writes(*from, *to - *from));
|
||||
spans
|
||||
}
|
||||
|
||||
/// A fence signal on a queue ([`late`]): goes behind the flights in the
|
||||
@@ -4295,6 +4312,40 @@ impl Host {
|
||||
working(was_working);
|
||||
}
|
||||
|
||||
/// For a submission of `runs` that refreshes the ranges `stale` of host
|
||||
/// copies, which flights may be writing and the title wrote too
|
||||
/// ([`stale_under_flights`]): the flights land first. `ranges` are
|
||||
/// those of the submission's one asking, which is made again.
|
||||
///
|
||||
/// With [`card_steps`] only the flights that declared them: a range of
|
||||
/// a copy nobody declared any more is refreshed like any other. What
|
||||
/// they landed is title memory written, so everything is asked and
|
||||
/// looked at again; what is left after three times waits as before.
|
||||
fn settle_stale(
|
||||
&self,
|
||||
submitted: &mut u64,
|
||||
runs: &[&HostList],
|
||||
mut stale: Vec<(std::sync::Arc<crate::shadow::Shadow>, usize, usize)>,
|
||||
ranges: &[(usize, usize)],
|
||||
) {
|
||||
if relay_exact() && card_steps::stage() > 0 {
|
||||
for _ in 0..3 {
|
||||
#[cfg(feature = "diagnostics")]
|
||||
blame_stale(&stale);
|
||||
relay_wait(WHY_STALE, |_| stale.iter().all(|(shadow, from, to)| !shadow.writes_pending_in(*from, *to)));
|
||||
crate::watch::ask_once(ranges);
|
||||
stale = stale_under_flights(runs);
|
||||
if stale.is_empty() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
blame_stale(&stale);
|
||||
self.settle(submitted, WHY_STALE);
|
||||
crate::watch::ask_once(ranges);
|
||||
}
|
||||
|
||||
/// [`Host::execute`], or with `late` the first half of
|
||||
/// [`Host::execute_late`]: the lists are prepared and sent, and what is
|
||||
/// to be done once they have run comes back with the submission lock
|
||||
@@ -4396,13 +4447,13 @@ impl Host {
|
||||
// may write too, and this submission refreshes it. The flights
|
||||
// are settled, and the asking made again: the copy-back wrote
|
||||
// title memory, which other copies of it must see.
|
||||
if behind && stale_under_flights(runs) {
|
||||
let stale = if behind { stale_under_flights(runs) } else { Vec::new() };
|
||||
if !stale.is_empty() {
|
||||
let settling = std::time::Instant::now();
|
||||
self.settle(&mut submitted, WHY_STALE);
|
||||
self.settle_stale(&mut submitted, runs, stale, &ranges);
|
||||
settled += settling.elapsed();
|
||||
crate::watch::ask_once(&ranges);
|
||||
}
|
||||
} else if behind && stale_under_flights(runs) {
|
||||
} else if behind && !stale_under_flights(runs).is_empty() {
|
||||
let settling = std::time::Instant::now();
|
||||
self.settle(&mut submitted, WHY_STALE);
|
||||
settled += settling.elapsed();
|
||||
@@ -5355,7 +5406,14 @@ impl HostList {
|
||||
pub(crate) fn defer_constants(&self, dst: *mut u8, src: *const u8, len: usize, slot: (usize, u32)) {
|
||||
self.deferred()
|
||||
.copies
|
||||
.push(Step::Fill(dst as usize, src as usize, len, Some(slot)));
|
||||
.push(Step::Fill(dst as usize, src as usize, len, Some(card_steps::FillTo::Slot(slot.0, slot.1))));
|
||||
}
|
||||
|
||||
/// As [`HostList::defer_fill`], for the beginning of a buffer
|
||||
/// [`HostList::upload`] made.
|
||||
pub(crate) fn defer_fill_buffer(&self, buffer: &ID3D12Resource, dst: *mut u8, src: *const u8, len: usize) {
|
||||
let to = (card_steps::stage() > 1).then(|| card_steps::FillTo::Buffer(buffer.clone()));
|
||||
self.deferred().copies.push(Step::Fill(dst as usize, src as usize, len, to));
|
||||
}
|
||||
|
||||
/// Brings `[address, address + len)` of a buffer's host copy up to date
|
||||
@@ -5407,7 +5465,8 @@ impl HostList {
|
||||
///
|
||||
/// shortcut: one buffer per copy; pool them once uploads are frequent.
|
||||
pub(crate) fn upload(&self, host: &Host, size: u64) -> Option<(ID3D12Resource, *mut u8)> {
|
||||
let (buffer, data) = host.upload_buffer(size)?;
|
||||
// With [`card_steps`] the card may be the one that fills it.
|
||||
let (buffer, data) = if card_steps::stage() > 1 { host.shared_buffer(size)? } else { host.upload_buffer(size)? };
|
||||
name(&buffer, || format!("list upload {size:#x}"));
|
||||
self.deferred().hold_upload(buffer.clone(), size);
|
||||
Some((buffer, data))
|
||||
|
||||
Reference in new issue
Block a user