Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

successful update to Vulkan version 1.3.239, working very reliably. #62

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a30771d
successful update to Vulkan version 1.3.211.0 -- builds but crashes o…
May 12, 2022
6e89b8c
now it works! had to revert to oct 14, 2018 version of c-for-go
May 12, 2022
827c7c2
add Bazel build support
garymm Aug 25, 2022
6a6a36b
Merge pull request #1 from garymm/bazel
rcoreilly Aug 26, 2022
57c291e
Bazel: Fetch libMoltenVK rather than relying on system library
garymm Aug 25, 2022
256f2ef
Merge pull request #2 from garymm/bazel-hermetic-macos-moltenvk
rcoreilly Aug 26, 2022
a9837df
Rely on system installation of MoltenVK with Bazel
garymm Sep 16, 2022
c67065a
Merge pull request #3 from garymm/bazel-hermetic-macos-moltenvk
rcoreilly Sep 28, 2022
9ad0685
Update to vulkan version 1.3.239 with UPDATING.md notes updated and u…
Feb 10, 2023
7305916
starting to update from changes on base version but realized that mig…
Feb 10, 2023
7de5f41
v1.0.1 release -- version.go updated
Feb 10, 2023
e19bb1c
add version.go
Feb 10, 2023
4525e5a
fix broken version.go stuff
Feb 10, 2023
4d96393
v1.0.2 release -- version.go updated
Feb 10, 2023
1c25b5b
remove video H246 decoding as it is not perhaps widely supported.
Feb 10, 2023
040226d
v1.0.3 release -- version.go updated
Feb 10, 2023
125cabe
and remove h265 video too
Feb 10, 2023
40622d3
v1.0.4 release -- version.go updated
Feb 10, 2023
5ab406f
encoder was also in beta.. too bad mac doesn't fail -- big loop testi…
Feb 10, 2023
5f16575
v1.0.5 release -- version.go updated
Feb 10, 2023
ce1681b
make bazel build not rely on system Vulkan
garymm Mar 10, 2023
7e2340c
Merge pull request #4 from garymm/bazel
rcoreilly Mar 10, 2023
1b6cfb7
v1.0.6 release -- version.go updated
Mar 10, 2023
a306a71
changes to get android building
rcoreilly Jun 29, 2023
d51c500
got mostly building on ios
kkoreilly Jul 6, 2023
02547c9
properly ignore acceptmoltenvklicense that Kai totally forgot to comm…
rcoreilly Jul 6, 2023
acc4679
plist info
rcoreilly Jul 6, 2023
83c5267
use framework version in original build
rcoreilly Jul 6, 2023
0bf6765
fixed formatting
kkoreilly Aug 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# JetBrains IDE
.idea/
*.iml

# Bazel
bazel-*
105 changes: 105 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

cc_library(
name = "vulkan_headers",
hdrs = glob(["vulkan/*"]),
)

