Преглед изворни кода

Title memory by address: every list brings up every copy, whoever made it

An arena another list made while this one was being recorded was brought up by that list's submission alone: structures unpacked from zeros, then written over by the arena's first upload. In run light-8 half of the 470 structures unpacked in the frame with the most (1381) were wrong, 5-15 % in frames with few. A title buffer the builder stores in sends up only the dwords the title changed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
local пре 1 дан
родитељ
комит
28fbbfdcbc
2 измењених фајлова са 25 додато и 13 уклоњено
  1. 15 9
      crates/victory-gpu/src/memory.rs
  2. 10 4
      crates/victory-gpu/src/shadow.rs

+ 15 - 9
crates/victory-gpu/src/memory.rs

@@ -463,6 +463,8 @@ impl Memory {
         if self.pages.contains_key(&(address / PAGE)) || !self.open.insert(n) {
             return;
         }
+        // (Its pages hold what the CPU writes beside the builder's scratch.)
+        self.copies[n].keep_stores();
         let (first, len) = self.copies[n].span();
         tracing::info!(
             start = format_args!("{first:#x}"),
@@ -791,7 +793,6 @@ pub(crate) fn ready(
     }
     let builds = use_ != Use::Reads;
     m.stats.uses[usize::from(builds)] += 1;
-    let numbered = m.copies.len();
     // Once per list and page named: the builder dispatches hundreds of times
     // a frame with the same arguments.
     const READ: usize = usize::MAX - 0x6d;
@@ -880,17 +881,22 @@ pub(crate) fn ready(
         heap.raw_uav_at(base + 1 + n as u32, &shadow.buffer, 0, len);
     }
     m.heaps.insert(key, (base, m.copies.len() as u32));
-    // shortcut: a copy another list numbers meanwhile is brought up to date
-    // by that list's submission, which may run after this one's.
+    // Every copy by every list that has come to by-address memory, whoever
+    // numbered it: an arena another list made while this one was being
+    // recorded was brought up to date by that list's submission alone, which
+    // may run after this one's (structures unpacked from zeros, and then
+    // written over by the arena's first upload: in frames that stream much in
+    // half of them, run light-8).
     let first_read = list.first_use(READ);
-    let from = if first_read { 0 } else { numbered };
-    if first_read || m.copies.len() > numbered {
+    if list.first_use(usize::MAX - (6 << 33) - m.copies.len()) {
         let (start, len) = m.directory.1.span();
         m.directory.1.refresh(list, start, len);
-    }
-    for shadow in &m.copies[from..] {
-        let (start, len) = shadow.span();
-        shadow.refresh(list, start, len);
+        for (n, shadow) in m.copies.iter().enumerate() {
+            if list.first_use(usize::MAX - (7 << 33) - n) {
+                let (start, len) = shadow.span();
+                shadow.refresh(list, start, len);
+            }
+        }
     }
     if first_read {
         list.keep(&m.faults.0);

+ 10 - 4
crates/victory-gpu/src/shadow.rs

@@ -85,7 +85,7 @@ pub(crate) struct Shadow {
     window: bool,
     /// Of a copy with two sides: only the dwords the title changed go up,
     /// as with [`send_changed`] ([`by_address`]).
-    changes_only: bool,
+    changes_only: std::sync::atomic::AtomicBool,
     /// A window in card memory the CPU maps ([`window_mapped_for`]).
     mapped: bool,
     /// With `crate::inplace`: not a copy at all. `buffer` is placed in a
@@ -2686,7 +2686,7 @@ impl Shadow {
             },
             card: None,
             window: false,
-            changes_only: false,
+            changes_only: Default::default(),
             mapped: false,
             place: None,
         }
@@ -3572,7 +3572,7 @@ impl Shadow {
             /// A page of title memory, as read.
             static TITLE: std::cell::RefCell<Vec<u8>> = const { std::cell::RefCell::new(Vec::new()) };
         }
-        let Some(card) = self.card.as_ref().filter(|_| self.changes_only || send_changed()) else {
+        let Some(card) = self.card.as_ref().filter(|_| self.changes_only.load(Ordering::Relaxed) || send_changed()) else {
             return self.copy(from, to);
         };
         let whole = !known && card.before.lock().unwrap_or_else(|e| e.into_inner()).is_none();
@@ -3640,6 +3640,12 @@ impl Shadow {
         self.card.is_some()
     }
 
+    /// Shaders store in it what is not declared: from here on only the dwords
+    /// the title changes go up ([`by_address`]).
+    pub(crate) fn keep_stores(&self) {
+        self.changes_only.store(true, Ordering::Relaxed);
+    }
+
     /// Offsets `[from, to)` go up again whole, as the CPU's side has them.
     pub(crate) fn resend(&self, from: usize, to: usize) {
         self.card_changed(from, to);
@@ -4673,7 +4679,7 @@ pub(crate) fn by_address(start: u64, len: u64) -> Option<Arc<Shadow>> {
     let gpu = unsafe { buffer.GetGPUVirtualAddress() };
     let mut shadow = Shadow::new(buffer, data, gpu, start, len);
     shadow.window = true;
-    shadow.changes_only = true;
+    shadow.changes_only.store(true, Ordering::Relaxed);
     shadow.card = Some(Card {
         staging,
         before: Mutex::default(),