Validation test: a texture over a no-copy import asserts the copies of the form the run reports

The test a_bytes_form_no_copy_buffer_is_an_import_and_a_descriptor_form_one_a_pool_buffer
asserted one imported over copy: the copy at use of a texture over host memory's import held in
an image of its own. A texture over host memory's import is now in place on an integrated or CPU
device whose external image query takes a linear image for that handle, its bytes saved and
written back once around its move home, so it counts that restore pair: two imported copies and
none at use. On the 780M (Phoenix, RADV, job m3-max-82442) the test read 2 and failed; its line
was "textures over buffers 2: 2 in place, 0 in an image of their own", with 2048 bytes of
host-memory restore. The product's count is the documented one; the test's expectation was
stale.

The test now reads each texture's form from what the run reports and asserts the copies that
form makes:
- #6, the one texture over an import, is in place where the device counts one texture in place
  over an import (textures_in_place_over_imports). Then it takes the restore pair: two imported
  copies and two host-memory restores of equal bytes, each at least the 784 bytes under the
  texture's rows, and none at use. Else it takes one imported copy of its 64 bytes at use, for
  host memory's cause or a linear-image decline.
- #13, over pool buffer #4, is in place where the textures-over line's in-place count, less #6,
  says so, with no copy. Else it takes one pool-side copy of 64 bytes at use.
- The at-use copies by cause sum to the textures in images of their own.
The test prints each texture's form and, where declined, its cause.

