vulkan/handle: add some handle types

This commit is contained in:
Matthew Waters 2019-11-26 16:25:43 +11:00 committed by GStreamer Merge Bot
parent a7c2aa473f
commit 960784af1f
2 changed files with 183 additions and 8 deletions

View file

@ -19,10 +19,10 @@
*/ */
/** /**
* SECTION:vulkancommandbuffer * SECTION:vulkanhandle
* @title: vulkancommandbuffer * @title: vulkanhandle
* *
* vulkancommandbuffer holds information about a command buffer. * #GstVulkanHandle holds information about a vulkan handle.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@ -82,7 +82,7 @@ gst_vulkan_handle_init (GstVulkanHandle * handle, GstVulkanDevice * device,
/** /**
* gst_vulkan_handle_new_wrapped: * gst_vulkan_handle_new_wrapped:
* @handle: a Vulkan handle * @handle: a Vulkan handle
* @destroy: a #GDestroyNotify * @notify: (scope call): a #GDestroyNotify
* @user_data: data to pass to @notify * @user_data: data to pass to @notify
* *
* Returns: (transfer full): a new #GstVulkanHandle wrapping @handle * Returns: (transfer full): a new #GstVulkanHandle wrapping @handle
@ -102,10 +102,131 @@ gst_vulkan_handle_new_wrapped (GstVulkanDevice * device,
GST_DEFINE_MINI_OBJECT_TYPE (GstVulkanHandle, gst_vulkan_handle); GST_DEFINE_MINI_OBJECT_TYPE (GstVulkanHandle, gst_vulkan_handle);
/**
* gst_vulkan_handle_free_descriptor_set_layout:
* @handle: a #GstVulkanHandle containing a vulkan `VkDescriptorSetLayout`
* @user_data: callback user data
*
* Frees the descriptor set layout in @handle
*/
void void
gst_vulkan_handle_free_descriptor_set_layout (GstVulkanHandle * handle, gst_vulkan_handle_free_descriptor_set_layout (GstVulkanHandle * handle,
gpointer user_data) gpointer user_data)
{ {
g_return_if_fail (handle != NULL);
g_return_if_fail (handle->handle != VK_NULL_HANDLE);
g_return_if_fail (handle->type ==
GST_VULKAN_HANDLE_TYPE_DESCRIPTOR_SET_LAYOUT);
vkDestroyDescriptorSetLayout (handle->device->device, vkDestroyDescriptorSetLayout (handle->device->device,
(VkDescriptorSetLayout) handle->handle, NULL); (VkDescriptorSetLayout) handle->handle, NULL);
} }
/**
* gst_vulkan_handle_free_pipeline:
* @handle: a #GstVulkanHandle containing a vulkan `VkPipeline`
* @user_data: callback user data
*
* Frees the pipeline in @handle
*/
void
gst_vulkan_handle_free_pipeline (GstVulkanHandle * handle, gpointer user_data)
{
g_return_if_fail (handle != NULL);
g_return_if_fail (handle->handle != VK_NULL_HANDLE);
g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_PIPELINE);
vkDestroyPipeline (handle->device->device, (VkPipeline) handle->handle, NULL);
}
/**
* gst_vulkan_handle_free_pipeline_layout:
* @handle: a #GstVulkanHandle containing a vulkan `VkPipelineLayout`
* @user_data: callback user data
*
* Frees the pipeline layout in @handle
*/
void
gst_vulkan_handle_free_pipeline_layout (GstVulkanHandle * handle,
gpointer user_data)
{
g_return_if_fail (handle != NULL);
g_return_if_fail (handle->handle != VK_NULL_HANDLE);
g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_PIPELINE_LAYOUT);
vkDestroyPipelineLayout (handle->device->device,
(VkPipelineLayout) handle->handle, NULL);
}
/**
* gst_vulkan_handle_free_render_pass:
* @handle: a #GstVulkanHandle containing a vulkan `VkRenderPass`
* @user_data: callback user data
*
* Frees the render pass in @handle
*/
void
gst_vulkan_handle_free_render_pass (GstVulkanHandle * handle,
gpointer user_data)
{
g_return_if_fail (handle != NULL);
g_return_if_fail (handle->handle != VK_NULL_HANDLE);
g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_RENDER_PASS);
vkDestroyRenderPass (handle->device->device,
(VkRenderPass) handle->handle, NULL);
}
/**
* gst_vulkan_handle_free_sampler:
* @handle: a #GstVulkanHandle containing a vulkan `VkSampler`
* @user_data: callback user data
*
* Frees the sampler in @handle
*/
void
gst_vulkan_handle_free_sampler (GstVulkanHandle * handle, gpointer user_data)
{
g_return_if_fail (handle != NULL);
g_return_if_fail (handle->handle != VK_NULL_HANDLE);
g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_SAMPLER);
vkDestroySampler (handle->device->device, (VkSampler) handle->handle, NULL);
}
/**
* gst_vulkan_handle_free_framebuffer:
* @handle: a #GstVulkanHandle containing a vulkan `VkFramebuffer`
* @user_data: callback user data
*
* Frees the framebuffer in @handle
*/
void
gst_vulkan_handle_free_framebuffer (GstVulkanHandle * handle,
gpointer user_data)
{
g_return_if_fail (handle != NULL);
g_return_if_fail (handle->handle != VK_NULL_HANDLE);
g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_FRAMEBUFFER);
vkDestroyFramebuffer (handle->device->device, (VkFramebuffer) handle->handle,
NULL);
}
/**
* gst_vulkan_handle_free_shader:
* @handle: a #GstVulkanHandle containing a vulkan `VkFramebuffer`
* @user_data: callback user data
*
* Frees the shader in @handle
*/
void
gst_vulkan_handle_free_shader (GstVulkanHandle * handle, gpointer user_data)
{
g_return_if_fail (handle != NULL);
g_return_if_fail (handle->handle != VK_NULL_HANDLE);
g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_SHADER);
vkDestroyShaderModule (handle->device->device,
(VkShaderModule) handle->handle, NULL);
}

