Ver código fonte

The title's bytes under flights' writes go up by whole words (VICTORY_UNDER_WORDS=0: by bytes)

Words are pairs of one dispatch and are not counted against the 4,096 copies a submission sends up, at which it stood until the flights had landed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
local 2 dias atrás
pai
commit
40580d778c

+ 1 - 0
crates/victory-gpu/src/host.rs

@@ -3161,6 +3161,7 @@ mod torn;
 pub(crate) mod upcheck;
 
 #[cfg(test)]
+pub(crate) use send::{goes_as_words, words_under};
 mod late_tests {
     use super::{continues, join_ranges, touches};
 

+ 31 - 1
crates/victory-gpu/src/host/send.rs

@@ -30,6 +30,36 @@ pub(super) fn own() -> bool {
 /// Runs up to this many bytes go as pairs.
 const SHORT: usize = 256;
 
+/// Whether a run of `len` bytes at offset `at` of a copy goes as pairs.
+fn short(at: usize, len: usize) -> bool {
+    len <= SHORT && at % 4 == 0 && len % 4 == 0
+}
+
+/// Whether a run of `len` bytes at offset `at` of a copy in the card's memory
+/// is no copy command of its own, but pairs of one dispatch.
+pub(crate) fn goes_as_words(at: usize, len: usize) -> bool {
+    own() && short(at, len)
+}
+
+/// Whether the title's bytes that go in under flights' writes
+/// (`Shadow::merge_under_writes`) go in by whole words
+/// (`VICTORY_UNDER_WORDS=0`: by the bytes that changed, as before).
+///
+/// By bytes nearly every run (a float's three low bytes) was a copy command
+/// of its own, and a submission with more than 4,096 of them stood until the
+/// flights had landed: 4 to 14 ms of a steady frame (session play-1125-0203:
+/// "more changed runs than a submission sends up"), for some 20 KB. Whole
+/// words are pairs of one dispatch, and are not counted.
+///
+/// A word is taken to be the title's or the shaders', not shared: where the
+/// title changed a byte of a word of which a flight's shader writes another
+/// byte, that byte is as it was before the flight. The landing rests on the
+/// same ([`crate::shadow::exact_back`]).
+pub(crate) fn words_under() -> bool {
+    static ON: OnceLock<bool> = OnceLock::new();
+    *ON.get_or_init(|| own() && std::env::var_os("VICTORY_UNDER_WORDS").is_none_or(|v| v != "0"))
+}
+
 const SCATTER: &str = r#"
 #define RS "RootConstants(num32BitConstants=2, b0), SRV(t0), UAV(u0)"
 cbuffer Part : register(b0) { uint at; uint count; };
@@ -142,7 +172,7 @@ pub(super) fn take(host: &Host, dirty: &[(std::sync::Arc<Shadow>, Vec<(usize, us
     pass(host)?;
     // Runs of whole words of the copy: only those are pairs. (A byte beside
     // them in a word may be the card's.)
-    let short = |&(a, b): &(usize, usize)| b - a <= SHORT && a % 4 == 0 && b % 4 == 0;
+    let short = |&(a, b): &(usize, usize)| short(a, b - a);
     let mut at = 0u64;
     let mut copies = Vec::with_capacity(dirty.len());
     for (_, ranges) in dirty {

+ 8 - 2
crates/victory-gpu/src/shadow.rs

@@ -3198,8 +3198,12 @@ impl Shadow {
                     // SAFETY: inside the mapping of the copy's CPU side,
                     // which only the submitting thread writes.
                     let held = unsafe { std::slice::from_raw_parts_mut(self.data.add(at), n) };
-                    let runs = changed_runs(title, held);
-                    if runs.len() > *runs_left {
+                    // Whole words go up as pairs, all of them in one
+                    // dispatch: only what is a copy of its own counts.
+                    let runs = if crate::host::words_under() { dword_runs(lo, title, held, 0) } else { changed_runs(title, held) };
+                    let own = |&&(r, m): &&(usize, usize)| !crate::host::words_under() || !crate::host::goes_as_words(at + r, m);
+                    let copies = runs.iter().filter(own).count();
+                    if copies > *runs_left {
                         note_stale(2);
                         return true;
                     }
@@ -3229,6 +3233,8 @@ impl Shadow {
                         // written here and nothing around them.
                         unsafe { std::ptr::copy_nonoverlapping(title.as_ptr().add(r), self.data.add(at + r), m) };
                         held[r..r + m].copy_from_slice(&title[r..r + m]);
+                    MERGED[1].fetch_add(runs.len() as u64, Ordering::Relaxed);
+                    self.card_changed_runs(runs.into_iter().map(|(r, m)| (at + r, at + r + m)));
                         MERGED[1].fetch_add(1, Ordering::Relaxed);
                         MERGED[2].fetch_add(m as u64, Ordering::Relaxed);
                     }