rt test: every device places a block of each class and the ring's nil buffer and zero range at a multiple of 16

What: every_device_of_the_cfgs_kind_opens_presents_and_tears_down_to_zero prints the alignment
Vulkan promises the device's buffer addresses (the largest of the buffers' memory requirements'
alignment, minStorageBufferOffsetAlignment, minUniformBufferOffsetAlignment and
minTexelBufferOffsetAlignment, the floor's usage holding each) and asserts that a Private and a
Shared block's first buffer, and the ring's nil buffer and zero range, lie at multiples of 16.

Why (L84): the ring now starts its chunks on 16 wherever the device places a block, but a block's
buffers take their allocation's address, and the blocks hold images bound at memory offsets beside
buffers reached by address, so no offset can serve both where an allocation's address is off 16.
Metal's offset rule for a device buffer (the offset aligned to its data type, up to 16; Apple's
setBuffer(_:offset:index:) page) asks a base at a multiple of 16. This pins, on every device the
device suites open, that the allocations they make lie on 16, and names the device where one does
not.

How verified: in the hand-over (lavapipe on msi, the Iris on ms01).
This commit is contained in:
Anees Iqbal committed 2026-12-02 06:51:00 -08:00
1 parent 459a50702a
commit a4001735fb
1 file changed
+38 -4
@@ -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!(