diff --git a/crates/metal2vulkan-runtime/src/tests/device.rs b/crates/metal2vulkan-runtime/src/tests/device.rs index 8d9a1eb60..d7b2a7b4b 100644 --- a/crates/metal2vulkan-runtime/src/tests/device.rs +++ b/crates/metal2vulkan-runtime/src/tests/device.rs @@ -1,7 +1,8 @@ //! The instance, the device and its counters: that the handles cross threads, that an object's //! handle is two words, and, under a device cfg, that every device of the cfg's kind opens, -//! presents on the queue its family offers, is torn down with its gauges at zero, and enables the -//! consumer's extensions and features it offers. +//! presents on the queue its family offers, places its blocks and the ring's chunks at multiples +//! of 16, is torn down with its gauges at zero, and enables the consumer's extensions and features +//! it offers. use crate::{ BlockId, BlockInfo, BlockMappings, Buffer, CommandBuffer, CommandBufferError, @@ -55,8 +56,9 @@ fn new_counters_read_zero_from_every_clone() { /// Every device of the cfg's kind the loader lists opens (CPU devices under `m2v_cpu_icd`, the /// others under `m2v_gpu`; the legs pick one with `VK_DRIVER_FILES` and `MESA_VK_DEVICE_SELECT`). -/// Its queue family does graphics and compute, and its memory types have the flags the floor asks -/// of each; the presenting queue is the family's second queue where it has one and the runtime's +/// Its queue family does graphics and compute, its memory types have the flags the floor asks of +/// each, and a block of each class and the ring's nil buffer and zero range lie at multiples of 16 +/// in the device address space; the presenting queue is the family's second queue where it has one and the runtime's /// own where it has one, and it runs a submission from another thread. Dropped before its instance /// or after, the device is torn down with every gauge at zero. #[cfg(any(m2v_gpu, m2v_cpu_icd))] @@ -155,6 +157,38 @@ fn every_device_of_the_cfgs_kind_opens_presents_and_tears_down_to_zero() { "{name}: buffer alignment {alignment}" ); println!("{name}: buffer alignment {alignment}"); + // Vulkan places a buffer's address at a multiple of the largest of its memory + // requirements' alignment and its usages' offset alignments (`vkGetBufferDeviceAddress`), + // which may be below 16. The ring starts its chunks on 16 wherever that is + // (`crate::ring::chunk_starts`); a block's buffers take its allocation's address, where + // Metal's offset rule (a device buffer's offset aligned to its type, up to 16) asks a base + // at a multiple of 16. Every device the tests open places a block of each class, and the + // ring's nil buffer and zero range, at one. + let limits = &properties.limits; + let promised = [ + alignment, + limits.min_storage_buffer_offset_alignment, + limits.min_uniform_buffer_offset_alignment, + limits.min_texel_buffer_offset_alignment, + ] + .into_iter() + .max() + .unwrap_or(1); + println!("{name}: buffer addresses at a multiple of {promised}, as Vulkan promises"); + for class in [crate::MemoryClass::Private, crate::MemoryClass::Shared] { + let block = (device.take_block(class, 64 << 10)) + .unwrap_or_else(|error| panic!("{name}: {class:?}: {error}")); + let buffer = (device.new_buffer(block.id, 0, 16, None)) + .unwrap_or_else(|error| panic!("{name}: {class:?}: {error}")); + let address = buffer.gpu_address(); + assert_eq!(address % 16, 0, "{name}: a {class:?} block at {address:#x}"); + } + let core = device.core(); + for (what, address) in [("nil", core.ring.nil(core)), ("zero", core.ring.zero(core))] { + let address = + address.unwrap_or_else(|error| panic!("{name}: the ring's {what}: {error}")); + assert_eq!(address % 16, 0, "{name}: the ring's {what} at {address:#x}"); + } assert_eq!( device.has_unified_memory(), matches!(