mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 10:41:04 +00:00
vkutils: add gst_vulkan_ensure_element_device
In order to keep the same device across the elements in the pipeline, use either the device id to create the device or get the device from the context set by the peer elements. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7843>
This commit is contained in:
parent
9a771b6909
commit
0dd706a420
10 changed files with 113 additions and 87 deletions
|
@ -7174,6 +7174,37 @@ retrieval is performed.</doc>
|
|||
</parameter>
|
||||
</parameters>
|
||||
</function>
|
||||
<function name="vulkan_ensure_element_device" c:identifier="gst_vulkan_ensure_element_device" version="1.26">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkutils.c">Perform the steps necessary for retrieving a #GstVulkanDevice from
|
||||
the surrounding elements or create a new device according to the device_id.
|
||||
|
||||
If the contents of @device_ptr is not %NULL, then no
|
||||
#GstContext query is necessary and no #GstVulkanDevice
|
||||
retrieval is performed.</doc>
|
||||
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkutils.h"/>
|
||||
<return-value transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkutils.c">whether a #GstVulkanDevice exists in @device_ptr</doc>
|
||||
<type name="gboolean" c:type="gboolean"/>
|
||||
</return-value>
|
||||
<parameters>
|
||||
<parameter name="element" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkutils.c">a #GstElement</doc>
|
||||
<type name="Gst.Element" c:type="GstElement*"/>
|
||||
</parameter>
|
||||
<parameter name="instance" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkutils.c">the #GstVulkanInstance</doc>
|
||||
<type name="VulkanInstance" c:type="GstVulkanInstance*"/>
|
||||
</parameter>
|
||||
<parameter name="device_ptr" direction="inout" caller-allocates="0" transfer-ownership="full" optional="1">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkutils.c">the resulting #GstVulkanDevice</doc>
|
||||
<type name="VulkanDevice" c:type="GstVulkanDevice**"/>
|
||||
</parameter>
|
||||
<parameter name="device_id" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkutils.c">The device number to use, 0 is default.</doc>
|
||||
<type name="guint" c:type="guint"/>
|
||||
</parameter>
|
||||
</parameters>
|
||||
</function>
|
||||
<function name="vulkan_error_quark" c:identifier="gst_vulkan_error_quark" moved-to="VulkanError.quark" version="1.18">
|
||||
<return-value transfer-ownership="none">
|
||||
<type name="GLib.Quark" c:type="GQuark"/>
|
||||
|
|
|
@ -569,20 +569,9 @@ gst_vulkan_download_change_state (GstElement * element,
|
|||
("Failed to retrieve vulkan instance"), (NULL));
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
if (!gst_vulkan_device_run_context_query (GST_ELEMENT (vk_download),
|
||||
&vk_download->device)) {
|
||||
GError *error = NULL;
|
||||
GST_DEBUG_OBJECT (vk_download,
|
||||
"No device retrieved from peer elements");
|
||||
if (!(vk_download->device =
|
||||
gst_vulkan_instance_create_device (vk_download->instance,
|
||||
&error))) {
|
||||
GST_ELEMENT_ERROR (vk_download, RESOURCE, NOT_FOUND,
|
||||
("Failed to create vulkan device"), ("%s",
|
||||
error ? error->message : ""));
|
||||
g_clear_error (&error);
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
if (!gst_vulkan_ensure_element_device (element, vk_download->instance,
|
||||
&vk_download->device, 0)) {
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
|
||||
if (gst_vulkan_queue_run_context_query (GST_ELEMENT (vk_download),
|
||||
|
|
|
@ -135,18 +135,9 @@ gst_vulkan_h264_decoder_open (GstVideoDecoder * decoder)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_vulkan_device_run_context_query (GST_ELEMENT (decoder),
|
||||
&self->device)) {
|
||||
GError *error = NULL;
|
||||
GST_DEBUG_OBJECT (self, "No device retrieved from peer elements");
|
||||
self->device = gst_vulkan_instance_create_device (self->instance, &error);
|
||||
if (!self->device) {
|
||||
GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND,
|
||||
("Failed to create vulkan device"),
|
||||
("%s", error ? error->message : ""));
|
||||
g_clear_error (&error);
|
||||
return FALSE;
|
||||
}
|
||||
if (!gst_vulkan_ensure_element_device (GST_ELEMENT (decoder), self->instance,
|
||||
&self->device, 0)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_vulkan_queue_run_context_query (GST_ELEMENT (self),
|
||||
|
|
|
@ -193,18 +193,9 @@ gst_vulkan_h265_decoder_open (GstVideoDecoder * decoder)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_vulkan_device_run_context_query (GST_ELEMENT (decoder),
|
||||
&self->device)) {
|
||||
GError *error = NULL;
|
||||
GST_DEBUG_OBJECT (self, "No device retrieved from peer elements");
|
||||
self->device = gst_vulkan_instance_create_device (self->instance, &error);
|
||||
if (!self->device) {
|
||||
GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND,
|
||||
("Failed to create vulkan device"),
|
||||
("%s", error ? error->message : ""));
|
||||
g_clear_error (&error);
|
||||
return FALSE;
|
||||
}
|
||||
if (!gst_vulkan_ensure_element_device (GST_ELEMENT (decoder), self->instance,
|
||||
&self->device, 0)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_vulkan_queue_run_context_query (GST_ELEMENT (self),
|
||||
|
|
|
@ -288,20 +288,9 @@ gst_vulkan_sink_change_state (GstElement * element, GstStateChange transition)
|
|||
("Failed to retrieve vulkan instance/display"), (NULL));
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
|
||||
if (!vk_sink->device) {
|
||||
if (!gst_vulkan_device_run_context_query (GST_ELEMENT (vk_sink),
|
||||
&vk_sink->device)) {
|
||||
if (!(vk_sink->device =
|
||||
gst_vulkan_instance_create_device (vk_sink->instance,
|
||||
&error))) {
|
||||
GST_ELEMENT_ERROR (vk_sink, RESOURCE, NOT_FOUND,
|
||||
("Failed to create vulkan device"), ("%s",
|
||||
error ? error->message : ""));
|
||||
g_clear_error (&error);
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
}
|
||||
if (!gst_vulkan_ensure_element_device (element, vk_sink->instance,
|
||||
&vk_sink->device, 0)) {
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
break;
|
||||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||
|
|
|
@ -1151,19 +1151,9 @@ gst_vulkan_upload_change_state (GstElement * element, GstStateChange transition)
|
|||
("Failed to retrieve vulkan instance"), (NULL));
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
if (!gst_vulkan_device_run_context_query (GST_ELEMENT (vk_upload),
|
||||
&vk_upload->device)) {
|
||||
GError *error = NULL;
|
||||
GST_DEBUG_OBJECT (vk_upload, "No device retrieved from peer elements");
|
||||
if (!(vk_upload->device =
|
||||
gst_vulkan_instance_create_device (vk_upload->instance,
|
||||
&error))) {
|
||||
GST_ELEMENT_ERROR (vk_upload, RESOURCE, NOT_FOUND,
|
||||
("Failed to create vulkan device"), ("%s",
|
||||
error ? error->message : ""));
|
||||
g_clear_error (&error);
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
if (!gst_vulkan_ensure_element_device (element, vk_upload->instance,
|
||||
&vk_upload->device, 0)) {
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
// Issue with NVIDIA driver where the output gets artifacts if I select another
|
||||
// queue seen the codec one does not support VK_QUEUE_GRAPHICS_BIT but VK_QUEUE_TRANSFER_BIT.
|
||||
|
|
|
@ -309,6 +309,61 @@ gst_vulkan_ensure_element_data (GstElement * element,
|
|||
return *display_ptr != NULL && *instance_ptr != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vulkan_ensure_element_device:
|
||||
* @element: a #GstElement
|
||||
* @instance: the #GstVulkanInstance
|
||||
* @device_ptr: (inout) (optional): the resulting #GstVulkanDevice
|
||||
* @device_id: The device number to use, 0 is default.
|
||||
*
|
||||
* Perform the steps necessary for retrieving a #GstVulkanDevice from
|
||||
* the surrounding elements or create a new device according to the device_id.
|
||||
*
|
||||
* If the contents of @device_ptr is not %NULL, then no
|
||||
* #GstContext query is necessary and no #GstVulkanDevice
|
||||
* retrieval is performed.
|
||||
*
|
||||
* Returns: whether a #GstVulkanDevice exists in @device_ptr
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
gboolean
|
||||
gst_vulkan_ensure_element_device (GstElement * element,
|
||||
GstVulkanInstance * instance, GstVulkanDevice ** device_ptr,
|
||||
guint device_id)
|
||||
{
|
||||
g_return_val_if_fail (instance != NULL, FALSE);
|
||||
|
||||
if (!gst_vulkan_device_run_context_query (element, device_ptr)) {
|
||||
GError *error = NULL;
|
||||
GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
|
||||
"No device retrieved from peer elements");
|
||||
|
||||
/* If no neighboor, or application not interested, use system default by device id */
|
||||
*device_ptr =
|
||||
gst_vulkan_instance_create_device_with_index (instance, device_id,
|
||||
&error);
|
||||
|
||||
if (!*device_ptr) {
|
||||
GST_ELEMENT_ERROR (element, RESOURCE, NOT_FOUND,
|
||||
("Failed to create vulkan device"),
|
||||
("%s", error ? error->message : ""));
|
||||
g_clear_error (&error);
|
||||
return FALSE;
|
||||
}
|
||||
GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
|
||||
"Created a new device from %s",
|
||||
(*device_ptr)->physical_device->properties.deviceName);
|
||||
} else {
|
||||
if ((*device_ptr)->physical_device->device_index != device_id) {
|
||||
GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
|
||||
"A device with a different id has been selected from a peer element");
|
||||
}
|
||||
}
|
||||
|
||||
return *device_ptr != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vulkan_handle_set_context:
|
||||
* @element: a #GstElement
|
||||
|
|
|
@ -30,6 +30,11 @@ gboolean gst_vulkan_ensure_element_data (GstElement * el
|
|||
GstVulkanDisplay ** display_ptr,
|
||||
GstVulkanInstance ** instance_ptr);
|
||||
GST_VULKAN_API
|
||||
gboolean gst_vulkan_ensure_element_device (GstElement * element,
|
||||
GstVulkanInstance * instance,
|
||||
GstVulkanDevice ** device_ptr,
|
||||
guint device_id);
|
||||
GST_VULKAN_API
|
||||
gboolean gst_vulkan_handle_set_context (GstElement * element,
|
||||
GstContext * context,
|
||||
GstVulkanDisplay ** display,
|
||||
|
|
|
@ -274,17 +274,10 @@ gst_vulkan_video_filter_start (GstBaseTransform * bt)
|
|||
("Failed to retrieve vulkan instance"), (NULL));
|
||||
return FALSE;
|
||||
}
|
||||
if (!gst_vulkan_device_run_context_query (GST_ELEMENT (render),
|
||||
&render->device)) {
|
||||
GError *error = NULL;
|
||||
GST_DEBUG_OBJECT (render, "No device retrieved from peer elements");
|
||||
if (!(render->device =
|
||||
gst_vulkan_instance_create_device (render->instance, &error))) {
|
||||
GST_ELEMENT_ERROR (render, RESOURCE, NOT_FOUND,
|
||||
("Failed to create vulkan device"), ("%s", error->message));
|
||||
g_clear_error (&error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_vulkan_ensure_element_device (GST_ELEMENT (bt), render->instance,
|
||||
&render->device, 0)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_vulkan_queue_run_context_query (GST_ELEMENT (render),
|
||||
|
|
|
@ -643,17 +643,9 @@ gst_vtdec_negotiate (GstVideoDecoder * decoder)
|
|||
gst_vulkan_ensure_element_data (GST_ELEMENT (vtdec), NULL,
|
||||
&vtdec->instance);
|
||||
|
||||
if (!gst_vulkan_device_run_context_query (GST_ELEMENT (vtdec),
|
||||
&vtdec->device)) {
|
||||
GError *error = NULL;
|
||||
GST_DEBUG_OBJECT (vtdec, "No device retrieved from peer elements");
|
||||
if (!(vtdec->device =
|
||||
gst_vulkan_instance_create_device (vtdec->instance, &error))) {
|
||||
GST_ELEMENT_ERROR (vtdec, RESOURCE, NOT_FOUND,
|
||||
("Failed to create vulkan device"), ("%s", error->message));
|
||||
g_clear_error (&error);
|
||||
return FALSE;
|
||||
}
|
||||
if (!gst_vulkan_ensure_element_device (GST_ELEMENT (vtdec),
|
||||
vtdec->instance, &vtdec->device, 0)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GST_INFO_OBJECT (vtdec, "pushing vulkan images, device %" GST_PTR_FORMAT
|
||||
|
|
Loading…
Reference in a new issue