Files
gio-patched/app/vulkan_android.go
T
Elias Naur 8999747ad2 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>
2021-09-21 18:40:05 +02:00

82 lines
1.5 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
//go:build !novulkan
// +build !novulkan
package app
import (
"unsafe"
"gioui.org/gpu"
"gioui.org/internal/vk"
)
type wlVkContext struct {
win *window
inst vk.Instance
ctx *vkContext
}
func init() {
newAndroidVulkanContext = func(w *window) (context, error) {
inst, err := vk.CreateInstance("VK_KHR_surface", "VK_KHR_android_surface")
if err != nil {
return nil, err
}
window, _, _ := w.nativeWindow()
surf, err := vk.CreateAndroidSurface(inst, unsafe.Pointer(window))
if err != nil {
vk.DestroyInstance(inst)
return nil, err
}
ctx, err := newVulkanContext(inst, surf)
if err != nil {
vk.DestroySurface(inst, surf)
vk.DestroyInstance(inst)
return nil, err
}
c := &wlVkContext{
win: w,
inst: inst,
ctx: ctx,
}
return c, nil
}
}
func (c *wlVkContext) RenderTarget() (gpu.RenderTarget, error) {
return c.ctx.RenderTarget()
}
func (c *wlVkContext) API() gpu.API {
return c.ctx.api()
}
func (c *wlVkContext) Release() {
c.ctx.release()
vk.DestroyInstance(c.inst)
*c = wlVkContext{}
}
func (c *wlVkContext) Present() error {
return c.ctx.present()
}
func (c *wlVkContext) Lock() error {
return nil
}
func (c *wlVkContext) Unlock() {}
func (c *wlVkContext) Refresh() error {
win, w, h := c.win.nativeWindow()
c.ctx.destroySurface()
surf, err := vk.CreateAndroidSurface(c.inst, unsafe.Pointer(win))
if err != nil {
return err
}
c.ctx.setSurface(surf)
return c.ctx.refresh(w, h)
}