Skip to content

Commit

Permalink
[vk] Don't request portability enumeration without the extension.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jimblandy committed Aug 11, 2023
1 parent 9dfb65b commit b12f69b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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).

## v0.17.0 (2023-07-20)

This is the first release that featured `wgpu-info` as a binary crate for getting information about what devices wgpu sees in your system. It can dump the information in both human readable format and json.
Expand Down
15 changes: 14 additions & 1 deletion wgpu-hal/src/vulkan/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ impl crate::Instance<super::Api> 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.
Expand Down Expand Up @@ -657,6 +662,14 @@ impl crate::Instance<super::Api> 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()
Expand All @@ -668,7 +681,7 @@ impl crate::Instance<super::Api> for super::Instance {
.collect::<Vec<_>>();

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()..]);
Expand Down

0 comments on commit b12f69b

Please sign in to comment.