|
@@ -2223,6 +2223,11 @@ struct Deferred {
|
|
|
/// memory they go to, the bytes of a row, the rows, the title's row
|
|
/// memory they go to, the bytes of a row, the rows, the title's row
|
|
|
/// pitch.
|
|
/// pitch.
|
|
|
backs: Vec<(ID3D12Resource, usize, [usize; 3])>,
|
|
backs: Vec<(ID3D12Resource, usize, [usize; 3])>,
|
|
|
|
|
+ /// Title textures of the kinds copied back ([`crate::texback`]) that
|
|
|
|
|
+ /// the list's shaders write, copied when the list closes.
|
|
|
|
|
+ back_wanted: Vec<crate::texback::Target>,
|
|
|
|
|
+ /// Those copies, whose texels go to title memory once the list has run.
|
|
|
|
|
+ texture_backs: Vec<crate::texback::Back>,
|
|
|
/// Whether the indirect-work budget is zeroed for this recording (a
|
|
/// Whether the indirect-work budget is zeroed for this recording (a
|
|
|
/// step on the CPU, or in the list for the card's copy).
|
|
/// step on the CPU, or in the list for the card's copy).
|
|
|
budget_zeroed: bool,
|
|
budget_zeroed: bool,
|
|
@@ -2561,6 +2566,8 @@ struct Sent {
|
|
|
back: Vec<Declared>,
|
|
back: Vec<Declared>,
|
|
|
/// What was taken off it to be done on the card.
|
|
/// What was taken off it to be done on the card.
|
|
|
own: Option<card_steps::Taken>,
|
|
own: Option<card_steps::Taken>,
|
|
|
|
|
+ /// Title-memory ranges written when its shader textures are copied back.
|
|
|
|
|
+ texture_back_ranges: Vec<(usize, usize)>,
|
|
|
/// Its bottom-of-pipe writes.
|
|
/// Its bottom-of-pipe writes.
|
|
|
writes: Vec<(usize, crate::queue::Written, usize)>,
|
|
writes: Vec<(usize, crate::queue::Written, usize)>,
|
|
|
}
|
|
}
|
|
@@ -2578,6 +2585,7 @@ struct Flight {
|
|
|
back: Vec<Declared>,
|
|
back: Vec<Declared>,
|
|
|
/// The list of ours that ran ahead of them ([`card_steps`]).
|
|
/// The list of ours that ran ahead of them ([`card_steps`]).
|
|
|
own: Option<card_steps::Taken>,
|
|
own: Option<card_steps::Taken>,
|
|
|
|
|
+ texture_back_ranges: Vec<(usize, usize)>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// One thing in the line of what waits for the card, in order.
|
|
/// One thing in the line of what waits for the card, in order.
|
|
@@ -2591,8 +2599,8 @@ enum Late {
|
|
|
|
|
|
|
|
struct Line {
|
|
struct Line {
|
|
|
line: Vec<Late>,
|
|
line: Vec<Late>,
|
|
|
- /// The title memory the flights' shaders may write (address, end), in
|
|
|
|
|
- /// order and joined.
|
|
|
|
|
|
|
+ /// The title memory the flights' shaders and texture readbacks may write
|
|
|
|
|
+ /// (address, end), in order and joined.
|
|
|
written: Vec<(usize, usize)>,
|
|
written: Vec<(usize, usize)>,
|
|
|
/// Host lists in the flights.
|
|
/// Host lists in the flights.
|
|
|
lists: usize,
|
|
lists: usize,
|
|
@@ -3754,6 +3762,11 @@ pub(crate) fn walls_trace() -> bool {
|
|
|
/// without it, so the title read a buffer nobody wrote, as before read-backs
|
|
/// without it, so the title read a buffer nobody wrote, as before read-backs
|
|
|
/// were made (the exposure metering's two small float targets, every frame).
|
|
/// were made (the exposure metering's two small float targets, every frame).
|
|
|
fn read_backs(list: &HostList) {
|
|
fn read_backs(list: &HostList) {
|
|
|
|
|
+ // Textures shaders wrote that the title reads on the CPU
|
|
|
|
|
+ // ([`crate::texback`]).
|
|
|
|
|
+ for back in &list.deferred().texture_backs {
|
|
|
|
|
+ crate::texback::land(back);
|
|
|
|
|
+ }
|
|
|
for (buffer, at, [row, rows, pitch]) in &list.deferred().backs {
|
|
for (buffer, at, [row, rows, pitch]) in &list.deferred().backs {
|
|
|
let mut data = std::ptr::null_mut();
|
|
let mut data = std::ptr::null_mut();
|
|
|
// SAFETY: a read-back buffer of ours, written by the list that has
|
|
// SAFETY: a read-back buffer of ours, written by the list that has
|
|
@@ -4169,7 +4182,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;
|
|
|
}
|
|
}
|
|
@@ -4193,11 +4208,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);
|
|
@@ -4220,12 +4238,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());
|
|
@@ -4255,13 +4274,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 {
|
|
@@ -4851,6 +4880,7 @@ impl Host {
|
|
|
if let Late::Run(flight) = item {
|
|
if let Late::Run(flight) = item {
|
|
|
*lists += flight.order.len().max(1);
|
|
*lists += flight.order.len().max(1);
|
|
|
ranges.extend(flight.back.iter().flat_map(|(_, r)| r.iter().copied()));
|
|
ranges.extend(flight.back.iter().flat_map(|(_, r)| r.iter().copied()));
|
|
|
|
|
+ ranges.extend(flight.texture_back_ranges.iter().copied());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
join_ranges(written, ranges);
|
|
join_ranges(written, ranges);
|
|
@@ -5058,7 +5088,13 @@ impl Host {
|
|
|
let most = {
|
|
let most = {
|
|
|
let mut line = line();
|
|
let mut line = line();
|
|
|
let Line { line: items, written, lists: flying, target, .. } = &mut *line;
|
|
let Line { line: items, written, lists: flying, target, .. } = &mut *line;
|
|
|
- join_ranges(written, sent.back.iter().flat_map(|(_, ranges)| ranges.iter().copied()));
|
|
|
|
|
|
|
+ join_ranges(
|
|
|
|
|
+ written,
|
|
|
|
|
+ sent.back
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .flat_map(|(_, ranges)| ranges.iter().copied())
|
|
|
|
|
+ .chain(sent.texture_back_ranges.iter().copied()),
|
|
|
|
|
+ );
|
|
|
*flying += order.len();
|
|
*flying += order.len();
|
|
|
*target = *submitted;
|
|
*target = *submitted;
|
|
|
items.push(Late::Run(Flight {
|
|
items.push(Late::Run(Flight {
|
|
@@ -5069,6 +5105,7 @@ impl Host {
|
|
|
card: sent.card,
|
|
card: sent.card,
|
|
|
back: sent.back,
|
|
back: sent.back,
|
|
|
own: sent.own,
|
|
own: sent.own,
|
|
|
|
|
+ texture_back_ranges: sent.texture_back_ranges,
|
|
|
}));
|
|
}));
|
|
|
items.extend(sent.writes.into_iter().map(|(at, what, bytes)| Late::Write(at, what, bytes)));
|
|
items.extend(sent.writes.into_iter().map(|(at, what, bytes)| Late::Write(at, what, bytes)));
|
|
|
*flying >= late_most()
|
|
*flying >= late_most()
|
|
@@ -5106,7 +5143,13 @@ impl Host {
|
|
|
{
|
|
{
|
|
|
let mut line = line();
|
|
let mut line = line();
|
|
|
let Line { line: items, written, lists: flying, target, .. } = &mut *line;
|
|
let Line { line: items, written, lists: flying, target, .. } = &mut *line;
|
|
|
- join_ranges(written, sent.back.iter().flat_map(|(_, ranges)| ranges.iter().copied()));
|
|
|
|
|
|
|
+ join_ranges(
|
|
|
|
|
+ written,
|
|
|
|
|
+ sent.back
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .flat_map(|(_, ranges)| ranges.iter().copied())
|
|
|
|
|
+ .chain(sent.texture_back_ranges.iter().copied()),
|
|
|
|
|
+ );
|
|
|
*flying += 1;
|
|
*flying += 1;
|
|
|
*target = *submitted;
|
|
*target = *submitted;
|
|
|
items.push(Late::Run(Flight {
|
|
items.push(Late::Run(Flight {
|
|
@@ -5117,6 +5160,7 @@ impl Host {
|
|
|
card: sent.card,
|
|
card: sent.card,
|
|
|
back: sent.back,
|
|
back: sent.back,
|
|
|
own: sent.own,
|
|
own: sent.own,
|
|
|
|
|
+ texture_back_ranges: sent.texture_back_ranges,
|
|
|
}));
|
|
}));
|
|
|
items.extend(sent.writes.into_iter().map(|(at, what, bytes)| Late::Write(at, what, bytes)));
|
|
items.extend(sent.writes.into_iter().map(|(at, what, bytes)| Late::Write(at, what, bytes)));
|
|
|
}
|
|
}
|
|
@@ -5584,6 +5628,10 @@ impl Host {
|
|
|
#[cfg(feature = "diagnostics")]
|
|
#[cfg(feature = "diagnostics")]
|
|
|
split.part(5);
|
|
split.part(5);
|
|
|
let back = crate::picked::with(declared, &picked.written);
|
|
let back = crate::picked::with(declared, &picked.written);
|
|
|
|
|
+ let mut texture_back_ranges = Vec::new();
|
|
|
|
|
+ for list in runs {
|
|
|
|
|
+ texture_back_ranges.extend(list.deferred().texture_backs.iter().map(crate::texback::Back::range));
|
|
|
|
|
+ }
|
|
|
let writes = runs.iter().flat_map(|l| l.deferred().writes.clone()).collect();
|
|
let writes = runs.iter().flat_map(|l| l.deferred().writes.clone()).collect();
|
|
|
SUBMISSION_US[0].fetch_add((prepared - started).saturating_sub(settled).as_micros() as u64, Ordering::Relaxed);
|
|
SUBMISSION_US[0].fetch_add((prepared - started).saturating_sub(settled).as_micros() as u64, Ordering::Relaxed);
|
|
|
submitting(0, 0);
|
|
submitting(0, 0);
|
|
@@ -5594,6 +5642,7 @@ impl Host {
|
|
|
card,
|
|
card,
|
|
|
back,
|
|
back,
|
|
|
own,
|
|
own,
|
|
|
|
|
+ texture_back_ranges,
|
|
|
writes,
|
|
writes,
|
|
|
};
|
|
};
|
|
|
working(was_working);
|
|
working(was_working);
|
|
@@ -6048,6 +6097,7 @@ impl HostList {
|
|
|
pub(crate) fn close(&self) {
|
|
pub(crate) fn close(&self) {
|
|
|
let _closing = crate::timeline::span("closing a host list");
|
|
let _closing = crate::timeline::span("closing a host list");
|
|
|
self.twins_to_depth();
|
|
self.twins_to_depth();
|
|
|
|
|
+ self.textures_back();
|
|
|
let scratch = self.indirect_args.lock().unwrap_or_else(|e| e.into_inner()).clone();
|
|
let scratch = self.indirect_args.lock().unwrap_or_else(|e| e.into_inner()).clone();
|
|
|
if let Some((scratch, _)) = scratch {
|
|
if let Some((scratch, _)) = scratch {
|
|
|
self.indirect_common(&scratch);
|
|
self.indirect_common(&scratch);
|
|
@@ -6364,6 +6414,34 @@ impl HostList {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// A draw or dispatch being prepared writes title texture `resource`
|
|
|
|
|
+ /// through unordered access: if it is of a kind copied back
|
|
|
|
|
+ /// ([`crate::texback`]), the list copies it when it closes.
|
|
|
|
|
+ pub(crate) fn texture_written(&self, resource: crate::object::This) {
|
|
|
|
|
+ if !crate::texback::wanted(resource) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ let mut deferred = self.deferred();
|
|
|
|
|
+ if !deferred.back_wanted.iter().any(|target| target.owner() == resource as usize)
|
|
|
|
|
+ && let Some(target) = crate::texback::Target::new(resource)
|
|
|
|
|
+ {
|
|
|
|
|
+ deferred.back_wanted.push(target);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// Before the list closes: the textures its shaders wrote that are copied
|
|
|
|
|
+ /// back go into read-back buffers ([`crate::texback::record`]).
|
|
|
|
|
+ fn textures_back(&self) {
|
|
|
|
|
+ const COPY_SOURCE: u32 = 0x800;
|
|
|
|
|
+ let wanted = std::mem::take(&mut self.deferred().back_wanted);
|
|
|
|
|
+ for target in wanted {
|
|
|
|
|
+ self.settle(&target.copy, COPY_SOURCE);
|
|
|
|
|
+ if let Some(back) = crate::texback::record(&self.list, target) {
|
|
|
|
|
+ self.deferred().texture_backs.push(back);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// The draw or dispatch just prepared is recorded: the twins it writes
|
|
/// The draw or dispatch just prepared is recorded: the twins it writes
|
|
|
/// now hold what their depth textures lack.
|
|
/// now hold what their depth textures lack.
|
|
|
pub(crate) fn twins_written(&self) {
|
|
pub(crate) fn twins_written(&self) {
|
|
@@ -6531,7 +6609,8 @@ impl HostList {
|
|
|
&& deferred.kept.is_empty()
|
|
&& deferred.kept.is_empty()
|
|
|
&& deferred.textures.is_empty()
|
|
&& deferred.textures.is_empty()
|
|
|
&& deferred.writes.is_empty()
|
|
&& deferred.writes.is_empty()
|
|
|
- && deferred.backs.is_empty())
|
|
|
|
|
|
|
+ && deferred.backs.is_empty()
|
|
|
|
|
+ && deferred.texture_backs.is_empty())
|
|
|
{
|
|
{
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|