A submission's fills of upload memory are done together on several threads (VICTORY_WIDE_FILLS=0: one by one)

5 ms of the submitting thread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 03:50:05 -06:00
1 parent 1a411ae49b
commit aff4def0fb
1 file changed
+53
+53
View File
@@ -4973,6 +4973,7 @@ impl Host {
#[cfg(feature = "diagnostics")]
split.part(2);
// The snapshots of the ranges shaders may write, if they were left
batch.fill();
// for now (`crate::shadow::wide_back`): the refreshes are done, the
// lists have not gone to the card.
{
@@ -6395,6 +6396,7 @@ impl HostList {
if let Some(bytes) = p.prepare(free) {
batch.placed.push((p.shadow.clone(), p.dst, bytes));
}
batch.fill();
(started, p.len)
}
Step::Refresh(shadow, address, len) => {
@@ -6411,12 +6413,19 @@ impl HostList {
let started = std::time::Instant::now();
if matches!(step, Step::Run(_)) {
batch.title_written();
if wide_fills() {
batch.fills.push((dst, src, len));
bytes += len as u64;
continue;
}
let started = std::time::Instant::now();
}
work();
// It wrote title memory, where is not known here: the
// submission's one asking ends, later refreshes ask anew.
if matches!(step, Step::Run(_)) {
crate::watch::ask_once_end();
batch.fill();
}
#[cfg(feature = "diagnostics")]
{
@@ -6435,6 +6444,7 @@ impl HostList {
#[cfg(feature = "diagnostics")]
let snapshot = std::time::Instant::now();
shadow.writing(*address, *len);
batch.fill();
#[cfg(feature = "diagnostics")]
{
add(C::GpuWrites, 1);
@@ -6705,6 +6715,22 @@ impl Batch {
(r.1, r.2) = (r.1.min(address), r.2.max(end));
}
None => {
/// Fills not done yet (destination, source, bytes): [`wide_fills`].
fills: Vec<(usize, usize, usize)>,
}
/// Whether the fills of a submission's upload memory are done together on
/// several threads (`VICTORY_WIDE_FILLS=0`: one after the other, where the
/// lists name them).
///
/// They are 7,000 to 12,000 a frame, some 500 bytes each, 5 ms of the
/// submitting thread. Each reads title memory and writes memory of its own
/// that the card alone reads, when the lists run; they are done before the
/// next step that writes title memory or runs code of ours, and before the
/// submission goes on from its steps.
fn wide_fills() -> bool {
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_WIDE_FILLS").is_none_or(|v| v != "0") && wide_refresh())
self.index.insert(key, self.refreshes.len());
self.refreshes.push((shadow.clone(), address, end));
}
@@ -6790,6 +6816,33 @@ impl Batch {
FLUSHES[0].fetch_add(1, Ordering::Relaxed);
FLUSHES[1].fetch_add(all as u64, Ordering::Relaxed);
}
/// The fills noted are done.
fn fill(&mut self) {
// Below this many the threads cost more than they save.
const FEW: usize = 96;
const PART: usize = 64;
if self.fills.is_empty() {
return;
}
let started = std::time::Instant::now();
if self.fills.len() < FEW {
for (dst, src, len) in self.fills.drain(..) {
copy_mapped(dst as *mut u8, src as *const u8, len, false);
}
} else {
let fills = std::mem::take(&mut self.fills);
crate::shadow::wide_each(fills.len().div_ceil(PART), move |i| {
for &(dst, src, len) in fills.iter().skip(i * PART).take(PART) {
copy_mapped(dst as *mut u8, src as *const u8, len, false);
}
});
}
let took = started.elapsed();
PREPARING[0].fetch_add(took.as_micros() as u64, Ordering::Relaxed);
#[cfg(feature = "diagnostics")]
SPLIT[7].fetch_add(took.as_nanos() as u64, Ordering::Relaxed);
}
}
fn flush_all(&mut self) {