internal/graphicsdriver/metal: improve an error message for Metal initialization

Updates #2732
This commit is contained in:
Hajime Hoshi 2023-08-26 12:43:16 +09:00
parent 4116fd3eb4
commit 592d6c57b7

View File

@ -75,14 +75,19 @@ const (
noStencil noStencil
) )
var systemDefaultDevice mtl.Device var (
systemDefaultDevice mtl.Device
systemDefaultDeviceErr error
)
func init() { func init() {
// mtl.CreateSystemDefaultDevice must be called on the main thread (#2147). // mtl.CreateSystemDefaultDevice must be called on the main thread (#2147).
d, err := mtl.CreateSystemDefaultDevice() d, err := mtl.CreateSystemDefaultDevice()
if err == nil { if err != nil {
systemDefaultDevice = d systemDefaultDeviceErr = err
return
} }
systemDefaultDevice = d
} }
// NewGraphics creates an implementation of graphicsdriver.Graphics for Metal. // NewGraphics creates an implementation of graphicsdriver.Graphics for Metal.
@ -91,8 +96,8 @@ func NewGraphics() (graphicsdriver.Graphics, error) {
// On old mac devices like iMac 2011, Metal is not supported (#779). // On old mac devices like iMac 2011, Metal is not supported (#779).
// TODO: Is there a better way to check whether Metal is available or not? // TODO: Is there a better way to check whether Metal is available or not?
// It seems OK to call MTLCreateSystemDefaultDevice multiple times, so this should be fine. // It seems OK to call MTLCreateSystemDefaultDevice multiple times, so this should be fine.
if systemDefaultDevice == (mtl.Device{}) { if systemDefaultDeviceErr != nil {
return nil, fmt.Errorf("metal: mtl.CreateSystemDefaultDevice failed") return nil, fmt.Errorf("metal: mtl.CreateSystemDefaultDevice failed: %w", systemDefaultDeviceErr)
} }
g := &Graphics{} g := &Graphics{}