Metal: Fail BackendConnection creation when Metal isn't supported
Chromium still supports macOS 10.10 that doesn't have Metal support and
calling any Metal function there results in a crash. Prevent using the
backend when Metal isn't present by not creating a BackendConnection.
BUG=chromium:852089
Change-Id: I53ffe6972f7b926b6bcbe740275fcee88b9df67a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/6480
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn_native/metal/BackendMTL.mm b/src/dawn_native/metal/BackendMTL.mm
index 9e89ed1..7030060 100644
--- a/src/dawn_native/metal/BackendMTL.mm
+++ b/src/dawn_native/metal/BackendMTL.mm
@@ -104,6 +104,12 @@
return value;
}
+
+ bool IsMetalSupported() {
+ // Metal was first introduced in macOS 10.11
+ NSOperatingSystemVersion macOS10_11 = {10, 11, 0};
+ return [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:macOS10_11];
+ }
} // anonymous namespace
// The Metal backend's Adapter.
@@ -155,6 +161,9 @@
}
BackendConnection* Connect(InstanceBase* instance) {
+ if (!IsMetalSupported()) {
+ return nullptr;
+ }
return new Backend(instance);
}