diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index 4bca1ac..7197f01 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -3187,15 +3187,18 @@ impl State { let (from, to, stride) = (from as usize, to as usize, stride as usize); let n = rects as usize; list.defer_host_read(from, n * 3 * stride, move || { - // The vertices are read in place, at submission: no change - // of mapping under the read (see - // `crate::watch::title_memory_reading`). - let _mapped = crate::watch::title_memory_reading(); + // The vertices are read through the kernel, at submission; in + // place only if that fails, with no change of mapping under + // the read (see `crate::watch::title_memory_reading`): while + // the world streams a change is under way most of the time, + // and this is the thread that submits. + let mut read = vec![0u8; n * 3 * stride]; + let held = (!crate::host::read_into(from as *const u8, &mut read)).then(crate::watch::title_memory_reading); // SAFETY: the vertices lie in a title buffer (checked when // recorded) and the scratch memory is the list's. let (src, dst) = unsafe { ( - std::slice::from_raw_parts(from as *const u8, n * 3 * stride), + if held.is_some() { std::slice::from_raw_parts(from as *const u8, n * 3 * stride) } else { &read[..] }, std::slice::from_raw_parts_mut(to as *mut u8, n * 6 * stride), ) }; diff --git a/crates/victory-gpu/src/land.rs b/crates/victory-gpu/src/land.rs index f8d1cf9..34c359e 100644 --- a/crates/victory-gpu/src/land.rs +++ b/crates/victory-gpu/src/land.rs @@ -419,6 +419,26 @@ impl Had { } } +/// Whether a piece is put through a view of ours while the runtime changes +/// a mapping too (`VICTORY_LAND_ANYTIME=0`: through the title's address, as +/// before). +/// +/// While the world streams a change is under way nearly all the time (pages +/// are mapped in groups, eight threads side by side: 28 of 1,620 pieces a +/// frame went through a view of ours in run textures-4, 630 in run n03). Put +/// through the title's address a piece opens the guards of its blocks, 5,000 +/// changes of protection a frame, which wait for the address-space lock the +/// mapping wants as well, and every refresh guards them again: the frame went +/// from 105 to 140 ms. The record names a run of a section only while it is +/// mapped there (it is taken out before a view goes and put in when one is +/// there), so the change is one of other memory, or one the title makes of +/// memory its shaders are writing at that moment, which it may not (its +/// fences are signalled after the landing). +fn anytime() -> bool { + static ON: std::sync::OnceLock = std::sync::OnceLock::new(); + *ON.get_or_init(|| std::env::var_os("VICTORY_LAND_ANYTIME").is_none_or(|v| v != "0")) +} + /// What a job wrote beside the guards, to be noted ([`Notes::flush`]). #[derive(Default)] pub(crate) struct Notes { @@ -528,9 +548,10 @@ unsafe fn piece_at( }; // From here until the piece is put the runtime changes no mapping: our // view's address stays where the title sees `title`. Not waited for: if - // a change is under way, the title's own address does. + // a change is under way, what the record of the views says now does + // ([`anytime`]), or the title's own address. let reading = beside.then(crate::watch::title_memory_reading_now).flatten(); - let beside = reading.as_ref().and_then(|_| crate::inplace::beside(title, end)); + let beside = if reading.is_some() || beside && anytime() { crate::inplace::beside(title, end) } else { None }; count(stat::PIECES, 1); count(if beside.is_some() { stat::BESIDE } else { stat::DIRECT }, 1); // The pages that differ, before any is written: none, and the guard