From 088461c51a822edbb5a7c49c328ec52d28271667 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 19 Feb 2026 17:24:10 -0800 Subject: [PATCH] macOS: avoid unstable MoltenVK Vulkan features --- vulkan/context.cpp | 2 ++ vulkan/device.cpp | 5 +++++ vulkan/wsi.cpp | 27 +++++++++++++-------------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/vulkan/context.cpp b/vulkan/context.cpp index b0c3dfa..e6d3197 100644 --- a/vulkan/context.cpp +++ b/vulkan/context.cpp @@ -1597,11 +1597,13 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface, enabled_extensions.push_back(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME); } +#ifndef __APPLE__ if (has_extension(VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME)) { enabled_extensions.push_back(VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME); ADD_CHAIN(ext.barycentric_features, FRAGMENT_SHADER_BARYCENTRIC_FEATURES_KHR); } +#endif if (ext.supports_video_queue && has_extension(VK_KHR_VIDEO_MAINTENANCE_1_EXTENSION_NAME)) { diff --git a/vulkan/device.cpp b/vulkan/device.cpp index bd7544c..f28d19a 100644 --- a/vulkan/device.cpp +++ b/vulkan/device.cpp @@ -881,6 +881,11 @@ void Device::init_workarounds() // Events are not supported in MoltenVK. // TODO: Use VK_KHR_portability_subset to determine this. workarounds.emulate_event_as_pipeline_barrier = true; + if (ext.vk13_features.synchronization2) + { + LOGW("Disabling synchronization2 on Metal emulation.\n"); + ext.vk13_features.synchronization2 = VK_FALSE; + } LOGW("Emulating events as pipeline barriers on Metal emulation.\n"); LOGW("Disabling push descriptors on Metal emulation.\n"); #else diff --git a/vulkan/wsi.cpp b/vulkan/wsi.cpp index 48599ec..9f19268 100644 --- a/vulkan/wsi.cpp +++ b/vulkan/wsi.cpp @@ -368,15 +368,20 @@ bool WSI::init_context_from_platform(unsigned num_thread_indices, const Context: new_context->set_num_thread_indices(num_thread_indices); new_context->set_system_handles(system_handles); - if (!new_context->init_instance( - instance_ext.data(), instance_ext.size(), - CONTEXT_CREATION_ENABLE_ADVANCED_WSI_BIT | - CONTEXT_CREATION_ENABLE_PUSH_DESCRIPTOR_BIT | - CONTEXT_CREATION_ENABLE_DESCRIPTOR_BUFFER_BIT | + ContextCreationFlags context_flags = video_context_flags; + +#ifndef __APPLE__ + context_flags |= CONTEXT_CREATION_ENABLE_ADVANCED_WSI_BIT | + CONTEXT_CREATION_ENABLE_PUSH_DESCRIPTOR_BIT | + CONTEXT_CREATION_ENABLE_DESCRIPTOR_BUFFER_BIT; +#endif + #ifdef GRANITE_VULKAN_SYSTEM_HANDLES - CONTEXT_CREATION_ENABLE_PIPELINE_BINARY_BIT | + context_flags |= CONTEXT_CREATION_ENABLE_PIPELINE_BINARY_BIT; #endif - video_context_flags)) + + if (!new_context->init_instance( + instance_ext.data(), instance_ext.size(), context_flags)) { LOGE("Failed to create Vulkan instance.\n"); return false; @@ -387,13 +392,7 @@ bool WSI::init_context_from_platform(unsigned num_thread_indices, const Context: bool ret = new_context->init_device( VK_NULL_HANDLE, tmp_surface, device_ext.data(), device_ext.size(), - CONTEXT_CREATION_ENABLE_ADVANCED_WSI_BIT | - CONTEXT_CREATION_ENABLE_PUSH_DESCRIPTOR_BIT | - CONTEXT_CREATION_ENABLE_DESCRIPTOR_BUFFER_BIT | -#ifdef GRANITE_VULKAN_SYSTEM_HANDLES - CONTEXT_CREATION_ENABLE_PIPELINE_BINARY_BIT | -#endif - video_context_flags); + context_flags); if (tmp_surface) platform->destroy_surface(new_context->get_instance(), tmp_surface);