2015-10-24 06:29:05 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2019-04-08 11:35:22 +00:00
|
|
|
#include "gstvkqueue.h"
|
2015-10-24 06:29:05 +00:00
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* SECTION:vkqueue
|
|
|
|
* @title: GstVulkanQueue
|
|
|
|
* @short_description: Vulkan command queue
|
|
|
|
* @see_also: #GstVulkanDevice
|
|
|
|
*
|
|
|
|
* GstVulkanQueue encapsulates the vulkan command queue.
|
|
|
|
*/
|
|
|
|
|
2015-10-24 06:29:05 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_vulkan_queue_debug
|
|
|
|
GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
|
2016-02-16 00:22:37 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_CONTEXT);
|
2015-10-24 06:29:05 +00:00
|
|
|
|
2019-06-11 08:37:59 +00:00
|
|
|
static void
|
|
|
|
_init_debug (void)
|
|
|
|
{
|
|
|
|
static volatile gsize init;
|
|
|
|
|
|
|
|
if (g_once_init_enter (&init)) {
|
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "vulkanqueue", 0, "Vulkan Queue");
|
|
|
|
GST_DEBUG_CATEGORY_GET (GST_CAT_CONTEXT, "GST_CONTEXT");
|
|
|
|
g_once_init_leave (&init, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-13 23:00:35 +00:00
|
|
|
struct _GstVulkanQueuePrivate
|
|
|
|
{
|
|
|
|
GMutex submit_lock;
|
|
|
|
};
|
|
|
|
|
2019-04-10 04:27:26 +00:00
|
|
|
#define parent_class gst_vulkan_queue_parent_class
|
2015-10-24 06:29:05 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVulkanQueue, gst_vulkan_queue, GST_TYPE_OBJECT,
|
2019-11-13 23:00:35 +00:00
|
|
|
G_ADD_PRIVATE (GstVulkanQueue); _init_debug ());
|
|
|
|
|
|
|
|
#define GET_PRIV(queue) gst_vulkan_queue_get_instance_private (queue)
|
2015-10-24 06:29:05 +00:00
|
|
|
|
|
|
|
static void gst_vulkan_queue_dispose (GObject * object);
|
|
|
|
|
|
|
|
static void
|
2019-11-13 23:00:35 +00:00
|
|
|
gst_vulkan_queue_init (GstVulkanQueue * queue)
|
2015-10-24 06:29:05 +00:00
|
|
|
{
|
2019-11-13 23:00:35 +00:00
|
|
|
GstVulkanQueuePrivate *priv = GET_PRIV (queue);
|
|
|
|
|
|
|
|
g_mutex_init (&priv->submit_lock);
|
2015-10-24 06:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-13 23:00:35 +00:00
|
|
|
gst_vulkan_queue_class_init (GstVulkanQueueClass * queue_class)
|
2015-10-24 06:29:05 +00:00
|
|
|
{
|
2019-11-13 23:00:35 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) queue_class;
|
2015-10-24 06:29:05 +00:00
|
|
|
|
|
|
|
gobject_class->dispose = gst_vulkan_queue_dispose;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vulkan_queue_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstVulkanQueue *queue = GST_VULKAN_QUEUE (object);
|
2019-11-13 23:00:35 +00:00
|
|
|
GstVulkanQueuePrivate *priv = GET_PRIV (queue);
|
2015-10-24 06:29:05 +00:00
|
|
|
|
|
|
|
if (queue->device)
|
|
|
|
gst_object_unref (queue->device);
|
|
|
|
queue->device = NULL;
|
2019-04-10 04:27:26 +00:00
|
|
|
|
2019-11-13 23:00:35 +00:00
|
|
|
g_mutex_clear (&priv->submit_lock);
|
|
|
|
|
2019-04-10 04:27:26 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2015-10-24 06:29:05 +00:00
|
|
|
}
|
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_queue_get_device
|
|
|
|
* @queue: a #GstVulkanQueue
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the #GstVulkanDevice for @queue
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2015-10-24 06:29:05 +00:00
|
|
|
GstVulkanDevice *
|
|
|
|
gst_vulkan_queue_get_device (GstVulkanQueue * queue)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_QUEUE (queue), NULL);
|
|
|
|
|
|
|
|
return queue->device ? gst_object_ref (queue->device) : NULL;
|
|
|
|
}
|
2016-02-16 00:22:37 +00:00
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_queue_create_command_pool:
|
|
|
|
* @queue: a #GstVulkanQueue
|
|
|
|
* @error: a #GError
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new #GstVUlkanCommandPool or %NULL
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2019-04-10 04:27:26 +00:00
|
|
|
GstVulkanCommandPool *
|
|
|
|
gst_vulkan_queue_create_command_pool (GstVulkanQueue * queue, GError ** error)
|
|
|
|
{
|
|
|
|
GstVulkanCommandPool *pool;
|
|
|
|
VkCommandPoolCreateInfo cmd_pool_info = { 0, };
|
|
|
|
VkCommandPool vk_pool;
|
|
|
|
VkResult err;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_QUEUE (queue), NULL);
|
|
|
|
|
|
|
|
cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
|
|
|
cmd_pool_info.pNext = NULL;
|
|
|
|
cmd_pool_info.queueFamilyIndex = queue->family;
|
2019-09-17 12:24:04 +00:00
|
|
|
cmd_pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
2019-04-10 04:27:26 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (queue->device);
|
|
|
|
err =
|
|
|
|
vkCreateCommandPool (queue->device->device, &cmd_pool_info, NULL,
|
|
|
|
&vk_pool);
|
|
|
|
if (gst_vulkan_error_to_g_error (err, error, "vkCreateCommandPool") < 0) {
|
|
|
|
GST_OBJECT_LOCK (queue->device);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (queue->device);
|
|
|
|
|
|
|
|
pool = g_object_new (GST_TYPE_VULKAN_COMMAND_POOL, NULL);
|
|
|
|
gst_object_ref_sink (pool);
|
|
|
|
pool->queue = gst_object_ref (queue);
|
|
|
|
pool->pool = vk_pool;
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
|
|
|
|
error:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-16 00:22:37 +00:00
|
|
|
/**
|
|
|
|
* gst_context_set_vulkan_queue:
|
|
|
|
* @context: a #GstContext
|
|
|
|
* @queue: a #GstVulkanQueue
|
|
|
|
*
|
|
|
|
* Sets @queue on @context
|
|
|
|
*
|
2019-04-11 06:52:54 +00:00
|
|
|
* Since: 1.18
|
2016-02-16 00:22:37 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_context_set_vulkan_queue (GstContext * context, GstVulkanQueue * queue)
|
|
|
|
{
|
|
|
|
GstStructure *s;
|
|
|
|
|
|
|
|
g_return_if_fail (context != NULL);
|
|
|
|
g_return_if_fail (gst_context_is_writable (context));
|
|
|
|
|
|
|
|
if (queue)
|
|
|
|
GST_CAT_LOG (GST_CAT_CONTEXT,
|
|
|
|
"setting GstVulkanQueue(%" GST_PTR_FORMAT ") on context(%"
|
|
|
|
GST_PTR_FORMAT ")", queue, context);
|
|
|
|
|
|
|
|
s = gst_context_writable_structure (context);
|
|
|
|
gst_structure_set (s, GST_VULKAN_QUEUE_CONTEXT_TYPE_STR,
|
|
|
|
GST_TYPE_VULKAN_QUEUE, queue, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_context_get_vulkan_queue:
|
|
|
|
* @context: a #GstContext
|
|
|
|
* @queue: resulting #GstVulkanQueue
|
|
|
|
*
|
|
|
|
* Returns: Whether @queue was in @context
|
|
|
|
*
|
2019-04-11 06:52:54 +00:00
|
|
|
* Since: 1.18
|
2016-02-16 00:22:37 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_context_get_vulkan_queue (GstContext * context, GstVulkanQueue ** queue)
|
|
|
|
{
|
|
|
|
const GstStructure *s;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (queue != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (context != NULL, FALSE);
|
|
|
|
|
|
|
|
s = gst_context_get_structure (context);
|
|
|
|
ret = gst_structure_get (s, GST_VULKAN_QUEUE_CONTEXT_TYPE_STR,
|
|
|
|
GST_TYPE_VULKAN_QUEUE, queue, NULL);
|
|
|
|
|
|
|
|
GST_CAT_LOG (GST_CAT_CONTEXT, "got GstVulkanQueue(%" GST_PTR_FORMAT
|
|
|
|
") from context(%" GST_PTR_FORMAT ")", *queue, context);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_queue_handle_context_query:
|
|
|
|
* @element: a #GstElement
|
|
|
|
* @query: a #GstQuery of type #GST_QUERY_CONTEXT
|
2019-09-16 01:21:55 +00:00
|
|
|
* @queue: (nullable): the #GstVulkanQueue
|
2019-04-11 06:52:54 +00:00
|
|
|
*
|
|
|
|
* If a #GstVulkanQueue is requested in @query, sets @queue as the reply.
|
|
|
|
*
|
|
|
|
* Intended for use with element query handlers to respond to #GST_QUERY_CONTEXT
|
|
|
|
* for a #GstVulkanQueue.
|
|
|
|
*
|
|
|
|
* Returns: whether @query was responded to with @queue
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2016-02-16 00:22:37 +00:00
|
|
|
gboolean
|
|
|
|
gst_vulkan_queue_handle_context_query (GstElement * element, GstQuery * query,
|
2019-09-16 01:21:55 +00:00
|
|
|
GstVulkanQueue * queue)
|
2016-02-16 00:22:37 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
const gchar *context_type;
|
|
|
|
GstContext *context, *old_context;
|
|
|
|
|
|
|
|
g_return_val_if_fail (element != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (query != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
|
2019-09-16 01:21:55 +00:00
|
|
|
|
|
|
|
if (!queue)
|
|
|
|
return FALSE;
|
2016-02-16 00:22:37 +00:00
|
|
|
|
|
|
|
gst_query_parse_context_type (query, &context_type);
|
|
|
|
|
|
|
|
if (g_strcmp0 (context_type, GST_VULKAN_QUEUE_CONTEXT_TYPE_STR) == 0) {
|
|
|
|
gst_query_parse_context (query, &old_context);
|
|
|
|
|
|
|
|
if (old_context)
|
|
|
|
context = gst_context_copy (old_context);
|
|
|
|
else
|
|
|
|
context = gst_context_new (GST_VULKAN_QUEUE_CONTEXT_TYPE_STR, TRUE);
|
|
|
|
|
2019-09-16 01:21:55 +00:00
|
|
|
gst_context_set_vulkan_queue (context, queue);
|
2016-02-16 00:22:37 +00:00
|
|
|
gst_query_set_context (query, context);
|
|
|
|
gst_context_unref (context);
|
|
|
|
|
2019-09-16 01:21:55 +00:00
|
|
|
res = queue != NULL;
|
2016-02-16 00:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_queue_run_context_query:
|
|
|
|
* @element: a #GstElement
|
|
|
|
* @queue: (inout): a #GstVulkanQueue
|
|
|
|
*
|
|
|
|
* Attempt to retrieve a #GstVulkanQueue using #GST_QUERY_CONTEXT from the
|
|
|
|
* surrounding elements of @element.
|
|
|
|
*
|
|
|
|
* Returns: whether @queue contains a valid #GstVulkanQueue
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2016-02-16 00:22:37 +00:00
|
|
|
gboolean
|
|
|
|
gst_vulkan_queue_run_context_query (GstElement * element,
|
|
|
|
GstVulkanQueue ** queue)
|
|
|
|
{
|
|
|
|
GstQuery *query;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
|
|
|
|
g_return_val_if_fail (queue != NULL, FALSE);
|
|
|
|
|
2019-06-11 08:37:59 +00:00
|
|
|
_init_debug ();
|
|
|
|
|
2016-02-16 00:22:37 +00:00
|
|
|
if (*queue && GST_IS_VULKAN_QUEUE (*queue))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if ((query =
|
|
|
|
gst_vulkan_local_context_query (element,
|
2019-04-08 11:35:22 +00:00
|
|
|
GST_VULKAN_QUEUE_CONTEXT_TYPE_STR))) {
|
2016-02-16 00:22:37 +00:00
|
|
|
GstContext *context;
|
|
|
|
|
|
|
|
gst_query_parse_context (query, &context);
|
|
|
|
if (context)
|
|
|
|
gst_context_get_vulkan_queue (context, queue);
|
2019-05-08 04:48:43 +00:00
|
|
|
|
|
|
|
gst_query_unref (query);
|
2016-02-16 00:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (element, "found queue %p", *queue);
|
|
|
|
|
|
|
|
if (*queue)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-11-13 23:00:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_queue_submit_lock:
|
|
|
|
* @queue: a #GstVulkanQueue
|
|
|
|
*
|
|
|
|
* Locks the queue for command submission using `vkQueueSubmit()` to meet the
|
|
|
|
* Vulkan requirements for externally synchronised resources.
|
2020-08-12 05:59:01 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
2019-11-13 23:00:35 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vulkan_queue_submit_lock (GstVulkanQueue * queue)
|
|
|
|
{
|
|
|
|
GstVulkanQueuePrivate *priv = GET_PRIV (queue);
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->submit_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_queue_submit_unlock:
|
|
|
|
* @queue: a #GstVulkanQueue
|
|
|
|
*
|
|
|
|
* Unlocks the queue for command submission using `vkQueueSubmit()`.
|
|
|
|
*
|
|
|
|
* See gst_vulkan_queue_submit_lock() for details on when this call is needed.
|
2020-08-12 05:59:01 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
2019-11-13 23:00:35 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vulkan_queue_submit_unlock (GstVulkanQueue * queue)
|
|
|
|
{
|
|
|
|
GstVulkanQueuePrivate *priv = GET_PRIV (queue);
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->submit_lock);
|
|
|
|
}
|