From 423f0d538494e027544c6952962f200aa91a6992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Fri, 19 Jul 2024 16:56:23 +0200 Subject: [PATCH] vkdecoder: handle barrier internally for coincide references This is to avoid a regression in validation layer (introduced by commit 916c4e70cd) when using vulkandownload VUID-VkImageMemoryBarrier2-srcAccessMask-03914 .. vkCmdPipelineBarrier2(): pDependencyInfo->pImageMemoryBarriers[1].srcAccessMask (VK_ACCESS_TRANSFER_READ_BIT) is not supported by stage mask (VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR) since vulkandownload set DPB memories' access mask to VK_ACCESS_TRANSFER_READ_BIT, while they are retain by the DPB queue, so when they are used as DPB after been shown, this validation error is raised. Must of the barrier values are set ignoring the previous state of the vulkan images. Part-of: --- .../gst/vulkan/gstvkdecoder-private.c | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) 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 e05e470c34..0e91a3b676 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 @@ -719,8 +719,35 @@ gst_vulkan_decoder_decode (GstVulkanDecoder * self, } if (!ref_pic->dpb) { - gst_vulkan_operation_add_frame_barrier (priv->exec, ref_buf, - VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR, + guint i, n = gst_buffer_n_memory (ref_buf); + GArray *barriers = + gst_vulkan_operation_new_extra_image_barriers (priv->exec); + + for (i = 0; i < n; i++) { + GstVulkanImageMemory *vkmem = + (GstVulkanImageMemory *) gst_buffer_peek_memory (ref_buf, i); + VkImageMemoryBarrier2KHR barrier = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2_KHR, + .pNext = NULL, + .srcStageMask = VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR, + .dstStageMask = VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR, + .srcAccessMask = VK_ACCESS_2_NONE, + .dstAccessMask = VK_ACCESS_2_VIDEO_DECODE_WRITE_BIT_KHR + | VK_ACCESS_2_VIDEO_DECODE_READ_BIT_KHR, + .oldLayout = vkmem->barrier.image_layout, + .newLayout = VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = vkmem->image, + .subresourceRange = vkmem->barrier.subresource_range, + }; + + g_array_append_val (barriers, barrier); + } + + gst_vulkan_operation_add_extra_image_barriers (priv->exec, barriers); + g_array_unref (barriers); + gst_vulkan_operation_update_frame (priv->exec, ref_buf, VK_PIPELINE_STAGE_2_VIDEO_DECODE_BIT_KHR, VK_ACCESS_2_VIDEO_DECODE_WRITE_BIT_KHR | VK_ACCESS_2_VIDEO_DECODE_READ_BIT_KHR,