dma_buf_beside: a copy over a live import is checked at its commit and completion

`inside` (RUNTIME 2453) checked unconditionally that a fill through the first buffer and a copy
through the second, of the bytes they share, see each other in ONE blit encoder. Where the
driver takes the first buffer's dma-buf import only dedicated to its buffer, as the RTX 5080
Laptop GPU's 615.71.09 does, the second buffer is a copy (HostBacking::Copied, the
copied-host-pages notice). A copy agrees with the pages only at its commit and its completion
(copied.rs, "Coherence"), and Metal orders no two no-copy buffers over one allocation
(host_aliases.rs, "Not joined"). So the test failed at dma_buf_beside.rs:449 on the 5080, both
at 596d917dfe and at 24a0613783 (b5080 entry pinreds-parent-161559). The sibling test over_part
already ran its in-one-encoder checks only where both buffers lie in imports.

Now both orders run in one encoder where the second buffer lies in an import, as before. Where
it is a copy they run in two command buffers, which checks what the copy does promise: the
first's fill is copied in at the next commit, and the second's fill is merged back into the pages
at completion.

Verified: the 5080 run of this commit (named in the tip report).
This commit is contained in:
Anees Iqbal committed 2026-11-16 16:18:34 -08:00
1 parent 8e9c144ccb
commit 9a7e59b1dd
1 file changed
+34 -13
@@ -432,36 +432,57 @@ fn inside(how: &str, device: &Device) {
bytes_of(&out, length) == later[offset..offset + length],
"{TEST} ({how}): the CPU's write before the commit, through the second"
);
// A fill through the first and a copy through the second of the bytes they share, in one
// encoder, either way round.
// A fill through the first and a copy through the second of the bytes they share, either way
// round: in one encoder where the second lies in an import (ordered by the bytes they share),
// in two command buffers where it is a copy, which agrees with the pages at its commit and its
// completion only (Metal orders no two no-copy buffers over one allocation).
let in_import = expected[0].0 == HostBacking::ImportedAsDmaBuf;
let apart = match in_import {
true => "in one encoder",
false => "in two command buffers",
};
let fill_then_read = |fill: &dyn Fn(&mut BlitCommandEncoder),
copy: &dyn Fn(&mut BlitCommandEncoder)| {
if in_import {
blits(
&queue,
|blit| {
fill(blit);
copy(blit);
},
|| {},
);
} else {
blits(&queue, fill, || {});
blits(&queue, copy, || {});
}
};
let shared = 2 * page - 256;
let out = scratch_buffer(device, shared);
blits(
&queue,
|blit| {
fill_then_read(
&|blit| {
blit.fill_buffer(&first, offset as u64..(offset + shared) as u64, 0xa1)
.unwrap();
},
&|blit| {
blit.copy_from_buffer_to_buffer(&second, 0, &out, 0, shared as u64)
.unwrap();
},
|| {},
);
assert!(
bytes_of(&out, shared).iter().all(|&b| b == 0xa1),
"{TEST} ({how}): the first's fill read through the second in one encoder"
"{TEST} ({how}): the first's fill read through the second {apart}"
);
blits(
&queue,
|blit| {
blit.fill_buffer(&second, 0..shared as u64, 0xb2).unwrap();
fill_then_read(
&|blit| blit.fill_buffer(&second, 0..shared as u64, 0xb2).unwrap(),
&|blit| {
blit.copy_from_buffer_to_buffer(&first, offset as u64, &out, 0, shared as u64)
.unwrap();
},
|| {},
);
assert!(
bytes_of(&out, shared).iter().all(|&b| b == 0xb2),
"{TEST} ({how}): the second's fill read through the first in one encoder"
"{TEST} ({how}): the second's fill read through the first {apart}"
);
// The first released, the second's fill still reaches the file's pages, and the third reads
// it where they meet.