GithubHelp home page GithubHelp logo

vulkan-go / vulkan Goto Github PK

View Code? Open in Web Editor NEW
739.0 38.0 55.0 910 KB

Vulkan API bindings for Go programming language

License: MIT License

Makefile 0.02% Go 6.65% C 86.58% Objective-C 6.75%
vulkan vulkan-api golang-bindings graphics framework golang android-ndk

vulkan's Introduction

Golang Bindings for Vulkan API version-1.1.88 GoDoc

Package vulkan provides Go bindings for Vulkan — a low-overhead, cross-platform 3D graphics and compute API. Updated October 13, 2018 — Vulkan 1.1.88.

Introduction

Vulkan API is the result of 18 months in an intense collaboration between leading hardware, game engine and platform vendors, built on significant contributions from multiple Khronos members. Vulkan is designed for portability across multiple platforms with desktop and mobile GPU architectures.

Read the brief: https://developer.nvidia.com/engaging-voyage-vulkan

The binding allows one to use Vulkan API directly within Go code, avoiding adding lots of C/C++ in the projects, also can be used to study Vulkan without diving too deep into C/C++ language semantics. For me it's just a matter of taste, writing Go code is simply more pleasant experience.

See all demos in vulkan-go/demos.

Project history timeline

  • 2016-02-16 Vulkan API publicly released.

  • 2016-03-06 vulkan-go initial commit and first binding.

  • 2016-05-14 Finally received my NVIDIA Shield Tablet K1 (DHL lost the first parcel), I decided to use tablet because it was the first device supporting Vulkan out of the box. And that was a really good implementation, much wow very reference.

  • 2016-05-17 Created android-go project in order to run Vulkan on the android platform.

  • 2016-05-23 First android-go + vulkan program runs on Tablet K1 (screenshot).

  • 2016-05-24 Improved VulkanInfo example runs on Tablet K1 (screenshot).

  • 2016-05-28 android-go released into public (Reddit post) with plenty of examples including GLES/EGL.

  • 2016-08-13 Finished an app that should draw triangle (ported from tri.c from LunarG demos). Draws nothing instead.

  • 2016-08-13 First unsuccessful attempt to write a spinning cube example. More than 25 hours spent, 2.5k lines of C code rewritten into 900 lines of Go code. The reference code was found in some very old LunarG demo, it seems I should've used the latest one.. At least got the validation layers working and found some bugs in the triangle app code.

  • 2016-08-16 First Vulkan API program in Go that draws triangle runs on Tablet K1 (photo), validaton layers work perfectly too.

  • 2016-08-16 Public announce of this project (Reddit post). Reaction was "Meh".

  • 2016-11-01 MoltenVK driver merged into GLFW (see GLFW issue #870) and this made possible to use Vulkan API under Apple OS X or macOS.

  • 2016-11-06 VulkanInfo and VulkanDraw both ported to desktop OS X and use GLFW to initialize Vulkan (screen #1 and screen #2)

  • 2016-11-07 VulkanInfo and VulkanDraw run fine on NVIDIA GTX980 initialized through GLFW under Windows 10 (screen #1 and screen #2).

  • 2016-11-08 VulkanInfo runs in headless (a.k.a computing) mode in Amazon AWS cloud on P2 Instance equipped Tesla K80 (screenshot).

  • 2016-11-09 ios-go project started, it's very easy to run Golang apps on iOS that use custom surface, for my case it was Metal surface.

  • 2016-11-11 VulkanInfo runs fine on my iPhone under iOS (screenshot), and so does VulkanDraw (photo also GPU report from XCode)

  • 2016-11-13 Second unsuccessful attempt to write spinning cube. 25 hours spent. The approach was highly inspired by Mali Vulkan SDK for Android 1.0 and I created initial version of vulkan-go/asche — a higher level framework to simplify Vulkan initialization for new apps.

  • 2016-11-29 Generic Linux support added in using GLFW (Issue #2) thanks @jfreymuth.

  • 2017-05-06 Third, successful attempt to write spining cube example. 16 hours spent, 4K LOC of C code rewritten from cube.c of LunarG demos. The whole process has been screencasted, maybe I will release it one day.

  • 2017-05-06 vulkan-go/asche complete.

  • 2018-10-13 Updated to Vulkan 1.1.88 spec.

  • 2022-11-26 Changed loader for Android. Now compatible with Android 8 (Oreo) API level 26 a higher.

How to use

Usage of this project is straightforward due to the stateless nature of Vulkan API. Just import the package like this:

import vk "github.com/vulkan-go/vulkan"

Set the GetProcAddress pointer (used to look up Vulkan functions) using SetGetInstanceProcAddr or SetDefaultGetInstanceProcAddr. After that you can call Init to initialise the library. For example:

// Using SDL2:
vk.SetGetInstanceProcAddr(sdl.VulkanGetVkGetInstanceProcAddr())

// OR using GLFW:
vk.SetGetInstanceProcAddr(glfw.GetVulkanGetInstanceProcAddress())

// OR without using a windowing library (Linux only, recommended for compute-only tasks)
if err := vk.SetDefaultGetInstanceProcAddr(); err != nil {
    panic(err)
}

if err := vk.Init(); err != nil {
    panic(err)
}

And you're set. I must warn you that using the API properly is not an easy task at all, so beware and follow the official documentation: https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html

In order to simplify development, I created a high-level framework that manages Vulkan platform state and initialization. It is called asche because when you throw a gopher into volcano you get a pile of ash. Currently it's used in VulkanCube demo app.

MoltenVK os macOS

MoltenVK provides a MoltenVK.xcframework which contains static libraries for all Apple platforms. Unfortuantely, linking with a xcframework outside of XCode is not possible.

Instead vulkan-go expects the dylibs to be present in the library search path.

Follow the build instructions, but instead of make install manually copy ./Package/Latest/MoltenVK/dylib/macOS/libMoltenVK.dylib to /usr/local/lib

Validation Layers

A good brief of the current state of Vulkan validation layers: Explore the Vulkan Loader and Validation Layers (PDF).

There is a full support of validation layers with custom callbacks in Go.

Khronos Group releasing compiled Validation Layers like .so library directly on their GitHub respository

Or You can build them from https://github.com/LunarG/VulkanTools like this:

$ cd build-android
$ ./update_external_sources_android.sh
$ ./android-generate.sh
$ ndk-build

After that you'd copy the files to android/jni/libs in your project and activate the ValidationLayers.mk in your Android.mk so when building APK they will be copied alongside with your shared library. It just works then:

[INFO] Instance extensions: [VK_KHR_surface VK_KHR_android_surface]
[INFO] Instance layers: [VK_LAYER_LUNARG_screenshot VK_LAYER_GOOGLE_unique_objects VK_LAYER_LUNARG_api_dump VK_LAYER_LUNARG_image VK_LAYER_LUNARG_core_validation VK_LAYER_LUNARG_object_tracker VK_LAYER_GOOGLE_threading VK_LAYER_LUNARG_parameter_validation VK_LAYER_LUNARG_swapchain]

[Layer Swapchain][ERROR 4] The surface in pCreateInfo->surface, that was given to vkCreateSwapchainKHR(), must be a surface that is supported by the device as determined by vkGetPhysicalDeviceSurfaceSupportKHR().  However, vkGetPhysicalDeviceSurfaceSupportKHR() was never called with this surface.

[Layer Swapchain][ERROR 10] vkCreateSwapchainKHR() called with a non-supported pCreateInfo->compositeAlpha (i.e. VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR).  Supported values are:
     VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR

[Layer DS][ERROR 8] Attempt to set lineWidth to 0.000000 but physical device wideLines feature not supported/enabled so lineWidth must be 1.0f!

[Layer DS][ERROR 22] Unable to allocate 2 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER from pool 0x1c. This pool only has 1 descriptors of this type remaining.

Useful links

License

MIT

vulkan's People

Contributors

fcvarela avatar jclc avatar klukawski avatar neurlang avatar postspectacular avatar ptxmac avatar russ- avatar solokirrik avatar thomasruiz avatar tomas-mraz avatar xlab avatar zigster64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vulkan's Issues

Conditional compilation to target Apple Metal API

As I understand it, to work on osx and iOS, we need to by "Molten" that is code that maps Vulkan calls to Aple's Metal API ?

I have not looked too deeply into this but historically Metal was a fork of Vulkan. Apple Just can't help itself :)

So, it maybe possible to use some conditional compilation to bypass Molten and target Metal direct ?

I am guessing you have also thought about this too but am raising it here to gather ideas / approaches .

This is super awesome project btw. Thank you so much for this work.

Go pointer stored into non-Go memory crashes

Hi, I tried to enable the debug reporting callback on the go vulkan demo (vulkancube) by setting VulkanDebug() to return true:

func (a *Application) VulkanDebug() bool {
	return true
}

It crashes with:

platform.go:59: vulkan: enabling 3 instance extensions
closer.go:137: run time panic: runtime error: cgo argument has Go pointer to Go pointer
/usr/local/go/src/runtime/cgocall.go:565 (0x414f09)
        cgoCheckArg: cgoCheckUnknownPointer(p, msg)
/usr/local/go/src/runtime/cgocall.go:452 (0x414a74)
        cgoCheckPointer: cgoCheckArg(t, ep.data, t.kind&kindDirectIface == 0, top, cgoCheckPointerFail)
/home/dv/go/src/github.com/vulkan-go/vulkan/vulkan.go:1556 (0x4e4e4c)
        CreateDebugReportCallback.func1: __ret := C.callVkCreateDebugReportCallbackEXT(cinstance, cpCreateInfo, cpAllocator, cpCallback)
/home/dv/go/src/github.com/vulkan-go/vulkan/vulkan.go:1556 (0x4dfad6)
        CreateDebugReportCallback: __ret := C.callVkCreateDebugReportCallbackEXT(cinstance, cpCreateInfo, cpAllocator, cpCallback)
/home/dv/go/src/github.com/vulkan-go/asche/platform.go:95 (0x4f891d)
        NewPlatform: ret := vk.CreateDebugReportCallback(instance, &vk.DebugReportCallbackCreateInfo{
/home/dv/go/src/vulkancube/vulkancube_glfw/main.go:97 (0x523993)
        main: platform, err := as.NewPlatform(app)
/usr/local/go/src/runtime/proc.go:203 (0x43dc3d)
        main: fn()
/usr/local/go/src/runtime/asm_amd64.s:1357 (0x468360)
        goexit: BYTE    $0x90   // NOP
exit status 1

I'm pretty worried about this issue because, when I restored the original code to disable the reporting functionality, but enabled Go's CGO checker to the maximum with GODEBUG=cgocheck=2, vk.CreateInstance crashed hard due to the same problem:

platform.go:59: vulkan: enabling 3 instance extensions
write of Go pointer 0xc00001c1b0 to non-Go memory 0x14acf70
fatal error: Go pointer stored into non-Go memory

runtime stack:
runtime.throw(0x5b3d97, 0x24)
        /usr/local/go/src/runtime/panic.go:774 +0x72
runtime.cgoCheckWriteBarrier.func1()
        /usr/local/go/src/runtime/cgocheck.go:55 +0xa9
runtime.systemstack(0x466194)
        /usr/local/go/src/runtime/asm_amd64.s:370 +0x66
runtime.mstart()
        /usr/local/go/src/runtime/proc.go:1146

goroutine 1 [running, locked to thread]:
runtime.systemstack_switch()
        /usr/local/go/src/runtime/asm_amd64.s:330 fp=0xc0000db7a0 sp=0xc0000db798 pc=0x466290
runtime.cgoCheckWriteBarrier(0x14acf70, 0xc00001c1b0)
        /usr/local/go/src/runtime/cgocheck.go:53 +0xc9 fp=0xc0000db7d8 sp=0xc0000db7a0 pc=0x4157d9
runtime.wbBufFlush(0x14acf70, 0xc00001c1b0)
        /usr/local/go/src/runtime/mwbbuf.go:196 +0x83 fp=0xc0000db808 sp=0xc0000db7d8 pc=0x438913
runtime.gcWriteBarrier(0xc000010900, 0xc000010060, 0xc000010900, 0x14acf60, 0x0, 0x0, 0xc00001c1b0, 0xb, 0xc0000db918, 0x4ba6ad, ...)
        /usr/local/go/src/runtime/asm_amd64.s:1444 +0xae fp=0xc0000db890 sp=0xc0000db808 pc=0x46841e
github.com/vulkan-go/vulkan.(*ApplicationInfo).PassRef(0xc000080300, 0xc000010060, 0x8c4cbc)
        /home/dv/go/src/github.com/vulkan-go/vulkan/cgo_helpers.go:171 +0x28e fp=0xc0000db8e0 sp=0xc0000db890 pc=0x4b9fde
github.com/vulkan-go/vulkan.(*InstanceCreateInfo).PassRef(0xc0000dbc90, 0x0, 0x5cefda)
        /home/dv/go/src/github.com/vulkan-go/vulkan/cgo_helpers.go:342 +0x11d fp=0xc0000db928 sp=0xc0000db8e0 pc=0x4ba6ad
github.com/vulkan-go/vulkan.CreateInstance(0xc0000dbc90, 0x0, 0xc0000120d0, 0x5ad96a)
        /home/dv/go/src/github.com/vulkan-go/vulkan/vulkan.go:21 +0x2b fp=0xc0000db958 sp=0xc0000db928 pc=0x4dd4eb
github.com/vulkan-go/asche.NewPlatform(0x5d8500, 0xc0000100a0, 0x5af90d, 0x11, 0x0, 0x0)
        /home/dv/go/src/github.com/vulkan-go/asche/platform.go:75 +0x4a5 fp=0xc0000dbdb8 sp=0xc0000db958 pc=0x4f7415
main.main()
        /home/dv/go/src/vulkancube/vulkancube_glfw/main.go:97 +0x1d4 fp=0xc0000dbf60 sp=0xc0000dbdb8 pc=0x523994
runtime.main()
        /usr/local/go/src/runtime/proc.go:203 +0x21e fp=0xc0000dbfe0 sp=0xc0000dbf60 pc=0x43dc3e
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc0000dbfe8 sp=0xc0000dbfe0 pc=0x468361

goroutine 6 [syscall]:
os/signal.signal_recv(0x0)
        /usr/local/go/src/runtime/sigqueue.go:147 +0x9c
os/signal.loop()
        /usr/local/go/src/os/signal/signal_unix.go:23 +0x22
created by os/signal.init.0
        /usr/local/go/src/os/signal/signal_unix.go:29 +0x41

goroutine 8 [select]:
github.com/xlab/closer.(*closer).wait(0xc0000bc000)
        /home/dv/go/src/github.com/xlab/closer/closer.go:104 +0xe8
created by github.com/xlab/closer.newCloser
        /home/dv/go/src/github.com/xlab/closer/closer.go:96 +0x1cf
exit status 2

Is this a false positive in the go tooling? Is this a real issue with these bindings? If so, I'd gladly try to help

Windows Compatibility

Can you make it compatible with Windows? It doesn't compile as Windows needs its own dynamic loading (windows.h instead of dlfcn.h)

Init, getting null functions on Linux with Nvidia

Hi! Just wanted to let you know that (unless I made some mistake) on Linux with the proprietary Nvidia driver I only get the three functions from the Init function, all other functions result in a null pointer unless an instance is provided.

I worked around it by calling Init, then creating the instance, then calling InitInstance with that instance. This works, but of course it checks for most the function addresses twice. Is there maybe some way to avoid that?

Not able to use dep to isolate vulkan dependency

Have a working example using go get, go run main.go works fine.

Use dep init to pull the same dependencies to the vendor folder.

  Using master as constraint for direct dep github.com/vulkan-go/vulkan
  Locking in master (f7f4611) for direct dep github.com/vulkan-go/vulkan
  Using ^0.8.0 as constraint for direct dep github.com/pkg/errors
  Locking in v0.8.0 (645ef00) for direct dep github.com/pkg/errors
  Using v3.3 as constraint for direct dep github.com/vulkan-go/glfw
  Locking in v3.3 (72ceac6) for direct dep github.com/vulkan-go/glfw

It appears there is bad path resolution happening.

# learn/vendor/github.com/vulkan-go/glfw/v3.3/glfw
vendor\github.com\vulkan-go\glfw\v3.3\glfw\c_glfw.go:4:30: fatal error: glfw/src/context.c: No such file or directory
compilation terminated.
# learn/vendor/github.com/vulkan-go/vulkan
vendor\github.com\vulkan-go\vulkan\cgo_helpers.go:10:27: fatal error: vulkan/vulkan.h: No such file or directory
compilation terminated.

[Question] Is there an easier way to debug errors from C?

When ever the c code errors out it just crashes the program with seg fault without anyway of telling whats wrong. Is there a way i can easily debug errors thrown from C while using this package?

I spent hours debugging swapchain, while i had just forgotten to add the swapchain extension. In bigger programs i am not sure i would have ever found the problem since there is no information to go on. Any thoughts?

Unable to generate bindings on Linux

I would like to update the bindings to the latest version but the code generation script fails with the following error:

[jclc@nakkimuki vulkan]$ make
c-for-go -ccdefs -out .. vulkan.yml
  processing vulkan.yml ⠋[ERR] vulkan/vk_platform.h:71:10: include file not found: stddef.h. Search paths:
	/usr/include
	/home/jclc/devel/vulkan
	/usr/include
	/home/jclc/devel/vulkan (and 1 more errors)
make: *** [Makefile:2: all] Error 1

I believe this was related to a c-for-go issue where the script expects all headers to be located in /usr/include. On Linux compiler-specific headers such as this are located in subdirectories such as /lib/gcc/<target>/<version>/include for gcc and /lib/clang/<version>/include for clang to avoid conflicts.

The code generation script should query the compiler for include directories instead of assuming only one path.

vulkan.CreateInstance throws runtime error

Calling CreateInstance panics with runtime error: cgo argument has Go pointer to Go pointer.

appInfo := &vk.ApplicationInfo{
	SType:              vk.StructureTypeApplicationInfo,
	PApplicationName:   title,
	ApplicationVersion: vk.MakeVersion(0, 0, 0),
	PEngineName:        "No Engine",
	EngineVersion:      vk.MakeVersion(0, 0, 0),
	ApiVersion:         vk.ApiVersion10,
}
createInfo := &vk.InstanceCreateInfo{
	SType:            vk.StructureTypeInstanceCreateInfo,
	PApplicationInfo: appInfo,
}

if ret := vk.CreateInstance(createInfo, nil, &vkInstance); ret != vk.Success {
	return errors.New("failed to create Vulkan instance")
}
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/vulkan-go/vulkan.CreateInstance.func1(0x1b10470, 0x0, 0x785048, 0xc4200b2060)
        /home/vhns/projects/go/src/github.com/vulkan-go/vulkan/vulkan.go:24 +0xa2
github.com/vulkan-go/vulkan.CreateInstance(0xc420069ea8, 0x0, 0x785048, 0xa)
        /home/vhns/projects/go/src/github.com/vulkan-go/vulkan/vulkan.go:24 +0x4d
gitlab.com/jclc/game/graphics.Init(0x4f4e7f, 0xa, 0xc4200b0020, 0x5073a0)
        /home/vhns/projects/go/src/gitlab.com/jclc/game/graphics/vulkan.go:51 +0x19e
main.main()
        /home/vhns/projects/go/src/gitlab.com/jclc/game/main.go:12 +0x3a
exit status 2

PhysicalDeviceProperties -> Limits, all values returned from GetPhysicalDeviceProperties() are set to 0

Hey! Thanks for great library!

I spotted the following issue with this lib. today on macOS.
When I call GetPhysicalDeviceProperties(), I can get other properties like DeviceName, VendorID of PhysicalDeviceProperties just fine, but the embedded Limits structure has all values set to 0.

I'm not sure if this is my local problem or it's just a bug?

{MaxImageDimension1D:0 MaxImageDimension2D:0 MaxImageDimension3D:0 MaxImageDimensionCube:0 MaxImageArrayLayers:0 MaxTexelBufferElements:0 MaxUniformBufferRange:0 MaxStorageBufferRange:0 MaxPushConstantsSize:0 MaxMemoryAllocationCount:0 MaxSamplerAllocationCount:0 BufferImageGranularity:0 SparseAddressSpaceSize:0 MaxBoundDescriptorSets:0 MaxPerStageDescriptorSamplers:0 MaxPerStageDescriptorUniformBuffers:0 MaxPerStageDescriptorStorageBuffers:0 MaxPerStageDescriptorSampledImages:0 MaxPerStageDescriptorStorageImages:0 MaxPerStageDescriptorInputAttachments:0 MaxPerStageResources:0 MaxDescriptorSetSamplers:0 MaxDescriptorSetUniformBuffers:0 MaxDescriptorSetUniformBuffersDynamic:0 MaxDescriptorSetStorageBuffers:0 MaxDescriptorSetStorageBuffersDynamic:0 MaxDescriptorSetSampledImages:0 MaxDescriptorSetStorageImages:0 MaxDescriptorSetInputAttachments:0 MaxVertexInputAttributes:0 MaxVertexInputBindings:0 MaxVertexInputAttributeOffset:0 MaxVertexInputBindingStride:0 MaxVertexOutputComponents:0 MaxTessellationGenerationLevel:0 MaxTessellationPatchSize:0 MaxTessellationControlPerVertexInputComponents:0 MaxTessellationControlPerVertexOutputComponents:0 MaxTessellationControlPerPatchOutputComponents:0 MaxTessellationControlTotalOutputComponents:0 MaxTessellationEvaluationInputComponents:0 MaxTessellationEvaluationOutputComponents:0 MaxGeometryShaderInvocations:0 MaxGeometryInputComponents:0 MaxGeometryOutputComponents:0 MaxGeometryOutputVertices:0 MaxGeometryTotalOutputComponents:0 MaxFragmentInputComponents:0 MaxFragmentOutputAttachments:0 MaxFragmentDualSrcAttachments:0 MaxFragmentCombinedOutputResources:0 MaxComputeSharedMemorySize:0 MaxComputeWorkGroupCount:[0 0 0] MaxComputeWorkGroupInvocations:0 MaxComputeWorkGroupSize:[0 0 0] SubPixelPrecisionBits:0 SubTexelPrecisionBits:0 MipmapPrecisionBits:0 MaxDrawIndexedIndexValue:0 MaxDrawIndirectCount:0 MaxSamplerLodBias:0 MaxSamplerAnisotropy:0 MaxViewports:0 MaxViewportDimensions:[0 0] ViewportBoundsRange:[0 0] ViewportSubPixelBits:0 MinMemoryMapAlignment:0 MinTexelBufferOffsetAlignment:0 MinUniformBufferOffsetAlignment:0 MinStorageBufferOffsetAlignment:0 MinTexelOffset:0 MaxTexelOffset:0 MinTexelGatherOffset:0 MaxTexelGatherOffset:0 MinInterpolationOffset:0 MaxInterpolationOffset:0 SubPixelInterpolationOffsetBits:0 MaxFramebufferWidth:0 MaxFramebufferHeight:0 MaxFramebufferLayers:0 FramebufferColorSampleCounts:0 FramebufferDepthSampleCounts:0 FramebufferStencilSampleCounts:0 FramebufferNoAttachmentsSampleCounts:0 MaxColorAttachments:0 SampledImageColorSampleCounts:0 SampledImageIntegerSampleCounts:0 SampledImageDepthSampleCounts:0 SampledImageStencilSampleCounts:0 StorageImageSampleCounts:0 MaxSampleMaskWords:0 TimestampComputeAndGraphics:0 TimestampPeriod:0 MaxClipDistances:0 MaxCullDistances:0 MaxCombinedClipAndCullDistances:0 DiscreteQueuePriorities:0 PointSizeRange:[0 0] LineWidthRange:[0 0] PointSizeGranularity:0 LineWidthGranularity:0 StrictLines:0 StandardSampleLocations:0 OptimalBufferCopyOffsetAlignment:0 OptimalBufferCopyRowPitchAlignment:0 NonCoherentAtomSize:0 ref7926795a:0x46f55728 allocs7926795a:<nil>}

vulkango.com is down

Not an issue with the library, but vulkango.com seems to be down for days, if not weeks.

Request to help with the translation of the page

Hello, I want to make this request to help translate the page vulkango-com. I am Spanish speaking and doing the Spanish translation of everything would make sense and would be easy to understand

Having trouble linking the MoltenVK framework on macOS

When I run go get "github.com/vulkan-go/vulkan", the framework cannot be found:

~/W/A/go-vulkan-engine ❯❯❯ go get "github.com/vulkan-go/vulkan"                                        ✘ 2
# github.com/vulkan-go/vulkan
ld: framework not found MoltenVK
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I tried copying MoltenVK.xcframework to the /Library/Frameworks folder, symlinking, also with vulkan.framework and I can't make it work.

I also tried to run it with sudo, no luck.

Has anyone run into the same problem?

accessing GetInstanceProcAddr externally (to call vkCreateMacOSSurfaceMVK)

I'm trying to integrate vulkan-go into my graphics package which has its own existing platform-specific backends, so I don't want to use GLFW. I want to be able to call e.g., vkCreateMacOSSurfaceMVK on macos to create a surface. As far as I've been able to determine, I need to do something like this:

vkCreateMacOSSurfaceMVK = (PFN_vkCreateMacOSSurfaceMVK)
    vgo_vkGetInstanceProcAddr(instance, "vkCreateMacOSSurfaceMVK");

to get the function pointer, and then I can call that.

but everything depends on that vgo_vkGetInstanceProcAddr which is in turn based on a static getInstanceProcAddress in vk_wrapper_desktop.c

would it be possible to export that somehow? or is there some way I can get access to that variable without having to reimplement my own copy of the code that gets it in the first place?

alternatively, can all the platform-specific create surface routines such as vkCreateMacOSSurfaceMVK be exported in a way that would be visible inside my cgo .m objective-C files? not sure how that would even work -- don't want to get into complicated pathing / config issues to find the cgo headers from vulkan-go.. I tried various ways of declaring them as extern vars and nothing has worked.

I might have missed something obvious here -- I'm a newbie to vulkan[-go]. Thanks!

Vulkan 1.2

Originally posted by @cers000 in #33 (comment)

The Vulkan 1.2 specification was launched on January 15th, 2020

As such, a new issue is probably a better place to track that than the issue for the missing 1.1 functions. Here's what's changed since 1.1:

Vulkan Version 1.2 promoted a number of key extensions into the core API:

  • VK_KHR_8bit_storage
  • VK_KHR_buffer_device_address
  • VK_KHR_create_renderpass2
  • VK_KHR_depth_stencil_resolve
  • VK_KHR_draw_indirect_count
  • VK_KHR_driver_properties
  • VK_KHR_image_format_list
  • VK_KHR_imageless_framebuffer
  • VK_KHR_sampler_mirror_clamp_to_edge
  • VK_KHR_separate_depth_stencil_layouts
  • VK_KHR_shader_atomic_int64
  • VK_KHR_shader_float16_int8
  • VK_KHR_shader_float_controls
  • VK_KHR_shader_subgroup_extended_types
  • VK_KHR_spirv_1_4
  • VK_KHR_timeline_semaphore
  • VK_KHR_uniform_buffer_standard_layout
  • VK_KHR_vulkan_memory_model
  • VK_EXT_descriptor_indexing
  • VK_EXT_host_query_reset
  • VK_EXT_sampler_filter_minmax
  • VK_EXT_scalar_block_layout
  • VK_EXT_separate_stencil_usage
  • VK_EXT_shader_viewport_index_layer

New Defines

  • VK_API_VERSION_1_2

New Enum Constants

None

New Enums

None

New Structures

  • VkPhysicalDeviceVulkan11Features
  • VkPhysicalDeviceVulkan11Properties
  • VkPhysicalDeviceVulkan12Features
  • VkPhysicalDeviceVulkan12Properties
  • VkPhysicalDevice8BitStorageFeatures
  • VkPhysicalDeviceBufferDeviceAddressFeatures
  • VkBufferDeviceAddressInfo
  • VkBufferOpaqueCaptureAddressCreateInfo
  • VkMemoryOpaqueCaptureAddressAllocateInfo
  • VkDeviceMemoryOpaqueCaptureAddressInfo
  • VkAttachmentDescription2
  • VkAttachmentReference2
  • VkSubpassDescription2
  • VkSubpassDependency2
  • VkRenderPassCreateInfo2
  • VkSubpassBeginInfo
  • VkSubpassEndInfo
  • VkPhysicalDeviceDepthStencilResolveProperties
  • VkSubpassDescriptionDepthStencilResolve
  • VkConformanceVersion
  • VkPhysicalDeviceDriverProperties
  • VkImageFormatListCreateInfo
  • VkPhysicalDeviceImagelessFramebufferFeatures
  • VkFramebufferAttachmentsCreateInfo
  • VkFramebufferAttachmentImageInfo
  • VkRenderPassAttachmentBeginInfo
  • VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures
  • VkAttachmentReferenceStencilLayout
  • VkAttachmentDescriptionStencilLayout
  • VkPhysicalDeviceShaderAtomicInt64Features
  • VkPhysicalDeviceShaderFloat16Int8Features
  • VkPhysicalDeviceFloatControlsProperties
  • VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures
  • VkPhysicalDeviceTimelineSemaphoreFeatures
  • VkPhysicalDeviceTimelineSemaphoreProperties
  • VkSemaphoreTypeCreateInfo
  • VkTimelineSemaphoreSubmitInfo
  • VkSemaphoreWaitInfo
  • VkSemaphoreSignalInfo
  • VkPhysicalDeviceUniformBufferStandardLayoutFeatures
  • VkPhysicalDeviceVulkanMemoryModelFeatures
  • VkDescriptorSetLayoutBindingFlagsCreateInfo
  • VkPhysicalDeviceDescriptorIndexingFeatures
  • VkPhysicalDeviceDescriptorIndexingProperties
  • VkDescriptorSetVariableDescriptorCountAllocateInfo
  • VkDescriptorSetVariableDescriptorCountLayoutSupport
  • VkPhysicalDeviceHostQueryResetFeatures
  • VkSamplerReductionModeCreateInfo
  • VkPhysicalDeviceSamplerFilterMinmaxProperties
  • VkPhysicalDeviceScalarBlockLayoutFeatures
  • VkImageStencilUsageCreateInfo

New Functions

  • vkGetBufferDeviceAddress
  • vkGetBufferOpaqueCaptureAddress
  • vkGetDeviceMemoryOpaqueCaptureAddress
  • vkCreateRenderPass2
  • vkCmdBeginRenderPass2
  • vkCmdNextSubpass2
  • vkCmdEndRenderPass2
  • vkCmdDrawIndirectCount
  • vkCmdDrawIndexedIndirectCount
  • vkGetSemaphoreCounterValue
  • vkWaitSemaphores
  • vkSignalSemaphore
  • vkResetQueryPool

build error under OSX 10.12.6

Hi, with the official deprecation announcement of OpenGL for OSX, I started looking into this exiciting project, but am getting struck down cold by the very first initial step:

go get -u github.com/vulkan-go/demos/vulkancube
# github.com/vulkan-go/vulkan
ld: warning: text-based stub file /System/Library/Frameworks//QuartzCore.framework/QuartzCore.tbd and library file /System/Library/Frameworks//QuartzCore.framework/QuartzCore are out of sync. Falling back to library file for linking.
ld: framework not found MoltenVK
clang: error: linker command failed with exit code 1 (use -v to see invocation)
# github.com/vulkan-go/vulkan
vk_wrapper_desktop.c:11:12: warning: implicit declaration of function 'glfwCreateWindowSurface' is invalid in C99 [-Wimplicit-function-declaration]
vk_wrapper_desktop.c:18:51: warning: implicit declaration of function 'glfwGetInstanceProcAddress' is invalid in C99 [-Wimplicit-function-declaration]
...
(dozens of other warnings)

I just have built MoltenVK and verified it works by running some demos, but it doesn't seem their build process installs the framework globally. Do you have any docs or config options for a) installing that framework for vulkan-go to find and/or b) specify library/include paths for vulkan-go to search in?
Thanks!

Remove GLFW dependency

The long-term goal should be to remove the hard dependency on GLFW so the bindings can be used with any windowing library.

Missing an LDFLAGS directive on Linux/Unix

First of all, love the refactoring; the repository is looking much nicer now without the different source files for each of the desktop platforms. We should strive for as little platform-specific code as possible. However, when the Linux source file was deleted, the cgo directive for linking with dl was also removed, preventing building.

go get -u -v github.com/vulkan-go/vulkan
github.com/vulkan-go/vulkan (download)
github.com/vulkan-go/vulkan
# github.com/vulkan-go/vulkan
/usr/bin/ld: $WORK/b001/_x010.o: in function `getDefaultProcAddr':
vulkan-go/vulkan/vk_default_loader.c:26: undefined reference to `dlopen'
/usr/bin/ld: vulkan-go/vulkan/vk_default_loader.c:30: undefined reference to `dlsym'
collect2: error: ld returned 1 exit status

A simple solution is to just add #cgo linux LDFLAGS: -ldl in vulkan.go, but that file is autogenerated. Could the line just be added in the generator? I'm not familiar with the bindings generator. Adding a new file just for that one directive would be a little ugly in my opinion, but maybe it would be the better choice? Otherwise you'd have to regen the bindings every time you change the build/link flags.

go get fails on macOS Mojave

After adding MoltenVK.framework and vulkan.framework to /Library/Frameworks, I ran go get github.com/vulkan-go/vulkan which gave me this:

# github.com/vulkan-go/vulkan
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_CAEDRMetadata", referenced from:
      objc-class-ref in MoltenVK(libMoltenVK.a-x86_64-master.o)
  "_kCGColorSpaceITUR_2020_HLG", referenced from:
      MVKSwapchain::initCAMetalLayer(VkSwapchainCreateInfoKHR const*, unsigned int) in MoltenVK(libMoltenVK.a-x86_64-master.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It appears MoltenVK isn't able to link with QuartzCore and other system frameworks. Is there a step I'm missing or is this broken for other people too? I'm not able to test this on Catalina. I intend to use these bindings with github.com/veandco/go-sdl2. Thanks

fatal: repository 'https://github.com/xlab/linmath-go/' not found

When trying to run vulkancube or vulkandraw, I get

go: finding module for package github.com/xlab/closer
go: finding module for package github.com/vulkan-go/vulkan
go: finding module for package github.com/vulkan-go/asche
go: finding module for package github.com/vulkan-go/demos/vulkancube
go: finding module for package github.com/vulkan-go/glfw/v3.3/glfw
go: found github.com/vulkan-go/asche in github.com/vulkan-go/asche v0.0.0-20190912134304-d4b318b67e07
go: found github.com/vulkan-go/demos/vulkancube in github.com/vulkan-go/demos v0.0.0-20200912085326-922fc3db80c5
go: found github.com/vulkan-go/glfw/v3.3/glfw in github.com/vulkan-go/glfw v0.0.0-20210402172934-58379a80228d
go: found github.com/vulkan-go/vulkan in github.com/vulkan-go/vulkan v0.0.0-20210402152248-956e3850d8f9
go: found github.com/xlab/closer in github.com/xlab/closer v0.0.0-20190328110542-03326addb7c2
go: finding module for package github.com/xlab/linmath-go/linmath
go: finding module for package github.com/stretchr/testify/assert
go: found github.com/stretchr/testify/assert in github.com/stretchr/testify v1.7.0
go: finding module for package github.com/xlab/linmath-go/linmath
cube imports
        github.com/vulkan-go/asche imports
        github.com/xlab/linmath tested by
        github.com/xlab/linmath.test imports
        github.com/xlab/linmath-go/linmath: cannot find module providing package github.com/xlab/linmath-go/linmath: module github.com/xlab/linmath-go/linmath: git ls-remote -q origin in /Users/nishant/go/pkg/mod/cache/vcs/97833a51e0eb989d3a7ed868526b7c9da4576ae8e9721796c4eaad8eb994ea79: exit status 128:
        remote: Repository not found.
        fatal: repository 'https://github.com/xlab/linmath-go/' not found

fails to build on Ubuntu 16.10

Just trying to install this library with "go get", and it's having problems finding all the function definitions for the C Vulkan library:

$ go get -v github.com/vulkan-go/vulkan
github.com/vulkan-go/vulkan
# github.com/vulkan-go/vulkan
/tmp/go-build113185610/github.com/vulkan-go/vulkan/_obj/init.cgo2.o: In function `_cgo_2f542f46001b_Cfunc_vkInit':
../../../go/src/github.com/vulkan-go/vulkan/init.go:50: undefined reference to `vkInit'
/tmp/go-build113185610/github.com/vulkan-go/vulkan/_obj/init.cgo2.o: In function `_cgo_2f542f46001b_Cfunc_vkInitInstance':
../../../go/src/github.com/vulkan-go/vulkan/init.go:68: undefined reference to `vkInitInstance'
/tmp/go-build113185610/github.com/vulkan-go/vulkan/_obj/vk_bridge.o: In function `callVkCreateInstance':
../../../go/src/github.com/vulkan-go/vulkan/vk_bridge.c:8: undefined reference to `vgo_vkCreateInstance'
/tmp/go-build113185610/github.com/vulkan-go/vulkan/_obj/vk_bridge.o: In function `callVkDestroyInstance':
../../../go/src/github.com/vulkan-go/vulkan/vk_bridge.c:14: undefined reference to `vgo_vkDestroyInstance'
/tmp/go-build113185610/github.com/vulkan-go/vulkan/_obj/vk_bridge.o: In function `callVkEnumeratePhysicalDevices':
../../../go/src/github.com/vulkan-go/vulkan/vk_bridge.c:21: undefined reference to `vgo_vkEnumeratePhysicalDevices'
[...]

It doesn't seem to be resolving the headers properly, either the system ones (via libvulkan-dev package) or via the header files you've included in the repo under /vulkan. Any ideas?

panic: runtime error: cgo argument has Go pointer to Go pointer

I am trying to follow https://vulkan-tutorial.com/ except using Go. I have done the tutorial once in C/C++, so I have a basic understanding of Vulkan (emphasis on basic). I also have some Go experience, but not much when it comes to CGo. I get the error in the title when running this code:

appInfo := vk.ApplicationInfo{}
appInfo.SType = vk.StructureTypeApplicationInfo
appInfo.PApplicationName = "Hello Triangle"
appInfo.ApplicationVersion = vk.MakeVersion(1, 0, 0)
appInfo.PEngineName = "No Engine"
appInfo.EngineVersion = vk.MakeVersion(1, 0, 0)
appInfo.ApiVersion = vk.ApiVersion10

createInfo := vk.InstanceCreateInfo{}
createInfo.SType = vk.StructureTypeInstanceCreateInfo
createInfo.PApplicationInfo = &appInfo

glfwExtensions := h.window.GetRequiredInstanceExtensions()

createInfo.EnabledExtensionCount = uint32(len(glfwExtensions))
createInfo.PpEnabledExtensionNames = glfwExtensions

createInfo.EnabledLayerCount = 0

result := vk.CreateInstance(&createInfo, nil, &h.instance)

if result != vk.Success {
  return errors.New("failed to create instance!")
}

return nil

In particular, vk.CreateInstance is failing. I am not familiar enough with CGo and how memory sharing between the languages works to really know how to debug this issue. Any guidance?

Help! What do I need to do to get coding with Vulkan?

I'm pretty new to Go and programming in general.
I am really interested to get working with Vulkan in Go but I don't know where to start. I understand that Vulkan and some other Go packages use C code behind the scenes and this requires a different compiler.
But I don't know what to get, how to install it, etc.
What programs do I need to install? I currently have Go 1.9.4 windows/amd64
When I start coding a new project, where do I put the files and how to I configure them?
How do I compile and run a program?

I tried figuring it out myself but I simply don't know what I need and I couldn't find a source that has all this information.
Thank you for the help!

vulkancube_glfw make

MoltenVK installed:
C02F32EDML85:vulkancube_glfw bytedance$ ls /usr/local/lib/MoltenVK/
MoltenVK.xcframework dylib include

run:
C02F32EDML85:vulkancube_glfw bytedance$ make
CGO_CFLAGS="-I"/usr/local/Cellar/glfw/3.3.7/include"" CGO_LDFLAGS="-L"/usr/local/Cellar/glfw/3.3.7/lib"" go install

error:

github.com/vulkan-go/vulkan

ld: framework not found MoltenVK
clang: error: linker command failed with exit code 1 (use -v to see invocation)

github.com/vulkan-go/glfw/v3.3/glfw

ld: framework not found MoltenVK
clang: error: linker command failed with exit code 1 (use -v to see invocation)

github.com/vulkan-go/glfw/v3.3/glfw

In file included from ../../../../../pkg/mod/github.com/vulkan-go/[email protected]/v3.3/glfw/c_glfw_darwin.go:8:
../../../../../pkg/mod/github.com/vulkan-go/[email protected]/v3.3/glfw/glfw/src/cocoa_window.m:1027:9: warning: multiple methods named 'center' found [-Wobjc-multiple-method-names]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSCollectionViewCompositionalLayout.h:604:19: note: using
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:341:1: note: also found
make: *** [install] Error 2

documentation as links not ideal

example

// Flags type as declared in https://www.khronos.org/registry/vulkan/specs/1.0/man/html/VkFlags.html
type Flags uint32

seems to me a couple of issues with providing documentation as links to documentation.

  1. in the case above the link target has changed, or rather is redirected, in the case above its to https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkFlags.html which i guess is fine since i would say its very likely still valid for version 1.0., but its surprising.

  2. when browsing, trying to grok the rather large API, having everything a link to follow is so time consuming as to really render the documentation, for this use case, useless.

so, a feature request, any chance the documentaton (summary) be copied and just inlined in the code?

pkg-config and --static flag

On linux, this project fails to build because of --static flag not being parsed by cgo, this is connected to this issue: golang/go#12058

Don't know about Windowsbeing affected, too. I'll prepare a pull request with fix in a few minutes.

SetDefaultGetInstanceProcAddr doesn't work on MacOS

Using SetDefaultGetInstanceProcAddr on MacOS just causes the error vulkan: error loading default getProcAddr. This is because:

  1. First, this function calls setDefaultProcAddr

    vulkan/init.go

    Line 22 in 956e385

    C.setDefaultProcAddr()
  2. In setDefaultProcAddr, it calls getDefaultProcAddr
    getInstanceProcAddress = getDefaultProcAddr();
  3. In getDefaultProcAddr, for MacOS, it just returns NULL
    #elif defined(__APPLE__) && defined(__MACH__)
    // return &loaderWrap;
    return NULL;
  4. In SetDefaultGetInstanceProcAddr, it checks for isProcAddrSet

    vulkan/init.go

    Lines 23 to 25 in 956e385

    if C.isProcAddrSet() == 0 {
    return errors.New("vulkan: error loading default getProcAddr")
    }
  5. In isProcAddrSet, it checks if it is equal to NULL
    return getInstanceProcAddress == NULL ? 0 : 1;

Therefore, on MacOS, isProcAddrSet will always return false. Why is it like this? Is there a way to get around this error? If you ignore it, you just get an error about proc addr not being set in Init.

Null-terminate go strings

If possible, I would like if the package would automatically append a null terminator where appropriate converting from go strings to c strings.

An example of the current behavior when creating a vulkan instance demonstrates my problem:

instanceExtensions := []string{
    vk.KhrSurfaceExtensionName, // Note - using constant defined by the package
}
instanceCreateInfo := &vk.InstanceCreateInfo{
    SType: vk.StructureTypeInstanceCreateInfo,
    PApplicationInfo: appInfo,
    EnabledExtensionCount: uint32(len(instanceExtensions)),
    PpEnabledExtensionNames: instanceExtensions,
}
err := vk.Error(vk.CreateInstance(instanceCreateInfo, nil, &v.instance)) // vulkan error: extension not present

I would like if using the constant vk.KhrSurfaceExtensionName or replacing it with its literal value "VK_KHR_surface" would both succeed without the need to append a null character, e.g. "VK_KHR_surface\x00", though I feel at a minimum the package constants should succeed without having to append the null-terminator at runtime.

This would also assist with GLFW integration, since GetRequiredInstanceExtensions() in the go-gl/glfw package does not return null-terminated values either, and would mitigate a current unexpected behavior if attempting to use vk.ToString() to test if an extension is supported, demonstrated below:

extensionCount := uint32(0)
vk.EnumerateInstanceExtensionProperties("", &extensionCount, nil)
supportedExtensions := make([]vk.ExtensionProperties, extensionCount)
vk.EnumerateInstanceExtensionProperties("", &extensionCount, supportedExtensions)

debugFound := false
for _, extProps := range supportedExtensions {
    if vk.ToString(extProps.ExtensionName == "VK_EXT_debug_utils" {
        // False positive: can cause runtime exception if used to test if extension is supported before calling CreateInstance
        debugFound = true
        break
    }

    if vk.ToString(extProps.ExtensionName) == "VK_EXT_debug_utils\x00" {
        // Unreachable since ToString() trims the null terminator
        debugFound = true
        break
    }
}

You can see that the above code will give the wrong result regardless of if the test string is null-terminated or not, causing the need to manually append a null-terminator to the test string after running this test or to write a custom ToString method.

How can I help?

Title says it all. I am a dev who has an interest in this side of things and alot of free time at the moment... how can I help?

GetPhysicalDeviceSurfaceCapabilities() does not return anything

hello, at minimum 3 rows needs inserting into GetPhysicalDeviceSurfaceCapabilities()

+	pSurfaceCapabilities.SupportedCompositeAlpha = CompositeAlphaFlags(cpSurfaceCapabilities.supportedCompositeAlpha)
+	pSurfaceCapabilities.MinImageCount = uint32(cpSurfaceCapabilities.minImageCount)
+	pSurfaceCapabilities.MaxImageCount = uint32(cpSurfaceCapabilities.maxImageCount)
	return __v

this is required to make it return a value using the result pointer.
thanks

'compute' build constraint tag

had some trouble building the compute example.

the 'compute' constraint seemed to be necessary, not surprising since without it vkinit() was checking for a window.

go build -tags="compute" main.go

but i also needed to make two files skip compilation for this constraint (maybe just a problem with a Linux built?);

"vulkan_linux.go"

// +build linux,!android

changed too

// +build !android
// +build !compute
// +build !headless

and..

"vk_wrapper_desktop.c"

// +build windows darwin,!ios linux,!android

changed too

// +build windows darwin,!ios linux,!android
// +build !compute
// +build !headless

vulkan.CreateDevice throws runtime panic

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.

EnumerateInstanceLayerProperties not setting the go struct values to the C values

So I am getting into vulkan using go and I am having some issues. When calling EnumerateInstanceLayerProperties it will return correctly, but the Go struct values are not correct. I can see internally that the internal values are correct however.

Screenshot from 2019-05-19 16-40-34

Here is my code:
layerNames := make([]string, 1)
layerNames[0] = "VK_LAYER_KHRONOS_validation"
layerCount := uint32(0)
vulkan.EnumerateInstanceLayerProperties(&layerCount, nil)
layers := make([]vulkan.LayerProperties, layerCount)
vulkan.EnumerateInstanceLayerProperties(&layerCount, layers)`

Thanks!

segfault in vulkaninfo example

on investigating seems to be three issues in play (see below code extract)

deviceCreate requires swapchain, my vulkan setup doesn't have it, so this errors.

but swapchain doesn't actually seem to be needed anyway, so it just commented it out to fix.

but when erroring the code calls DestroySurface without first having setup one, so this is the seqfault.

again i just commented out to get to work; correctly report unavailable extension.

when i looked in the docs of DistroySurface, to see if the surface could be null, the link in the docs is broken, seems the url changed? this;

https://www.khronos.org/registry/vulkan/specs/1.0-wsi_extensions/html/vkspec.html#VkDestroySurfaceKHR

needs the uppercase 'V' changed to lowercase to work.

	deviceExtensions := []string{
		"VK_KHR_swapchain\x00",
	}
	deviceCreateInfo := &vk.DeviceCreateInfo{
		SType:                   vk.StructureTypeDeviceCreateInfo,
		QueueCreateInfoCount:    uint32(len(queueCreateInfos)),
		PQueueCreateInfos:       queueCreateInfos,
		EnabledExtensionCount:   uint32(len(deviceExtensions)),
		PpEnabledExtensionNames: deviceExtensions,
	}
	var device vk.Device
	err = vk.Error(vk.CreateDevice(v.gpuDevices[0], deviceCreateInfo, nil, &device))
	if err != nil {
		v.gpuDevices = nil
		vk.DestroySurface(v.instance, v.surface, nil)
		vk.DestroyInstance(v.instance, nil)
		err = fmt.Errorf("CreateDevice with extensions %s failed with %s",deviceExtensions, err)
		return

Missing Vulkan 1.1 functions

Vulkan 1.1 introduced some new functions. The most important function is EnumerateInstanceVersion() which is used to enumerate supported instance versions. Many extensions are now members of the Vulkan core:

  • VK_KHR_16bit_storage
  • VK_KHR_bind_memory2
  • VK_KHR_dedicated_allocation
  • VK_KHR_descriptor_update_template
  • VK_KHR_device_group
  • VK_KHR_device_group_creation
  • VK_KHR_external_memory
  • VK_KHR_external_memory_capabilities
  • VK_KHR_external_semaphore
  • VK_KHR_external_semaphore_capabilities
  • VK_KHR_external_fence
  • VK_KHR_external_fence_capabilities
  • VK_KHR_get_memory_requirements2
  • VK_KHR_get_physical_device_properties2
  • VK_KHR_maintenance1
  • VK_KHR_maintenance2
  • VK_KHR_maintenance3
  • VK_KHR_multiview
  • VK_KHR_relaxed_block_layout
  • VK_KHR_sampler_ycbcr_conversion
  • VK_KHR_shader_draw_parameters
  • VK_KHR_storage_buffer_storage_class
  • VK_KHR_variable_pointers

Vulkan 1.1 compatibility statement can be found here. Most important changes are described here.

Do you plan to implement missing functions?

Support debug_utils

Was going through the Vulkan tutorial and noticed debug_report work via your demos but debug_utils used by the tutorial is not. The spec says

Layer Controls
There are two general methods for controlling layer behavior supported by most of the layers listed herein: layer settings file and a debug extension. The layer settings file provides a general mechanism for a user to control various layer behaviors by providing arbitrary settings. Currently the layer settings file has settings only pertaining to layer message logging.

There are currently two available debug extensions: VK_EXT_debug_utils and VK_EXT_debug_report. Both are available for use by applications to programmatically control layer message logging. VK_EXT_debug_utils is preferable to VK_EXT_debug_report as the later extension has become deprecated and will not continue to evolve with the Vulkan API. However, VK_EXT_debug_report will continue to work for existing applications supporting Vulkan 1.0 should that be all you require.

Vulkan layers support both methods.

Since its is deprecated can we get support for debug_utils?

How can i get a vk.Surface ?

Hello
I am trying to create a vk.Surface and i know of two ways to create it.

Using platform specific code like the function vkCreateWin32SurfaceKHR from the Vulkan API, however this function does not seam to be defined in these bindings.

Using the function CreateWindowSurface from GLFW with is platform agnostic and the preferred way to do it when using GLFW, the problem is i don't know how to use this function and the function does not seam to be very well documented.
Most functions i have seen so far work by me creating the data type and passing a pointer of that data type to a function but the function CreateWindowSurface from GLFW does not work this way, well the one from these bindings at least does not seam to work this way because when i search for it on the internet i keep finding things like "glfwCreateWindowSurface(instance, window, nullptr, &surface)" but the one from this bindings is "func (window *Window) CreateWindowSurface(instance interface{}, allocCallbacks unsafe.Pointer) (surface uintptr, err error)" and dosen't even return a vk.Surface.
It gets the surface grabs a unsafe pointer to it and then gets it's pointer as a uintptr like so "return uintptr(unsafe.Pointer(&vulkanSurface)), nil".

I have tried to drill thru these pointers to get a vk.Surface like so "(vk.Surface)(unsafe.Pointer(surface))" but when i then try to pass this surface to the function GetPhysicalDeviceSurfaceSupport the validation layers complain this is not a valid handle "The Vulkan spec states: surface must be a valid VkSurfaceKHR handle".

So my question is how do i create vk.Surface and can the CreateWindowSurface from GLFW be better documented in relation to this issue since it works in such a different way from the rest of the functions of the Vulkan API?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.