From 2990cc5f71f9c285510e362d8dc4a6efc4f3c2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 11 Jul 2024 13:05:28 +0200 Subject: [PATCH] vulkan: add source pipeline stage to _operation_add_frame_barrier() Instead of dragging the last destination pipeline stage as current barrier source pipeline stage (which isn't a valid semantic) this patch adds a parameter to gst_vulkan_operation_add_frame_barrier() to set the source pipeline stage to define the barrier. The previous logic brought problems particularly with queue transfers, when the new queue doesn't support the stage set during a previous operation in a different queue. Now the operation API is closer to Vulkan semantics. Part-of: --- girs/GstVulkan-1.0.gir | 5 +++++ subprojects/gst-plugins-bad/ext/vulkan/vkdownload.c | 5 +++-- subprojects/gst-plugins-bad/ext/vulkan/vkupload.c | 10 ++++++---- .../gst-libs/gst/vulkan/gstvkdecoder-private.c | 6 ++++-- .../gst-libs/gst/vulkan/gstvkencoder-private.c | 2 ++ .../gst-libs/gst/vulkan/gstvkimagebufferpool.c | 4 ++-- .../gst-libs/gst/vulkan/gstvkoperation.c | 7 ++++--- .../gst-libs/gst/vulkan/gstvkoperation.h | 1 + .../gst-plugins-bad/tests/check/libs/vkvideodecode.c | 4 ++-- .../tests/check/libs/vkvideoencodeh264.c | 5 +++-- .../tests/check/libs/vkvideoencodeh265.c | 5 +++-- 11 files changed, 35 insertions(+), 19 deletions(-) diff --git a/girs/GstVulkan-1.0.gir b/girs/GstVulkan-1.0.gir index f37bb6d2a0..e917d91852 100644 --- a/girs/GstVulkan-1.0.gir +++ b/girs/GstVulkan-1.0.gir @@ -4636,6 +4636,11 @@ gst_vulkan_operation_update_frame(). a Vulkan Image #GstBuffer + + source pipeline stage (VkPipelineStageFlags or + VkPipelineStageFlags2) + + destination pipeline stage (VkPipelineStageFlags or VkPipelineStageFlags2) diff --git a/subprojects/gst-plugins-bad/ext/vulkan/vkdownload.c b/subprojects/gst-plugins-bad/ext/vulkan/vkdownload.c index 34f5e9de40..37fbf39755 100644 --- a/subprojects/gst-plugins-bad/ext/vulkan/vkdownload.c +++ b/subprojects/gst-plugins-bad/ext/vulkan/vkdownload.c @@ -197,8 +197,9 @@ _image_to_raw_perform (gpointer impl, GstBuffer * inbuf, GstBuffer ** outbuf) cmd_buf = raw->exec->cmd_buf; if (!gst_vulkan_operation_add_frame_barrier (raw->exec, inbuf, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, NULL)) + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + NULL)) goto unlock_error; barriers = gst_vulkan_operation_retrieve_image_barriers (raw->exec); diff --git a/subprojects/gst-plugins-bad/ext/vulkan/vkupload.c b/subprojects/gst-plugins-bad/ext/vulkan/vkupload.c index a7e4549c3f..27eaecadfb 100644 --- a/subprojects/gst-plugins-bad/ext/vulkan/vkupload.c +++ b/subprojects/gst-plugins-bad/ext/vulkan/vkupload.c @@ -423,8 +423,9 @@ _buffer_to_image_perform (gpointer impl, GstBuffer * inbuf, GstBuffer ** outbuf) cmd_buf = raw->exec->cmd_buf; if (!gst_vulkan_operation_add_frame_barrier (raw->exec, *outbuf, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, NULL)) + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + NULL)) goto unlock_error; barriers = gst_vulkan_operation_retrieve_image_barriers (raw->exec); @@ -685,8 +686,9 @@ _raw_to_image_perform (gpointer impl, GstBuffer * inbuf, GstBuffer ** outbuf) cmd_buf = raw->exec->cmd_buf; if (!gst_vulkan_operation_add_frame_barrier (raw->exec, *outbuf, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, NULL)) + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + NULL)) goto unlock_error; barriers = gst_vulkan_operation_retrieve_image_barriers (raw->exec); diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.c index d505a3f6f0..e05e470c34 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdecoder-private.c @@ -692,7 +692,8 @@ gst_vulkan_decoder_decode (GstVulkanDecoder * self, VK_IMAGE_LAYOUT_VIDEO_DECODE_DST_KHR : VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR; gst_vulkan_operation_add_frame_barrier (priv->exec, pic->out, - VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR, + VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR, VK_ACCESS_2_VIDEO_DECODE_WRITE_BIT_KHR, new_layout, NULL); /* Reference for the current image, if existing and not layered */ @@ -719,7 +720,8 @@ gst_vulkan_decoder_decode (GstVulkanDecoder * self, if (!ref_pic->dpb) { gst_vulkan_operation_add_frame_barrier (priv->exec, ref_buf, - VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR, + VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR, VK_ACCESS_2_VIDEO_DECODE_WRITE_BIT_KHR | VK_ACCESS_2_VIDEO_DECODE_READ_BIT_KHR, VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR, NULL); diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.c index 0af8f8736c..768a4b7bb5 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.c @@ -1303,6 +1303,7 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self, VK_PIPELINE_STAGE_2_VIDEO_ENCODE_BIT_KHR); gst_vulkan_operation_add_frame_barrier (priv->exec, pic->in_buffer, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_2_VIDEO_ENCODE_BIT_KHR, VK_ACCESS_2_VIDEO_ENCODE_READ_BIT_KHR, VK_IMAGE_LAYOUT_VIDEO_ENCODE_SRC_KHR, NULL); @@ -1311,6 +1312,7 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self, VK_PIPELINE_STAGE_2_VIDEO_ENCODE_BIT_KHR); gst_vulkan_operation_add_frame_barrier (priv->exec, pic->dpb_buffer, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_2_VIDEO_ENCODE_BIT_KHR, VK_ACCESS_2_VIDEO_ENCODE_READ_BIT_KHR, VK_IMAGE_LAYOUT_VIDEO_ENCODE_DPB_KHR, NULL); diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagebufferpool.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagebufferpool.c index 86f4f0d10a..cee8b90423 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagebufferpool.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagebufferpool.c @@ -428,8 +428,8 @@ prepare_buffer (GstVulkanImageBufferPool * vk_pool, GstBuffer * buffer) goto error; if (!gst_vulkan_operation_add_frame_barrier (priv->exec, buffer, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, priv->initial_access, - priv->initial_layout, NULL)) + VK_PIPELINE_STAGE_NONE_KHR, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + priv->initial_access, priv->initial_layout, NULL)) goto error; barriers = gst_vulkan_operation_retrieve_image_barriers (priv->exec); diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkoperation.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkoperation.c index a1ae7c9572..1bcb6a2a3e 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkoperation.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkoperation.c @@ -859,6 +859,8 @@ gst_vulkan_operation_add_extra_image_barriers (GstVulkanOperation * self, * gst_vulkan_operation_add_frame_barrier: * @self: a #GstVulkanOperation * @frame: a Vulkan Image #GstBuffer + * @src_stage: source pipeline stage (VkPipelineStageFlags or + * VkPipelineStageFlags2) * @dst_stage: destination pipeline stage (VkPipelineStageFlags or * VkPipelineStageFlags2) * @new_access: the new access flags (VkAccessFlags2 or VkAccessFlags) @@ -876,7 +878,7 @@ gst_vulkan_operation_add_extra_image_barriers (GstVulkanOperation * self, */ gboolean gst_vulkan_operation_add_frame_barrier (GstVulkanOperation * self, - GstBuffer * frame, guint64 dst_stage, guint64 new_access, + GstBuffer * frame, guint64 src_stage, guint64 dst_stage, guint64 new_access, VkImageLayout new_layout, GstVulkanQueue * new_queue) { guint i, n_mems; @@ -932,8 +934,7 @@ gst_vulkan_operation_add_frame_barrier (GstVulkanOperation * self, VkImageMemoryBarrier2KHR barrier2 = { .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2_KHR, .pNext = NULL, - .srcStageMask = dep_frame ? - dep_frame->dst_stage : vkmem->barrier.parent.pipeline_stages, + .srcStageMask = src_stage, .dstStageMask = dst_stage, .srcAccessMask = dep_frame ? dep_frame->new_access : vkmem->barrier.parent.access_flags, diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkoperation.h b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkoperation.h index fc10fccf7d..9a324fbccb 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkoperation.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkoperation.h @@ -103,6 +103,7 @@ GArray * gst_vulkan_operation_new_extra_image_barriers GST_VULKAN_API gboolean gst_vulkan_operation_add_frame_barrier (GstVulkanOperation * self, GstBuffer * frame, + guint64 src_stage, guint64 dst_stage, guint64 new_access, VkImageLayout new_layout, diff --git a/subprojects/gst-plugins-bad/tests/check/libs/vkvideodecode.c b/subprojects/gst-plugins-bad/tests/check/libs/vkvideodecode.c index 5603374291..97b16070ee 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkvideodecode.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkvideodecode.c @@ -188,8 +188,8 @@ download_and_check_output_buffer (GstVulkanDecoder * dec, VkFormat vk_format, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); gst_vulkan_operation_add_frame_barrier (exec, pic->out, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, NULL); + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, NULL); barriers = gst_vulkan_operation_retrieve_image_barriers (exec); /* *INDENT-OFF* */ diff --git a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c index f37ee0993d..8d6bc7bb87 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c @@ -240,8 +240,9 @@ upload_buffer_to_image (GstBufferPool * pool, GstBuffer * inbuf, cmd_buf = exec->cmd_buf; if (!gst_vulkan_operation_add_frame_barrier (exec, *outbuf, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, NULL)) + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + NULL)) goto unlock_error; barriers = gst_vulkan_operation_retrieve_image_barriers (exec); diff --git a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c index 04cc82e46f..7d442505c1 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c @@ -245,8 +245,9 @@ upload_buffer_to_image (GstBufferPool * pool, GstBuffer * inbuf, cmd_buf = exec->cmd_buf; if (!gst_vulkan_operation_add_frame_barrier (exec, *outbuf, - VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, NULL)) + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + NULL)) goto unlock_error; barriers = gst_vulkan_operation_retrieve_image_barriers (exec);