SDL: GPU: Explicitly check Metal hardware support on device creation

From a27c139b12b6c9bb7b3d307fb9cb5311b08b5b19 Mon Sep 17 00:00:00 2001
From: Caleb Cornett <[EMAIL REDACTED]>
Date: Mon, 23 Dec 2024 22:29:28 -0500
Subject: [PATCH] GPU: Explicitly check Metal hardware support on device
 creation

---
 src/gpu/metal/SDL_gpu_metal.m | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/gpu/metal/SDL_gpu_metal.m b/src/gpu/metal/SDL_gpu_metal.m
index 028e18a438633..d2a970a18b1a1 100644
--- a/src/gpu/metal/SDL_gpu_metal.m
+++ b/src/gpu/metal/SDL_gpu_metal.m
@@ -4180,7 +4180,7 @@ static bool METAL_SupportsTextureFormat(
 
 static bool METAL_PrepareDriver(SDL_VideoDevice *this)
 {
-    if (@available(macOS 10.13, iOS 13.0, tvOS 13.0, *)) {
+    if (@available(macOS 10.14, iOS 13.0, tvOS 13.0, *)) {
         return (this->Metal_CreateView != NULL);
     }
     return false;
@@ -4342,6 +4342,7 @@ static void METAL_INTERNAL_DestroyBlitResources(
     @autoreleasepool {
         MetalRenderer *renderer;
         id<MTLDevice> device = NULL;
+        bool hasHardwareSupport = false;
 
         if (debugMode) {
             /* Due to a Metal driver quirk, once a MTLDevice has been created
@@ -4372,6 +4373,23 @@ static void METAL_INTERNAL_DestroyBlitResources(
             }
         }
 
+#ifdef SDL_PLATFORM_MACOS
+        if (@available(macOS 10.15, *)) {
+            hasHardwareSupport = [device supportsFamily:MTLGPUFamilyMac2];
+        } else if (@available(macOS 10.14, *)) {
+            hasHardwareSupport = [device supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily2_v1];
+        }
+#else
+        if (@available(iOS 13.0, tvOS 13.0, *)) {
+            hasHardwareSupport = [device supportsFamily:MTLGPUFamilyApple3];
+        }
+#endif
+
+        if (!hasHardwareSupport) {
+            SDL_SetError("Device does not meet the hardware requirements for SDL_GPU Metal");
+            return NULL;
+        }
+
         // Allocate and zero out the renderer
         renderer = (MetalRenderer *)SDL_calloc(1, sizeof(MetalRenderer));