SDL: vulkan_metal.h: Make compatible with ObjC ARC (thanks @jmroot!) (8386d)

From 8386daddcbf6ee5f81f3a2f74747ba748d75335e Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 2 Feb 2024 18:29:59 -0800
Subject: [PATCH] vulkan_metal.h: Make compatible with ObjC ARC (thanks
 @jmroot!)

(re)Fixes #6598

We need to remember to apply this again once we update from upstream headers.

(cherry picked from commit e67e0c5d55874d4b18def5709ce8c25934073700)
(cherry picked from commit fc787a41dc3c8ad0c4ba7d5a35da9d9b3e6ae320)
---
 src/video/khronos/vulkan/vulkan_metal.h | 26 ++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/video/khronos/vulkan/vulkan_metal.h b/src/video/khronos/vulkan/vulkan_metal.h
index e6f7bf7a702c..badb45078add 100644
--- a/src/video/khronos/vulkan/vulkan_metal.h
+++ b/src/video/khronos/vulkan/vulkan_metal.h
@@ -27,6 +27,14 @@ extern "C" {
 typedef void CAMetalLayer;
 #endif
 
+#define SDL_UNSAFE_UNRETAINED
+#if defined(__OBJC__) && defined(__has_feature)
+#if __has_feature(objc_arc)
+#undef SDL_UNSAFE_UNRETAINED
+#define SDL_UNSAFE_UNRETAINED __unsafe_unretained
+#endif
+#endif
+
 #define VK_EXT_METAL_SURFACE_SPEC_VERSION 1
 #define VK_EXT_METAL_SURFACE_EXTENSION_NAME "VK_EXT_metal_surface"
 typedef VkFlags VkMetalSurfaceCreateFlagsEXT;
@@ -34,7 +42,7 @@ typedef struct VkMetalSurfaceCreateInfoEXT {
     VkStructureType                 sType;
     const void*                     pNext;
     VkMetalSurfaceCreateFlagsEXT    flags;
-    const CAMetalLayer*             pLayer;
+    const CAMetalLayer SDL_UNSAFE_UNRETAINED *pLayer;
 } VkMetalSurfaceCreateInfoEXT;
 
 typedef VkResult (VKAPI_PTR *PFN_vkCreateMetalSurfaceEXT)(VkInstance instance, const VkMetalSurfaceCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
@@ -113,27 +121,27 @@ typedef struct VkExportMetalObjectsInfoEXT {
 typedef struct VkExportMetalDeviceInfoEXT {
     VkStructureType    sType;
     const void*        pNext;
-    MTLDevice_id       mtlDevice;
+    MTLDevice_id SDL_UNSAFE_UNRETAINED mtlDevice;
 } VkExportMetalDeviceInfoEXT;
 
 typedef struct VkExportMetalCommandQueueInfoEXT {
     VkStructureType       sType;
     const void*           pNext;
     VkQueue               queue;
-    MTLCommandQueue_id    mtlCommandQueue;
+    MTLCommandQueue_id SDL_UNSAFE_UNRETAINED mtlCommandQueue;
 } VkExportMetalCommandQueueInfoEXT;
 
 typedef struct VkExportMetalBufferInfoEXT {
     VkStructureType    sType;
     const void*        pNext;
     VkDeviceMemory     memory;
-    MTLBuffer_id       mtlBuffer;
+    MTLBuffer_id SDL_UNSAFE_UNRETAINED mtlBuffer;
 } VkExportMetalBufferInfoEXT;
 
 typedef struct VkImportMetalBufferInfoEXT {
     VkStructureType    sType;
     const void*        pNext;
-    MTLBuffer_id       mtlBuffer;
+    MTLBuffer_id SDL_UNSAFE_UNRETAINED mtlBuffer;
 } VkImportMetalBufferInfoEXT;
 
 typedef struct VkExportMetalTextureInfoEXT {
@@ -143,14 +151,14 @@ typedef struct VkExportMetalTextureInfoEXT {
     VkImageView              imageView;
     VkBufferView             bufferView;
     VkImageAspectFlagBits    plane;
-    MTLTexture_id            mtlTexture;
+    MTLTexture_id SDL_UNSAFE_UNRETAINED mtlTexture;
 } VkExportMetalTextureInfoEXT;
 
 typedef struct VkImportMetalTextureInfoEXT {
     VkStructureType          sType;
     const void*              pNext;
     VkImageAspectFlagBits    plane;
-    MTLTexture_id            mtlTexture;
+    MTLTexture_id SDL_UNSAFE_UNRETAINED mtlTexture;
 } VkImportMetalTextureInfoEXT;
 
 typedef struct VkExportMetalIOSurfaceInfoEXT {
@@ -171,13 +179,13 @@ typedef struct VkExportMetalSharedEventInfoEXT {
     const void*          pNext;
     VkSemaphore          semaphore;
     VkEvent              event;
-    MTLSharedEvent_id    mtlSharedEvent;
+    MTLSharedEvent_id SDL_UNSAFE_UNRETAINED mtlSharedEvent;
 } VkExportMetalSharedEventInfoEXT;
 
 typedef struct VkImportMetalSharedEventInfoEXT {
     VkStructureType      sType;
     const void*          pNext;
-    MTLSharedEvent_id    mtlSharedEvent;
+    MTLSharedEvent_id SDL_UNSAFE_UNRETAINED mtlSharedEvent;
 } VkImportMetalSharedEventInfoEXT;
 
 typedef void (VKAPI_PTR *PFN_vkExportMetalObjectsEXT)(VkDevice device, VkExportMetalObjectsInfoEXT* pMetalObjectsInfo);