From bdbcdd539d0a3aa2c4ee1fec16beba944089ecc9 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 20 Nov 2026 05:32:59 -0800 Subject: [PATCH] rt: under direct driver loading, an instance extension counts only where a given driver lists it, or the loader implements it Instance::with_drivers gives the loader the consumer's drivers in its exclusive mode, so no driver a manifest names is loaded. But the loader's vkEnumerateInstanceExtensionProperties still lists those manifest drivers' extensions, and enabled() counted an extension as offered where the loader OR a given driver listed it. On the Mac host, with KosmicKrisp loaded directly and MoltenVK's manifest installed, a consumer asking for VK_EXT_headless_surface got it enabled because MoltenVK lists it, and vkCreateInstance failed with VK_ERROR_EXTENSION_NOT_PRESENT: every rt test of reims's Mac leg failed at the instance (its batch 329b, m3-max-58452). Now, with drivers given, a consumer's extension counts only where a given driver lists it. The optional floor extension VK_KHR_portability_enumeration, which the specification says "is implemented in the loader", still counts on the loader's list. Without drivers nothing changes: the loader's list is the system drivers'. Verified: the floor test's new cases (a manifest driver's extension counted without drivers, left out with drivers that do not list it, portability enumeration kept) beside the existing ones; the compile job named in the landing. --- crates/metal2vulkan-rt/src/instance.rs | 34 +++++++++++++---------- crates/metal2vulkan-rt/src/tests/floor.rs | 14 ++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/crates/metal2vulkan-rt/src/instance.rs b/crates/metal2vulkan-rt/src/instance.rs index 1007a95f0..86ea85bb8 100644 --- a/crates/metal2vulkan-rt/src/instance.rs +++ b/crates/metal2vulkan-rt/src/instance.rs @@ -64,8 +64,12 @@ impl Instance { /// instance then enables `VK_LUNARG_direct_driver_loading` and gives the loader the list in /// its exclusive mode (`VK_DIRECT_DRIVER_LOADING_MODE_EXCLUSIVE_LUNARG`): no driver the system /// installed, or that the loader's variables name, is loaded. An instance extension is offered - /// where the loader or one of the drivers lists it, as the loader does not ask such drivers - /// for theirs. With no loader and no driver, it is [`Instance::new`]. + /// where one of the drivers lists it, as the loader does not ask such drivers for theirs, or, + /// for one the loader implements itself (`VK_KHR_portability_enumeration`: "This extension is + /// implemented in the loader"), where the loader lists it. The loader's own list also holds + /// the extensions of the drivers its manifests name, which the exclusive mode does not load, + /// so no other extension counts for being on it. With no loader and no driver, it is + /// [`Instance::new`]. /// /// Err: as [`Instance::new`], [`Error::Loader`] where the library at `loader` does not load; /// [`Error::NoDirectDriverLoading`] where a driver is given and the loader does not offer @@ -235,10 +239,13 @@ fn names(listed: Result, vk::Result>) -> Result = (floor::INSTANCE_EXTENSIONS.iter()) .map(|&name| name.to_owned()) .collect(); - let listed = |name: &CStr| { - loader - .iter() - .chain(drivers) - .any(|offered| offered.as_c_str() == name) - }; - for &name in floor::OPTIONAL_INSTANCE_EXTENSIONS.iter().chain(extensions) { - if listed(name) && !names.iter().any(|enabled| enabled.as_c_str() == name) { + let lists = + |list: &[CString], name: &CStr| list.iter().any(|offered| offered.as_c_str() == name); + let optional = (floor::OPTIONAL_INSTANCE_EXTENSIONS.iter()).map(|&name| (name, true)); + let asked = extensions.iter().map(|&name| (name, false)); + for (name, in_the_loader) in optional.chain(asked) { + let offered = lists(drivers, name) || ((!direct || in_the_loader) && lists(loader, name)); + if offered && !names.iter().any(|enabled| enabled.as_c_str() == name) { names.push(name.to_owned()); } } diff --git a/crates/metal2vulkan-rt/src/tests/floor.rs b/crates/metal2vulkan-rt/src/tests/floor.rs index a0ec504fb..5b5300b36 100644 --- a/crates/metal2vulkan-rt/src/tests/floor.rs +++ b/crates/metal2vulkan-rt/src/tests/floor.rs @@ -195,6 +195,20 @@ fn an_instance_enables_what_the_loader_or_the_drivers_offer_and_direct_loading_w enabled(&owned(&[portability]), &drivers, &[], true), Err(Error::NoDirectDriverLoading) )); + // The loader also lists a manifest driver's extension (`headless`). Without drivers it is the + // system's driver's, and counts; with drivers that do not list it, the exclusive mode loads no + // driver that offers it, so it is left out, while the loader's own portability enumeration + // still counts. + let headless = ash::ext::headless_surface::NAME; + let loader = owned(&[direct, portability, headless]); + assert_eq!( + names(enabled(&loader, &[], &[headless], false)), + owned(&[surface, portability, headless]) + ); + assert_eq!( + names(enabled(&loader, &drivers, &[headless], true)), + owned(&[surface, portability, direct]) + ); } /// The consumer's loader is the library at its path, alone: a path that holds none is refused by