go_library(
name = "vulkan",
srcs = [
"cgo_helpers.c",
"cgo_helpers.go",
"cgo_helpers.h",
"const.go",
"doc.go",
"errors.go",
"init.go",
"types.go",
"util.go",
"vk_bridge.c",
"vk_bridge.h",
"vk_debug_android.go",
"vk_default_loader.c",
"vk_default_loader.h",
"vk_null32.go",
"vk_null64.go",
"vk_wrapper.h",
"vk_wrapper_android.c",
"vk_wrapper_desktop.c",
"vk_wrapper_ios.m",
"vulkan.go",
"vulkan_android.go",
"vulkan_darwin.go",
"vulkan_freebsd.go",
"vulkan_ios.go",
"vulkan_linux.go",
],
cdeps = [":vulkan_headers"] + select({
"@io_bazel_rules_go//go/platform:darwin": [
"@com_github_goki_vulkan_mac_deps//:vulkan_mac_deps",
],
"//conditions:default": [],
}),
cgo = True,
clinkopts = select({
"@io_bazel_rules_go//go/platform:android": [
"-Wl,--no-warn-mismatch",
"-lm_hard",
"-llog",
],
"@io_bazel_rules_go//go/platform:darwin": [
"-F/Library/Frameworks",
"-framework Cocoa",
"-framework IOKit",
"-framework IOSurface",
"-framework QuartzCore",
"-framework Metal",
"-lc++",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"-L/usr/local/lib",
"-ldl",
"-lvulkan",
],
"@io_bazel_rules_go//go/platform:linux": [
"-ldl",
],
"//conditions:default": [],
}) + select({
"@io_bazel_rules_go//go/platform:ios_arm64": [
"-framework Foundation",
"-framework Metal",
"-framework QuartzCore",
"-framework MoltenVK",
"-lc++",
],
"//conditions:default": [],
}),
copts = [
"-I.",
"-DVK_NO_PROTOTYPES",
] + select({
"@io_bazel_rules_go//go/platform:android": [
"-DVK_USE_PLATFORM_ANDROID_KHR",
"-D__ARM_ARCH_7A__",
"-D_NDK_MATH_NO_SOFTFP=1",
"-mfpu=vfp",
"-mfloat-abi=hard",
"-march=armv7-a",
],
"@io_bazel_rules_go//go/platform:darwin": [
"-DVK_USE_PLATFORM_MACOS_MVK",
"-Wno-deprecated-declarations",
],
"//conditions:default": [],
}) + select({
"@io_bazel_rules_go//go/platform:ios_arm64": [
"-x objective-c",
"-DVK_USE_PLATFORM_IOS_MVK",
],
"//conditions:default": [],
}),
importpath = "github.com/goki/vulkan",
visibility = ["//visibility:public"],
)
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,30 @@ clean:

test:
go build

# NOTE: MUST update version number here prior to running 'make release'
VERS=v1.0.6
PACKAGE=vulkan
GIT_COMMIT=`git rev-parse --short HEAD`
VERS_DATE=`date -u +%Y-%m-%d\ %H:%M`
VERS_FILE=version.go

release:
/bin/rm -f $(VERS_FILE)
@echo "// WARNING: auto-generated by Makefile release target -- run 'make release' to update" > $(VERS_FILE)
@echo "" >> $(VERS_FILE)
@echo "package $(PACKAGE)" >> $(VERS_FILE)
@echo "" >> $(VERS_FILE)
@echo "const (" >> $(VERS_FILE)
@echo " GoVersion = \"$(VERS)\"" >> $(VERS_FILE)
@echo " GitCommit = \"$(GIT_COMMIT)\" // the commit JUST BEFORE the release" >> $(VERS_FILE)
@echo " VersionDate = \"$(VERS_DATE)\" // UTC" >> $(VERS_FILE)
@echo ")" >> $(VERS_FILE)
@echo "" >> $(VERS_FILE)
goimports -w $(VERS_FILE)
/bin/cat $(VERS_FILE)
git commit -am "$(VERS) release -- $(VERS_FILE) updated"
git tag -a $(VERS) -m "$(VERS) release"
git push
git push origin --tags

203 changes: 145 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,30 @@
<img src="https://cl.ly/2H2E3c0T1X16/Vulkan_500px_Mar15.png" width="200">

# Golang Bindings for Vulkan API ![version-1.1.88](https://img.shields.io/badge/version-1.1.88-lightgrey.svg) [![GoDoc](https://godoc.org/github.com/vulkan-go/vulkan?status.svg)](https://godoc.org/github.com/vulkan-go/vulkan)
# Golang Bindings for Vulkan API ![version-1.3.239](https://img.shields.io/badge/version-1.3.239-lightgrey.svg) [![GoDoc](https://pkg.go.dev/badge/github.com/goki/vulkan.svg)](https://pkg.go.dev/github.com/goki/vulkan)

