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>
This commit is contained in:
Corentin Wallez 2019-04-11 07:14:28 +00:00 committed by Commit Bot service account
parent f4c3f4562e
commit c005c9acf0
1 changed files with 9 additions and 0 deletions

View File

@ -104,6 +104,12 @@ namespace dawn_native { namespace metal {
return value; 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 } // anonymous namespace
// The Metal backend's Adapter. // The Metal backend's Adapter.
@ -155,6 +161,9 @@ namespace dawn_native { namespace metal {
} }
BackendConnection* Connect(InstanceBase* instance) { BackendConnection* Connect(InstanceBase* instance) {
if (!IsMetalSupported()) {
return nullptr;
}
return new Backend(instance); return new Backend(instance);
} }