fix: enable Vulkan portability drivers on macOS for MoltenVK compatibility
Some checks are pending
Build / Build (arm64) (push) Waiting to run
Build / Build (x86-64) (push) Waiting to run
Build / Build (macOS arm64) (push) Waiting to run
Build / Build (windows-arm64) (push) Waiting to run
Build / Build (windows-x86-64) (push) Waiting to run
Security / CodeQL (C/C++) (push) Waiting to run
Security / Semgrep (push) Waiting to run
Security / Sanitizer Build (ASan/UBSan) (push) Waiting to run

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.
This commit is contained in:
Kelsi Davis 2026-03-23 19:16:12 -07:00
parent 5e8d4e76c8
commit 2e136e9fdc

View file

@ -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) {