app: [Vulkan] keep VkSurfaceKHR ownership to platforms

Before this change, it was unclear who owned the platform specific
VkSurfaceKHR object, leading to a double-free in the error path for
devices with no Vulkan support. This change moves the ownership to the
platform specific code.

Add vk.EnumeratePhysicalDevices while here (refactor was part of
debugging of the double-free).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-09-23 11:26:41 +02:00
parent 53fe2e5235
commit 94f7fa3218
5 changed files with 34 additions and 33 deletions
+8 -3
View File
@@ -15,6 +15,7 @@ import (
type wlVkContext struct {
win *window
inst vk.Instance
surf vk.Surface
ctx *vkContext
}
@@ -39,6 +40,7 @@ func init() {
c := &wlVkContext{
win: w,
inst: inst,
surf: surf,
ctx: ctx,
}
return c, nil
@@ -55,6 +57,7 @@ func (c *wlVkContext) API() gpu.API {
func (c *wlVkContext) Release() {
c.ctx.release()
vk.DestroySurface(c.inst, c.surf)
vk.DestroyInstance(c.inst)
*c = wlVkContext{}
}
@@ -71,11 +74,13 @@ func (c *wlVkContext) Unlock() {}
func (c *wlVkContext) Refresh() error {
win, w, h := c.win.nativeWindow()
c.ctx.destroySurface()
if c.surf != 0 {
c.ctx.destroySwapchain()
vk.DestroySurface(c.inst, c.surf)
}
surf, err := vk.CreateAndroidSurface(c.inst, unsafe.Pointer(win))
if err != nil {
return err
}
c.ctx.setSurface(surf)
return c.ctx.refresh(w, h)
return c.ctx.refresh(surf, w, h)
}