Title: [275683] trunk/Source/WebCore
Revision
275683
Author
commit-qu...@webkit.org
Date
2021-04-08 15:23:06 -0700 (Thu, 08 Apr 2021)

Log Message

[Metal ANGLE] check to see that a Metal device is available before selecting the backend.
https://bugs.webkit.org/show_bug.cgi?id=224341

Some platforms, including virtual machines, do not support Metal.
If we cannot create a default device, fall back on selecting the OpenGL backend.

Patch by Kyle Piddington <kpidding...@apple.com> on 2021-04-08
Reviewed by Dean Jackson.

* platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
(WebCore::platformSupportsMetal):
(WebCore::InitializeEGLDisplay):
Added Metal header include, and runtime check to ensure a metal device can be created before selecting the Metal backend.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (275682 => 275683)


--- trunk/Source/WebCore/ChangeLog	2021-04-08 22:14:30 UTC (rev 275682)
+++ trunk/Source/WebCore/ChangeLog	2021-04-08 22:23:06 UTC (rev 275683)
@@ -1,3 +1,18 @@
+2021-04-08  Kyle Piddington  <kpidding...@apple.com>
+
+        [Metal ANGLE] check to see that a Metal device is available before selecting the backend.    
+        https://bugs.webkit.org/show_bug.cgi?id=224341
+
+        Some platforms, including virtual machines, do not support Metal.
+        If we cannot create a default device, fall back on selecting the OpenGL backend.
+
+        Reviewed by Dean Jackson.
+
+        * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+        (WebCore::platformSupportsMetal):
+        (WebCore::InitializeEGLDisplay):
+        Added Metal header include, and runtime check to ensure a metal device can be created before selecting the Metal backend.
+
 2021-04-08  Chris Dumez  <cdu...@apple.com>
 
         Suspended OfflineAudioContext objects are leaking

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (275682 => 275683)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2021-04-08 22:14:30 UTC (rev 275682)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2021-04-08 22:23:06 UTC (rev 275683)
@@ -37,6 +37,7 @@
 #import "WebCoreThread.h"
 #import "WebGLLayer.h"
 #import <CoreGraphics/CGBitmapContext.h>
+#import <Metal/Metal.h>
 #import <wtf/BlockObjCExceptions.h>
 #import <wtf/darwin/WeakLinking.h>
 #import <wtf/text/CString.h>
@@ -84,6 +85,14 @@
 }
 #endif
 
+static bool platformSupportsMetal()
+{
+    if (MTLCreateSystemDefaultDevice())
+        return true;
+    
+    return false;
+}
+
 static ScopedEGLDefaultDisplay InitializeEGLDisplay(const GraphicsContextGLAttributes& attrs)
 {
     EGLint majorVersion = 0;
@@ -103,13 +112,13 @@
         displayAttributes.append(EGL_PLATFORM_ANGLE_DEVICE_CONTEXT_VOLATILE_CGL_ANGLE);
         displayAttributes.append(EGL_TRUE);
     }
-
-    if (attrs.useMetal) {
+    bool canUseMetal = platformSupportsMetal();
+    if (attrs.useMetal && canUseMetal) {
         displayAttributes.append(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
         displayAttributes.append(EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE);
     }
 
-    LOG(WebGL, "Attempting to use ANGLE's %s backend.", attrs.useMetal ? "Metal" : "OpenGL");
+    LOG(WebGL, "Attempting to use ANGLE's %s backend.", attrs.useMetal && canUseMetal ? "Metal" : "OpenGL");
 
     displayAttributes.append(EGL_NONE);
     display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), displayAttributes.data());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to