[FFmpeg-devel] [PATCH 3/6] vulkan_decode: move temporary Vulkan structs into each codec
Lynne
dev at lynne.ee
Mon Mar 31 05:37:39 EEST 2025
Required for next refactor.
---
libavcodec/vulkan_av1.c | 30 +++++++++++++++++++++---------
libavcodec/vulkan_decode.c | 20 ++++++++++----------
libavcodec/vulkan_decode.h | 13 +------------
libavcodec/vulkan_h264.c | 32 ++++++++++++++++++++++----------
libavcodec/vulkan_hevc.c | 28 ++++++++++++++++++++--------
5 files changed, 74 insertions(+), 49 deletions(-)
diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
index 115db8badb..c4ae0bb2ab 100644
--- a/libavcodec/vulkan_av1.c
+++ b/libavcodec/vulkan_av1.c
@@ -66,6 +66,17 @@ typedef struct AV1VulkanDecodePicture {
StdVideoDecodeAV1ReferenceInfo std_refs [AV1_NUM_REF_FRAMES];
VkVideoDecodeAV1DpbSlotInfoKHR vkav1_refs[AV1_NUM_REF_FRAMES];
+ /* Current picture */
+ VkVideoPictureResourceInfoKHR ref;
+ VkVideoReferenceSlotInfoKHR ref_slot;
+
+ /* Picture refs. H264 has the maximum number of refs (36) of any supported codec. */
+ VkVideoPictureResourceInfoKHR refs [36];
+ VkVideoReferenceSlotInfoKHR ref_slots[36];
+
+ /* Main decoding struct */
+ VkVideoDecodeInfoKHR decode_info;
+
uint8_t frame_id_set;
uint8_t frame_id;
uint8_t ref_frame_sign_bias_mask;
@@ -295,7 +306,7 @@ static int vk_av1_start_frame(AVCodecContext *avctx,
continue;
for (int j = 0; j < ref_count; j++) {
- if (vp->ref_slots[j].slotIndex == hp->frame_id) {
+ if (ap->ref_slots[j].slotIndex == hp->frame_id) {
found = 1;
break;
}
@@ -303,8 +314,8 @@ static int vk_av1_start_frame(AVCodecContext *avctx,
if (found)
continue;
- err = vk_av1_fill_pict(avctx, &ap->ref_src[ref_count], &vp->ref_slots[ref_count],
- &vp->refs[ref_count], &ap->std_refs[ref_count], &ap->vkav1_refs[ref_count],
+ err = vk_av1_fill_pict(avctx, &ap->ref_src[ref_count], &ap->ref_slots[ref_count],
+ &ap->refs[ref_count], &ap->std_refs[ref_count], &ap->vkav1_refs[ref_count],
ref_frame, 0, 0, ref_frame->order_hints);
if (err < 0)
return err;
@@ -312,7 +323,7 @@ static int vk_av1_start_frame(AVCodecContext *avctx,
ref_count++;
}
- err = vk_av1_fill_pict(avctx, NULL, &vp->ref_slot, &vp->ref,
+ err = vk_av1_fill_pict(avctx, NULL, &ap->ref_slot, &ap->ref,
&ap->std_ref,
&ap->vkav1_ref,
pic, 1, apply_grain, NULL);
@@ -339,13 +350,13 @@ static int vk_av1_start_frame(AVCodecContext *avctx,
ap->av1_pic_info.referenceNameSlotIndices[i] = hp->frame_id;
}
- vp->decode_info = (VkVideoDecodeInfoKHR) {
+ ap->decode_info = (VkVideoDecodeInfoKHR) {
.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR,
.pNext = &ap->av1_pic_info,
.flags = 0x0,
- .pSetupReferenceSlot = &vp->ref_slot,
+ .pSetupReferenceSlot = &ap->ref_slot,
.referenceSlotCount = ref_count,
- .pReferenceSlots = vp->ref_slots,
+ .pReferenceSlots = ap->ref_slots,
.dstPictureResource = (VkVideoPictureResourceInfoKHR) {
.sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
.codedOffset = (VkOffset2D){ 0, 0 },
@@ -618,7 +629,7 @@ static int vk_av1_end_frame(AVCodecContext *avctx)
return err;
}
- for (int i = 0; i < vp->decode_info.referenceSlotCount; i++) {
+ for (int i = 0; i < ap->decode_info.referenceSlotCount; i++) {
const AV1Frame *rp = ap->ref_src[i];
AV1VulkanDecodePicture *rhp = rp->hwaccel_picture_private;
@@ -629,7 +640,8 @@ static int vk_av1_end_frame(AVCodecContext *avctx)
av_log(avctx, AV_LOG_VERBOSE, "Decoding frame, %"SIZE_SPECIFIER" bytes, %i tiles\n",
vp->slices_size, ap->av1_pic_info.tileCount);
- return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp);
+ return ff_vk_decode_frame(avctx, &ap->decode_info,
+ pic->f, vp, rav, rvp);
}
static void vk_av1_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index 48a206e3c0..058efe3037 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -354,7 +354,7 @@ void ff_vk_decode_flush(AVCodecContext *avctx)
ff_vk_exec_submit(&ctx->s, exec);
}
-int ff_vk_decode_frame(AVCodecContext *avctx,
+int ff_vk_decode_frame(AVCodecContext *avctx, VkVideoDecodeInfoKHR *decode_info,
AVFrame *pic, FFVulkanDecodePicture *vp,
AVFrame *rpic[], FFVulkanDecodePicture *rvkp[])
{
@@ -379,8 +379,8 @@ int ff_vk_decode_frame(AVCodecContext *avctx,
.videoSessionParameters = dec->session_params ?
*((VkVideoSessionParametersKHR *)dec->session_params->data) :
VK_NULL_HANDLE,
- .referenceSlotCount = vp->decode_info.referenceSlotCount,
- .pReferenceSlots = vp->decode_info.pReferenceSlots,
+ .referenceSlotCount = decode_info->referenceSlotCount,
+ .pReferenceSlots = decode_info->pReferenceSlots,
};
VkVideoEndCodingInfoKHR decode_end = {
.sType = VK_STRUCTURE_TYPE_VIDEO_END_CODING_INFO_KHR,
@@ -396,7 +396,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx,
/* The current decoding reference has to be bound as an inactive reference */
VkVideoReferenceSlotInfoKHR *cur_vk_ref;
cur_vk_ref = (void *)&decode_start.pReferenceSlots[decode_start.referenceSlotCount];
- cur_vk_ref[0] = vp->ref_slot;
+ cur_vk_ref[0] = *decode_info->pSetupReferenceSlot;
cur_vk_ref[0].slotIndex = -1;
decode_start.referenceSlotCount++;
@@ -420,9 +420,9 @@ int ff_vk_decode_frame(AVCodecContext *avctx,
}
}
- vp->decode_info.srcBuffer = sd_buf->buf;
- vp->decode_info.srcBufferOffset = 0;
- vp->decode_info.srcBufferRange = data_size;
+ decode_info->srcBuffer = sd_buf->buf;
+ decode_info->srcBufferOffset = 0;
+ decode_info->srcBufferRange = data_size;
/* Start command buffer recording */
err = ff_vk_exec_start(&ctx->s, exec);
@@ -488,7 +488,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx,
if (!layered_dpb) {
/* All references (apart from the current) for non-layered refs */
- for (int i = 0; i < vp->decode_info.referenceSlotCount; i++) {
+ for (int i = 0; i < decode_info->referenceSlotCount; i++) {
AVFrame *ref_frame = rpic[i];
FFVulkanDecodePicture *rvp = rvkp[i];
AVFrame *ref = rvp->dpb_frame ? rvp->dpb_frame : ref_frame;
@@ -533,7 +533,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx,
&img_bar[nb_img_bar], &nb_img_bar);
}
}
- } else if (vp->decode_info.referenceSlotCount ||
+ } else if (decode_info->referenceSlotCount ||
vp->view.out[0] != vp->view.ref[0]) {
/* Single barrier for a single layered ref */
err = ff_vk_exec_add_dep_frame(&ctx->s, exec, ctx->common.layered_frame,
@@ -553,7 +553,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx,
/* Start, use parameters, decode and end decoding */
vk->CmdBeginVideoCodingKHR(cmd_buf, &decode_start);
- vk->CmdDecodeVideoKHR(cmd_buf, &vp->decode_info);
+ vk->CmdDecodeVideoKHR(cmd_buf, decode_info);
vk->CmdEndVideoCodingKHR(cmd_buf, &decode_end);
/* End recording and submit for execution */
diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h
index 4bd755c1f6..6c3e1486b0 100644
--- a/libavcodec/vulkan_decode.h
+++ b/libavcodec/vulkan_decode.h
@@ -96,17 +96,6 @@ typedef struct FFVulkanDecodePicture {
VkSemaphore sem;
uint64_t sem_value;
- /* Current picture */
- VkVideoPictureResourceInfoKHR ref;
- VkVideoReferenceSlotInfoKHR ref_slot;
-
- /* Picture refs. H264 has the maximum number of refs (36) of any supported codec. */
- VkVideoPictureResourceInfoKHR refs [36];
- VkVideoReferenceSlotInfoKHR ref_slots[36];
-
- /* Main decoding struct */
- VkVideoDecodeInfoKHR decode_info;
-
/* Slice data */
AVBufferRef *slices_buf;
size_t slices_size;
@@ -165,7 +154,7 @@ int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp,
/**
* Decode a frame.
*/
-int ff_vk_decode_frame(AVCodecContext *avctx,
+int ff_vk_decode_frame(AVCodecContext *avctx, VkVideoDecodeInfoKHR *decode_info,
AVFrame *pic, FFVulkanDecodePicture *vp,
AVFrame *rpic[], FFVulkanDecodePicture *rvkp[]);
diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c
index d950c6948f..71a9c06801 100644
--- a/libavcodec/vulkan_h264.c
+++ b/libavcodec/vulkan_h264.c
@@ -47,6 +47,17 @@ typedef struct H264VulkanDecodePicture {
/* Current picture (contd.) */
StdVideoDecodeH264PictureInfo h264pic;
VkVideoDecodeH264PictureInfoKHR h264_pic_info;
+
+ /* Current picture */
+ VkVideoPictureResourceInfoKHR ref;
+ VkVideoReferenceSlotInfoKHR ref_slot;
+
+ /* Picture refs. H264 has the maximum number of refs (36) of any supported codec. */
+ VkVideoPictureResourceInfoKHR refs [36];
+ VkVideoReferenceSlotInfoKHR ref_slots[36];
+
+ /* Main decoding struct */
+ VkVideoDecodeInfoKHR decode_info;
} H264VulkanDecodePicture;
const static int h264_scaling_list8_order[] = { 0, 3, 1, 4, 2, 5 };
@@ -380,7 +391,7 @@ static int vk_h264_start_frame(AVCodecContext *avctx,
}
}
- err = vk_h264_fill_pict(avctx, NULL, &vp->ref_slot, &vp->ref,
+ err = vk_h264_fill_pict(avctx, NULL, &hp->ref_slot, &hp->ref,
&hp->vkh264_ref, &hp->h264_ref, pic, 1,
h->DPB[dpb_slot_index].field_picture,
h->DPB[dpb_slot_index].reference,
@@ -397,8 +408,8 @@ static int vk_h264_start_frame(AVCodecContext *avctx,
break;
}
}
- err = vk_h264_fill_pict(avctx, &hp->ref_src[i], &vp->ref_slots[i],
- &vp->refs[i], &hp->vkh264_refs[i],
+ err = vk_h264_fill_pict(avctx, &hp->ref_src[i], &hp->ref_slots[i],
+ &hp->refs[i], &hp->vkh264_refs[i],
&hp->h264_refs[i], h->short_ref[i], 0,
h->DPB[dpb_slot_index].field_picture,
h->DPB[dpb_slot_index].reference,
@@ -420,8 +431,8 @@ static int vk_h264_start_frame(AVCodecContext *avctx,
break;
}
}
- err = vk_h264_fill_pict(avctx, &hp->ref_src[i], &vp->ref_slots[i],
- &vp->refs[i], &hp->vkh264_refs[i],
+ err = vk_h264_fill_pict(avctx, &hp->ref_src[i], &hp->ref_slots[i],
+ &hp->refs[i], &hp->vkh264_refs[i],
&hp->h264_refs[i], h->long_ref[r], 0,
h->DPB[dpb_slot_index].field_picture,
h->DPB[dpb_slot_index].reference,
@@ -454,13 +465,13 @@ static int vk_h264_start_frame(AVCodecContext *avctx,
.pStdPictureInfo = &hp->h264pic,
};
- vp->decode_info = (VkVideoDecodeInfoKHR) {
+ hp->decode_info = (VkVideoDecodeInfoKHR) {
.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR,
.pNext = &hp->h264_pic_info,
.flags = 0x0,
- .pSetupReferenceSlot = &vp->ref_slot,
+ .pSetupReferenceSlot = &hp->ref_slot,
.referenceSlotCount = h->short_ref_count + h->long_ref_count,
- .pReferenceSlots = vp->ref_slots,
+ .pReferenceSlots = hp->ref_slots,
.dstPictureResource = (VkVideoPictureResourceInfoKHR) {
.sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
.codedOffset = (VkOffset2D){ 0, 0 },
@@ -545,7 +556,7 @@ static int vk_h264_end_frame(AVCodecContext *avctx)
hp->h264pic.pic_parameter_set_id = pic->pps->pps_id;
}
- for (int i = 0; i < vp->decode_info.referenceSlotCount; i++) {
+ for (int i = 0; i < hp->decode_info.referenceSlotCount; i++) {
H264Picture *rp = hp->ref_src[i];
H264VulkanDecodePicture *rhp = rp->hwaccel_picture_private;
@@ -556,7 +567,8 @@ static int vk_h264_end_frame(AVCodecContext *avctx)
av_log(avctx, AV_LOG_VERBOSE, "Decoding frame, %"SIZE_SPECIFIER" bytes, %i slices\n",
vp->slices_size, hp->h264_pic_info.sliceCount);
- return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp);
+ return ff_vk_decode_frame(avctx, &hp->decode_info,
+ pic->f, vp, rav, rvp);
}
static void vk_h264_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index bc43591e19..e83f8346a0 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -127,6 +127,17 @@ typedef struct HEVCVulkanDecodePicture {
/* Current picture (contd.) */
StdVideoDecodeH265PictureInfo h265pic;
VkVideoDecodeH265PictureInfoKHR h265_pic_info;
+
+ /* Current picture */
+ VkVideoPictureResourceInfoKHR ref;
+ VkVideoReferenceSlotInfoKHR ref_slot;
+
+ /* Picture refs. H264 has the maximum number of refs (36) of any supported codec. */
+ VkVideoPictureResourceInfoKHR refs [36];
+ VkVideoReferenceSlotInfoKHR ref_slots[36];
+
+ /* Main decoding struct */
+ VkVideoDecodeInfoKHR decode_info;
} HEVCVulkanDecodePicture;
static int vk_hevc_fill_pict(AVCodecContext *avctx, HEVCFrame **ref_src,
@@ -749,7 +760,7 @@ static int vk_hevc_start_frame(AVCodecContext *avctx,
continue;
if (ref == pic) {
- err = vk_hevc_fill_pict(avctx, NULL, &vp->ref_slot, &vp->ref,
+ err = vk_hevc_fill_pict(avctx, NULL, &hp->ref_slot, &hp->ref,
&hp->vkh265_ref, &hp->h265_ref, pic, 1, i);
if (err < 0)
return err;
@@ -757,8 +768,8 @@ static int vk_hevc_start_frame(AVCodecContext *avctx,
continue;
}
- err = vk_hevc_fill_pict(avctx, &hp->ref_src[idx], &vp->ref_slots[idx],
- &vp->refs[idx], &hp->vkh265_refs[idx],
+ err = vk_hevc_fill_pict(avctx, &hp->ref_src[idx], &hp->ref_slots[idx],
+ &hp->refs[idx], &hp->vkh265_refs[idx],
&hp->h265_refs[idx], (HEVCFrame *)ref, 0, i);
if (err < 0)
return err;
@@ -806,13 +817,13 @@ static int vk_hevc_start_frame(AVCodecContext *avctx,
.sliceSegmentCount = 0,
};
- vp->decode_info = (VkVideoDecodeInfoKHR) {
+ hp->decode_info = (VkVideoDecodeInfoKHR) {
.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR,
.pNext = &hp->h265_pic_info,
.flags = 0x0,
- .pSetupReferenceSlot = &vp->ref_slot,
+ .pSetupReferenceSlot = &hp->ref_slot,
.referenceSlotCount = nb_refs,
- .pReferenceSlots = vp->ref_slots,
+ .pReferenceSlots = hp->ref_slots,
.dstPictureResource = (VkVideoPictureResourceInfoKHR) {
.sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
.codedOffset = (VkOffset2D){ 0, 0 },
@@ -915,7 +926,7 @@ static int vk_hevc_end_frame(AVCodecContext *avctx)
hp->h265pic.pps_pic_parameter_set_id = pps->pps_id;
}
- for (int i = 0; i < vp->decode_info.referenceSlotCount; i++) {
+ for (int i = 0; i < hp->decode_info.referenceSlotCount; i++) {
HEVCVulkanDecodePicture *rfhp = hp->ref_src[i]->hwaccel_picture_private;
rav[i] = hp->ref_src[i]->f;
rvp[i] = &rfhp->vp;
@@ -924,7 +935,8 @@ static int vk_hevc_end_frame(AVCodecContext *avctx)
av_log(avctx, AV_LOG_VERBOSE, "Decoding frame, %"SIZE_SPECIFIER" bytes, %i slices\n",
vp->slices_size, hp->h265_pic_info.sliceSegmentCount);
- return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp);
+ return ff_vk_decode_frame(avctx, &hp->decode_info,
+ pic->f, vp, rav, rvp);
}
static void vk_hevc_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
--
2.49.0
More information about the ffmpeg-devel
mailing list