vkencoder-private: add VkVideoReferenceSlotInfoKHR in GstVulkanEncoderPicture
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Thu, 19 Sep 2024 10:21:04 +0000 (12:21 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 4 Dec 2024 02:17:44 +0000 (02:17 +0000)
And remove slotIndex since it's part of VkVideoReferenceSlotInfoKHR, simplifying
the reference slots array creation, and changing the tests accordingly.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8007>

subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.c
subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkencoder-private.h
subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh264.c
subprojects/gst-plugins-bad/tests/check/libs/vkvideoencodeh265.c

index 03b1a3f3ec4d8aac18ac43ceecdfca39f4c0ecae..3e3fc5fc76b61fb75986b8c7b50afbdf14c1922f 100644 (file)
@@ -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* */
index cbed184baa234c462327702e81d696a1a27cc24a..42f49c2259cc7e859ba334ae848a6e08e783c5e8 100644 (file)
@@ -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;
index e256779fb1d3ce8a232889088045398399a4992c..d7711a07dffb25ccf325be433771c57f38ad684d 100644 (file)
@@ -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,
index ec41e512a673e8029e077a03dfa3b2234502667e..669ab1f8589f66efc8b363f57cf673b5771da459 100644 (file)
@@ -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,