veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.17k stars 219 forks source link

VulkanCreateSurface example? #493

Closed CannibalVox closed 2 years ago

CannibalVox commented 2 years ago

I'm attempting to use a vulkan surface in an application, and I am receiving the error VK_KHR_win32_surface extension is not enabled in the Vulkan instance. - in fact that extension is enabled in the instance. And that error is raised when vkGetInstanceProcAddr(instance, "vkCreateWin32SurfaceKHR") returns NULL (https://github.com/emscripten-ports/SDL2/blob/edfa5806ffc8a8fc05327ac709124a479514cab7/src/video/windows/SDL_windowsvulkan.c#L154) but if I call vkGetInstanceProcAddr myself it works just fine.

It seems like I must be doing something wrong but I can't imagine what, is there an example I can refer to?

CannibalVox commented 2 years ago

Some code:

    instanceHandle := (C.VkInstance)(unsafe.Pointer(app.instance.Handle()))
    proc := (C.PFN_vkCreateWin32SurfaceKHR)(C.vkGetInstanceProcAddr(instanceHandle, (*C.char)(C.CString("vkCreateWin32SurfaceKHR"))))
    if proc == nil {
        panic("NULL")
    }
    fmt.Printf("%x\n",uintptr(unsafe.Pointer(proc)))

    surface, err := app.window.VulkanCreateSurface(instanceHandle)
    if err != nil {
        return err
    }

Output:

7ffb06db7460
2021/08/24 22:26:08 VK_KHR_win32_surface extension is not enabled in the Vulkan instance.
veeableful commented 2 years ago

Hi @CannibalVox, have you taken a look at this thread? I wonder if it is the same issue. https://discourse.libsdl.org/t/sdl-vulkan-createsurface-vk-khr-win32-surface-extension-not-enabled/24934

I'm not familiar with Vulkan so if that doesn't solve the issue, perhaps you could share a minimal example using your existing code? I will look into it!

gen2brain commented 2 years ago

@CannibalVox there are examples in vulkan-go, e.g. https://github.com/vulkan-go/demos/blob/master/vulkancube/vulkancube_sdl2/main.go

CannibalVox commented 2 years ago

Hi @CannibalVox, have you taken a look at this thread? I wonder if it is the same issue. https://discourse.libsdl.org/t/sdl-vulkan-createsurface-vk-khr-win32-surface-extension-not-enabled/24934

I'm not familiar with Vulkan so if that doesn't solve the issue, perhaps you could share a minimal example using your existing code? I will look into it!

This was broadly the issue- SDL I guess likes to load its own copy of the vulkan DLL in order to make everything work, which means that instances loaded from another copy (i.e. the copy loaded by my vulkan library itself) won't work with SDL. In order to facilitate this it exposes a function pointer via VulkanGetVkGetInstanceProcAddr (and vulkan-go apparently builds its API functions from that here, rather than using the ones from the header file: https://github.com/vulkan-go/demos/blob/master/vulkancube/vulkancube_sdl2/main.go#L92).

Thank you for the help!