Replay dumps: a texture the cover rule holds covered is dumped with a whole-texture cover

A heap texture that another placement's texture wrote over after its last write was reported by
compare-dumps as a difference: the dump loop passed no cover for a texture (dumps.rs: "always `-`
for a texture"), so the bytes Metal leaves undefined there were compared. Each texture a listed
command buffer stores or binds is now dumped, when the dump reads it (after the wait that saw
the command buffer complete, the moment a buffer's ranges are taken), with the cover 0..N, N its
dump's length, where the cover rule holds any byte of it covered (Covers::covered), and `-`
otherwise. A texture's ranges in the rule are its bytes in its heap, which the dump's parts are
not laid out as, so a covered texture is covered whole. The compare then leaves its words out
as it leaves out a covered buffer word. dumps.rs and docs/REPLAY-STREAM.md section 10 say so.

Test: the_dump_compare_leaves_out_a_covered_texture_and_reports_one_outside_every_cover (no
device; Kept reads a texture part's first word from a per-texture word where it holds one). Of
three textures placed in a heap, #5 and #6 over each other and #7 apart, two dispatches of a
state that writes slot 0 write #5 then #6, which covers #5; the second play reads #5 and #7
otherwise. #5's cover is 0..32 and its differing word is counted covered; #7, covered by
nothing, is the one difference reported.

Verified at this commit: nothing yet; the lane's jobs follow.
This commit is contained in:
Anees Iqbal committed 2026-11-25 16:41:51 -08:00
1 parent f6b1adf204
commit e9484b7d03
4 files changed
+113 -17

No files matched your search

@@ -9,20 +9,23 @@
//! renders), in the order of [`Part`], and a compute-bound texture's first level and slice,
//! each laid out as a check reads a texture's first level and slice;
//! - `cb<C>-obj<O>.cover`: the ranges of it the player's cover rule (`covers.rs`) held covered
//! then, as `start..end` byte offsets joined by commas, or `-` for none (always `-` for a
//! texture);
//! then, as `start..end` byte offsets joined by commas, or `-` for none. A texture's is the
//! whole of its bytes, `0..N`, where the rule held any byte of it covered (`Covers::covered`),
//! and `-` otherwise: the rule's ranges are the texture's bytes in its heap, which its parts
//! here are not laid out as;
//! - `cb<C>-obj<O>.unread`: where the backend could not read the buffer or texture, why, in place
//! of its bytes (a multisample texture a pass stores without resolving it, for one);
//! - `cb<C>-obj<O>.copy`: for a buffer the play keeps two copies of, which one the bytes are
//! ([`ReadCopy::label`]): its CPU copy, or its device copy, read back.
//!
//! [`compare_dumps`] reads two plays' dumps and compares each buffer's bytes word by word (4 bytes).
//! It leaves out a word that lies wholly inside a covered range of either play: the cover rule
//! leaves those bytes undefined, and a backend that answers no texture writes covers less
//! (`Backend::texture_writes`). Every other differing word is reported, and so is a dump that
//! only one play has, a buffer that either play could not read, and a difference in length. So is
//! a buffer the two plays read different copies of: the CPU's bytes of one and the device's of the
//! other are no compare of either. The summary counts the buffers compared by the copy both read.
//! It leaves out a word that lies wholly inside a covered range of either play, so all of a
//! texture that either play's rule held covered: the cover rule leaves those bytes undefined, and
//! a backend that answers no texture writes covers less (`Backend::texture_writes`). Every other
//! differing word is reported, and so is a dump that only one play has, a buffer that either play
//! could not read, and a difference in length. So is a buffer the two plays read different copies
//! of: the CPU's bytes of one and the device's of the other are no compare of either. The summary
//! counts the buffers compared by the copy both read.
//! A whole-object checksum is no such compare: one word under a cover would make a buffer differ,
//! and one word outside it would hide behind a cover elsewhere in the buffer.
//!
@@ -1268,7 +1268,8 @@ impl<'b, B: Backend> Player<'b, B> {
/// The player that, once each command buffer whose stream id `command_buffers` holds
/// completed, writes every buffer its encoders named into `dir`, with the ranges of it the
/// cover rule held covered then, and every colour attachment its render passes stored, the
/// parts of it they stored (`dumps.rs`): the per-command-buffer compare of two plays
/// parts of it they stored, covered whole where the rule held any byte of it covered then
/// (`dumps.rs`): the per-command-buffer compare of two plays
/// ([`compare_dumps`](super::compare_dumps)) reads them. A listed command buffer's buffers are
/// read after the wait that saw it complete, before the next call plays.
pub fn dumping(mut self, command_buffers: dumps::CommandBufferList, dir: PathBuf) -> Self {
@@ -1728,7 +1729,8 @@ impl<'b, B: Backend> Player<'b, B> {
/// Write out the listed command buffers that completed (`dumping`): each buffer they named,
/// read now, and its covered ranges now; each colour attachment their render passes stored,
/// the parts of it they stored, and each texture their compute encoders bound, its first
/// level and slice, read now.
/// level and slice, read now, covered whole where the cover rule holds any byte of it covered
/// now.
fn dump_completed(&mut self, left_out: &mut Counters) -> Result<(), PlayError> {
let Some(dump) = &mut self.dump else {
return Ok(());
@@ -1764,7 +1766,13 @@ impl<'b, B: Backend> Player<'b, B> {
for (command_buffer, texture, parts) in textures {
let bytes = self.uncounted(left_out, |player| player.read_parts(texture, &parts));
let bytes = bytes.as_deref().map_err(|error| error.to_string());
dumps::write(&dir, command_buffer, texture, bytes, &[], None)
// The rule's ranges are the texture's bytes in its heap, which its parts are not laid
// out as: a texture any byte of which is covered is covered whole.
let whole = match (&bytes, self.covers.covered(texture)) {
(Ok(bytes), true) => vec![(0, bytes.len() as u64)],
_ => Vec::new(),
};
dumps::write(&dir, command_buffer, texture, bytes, &whole, None)
.map_err(failed(command_buffer, texture))?;
}
Ok(())
@@ -586,6 +586,9 @@ struct Kept {
per_commit: Counters,
/// The buffers it keeps two copies of, and which one its read takes.
read_copies: HashMap<u64, ReadCopy>,
/// The word it reads first in each part of a texture here, in place of the texture's id; it
/// reads a part as that word, then the part's level, slice and plane.
texels: HashMap<u64, u64>,
}
impl Backend for Kept {
@@ -667,7 +670,8 @@ impl Backend for Kept {
}
fn read_texture_part(&mut self, object: u64, part: Part) -> Result<Vec<u8>, PlayError> {
let words = [object, part.level, part.slice, part.plane];
let first = self.texels.get(&object).copied().unwrap_or(object);
let words = [first, part.level, part.slice, part.plane];
Ok(words.iter().flat_map(|word| word.to_le_bytes()).collect())
}
@@ -3439,6 +3443,84 @@ fn the_dump_compare_reports_a_word_whose_cover_the_buffer_s_last_write_voided()
assert!(!comparison.agrees());
}
/// The dump tests' play of three textures of 0x1000 bytes placed in a heap, into `dir`, their
/// parts read with `texels` ([`Kept::texels`]): #5 and #6 at offset 0, one over the other, and #7
/// at 0x1000, apart. Command buffer #20 dispatches a state that writes texture slot 0 twice: the
/// first time with #5 there, which covers #6, the second with #6, which covers #5 and is written
/// again itself; #7, at slot 1, which the state does not write, is neither.
fn play_covered_textures(dir: &std::path::Path, texels: &[(u64, u64)]) {
let mut kept = Kept::default();
kept.heap_answers.insert(4, (0x1000, 0x1000));
kept.kernel_writes.insert(9, vec![0]);
kept.texels.extend(texels.iter().copied());
let (_, ended) = dumped(&mut kept, dir, |w| {
w.call("MTLCreateSystemDefaultDevice", 0, 1, &[], &[])?;
w.call("newHeapWithDescriptor:", 1, 2, &heap_of(0x1_0000, 1), &[])?;
w.call("m2v.textureDescriptor", 0, 4, &[map(&[])], &[])?;
for (texture, offset) in [(5, 0), (6, 0), (7, 0x1000)] {
let placed = [Value::Object(4), Value::Uint(offset)];
w.call("newTextureWithDescriptor:offset:", 2, texture, &placed, &[])?;
}
w.call("newCommandQueue", 1, 8, &[], &[])?;
w.call("newComputePipelineStateWithFunction:error:", 1, 9, &[], &[])?;
w.call("commandBuffer", 8, 20, &[], &[])?;
w.call("computeCommandEncoder", 20, 21, &[], &[])?;
w.call("setComputePipelineState:", 21, 0, &[Value::Object(9)], &[])?;
let size = map(&[("width", Value::Uint(1)), ("height", Value::Uint(1))]);
let groups = [size.clone(), size];
let dispatch = "dispatchThreadgroups:threadsPerThreadgroup:";
let apart = [Value::Object(7), Value::Uint(1)];
w.call("setTexture:atIndex:", 21, 0, &apart, &[])?;
for written in [5, 6] {
let slot = [Value::Object(written), Value::Uint(0)];
w.call("setTexture:atIndex:", 21, 0, &slot, &[])?;
w.call(dispatch, 21, 0, &groups, &[])?;
}
w.call("endEncoding", 21, 0, &[], &[])?;
w.call("commit", 20, 0, &[], &[])
});
ended.unwrap();
}
/// A texture the cover rule holds covered when its command buffer's dump reads it is covered
/// whole, and the compare leaves it out; one it does not hold covered is compared: in the second
/// play #5 (covered by #6's write after its own) and #7 (apart) read otherwise, each one part of
/// 32 bytes whose first word differs, and only #7 is reported. #6, written last, is alike.
#[test]
fn the_dump_compare_leaves_out_a_covered_texture_and_reports_one_outside_every_cover() {
let (a, b) = (
ScratchDir::new("dumps-a").unwrap(),
ScratchDir::new("dumps-b").unwrap(),
);
play_covered_textures(a.path(), &[]);
play_covered_textures(b.path(), &[(5, 50), (7, 70)]);
let cover = |texture: u64| {
let name = format!("cb20-obj{texture}.cover");
std::fs::read_to_string(a.path().join(name)).unwrap()
};
assert_eq!([cover(5), cover(6), cover(7)], ["0..32", "-", "-"]);
let comparison = compare_dumps(a.path(), b.path()).unwrap();
assert_eq!(comparison.compared, 3);
let differs = |object, covered, first_uncovered| Difference {
command_buffer: 20,
object,
differing: 1,
covered,
first_uncovered,
lengths: (32, 32),
};
assert_eq!(
comparison.differences,
[differs(5, 1, None), differs(7, 0, Some(0))]
);
assert!(!comparison.agrees());
assert_eq!(
comparison.lines()[0],
"differs cb #20 obj #7: 1 words outside every cover, the first word 0; 0 covered; \
lengths 32 and 32"
);
}
/// A listed command buffer's dump holds every buffer its encoders named, whatever made it: a
/// plain buffer, a buffer in a block and a host's padded buffer; and the texture its compute
/// encoder binds, as such a texture
@@ -3502,7 +3584,8 @@ fn a_listed_command_buffer_dumps_every_buffer_it_names_whatever_made_it() {
/// `MTLStoreActionDontCare`), the resolve texture #11's level 1 and slice 2 of multisample #10,
/// not #10 itself (2, `MTLStoreActionMultisampleResolve`), #12's level 1 by the encoder's
/// `setColorStoreAction:atIndex:` (3, `MTLStoreActionUnknown`), and no depth attachment (#13);
/// the second stores #8's level 2 and depth plane 3. A texture's dump covers nothing.
/// the second stores #8's level 2 and depth plane 3. No texture is placed in a heap, so no
/// texture's dump has a cover.
#[test]
fn a_listed_command_buffer_dumps_the_colour_attachments_its_render_passes_store() {
let dir = ScratchDir::new("dumps-stores").unwrap();
+6 -4
View File
@@ -1156,15 +1156,17 @@ encoder's `setColorStoreAction:atIndex:`. `cbC-objT.bin` holds the texture's par
stored, each a level, a slice and a depth plane (`level`, `slice` and `depthPlane`, or the
resolve's; a pass of `renderTargetArrayLength` 2 or more stores that many slices from the slice),
one after another by level, then slice, then plane, each laid out as a check reads a texture's
first level and slice; its `cbC-objT.cover` is `-`, and `cbC-objT.unread` replaces the bytes
where the backend could not read a part (a multisample texture stored without its resolve, for
one). It writes too each texture the command buffer's compute encoders bound
first level and slice; and `cbC-objT.unread` replaces the bytes where the backend could not read
a part (a multisample texture stored without its resolve, for one). It writes too each texture the command buffer's compute encoders bound
(`setTexture:atIndex:` and `setTextures:withRange:`, a nil one left out): its first level and
slice as a part, read once the command buffer completed as an attachment's parts are, so what the
command buffer's last write left there; a texture both stored and bound holds each of its parts
once, in that order. A depth or stencil attachment is not written: a texture of a combined depth and
stencil format reads back one aspect at a time, through a copy with that aspect's blit option,
which this read does not make. `command-replay compare-dumps --a DIR --b DIR` compares two plays' dumps word by word (4 bytes), leaving out a word
which this read does not make. A texture's `cbC-objT.cover` is `0..N`, the whole of its `N`
bytes, where the cover rule (above) held any byte of the texture covered then, and `-` otherwise:
the rule's ranges are the texture's bytes in its heap, which its parts are not laid out as.
`command-replay compare-dumps --a DIR --b DIR` compares two plays' dumps word by word (4 bytes), leaving out a word
wholly inside a range either play held covered, and prints `differs cb #C obj #O: N words outside every cover, the first word
W; M covered; lengths A and B` for each buffer that differs outside every cover, `only in a|b:
cbC-objO` for a dump one play lacks, `unread in a|b: cbC-objO: WHY`, `copies differ: cbC-objO: a