Kaynağa Gözat

Landing goes beside the guards while mappings change; rectangles read without that lock

Pieces went through the title's address, guards opened, whenever the runtime was mapping pages, which is most of the time since they
are mapped in groups (28 of 1,620 pieces a frame beside the guards in run textures-4, 640 before): 5,000 blocks opened and 7,000
guarded a frame. VICTORY_LAND_ANYTIME=0: as before. The vertices of rectangle lists are read through the kernel at submission, not
under the lock the mapping holds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
local 2 gün önce
ebeveyn
işleme
2c982ee5a5
2 değiştirilmiş dosya ile 31 ekleme ve 7 silme
  1. 8 5
      crates/victory-gpu/src/draw.rs
  2. 23 2
      crates/victory-gpu/src/land.rs

+ 8 - 5
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),
                     )
                 };

+ 23 - 2
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<bool> = 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