View file

@ -34,19 +34,48 @@ GType gst_vulkan_handle_get_type (void);
VK_DEFINE_NON_DISPATCHABLE_HANDLE(GstVulkanHandleTypedef) VK_DEFINE_NON_DISPATCHABLE_HANDLE(GstVulkanHandleTypedef)
/**
* GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT:
*
* The printf format specifier for raw Vulkan non dispatchable handles.
*/
#if GLIB_SIZEOF_VOID_P == 8 #if GLIB_SIZEOF_VOID_P == 8
# define GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT "p" # define GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT "p"
#else #else
# define GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT G_GUINT64_FORMAT # define GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT G_GUINT64_FORMAT
#endif #endif
/**
* GstVulkanHandleDestroyNotify:
* @handle: the #GstVulkanHandle
* @user_data: callback user data
*
* Function definition called when the #GstVulkanHandle is no longer in use.
* All implementations of this callback must free the internal handle stored
* inside @handle.
*/
typedef void (*GstVulkanHandleDestroyNotify) (GstVulkanHandle * handle, gpointer user_data); typedef void (*GstVulkanHandleDestroyNotify) (GstVulkanHandle * handle, gpointer user_data);
typedef enum typedef enum
{ {
GST_VULKAN_HANDLE_TYPE_DESCRIPTOR_SET_LAYOUT = 1, GST_VULKAN_HANDLE_TYPE_DESCRIPTOR_SET_LAYOUT = 1,
GST_VULKAN_HANDLE_TYPE_PIPELINE_LAYOUT = 2,
GST_VULKAN_HANDLE_TYPE_PIPELINE = 3,
GST_VULKAN_HANDLE_TYPE_RENDER_PASS = 4,
GST_VULKAN_HANDLE_TYPE_SAMPLER = 5,
GST_VULKAN_HANDLE_TYPE_FRAMEBUFFER = 6,
GST_VULKAN_HANDLE_TYPE_SHADER = 7,
} GstVulkanHandleType; } GstVulkanHandleType;
/**
* GstVulkanHandle:
* @parent: the parent #GstMiniObject
* @device: the #GstVulkanDevice for this handle
* @type: the type of handle
* @handle: the handle value
*
* Holds information about a vulkan non dispatchable handle
*/
struct _GstVulkanHandle struct _GstVulkanHandle
{ {
GstMiniObject parent; GstMiniObject parent;
@ -59,15 +88,20 @@ struct _GstVulkanHandle
/* <protected> */ /* <protected> */
GstVulkanHandleDestroyNotify notify; GstVulkanHandleDestroyNotify notify;
gpointer user_data; gpointer user_data;
/* <private> */
gpointer _reserved [GST_PADDING];
}; };
/** /**
* gst_vulkan_handle_ref: (skip) * gst_vulkan_handle_ref: (skip)
* @cmd: a #GstVulkanHandle. * @handle: a #GstVulkanHandle.
* *
* Increases the refcount of the given handle by one. * Increases the refcount of the given handle by one.
* *
* Returns: (transfer full): @buf * Returns: (transfer full): @buf
*
* Since: 1.18
*/ */
static inline GstVulkanHandle* gst_vulkan_handle_ref(GstVulkanHandle* handle); static inline GstVulkanHandle* gst_vulkan_handle_ref(GstVulkanHandle* handle);
static inline GstVulkanHandle * static inline GstVulkanHandle *
@ -78,10 +112,12 @@ gst_vulkan_handle_ref (GstVulkanHandle * handle)
/** /**
* gst_vulkan_handle_unref: (skip) * gst_vulkan_handle_unref: (skip)
* @cmd: (transfer full): a #GstVulkanHandle. * @handle: (transfer full): a #GstVulkanHandle.
* *
* Decreases the refcount of the buffer. If the refcount reaches 0, the buffer * Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
* will be freed. * will be freed.
*
* Since: 1.18
*/ */
static inline void gst_vulkan_handle_unref(GstVulkanHandle* handle); static inline void gst_vulkan_handle_unref(GstVulkanHandle* handle);
static inline void static inline void
@ -101,7 +137,7 @@ gst_vulkan_handle_unref (GstVulkanHandle * handle)
* If the reference is %NULL then this function does nothing. Otherwise, the * If the reference is %NULL then this function does nothing. Otherwise, the
* reference count of the handle is decreased and the pointer is set to %NULL. * reference count of the handle is decreased and the pointer is set to %NULL.
* *
* Since: 1.16 * Since: 1.18
*/ */
static inline void static inline void
gst_clear_vulkan_handle (GstVulkanHandle ** handle_ptr) gst_clear_vulkan_handle (GstVulkanHandle ** handle_ptr)
@ -119,6 +155,24 @@ GstVulkanHandle * gst_vulkan_handle_new_wrapped (GstVulkanDevice *de
GST_VULKAN_API GST_VULKAN_API
void gst_vulkan_handle_free_descriptor_set_layout (GstVulkanHandle * handle, void gst_vulkan_handle_free_descriptor_set_layout (GstVulkanHandle * handle,
gpointer user_data); gpointer user_data);
GST_VULKAN_API
void gst_vulkan_handle_free_pipeline_layout (GstVulkanHandle * handle,
gpointer user_data);
GST_VULKAN_API
void gst_vulkan_handle_free_pipeline (GstVulkanHandle * handle,
gpointer user_data);
GST_VULKAN_API
void gst_vulkan_handle_free_render_pass (GstVulkanHandle * handle,
gpointer user_data);
GST_VULKAN_API
void gst_vulkan_handle_free_sampler (GstVulkanHandle * handle,
gpointer user_data);
GST_VULKAN_API
void gst_vulkan_handle_free_framebuffer (GstVulkanHandle * handle,
gpointer user_data);
GST_VULKAN_API
void gst_vulkan_handle_free_shader (GstVulkanHandle * handle,
gpointer user_data);
G_END_DECLS G_END_DECLS