From 2e136e9fdc296cec1df25c8d4973f1c350953d78 Mon Sep 17 00:00:00 2001 From: Kelsi Davis Date: Mon, 23 Mar 2026 19:16:12 -0700 Subject: [PATCH] fix: enable Vulkan portability drivers on macOS for MoltenVK compatibility Homebrew's vulkan-loader hides portability ICDs (like MoltenVK) from pre-instance extension enumeration by default, causing SDL2 to fail with "doesn't implement VK_KHR_surface". Set VK_LOADER_ENABLE_PORTABILITY_DRIVERS before loading the Vulkan library so the loader includes MoltenVK and its surface extensions. --- src/core/window.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/window.cpp b/src/core/window.cpp index 9f74a81c..318e5408 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -38,6 +38,15 @@ bool Window::initialize() { // clear error and avoids the misleading "not configured in SDL" message. // SDL 2.28+ uses LoadLibraryExW(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS) which does // not search System32, so fall back to the explicit path on Windows if needed. + // + // On macOS, MoltenVK is a Vulkan "portability" driver. The Vulkan loader + // hides portability drivers (and their extensions like VK_KHR_surface) from + // pre-instance enumeration unless told otherwise. Setting this env var + // makes the loader include portability ICDs so SDL's VK_KHR_surface check + // succeeds. +#ifdef __APPLE__ + setenv("VK_LOADER_ENABLE_PORTABILITY_DRIVERS", "1", 0 /*don't overwrite*/); +#endif bool vulkanLoaded = (SDL_Vulkan_LoadLibrary(nullptr) == 0); #ifdef _WIN32 if (!vulkanLoaded) {