aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2023-02-17 04:09:16 +0100
committerLynne <dev@lynne.ee>2023-05-29 00:42:00 +0200
commit77478f6793fad61a29ce92e56ee6116dd99ceca4 (patch)
treedae6815c5991f395a0c4855b06d863eed4997cd5 /libavcodec
parent5dc047716ab62945e30e490e88b4f2faad3ddb3d (diff)
downloadffmpeg-77478f6793fad61a29ce92e56ee6116dd99ceca4.tar.gz
av1dec: add Vulkan hwaccel
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/Makefile3
-rw-r--r--libavcodec/av1dec.c47
-rw-r--r--libavcodec/hwaccels.h1
-rw-r--r--libavcodec/vulkan_av1.c597
-rw-r--r--libavcodec/vulkan_decode.c34
-rw-r--r--libavcodec/vulkan_decode.h2
-rw-r--r--libavcodec/vulkan_video.c6
-rw-r--r--libavcodec/vulkan_video.h2
-rw-r--r--libavcodec/vulkan_video_codec_av1std.h403
-rw-r--r--libavcodec/vulkan_video_codec_av1std_decode.h36
10 files changed, 1128 insertions, 3 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index d421844903..9aacc1d477 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -989,6 +989,7 @@ OBJS-$(CONFIG_AV1_DXVA2_HWACCEL) += dxva2_av1.o
OBJS-$(CONFIG_AV1_NVDEC_HWACCEL) += nvdec_av1.o
OBJS-$(CONFIG_AV1_VAAPI_HWACCEL) += vaapi_av1.o
OBJS-$(CONFIG_AV1_VDPAU_HWACCEL) += vdpau_av1.o
+OBJS-$(CONFIG_AV1_VULKAN_HWACCEL) += vulkan_av1.o
OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o
OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
OBJS-$(CONFIG_H264_D3D11VA_HWACCEL) += dxva2_h264.o
@@ -1293,7 +1294,7 @@ SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h
SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_decode.h vaapi_hevc.h vaapi_encode.h
SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h vdpau_internal.h
SKIPHEADERS-$(CONFIG_VIDEOTOOLBOX) += videotoolbox.h vt_internal.h
-SKIPHEADERS-$(CONFIG_VULKAN) += vulkan.h vulkan_video.h vulkan_decode.h
+SKIPHEADERS-$(CONFIG_VULKAN) += vulkan.h vulkan_video.h vulkan_decode.h vulkan_video_codec_av1std.h vulkan_video_codec_av1std_decode.h
SKIPHEADERS-$(CONFIG_V4L2_M2M) += v4l2_buffers.h v4l2_context.h v4l2_m2m.h
SKIPHEADERS-$(CONFIG_ZLIB) += zlib_wrapper.h
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 47fa919e62..5cc5d87c64 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -450,7 +450,8 @@ static int get_pixel_format(AVCodecContext *avctx)
CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
CONFIG_AV1_NVDEC_HWACCEL + \
CONFIG_AV1_VAAPI_HWACCEL + \
- CONFIG_AV1_VDPAU_HWACCEL)
+ CONFIG_AV1_VDPAU_HWACCEL + \
+ CONFIG_AV1_VULKAN_HWACCEL)
enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
@@ -531,6 +532,9 @@ static int get_pixel_format(AVCodecContext *avctx)
#if CONFIG_AV1_VDPAU_HWACCEL
*fmtp++ = AV_PIX_FMT_VDPAU;
#endif
+#if CONFIG_AV1_VULKAN_HWACCEL
+ *fmtp++ = AV_PIX_FMT_VULKAN;
+#endif
break;
case AV_PIX_FMT_YUV420P10:
#if CONFIG_AV1_DXVA2_HWACCEL
@@ -549,6 +553,44 @@ static int get_pixel_format(AVCodecContext *avctx)
#if CONFIG_AV1_VDPAU_HWACCEL
*fmtp++ = AV_PIX_FMT_VDPAU;
#endif
+#if CONFIG_AV1_VULKAN_HWACCEL
+ *fmtp++ = AV_PIX_FMT_VULKAN;
+#endif
+ break;
+ case AV_PIX_FMT_YUV420P12:
+#if CONFIG_AV1_VULKAN_HWACCEL
+ *fmtp++ = AV_PIX_FMT_VULKAN;
+#endif
+ break;
+ case AV_PIX_FMT_YUV422P:
+#if CONFIG_AV1_VULKAN_HWACCEL
+ *fmtp++ = AV_PIX_FMT_VULKAN;
+#endif
+ break;
+ case AV_PIX_FMT_YUV422P10:
+#if CONFIG_AV1_VULKAN_HWACCEL
+ *fmtp++ = AV_PIX_FMT_VULKAN;
+#endif
+ break;
+ case AV_PIX_FMT_YUV422P12:
+#if CONFIG_AV1_VULKAN_HWACCEL
+ *fmtp++ = AV_PIX_FMT_VULKAN;
+#endif
+ break;
+ case AV_PIX_FMT_YUV444P:
+#if CONFIG_AV1_VULKAN_HWACCEL
+ *fmtp++ = AV_PIX_FMT_VULKAN;
+#endif
+ break;
+ case AV_PIX_FMT_YUV444P10:
+#if CONFIG_AV1_VULKAN_HWACCEL
+ *fmtp++ = AV_PIX_FMT_VULKAN;
+#endif
+ break;
+ case AV_PIX_FMT_YUV444P12:
+#if CONFIG_AV1_VULKAN_HWACCEL
+ *fmtp++ = AV_PIX_FMT_VULKAN;
+#endif
break;
case AV_PIX_FMT_GRAY8:
#if CONFIG_AV1_NVDEC_HWACCEL
@@ -1508,6 +1550,9 @@ const FFCodec ff_av1_decoder = {
#if CONFIG_AV1_VDPAU_HWACCEL
HWACCEL_VDPAU(av1),
#endif
+#if CONFIG_AV1_VULKAN_HWACCEL
+ HWACCEL_VULKAN(av1),
+#endif
NULL
},
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
index a7c74d07cb..48dfc17f72 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -27,6 +27,7 @@ extern const AVHWAccel ff_av1_dxva2_hwaccel;
extern const AVHWAccel ff_av1_nvdec_hwaccel;
extern const AVHWAccel ff_av1_vaapi_hwaccel;
extern const AVHWAccel ff_av1_vdpau_hwaccel;
+extern const AVHWAccel ff_av1_vulkan_hwaccel;
extern const AVHWAccel ff_h263_vaapi_hwaccel;
extern const AVHWAccel ff_h263_videotoolbox_hwaccel;
extern const AVHWAccel ff_h264_d3d11va_hwaccel;
diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
new file mode 100644
index 0000000000..5dc3e8919c
--- /dev/null
+++ b/libavcodec/vulkan_av1.c
@@ -0,0 +1,597 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "av1dec.h"
+
+#include "vulkan_decode.h"
+
+/* Maximum number of tiles specified by any defined level */
+#define MAX_TILES 256
+
+const VkExtensionProperties ff_vk_dec_av1_ext = {
+ .extensionName = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_EXTENSION_NAME,
+ .specVersion = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_SPEC_VERSION,
+};
+
+typedef struct AV1VulkanDecodePicture {
+ FFVulkanDecodePicture vp;
+
+ /* Workaround for a spec issue.
+ *Can be removed once no longer needed, and threading can be enabled. */
+ FFVulkanDecodeContext *dec;
+
+ StdVideoAV1MESATile tiles[MAX_TILES];
+ StdVideoAV1MESATileList tile_list;
+ const uint32_t *tile_offsets;
+
+ /* Current picture */
+ VkVideoDecodeAV1DpbSlotInfoMESA vkav1_ref;
+ StdVideoAV1MESAFrameHeader av1_frame_header;
+ VkVideoDecodeAV1PictureInfoMESA av1_pic_info;
+
+ /* Picture refs */
+ const AV1Frame *ref_src [AV1_NUM_REF_FRAMES];
+ VkVideoDecodeAV1DpbSlotInfoMESA vkav1_refs[AV1_NUM_REF_FRAMES];
+
+ uint8_t frame_id_set;
+ uint8_t frame_id;
+} AV1VulkanDecodePicture;
+
+static int vk_av1_fill_pict(AVCodecContext *avctx, const AV1Frame **ref_src,
+ VkVideoReferenceSlotInfoKHR *ref_slot, /* Main structure */
+ VkVideoPictureResourceInfoKHR *ref, /* Goes in ^ */
+ VkVideoDecodeAV1DpbSlotInfoMESA *vkav1_ref, /* Goes in ^ */
+ const AV1Frame *pic, int is_current, int has_grain,
+ int dpb_slot_index)
+{
+ FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
+ AV1VulkanDecodePicture *hp = pic->hwaccel_picture_private;
+ FFVulkanDecodePicture *vkpic = &hp->vp;
+
+ int err = ff_vk_decode_prepare_frame(dec, pic->f, vkpic, is_current,
+ has_grain || dec->dedicated_dpb);
+ if (err < 0)
+ return err;
+
+ *vkav1_ref = (VkVideoDecodeAV1DpbSlotInfoMESA) {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_DPB_SLOT_INFO_MESA,
+ .frameIdx = hp->frame_id,
+ };
+
+ for (unsigned i = 0; i < 7; i++) {
+ const int idx = pic->raw_frame_header->ref_frame_idx[i];
+ vkav1_ref->ref_order_hint[i] = pic->raw_frame_header->ref_order_hint[idx];
+ }
+
+ vkav1_ref->disable_frame_end_update_cdf = pic->raw_frame_header->disable_frame_end_update_cdf;
+
+ *ref = (VkVideoPictureResourceInfoKHR) {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
+ .codedOffset = (VkOffset2D){ 0, 0 },
+ .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },
+ .baseArrayLayer = ((has_grain || dec->dedicated_dpb) && dec->layered_dpb) ?
+ dpb_slot_index : 0,
+ .imageViewBinding = vkpic->img_view_ref,
+ };
+
+ *ref_slot = (VkVideoReferenceSlotInfoKHR) {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_REFERENCE_SLOT_INFO_KHR,
+ .pNext = vkav1_ref,
+ .slotIndex = dpb_slot_index,
+ .pPictureResource = ref,
+ };
+
+ if (ref_src)
+ *ref_src = pic;
+
+ return 0;
+}
+
+static int vk_av1_create_params(AVCodecContext *avctx, AVBufferRef **buf)
+{
+ VkResult ret;
+
+ const AV1DecContext *s = avctx->priv_data;
+ FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
+ FFVulkanDecodeShared *ctx = (FFVulkanDecodeShared *)dec->shared_ref->data;
+ FFVulkanFunctions *vk = &ctx->s.vkfn;
+
+ const AV1RawSequenceHeader *seq = s->raw_seq;
+
+ StdVideoAV1MESASequenceHeader av1_sequence_header;
+ VkVideoDecodeAV1SessionParametersAddInfoMESA av1_params_info;
+ VkVideoDecodeAV1SessionParametersCreateInfoMESA av1_params;
+ VkVideoSessionParametersCreateInfoKHR session_params_create;
+
+ AVBufferRef *tmp;
+ VkVideoSessionParametersKHR *par = av_malloc(sizeof(*par));
+ if (!par)
+ return AVERROR(ENOMEM);
+
+ av1_sequence_header = (StdVideoAV1MESASequenceHeader) {
+ .flags = (StdVideoAV1MESASequenceHeaderFlags) {
+ .still_picture = seq->still_picture,
+ .reduced_still_picture_header = seq->reduced_still_picture_header,
+ .use_128x128_superblock = seq->use_128x128_superblock,
+ .enable_filter_intra = seq->enable_filter_intra,
+ .enable_intra_edge_filter = seq->enable_intra_edge_filter,
+ .enable_interintra_compound = seq->enable_interintra_compound,
+ .enable_masked_compound = seq->enable_masked_compound,
+ .enable_warped_motion = seq->enable_warped_motion,
+ .enable_dual_filter = seq->enable_dual_filter,
+ .enable_order_hint = seq->enable_order_hint,
+ .enable_jnt_comp = seq->enable_jnt_comp,
+ .enable_ref_frame_mvs = seq->enable_ref_frame_mvs,
+ .frame_id_numbers_present_flag = seq->frame_id_numbers_present_flag,
+ .enable_superres = seq->enable_superres,
+ .enable_cdef = seq->enable_cdef,
+ .enable_restoration = seq->enable_restoration,
+ .film_grain_params_present = seq->film_grain_params_present,
+ .timing_info_present_flag = seq->timing_info_present_flag,
+ .initial_display_delay_present_flag = seq->initial_display_delay_present_flag,
+ },
+ .seq_profile = seq->seq_profile,
+ .frame_width_bits_minus_1 = seq->frame_width_bits_minus_1,
+ .frame_height_bits_minus_1 = seq->frame_height_bits_minus_1,
+ .max_frame_width_minus_1 = seq->max_frame_width_minus_1,
+ .max_frame_height_minus_1 = seq->max_frame_height_minus_1,
+ .delta_frame_id_length_minus_2 = seq->delta_frame_id_length_minus_2,
+ .additional_frame_id_length_minus_1 = seq->additional_frame_id_length_minus_1,
+ .order_hint_bits_minus_1 = seq->order_hint_bits_minus_1,
+ .timing_info = (StdVideoAV1MESATimingInfo) {
+ .flags = (StdVideoAV1MESATimingInfoFlags) {
+ .equal_picture_interval = seq->timing_info.equal_picture_interval,
+ },
+ .num_units_in_display_tick = seq->timing_info.num_units_in_display_tick,
+ .time_scale = seq->timing_info.time_scale,
+ .num_ticks_per_picture_minus_1 = seq->timing_info.num_ticks_per_picture_minus_1,
+ },
+ .color_config = (StdVideoAV1MESAColorConfig) {
+ .flags = (StdVideoAV1MESAColorConfigFlags) {
+ .mono_chrome = seq->color_config.mono_chrome,
+ .color_range = seq->color_config.color_range,
+ .separate_uv_delta_q = seq->color_config.separate_uv_delta_q,
+ },
+ .bit_depth = seq->color_config.twelve_bit ? 12 :
+ seq->color_config.high_bitdepth ? 10 : 8,
+ .subsampling_x = seq->color_config.subsampling_x,
+ .subsampling_y = seq->color_config.subsampling_y,
+ },
+ };
+
+ av1_params_info = (VkVideoDecodeAV1SessionParametersAddInfoMESA) {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_SESSION_PARAMETERS_ADD_INFO_MESA,
+ .sequence_header = &av1_sequence_header,
+ };
+ av1_params = (VkVideoDecodeAV1SessionParametersCreateInfoMESA) {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_SESSION_PARAMETERS_CREATE_INFO_MESA,
+ .pParametersAddInfo = &av1_params_info,
+ };
+ session_params_create = (VkVideoSessionParametersCreateInfoKHR) {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
+ .pNext = &av1_params,
+ .videoSession = ctx->common.session,
+ .videoSessionParametersTemplate = NULL,
+ };
+
+ /* Create session parameters */
+ ret = vk->CreateVideoSessionParametersKHR(ctx->s.hwctx->act_dev, &session_params_create,
+ ctx->s.hwctx->alloc, par);
+ if (ret != VK_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Unable to create Vulkan video session parameters: %s!\n",
+ ff_vk_ret2str(ret));
+ return AVERROR_EXTERNAL;
+ }
+
+ tmp = av_buffer_create((uint8_t *)par, sizeof(*par), ff_vk_decode_free_params,
+ ctx, 0);
+ if (!tmp) {
+ ff_vk_decode_free_params(ctx, (uint8_t *)par);
+ return AVERROR(ENOMEM);
+ }
+
+ av_log(avctx, AV_LOG_DEBUG, "Created frame parameters\n");
+
+ *buf = tmp;
+
+ return 0;
+}
+
+static int vk_av1_start_frame(AVCodecContext *avctx,
+ av_unused const uint8_t *buffer,
+ av_unused uint32_t size)
+{
+ int err;
+ int ref_count = 0;
+ AV1DecContext *s = avctx->priv_data;
+ const AV1Frame *pic = &s->cur_frame;
+ FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
+ AV1VulkanDecodePicture *ap = pic->hwaccel_picture_private;
+ FFVulkanDecodePicture *vp = &ap->vp;
+
+ const AV1RawFrameHeader *frame_header = s->raw_frame_header;
+ const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
+ const int apply_grain = !(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
+ film_grain->apply_grain;
+
+ if (!dec->session_params || dec->params_changed) {
+ av_buffer_unref(&dec->session_params);
+ err = vk_av1_create_params(avctx, &dec->session_params);
+ if (err < 0)
+ return err;
+ dec->params_changed = 0;
+ }
+
+ if (!ap->frame_id_set) {
+ unsigned slot_idx = 0;
+ for (unsigned i = 0; i < 32; i++) {
+ if (!(dec->frame_id_alloc_mask & (1 << i))) {
+ slot_idx = i;
+ break;
+ }
+ }
+ ap->frame_id = slot_idx;
+ ap->frame_id_set = 1;
+ dec->frame_id_alloc_mask |= (1 << slot_idx);
+ }
+
+ /* Fill in references */
+ for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
+ const AV1Frame *ref_frame = &s->ref[i];
+ if (s->ref[i].f->pict_type == AV_PICTURE_TYPE_NONE)
+ continue;
+
+ err = vk_av1_fill_pict(avctx, &ap->ref_src[i], &vp->ref_slots[i],
+ &vp->refs[i], &ap->vkav1_refs[i],
+ ref_frame, 0, 0, i);
+ if (err < 0)
+ return err;
+
+ ref_count++;
+ }
+
+ err = vk_av1_fill_pict(avctx, NULL, &vp->ref_slot, &vp->ref,
+ &ap->vkav1_ref,
+ pic, 1, apply_grain, 8);
+ if (err < 0)
+ return err;
+
+ ap->tile_list.nb_tiles = 0;
+ ap->tile_list.tile_list = ap->tiles;
+
+ ap->av1_pic_info = (VkVideoDecodeAV1PictureInfoMESA) {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PICTURE_INFO_MESA,
+ .frame_header = &ap->av1_frame_header,
+ .tile_list = &ap->tile_list,
+ };
+
+ vp->decode_info = (VkVideoDecodeInfoKHR) {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR,
+ .pNext = &ap->av1_pic_info,
+ .flags = 0x0,
+ .pSetupReferenceSlot = &vp->ref_slot,
+ .referenceSlotCount = ref_count,
+ .pReferenceSlots = vp->ref_slots,
+ .dstPictureResource = (VkVideoPictureResourceInfoKHR) {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
+ .codedOffset = (VkOffset2D){ 0, 0 },
+ .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },
+ .baseArrayLayer = 0,
+ .imageViewBinding = vp->img_view_out,
+ },
+ };
+
+ /* Setup frame header */
+ ap->av1_frame_header = (StdVideoAV1MESAFrameHeader) {
+ .flags = (StdVideoAV1MESAFrameHeaderFlags) {
+ .error_resilient_mode = frame_header->error_resilient_mode,
+ .disable_cdf_update = frame_header->disable_cdf_update,
+ .use_superres = frame_header->use_superres,
+ .render_and_frame_size_different = frame_header->render_and_frame_size_different,
+ .allow_screen_content_tools = frame_header->allow_screen_content_tools,
+ .is_filter_switchable = frame_header->is_filter_switchable,
+ .force_integer_mv = frame_header->force_integer_mv,
+ .frame_size_override_flag = frame_header->frame_size_override_flag,
+ .buffer_removal_time_present_flag = frame_header->buffer_removal_time_present_flag,
+ .allow_intrabc = frame_header->allow_intrabc,
+ .frame_refs_short_signaling = frame_header->frame_refs_short_signaling,
+ .allow_high_precision_mv = frame_header->allow_high_precision_mv,
+ .is_motion_mode_switchable = frame_header->is_motion_mode_switchable,
+ .use_ref_frame_mvs = frame_header->use_ref_frame_mvs,
+ .disable_frame_end_update_cdf = frame_header->disable_frame_end_update_cdf,
+ .allow_warped_motion = frame_header->allow_warped_motion,
+ .reduced_tx_set = frame_header->reduced_tx_set,
+ .reference_select = frame_header->reference_select,
+ .skip_mode_present = frame_header->skip_mode_present,
+ .delta_q_present = frame_header->delta_q_present,
+ },
+ .frame_to_show_map_idx = frame_header->frame_to_show_map_idx,
+ .frame_presentation_time = frame_header->frame_presentation_time,
+ .display_frame_id = frame_header->display_frame_id,
+ .frame_type = frame_header->frame_type,
+ .current_frame_id = frame_header->current_frame_id,
+ .order_hint = frame_header->order_hint,
+ .primary_ref_frame = frame_header->primary_ref_frame,
+ .frame_width_minus_1 = frame_header->frame_width_minus_1,
+ .frame_height_minus_1 = frame_header->frame_height_minus_1,
+ .coded_denom = frame_header->coded_denom,
+ .render_width_minus_1 = frame_header->render_width_minus_1,
+ .render_height_minus_1 = frame_header->render_height_minus_1,
+ .refresh_frame_flags = frame_header->refresh_frame_flags,
+ .interpolation_filter = frame_header->interpolation_filter,
+ .tx_mode = frame_header->tx_mode,
+ .tiling = (StdVideoAV1MESATileInfo) {
+ .flags = (StdVideoAV1MESATileInfoFlags) {
+ .uniform_tile_spacing_flag = frame_header->uniform_tile_spacing_flag,
+ },
+ .tile_cols = frame_header->tile_cols,
+ .tile_rows = frame_header->tile_rows,
+ .context_update_tile_id = frame_header->context_update_tile_id,
+ .tile_size_bytes_minus1 = frame_header->tile_size_bytes_minus1,
+ },
+ .quantization = (StdVideoAV1MESAQuantization) {
+ .flags.using_qmatrix = frame_header->using_qmatrix,
+ .base_q_idx = frame_header->base_q_idx,
+ .delta_q_y_dc = frame_header->delta_q_y_dc,
+ .diff_uv_delta = frame_header->diff_uv_delta,
+ .delta_q_u_dc = frame_header->delta_q_u_dc,
+ .delta_q_u_ac = frame_header->delta_q_u_ac,
+ .delta_q_v_dc = frame_header->delta_q_v_dc,
+ .delta_q_v_ac = frame_header->delta_q_v_ac,
+ .qm_y = frame_header->qm_y,
+ .qm_u = frame_header->qm_u,
+ .qm_v = frame_header->qm_v,
+ },
+ .delta_q = (StdVideoAV1MESADeltaQ) {
+ .flags = (StdVideoAV1MESADeltaQFlags) {
+ .delta_lf_present = frame_header->delta_lf_present,
+ .delta_lf_multi = frame_header->delta_lf_multi,
+ },
+ .delta_q_res = frame_header->delta_q_res,
+ .delta_lf_res = frame_header->delta_lf_res,
+ },
+ .loop_filter = (StdVideoAV1MESALoopFilter) {
+ .flags = (StdVideoAV1MESALoopFilterFlags) {
+ .delta_enabled = frame_header->loop_filter_delta_enabled,
+ .delta_update = frame_header->loop_filter_delta_update,
+ },
+ .level = {
+ frame_header->loop_filter_level[0], frame_header->loop_filter_level[1],
+ frame_header->loop_filter_level[2], frame_header->loop_filter_level[3],
+ },
+ .sharpness = frame_header->loop_filter_sharpness,
+ .mode_deltas = {
+ frame_header->loop_filter_mode_deltas[0], frame_header->loop_filter_mode_deltas[1],
+ },
+ },
+ .cdef = (StdVideoAV1MESACDEF) {
+ .damping_minus_3 = frame_header->cdef_damping_minus_3,
+ .bits = frame_header->cdef_bits,
+ },
+ .lr = (StdVideoAV1MESALoopRestoration) {
+ .lr_unit_shift = frame_header->lr_unit_shift,
+ .lr_uv_shift = frame_header->lr_uv_shift,
+ .lr_type = { frame_header->lr_type[0], frame_header->lr_type[1], frame_header->lr_type[2] },
+ },
+ .segmentation = (StdVideoAV1MESASegmentation) {
+ .flags = (StdVideoAV1MESASegmentationFlags) {
+ .enabled = frame_header->segmentation_enabled,
+ .update_map = frame_header->segmentation_update_map,
+ .temporal_update = frame_header->segmentation_temporal_update,
+ .update_data = frame_header->segmentation_update_data,
+ },
+ },
+ .film_grain = (StdVideoAV1MESAFilmGrainParameters) {
+ .flags = (StdVideoAV1MESAFilmGrainFlags) {
+ .apply_grain = apply_grain,
+ .chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma,
+ .overlap_flag = film_grain->overlap_flag,
+ .clip_to_restricted_range = film_grain->clip_to_restricted_range,
+ },
+ .grain_scaling_minus_8 = film_grain->grain_scaling_minus_8,
+ .ar_coeff_lag = film_grain->ar_coeff_lag,
+ .ar_coeff_shift_minus_6 = film_grain->ar_coeff_shift_minus_6,
+ .grain_scale_shift = film_grain->grain_scale_shift,
+ .grain_seed = film_grain->grain_seed,
+ .num_y_points = film_grain->num_y_points,
+ .num_cb_points = film_grain->num_cb_points,
+ .num_cr_points = film_grain->num_cr_points,
+ .cb_mult = film_grain->cb_mult,
+ .cb_luma_mult = film_grain->cb_luma_mult,
+ .cb_offset = film_grain->cb_offset,
+ .cr_mult = film_grain->cr_mult,
+ .cr_luma_mult = film_grain->cr_luma_mult,
+ .cr_offset = film_grain->cr_offset,
+ },
+ };
+
+ for (int i = 0; i < 64; i++) {
+ ap->av1_frame_header.tiling.width_in_sbs_minus_1[i] = frame_header->width_in_sbs_minus_1[i];
+ ap->av1_frame_header.tiling.height_in_sbs_minus_1[i] = frame_header->height_in_sbs_minus_1[i];
+ ap->av1_frame_header.tiling.tile_start_col_sb[i] = frame_header->tile_start_col_sb[i];
+ ap->av1_frame_header.tiling.tile_start_row_sb[i] = frame_header->tile_start_row_sb[i];
+ }
+
+ for (int i = 0; i < 8; i++) {
+ ap->av1_frame_header.segmentation.feature_enabled_bits[i] = 0;
+ for (int j = 0; j < 8; j++) {
+ ap->av1_frame_header.segmentation.feature_enabled_bits[i] |= (frame_header->feature_enabled[i][j] << j);
+ ap->av1_frame_header.segmentation.feature_data[i][j] = frame_header->feature_value[i][j];
+ }
+
+ ap->av1_frame_header.loop_filter.ref_deltas[i] = frame_header->loop_filter_ref_deltas[i];
+
+ ap->av1_frame_header.cdef.y_pri_strength[i] = frame_header->cdef_y_pri_strength[i];
+ ap->av1_frame_header.cdef.y_sec_strength[i] = frame_header->cdef_y_sec_strength[i];
+ ap->av1_frame_header.cdef.uv_pri_strength[i] = frame_header->cdef_uv_pri_strength[i];
+ ap->av1_frame_header.cdef.uv_sec_strength[i] = frame_header->cdef_uv_sec_strength[i];
+
+ ap->av1_frame_header.ref_order_hint[i] = frame_header->ref_order_hint[i];
+ ap->av1_frame_header.global_motion[i] = (StdVideoAV1MESAGlobalMotion) {
+ .flags = (StdVideoAV1MESAGlobalMotionFlags) {
+ .gm_invalid = s->cur_frame.gm_invalid[i],
+ },
+ .gm_type = s->cur_frame.gm_type[i],
+ .gm_params = {
+ frame_header->gm_params[i][0], frame_header->gm_params[i][1],
+ frame_header->gm_params[i][2], frame_header->gm_params[i][3],
+ frame_header->gm_params[i][4], frame_header->gm_params[i][5],
+ },
+ };
+ }
+
+ for (int i = 0; i < 7; i++) {
+ ap->av1_frame_header.ref_frame_idx[i] = frame_header->ref_frame_idx[i];
+ ap->av1_frame_header.delta_frame_id_minus1[i] = frame_header->delta_frame_id_minus1[i];
+ }
+
+ ap->av1_pic_info.skip_mode_frame_idx[0] = s->cur_frame.skip_mode_frame_idx[0];
+ ap->av1_pic_info.skip_mode_frame_idx[1] = s->cur_frame.skip_mode_frame_idx[1];
+
+ if (apply_grain) {
+ for (int i = 0; i < 14; i++) {
+ ap->av1_frame_header.film_grain.point_y_value[i] = film_grain->point_y_value[i];
+ ap->av1_frame_header.film_grain.point_y_scaling[i] = film_grain->point_y_scaling[i];
+ }
+
+ for (int i = 0; i < 10; i++) {
+ ap->av1_frame_header.film_grain.point_cb_value[i] = film_grain->point_cb_value[i];
+ ap->av1_frame_header.film_grain.point_cb_scaling[i] = film_grain->point_cb_scaling[i];
+ ap->av1_frame_header.film_grain.point_cr_value[i] = film_grain->point_cr_value[i];
+ ap->av1_frame_header.film_grain.point_cr_scaling[i] = film_grain->point_cr_scaling[i];
+ }
+
+ for (int i = 0; i < 24; i++) {
+ ap->av1_frame_header.film_grain.ar_coeffs_y_plus_128[i] = film_grain->ar_coeffs_y_plus_128[i];
+ ap->av1_frame_header.film_grain.ar_coeffs_cb_plus_128[i] = film_grain->ar_coeffs_cb_plus_128[i];
+ ap->av1_frame_header.film_grain.ar_coeffs_cr_plus_128[i] = film_grain->ar_coeffs_cr_plus_128[i];
+ }
+
+ ap->av1_frame_header.film_grain.ar_coeffs_cb_plus_128[24] = film_grain->ar_coeffs_cb_plus_128[24];
+ ap->av1_frame_header.film_grain.ar_coeffs_cr_plus_128[24] = film_grain->ar_coeffs_cr_plus_128[24];
+ }
+
+ av_log(avctx, AV_LOG_DEBUG, "Created frame parameters");
+
+ /* Workaround for a spec issue. */
+ ap->dec = dec;
+
+ return 0;
+}
+
+static int vk_av1_decode_slice(AVCodecContext *avctx,
+ const uint8_t *data,
+ uint32_t size)
+{
+ int err;
+ const AV1DecContext *s = avctx->priv_data;
+ AV1VulkanDecodePicture *ap = s->cur_frame.hwaccel_picture_private;
+ FFVulkanDecodePicture *vp = &ap->vp;
+
+ for (int i = s->tg_start; i <= s->tg_end; i++) {
+ ap->tiles[ap->tile_list.nb_tiles] = (StdVideoAV1MESATile) {
+ .size = s->tile_group_info[i].tile_size,
+ .offset = s->tile_group_info[i].tile_offset,
+ .row = s->tile_group_info[i].tile_row,
+ .column = s->tile_group_info[i].tile_column,
+ .tg_start = s->tg_start,
+ .tg_end = s->tg_end,
+ };
+
+ err = ff_vk_decode_add_slice(avctx, vp, data, size, 0,
+ &ap->tile_list.nb_tiles,
+ &ap->tile_offsets);
+ if (err < 0)
+ return err;
+
+// ap->tiles[ap->tile_list.nb_tiles - 1].offset = ap->tile_offsets[ap->tile_list.nb_tiles - 1];
+ }
+
+ return 0;
+}
+
+static int vk_av1_end_frame(AVCodecContext *avctx)
+{
+ const AV1DecContext *s = avctx->priv_data;
+ const AV1Frame *pic = &s->cur_frame;
+ AV1VulkanDecodePicture *ap = pic->hwaccel_picture_private;
+ FFVulkanDecodePicture *vp = &ap->vp;
+ FFVulkanDecodePicture *rvp[AV1_NUM_REF_FRAMES] = { 0 };
+ AVFrame *rav[AV1_NUM_REF_FRAMES] = { 0 };
+
+ for (int i = 0; i < vp->decode_info.referenceSlotCount; i++) {
+ const AV1Frame *rp = ap->ref_src[i];
+ AV1VulkanDecodePicture *rhp = rp->hwaccel_picture_private;
+
+ rvp[i] = &rhp->vp;
+ rav[i] = ap->ref_src[i]->f;
+ }
+
+ av_log(avctx, AV_LOG_VERBOSE, "Decoding frame, %lu bytes, %i tiles\n",
+ vp->slices_size, ap->tile_list.nb_tiles);
+
+ return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp);
+}
+
+static void vk_av1_free_frame_priv(void *_hwctx, uint8_t *data)
+{
+ AVHWDeviceContext *hwctx = _hwctx;
+ AV1VulkanDecodePicture *ap = (AV1VulkanDecodePicture *)data;
+
+ /* Workaround for a spec issue. */
+ if (ap->frame_id_set)
+ ap->dec->frame_id_alloc_mask &= ~(1 << ap->frame_id);
+
+ /* Free frame resources, this also destroys the session parameters. */
+ ff_vk_decode_free_frame(hwctx, &ap->vp);
+
+ /* Free frame context */
+ av_free(ap);
+}
+
+const AVHWAccel ff_av1_vulkan_hwaccel = {
+ .name = "av1_vulkan",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_AV1,
+ .pix_fmt = AV_PIX_FMT_VULKAN,
+ .start_frame = &vk_av1_start_frame,
+ .decode_slice = &vk_av1_decode_slice,
+ .end_frame = &vk_av1_end_frame,
+ .free_frame_priv = &vk_av1_free_frame_priv,
+ .frame_priv_data_size = sizeof(AV1VulkanDecodePicture),
+ .init = &ff_vk_decode_init,
+ .update_thread_context = &ff_vk_update_thread_context,
+ .decode_params = &ff_vk_params_changed,
+ .flush = &ff_vk_decode_flush,
+ .uninit = &ff_vk_decode_uninit,
+ .frame_params = &ff_vk_frame_params,
+ .priv_data_size = sizeof(FFVulkanDecodeContext),
+
+ /* NOTE: Threading is intentionally disabled here. Due to the design of Vulkan,
+ * where frames are opaque to users, and mostly opaque for driver developers,
+ * there's an issue with current hardware accelerator implementations of AV1,
+ * where they require an internal index. With regular hwaccel APIs, this index
+ * is given to users as an opaque handle directly. With Vulkan, due to increased
+ * flexibility, this index cannot be present anywhere.
+ * The current implementation tracks the index for the driver and submits it
+ * as necessary information. Due to needing to modify the decoding context,
+ * which is not thread-safe, on frame free, threading is disabled.
+ * In the future, once this is fixed in the spec, the workarounds may be removed
+ * and threading enabled. */
+ .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
+};
diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index a2900d9562..1d1fb9ad97 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -26,6 +26,9 @@ extern const VkExtensionProperties ff_vk_dec_h264_ext;
#if CONFIG_HEVC_VULKAN_HWACCEL
extern const VkExtensionProperties ff_vk_dec_hevc_ext;
#endif
+#if CONFIG_AV1_VULKAN_HWACCEL
+extern const VkExtensionProperties ff_vk_dec_av1_ext;
+#endif
static const VkExtensionProperties *dec_ext[] = {
#if CONFIG_H264_VULKAN_HWACCEL
@@ -34,6 +37,9 @@ static const VkExtensionProperties *dec_ext[] = {
#if CONFIG_HEVC_VULKAN_HWACCEL
[AV_CODEC_ID_HEVC] = &ff_vk_dec_hevc_ext,
#endif
+#if CONFIG_AV1_VULKAN_HWACCEL
+ [AV_CODEC_ID_AV1] = &ff_vk_dec_av1_ext,
+#endif
};
int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
@@ -54,6 +60,8 @@ int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
dst_ctx->dedicated_dpb = src_ctx->dedicated_dpb;
dst_ctx->layered_dpb = src_ctx->layered_dpb;
+ dst_ctx->external_fg = src_ctx->external_fg;
+ dst_ctx->frame_id_alloc_mask = src_ctx->frame_id_alloc_mask;
return 0;
}
@@ -630,6 +638,7 @@ static VkResult vulkan_setup_profile(AVCodecContext *avctx,
const struct FFVkCodecMap *vk_codec,
VkVideoDecodeH264CapabilitiesKHR *h264_caps,
VkVideoDecodeH265CapabilitiesKHR *h265_caps,
+ VkVideoDecodeAV1CapabilitiesMESA *av1_caps,
int cur_profile)
{
VkVideoCapabilitiesKHR *caps = &prof->caps;
@@ -640,6 +649,7 @@ static VkResult vulkan_setup_profile(AVCodecContext *avctx,
VkVideoDecodeH264ProfileInfoKHR *h264_profile = &prof->h264_profile;
VkVideoDecodeH264ProfileInfoKHR *h265_profile = &prof->h265_profile;
+ VkVideoDecodeAV1ProfileInfoMESA *av1_profile = &prof->av1_profile;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
if (!desc)
@@ -659,6 +669,11 @@ static VkResult vulkan_setup_profile(AVCodecContext *avctx,
usage->pNext = h265_profile;
h265_profile->sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_PROFILE_INFO_KHR;
h265_profile->stdProfileIdc = cur_profile;
+ } else if (avctx->codec_id == AV_CODEC_ID_AV1) {
+ dec_caps->pNext = &av1_caps;
+ usage->pNext = av1_profile;
+ av1_profile->sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PROFILE_INFO_MESA;
+ av1_profile->stdProfileIdc = cur_profile;
}
usage->sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_USAGE_INFO_KHR;
@@ -714,6 +729,9 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
VkVideoDecodeH265CapabilitiesKHR h265_caps = {
.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_CAPABILITIES_KHR,
};
+ VkVideoDecodeAV1CapabilitiesMESA av1_caps = {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_CAPABILITIES_MESA,
+ };
VkPhysicalDeviceVideoFormatInfoKHR fmt_info = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VIDEO_FORMAT_INFO_KHR,
@@ -735,11 +753,13 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
cur_profile = avctx->profile;
base_profile = avctx->codec_id == AV_CODEC_ID_H264 ? FF_PROFILE_H264_CONSTRAINED_BASELINE :
avctx->codec_id == AV_CODEC_ID_H265 ? FF_PROFILE_HEVC_MAIN :
+ avctx->codec_id == AV_CODEC_ID_AV1 ? STD_VIDEO_AV1_MESA_PROFILE_MAIN :
0;
ret = vulkan_setup_profile(avctx, prof, hwctx, vk, vk_codec,
&h264_caps,
&h265_caps,
+ &av1_caps,
cur_profile);
if (ret == VK_ERROR_VIDEO_PROFILE_OPERATION_NOT_SUPPORTED_KHR &&
avctx->flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH &&
@@ -753,6 +773,7 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
ret = vulkan_setup_profile(avctx, prof, hwctx, vk, vk_codec,
&h264_caps,
&h265_caps,
+ &av1_caps,
cur_profile);
}
@@ -776,6 +797,7 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
max_level = avctx->codec_id == AV_CODEC_ID_H264 ? h264_caps.maxLevelIdc :
avctx->codec_id == AV_CODEC_ID_H265 ? h265_caps.maxLevelIdc :
+ avctx->codec_id == AV_CODEC_ID_AV1 ? av1_caps.maxLevelIdc :
0;
av_log(avctx, AV_LOG_VERBOSE, "Decoder capabilities for %s profile \"%s\":\n",
@@ -843,11 +865,17 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
"VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR set "
"but VK_VIDEO_CAPABILITY_SEPARATE_REFERENCE_IMAGES_BIT_KHR is unset!\n");
return AVERROR_EXTERNAL;
+ } else if (!(dec_caps->flags & VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_DISTINCT_BIT_KHR) &&
+ avctx->codec_id == AV_CODEC_ID_AV1) {
+ av_log(avctx, AV_LOG_ERROR, "Cannot initialize Vulkan decoding session, buggy driver: "
+ "codec is AV1, but VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_DISTINCT_BIT_KHR isn't set!\n");
+ return AVERROR_EXTERNAL;
}
/* TODO: make dedicated_dpb tunable */
dec->dedicated_dpb = !(dec_caps->flags & VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR);
dec->layered_dpb = !(caps->flags & VK_VIDEO_CAPABILITY_SEPARATE_REFERENCE_IMAGES_BIT_KHR);
+ dec->external_fg = av1_caps.flags & VK_VIDEO_DECODE_AV1_CAPABILITY_EXTERNAL_FILM_GRAIN_MESA;
if (dec->dedicated_dpb) {
fmt_info.imageUsage = VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR;
@@ -1013,10 +1041,14 @@ int ff_vk_decode_init(AVCodecContext *avctx)
VkVideoDecodeH265SessionParametersCreateInfoKHR h265_params = {
.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_SESSION_PARAMETERS_CREATE_INFO_KHR,
};
+ VkVideoDecodeAV1SessionParametersCreateInfoMESA av1_params = {
+ .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_SESSION_PARAMETERS_CREATE_INFO_MESA,
+ };
VkVideoSessionParametersCreateInfoKHR session_params_create = {
.sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
.pNext = avctx->codec_id == AV_CODEC_ID_H264 ? (void *)&h264_params :
avctx->codec_id == AV_CODEC_ID_HEVC ? (void *)&h265_params :
+ avctx->codec_id == AV_CODEC_ID_AV1 ? (void *)&av1_params :
NULL,
};
VkVideoSessionCreateInfoKHR session_create = {
@@ -1100,7 +1132,7 @@ int ff_vk_decode_init(AVCodecContext *avctx)
}
/* If doing an out-of-place decoding, create a DPB pool */
- if (dec->dedicated_dpb) {
+ if (dec->dedicated_dpb || avctx->codec_id == AV_CODEC_ID_AV1) {
AVHWFramesContext *dpb_frames;
AVVulkanFramesContext *dpb_hwfc;
diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h
index bfde86e45f..681d2476cd 100644
--- a/libavcodec/vulkan_decode.h
+++ b/libavcodec/vulkan_decode.h
@@ -59,6 +59,8 @@ typedef struct FFVulkanDecodeContext {
int dedicated_dpb; /* Oddity #1 - separate DPB images */
int layered_dpb; /* Madness #1 - layered DPB images */
+ int external_fg; /* Oddity #2 - hardware can't apply film grain */
+ uint32_t frame_id_alloc_mask; /* For AV1 only */
/* Thread-local state below */
AVBufferPool *tmp_pool; /* Pool for temporary data, if needed (HEVC) */
diff --git a/libavcodec/vulkan_video.c b/libavcodec/vulkan_video.c
index 5fb867df87..24ef73ddf9 100644
--- a/libavcodec/vulkan_video.c
+++ b/libavcodec/vulkan_video.c
@@ -33,6 +33,12 @@ const FFVkCodecMap ff_vk_codec_map[AV_CODEC_ID_FIRST_AUDIO] = {
FF_VK_EXT_VIDEO_DECODE_H265,
VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR
},
+ [AV_CODEC_ID_AV1] = {
+ 0,
+ 0,
+ FF_VK_EXT_VIDEO_DECODE_AV1,
+ 0x01000000 /* TODO fix this */
+ },
};
#define ASPECT_2PLANE (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT)
diff --git a/libavcodec/vulkan_video.h b/libavcodec/vulkan_video.h
index b4adde4ec1..183ce89bf0 100644
--- a/libavcodec/vulkan_video.h
+++ b/libavcodec/vulkan_video.h
@@ -23,6 +23,8 @@
#include "vulkan.h"
#include <vk_video/vulkan_video_codecs_common.h>
+#include "vulkan_video_codec_av1std.h"
+#include "vulkan_video_codec_av1std_decode.h"
#define CODEC_VER_MAJ(ver) (ver >> 22)
#define CODEC_VER_MIN(ver) ((ver >> 12) & ((1 << 10) - 1))
diff --git a/libavcodec/vulkan_video_codec_av1std.h b/libavcodec/vulkan_video_codec_av1std.h
new file mode 100644
index 0000000000..c46236c457
--- /dev/null
+++ b/libavcodec/vulkan_video_codec_av1std.h
@@ -0,0 +1,403 @@
+/* Copyright 2023 Lynne
+ * Copyright 2023 Dave Airlie
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef VULKAN_VIDEO_CODEC_AV1STD_H_
+#define VULKAN_VIDEO_CODEC_AV1STD_H_ 1
+
+/*
+** This header is NOT YET generated from the Khronos Vulkan XML API Registry.
+**
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#define vulkan_video_codec_av1std 1
+
+#define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \
+ ((((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch)))
+#define VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_API_VERSION_0_1_0 VK_MAKE_VIDEO_STD_VERSION(0, 1, 0)
+#define VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_API_VERSION_0_1_0
+#define VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_av1_decode"
+
+typedef enum StdVideoAV1MESAProfile {
+ STD_VIDEO_AV1_MESA_PROFILE_MAIN = 0,
+ STD_VIDEO_AV1_MESA_PROFILE_HIGH = 1,
+ STD_VIDEO_AV1_MESA_PROFILE_PROFESSIONAL = 2,
+} StdVideoAV1MESAProfile;
+
+typedef enum StdVideoAV1MESALevel {
+ STD_VIDEO_AV1_MESA_LEVEL_2_0 = 0,
+ STD_VIDEO_AV1_MESA_LEVEL_2_1 = 1,
+ STD_VIDEO_AV1_MESA_LEVEL_2_2 = 2,
+ STD_VIDEO_AV1_MESA_LEVEL_2_3 = 3,
+ STD_VIDEO_AV1_MESA_LEVEL_3_0 = 4,
+ STD_VIDEO_AV1_MESA_LEVEL_3_1 = 5,
+ STD_VIDEO_AV1_MESA_LEVEL_3_2 = 6,
+ STD_VIDEO_AV1_MESA_LEVEL_3_3 = 7,
+ STD_VIDEO_AV1_MESA_LEVEL_4_0 = 8,
+ STD_VIDEO_AV1_MESA_LEVEL_4_1 = 9,
+ STD_VIDEO_AV1_MESA_LEVEL_4_2 = 10,
+ STD_VIDEO_AV1_MESA_LEVEL_4_3 = 11,
+ STD_VIDEO_AV1_MESA_LEVEL_5_0 = 12,
+ STD_VIDEO_AV1_MESA_LEVEL_5_1 = 13,
+ STD_VIDEO_AV1_MESA_LEVEL_5_2 = 14,
+ STD_VIDEO_AV1_MESA_LEVEL_5_3 = 15,
+ STD_VIDEO_AV1_MESA_LEVEL_6_0 = 16,
+ STD_VIDEO_AV1_MESA_LEVEL_6_1 = 17,
+ STD_VIDEO_AV1_MESA_LEVEL_6_2 = 18,
+ STD_VIDEO_AV1_MESA_LEVEL_6_3 = 19,
+ STD_VIDEO_AV1_MESA_LEVEL_7_0 = 20,
+ STD_VIDEO_AV1_MESA_LEVEL_7_1 = 21,
+ STD_VIDEO_AV1_MESA_LEVEL_7_2 = 22,
+ STD_VIDEO_AV1_MESA_LEVEL_7_3 = 23,
+ STD_VIDEO_AV1_MESA_LEVEL_MAX = 31,
+} StdVideoAV1MESALevel;
+
+typedef struct StdVideoAV1MESAFilmGrainFlags {
+ uint8_t apply_grain;
+ uint8_t chroma_scaling_from_luma;
+ uint8_t overlap_flag;
+ uint8_t clip_to_restricted_range;
+} StdVideoAV1MESAFilmGrainFlags;
+
+typedef struct StdVideoAV1MESAFilmGrainParameters {
+ StdVideoAV1MESAFilmGrainFlags flags;
+ uint32_t grain_scaling_minus_8;
+ uint32_t ar_coeff_lag;
+ uint32_t ar_coeff_shift_minus_6;
+ uint32_t grain_scale_shift;
+
+ uint16_t grain_seed;
+ uint8_t num_y_points;
+ uint8_t point_y_value[14];
+ uint8_t point_y_scaling[14];
+
+ uint8_t num_cb_points;
+ uint8_t point_cb_value[10];
+ uint8_t point_cb_scaling[10];
+
+ uint8_t num_cr_points;
+ uint8_t point_cr_value[10];
+ uint8_t point_cr_scaling[10];
+
+ int8_t ar_coeffs_y_plus_128[24];
+ int8_t ar_coeffs_cb_plus_128[25];
+ int8_t ar_coeffs_cr_plus_128[25];
+ uint8_t cb_mult;
+ uint8_t cb_luma_mult;
+ uint16_t cb_offset;
+ uint8_t cr_mult;
+ uint8_t cr_luma_mult;
+ uint16_t cr_offset;
+} StdVideoAV1MESAFilmGrainParameters;
+
+typedef struct StdVideoAV1MESAGlobalMotionFlags {
+ uint8_t gm_invalid;
+} StdVideoAV1MESAGlobalMotionFlags;
+
+typedef struct StdVideoAV1MESAGlobalMotion {
+ StdVideoAV1MESAGlobalMotionFlags flags;
+ uint8_t gm_type;
+ uint32_t gm_params[6];
+} StdVideoAV1MESAGlobalMotion;
+
+typedef struct StdVideoAV1MESALoopRestoration {
+ uint8_t lr_type[3];
+ uint8_t lr_unit_shift;
+ uint8_t lr_uv_shift;
+} StdVideoAV1MESALoopRestoration;
+
+typedef struct StdVideoAV1MESATileInfoFlags {
+ uint8_t uniform_tile_spacing_flag;
+} StdVideoAV1MESATileInfoFlags;
+
+typedef struct StdVideoAV1MESATileInfo {
+ StdVideoAV1MESATileInfoFlags flags;
+ uint8_t tile_cols;
+ uint8_t tile_rows;
+ uint8_t tile_start_col_sb[64];
+ uint8_t tile_start_row_sb[64];
+ uint8_t width_in_sbs_minus_1[64];
+ uint8_t height_in_sbs_minus_1[64];
+ uint16_t context_update_tile_id;
+ uint8_t tile_size_bytes_minus1;
+} StdVideoAV1MESATileInfo;
+
+typedef struct StdVideoAV1MESAQuantizationFlags {
+ uint8_t using_qmatrix;
+} StdVideoAV1MESAQuantizationFlags;
+
+typedef struct StdVideoAV1MESAQuantization {
+ StdVideoAV1MESAQuantizationFlags flags;
+ uint8_t base_q_idx;
+ int8_t delta_q_y_dc;
+ uint8_t diff_uv_delta;
+ int8_t delta_q_u_dc;
+ int8_t delta_q_u_ac;
+ int8_t delta_q_v_dc;
+ int8_t delta_q_v_ac;
+ uint8_t qm_y;
+ uint8_t qm_u;
+ uint8_t qm_v;
+} StdVideoAV1MESAQuantization;
+
+typedef struct StdVideoAV1MESACDEF {
+ uint8_t damping_minus_3;
+ uint8_t bits;
+ uint8_t y_pri_strength[8];
+ uint8_t y_sec_strength[8];
+ uint8_t uv_pri_strength[8];
+ uint8_t uv_sec_strength[8];
+} StdVideoAV1MESACDEF;
+
+typedef struct StdVideoAV1MESADeltaQFlags {
+ uint8_t delta_lf_present;
+ uint8_t delta_lf_multi;
+} StdVideoAV1MESADeltaQFlags;
+
+typedef struct StdVideoAV1MESADeltaQ {
+ StdVideoAV1MESADeltaQFlags flags;
+ uint8_t delta_q_res;
+ uint8_t delta_lf_res;
+} StdVideoAV1MESADeltaQ;
+
+typedef struct StdVideoAV1MESASegmentationFlags {
+ uint8_t enabled;
+ uint8_t update_map;
+ uint8_t temporal_update;
+ uint8_t update_data;
+} StdVideoAV1MESASegmentationFlags;
+
+typedef struct StdVideoAV1MESASegmentation {
+ StdVideoAV1MESASegmentationFlags flags;
+ uint8_t feature_enabled_bits[8];
+ int16_t feature_data[8][8];
+} StdVideoAV1MESASegmentation;
+
+typedef struct StdVideoAV1MESALoopFilterFlags {
+ uint8_t delta_enabled;
+ uint8_t delta_update;
+} StdVideoAV1MESALoopFilterFlags;
+
+typedef struct StdVideoAV1MESALoopFilter {
+ StdVideoAV1MESALoopFilterFlags flags;
+ uint8_t level[4];
+ uint8_t sharpness;
+ int8_t ref_deltas[8];
+ int8_t mode_deltas[2];
+} StdVideoAV1MESALoopFilter;
+
+typedef struct StdVideoAV1MESAFrameHeaderFlags {
+ uint8_t error_resilient_mode;
+ uint8_t disable_cdf_update;
+ uint8_t use_superres;
+ uint8_t render_and_frame_size_different;
+ uint8_t allow_screen_content_tools;
+ uint8_t is_filter_switchable;
+ uint8_t force_integer_mv;
+ uint8_t frame_size_override_flag;
+ uint8_t buffer_removal_time_present_flag;
+ uint8_t allow_intrabc;
+ uint8_t frame_refs_short_signaling;
+ uint8_t allow_high_precision_mv;
+ uint8_t is_motion_mode_switchable;
+ uint8_t use_ref_frame_mvs;
+ uint8_t disable_frame_end_update_cdf;
+ uint8_t allow_warped_motion;
+ uint8_t reduced_tx_set;
+ uint8_t reference_select;
+ uint8_t skip_mode_present;
+ uint8_t delta_q_present;
+ uint8_t UsesLr;
+} StdVideoAV1MESAFrameHeaderFlags;
+
+typedef struct StdVideoAV1MESAFrameHeader {
+ StdVideoAV1MESAFrameHeaderFlags flags;
+
+ uint32_t frame_presentation_time;
+ uint32_t display_frame_id;
+ uint32_t current_frame_id;
+ uint8_t frame_to_show_map_idx;
+ uint8_t frame_type;
+ uint8_t order_hint;
+ uint8_t primary_ref_frame;
+ uint16_t frame_width_minus_1;
+ uint16_t frame_height_minus_1;
+ uint16_t render_width_minus_1;
+ uint16_t render_height_minus_1;
+ uint8_t coded_denom;
+
+ uint8_t refresh_frame_flags;
+ uint8_t ref_order_hint[8];
+ int8_t ref_frame_idx[7];
+ uint32_t delta_frame_id_minus1[7];
+
+ uint8_t interpolation_filter;
+ uint8_t tx_mode;
+
+ StdVideoAV1MESATileInfo tiling;
+ StdVideoAV1MESAQuantization quantization;
+ StdVideoAV1MESASegmentation segmentation;
+ StdVideoAV1MESADeltaQ delta_q;
+ StdVideoAV1MESALoopFilter loop_filter;
+ StdVideoAV1MESACDEF cdef;
+ StdVideoAV1MESALoopRestoration lr;
+ StdVideoAV1MESAGlobalMotion global_motion[8]; // One per ref frame
+ StdVideoAV1MESAFilmGrainParameters film_grain;
+} StdVideoAV1MESAFrameHeader;
+
+typedef struct StdVideoAV1MESAScreenCoding {
+ uint8_t seq_force_screen_content_tools;
+} StdVideoAV1MESAScreenCoding;
+
+typedef struct StdVideoAV1MESATimingInfoFlags {
+ uint8_t equal_picture_interval;
+} StdVideoAV1MESATimingInfoFlags;
+
+typedef struct StdVideoAV1MESATimingInfo {
+ StdVideoAV1MESATimingInfoFlags flags;
+ uint32_t num_units_in_display_tick;
+ uint32_t time_scale;
+ uint32_t num_ticks_per_picture_minus_1;
+} StdVideoAV1MESATimingInfo;
+
+typedef struct StdVideoAV1MESAColorConfigFlags {
+ uint8_t mono_chrome;
+ uint8_t color_range;
+ uint8_t separate_uv_delta_q;
+} StdVideoAV1MESAColorConfigFlags;
+
+typedef struct StdVideoAV1MESAColorConfig {
+ StdVideoAV1MESAColorConfigFlags flags;
+ uint8_t bit_depth;
+ uint8_t subsampling_x;
+ uint8_t subsampling_y;
+} StdVideoAV1MESAColorConfig;
+
+typedef struct StdVideoAV1MESASequenceHeaderFlags {
+ uint8_t still_picture;
+ uint8_t reduced_still_picture_header;
+ uint8_t use_128x128_superblock;
+ uint8_t enable_filter_intra;
+ uint8_t enable_intra_edge_filter;
+ uint8_t enable_interintra_compound;
+ uint8_t enable_masked_compound;
+ uint8_t enable_warped_motion;
+ uint8_t enable_dual_filter;
+ uint8_t enable_order_hint;
+ uint8_t enable_jnt_comp;
+ uint8_t enable_ref_frame_mvs;
+ uint8_t frame_id_numbers_present_flag;
+ uint8_t enable_superres;
+ uint8_t enable_cdef;
+ uint8_t enable_restoration;
+ uint8_t film_grain_params_present;
+ uint8_t timing_info_present_flag;
+ uint8_t initial_display_delay_present_flag;
+} StdVideoAV1MESASequenceHeaderFlags;
+
+typedef struct StdVideoAV1MESASequenceHeader {
+ StdVideoAV1MESASequenceHeaderFlags flags;
+
+ StdVideoAV1MESAProfile seq_profile;
+ uint8_t frame_width_bits_minus_1;
+ uint8_t frame_height_bits_minus_1;
+ uint16_t max_frame_width_minus_1;
+ uint16_t max_frame_height_minus_1;
+ uint8_t delta_frame_id_length_minus_2;
+ uint8_t additional_frame_id_length_minus_1;
+ uint8_t order_hint_bits_minus_1;
+ uint8_t seq_choose_integer_mv;
+ uint8_t seq_force_integer_mv;
+
+ StdVideoAV1MESATimingInfo timing_info;
+ StdVideoAV1MESAColorConfig color_config;
+} StdVideoAV1MESASequenceHeader;
+
+typedef struct StdVideoAV1MESATile {
+ uint16_t tg_start;
+ uint16_t tg_end;
+ uint16_t row;
+ uint16_t column;
+ uint32_t size;
+ uint32_t offset;
+} StdVideoAV1MESATile;
+
+typedef struct StdVideoAV1MESATileList {
+ StdVideoAV1MESATile *tile_list;
+ uint32_t nb_tiles;
+} StdVideoAV1MESATileList;
+
+typedef struct VkVideoDecodeAV1PictureInfoMESA {
+ VkStructureType sType;
+ const void *pNext;
+ StdVideoAV1MESAFrameHeader *frame_header;
+ StdVideoAV1MESATileList *tile_list;
+ uint8_t skip_mode_frame_idx[2];
+} VkVideoDecodeAV1PictureInfoMESA;
+
+typedef struct VkVideoDecodeAV1DpbSlotInfoMESA {
+ VkStructureType sType;
+ const void *pNext;
+ uint8_t frameIdx;
+ uint8_t ref_order_hint[7];
+ uint8_t disable_frame_end_update_cdf;
+} VkVideoDecodeAV1DpbSlotInfoMESA;
+
+typedef struct VkVideoDecodeAV1SessionParametersAddInfoMESA {
+ VkStructureType sType;
+ const void *pNext;
+ StdVideoAV1MESASequenceHeader *sequence_header;
+} VkVideoDecodeAV1SessionParametersAddInfoMESA;
+
+typedef struct VkVideoDecodeAV1SessionParametersCreateInfoMESA {
+ VkStructureType sType;
+ const void *pNext;
+ const VkVideoDecodeAV1SessionParametersAddInfoMESA *pParametersAddInfo;
+} VkVideoDecodeAV1SessionParametersCreateInfoMESA;
+
+typedef struct VkVideoDecodeAV1ProfileInfoMESA {
+ VkStructureType sType;
+ const void *pNext;
+ StdVideoAV1MESAProfile stdProfileIdc;
+} VkVideoDecodeAV1ProfileInfoMESA;
+
+typedef enum VkVideoDecodeAV1CapabilityFlagBitsMESA {
+ VK_VIDEO_DECODE_AV1_CAPABILITY_EXTERNAL_FILM_GRAIN_MESA = 0x00000001,
+ VK_VIDEO_DECODE_AV1_CAPABILITY_FLAG_BITS_MAX_ENUM_MESA = 0x7FFFFFFF
+} VkVideoDecodeAV1CapabilityFlagBitsMESA;
+typedef VkFlags VkVideoDecodeAV1CapabilityFlagsMESA;
+
+typedef struct VkVideoDecodeAV1CapabilitiesMESA {
+ VkStructureType sType;
+ const void *pNext;
+ VkVideoDecodeAV1CapabilityFlagsMESA flags;
+ StdVideoAV1MESALevel maxLevelIdc;
+} VkVideoDecodeAV1CapabilitiesMESA;
+
+#define VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PICTURE_INFO_MESA 1000509000
+#define VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_SESSION_PARAMETERS_CREATE_INFO_MESA 1000509001
+#define VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_SESSION_PARAMETERS_ADD_INFO_MESA 1000509002
+#define VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_DPB_SLOT_INFO_MESA 1000509003
+#define VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_CAPABILITIES_MESA 1000509004
+#define VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PROFILE_INFO_MESA 1000509005
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libavcodec/vulkan_video_codec_av1std_decode.h b/libavcodec/vulkan_video_codec_av1std_decode.h
new file mode 100644
index 0000000000..a697c00593
--- /dev/null
+++ b/libavcodec/vulkan_video_codec_av1std_decode.h
@@ -0,0 +1,36 @@
+/* Copyright 2023 Lynne
+ * Copyright 2023 Dave Airlie
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef VULKAN_VIDEO_CODEC_AV1STD_DECODE_H_
+#define VULKAN_VIDEO_CODEC_AV1STD_DECODE_H_ 1
+
+/*
+** This header is NOT YET generated from the Khronos Vulkan XML API Registry.
+**
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#define vulkan_video_codec_av1std_decode 1
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif