vulkan-go / vulkan

Vulkan API bindings for Go programming language
MIT License
742 stars 55 forks source link

vulkan.CreateDevice throws runtime panic #34

Closed Noofbiz closed 5 years ago

Noofbiz commented 5 years ago

I'm trying to create a device via

dqci := []vk.DeviceQueueCreateInfo{{
        SType:            vk.StructureTypeDeviceQueueCreateInfo,
        QueueFamilyIndex: v.graphicsIdx,
        QueueCount:       1,
        PQueuePriorities: []float32{1.0},
}}
ci := vk.DeviceCreateInfo{
    SType:                   vk.StructureTypeDeviceCreateInfo,
    PQueueCreateInfos:       dqci,
    QueueCreateInfoCount:    uint32(len(dqci)),
    EnabledExtensionCount:   uint32(len(v.enabledExtensions)),
    PpEnabledExtensionNames: safeStrings(v.enabledExtensions),
    EnabledLayerCount:       0,
}
if res := vk.CreateDevice(v.pd, &ci, nil, &v.d); res != vk.Success {
    return errors.New("unable to create device")
}

which looks almost exactly what you have in asche. However, I am getting a runtime panic when I try it

[mvk-info] MoltenVK version 1.0.10. Vulkan version 1.0.75.
[mvk-info] GPU device:
        model: Intel(R) Iris(TM) Plus Graphics 640
        type: Integrated
        vendorID: 0x8086
        deviceID: 0x5926
        pipelineCacheUUID: 00000000-0000-0000-0000-27130000271A
    supports the following Metal Feature Sets:
        macOS GPU Family 1 v3
        macOS GPU Family 1 v2
        macOS GPU Family 1 v1
panic: runtime error: cgo argument has Go pointer to Go pointer
    panic: runtime error: index out of range

goroutine 1 [running, locked to thread]:
main.(*vulkanApp).cleanup(0xc00008a000)
    /Users/noofapple/go/src/vulkanPlay/main.go:822 +0x331
panic(0x4402220, 0xc000010440)
    /usr/local/go/src/runtime/panic.go:513 +0x1b9
github.com/vulkan-go/vulkan.CreateDevice.func1(0x5074410, 0x4a71d70, 0x0, 0xc00008a038, 0x0)
    /Users/noofapple/go/src/github.com/vulkan-go/vulkan/vulkan.go:104 +0xcd
github.com/vulkan-go/vulkan.CreateDevice(0x5074410, 0xc000045e48, 0x0, 0xc00008a038, 0x1)
    /Users/noofapple/go/src/github.com/vulkan-go/vulkan/vulkan.go:104 +0x57
main.(*vulkanApp).createLogicalDevice(0xc00008a000, 0x0, 0x0)
    /Users/noofapple/go/src/vulkanPlay/main.go:151 +0x19d
main.(*vulkanApp).initVulkan(0xc00008a000, 0x0, 0x0)
    /Users/noofapple/go/src/vulkanPlay/main.go:100 +0x92
main.(*vulkanApp).run(0xc00008a000, 0x0, 0x0)
    /Users/noofapple/go/src/vulkanPlay/main.go:60 +0x82
main.main()
    /Users/noofapple/go/src/vulkanPlay/main.go:873 +0x3b
exit status 2

This has worked for me before, but trying to run it today is causing this problem. I've tried printing all the things passed to make sure okay and it looks fine. Anyone have any tips or advice?

ETA: The second panic, index out of range, is in the cleanup step and there's no fences to cleanup since they're created after the device is created which is where the first panic happens.

xlab commented 5 years ago

Hi, I think you've updated your Go installation, because this error is detected by newer Go runtimes (1.8+ as far as I remember), also it worked that way for me:

https://github.com/vulkan-go/asche/blob/master/platform.go#L218-L229

In my examples I create a local variable and pass it around, only then set that to the struct. I had to do that, because of this error otherwise.

vk.CreateDevice(v.pd, &ci, nil, &v.d)

It complains about &v.d my guess is.

Noofbiz commented 5 years ago

Ah, I see. Thanks ^_^

Noofbiz commented 5 years ago

As a note in case anyone else hits this issue and finds it, I ended up getting rid of v.pd as well, so the only things passed were local variables.

xlab commented 5 years ago

@Noofbiz I think v.pd here is okay. Same as ret = vk.CreateDevice(p.gpu, ... in my code