rt: the floor asks the created device for support of the runtime's set layouts

vkGetDescriptorSetLayoutSupport is Vulkan's answer to whether a set layout can be made; the
limits the floor checks do not promise it. MoltenVK 1.4.2 on an M3 Max reports set 1's layout
(65,536 sampled images, 4,096 storage images, three arrays of 4,000 samplers, update after bind)
unsupported, and the validation layer then names VUID-vkCreateDescriptorSetLayout-support-09582
at device creation (probe job m3-max-43634).

Arrays::make asks it for the empty set 0 and for set 1 before making either; an unsupported one
refuses the device with Error::BelowFloor and the new Missing::SetLayout { set }. Vulkan answers
it only for a created device, so PhysicalDevice::check cannot. Set 1's layout is built in one
place, with_arrays_layout, for the query and the creation.

Tests: every_device_supports_the_runtimes_set_layouts (each device of the cfg's kind supports
both), a_set_layout_the_device_does_not_support_is_named. README floor section, REFUSALS.md and
api_signatures.tsv regenerated.
This commit is contained in:
Anees Iqbal committed 2026-11-17 18:52:30 -08:00
1 parent 088f8bb61c
commit 594b86d1f2
7 files changed
+129 -31

No files matched your search

+6 -2
View File
@@ -727,8 +727,12 @@ below, of the instance and of every device. `PhysicalDevice::check` decides for
device, with no unsafe call: it returns what the device offers above the floor
(`floor::Capabilities`), or `floor::BelowFloor`, a typed refusal that names every item the device
lacks (`floor::Missing`: the version, an extension, a feature, a limit, the queue family, a
memory type or a time domain). `Device::new` makes the last choice, of memory types, on the
created device.
memory type, a time domain or a set layout). `Device::new` makes the last choice, of memory
types, on the created device, and asks the last item there: that the device supports both of the
runtime's descriptor set layouts, the empty set 0 and set 1 of the arrays
(`vkGetDescriptorSetLayoutSupport`, which Vulkan answers only for a created device; the limits
alone do not promise it). A device that does not is refused with `Error::BelowFloor`,
`Missing::SetLayout`.
### Extensions
+59 -19
View File
@@ -26,7 +26,7 @@
use crate::counters::{Counters, Gauge};
use crate::device::lock;
use crate::error::{Error, Limit, Refusal};
use crate::floor::{SAMPLED_IMAGES, SAMPLERS, SAMPLER_ARRAYS, STORAGE_IMAGES};
use crate::floor::{BelowFloor, Missing, SAMPLED_IMAGES, SAMPLERS, SAMPLER_ARRAYS, STORAGE_IMAGES};
use crate::Device;
use ash::vk;
use std::ops::Range;
@@ -437,29 +437,21 @@ impl Made {
unsafe fn make(&mut self, device: &ash::Device, counters: &Counters) -> Result<Arrays, Error> {
let empty = vk::DescriptorSetLayoutCreateInfo::default();
// SAFETY: the device is live.
unsafe { supported(device, &empty, 0) }?;
// SAFETY: the device is live.
let empty = unsafe { device.create_descriptor_set_layout(&empty, None) }
.map_err(Error::vulkan("vkCreateDescriptorSetLayout"))?;
self.empty = Some(empty);
let bindings = BINDINGS.map(|(binding, ty, count)| {
vk::DescriptorSetLayoutBinding::default()
.binding(binding)
.descriptor_type(ty)
.descriptor_count(count)
.stage_flags(vk::ShaderStageFlags::ALL)
});
let flags = [vk::DescriptorBindingFlags::PARTIALLY_BOUND
| vk::DescriptorBindingFlags::UPDATE_AFTER_BIND
| vk::DescriptorBindingFlags::UPDATE_UNUSED_WHILE_PENDING; 5];
let mut binding_flags =
vk::DescriptorSetLayoutBindingFlagsCreateInfo::default().binding_flags(&flags);
let info = vk::DescriptorSetLayoutCreateInfo::default()
.flags(vk::DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL)
.bindings(&bindings)
.push_next(&mut binding_flags);
// SAFETY: the device is live, with the update-after-bind features of each binding's type
// (the floor's).
let layout = unsafe { device.create_descriptor_set_layout(&info, None) }
.map_err(Error::vulkan("vkCreateDescriptorSetLayout"))?;
let layout = unsafe {
with_arrays_layout(BINDINGS.map(|(_, _, count)| count), |info| {
supported(device, info, 1)?;
device
.create_descriptor_set_layout(info, None)
.map_err(Error::vulkan("vkCreateDescriptorSetLayout"))
})
}?;
self.layout = Some(layout);
let sizes = [
vk::DescriptorPoolSize {
@@ -543,6 +535,54 @@ impl Made {
}
}
/// Runs `f` with set 1's layout, `counts` elements in each binding of [`BINDINGS`].
pub(crate) fn with_arrays_layout<R>(
counts: [u32; 5],
f: impl FnOnce(&vk::DescriptorSetLayoutCreateInfo) -> R,
) -> R {
let bindings = std::array::from_fn::<_, 5, _>(|index| {
let (binding, ty, _) = BINDINGS[index];
vk::DescriptorSetLayoutBinding::default()
.binding(binding)
.descriptor_type(ty)
.descriptor_count(counts[index])
.stage_flags(vk::ShaderStageFlags::ALL)
});
let flags = [vk::DescriptorBindingFlags::PARTIALLY_BOUND
| vk::DescriptorBindingFlags::UPDATE_AFTER_BIND
| vk::DescriptorBindingFlags::UPDATE_UNUSED_WHILE_PENDING; 5];
let mut binding_flags =
vk::DescriptorSetLayoutBindingFlagsCreateInfo::default().binding_flags(&flags);
let info = vk::DescriptorSetLayoutCreateInfo::default()
.flags(vk::DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL)
.bindings(&bindings)
.push_next(&mut binding_flags);
f(&info)
}
/// The floor's last item, asked of the created device: the device supports the layout `info` of
/// set `set` (`vkGetDescriptorSetLayoutSupport`), which the limits alone do not promise. Else the
/// device is below the floor, [`Missing::SetLayout`].
///
/// # Safety
///
/// `device` is live, with the features `info` needs.
pub(crate) unsafe fn supported(
device: &ash::Device,
info: &vk::DescriptorSetLayoutCreateInfo,
set: u32,
) -> Result<(), Error> {
let mut support = vk::DescriptorSetLayoutSupport::default();
// SAFETY: the caller's contract.
unsafe { device.get_descriptor_set_layout_support(info, &mut support) };
match support.supported == vk::TRUE {
true => Ok(()),
false => Err(Error::BelowFloor(BelowFloor {
missing: vec![Missing::SetLayout { set }],
})),
}
}
/// Writes every element of `set` its default: a null descriptor in each texture array, `plain`
/// in the plain and integer-texture sampler arrays and `compare` in the comparison array.
///
+14 -1
View File
@@ -399,6 +399,14 @@ pub enum Missing {
/// A time domain of [`TIME_DOMAINS`] the device does not calibrate
/// (`vkGetPhysicalDeviceCalibrateableTimeDomainsEXT`), as Vulkan names it.
TimeDomain(&'static str),
/// The layout of one of the runtime's descriptor sets, `set` 0 (empty) or 1 (the texture and
/// sampler arrays), which `vkGetDescriptorSetLayoutSupport` reports unsupported. Vulkan
/// answers it only for a created device, so `Device::new` asks it, and
/// `PhysicalDevice::check` cannot.
SetLayout {
/// The set.
set: u32,
},
}
impl fmt::Display for Missing {
@@ -421,6 +429,10 @@ impl fmt::Display for Missing {
Missing::QueueFamily => f.write_str("a queue family with graphics and compute"),
Missing::MemoryType { flags } => write!(f, "a memory type with {flags} for buffers"),
Missing::TimeDomain(name) => write!(f, "the calibrateable time domain {name}"),
Missing::SetLayout { set } => write!(
f,
"support for descriptor set {set}'s layout (vkGetDescriptorSetLayoutSupport)"
),
}
}
}
@@ -432,7 +444,8 @@ impl fmt::Display for Missing {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BelowFloor {
/// Each item the device lacks, in the floor's order: the version, extensions, features,
/// limits, the queue family, memory types, then time domains.
/// limits, the queue family, memory types, then time domains; or, from `Device::new`, a set
/// layout.
pub missing: Vec<Missing>,
}
+31 -2
View File
@@ -8,7 +8,8 @@
//! - Under a device cfg, on every device of the cfg's kind, the device writes every element of
//! set 1 its default at creation, and holds two `VkSampler`s for it; grants work through the
//! device; `Device::new`, and making and destroying a second set 1, are timed and reported,
//! and the second set's two samplers are gone after it.
//! and the second set's two samplers are gone after it; every device supports both of the
//! runtime's set layouts, which `Device::new` asks before it makes them.
use crate::arrays::Grants;
use crate::error::{Error, Limit, Refusal};
@@ -107,11 +108,39 @@ fn an_index_has_one_grant_at_a_time() {
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod on_device {
use super::refusal;
use crate::arrays::Arrays;
use crate::arrays::{supported, with_arrays_layout, Arrays, BINDINGS};
use crate::tests::devices_of_the_cfgs_kind;
use crate::{Device, DeviceOptions, IndexClass, Instance, Refusal};
use ash::vk;
use std::time::Instant;
/// The floor's last item, asked of the created device: every device of the cfg's kind
/// supports both of the runtime's set layouts (`vkGetDescriptorSetLayoutSupport`), the empty
/// set 0 and set 1 of the arrays, which `Device::new` asks before it makes them.
#[test]
fn every_device_supports_the_runtimes_set_layouts() {
let instance = Instance::new(&[]).expect("an instance at the floor");
let devices = devices_of_the_cfgs_kind(&instance);
assert!(
!devices.is_empty(),
"the loader lists 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}"));
let raw = &device.core().device;
let empty = vk::DescriptorSetLayoutCreateInfo::default();
// SAFETY: the device is live, with the floor's features.
unsafe { supported(raw, &empty, 0) }.unwrap_or_else(|error| panic!("{name}: {error}"));
with_arrays_layout(BINDINGS.map(|(_, _, count)| count), |info| {
// SAFETY: the device is live, with the floor's features.
unsafe { supported(raw, info, 1) }
})
.unwrap_or_else(|error| panic!("{name}: {error}"));
println!("floor: {name}: set layouts 0 and 1 supported");
}
}
/// Set 1 is made with the device: its two default samplers are live while it is, grants
/// work through it, and making a second set 1 with every element written is timed.
#[test]
@@ -853,6 +853,15 @@ fn the_translator_sees_the_portability_subset_device_creation_enables() {
.contains(&VkFeature::ImageViewFormatSwizzle));
}
/// A set layout the created device does not support is named by its set.
#[test]
fn a_set_layout_the_device_does_not_support_is_named() {
assert_eq!(
Missing::SetLayout { set: 1 }.to_string(),
"support for descriptor set 1's layout (vkGetDescriptorSetLayoutSupport)"
);
}
#[test]
fn the_optional_features_decide_the_capabilities() {
type Set = fn(&mut Features);
+6 -5
View File
@@ -2234,12 +2234,12 @@ field metal2vulkan-rt::BlockInfo.device_local pub device_local: bool
field metal2vulkan-rt::BlockInfo.gpu_address pub gpu_address: u64
field metal2vulkan-rt::BlockInfo.id pub id: BlockId
field metal2vulkan-rt::BlockInfo.len pub len: u64
field metal2vulkan-rt::BytesPlace.bytes_per_image pub bytes_per_image: u64
field metal2vulkan-rt::BytesPlace.bytes_per_row pub bytes_per_row: u64
field metal2vulkan-rt::BytesPlace.offset pub offset: u64
field metal2vulkan-rt::BufferLayout.bytes_per_image pub bytes_per_image: u64
field metal2vulkan-rt::BufferLayout.bytes_per_row pub bytes_per_row: u64
field metal2vulkan-rt::BufferLayout.offset pub offset: u64
field metal2vulkan-rt::BytesPlace.bytes_per_image pub bytes_per_image: u64
field metal2vulkan-rt::BytesPlace.bytes_per_row pub bytes_per_row: u64
field metal2vulkan-rt::BytesPlace.offset pub offset: u64
field metal2vulkan-rt::ComputePipelineDescriptor.buffers pub buffers: BTreeMap<u32, metal::Mutability>
field metal2vulkan-rt::ComputePipelineDescriptor.kernel pub kernel: StageSource
field metal2vulkan-rt::ComputePipelineDescriptor.max_call_stack_depth pub max_call_stack_depth: u32
@@ -11386,8 +11386,8 @@ struct metal2vulkan-rt::BlitCommandEncoder pub struct BlitCommandEncoder
struct metal2vulkan-rt::BlockId #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct BlockId(u32)
struct metal2vulkan-rt::BlockInfo #[derive(Clone, Copy, Debug)] #[non_exhaustive] pub struct BlockInfo
struct metal2vulkan-rt::Buffer #[derive(Clone)] pub struct Buffer
struct metal2vulkan-rt::BytesPlace #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct BytesPlace
struct metal2vulkan-rt::BufferLayout #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct BufferLayout
struct metal2vulkan-rt::BytesPlace #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct BytesPlace
struct metal2vulkan-rt::CommandBuffer #[derive(Clone)] pub struct CommandBuffer
struct metal2vulkan-rt::CommandQueue #[derive(Clone)] pub struct CommandQueue
struct metal2vulkan-rt::ComputeCommandEncoder pub struct ComputeCommandEncoder
@@ -13424,8 +13424,8 @@ variant metal2vulkan-rt::Refusal::BufferTooLong BufferTooLong { length: u64, max
variant metal2vulkan-rt::Refusal::Committed Committed
variant metal2vulkan-rt::Refusal::EmptyBuffer EmptyBuffer
variant metal2vulkan-rt::Refusal::EncoderOpen EncoderOpen
variant metal2vulkan-rt::Refusal::HeapTexturePlace HeapTexturePlace { offset: u64, size: u64, align: u64, heap_len: u64 }
variant metal2vulkan-rt::Refusal::FillRange FillRange { start: u64, end: u64, len: u64 }
variant metal2vulkan-rt::Refusal::HeapTexturePlace HeapTexturePlace { offset: u64, size: u64, align: u64, heap_len: u64 }
variant metal2vulkan-rt::Refusal::IndexInUse IndexInUse { class: IndexClass, index: u32 }
variant metal2vulkan-rt::Refusal::IndicesGranted IndicesGranted { class: IndexClass, index: u32 }
variant metal2vulkan-rt::Refusal::IndicesInUse IndicesInUse { class: IndexClass, index: u32 }
@@ -13467,6 +13467,7 @@ variant metal2vulkan-rt::floor::Missing::Feature Feature { structure: &'static s
variant metal2vulkan-rt::floor::Missing::Limit Limit { name: &'static str, device: u32, needed: u32 }
variant metal2vulkan-rt::floor::Missing::MemoryType MemoryType { flags: String }
variant metal2vulkan-rt::floor::Missing::QueueFamily QueueFamily
variant metal2vulkan-rt::floor::Missing::SetLayout SetLayout { set: u32 }
variant metal2vulkan-rt::floor::Missing::TimeDomain TimeDomain(&'static str)
variant metal2vulkan-rt::floor::Missing::Version Version(u32)
variant metal2vulkan-runtime::AddressPlacement::Any Any
Can't render this file because it is too large.
+4 -2
View File
@@ -36,7 +36,7 @@ Columns:
| The translation deadline | 1 | 1 | 0 | 0 | 0 | 1 | 0 |
| What a call did wrong | 73 | 73 | 0 | 0 | 0 | 0 | 0 |
| What a call did wrong, in detail | 174 | 157 | 0 | 0 | 0 | 0 | 0 |
| Devices below the new runtime's floor | 7 | 7 | 0 | 0 | 0 | 0 | 0 |
| Devices below the new runtime's floor | 8 | 8 | 0 | 0 | 0 | 0 | 0 |
| The new runtime's `Refusal` | 37 | 37 | 0 | 0 | 0 | 0 | 0 |
| The new runtime's `Limit` | 10 | 10 | 0 | 0 | 0 | 0 | 0 |
| The new runtime's `Gap` | 14 | 14 | 0 | 0 | 0 | 0 | 0 |
@@ -54,7 +54,7 @@ Columns:
| The translation deadline | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| What a call did wrong | 22 | 3 | 5 | 0 | 18 | 8 | 17 | 0 |
| What a call did wrong, in detail | 60 | 26 | 23 | 0 | 39 | 26 | 0 | 0 |
| Devices below the new runtime's floor | 0 | 0 | 0 | 7 | 0 | 0 | 0 | 0 |
| Devices below the new runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 |
| The new runtime's `Refusal` | 12 | 8 | 0 | 0 | 17 | 0 | 0 | 0 |
| The new runtime's `Limit` | 0 | 0 | 0 | 7 | 3 | 0 | 0 | 0 |
| The new runtime's `Gap` | 0 | 0 | 0 | 0 | 14 | 0 | 0 | 0 |
@@ -608,6 +608,7 @@ Columns:
| `QueueFamily` | A queue family with both `VK_QUEUE_GRAPHICS_BIT` and `VK_QUEUE_COMPUTE_BIT` | devices below the floor, at device creation | `device` | 1: `crates/metal2vulkan-rt/src/floor.rs (decide)` | `-` |
| `MemoryType` | A memory type with these property flags, as Vulkan names them, for buffers of every usage the runtime gives them | devices below the floor, at device creation | `device` | 1: `crates/metal2vulkan-rt/src/floor.rs (choose)` | `-` |
| `TimeDomain` | A time domain of [`TIME_DOMAINS`] the device does not calibrate (`vkGetPhysicalDeviceCalibrateableTimeDomainsEXT`), as Vulkan names it | devices below the floor, at device creation | `device` | 1: `crates/metal2vulkan-rt/src/floor.rs (decide)` | `-` |
| `SetLayout` | The layout of one of the runtime's descriptor sets, `set` 0 (empty) or 1 (the texture and sampler arrays), which `vkGetDescriptorSetLayoutSupport`... | devices below the floor, at device creation | `device` | 1: `crates/metal2vulkan-rt/src/arrays.rs (supported)` | `-` |
## 11. The new runtime's `Refusal` (`Error::Refused(Refusal)`)
@@ -1172,6 +1173,7 @@ Each refusal's sites, with the function that builds it.
- `floor::QueueFamily`: `crates/metal2vulkan-rt/src/floor.rs (decide)`
- `floor::MemoryType`: `crates/metal2vulkan-rt/src/floor.rs (choose)`
- `floor::TimeDomain`: `crates/metal2vulkan-rt/src/floor.rs (decide)`
- `floor::SetLayout`: `crates/metal2vulkan-rt/src/arrays.rs (supported)`
- `rt:Refusal::EmptyBuffer`: `crates/metal2vulkan-rt/src/buffer.rs (new_buffer)`; `crates/metal2vulkan-rt/src/buffer.rs (new_managed_buffer)`
- `rt:Refusal::BufferTooLong`: `crates/metal2vulkan-rt/src/buffer.rs (new_buffer)`; `crates/metal2vulkan-rt/src/buffer.rs (new_managed_buffer)`
- `rt:Refusal::BufferPastBlock`: `crates/metal2vulkan-rt/src/buffer.rs (new_buffer)`; `crates/metal2vulkan-rt/src/buffer.rs (new_managed_buffer)`