GLFW can't find VK_KHR_win32_surface in MinGW

Viewed 721

Description

Currently my program runs on MSVC without any problems but on MinGW glfwCreateWindowSurface(...) strangely throws an error that it's missing the VK_KHR_win32_surface extension.

Surface Code

void createSurface() {
    if (glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) {
        throw std::runtime_error("failed to create window surface!");
    }
}

Additional Info

  • vkGetInstanceProcAddr(..., "vkCreateWin32SurfaceKHR") and glfwGetInstanceProcAddress(..., "vkCreateWin32SurfaceKHR"): return a non-null function pointer
  • glfwGetError(...): returns 65542 and Win32: Vulkan instance missing VK_KHR_win32_surface extension
  • vkEnumerateInstanceExtensionProperties(...): lists the VK_KHR_win32_surface extension
  • glfwCreateWindowSurface(...): returns VK_ERROR_EXTENSION_NOT_PRESENT
  • glfwVulkanSupported(): returns 1
  • It should be the same code as https://vulkan-tutorial.com/code/26_depth_buffering.cpp
3 Answers

Fixed by using GLFW Native since it works:

#define GLFW_EXPOSE_NATIVE_WIN32
#include <GLFW/glfw3native.h>

// ...

VkWin32SurfaceCreateInfoKHR surfaceInfo {};
surfaceInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
surfaceInfo.hinstance = GetModuleHandle(nullptr);
surfaceInfo.hwnd = glfwGetWin32Window(window);

if (vkCreateWin32SurfaceKHR(instance, &surfaceInfo, nullptr, &surface) != VK_SUCCESS) {
    throw std::runtime_error("failed to create window surface!");
}

Is there any chance you have an older glfw?

I have the glfwCreateWindowSurface present in glfw3.

I built glfw3 myself (both static and shared library) with MinGW-w64 in the MSYS2 shell from the source file at http://downloads.sourceforge.net/project/glfw/glfw/3.3.2/glfw-3.3.2.tar.bz2 using these commands:

cmake.exe -G"MSYS Makefiles" -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -DGLFW_BUILD_EXAMPLES:BOOL=OFF -DGLFW_BUILD_TESTS:BOOL=OFF -S. -Bbuild_static &&
cmake.exe -G"MSYS Makefiles" -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DGLFW_BUILD_EXAMPLES:BOOL=OFF -DGLFW_BUILD_TESTS:BOOL=OFF -S. -Bbuild_shared &&
make -Cbuild_static install/strip &&
make -Cbuild_shared install/strip &&
echo Success

Make sure that your application is using the proper Vulkan library for your target platform. With MinGW targeting Windows you therefore may need to manually link against vulkan-1.dll.

Related