From f54876deb03eda0053331955df2a589d3a4e759c Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 20 Jun 2020 20:37:37 +1000 Subject: [PATCH] Vulkan/Context: Use VK_MVK_macos_surface not VK_EXT_metal_surface Will change this over some time in the future when I can work on a Mac again and set up the layer. --- .../include/vulkan_entry_points.inl | 4 ++++ dep/vulkan-loader/include/vulkan_loader.h | 4 +++- src/common/vulkan/context.cpp | 7 +++++++ src/common/vulkan/swap_chain.cpp | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/dep/vulkan-loader/include/vulkan_entry_points.inl b/dep/vulkan-loader/include/vulkan_entry_points.inl index 84b58e38d..acd2305df 100644 --- a/dep/vulkan-loader/include/vulkan_entry_points.inl +++ b/dep/vulkan-loader/include/vulkan_entry_points.inl @@ -54,6 +54,10 @@ VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceXlibPresentationSupportKHR, false VULKAN_INSTANCE_ENTRY_POINT(vkCreateAndroidSurfaceKHR, false) #endif +#if defined(VK_USE_PLATFORM_MACOS_MVK) +VULKAN_INSTANCE_ENTRY_POINT(vkCreateMacOSSurfaceMVK, false) +#endif + #if defined(VK_USE_PLATFORM_METAL_EXT) VULKAN_INSTANCE_ENTRY_POINT(vkCreateMetalSurfaceEXT, false) #endif diff --git a/dep/vulkan-loader/include/vulkan_loader.h b/dep/vulkan-loader/include/vulkan_loader.h index 7676a0b4f..9afb8749d 100644 --- a/dep/vulkan-loader/include/vulkan_loader.h +++ b/dep/vulkan-loader/include/vulkan_loader.h @@ -38,7 +38,9 @@ #endif #if defined(__APPLE__) -#define VK_USE_PLATFORM_METAL_EXT +// TODO: Switch to Metal +#define VK_USE_PLATFORM_MACOS_MVK +// #define VK_USE_PLATFORM_METAL_EXT #endif #include "vulkan/vulkan.h" diff --git a/src/common/vulkan/context.cpp b/src/common/vulkan/context.cpp index 382b6a096..bd861626d 100644 --- a/src/common/vulkan/context.cpp +++ b/src/common/vulkan/context.cpp @@ -189,8 +189,15 @@ bool Context::SelectInstanceExtensions(ExtensionList* extension_list, bool enabl #elif defined(VK_USE_PLATFORM_ANDROID_KHR) if (enable_surface && !SupportsExtension(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, true)) return false; +#elif defined(VK_USE_PLATFORM_MACOS_MVK) + if (enable_surface && !SupportsExtension(VK_MVK_MACOS_SURFACE_EXTENSION_NAME, true)) + return false; +#elif defined(VK_USE_PLATFORM_METAL_EXT) + if (enable_surface && !SupportsExtension(VK_EXT_METAL_SURFACE_EXTENSION_NAME, true)) + return false; #endif + // VK_EXT_debug_report if (enable_debug_report && !SupportsExtension(VK_EXT_DEBUG_REPORT_EXTENSION_NAME, false)) Log_WarningPrintf("Vulkan: Debug report requested, but extension is not available."); diff --git a/src/common/vulkan/swap_chain.cpp b/src/common/vulkan/swap_chain.cpp index 7e23ac94f..30050ef45 100644 --- a/src/common/vulkan/swap_chain.cpp +++ b/src/common/vulkan/swap_chain.cpp @@ -115,6 +115,22 @@ VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, const WindowInf return VK_NULL_HANDLE; } + return surface; + } +#elif defined(VK_USE_PLATFORM_MACOS_MVK) + if (wi.type == WindowInfo::Type::MacOS) + { + VkMacOSSurfaceCreateInfoMVK surface_create_info = {VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK, nullptr, 0, + wi.window_handle}; + + VkSurfaceKHR surface; + VkResult res = vkCreateMacOSSurfaceMVK(instance, &surface_create_info, nullptr, &surface); + if (res != VK_SUCCESS) + { + LOG_VULKAN_ERROR(res, "vkCreateMacOSSurfaceMVK failed: "); + return VK_NULL_HANDLE; + } + return surface; } #endif