vktrash: add more destruction of vulkan types

This commit is contained in:
Matthew Waters 2019-05-16 19:33:06 +10:00
parent d61e771c37
commit ca38c2f25e
2 changed files with 128 additions and 57 deletions

View file

@ -138,58 +138,106 @@ gst_vulkan_trash_list_wait (GList * trash_list, guint64 timeout)
return err == VK_SUCCESS;
}
struct cmd_buffer_free_info
{
GstVulkanCommandPool *pool;
VkCommandBuffer cmd;
};
#define FREE_DESTROY_FUNC(func, type, type_name) \
static void \
G_PASTE(_free_,type_name) (GstVulkanDevice * device, type resource) \
{ \
GST_TRACE_OBJECT (device, "Freeing vulkan " G_STRINGIFY (type) " %p", resource); \
func (device->device, resource, NULL); \
} \
GstVulkanTrash * \
G_PASTE(gst_vulkan_trash_new_free_,type_name) (GstVulkanFence * fence, \
type type_name) \
{ \
GstVulkanTrash *trash; \
g_return_val_if_fail (type_name != NULL, NULL); \
trash = gst_vulkan_trash_new (fence, \
(GstVulkanTrashNotify) G_PASTE(_free_,type_name), type_name); \
return trash; \
}
static void
_free_command_buffer (GstVulkanDevice * device,
struct cmd_buffer_free_info *info)
{
vkFreeCommandBuffers (device->device, info->pool->pool, 1, &info->cmd);
gst_object_unref (info->pool);
FREE_DESTROY_FUNC (vkDestroyDescriptorPool, VkDescriptorPool, descriptor_pool)
FREE_DESTROY_FUNC (vkDestroyDescriptorSetLayout, VkDescriptorSetLayout,
descriptor_set_layout)
FREE_DESTROY_FUNC (vkDestroyFramebuffer, VkFramebuffer, framebuffer)
FREE_DESTROY_FUNC (vkDestroyPipeline, VkPipeline, pipeline)
FREE_DESTROY_FUNC (vkDestroyPipelineLayout, VkPipelineLayout, pipeline_layout)
FREE_DESTROY_FUNC (vkDestroyRenderPass, VkRenderPass, render_pass)
FREE_DESTROY_FUNC (vkDestroySemaphore, VkSemaphore, semaphore)
FREE_DESTROY_FUNC (vkDestroySampler, VkSampler, sampler)
#define FREE_WITH_GST_PARENT(func, type, type_name, parent_type, parent_resource) \
struct G_PASTE(free_parent_info_,type_name) \
{ \
parent_type parent; \
type resource; \
}; \
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); \
func (device->device, info->parent parent_resource, 1, &info->resource); \
gst_object_unref (info->parent); \
g_free (info); \
} \
GstVulkanTrash * \
G_PASTE(gst_vulkan_trash_new_free_,type_name) (GstVulkanFence * fence, \
parent_type parent, type type_name) \
{ \
struct G_PASTE(free_parent_info_,type_name) *info; \
GstVulkanTrash *trash; \
g_return_val_if_fail (type_name != NULL, NULL); \
info = g_new0 (struct G_PASTE(free_parent_info_,type_name), 1); \
info->parent = gst_object_ref (parent); \
info->resource = (gpointer) type_name; \
trash = gst_vulkan_trash_new (fence, \
(GstVulkanTrashNotify) G_PASTE(_free_,type_name), info); \
return trash; \
}
FREE_WITH_GST_PARENT (vkFreeCommandBuffers, VkCommandBuffer, command_buffer,
GstVulkanCommandPool *,->pool)
#define FREE_WITH_VK_PARENT(func, type, type_name, parent_type) \
struct G_PASTE(free_parent_info_,type_name) \
{ \
parent_type parent; \
type resource; \
}; \
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); \
func (device->device, info->parent, 1, &info->resource); \
g_free (info); \
} \
GstVulkanTrash * \
G_PASTE(gst_vulkan_trash_new_free_,type_name) (GstVulkanFence * fence, \
parent_type parent, type type_name) \
{ \
struct G_PASTE(free_parent_info_,type_name) *info; \
GstVulkanTrash *trash; \
g_return_val_if_fail (type_name != NULL, NULL); \
info = g_new0 (struct G_PASTE(free_parent_info_,type_name), 1); \
/* FIXME: keep parent alive ? */\
info->parent = parent; \
info->resource = (gpointer) type_name; \
trash = gst_vulkan_trash_new (fence, \
(GstVulkanTrashNotify) G_PASTE(_free_,type_name), info); \
return trash; \
}
FREE_WITH_VK_PARENT (vkFreeDescriptorSets, VkDescriptorSet, descriptor_set,
VkDescriptorPool)
g_free (info);
static void
_trash_object_unref (GstVulkanDevice * device, GstObject * object)
{
gst_object_unref (object);
}
GstVulkanTrash *
gst_vulkan_trash_new_free_command_buffer (GstVulkanFence * fence,
GstVulkanCommandPool * pool, VkCommandBuffer cmd)
gst_vulkan_trash_new_object_unref (GstVulkanFence * fence, GstObject * object)
{
struct cmd_buffer_free_info *info;
GstVulkanTrash *trash;
info = g_new0 (struct cmd_buffer_free_info, 1);
info->pool = gst_object_ref (pool);
info->cmd = cmd;
g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
trash = gst_vulkan_trash_new (fence,
(GstVulkanTrashNotify) _free_command_buffer, info);
return trash;
}
static void
_free_semaphore (GstVulkanDevice * device, VkSemaphore * semaphore)
{
if (semaphore)
vkDestroySemaphore (device->device, *semaphore, NULL);
g_free (semaphore);
}
GstVulkanTrash *
gst_vulkan_trash_new_free_semaphore (GstVulkanFence * fence,
VkSemaphore semaphore)
{
VkSemaphore *data;
GstVulkanTrash *trash;
data = g_new0 (VkSemaphore, 1);
*data = semaphore;
trash = gst_vulkan_trash_new (fence,
(GstVulkanTrashNotify) _free_semaphore, data);
(GstVulkanTrashNotify) _trash_object_unref, object);
return trash;
}

