Reputation: 101
Hey I'm trying to create a Windows Surface with Vulkan
but the somehow vkGetInstanceProcAddr
fails to load the vkCreateWin32SurfaceKHR
function even though the extension is loaded properly.
Edit: here I try to get the function pointer:
vkCreateWin32SurfaceKHR =
(PFN_vkCreateWin32SurfaceKHR)vkGetInstanceProcAddr(vulkanInstance.instance,
"vkCreateWin32SurfaceKHR");
Upvotes: 3
Views: 3104
Reputation: 57
I have been struggling with the same problem and found another cause.
vkCreateInstance takes a list of extensions
vkCreateDevice ALSO takes a list of extensions to enable
vkCreateWin32SurfaceKHR MUST be called to create the surface used by vkCreateDevice.
I was adding VK_KHR_WIN32_SURFACE_EXTENSION_NAME for vkCreateDevice NOT vkCreateInstance.
Moving the declaration to the right place resolved the issue.
Upvotes: 0
Reputation: 71
On this... if you receive an error with the call to vkCreateWin32SurfaceKHR, make sure you defined the sType on the VkWin32SurfaceCreateInfoKHR structure... Even though it's an VkWin32SurfaceCreateInfoKHR struct, forgetting stype is enough to make it fail.
Upvotes: 0
Reputation:
Did you #include
the vulkan_win32.h
header in your source file?
PFN_vkCreateWin32SurfaceKHR
comes from an extension and so it is not defined in the core vulkan headers.
Upvotes: 0
Reputation: 986
In case you're okay using the C++ API instead of the C one, an easier way to do this is via the vulkan.hpp
file that ships in the SDK.
You can #define VK_USE_PLATFORM_WIN32_KHR
and vk::Instance
will have a vk::Result createWin32SurfaceKHR(vk::Win32SurfaceCreateInfoKHR*, vk::AllocationCallbacks*, vk::SurfaceKHR*)
member function. This helps alleviate the need for grabbing function pointers yourself.
Upvotes: 0
Reputation: 5798
Did you enable the appropriate extension using e.g. the const VK_KHR_WIN32_SURFACE_EXTENSION_NAME
at instance creation time?
Also note that you don't need to manually get the function pointer for vkCreateWin32SurfaceKHR
unless you define VK_NO_PROTOTYPES
as it's part of the core.
If you have enabled the extension and still don't get a valid function pointer, check if your drivers are properly installed, esp. that there is no old ICD registered that may cause problems. The LunarG Vulkan SDK contains a tool called "via" (in the bin folder) to check your Vulkan installation.
Upvotes: 4