From f738c1f138fa40c04ec14cb9aee2ee5a760bad56 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Wed, 16 Oct 2019 17:47:33 +1100 Subject: [PATCH] vulkan: fix non-dispatchable handles on 32-bit platforms non-dispatchable handles are 64-bit integers on 32-bit platforms --- gst-libs/gst/vulkan/gstvktrash.c | 40 ++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/gst-libs/gst/vulkan/gstvktrash.c b/gst-libs/gst/vulkan/gstvktrash.c index 6364ac8483..a9253f6304 100644 --- a/gst-libs/gst/vulkan/gstvktrash.c +++ b/gst-libs/gst/vulkan/gstvktrash.c @@ -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; \