diff --git a/crates/metal2vulkan-validation/src/replay/rt_replay.rs b/crates/metal2vulkan-validation/src/replay/rt_replay.rs index d63d21e59..5a9671620 100644 --- a/crates/metal2vulkan-validation/src/replay/rt_replay.rs +++ b/crates/metal2vulkan-validation/src/replay/rt_replay.rs @@ -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::>() + .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);