Go binding for Vulkan
Fetch the package:
$ go get -u github.com/sparkkoori/go-vulkan
Install the Vulkan SDK, make sure loader vulkan-1 or vulkan.1 exists in search path.
Use vk
in your package:
package main
import (
"github.com/sparkkoori/go-vulkan/v1.1/vk"
)
func main() {
appInfo := &vk.ApplicationInfo{
ApplicationName: "AppName",
ApplicationVersion: 1,
EngineName: "AppName",
EngineVersion: 1,
ApiVersion: vk.MAKE_VERSION(1, 1, 0),
}
createInfo := &vk.InstanceCreateInfo{
Flags: 0,
ApplicationInfo: appInfo,
EnabledLayerNames: nil,
EnabledExtensionNames: nil,
}
var ins vk.Instance
//Directly Call
rs := vk.CreateInstance(createInfo, nil, &ins)
if rs == vk.ERROR_INCOMPATIBLE_DRIVER {
panic("cannot find a compatible Vulkan ICD")
} else if rs != vk.SUCCESS {
panic("unknown error")
}
vk.DestroyInstance(ins, nil)
//Indirectly Call
{
fn := vk.ToCreateInstance(vk.GetInstanceProcAddr(nil, "vkCreateInstance"))
rs = fn(createInfo, nil, &ins)
if rs == vk.ERROR_INCOMPATIBLE_DRIVER {
panic("cannot find a compatible Vulkan ICD")
} else if rs != vk.SUCCESS {
panic("unknown error")
}
}
{
fn := vk.ToDestroyInstance(vk.GetInstanceProcAddr(ins, "vkDestroyInstance"))
fn(ins, nil)
}
}
The warping rules used in this package.
-
No translation for handle types.
- eg.
type Instance C.VkInstance
- eg.
-
Map
Bool32
tobool
. -
Map
char *
tostring
. -
Merge size and pointer fields to slice.
- eg.
EnabledLayerNames []string
foruint32_t enabledLayerCount
andconst char* const* ppEnabledLayerNames
- eg.
-
Remove
sType
field, it can be inferred from struct name. -
Map
void *
toStructure
inpNext
field. -
Map
PFN*
touintptr
.- This allow conversion between
PFN*
.
- This allow conversion between
-
Map
union
tostruct
, keep it's memory layout.
-
Copy data between go and c, instead of pass memory.
- Except Go arrays with same layout as C arrays in function params.
-
No manual memory management is need.
- Because cgo does not support calling function pointer, for every
PFN*
, a bridge methodTo*()
was created.
-
Prefix has been trimed.
- eg. Vk, vk, VK_, p, pp
MIT