View file

@ -37,19 +37,42 @@ struct _GstVulkanTrash
gpointer user_data;
};
GstVulkanTrash * gst_vulkan_trash_new (GstVulkanFence * fence,
GstVulkanTrashNotify notify,
gpointer user_data);
GstVulkanTrash * gst_vulkan_trash_new_free_command_buffer (GstVulkanFence * fence,
GstVulkanCommandPool * pool,
VkCommandBuffer cmd);
GstVulkanTrash * gst_vulkan_trash_new_free_semaphore (GstVulkanFence * fence,
VkSemaphore cmd);
void gst_vulkan_trash_free (GstVulkanTrash * trash);
GstVulkanTrash * gst_vulkan_trash_new (GstVulkanFence * fence,
GstVulkanTrashNotify notify,
gpointer user_data);
GList * gst_vulkan_trash_list_gc (GList * trash_list);
gboolean gst_vulkan_trash_list_wait (GList * trash_list,
guint64 timeout);
GstVulkanTrash * gst_vulkan_trash_new_free_descriptor_pool (GstVulkanFence * fence,
VkDescriptorPool descriptor_pool);
GstVulkanTrash * gst_vulkan_trash_new_free_descriptor_set_layout (GstVulkanFence * fence,
VkDescriptorSetLayout descriptor_set_layout);
GstVulkanTrash * gst_vulkan_trash_new_free_framebuffer (GstVulkanFence * fence,
VkFramebuffer framebuffer);
GstVulkanTrash * gst_vulkan_trash_new_free_pipeline (GstVulkanFence * fence,
VkPipeline pipeline);
GstVulkanTrash * gst_vulkan_trash_new_free_pipeline_layout (GstVulkanFence * fence,
VkPipelineLayout pipeline_layout);
GstVulkanTrash * gst_vulkan_trash_new_free_render_pass (GstVulkanFence * fence,
VkRenderPass render_pass);
GstVulkanTrash * gst_vulkan_trash_new_free_sampler (GstVulkanFence * fence,
VkSampler sampler);
GstVulkanTrash * gst_vulkan_trash_new_free_semaphore (GstVulkanFence * fence,
VkSemaphore semaphore);
GstVulkanTrash * gst_vulkan_trash_new_free_command_buffer (GstVulkanFence * fence,
GstVulkanCommandPool * parent,
VkCommandBuffer command_buffer);
GstVulkanTrash * gst_vulkan_trash_new_free_descriptor_set (GstVulkanFence * fence,
VkDescriptorPool parent,
VkDescriptorSet descriptor_set);
GstVulkanTrash * gst_vulkan_trash_new_object_unref (GstVulkanFence * fence,
GstObject * object);
void gst_vulkan_trash_free (GstVulkanTrash * trash);
GList * gst_vulkan_trash_list_gc (GList * trash_list);
gboolean gst_vulkan_trash_list_wait (GList * trash_list,
guint64 timeout);
G_END_DECLS