Skip to content

Commit

Permalink
Support for Vulkan SDK 1.3 (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
aclysma committed Aug 23, 2022
1 parent f666f57 commit 38ca251
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
3 changes: 2 additions & 1 deletion deny.toml
Expand Up @@ -76,7 +76,8 @@ allow = [
"CC0-1.0",
"BSD-3-Clause",
"BSD-2-Clause",
"Zlib"
"Zlib",
"Unicode-DFS-2016"
#"Apache-2.0 WITH LLVM-exception",
]
# List of explictly disallowed licenses
Expand Down
27 changes: 16 additions & 11 deletions rafx-api/src/backends/vulkan/device_context.rs
Expand Up @@ -806,20 +806,25 @@ fn create_logical_device(
) -> RafxResult<ash::Device> {
//TODO: Ideally we would set up validation layers for the logical device too.

fn khr_portability_subset_extension_name() -> &'static CStr {
CStr::from_bytes_with_nul(b"VK_KHR_portability_subset\0").expect("Wrong extension string")
}

#[allow(unused_mut)]
let mut device_extension_names = vec![khr::Swapchain::name().as_ptr()];

// Add VK_KHR_portability_subset if the extension exists (this is mandated by spec)
let portability_subset_extension_name = khr_portability_subset_extension_name();
for extension in &physical_device_info.extension_properties {
let extension_name = unsafe { CStr::from_ptr(extension.extension_name.as_ptr()) };
#[cfg(target_os = "macos")]
{
fn khr_portability_subset_extension_name() -> &'static CStr {
CStr::from_bytes_with_nul(b"VK_KHR_portability_subset\0")
.expect("Wrong extension string")
}

// Add VK_KHR_portability_subset if the extension exists (this is mandated by spec)
let portability_subset_extension_name = khr_portability_subset_extension_name();
for extension in &physical_device_info.extension_properties {
let extension_name = unsafe { CStr::from_ptr(extension.extension_name.as_ptr()) };

if extension_name == portability_subset_extension_name {
device_extension_names.push(khr_portability_subset_extension_name().as_ptr());
break;
if extension_name == portability_subset_extension_name {
device_extension_names.push(portability_subset_extension_name.as_ptr());
break;
}
}
}

Expand Down
27 changes: 26 additions & 1 deletion rafx-api/src/backends/vulkan/internal/instance.rs
Expand Up @@ -153,6 +153,30 @@ impl VkInstance {
extension_names.push(swapchain_extension_name.as_c_str());
}

#[allow(unused_mut)]
let mut create_instance_flags = vk::InstanceCreateFlags::empty();

// Required to support MoltenVK 1.3
#[cfg(target_os = "macos")]
{
// From https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkInstanceCreateFlagBits.html
const VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR: vk::InstanceCreateFlags =
vk::InstanceCreateFlags::from_raw(0x00000001);

fn khr_portability_subset_extension_name() -> &'static CStr {
CStr::from_bytes_with_nul(b"VK_KHR_portability_enumeration\0")
.expect("Wrong extension string")
}

let swapchain_extension_name = khr_portability_subset_extension_name();
if extensions.iter().any(|extension| unsafe {
CStr::from_ptr(extension.extension_name.as_ptr()) == swapchain_extension_name
}) {
extension_names.push(swapchain_extension_name);
create_instance_flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
}
}

if log::log_enabled!(log::Level::Debug) {
log::debug!("Using layers: {:?}", layer_names);
log::debug!("Using extensions: {:?}", extension_names);
Expand All @@ -165,7 +189,8 @@ impl VkInstance {
let create_info = vk::InstanceCreateInfo::builder()
.application_info(&appinfo)
.enabled_layer_names(&layer_names)
.enabled_extension_names(&extension_names);
.enabled_extension_names(&extension_names)
.flags(create_instance_flags);

log::info!("Creating vulkan instance");
let instance: ash::Instance = unsafe { entry.create_instance(&create_info, None)? };
Expand Down

0 comments on commit 38ca251

Please sign in to comment.