vulkan: fix non-dispatchable handles on 32-bit platforms
authorMatthew Waters <matthew@centricular.com>
Wed, 16 Oct 2019 06:47:33 +0000 (17:47 +1100)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 7 Nov 2019 20:01:57 +0000 (20:01 +0000)
non-dispatchable handles are 64-bit integers on 32-bit platforms

gst-libs/gst/vulkan/gstvktrash.c

index 6364ac8..a9253f6 100644 (file)
@@ -89,11 +89,34 @@ gst_vulkan_trash_new (GstVulkanFence * fence, GstVulkanTrashNotify notify,
   return ret;
 }
 
+#if GLIB_SIZEOF_VOID_P == 8
+# define VK_NON_DISPATCHABLE_HANDLE_FORMAT "p"
+# define GstVulkanHandleType void *
+# define PUSH_NON_DISPATCHABLE_HANDLE_TO_GPOINTER(pointer, handle) pointer = (gpointer) handle
+# define TAKE_NON_DISPATCHABLE_HANDLE_FROM_GPOINTER(handle, type, pointer) handle = (type) pointer
+#else
+# define VK_NON_DISPATCHABLE_HANDLE_FORMAT G_GUINT64_FORMAT
+# define GstVulkanHandleType guint64
+# define PUSH_NON_DISPATCHABLE_HANDLE_TO_GPOINTER(pointer, handle) \
+    G_STMT_START { \
+      pointer = g_new0(guint64, 1); \
+      *((GstVulkanHandleType *) pointer) = (GstVulkanHandleType) handle; \
+    } G_STMT_END
+# define TAKE_NON_DISPATCHABLE_HANDLE_FROM_GPOINTER(handle, type, pointer) \
+    G_STMT_START { \
+      handle = *((type *) pointer); \
+      g_free (pointer); \
+    } G_STMT_END
+#endif
+
 #define FREE_DESTROY_FUNC(func, type, type_name) \
 static void \
-G_PASTE(_free_,type_name) (GstVulkanDevice * device, type resource) \
+G_PASTE(_free_,type_name) (GstVulkanDevice * device, gpointer resource_handle) \
 { \
-  GST_TRACE_OBJECT (device, "Freeing vulkan " G_STRINGIFY (type) " %p", resource); \
+  type resource; \
+  TAKE_NON_DISPATCHABLE_HANDLE_FROM_GPOINTER(resource, type, resource_handle); \
+  GST_TRACE_OBJECT (device, "Freeing vulkan " G_STRINGIFY (type) \
+      " %" VK_NON_DISPATCHABLE_HANDLE_FORMAT, resource); \
   func (device->device, resource, NULL); \
 } \
 GstVulkanTrash * \
@@ -101,9 +124,11 @@ G_PASTE(gst_vulkan_trash_new_free_,type_name) (GstVulkanFence * fence, \
     type type_name) \
 { \
   GstVulkanTrash *trash; \
-  g_return_val_if_fail (type_name != VK_NULL_HANDLE, NULL); \
+  gpointer handle_data; \
+  PUSH_NON_DISPATCHABLE_HANDLE_TO_GPOINTER(handle_data, type_name); \
+  g_return_val_if_fail (type_name != VK_NULL_HANDLE, VK_NULL_HANDLE); \
   trash = gst_vulkan_trash_new (fence, \
-      (GstVulkanTrashNotify) G_PASTE(_free_,type_name), type_name); \
+      (GstVulkanTrashNotify) G_PASTE(_free_,type_name), handle_data); \
   return trash; \
 }
 
@@ -125,7 +150,8 @@ struct G_PASTE(free_parent_info_,type_name) \
 static void \
 G_PASTE(_free_,type_name) (GstVulkanDevice * device, struct G_PASTE(free_parent_info_,type_name) *info) \
 { \
-  GST_TRACE_OBJECT (device, "Freeing vulkan " G_STRINGIFY (type) " %p", info->resource); \
+  GST_TRACE_OBJECT (device, "Freeing vulkan " G_STRINGIFY (type) \
+      " %" VK_NON_DISPATCHABLE_HANDLE_FORMAT, info->resource); \
   func (device->device, info->parent, 1, &info->resource); \
   g_free (info); \
 } \
@@ -135,11 +161,11 @@ G_PASTE(gst_vulkan_trash_new_free_,type_name) (GstVulkanFence * fence, \
 { \
   struct G_PASTE(free_parent_info_,type_name) *info; \
   GstVulkanTrash *trash; \
-  g_return_val_if_fail (type_name != VK_NULL_HANDLE, NULL); \
+  g_return_val_if_fail (type_name != VK_NULL_HANDLE, VK_NULL_HANDLE); \
   info = g_new0 (struct G_PASTE(free_parent_info_,type_name), 1); \
   /* FIXME: keep parent alive ? */\
   info->parent = parent; \
-  info->resource = (gpointer) type_name; \
+  info->resource = (GstVulkanHandleType) type_name; \
   trash = gst_vulkan_trash_new (fence, \
       (GstVulkanTrashNotify) G_PASTE(_free_,type_name), info); \
   return trash; \