Verified on the fix's first form, the same assertions:
- 780M (Phoenix), m3-max-82451: both in place, #6 by its restore pair (2048 bytes), passed.
- Iris Xe, m3-max-82452: both declined for pitch (the linear image's row pitch or start is not
  the texture's 256), one copy each at use, passed. That is why the Iris read 1 before.
- RTX 2080, m3-max-82453: #6 for host memory (a discrete device), #13 for pitch, passed.

Product code is unchanged.
This commit is contained in:
Anees Iqbal committed 2026-12-02 23:25:26 -08:00
1 parent 28e4da1f17
commit 1a84985dd4
1 file changed
+106 -11
@@ -4748,9 +4748,11 @@ fn a_linear_texture_over_a_buffer_plays_where_2d_and_is_refused_as_an_array() {
}
}
/// A bytes-form no-copy buffer is an import: a texture over it is the runtime's counted copy,
/// which a blit of the texture reads the stream's bytes through, and the imports end with the
/// device. A descriptor-form one is a pool buffer with no import: recorded inside a block's
/// A bytes-form no-copy buffer is an import: a texture over it, which a blit of the texture reads
/// the stream's bytes through, is in place in the import's memory where the device takes it
/// there, its bytes saved and written back once around its move home, and else an image of its
/// own that the runtime copies them into at use; the imports end with the device. A
/// descriptor-form one is a pool buffer with no import: recorded inside a block's
/// recorded range, a buffer of that block, which reads the bytes written into the block there;
/// outside every block, a place of its own, a texture over which reads the stream's bytes and is
/// no copy on the imported side. The gap line counts, of those outside, the pinned ones with no
@@ -4934,15 +4936,108 @@ fn a_bytes_form_no_copy_buffer_is_an_import_and_a_descriptor_form_one_a_pool_buf
as pool buffers, count unknown: at most 1, those outside every block with a \
pinnedGpuAddress and no zeroFrom (4096 bytes in all)";
assert!(lines.iter().any(|line| line == gap), "{lines:?}");
// The texture over the import is held in an image of its own; the one over #4 is in place
// where the device's linear image takes it, and else the runtime's copy of a pool buffer's.
let over = "textures over buffers 2: ";
assert!(lines.iter().any(|line| line.starts_with(over)), "{lines:?}");
// The import's texture's bytes into its image of its own, once, on the imported side; #4's,
// if copied, on the pool side.
// Each texture's form, as the run reports it, and the copies that form makes. #6 is the one
// texture over an imported block, so the device's count of textures in place over an import
// is its form; the line's count of those in place, less #6, is #13's.
let executed = &report.total.executed;
assert_eq!(executed["over_copies_imported"], 1, "{executed:?}");
assert_eq!(executed["over_copy_bytes_imported"], 64, "{executed:?}");
let over = "textures over buffers 2: ";
let made = (lines.iter())
.find_map(|line| line.strip_prefix(over))
.unwrap_or_else(|| panic!("{lines:?}"));
let in_place: u64 = (made.split(' ').next())
.and_then(|count| count.parse().ok())
.unwrap_or_else(|| panic!("{made}"));
let import_in_place = executed["textures_in_place_over_imports"];
assert!(import_in_place <= in_place.min(1), "{made}: {executed:?}");
let pool_in_place = in_place - import_in_place;
// A texture in an image of its own takes one copy, at the blit's use: over the import for
// the cause host memory has, no linear image there (a discrete or virtual device, or an
// external image query that declines the image), or for a cause the device's linear image
// declines it for, as over #4 (another row pitch than 256, a start off its alignment, a
// format or usage its linear tiling lacks, memory it cannot bind).
const DECLINES: [&str; 11] = [
"over_copies_pitch",
"over_copies_alignment",
"over_copies_linear",
"over_copies_linear_features",
"over_copies_render_reach",
"over_copies_image_memory",
"over_copies_spilled",
"over_copies_dedicated",
"over_copies_surface",
"over_copies_dma_buf",
"over_copies_dma_bufs",
];
let host_memory = executed["over_copies_host_memory"];
let declined: Vec<(&str, u64)> = (DECLINES.iter())
.map(|&cause| (&cause["over_copies_".len()..], executed[cause]))
.filter(|&(_, copies)| copies > 0)
.collect();
let declines: u64 = declined.iter().map(|&(_, copies)| copies).sum();
// Where two textures are declined for two causes, the counts do not say whose is whose.
let declined = (declined.iter())
.map(|&(cause, _)| cause)
.collect::<Vec<_>>()
.join(" or ");
let (imported, imported_bytes) = (
executed["over_copies_imported"],
executed["over_copy_bytes_imported"],
);
let restores = executed["over_copies_host_memory_restore"];
let restored = executed["over_copy_bytes_host_memory_restore"];
eprintln!(
"REPLAY no-copy forms: {made}; in place over an import {import_in_place}; over copies \
{} imported {imported} ({imported_bytes} bytes), restore {restores} ({restored} bytes), \
at use host_memory {host_memory}, declined {declines} ({declined})",
executed["over_copies"]
);
assert_eq!(
host_memory + declines,
2 - in_place,
"a copy at use for each texture in an image of its own: {made}: {executed:?}"
);
// #6 in place: on an integrated or CPU device whose external image query takes a linear
// image for host memory, two copies on the imported side, the restore pair, each of the
// bytes under the image (its rows, 3 times 256 and 16 bytes at least), and none at use.
// Else its 64 bytes once, at use, on the imported side.
let import_form = if import_in_place == 1 {
assert_eq!((imported, restores), (2, 2), "{executed:?}");
assert_eq!(imported_bytes, restored, "{executed:?}");
assert!(
restored.is_multiple_of(2) && restored / 2 >= 3 * 256 + 16,
"{executed:?}"
);
format!(
"in place, its bytes saved and written back around its move home, 2 copies, \
{restored} bytes in all, none at use"
)
} else {
assert_eq!(
(imported, imported_bytes, restores),
(1, 64, 0),
"{executed:?}"
);
assert!(host_memory == 1 || declines > 0, "{executed:?}");
let cause: &str = if host_memory == 1 {
"host_memory"
} else {
&declined
};
format!("in an image of its own, 1 copy of 64 bytes at use, cause {cause}")
};
// #13 in place: no copy. Else its 64 bytes once, at use, on the pool side.
let pool = executed["over_copies"] - imported;
let pool_bytes = executed["over_copy_bytes"] - imported_bytes;
let pool_form = if pool_in_place == 1 {
assert_eq!((pool, pool_bytes), (0, 0), "{executed:?}");
"in place, no copy".to_string()
} else {
assert_eq!((pool, pool_bytes), (1, 64), "{executed:?}");
assert!(declines > 0, "{executed:?}");
format!("in an image of its own, 1 copy of 64 bytes at use, cause {declined}")
};
eprintln!("REPLAY no-copy texture #6 over the import: {import_form}");
eprintln!("REPLAY no-copy texture #13 over pool buffer #4: {pool_form}");
let ended = backend.end();
ended.result().unwrap();
assert!(ended.gauges.contains(&("imports", 0)), "{:?}", ended.gauges);