3
votes

I've been writing a wrapper library for Vulkan targeting MacOS. It was going fine until I hit this obstacle. There's a call to SDL_Vulkan_CreateSurface which is supposed to return a pointer to a surface VkSurfaceKHR. However, the returned pointer is not a memory address, but rather the number 1. At first I thought this could be a bug with SDL, but then I noticed another call to another Vulkan API is returning 2. I am out of options now and I'm hoping it's something I can fix on my end. This is the output:

1== CREATE VULKAN INSTANCE
Enabling extensions:
VK_KHR_surface
VK_MVK_macos_surface
===

2== CREATE PHYSICAL DEVICE
Created GPU (Physical device): 0x00007fe23b81e380

3== CREATE SURFACE (Metal->MoltenVK)
Created Surface: 0x0000000000000001

4== CREATE DEVICE
Chosen queue Family is 0
Created Device: 0x00007fe23c017a10

5== CREATE COMMAND POOL
Created Command Pool: 0x0000000000000002

6== CREATE COMMAND BUFFER
Created Command Buffer: 0x00007fe23a4d2bd0

7== CREATE SWAPCHAIN
Segmentation fault: 11
   

The responsible function is this:

func createVulkanSurface() throws -> Surface {
    var surface = VkSurfaceKHR(bitPattern: 0)

    if SDL_Vulkan_CreateSurface(window, self.instance!.pointer, &surface) != SDL_TRUE {
        throw lastSDLError()
    }

    return Surface(instance: self.instance!, surface: surface!)
}

The code is here: https://github.com/alexanderuv/vulkanSwift

Specific code above is here: https://github.com/alexanderuv/vulkanSwift/blob/master/Sources/SwiftSDL2/Window.swift#L198

Any help will be appreciated!

1

1 Answers

3
votes

VkSurfaceKHR is not a pointer; it's a non-dispatchable handle. From the standard:

Non-dispatchable handle types are a 64-bit integer type whose meaning is implementation- dependent, and may encode object information directly in the handle rather than acting as a reference to an underlying object.

So 1 or 2 may well be valid values for non-dispatchable handles. If you're getting a seg-fault, it's not because the surface handle is invalid.