From 0c1fbce6a7c611702a55dc177fc58f46b4f680f1 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 11 Aug 2023 15:35:48 -0700 Subject: [PATCH] [vk] Don't request portability enumeration without the extension. VUID-VkInstanceCreateInfo-flags-06559 forbids us from passing `vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR` unless we actually found and requested the "VK_KHR_portability_enumeration" layer. Fixes #4004. --- wgpu-hal/src/vulkan/instance.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/wgpu-hal/src/vulkan/instance.rs b/wgpu-hal/src/vulkan/instance.rs index 5e07cd7794d..0083d856549 100644 --- a/wgpu-hal/src/vulkan/instance.rs +++ b/wgpu-hal/src/vulkan/instance.rs @@ -609,6 +609,11 @@ impl crate::Instance for super::Instance { let obs_layer = CStr::from_bytes_with_nul(b"VK_LAYER_OBS_HOOK\0").unwrap(); let has_obs_layer = find_layer(&instance_layers, obs_layer).is_some(); + let portability_enumeration_layer = + CStr::from_bytes_with_nul(b"VK_KHR_portability_enumeration\0").unwrap(); + let has_portability_enumeration_layer = + find_layer(&instance_layers, portability_enumeration_layer).is_some(); + let mut layers: Vec<&'static CStr> = Vec::new(); // Request validation layer if asked. @@ -657,6 +662,14 @@ impl crate::Instance for super::Instance { #[cfg(not(target_os = "android"))] let android_sdk_version = 0; + // Avoid VUID-VkInstanceCreateInfo-flags-06559: Only ask the instance to + // enumerate incomplete Vulkan implementations (which we need on Mac) if + // we managed to find the layer that provides the flag. + let mut flags = vk::InstanceCreateFlags::empty(); + if has_portability_enumeration_layer { + flags |= vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR; + } + let vk_instance = { let str_pointers = layers .iter() @@ -668,7 +681,7 @@ impl crate::Instance for super::Instance { .collect::>(); let create_info = vk::InstanceCreateInfo::builder() - .flags(vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR) + .flags(flags) .application_info(&app_info) .enabled_layer_names(&str_pointers[..layers.len()]) .enabled_extension_names(&str_pointers[layers.len()..]);