From 17291a8a139bdd95715ffac21c2ead5139e67109 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 2 Oct 2023 12:48:14 +0200 Subject: [PATCH] Fix `Cannot find compatible metal driver` on macOS due to the newest Vulkan SDK regression #1469 --- .../GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp | 7 +++++++ .../Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp | 3 +++ .../GraphicsDevice/Vulkan/IncludeVulkanHeaders.h | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp index bdd92c762..1e086788e 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp @@ -35,6 +35,10 @@ static const char* GValidationLayers[] = static const char* GInstanceExtensions[] = { +#if PLATFORM_APPLE_FAMILY && defined(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) + VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, + VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, +#endif #if VK_EXT_validation_cache VK_EXT_VALIDATION_CACHE_EXTENSION_NAME, #endif @@ -46,6 +50,9 @@ static const char* GInstanceExtensions[] = static const char* GDeviceExtensions[] = { +#if PLATFORM_APPLE_FAMILY && defined(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME) + VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME, +#endif VK_KHR_SWAPCHAIN_EXTENSION_NAME, #if VK_KHR_maintenance1 VK_KHR_MAINTENANCE1_EXTENSION_NAME, diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp index bd6246d6d..cb40504d4 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp @@ -1078,6 +1078,9 @@ GPUDevice* GPUDeviceVulkan::Create() VkInstanceCreateInfo instInfo; RenderToolsVulkan::ZeroStruct(instInfo, VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO); +#ifdef PLATFORM_APPLE_FAMILY + instInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; +#endif instInfo.pApplicationInfo = &appInfo; GetInstanceLayersAndExtensions(InstanceExtensions, InstanceLayers, SupportsDebugUtilsExt); diff --git a/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h b/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h index 3a1b6a615..4e2694aab 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h +++ b/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h @@ -41,4 +41,15 @@ #define VMA_NOT_NULL #include +#if PLATFORM_APPLE_FAMILY +// Declare potentially missing extensions from newer SDKs +#ifndef VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME +#define VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME "VK_KHR_portability_enumeration" +#define VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR 0x00000001 +#endif +#ifndef VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME +#define VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME "VK_KHR_portability_subset" +#endif +#endif + #endif