Package [vulkan](https://github.com/vulkan-go/vulkan) provides Go bindings for [Vulkan](https://www.khronos.org/vulkan/) — a low-overhead, cross-platform 3D graphics and compute API. Updated October 13, 2018 — Vulkan 1.1.88.
Package [vulkan](https://github.com/goki/vulkan) provides Go bindings for [Vulkan](https://www.khronos.org/vulkan/) — a low-overhead, cross-platform 3D graphics and compute API. Updated February 9, 2023 — Vulkan 1.3.239.

## 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.
The [Vulkan API](https://www.vulkan.org) is a cross-platform industry standard enabling developers to target a wide range of devices with the same graphics API.

Read the brief: https://developer.nvidia.com/engaging-voyage-vulkan
This Go binding allows one to use Vulkan API directly within Go code, avoiding adding lots of C/C++ in the projects. The original version is at https://github.com/vulkan-go/vulkan (still on 1.1.88 from 2018) and a fork at https://github.com/goki/vulkan is being more actively maintained at this point.

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 [UPDATING](UPDATING.md) for extensive notes on how to update to newer vulkan versions as they are released.

## Project history timeline
## Examples and usage

* **2016-02-16** Vulkan API publicly released.
The original author, `xlab`, has examples at: https://github.com/vulkan-go/demos and the beginnings of a toolkit at: https://github.com/vulkan-go/asche.

* **2016-03-06** [vulkan-go](https://github.com/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](https://github.com/xlab/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](http://dl.kc.vc/vulkan/screens/first-android-vulkaninfo.png)).

* **2016-05-24** Improved VulkanInfo example runs on Tablet K1 ([screenshot](http://dl.kc.vc/vulkan/screens/improved-android-vulkaninfo.png)).

* **2016-05-28** [android-go](https://github.com/xlab/android-go) released into public ([Reddit post](https://www.reddit.com/r/golang/comments/4lgttr/full_golang_bindings_for_android_ndk_api_with/)) 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](http://dl.kc.vc/vulkan/screens/first-android-vulkandraw.jpg)), validaton layers work perfectly too.

* **2016-08-16** Public announce of this project ([Reddit post](https://www.reddit.com/r/golang/comments/4y2dj4/golang_bindings_for_vulkan_api_with_demos/)). Reaction was "Meh".

* **2016-11-01** [MoltenVK](https://moltengl.com/moltenvk/) driver merged into GLFW (see [GLFW issue #870](https://github.com/glfw/glfw/issues/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](http://dl.kc.vc/vulkan/screens/first-moltenvk-vulkaninfo.png) and [screen #2](http://dl.kc.vc/vulkan/screens/first-moltenvk-vulkandraw.png))

* **2016-11-07** VulkanInfo and VulkanDraw run fine on NVIDIA GTX980 initialized through GLFW under Windows 10 ([screen #1](http://dl.kc.vc/vulkan/screens/first-windows-vulkaninfo.png) and [screen #2](http://dl.kc.vc/vulkan/screens/first-windows-vulkandraw.png)).

* **2016-11-08** VulkanInfo runs in headless (a.k.a computing) mode in Amazon AWS cloud on P2 Instance equipped Tesla K80 ([screenshot](http://dl.kc.vc/vulkan/screens/first-amazon-vulkaninfo.png)).

* **2016-11-09** [ios-go](https://github.com/xlab/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](http://dl.kc.vc/vulkan/screens/first-ios-vulkaninfo.png)), and so does VulkanDraw ([photo](http://dl.kc.vc/vulkan/screens/first-ios-vulkandraw.jpg) also [GPU report from XCode](http://dl.kc.vc/vulkan/screens/gpureport-ios-vulkandraw.png))

* **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](http://malideveloper.arm.com/downloads/deved/tutorial/SDK/Vulkan/1.0/index.html) and I created initial version of [vulkan-go/asche](https://github.com/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](https://github.com/vulkan-go/vulkan/issues/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](https://github.com/LunarG/VulkanSamples/blob/master/demos/cube.c) of LunarG demos. The whole process has been screencasted, maybe I will release it one day.

* **2017-05-06** [vulkan-go/asche](https://github.com/vulkan-go/asche) complete.

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

![vulkan cube golang](http://dl.kc.vc/vulkan/screens/cube.gif)

See all demos in [vulkan-go/demos](https://github.com/vulkan-go/demos).
The updated version is being used extensively in the [goki](https://github.com/goki) framework, powering the [GoGi](https://github.com/goki/gi) 2D and 3D GUI framework, based on the [VGPU](https://github.com/goki/vgpu) toolkit that manages the considerable complexity of dealing with Vulkan. VGPU is also used as a GPU compute engine framework in the emergent neural network modeling framework [axon](https://github.com/emer/axon).

## 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"
import vk "github.com/goki/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:
Expand Down Expand Up @@ -105,6 +58,138 @@ Instead vulkan-go expects the dylibs to be present in the library search path.

Follow the [build instructions](https://github.com/KhronosGroup/MoltenVK#building), but instead of `make install` manually copy `./Package/Latest/MoltenVK/dylib/macOS/libMoltenVK.dylib` to `/usr/local/lib`

**IMPORTANT:** be sure to remove any existing `libMoltenVK.dylib` file *before* copying a new one, otherwise you'll have to reboot your computer due to the way the gatekeeper mechanism works!

## MoltenVK on iOS

grab MoltenVK asset from github actions, copy to suitable directory:

```
-L/Users/oreilly/dev/ios/MoltenVK/MoltenVK/dylib/iOS/` and `-lMoltenVK ` in `vulkan_ios.go`

$ cp libMoltenVK.dylib myapp.app`
$ lipo -create libMoltenVK.dylib -output MoltenVK`
$ mkdir MoltenVK.framework
$ mv MoltenVK MoltenVK.framework/
$ install_name_tool -change @rpath/libMoltenVK.dylib @executable_path/MoltenVK.framework/MoltenVK main
$ codesign --force --deep --verbose=2 --sign "Randall O'Reilly" widgets.app
$ codesign -vvvv ../widgets.app
```

Info.plist for `MoltenVK.framework`

```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>22F82</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>MoltenVK</string>
<key>CFBundleIdentifier</key>
<string>com.example.test.MoltenVK</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>MoltenVK</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
```

main Info.plist for reference:

```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>22F82</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>main</string>
<key>CFBundleIdentifier</key>
<string>com.example.test.widgets</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Widgets</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>20E238</string>
<key>DTPlatformName</key>
<string>iphoneos</string>
<key>DTPlatformVersion</key>
<string>16.4</string>
<key>DTSDKBuild</key>
<string>20E238</string>
<key>DTSDKName</key>
<string>iphoneos16.4</string>
<key>DTXcode</key>
<string>1431</string>
<key>DTXcodeBuild</key>
<string>14E300c</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
<string>16.4</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
```



## Validation Layers

A good brief of the current state of Vulkan validation layers: [Explore the Vulkan Loader and Validation Layers](https://lunarg.com/wp-content/uploads/2016/07/lunarg-birds-feather-session-siggraph-july-26-2016.pdf) (PDF).
Expand All @@ -118,7 +203,7 @@ $ ./android-generate.sh
$ ndk-build
```

After that you'd copy the objects 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:
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]
Expand All @@ -138,8 +223,10 @@ After that you'd copy the objects to `android/jni/libs` in your project and acti

* [vulkanGo.com](https://vulkanGo.com)
* [SaschaWillems Demos (C++)](https://github.com/SaschaWillems/Vulkan)
* [LunarG Vulkan Samples](https://github.com/LunarG/VulkanSamples)
* [LunarG Vulkan Samples](https://github.com/LunarG/VulkanSamples) (archived)
* [Vulkan Samples from Khronos Group](https://github.com/KhronosGroup/Vulkan-Samples)
* [Official list of Vulkan resources](https://www.khronos.org/vulkan/resources)
* [API description](https://registry.khronos.org/vulkan/)
* [Vulkan API quick reference](https://www.khronos.org/registry/vulkan/specs/1.0/refguide/Vulkan-1.0-web.pdf)

## License
Expand Down
Loading