mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
app,gpu,internal/vk: add Vulkan port for Wayland, X11, Android
This change implements a Vulkan port for the two renderers, old and compute. Run with GIORENDERER=forcecompute to test the compute renderer. To shake out bugs faster, it is also made the default on systems that support it. To disable Vulkan and force the use of OpenGL, use the `novulkan` tag: $ go run -tags novulkan gioui.org/example/kitchen Don't forget to file an issue describing the issue that prompted the use of the tag. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
//go:build !nowayland
|
||||
// +build !nowayland
|
||||
|
||||
package vk
|
||||
|
||||
/*
|
||||
#define VK_USE_PLATFORM_ANDROID_KHR
|
||||
#define VK_NO_PROTOTYPES 1
|
||||
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
|
||||
#include <android/native_window.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
static VkResult vkCreateAndroidSurfaceKHR(PFN_vkCreateAndroidSurfaceKHR f, VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
|
||||
return f(instance, pCreateInfo, pAllocator, pSurface);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var wlFuncs struct {
|
||||
vkCreateAndroidSurfaceKHR C.PFN_vkCreateAndroidSurfaceKHR
|
||||
}
|
||||
|
||||
func init() {
|
||||
loadFuncs = append(loadFuncs, func(dlopen func(name string) *[0]byte) {
|
||||
wlFuncs.vkCreateAndroidSurfaceKHR = dlopen("vkCreateAndroidSurfaceKHR")
|
||||
})
|
||||
}
|
||||
|
||||
func CreateAndroidSurface(inst Instance, window unsafe.Pointer) (Surface, error) {
|
||||
inf := C.VkAndroidSurfaceCreateInfoKHR{
|
||||
sType: C.VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
|
||||
window: (*C.ANativeWindow)(window),
|
||||
}
|
||||
var surf Surface
|
||||
if err := vkErr(C.vkCreateAndroidSurfaceKHR(wlFuncs.vkCreateAndroidSurfaceKHR, inst, &inf, nil, &surf)); err != nil {
|
||||
return 0, fmt.Errorf("vulkan: vkCreateAndroidSurfaceKHR: %w", err)
|
||||
}
|
||||
return surf, nil
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
//go:build ((linux && !android) || freebsd) && !nowayland
|
||||
// +build linux,!android freebsd
|
||||
// +build !nowayland
|
||||
|
||||
package vk
|
||||
|
||||
/*
|
||||
#define VK_USE_PLATFORM_WAYLAND_KHR
|
||||
#define VK_NO_PROTOTYPES 1
|
||||
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
static VkResult vkCreateWaylandSurfaceKHR(PFN_vkCreateWaylandSurfaceKHR f, VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
|
||||
return f(instance, pCreateInfo, pAllocator, pSurface);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var wlFuncs struct {
|
||||
vkCreateWaylandSurfaceKHR C.PFN_vkCreateWaylandSurfaceKHR
|
||||
}
|
||||
|
||||
func init() {
|
||||
loadFuncs = append(loadFuncs, func(dlopen func(name string) *[0]byte) {
|
||||
wlFuncs.vkCreateWaylandSurfaceKHR = dlopen("vkCreateWaylandSurfaceKHR")
|
||||
})
|
||||
}
|
||||
|
||||
func CreateWaylandSurface(inst Instance, disp unsafe.Pointer, wlSurf unsafe.Pointer) (Surface, error) {
|
||||
inf := C.VkWaylandSurfaceCreateInfoKHR{
|
||||
sType: C.VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
|
||||
display: (*C.struct_wl_display)(disp),
|
||||
surface: (*C.struct_wl_surface)(wlSurf),
|
||||
}
|
||||
var surf Surface
|
||||
if err := vkErr(C.vkCreateWaylandSurfaceKHR(wlFuncs.vkCreateWaylandSurfaceKHR, inst, &inf, nil, &surf)); err != nil {
|
||||
return 0, fmt.Errorf("vulkan: vkCreateWaylandSurfaceKHR: %w", err)
|
||||
}
|
||||
return surf, nil
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
//go:build ((linux && !android) || freebsd) && !nox11
|
||||
// +build linux,!android freebsd
|
||||
// +build !nox11
|
||||
|
||||
package vk
|
||||
|
||||
/*
|
||||
#define VK_USE_PLATFORM_XLIB_KHR
|
||||
#define VK_NO_PROTOTYPES 1
|
||||
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
static VkResult vkCreateXlibSurfaceKHR(PFN_vkCreateXlibSurfaceKHR f, VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
|
||||
return f(instance, pCreateInfo, pAllocator, pSurface);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var x11Funcs struct {
|
||||
vkCreateXlibSurfaceKHR C.PFN_vkCreateXlibSurfaceKHR
|
||||
}
|
||||
|
||||
func init() {
|
||||
loadFuncs = append(loadFuncs, func(dlopen func(name string) *[0]byte) {
|
||||
x11Funcs.vkCreateXlibSurfaceKHR = dlopen("vkCreateXlibSurfaceKHR")
|
||||
})
|
||||
}
|
||||
|
||||
func CreateXlibSurface(inst Instance, dpy unsafe.Pointer, window uintptr) (Surface, error) {
|
||||
inf := C.VkXlibSurfaceCreateInfoKHR{
|
||||
sType: C.VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
|
||||
dpy: (*C.Display)(dpy),
|
||||
window: (C.Window)(window),
|
||||
}
|
||||
var surf Surface
|
||||
if err := vkErr(C.vkCreateXlibSurfaceKHR(x11Funcs.vkCreateXlibSurfaceKHR, inst, &inf, nil, &surf)); err != nil {
|
||||
return 0, fmt.Errorf("vulkan: vkCreateXlibSurfaceKHR: %w", err)
|
||||
}
|
||||
return surf, nil
|
||||
}
|
||||
Reference in New Issue
Block a user