From d4de93266401af9acc4ded32b299fe812044f51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 19 Sep 2024 12:21:04 +0200 Subject: [PATCH] vkencoder-private: add VkVideoReferenceSlotInfoKHR in GstVulkanEncoderPicture And remove slotIndex since it's part of VkVideoReferenceSlotInfoKHR, simplifying the reference slots array creation, and changing the tests accordingly. Part-of: --- .../gst/vulkan/gstvkencoder-private.c | 35 ++++++------------- .../gst/vulkan/gstvkencoder-private.h | 3 +- .../tests/check/libs/vkvideoencodeh264.c | 4 +-- .../tests/check/libs/vkvideoencodeh265.c | 4 +-- 4 files changed, 15 insertions(+), 31 deletions(-) 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 03b1a3f3ec..3e3fc5fc76 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 @@ -418,7 +418,6 @@ gst_vulkan_encoder_picture_init (GstVulkanEncoderPicture * pic, gst_clear_buffer (&pic->dpb_buffer); return FALSE; } - pic->slotIndex = -1; pic->offset = 0; pic->img_view = gst_vulkan_video_image_create_view (pic->in_buffer, @@ -1080,7 +1079,6 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self, GstVideoInfo * info, VkVideoEndCodingInfoKHR end_coding; gint maxDpbSlots; VkVideoReferenceSlotInfoKHR ref_slots[37]; - gint ref_slot_num = 0; GstVulkanCommandBuffer *cmd_buf; GArray *barriers; @@ -1167,33 +1165,22 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self, GstVideoInfo * info, .baseArrayLayer = 0, .imageViewBinding = pic->dpb_view->view, }; - /* *INDENT-ON* */ - - for (i = 0; i < nb_refs; i++) { - /* *INDENT-OFF* */ - ref_slots[i] = (VkVideoReferenceSlotInfoKHR) { - .sType = VK_STRUCTURE_TYPE_VIDEO_REFERENCE_SLOT_INFO_KHR, - .pNext = ref_pics[i]->codec_dpb_slot_info, - .slotIndex = ref_pics[i]->slotIndex, - .pPictureResource = &ref_pics[i]->dpb, - }; - /* *INDENT-ON* */ - ref_slot_num++; - } - - /* *INDENT-OFF* */ - ref_slots[ref_slot_num] = (VkVideoReferenceSlotInfoKHR) { + pic->dpb_slot = (VkVideoReferenceSlotInfoKHR) { .sType = VK_STRUCTURE_TYPE_VIDEO_REFERENCE_SLOT_INFO_KHR, .pNext = pic->codec_dpb_slot_info, - .slotIndex = pic->slotIndex, + .slotIndex = priv->current_slot_index, .pPictureResource = &pic->dpb, }; /* *INDENT-ON* */ - ref_slot_num++; + for (i = 0; i < nb_refs; i++) + ref_slots[i] = ref_pics[i]->dpb_slot; + + ref_slots[nb_refs] = pic->dpb_slot; + ref_slots[nb_refs].slotIndex = -1; /* Setup the begin coding structure using the reference slots */ - begin_coding.referenceSlotCount = ref_slot_num; + begin_coding.referenceSlotCount = nb_refs + 1; begin_coding.pReferenceSlots = ref_slots; cmd_buf = priv->exec->cmd_buf; @@ -1244,8 +1231,6 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self, GstVideoInfo * info, /* Attribute a free slot index to the picture to be used later as a reference. * The picture is kept until it remains useful to the encoding process.*/ - pic->slotIndex = priv->current_slot_index; - ref_slots[ref_slot_num - 1].slotIndex = pic->slotIndex; priv->current_slot_index++; if (priv->current_slot_index >= maxDpbSlots) priv->current_slot_index = 0; @@ -1270,9 +1255,9 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self, GstVideoInfo * info, .baseArrayLayer = 0, .imageViewBinding = pic->img_view->view, }, - .pSetupReferenceSlot = &ref_slots[ref_slot_num - 1], + .pSetupReferenceSlot = &pic->dpb_slot, .referenceSlotCount = nb_refs, - .pReferenceSlots = nb_refs ? ref_slots : NULL, + .pReferenceSlots = ref_slots, .precedingExternallyEncodedBytes = 0, }; /* *INDENT-ON* */ diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.h b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.h index cbed184baa..42f49c2259 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.h @@ -51,8 +51,6 @@ typedef struct _GstVulkanEncoderPicture GstVulkanEncoderPicture; */ struct _GstVulkanEncoderPicture { - gint slotIndex; - guint64 offset; GstBuffer *in_buffer; @@ -64,6 +62,7 @@ struct _GstVulkanEncoderPicture GstVulkanImageView *dpb_view; VkVideoPictureResourceInfoKHR dpb; + VkVideoReferenceSlotInfoKHR dpb_slot; gpointer codec_rc_info; gpointer codec_pic_info; diff --git a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c index e256779fb1..d7711a07df 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c @@ -545,11 +545,11 @@ encode_frame (GstVulkanEncoder * enc, GstVulkanH264EncodeFrame * frame, for (i = 0; i < list0_num; i++) { ref_pics[i] = &list0[i]->picture; - frame->ref_list_info.RefPicList0[0] = list0[i]->picture.slotIndex; + frame->ref_list_info.RefPicList0[0] = list0[i]->picture.dpb_slot.slotIndex; } for (i = 0; i < list1_num; i++) { ref_pics[i + list0_num] = &list1[i]->picture; - frame->ref_list_info.RefPicList1[i] = list1[i]->picture.slotIndex; + frame->ref_list_info.RefPicList1[i] = list1[i]->picture.dpb_slot.slotIndex; } fail_unless (gst_vulkan_encoder_encode (enc, &in_info, picture, ref_pics_num, diff --git a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c index ec41e512a6..669ab1f858 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c @@ -611,11 +611,11 @@ encode_frame (GstVulkanEncoder * enc, GstVulkanH265EncodeFrame * frame, for (i = 0; i < list0_num; i++) { ref_pics[i] = &list0[i]->picture; - frame->ref_list_info.RefPicList0[0] = list0[i]->picture.slotIndex; + frame->ref_list_info.RefPicList0[0] = list0[i]->picture.dpb_slot.slotIndex; } for (i = 0; i < list1_num; i++) { ref_pics[i + list0_num] = &list1[i]->picture; - frame->ref_list_info.RefPicList1[i] = list1[i]->picture.slotIndex; + frame->ref_list_info.RefPicList1[i] = list1[i]->picture.dpb_slot.slotIndex; } fail_unless (gst_vulkan_encoder_encode (enc, &in_info, picture, ref_pics_num,