Skip to content

Commit

Permalink
Merge pull request #2200 from billhollings/VK_EXT_metal_objects-ARC
Browse files Browse the repository at this point in the history
Fix crash when using VK_EXT_metal_objects under ARC.
  • Loading branch information
billhollings authored Apr 6, 2024
2 parents c0dce05 + 11a3adc commit 3f6a3c2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Released TBD

- To support legacy apps, restore `MoltenVK/dylib` directory via symlink to `MoltenVK/dynamic/dylib`.
- Add `MVKPerformanceTracker::previous` to track latest-but-one performance measurements.
- Fix crash when using `VK_EXT_metal_objects` under _ARC_.


MoltenVK 1.2.8
Expand Down
46 changes: 46 additions & 0 deletions Templates/Vulkan-Headers/VK_EXT_metal_objects-unret.gitdiff
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
diff --git a/include/vulkan/vulkan_metal.h b/include/vulkan/vulkan_metal.h
index e6f7bf7..c6bccf5 100644
--- a/include/vulkan/vulkan_metal.h
+++ b/include/vulkan/vulkan_metal.h
@@ -52,28 +52,28 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateMetalSurfaceEXT(
#define VK_EXT_metal_objects 1
#ifdef __OBJC__
@protocol MTLDevice;
-typedef id<MTLDevice> MTLDevice_id;
+typedef __unsafe_unretained id<MTLDevice> MTLDevice_id;
#else
typedef void* MTLDevice_id;
#endif

#ifdef __OBJC__
@protocol MTLCommandQueue;
-typedef id<MTLCommandQueue> MTLCommandQueue_id;
+typedef __unsafe_unretained id<MTLCommandQueue> MTLCommandQueue_id;
#else
typedef void* MTLCommandQueue_id;
#endif

#ifdef __OBJC__
@protocol MTLBuffer;
-typedef id<MTLBuffer> MTLBuffer_id;
+typedef __unsafe_unretained id<MTLBuffer> MTLBuffer_id;
#else
typedef void* MTLBuffer_id;
#endif

#ifdef __OBJC__
@protocol MTLTexture;
-typedef id<MTLTexture> MTLTexture_id;
+typedef __unsafe_unretained id<MTLTexture> MTLTexture_id;
#else
typedef void* MTLTexture_id;
#endif
@@ -81,7 +81,7 @@ typedef void* MTLTexture_id;
typedef struct __IOSurface* IOSurfaceRef;
#ifdef __OBJC__
@protocol MTLSharedEvent;
-typedef id<MTLSharedEvent> MTLSharedEvent_id;
+typedef __unsafe_unretained id<MTLSharedEvent> MTLSharedEvent_id;
#else
typedef void* MTLSharedEvent_id;
#endif
8 changes: 8 additions & 0 deletions fetchDependencies
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,14 @@ else
update_repo ${REPO_NAME} ${REPO_URL} ${REPO_REV}
fi

# Apply a Git diff file to add an __unsafe_unretained ownership
# qualifier to the Metal object declarations in vulkan_metal.h.
# This should be a temporary patch until the VK_EXT_metal_objects extension can be properly modified.
echo "Adding __unsafe_unretained ownership qualifier to the Metal objects in vulkan_metal.h."
cd ${REPO_NAME}
git apply ../../Templates/${REPO_NAME}/VK_EXT_metal_objects-unret.gitdiff
cd - > /dev/null


# ----------------- SPIRV-Cross -------------------

Expand Down

0 comments on commit 3f6a3c2

Please sign in to comment.