From c005c9acf0512633ccfc7497ada99a2f620856bb Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Thu, 11 Apr 2019 07:14:28 +0000 Subject: [PATCH] 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 Reviewed-by: Kai Ninomiya Commit-Queue: Corentin Wallez --- src/dawn_native/metal/BackendMTL.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dawn_native/metal/BackendMTL.mm b/src/dawn_native/metal/BackendMTL.mm index 9e89ed1818..7030060895 100644 --- a/src/dawn_native/metal/BackendMTL.mm +++ b/src/dawn_native/metal/BackendMTL.mm @@ -104,6 +104,12 @@ namespace dawn_native { namespace metal { 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 @@ namespace dawn_native { namespace metal { } BackendConnection* Connect(InstanceBase* instance) { + if (!IsMetalSupported()) { + return nullptr; + } return new Backend(instance); }