From 19553ba3bce0b378fdfd2f696f79ed9bccd0c123 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sat, 7 Nov 2026 23:56:46 -0800 Subject: [PATCH] Bound a placement query's cost in the device test: images made, none bound, nothing submitted The pitch test now asks every case once before any texture is made and reads the process's ObjectChurn and the device's queue_submissions across the query: no vkBindImageMemory, no submission, no more vkDestroyImage than vkCreateImage (a creation the driver refuses is counted and has nothing to release), and one or two vkCreateImage calls where the answer is InPlace. Printed per case. Verified: the pitch test itself passed on the M3 (m3-max-7464, 6 of 8 pitches refused, each query matching the making) and failed with the route's answer ignored (m3-max-7468: 272 bytes asked InPlace, made Refused(Pitch)); the cost check runs in the potluck runs that follow. (cherry picked from commit 5cc6e0a175034b81ce1a37debf2b480b20890743) --- .../src/tests/texture_placement_device.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/crates/metal2vulkan-runtime/src/tests/texture_placement_device.rs b/crates/metal2vulkan-runtime/src/tests/texture_placement_device.rs index 3de65050e..18340b23c 100644 --- a/crates/metal2vulkan-runtime/src/tests/texture_placement_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/texture_placement_device.rs @@ -27,6 +27,9 @@ //! counted in `host_texture_shadows_refused_pitch`. At least one is: 272 bytes, 16 past a //! 256-byte row, is a pitch no driver measured lays rows at (llvmpipe's linear images step by //! 64 bytes, MoltenVK lays them at their own pitch alone, RADV's modifier images step by 256). +//! Each answer, asked before any texture is made, costs one or two `vkCreateImage` calls where +//! it is `InPlace` (more where refused, a pair per wider plan the making tries), no +//! `vkBindImageMemory` and no submission (`ObjectChurn`, `WorkCounts::queue_submissions`). //! //! A device test: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`, //! `m2v_cpu_icd`), on the kind of device the cfg selects. Printed (`TEXTURE-PLACEMENT`): each @@ -539,6 +542,40 @@ fn a_pitch_the_device_lays_no_image_at_answers_its_shadow() { ((3664, 16), renders, 14672), ((3664, 16), renders, 14848), ]; + // Each answer's cost, asked before any texture is made: the images the query made (a call the + // driver refuses is counted made and has nothing to release), none bound, nothing submitted. + for (at, &(size, usage, bytes_per_row)) in cases.iter().enumerate() { + let shaped = descriptor(PixelFormat::BGRA8Unorm, size, usage, options); + let offset = at as u64 * (256 << 10); + let case = format!("{}x{} at {bytes_per_row} bytes a row", size.0, size.1); + let before = device.work_counts(); + let answer = buffer + .texture_placement(&shaped, offset, bytes_per_row) + .unwrap(); + let after = device.work_counts(); + let delta = |of: fn(&WorkCounts) -> u64| of(&after) - of(&before); + let made = delta(|c| c.object_churn.vk_images_made); + let released = delta(|c| c.object_churn.vk_images_destroyed); + assert!( + released <= made, + "{case}: {released} released of {made} made" + ); + let bound = delta(|c| c.object_churn.vk_image_bindings); + assert_eq!(bound, 0, "{case}: the query bound an image"); + let submitted = delta(|c| c.queue_submissions); + assert_eq!(submitted, 0, "{case}: the query submitted work"); + if answer == TexturePlacement::InPlace { + assert!( + (1..=2).contains(&made), + "{case}: {made} images made for an image in place" + ); + } + eprintln!( + "TEXTURE-PLACEMENT on {}: {case}: asked {answer:?}: {made} vkCreateImage, {released} \ + vkDestroyImage, none bound, nothing submitted", + device.name() + ); + } let mut refused = 0; for (at, &(size, usage, bytes_per_row)) in cases.iter().enumerate() { let shaped = descriptor(PixelFormat::BGRA8Unorm, size, usage, options);