From 9ac7cb0d95b8d648745436b69f619d8174c6522d Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 11 Aug 2023 15:24:00 -0700 Subject: [PATCH 1/2] [vk] Use `ash`'s definition of `ENUMERATE_PORTABILITY_KHR`. Use the `ash` crate's definition of `vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR` in `wgpu_hal::vulkan::Instance::init`, rather than re-declaring it locally ourselves. --- wgpu-hal/src/vulkan/instance.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/wgpu-hal/src/vulkan/instance.rs b/wgpu-hal/src/vulkan/instance.rs index 931d4a2819..5e07cd7794 100644 --- a/wgpu-hal/src/vulkan/instance.rs +++ b/wgpu-hal/src/vulkan/instance.rs @@ -667,11 +667,8 @@ impl crate::Instance for super::Instance { }) .collect::>(); - const VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR: u32 = 0x00000001; let create_info = vk::InstanceCreateInfo::builder() - .flags(vk::InstanceCreateFlags::from_raw( - VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR, - )) + .flags(vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR) .application_info(&app_info) .enabled_layer_names(&str_pointers[..layers.len()]) .enabled_extension_names(&str_pointers[layers.len()..]); From 49cc50ed839aea6a3f810e575d20b2761b1cd3c1 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 11 Aug 2023 15:35:48 -0700 Subject: [PATCH 2/2] [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" extension. Fixes #4004. --- CHANGELOG.md | 2 ++ wgpu-hal/src/vulkan/instance.rs | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ce67f6e8d..ff9bf871bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,8 @@ By @Valaphee in [#3402](https://github.com/gfx-rs/wgpu/pull/3402) #### Vulkan - Fix enabling `wgpu::Features::PARTIALLY_BOUND_BINDING_ARRAY` not being actually enabled in vulkan backend. By @39ali in[#3772](https://github.com/gfx-rs/wgpu/pull/3772). +- Don't pass `vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR` unless the `VK_KHR_portability_enumeration` extension is available. By @jimblandy in[#4038](https://github.com/gfx-rs/wgpu/pull/4038). + #### DX12 - DX12 doesn't support `Features::POLYGON_MODE_POINT``. By @teoxoy in [#4032](https://github.com/gfx-rs/wgpu/pull/4032). diff --git a/wgpu-hal/src/vulkan/instance.rs b/wgpu-hal/src/vulkan/instance.rs index 5e07cd7794..adaa4f1c11 100644 --- a/wgpu-hal/src/vulkan/instance.rs +++ b/wgpu-hal/src/vulkan/instance.rs @@ -589,6 +589,11 @@ impl crate::Instance for super::Instance { let extensions = Self::required_extensions(&entry, driver_api_version, desc.flags)?; + let portability_enumeration_extension = + CStr::from_bytes_with_nul(b"VK_KHR_portability_enumeration\0").unwrap(); + let has_portability_enumeration_extension = + extensions.contains(&portability_enumeration_extension); + let instance_layers = entry.enumerate_instance_layer_properties().map_err(|e| { log::info!("enumerate_instance_layer_properties: {:?}", e); crate::InstanceError @@ -657,6 +662,15 @@ impl crate::Instance for super::Instance { #[cfg(not(target_os = "android"))] let android_sdk_version = 0; + let mut flags = vk::InstanceCreateFlags::empty(); + + // 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 extension that provides the flag. + if has_portability_enumeration_extension { + flags |= vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR; + } + let vk_instance = { let str_pointers = layers .iter() @@ -668,7 +682,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()..]);