From cb3d9131398979e19cdfdba0a67b4a45d4bbc39d Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 25 Nov 2026 15:25:58 -0800 Subject: [PATCH] Runtime tests: the view tests take the floor's choice over the view as their arm, on every device What: tests::floor's a_device_with_no_cached_coherent_type_opens_where_the_floor_chooses_its_types and tests::coherence's view test (renamed from every_gpu_read_as_the_refused_device_... to every_device_opened_under_the_view_flushes_and_invalidates_the_shared_memory_work_reaches) share one helper beside open_each_device, tests::command::on_device::each_device_under_the_view. For each device of the cfg's kind it reads the buffer bits from a device made with no view, takes the floor's choice (floor::choose) over the viewed memory properties, and makes the device through the view: where the choice refuses, the make must refuse with exactly BelowFloor { missing } from that choice, and one line names the device and the refusal; where it chooses, the device must open with the chosen types and the test's body runs on it, settled and with its gauges checked at drop as open_each_device does (its per-device steps are now run_settled, which both use). The floor test's `if cfg!(m2v_cpu_icd)` guard is gone, and the coherence test's #[cfg(m2v_gpu)] with it: both run under every device cfg. The doc comments state the structure: a device whose one host-visible, host-cached buffer type also holds the parameter ring is refused under the view, with its refusal. Why: round efd7dbcd4d-1125-1433, leg mac:rt (job m3-max-74110), KosmicKrisp 26.3.1 on the M3: both tests failed with "below the runtime's floor: it lacks a memory type with DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT for buffers (the device offers buffers: type 0 with DEVICE_LOCAL | HOST_VISIBLE | HOST_CACHED)". That device's one buffer type also holds the parameter ring, as lavapipe's does, so the view leaves no ring type and the floor refuses it, as it should. The floor test took the refusal arm by the device's kind; the coherence test had none. Test-only; the runtime's behaviour is unchanged. docs/VALIDATION.md's m2v_shared_view note checked: nothing in it is false, unchanged. Verified: cargo fmt only; the quick check, the KosmicKrisp rt leg on the M3 and the Iris view leg follow. --- .../src/tests/coherence.rs | 42 ++++---- .../metal2vulkan-runtime/src/tests/command.rs | 100 ++++++++++++++---- .../metal2vulkan-runtime/src/tests/floor.rs | 78 +++++--------- 3 files changed, 128 insertions(+), 92 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/coherence.rs b/crates/metal2vulkan-runtime/src/tests/coherence.rs index c9fb5fd04..25b316327 100644 --- a/crates/metal2vulkan-runtime/src/tests/coherence.rs +++ b/crates/metal2vulkan-runtime/src/tests/coherence.rs @@ -1,19 +1,21 @@ //! Shared memory's coherence (`crate::coherence`). Under a device cfg, on every device of the //! cfg's kind: the device holds a coherence state exactly where its Shared type, as it reads it, //! is not host-coherent, and makes no flush or invalidate where it holds none. Where it holds one -//! (every GPU read through the refused device's view, `crate::tests::cached_types_incoherent`): -//! the zero source is flushed at its make; a fill into a Shared buffer is flushed over the -//! buffer's atoms before its submission, then flushed and invalidated there before its status -//! reads completed, and its bytes are the fill's; a fill into a Private buffer makes no call; the -//! bytes a texture's `replace_region` stages are flushed once, and those its `get_bytes` reads -//! flushed and invalidated once. Each call is counted with its bytes, and none fails. +//! (every device the floor opens through the refused device's view, +//! `crate::tests::cached_types_incoherent`): the zero source is flushed at its make; a fill into a +//! Shared buffer is flushed over the buffer's atoms before its submission, then flushed and +//! invalidated there before its status reads completed, and its bytes are the fill's; a fill into +//! a Private buffer makes no call; the bytes a texture's `replace_region` stages are flushed once, +//! and those its `get_bytes` reads flushed and invalidated once. Each call is counted with its +//! bytes, and none fails. A device whose one host-visible, host-cached buffer type also holds the +//! parameter ring is refused under the view, with its refusal. #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod on_device { use crate::tests::blit::on_device::settled; - #[cfg(m2v_gpu)] - use crate::tests::command::on_device::each_device_with; - use crate::tests::command::on_device::{finished, on_each_device, within}; + use crate::tests::command::on_device::{ + each_device_under_the_view, finished, on_each_device, within, + }; use crate::{ CommandBuffer, CommandQueue, Device, HostBytes, MemoryClass, Metrics, PixelFormat, Region, TextureDescriptor, TextureType, @@ -206,20 +208,16 @@ mod on_device { }); } - /// Every GPU of the cfg's kind, read through the refused device's view - /// (`crate::tests::cached_types_incoherent`): its Shared type is cached and not coherent, so - /// it holds the coherence state and makes the calls, on memory that is coherent in fact. - /// Lavapipe's one memory type holds the parameter ring too, which the view leaves with no - /// coherent type, so the floor refuses it there (`tests::floor`). - #[cfg(m2v_gpu)] + /// Every device of the cfg's kind, read through the refused device's view + /// (`crate::tests::cached_types_incoherent`), decided by the floor's choice over the view + /// (`each_device_under_the_view`). A device the choice opens has a Shared type that is cached + /// and not coherent, so it holds the coherence state and makes the calls, on memory that is + /// coherent in fact. A device whose one host-visible, host-cached buffer type also holds the + /// parameter ring is left with no coherent type for the ring, so the floor refuses it under + /// the view, with that choice's refusal, which is printed. #[test] - fn every_gpu_read_as_the_refused_device_flushes_and_invalidates_the_shared_memory_work_reaches() - { - let view = || crate::DeviceOptions { - memory: Some(crate::tests::cached_types_incoherent), - ..crate::DeviceOptions::default() - }; - each_device_with("coherence", view, |name, _, device| { + fn every_device_opened_under_the_view_flushes_and_invalidates_the_shared_memory_work_reaches() { + each_device_under_the_view("coherence", |name, _, device, _| { let atom = (device.core().coherence.as_ref()).map(|coherence| coherence.atom); assert!(atom.is_some(), "{name}: the view built the coherence state"); calls_of_the_work(name, &device, atom); diff --git a/crates/metal2vulkan-runtime/src/tests/command.rs b/crates/metal2vulkan-runtime/src/tests/command.rs index 59533f221..79e0d3b48 100644 --- a/crates/metal2vulkan-runtime/src/tests/command.rs +++ b/crates/metal2vulkan-runtime/src/tests/command.rs @@ -141,8 +141,9 @@ fn a_push_of_the_bytes_a_command_buffer_holds_records_nothing() { pub(crate) mod on_device { use crate::buffer::BufferObject; use crate::device::lock; + use crate::floor::{buffer_memory_bits, choose, BelowFloor}; use crate::submit::{GROUP_RUN, IN_FLIGHT, UNSEEN_JOINS}; - use crate::tests::devices_of_the_cfgs_kind; + use crate::tests::{cached_types_incoherent, devices_of_the_cfgs_kind}; use crate::{ host_time, AllocationId, AllocationInfo, Block, BlockMappings, Buffer, CommandBuffer, CommandBufferError, CommandBufferStatus, CommandQueue, Device, DeviceLoss, DeviceOptions, @@ -261,26 +262,89 @@ pub(crate) mod on_device { for (name, physical) in &devices { let device = Device::new(physical, options()).unwrap_or_else(|error| panic!("{name}: {error}")); - // The block-maker thread's first work done, so a body's counts start from a device - // that holds its fixed-size internals. - device.core().pool.await_internals(); - // And the reaper's first work: the seed makes the pipeline cache and sets - // `pipeline_cache_bytes` (`Caches::seed`), after `Device::new` returns, so a body that - // compares the gauges across its work starts from settled ones. - within("the seed", || device.core().caches.is_seeded()); - let counters = device.counters(); - body(name, instance, device); - within("the teardown", || counters.gauges() == Gauges::default()); - print_gauges_at_drop(test, counters.gauges()); - // The matrix holds these at 0 (`readback::timestamps`, the completion thread's wait). - let metrics = counters.metrics(); - let unavailable = metrics.stamps_not_available; - println!("M2V-MATRIX metric {test}/stamps_not_available {unavailable}"); - let behind = metrics.waits_behind_counter; - println!("M2V-MATRIX metric {test}/waits_behind_counter {behind}"); + run_settled(test, instance, name, device, &mut body); } } + /// Each device of the cfg's kind, read through the memory view of the refused device's shape + /// ([`cached_types_incoherent`]), decided by the floor's choice over the view + /// (`floor::choose`), with the buffer bits a device made with no view answers. Where the + /// choice refuses, as it does a device whose one host-visible, host-cached buffer type also + /// holds the parameter ring, the device's make through the view is refused with exactly that + /// choice's refusal, which is printed. Where it chooses, the device opens through the view + /// with the chosen types and `body` runs on it as in [`each_device_with`], given the viewed + /// memory properties. + pub(crate) fn each_device_under_the_view( + test: &str, + mut body: impl FnMut(&str, &Instance, Device, &vk::PhysicalDeviceMemoryProperties), + ) { + let instance = crate::tests::validation::instance(&[]); + let (_, vk_instance) = instance.raw(); + let devices = devices_of_the_cfgs_kind(&instance); + assert!(!devices.is_empty(), "no device of this cfg's kind"); + for (name, physical) in &devices { + let device = Device::new(physical, DeviceOptions::default()) + .unwrap_or_else(|error| panic!("{name}: {error}")); + // SAFETY: the device is live, made with the floor's features. + let usable = unsafe { buffer_memory_bits(device.raw().device) }; + drop(device); + // SAFETY: `physical` is one of the instance's. + let mut memory = + unsafe { vk_instance.get_physical_device_memory_properties(physical.raw()) }; + cached_types_incoherent(&mut memory); + let view = DeviceOptions { + memory: Some(cached_types_incoherent), + ..DeviceOptions::default() + }; + match (choose(&memory, usable), Device::new(physical, view)) { + (Ok(types), Ok(device)) => { + assert_eq!(device.memory_types(), types, "{name}"); + run_settled(test, &instance, name, device, |name, instance, device| { + body(name, instance, device, &memory) + }); + } + (Err(missing), Err(Error::BelowFloor(below))) => { + assert_eq!(below, BelowFloor { missing }, "{name}"); + println!( + "{test}: {name} under the view: {}", + Error::BelowFloor(below) + ); + } + (chosen, Err(error)) => panic!("{name}: {error}, where the floor chose {chosen:?}"), + (chosen, Ok(_)) => panic!("{name}: made, where the floor chose {chosen:?}"), + } + } + } + + /// Runs `body` on `device` of `instance`, just made, once the block-maker thread's first work + /// and the reaper's are done, then checks that every gauge reaches zero once `body` has + /// dropped it, and prints the matrix's records. + fn run_settled( + test: &str, + instance: &Instance, + name: &str, + device: Device, + body: impl FnOnce(&str, &Instance, Device), + ) { + // The block-maker thread's first work done, so a body's counts start from a device that + // holds its fixed-size internals. + device.core().pool.await_internals(); + // And the reaper's first work: the seed makes the pipeline cache and sets + // `pipeline_cache_bytes` (`Caches::seed`), after `Device::new` returns, so a body that + // compares the gauges across its work starts from settled ones. + within("the seed", || device.core().caches.is_seeded()); + let counters = device.counters(); + body(name, instance, device); + within("the teardown", || counters.gauges() == Gauges::default()); + print_gauges_at_drop(test, counters.gauges()); + // The matrix holds these at 0 (`readback::timestamps`, the completion thread's wait). + let metrics = counters.metrics(); + let unavailable = metrics.stamps_not_available; + println!("M2V-MATRIX metric {test}/stamps_not_available {unavailable}"); + let behind = metrics.waits_behind_counter; + println!("M2V-MATRIX metric {test}/waits_behind_counter {behind}"); + } + /// Buffers of 256 bytes in one Shared block, each zeroed. pub(crate) struct Arena { device: Device, diff --git a/crates/metal2vulkan-runtime/src/tests/floor.rs b/crates/metal2vulkan-runtime/src/tests/floor.rs index 3ff5e4425..583753197 100644 --- a/crates/metal2vulkan-runtime/src/tests/floor.rs +++ b/crates/metal2vulkan-runtime/src/tests/floor.rs @@ -2474,62 +2474,36 @@ fn every_device_the_loader_lists_is_above_the_floor() { /// Every device of the cfg's kind, read through the memory view of the refused device's shape /// ([`cached_types_incoherent`](crate::tests::cached_types_incoherent)), answers at its make as /// the floor's choice over the view does, with the buffer bits a device made with no view first -/// answers. Every GPU opens: Shared takes the first cached type, which the view left not -/// coherent, and the device holds the coherence state (`crate::coherence`). A device the choice -/// refuses is refused with its refusal, which names the flags each missing type needs and the -/// types the device offers a buffer, with the view's flags: lavapipe, whose one type holds the -/// parameter ring too and is left with no coherent type. +/// answers (`each_device_under_the_view`). A device the choice opens has the chosen types: Shared +/// takes the first cached type, which the view left not coherent, and the device holds the +/// coherence state (`crate::coherence`). A device whose one host-visible, host-cached buffer type +/// also holds the parameter ring is left with no coherent type for the ring, so the choice refuses +/// it, and its make is refused with exactly that refusal, which names the flags each missing type +/// needs and the types the device offers a buffer, with the view's flags. #[cfg(any(m2v_gpu, m2v_cpu_icd))] #[test] fn a_device_with_no_cached_coherent_type_opens_where_the_floor_chooses_its_types() { - use crate::tests::cached_types_incoherent; - use crate::{Device, DeviceOptions, Error}; + use crate::tests::command::on_device::each_device_under_the_view; - let runtime = crate::tests::validation::instance(&[]); - let (_, vk_instance) = runtime.raw(); - for (name, physical) in crate::tests::devices_of_the_cfgs_kind(&runtime) { - let device = Device::new(&physical, DeviceOptions::default()) - .unwrap_or_else(|error| panic!("{name}: {error}")); - // SAFETY: the device is live, made with the floor's features. - let usable = unsafe { crate::floor::buffer_memory_bits(device.raw().device) }; - drop(device); - // SAFETY: `physical` is one of the instance's. - let mut memory = - unsafe { vk_instance.get_physical_device_memory_properties(physical.raw()) }; - cached_types_incoherent(&mut memory); - let options = DeviceOptions { - memory: Some(cached_types_incoherent), - ..DeviceOptions::default() - }; - match (choose(&memory, usable), Device::new(&physical, options)) { - (Ok(types), Ok(device)) => { - assert_eq!(device.memory_types(), types, "{name}"); - let shared = memory.memory_types_as_slice()[types.shared as usize]; - assert!( - !(shared.property_flags).contains(vk::MemoryPropertyFlags::HOST_COHERENT), - "{name}: the view left Shared's type {} coherent", - types.shared - ); - assert!( - device.core().coherence.is_some(), - "{name}: the coherence state" - ); - println!( - "floor: {name} under the view opens: Shared memory type {} with {}, the \ - coherence state built", - types.shared, - flag_names(shared.property_flags) - ); - } - // A GPU refused under the view fails below, with its refusal. - (Err(missing), Err(Error::BelowFloor(below))) if cfg!(m2v_cpu_icd) => { - assert_eq!(below, BelowFloor { missing }, "{name}"); - println!("floor: {name} under the view: {}", Error::BelowFloor(below)); - } - (chosen, Err(error)) => panic!("{name}: {error}, where the floor chose {chosen:?}"), - (chosen, Ok(_)) => panic!("{name}: made, where the floor chose {chosen:?}"), - } - } + each_device_under_the_view("floor", |name, _, device, memory| { + let types = device.memory_types(); + let shared = memory.memory_types_as_slice()[types.shared as usize]; + assert!( + !(shared.property_flags).contains(vk::MemoryPropertyFlags::HOST_COHERENT), + "{name}: the view left Shared's type {} coherent", + types.shared + ); + assert!( + device.core().coherence.is_some(), + "{name}: the coherence state" + ); + println!( + "floor: {name} under the view opens: Shared memory type {} with {}, the coherence \ + state built", + types.shared, + flag_names(shared.property_flags) + ); + }); } /// A device that does not calibrate the host clock's time domain with its own is below the floor,