examples: Fix validation errors on macOS and iOS (#623)
* Error: vkCreateDevice: VK_KHR_portability_subset must be enabled [...] * Error: Attempting to create a VkDevice from a VkPhysicalDevice which is from a portability driver without the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo flags being set and the VK_KHR_portability_enumeration extension enabled.
This commit is contained in:
parent
c4f1c053ea
commit
6308470479
|
@ -15,6 +15,11 @@ use std::ffi::CStr;
|
||||||
use std::ops::Drop;
|
use std::ops::Drop;
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
use ash::vk::{
|
||||||
|
KhrGetPhysicalDeviceProperties2Fn, KhrPortabilityEnumerationFn, KhrPortabilitySubsetFn,
|
||||||
|
};
|
||||||
|
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
|
@ -229,6 +234,13 @@ impl ExampleBase {
|
||||||
.to_vec();
|
.to_vec();
|
||||||
extension_names.push(DebugUtils::name().as_ptr());
|
extension_names.push(DebugUtils::name().as_ptr());
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
{
|
||||||
|
extension_names.push(KhrPortabilityEnumerationFn::name().as_ptr());
|
||||||
|
// Enabling this extension is a requirement when using `VK_KHR_portability_subset`
|
||||||
|
extension_names.push(KhrGetPhysicalDeviceProperties2Fn::name().as_ptr());
|
||||||
|
}
|
||||||
|
|
||||||
let appinfo = vk::ApplicationInfo::default()
|
let appinfo = vk::ApplicationInfo::default()
|
||||||
.application_name(app_name)
|
.application_name(app_name)
|
||||||
.application_version(0)
|
.application_version(0)
|
||||||
|
@ -236,10 +248,17 @@ impl ExampleBase {
|
||||||
.engine_version(0)
|
.engine_version(0)
|
||||||
.api_version(vk::make_api_version(0, 1, 0, 0));
|
.api_version(vk::make_api_version(0, 1, 0, 0));
|
||||||
|
|
||||||
|
let create_flags = if cfg!(any(target_os = "macos", target_os = "ios")) {
|
||||||
|
vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR
|
||||||
|
} else {
|
||||||
|
vk::InstanceCreateFlags::default()
|
||||||
|
};
|
||||||
|
|
||||||
let create_info = vk::InstanceCreateInfo::default()
|
let create_info = vk::InstanceCreateInfo::default()
|
||||||
.application_info(&appinfo)
|
.application_info(&appinfo)
|
||||||
.enabled_layer_names(&layers_names_raw)
|
.enabled_layer_names(&layers_names_raw)
|
||||||
.enabled_extension_names(&extension_names);
|
.enabled_extension_names(&extension_names)
|
||||||
|
.flags(create_flags);
|
||||||
|
|
||||||
let instance: Instance = entry
|
let instance: Instance = entry
|
||||||
.create_instance(&create_info, None)
|
.create_instance(&create_info, None)
|
||||||
|
@ -293,7 +312,11 @@ impl ExampleBase {
|
||||||
})
|
})
|
||||||
.expect("Couldn't find suitable device.");
|
.expect("Couldn't find suitable device.");
|
||||||
let queue_family_index = queue_family_index as u32;
|
let queue_family_index = queue_family_index as u32;
|
||||||
let device_extension_names_raw = [Swapchain::name().as_ptr()];
|
let device_extension_names_raw = [
|
||||||
|
Swapchain::name().as_ptr(),
|
||||||
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
KhrPortabilitySubsetFn::name().as_ptr(),
|
||||||
|
];
|
||||||
let features = vk::PhysicalDeviceFeatures {
|
let features = vk::PhysicalDeviceFeatures {
|
||||||
shader_clip_distance: 1,
|
shader_clip_distance: 1,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
Loading…
Reference in a new issue