Merge branch 'local/next' into local/copies
This commit is contained in:
commit
0b3af7939c
15 files changed
+2212
-35
No files matched your search
@@ -382,6 +382,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();
|
||||
@@ -449,9 +454,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]
|
||||
@@ -507,6 +519,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)]);
|
||||
@@ -971,6 +1002,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.
|
||||
@@ -2989,7 +3030,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);
|
||||
@@ -3018,6 +3068,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)> {
|
||||
@@ -3065,6 +3133,19 @@ impl Shadow {
|
||||
card_piece_of(self.start as usize, self.len as usize, span, i)
|
||||
}
|
||||
|
||||
/// The piece that holds offset `at`.
|
||||
pub(crate) fn card_piece_of(&self, at: usize) -> u32 {
|
||||
self.pieces(at, at + 1).start as u32
|
||||
}
|
||||
|
||||
/// 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:
|
||||
|
||||
Reference in new issue
Block a user