What goes up to card copies: a check, and fetches caught in between put right

VICTORY_FETCH_CHECK=1 (off by default): with VICTORY_RELAY_COPY a piece is
fetched beside later submissions, and one of those that clears it and fills
it again with the same is not flagged by its compare: title memory and the
CPU's side kept what was in between, and the next refresh of the 64 KiB
sent it up over the right bytes. The compare now gives the piece's hash
with its flag; a fetch that is not that is made again by the next flight
that may write the piece. (The test shows 11-12 of 12 wrong without it.)

VICTORY_UPCOPY_CHECK=1 (diagnostics): at each send up, the words that the
title did not change and the card holds another value of; every few seconds
at rest, the words in which a copy's card side is not its CPU side, and
whether they were declared as written and fetched.

victory replay --upcopies: the same question of a captured frame, and which
pieces were written undeclared (replay1 and replay2: compute
82a2ad6d07417d36 through views picked by index, 73-75 pieces a frame).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-24 22:17:50 -06:00
1 parent da89c8a5a9
commit f86aae992a
10 files changed
+1688 -54

No files matched your search

+78 -2
View File
@@ -372,6 +372,11 @@ pub(crate) fn card_dirty(sent_as: u64) -> Vec<(Arc<Shadow>, Vec<(usize, usize)>)
out
}
/// The copies in the card's memory (diagnostics: `crate::host::upcheck`).
pub(crate) fn carded_copies() -> Vec<Arc<Shadow>> {
CARDED.lock().unwrap_or_else(|e| e.into_inner()).iter().filter_map(std::sync::Weak::upgrade).collect()
}
/// Ranges in order, those that overlap or touch as one.
fn joined(mut ranges: Vec<(usize, usize)>) -> Vec<(usize, usize)> {
ranges.sort_unstable();
@@ -439,9 +444,16 @@ fn card_piece_of(start: usize, len: usize, span: &CardSpan, i: u32) -> (usize, u
(lo.max(span.from as usize), hi.min(span.to as usize))
}
/// The offsets [`Shadow::card_hashed`] gives, for a card's buffer of `size`
/// bytes for title memory from `start` on.
fn card_hashed_of(start: usize, size: usize, piece: usize) -> (usize, usize) {
let (lo, hi) = piece_at(start, size, piece);
(lo & !15, hi.next_multiple_of(16))
}
#[cfg(test)]
mod card_tests {
use super::{CardSpan, PIECE, card_piece_of, card_span_of, joined, joined_piece_runs};
use super::{CardSpan, PIECE, card_hashed_of, card_piece_of, card_span_of, joined, joined_piece_runs};
/// Joined runs hold every piece of the runs given, once, and no other.
#[test]
@@ -497,6 +509,25 @@ mod card_tests {
}
/// Changed ranges are joined where they overlap or touch, and only there.
/// What is fetched of a piece to hash it is what the shader hashes.
#[test]
fn a_piece_is_hashed_here_as_on_the_card() {
for start in [0usize, 0x10_0000, 0xd_5edb_c780, 0x12_3456_7008] {
for size in [1usize << 16, 5 << 16, 0x20_0000] {
let span = card_span_of(start, 0, size);
for i in 0..span.pieces {
// As `CARD_COMPARE` has it.
let (piece, skew, size) = (span.first + i, span.skew, size as u32);
let lo = (piece * 65536).saturating_sub(skew);
let hi = ((piece + 1) * 65536 - skew).min(size);
let shader = (lo & !15, (hi + 15) & !15);
let here = card_hashed_of(start, size as usize, piece as usize);
assert_eq!((here.0 as u32, here.1 as u32), shader, "start {start:#x} size {size:#x} piece {piece}");
}
}
}
}
#[test]
fn ranges_join_where_they_touch() {
assert_eq!(joined(vec![(8, 12), (0, 4), (4, 6), (10, 20), (30, 31)]), [(0, 6), (8, 20), (30, 31)]);
@@ -965,6 +996,16 @@ mod difference_tests {
/// The unit shader writes are looked for and put back in.
const PIECE: usize = 64 << 10;
/// Calls `f` with `[from, to)` cut at multiples of [`PIECE`].
fn for_pieces_of(from: usize, to: usize, mut f: impl FnMut(usize, usize)) {
let mut at = from;
while at < to {
let next = ((at / PIECE + 1) * PIECE).min(to);
f(at, next);
at = next;
}
}
/// Copies `len` bytes, on several threads if they are many: a snapshot of
/// the world's big heap is 100-170 MB per submission, 2-4 GB a frame, and
/// one thread copies some 8 GB/s.
@@ -2680,7 +2721,16 @@ impl Shadow {
let (from, to) = (from.max(start), to.min(end));
// SAFETY: inside the mapping (`from` and `to` are within the buffer).
let at = unsafe { self.data.add(from - start) };
crate::host::copy_mapped(at, from as *const u8, to - from, false);
if self.card.is_some() && from < to && crate::host::upcheck::on() {
for_pieces_of(from - start, to - start, |a, b| {
let was = self.card_held(a, b - a);
// SAFETY: inside the mapping, as above.
crate::host::copy_mapped(unsafe { self.data.add(a) }, (start + a) as *const u8, b - a, false);
crate::host::upcheck::note(self.id, a, &was, &self.card_held(a, b - a));
});
} else {
crate::host::copy_mapped(at, from as *const u8, to - from, false);
}
// After the bytes are in: a snapshot taken meanwhile is not current.
self.changed(from - start, to - start);
self.card_changed(from - start, to - start);
@@ -2709,6 +2759,24 @@ impl Shadow {
}
}
/// Diagnostics: of a copy in the card's memory, what its CPU side holds
/// at offsets `[at, at + len)` (cut to the copy).
pub(crate) fn card_held(&self, at: usize, len: usize) -> Vec<u8> {
let to = (at + len).min(self.len as usize);
if self.card.is_none() || at >= to {
return Vec::new();
}
// SAFETY: inside the mapping; the caller holds the submission lock,
// under which it is written but for what is being landed.
unsafe { std::slice::from_raw_parts(self.data.add(at).cast_const(), to - at) }.to_vec()
}
/// Diagnostics: the offsets whose bytes have not gone to the card's side
/// yet.
pub(crate) fn card_dirty_now(&self) -> Vec<(usize, usize)> {
self.card.as_ref().map_or_else(Vec::new, |c| c.dirty.lock().unwrap_or_else(|e| e.into_inner()).clone())
}
/// Of a copy in the card's memory: the CPU's side (PC memory), the
/// card side's bytes from before if made yet, and their size.
pub(crate) fn card_sides(&self) -> Option<(&ID3D12Resource, Option<ID3D12Resource>, u64)> {
@@ -2756,6 +2824,14 @@ impl Shadow {
card_piece_of(self.start as usize, self.len as usize, span, i)
}
/// The offsets the compare on the card hashes of a piece: what lies of
/// it in the card's buffer (which may be longer than the copy), widened
/// to 16 bytes.
pub(crate) fn card_hashed(&self, piece: u32) -> (usize, usize) {
let size = self.card.as_ref().map_or(self.len, |c| c.size) as usize;
card_hashed_of(self.start as usize, size, piece as usize)
}
/// The walls trace (`crate::host::walls_trace`): a piece of `fetched`
/// bytes of this copy came back from the card and `written` of them
/// went into title memory. Summed per buffer and logged once a frame: