Files
Chris Waldon dbf6429026 app,gpu/headless: [linux] make EGL the default backend
This commit switches the priority of EGL and Vulkan so that EGL is always
tried first. This is because our EGL backend performs significantly better
than the Vulkan one, and we want the most performant experience to be the
default.

Our hypothesis is that the EGL backend is benefitting from lots of optimization
within the OpenGL driver that Vulkan drivers expect applications to perform
themselves. Rather than invest a bunch of time optimizing the Vulkan backend
right now, this change lets us focus on other priorities.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-09-08 11:41:35 +02:00

75 lines
1.3 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
//go:build (linux || freebsd) && !novulkan
// +build linux freebsd
// +build !novulkan
package headless
import (
"unsafe"
"gioui.org/gpu"
"gioui.org/internal/vk"
)
type vkContext struct {
physDev vk.PhysicalDevice
inst vk.Instance
dev vk.Device
queueFam int
}
func init() {
newContextFallback = newVulkanContext
}
func newVulkanContext() (context, error) {
inst, err := vk.CreateInstance()
if err != nil {
return nil, err
}
physDev, qFam, err := vk.ChoosePhysicalDevice(inst, 0)
if err != nil {
vk.DestroyInstance(inst)
return nil, err
}
dev, err := vk.CreateDeviceAndQueue(physDev, qFam)
if err != nil {
vk.DestroyInstance(inst)
return nil, err
}
ctx := &vkContext{
physDev: physDev,
inst: inst,
dev: dev,
queueFam: qFam,
}
return ctx, nil
}
func (c *vkContext) API() gpu.API {
return gpu.Vulkan{
PhysDevice: unsafe.Pointer(c.physDev),
Device: unsafe.Pointer(c.dev),
Format: int(vk.FORMAT_R8G8B8A8_SRGB),
QueueFamily: c.queueFam,
QueueIndex: 0,
}
}
func (c *vkContext) MakeCurrent() error {
return nil
}
func (c *vkContext) ReleaseCurrent() {
}
func (c *vkContext) Release() {
vk.DeviceWaitIdle(c.dev)
vk.DestroyDevice(c.dev)
vk.DestroyInstance(c.inst)
*c = vkContext{}
}