From bdd0893dd099b634363177badcfd6421bf6728d2 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 20 Sep 2021 11:48:17 +0200 Subject: [PATCH] app,gpu: move errDeviceLost from package app to package gpu The Vulkan backend can return device lost error from more than just Present. Signed-off-by: Elias Naur --- app/d3d11_windows.go | 2 +- app/os.go | 5 ----- app/window.go | 4 ++-- gpu/api.go | 4 ++++ gpu/internal/driver/driver.go | 2 ++ 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/d3d11_windows.go b/app/d3d11_windows.go index e9e09c48..ab04ee4a 100644 --- a/app/d3d11_windows.go +++ b/app/d3d11_windows.go @@ -70,7 +70,7 @@ func (c *d3d11Context) Present() error { // Ignore return nil case d3d11.DXGI_ERROR_DEVICE_RESET, d3d11.DXGI_ERROR_DEVICE_REMOVED, d3d11.D3DDDIERR_DEVICEREMOVED: - return errDeviceLost + return gpu.ErrDeviceLost } } return err diff --git a/app/os.go b/app/os.go index 4d8227c1..7b6351ba 100644 --- a/app/os.go +++ b/app/os.go @@ -113,11 +113,6 @@ type context interface { Unlock() } -// errDeviceLost is returned from Context.Present when -// the underlying GPU device is gone and should be -// recreated. -var errDeviceLost = errors.New("GPU device lost") - // Driver is the interface for the platform implementation // of a window. type driver interface { diff --git a/app/window.go b/app/window.go index 8106be2c..09b07c90 100644 --- a/app/window.go +++ b/app/window.go @@ -153,7 +153,7 @@ func (w *Window) validateAndProcess(frameStart time.Time, size image.Point, sync }) if err != nil { w.destroyGPU() - if err == errDeviceLost { + if errors.Is(err, gpu.ErrDeviceLost) { continue } return err @@ -175,7 +175,7 @@ func (w *Window) validateAndProcess(frameStart time.Time, size image.Point, sync if w.gpu != nil { if err := w.render(frame, size); err != nil { w.destroyGPU() - if err == errDeviceLost { + if errors.Is(err, gpu.ErrDeviceLost) { continue } return err diff --git a/gpu/api.go b/gpu/api.go index a5a2f80a..1a390899 100644 --- a/gpu/api.go +++ b/gpu/api.go @@ -28,3 +28,7 @@ type Direct3D11 = driver.Direct3D11 // Metal denotes the Apple Metal API. type Metal = driver.Metal + +// ErrDeviceLost is returned from GPU operations when the underlying GPU device +// is lost and should be recreated. +var ErrDeviceLost = driver.ErrDeviceLost diff --git a/gpu/internal/driver/driver.go b/gpu/internal/driver/driver.go index a5a27b9f..2f8ba7f9 100644 --- a/gpu/internal/driver/driver.go +++ b/gpu/internal/driver/driver.go @@ -54,6 +54,8 @@ type Device interface { Release() } +var ErrDeviceLost = errors.New("GPU device lost") + type LoadDesc struct { Action LoadAction ClearColor f32color.RGBA