29 .decode_op = VK_VIDEO_CODEC_OPERATION_DECODE_AV1_BIT_KHR,
31 .extensionName = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_EXTENSION_NAME,
32 .specVersion = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_SPEC_VERSION,
74 VkVideoReferenceSlotInfoKHR *ref_slot,
75 VkVideoPictureResourceInfoKHR *
ref,
76 StdVideoDecodeAV1ReferenceInfo *vkav1_std_ref,
77 VkVideoDecodeAV1DpbSlotInfoKHR *vkav1_ref,
78 const AV1Frame *pic,
int is_current,
int has_grain,
79 const uint8_t *saved_order_hints)
91 *vkav1_std_ref = (StdVideoDecodeAV1ReferenceInfo) {
92 .flags = (StdVideoDecodeAV1ReferenceInfoFlags) {
101 if (saved_order_hints) {
103 for (
int i = 1;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++)
104 vkav1_std_ref->SavedOrderHints[
i - 1] = saved_order_hints[
i];
106 for (
int i = 0;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++)
107 vkav1_std_ref->SavedOrderHints[
i] = saved_order_hints[
i];
110 *vkav1_ref = (VkVideoDecodeAV1DpbSlotInfoKHR) {
111 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_DPB_SLOT_INFO_KHR,
112 .pStdReferenceInfo = vkav1_std_ref,
119 *
ref = (VkVideoPictureResourceInfoKHR) {
120 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
121 .codedOffset = (VkOffset2D){ 0, 0 },
122 .codedExtent = (VkExtent2D){ pic->
f->
width, pic->
f->
height },
123 .baseArrayLayer = ((has_grain || dec->
dedicated_dpb) &&
ctx->common.layered_dpb) ?
128 *ref_slot = (VkVideoReferenceSlotInfoKHR) {
129 .sType = VK_STRUCTURE_TYPE_VIDEO_REFERENCE_SLOT_INFO_KHR,
132 .pPictureResource =
ref,
149 StdVideoAV1SequenceHeader av1_sequence_header;
150 StdVideoAV1TimingInfo av1_timing_info;
151 StdVideoAV1ColorConfig av1_color_config;
152 VkVideoDecodeAV1SessionParametersCreateInfoKHR av1_params;
153 VkVideoSessionParametersCreateInfoKHR session_params_create;
157 av1_timing_info = (StdVideoAV1TimingInfo) {
158 .flags = (StdVideoAV1TimingInfoFlags) {
166 av1_color_config = (StdVideoAV1ColorConfig) {
167 .flags = (StdVideoAV1ColorConfigFlags) {
181 av1_sequence_header = (StdVideoAV1SequenceHeader) {
182 .flags = (StdVideoAV1SequenceHeaderFlags) {
213 .pTimingInfo = &av1_timing_info,
214 .pColorConfig = &av1_color_config,
217 av1_params = (VkVideoDecodeAV1SessionParametersCreateInfoKHR) {
218 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_SESSION_PARAMETERS_CREATE_INFO_KHR,
219 .pStdSequenceHeader = &av1_sequence_header,
221 session_params_create = (VkVideoSessionParametersCreateInfoKHR) {
222 .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
223 .pNext = &av1_params,
224 .videoSession =
ctx->common.session,
225 .videoSessionParametersTemplate = VK_NULL_HANDLE,
254 StdVideoAV1FrameRestorationType remap_lr_type[4] = { STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_NONE,
255 STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_SWITCHABLE,
256 STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_WIENER,
257 STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_SGRPROJ };
259 if (!dec->session_params) {
265 if (!ap->frame_id_set) {
266 unsigned slot_idx = 0;
267 for (
unsigned i = 0;
i < 32;
i++) {
268 if (!(dec->frame_id_alloc_mask & (1 <<
i))) {
273 ap->frame_id = slot_idx;
274 ap->frame_id_set = 1;
275 dec->frame_id_alloc_mask |= (1 << slot_idx);
278 ap->ref_frame_sign_bias_mask = 0x0;
279 for (
int i = 0;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++)
280 ap->ref_frame_sign_bias_mask |= pic->ref_frame_sign_bias[
i] <<
i;
282 for (
int i = 0;
i < STD_VIDEO_AV1_REFS_PER_FRAME;
i++) {
283 const int idx = pic->raw_frame_header->ref_frame_idx[
i];
291 for (
int j = 0; j < ref_count; j++) {
292 if (vp->ref_slots[j].slotIndex == hp->
frame_id) {
300 err =
vk_av1_fill_pict(avctx, &ap->ref_src[ref_count], &vp->ref_slots[ref_count],
301 &vp->refs[ref_count], &ap->std_refs[ref_count], &ap->vkav1_refs[ref_count],
312 pic, 1, apply_grain,
NULL);
316 ap->av1_pic_info = (VkVideoDecodeAV1PictureInfoKHR) {
317 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PICTURE_INFO_KHR,
318 .pStdPictureInfo = &ap->std_pic_info,
319 .frameHeaderOffset = 0,
321 .pTileOffsets =
NULL,
322 .pTileSizes = ap->tile_sizes,
325 for (
int i = 0;
i < STD_VIDEO_AV1_REFS_PER_FRAME;
i++) {
326 const int idx = pic->raw_frame_header->ref_frame_idx[
i];
333 ap->av1_pic_info.referenceNameSlotIndices[
i] = hp->
frame_id;
336 vp->decode_info = (VkVideoDecodeInfoKHR) {
337 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR,
338 .pNext = &ap->av1_pic_info,
340 .pSetupReferenceSlot = &vp->ref_slot,
341 .referenceSlotCount = ref_count,
342 .pReferenceSlots = vp->ref_slots,
343 .dstPictureResource = (VkVideoPictureResourceInfoKHR) {
344 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
345 .codedOffset = (VkOffset2D){ 0, 0 },
346 .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },
348 .imageViewBinding = vp->img_view_out,
352 ap->tile_info = (StdVideoAV1TileInfo) {
353 .flags = (StdVideoAV1TileInfoFlags) {
354 .uniform_tile_spacing_flag =
frame_header->uniform_tile_spacing_flag,
358 .context_update_tile_id =
frame_header->context_update_tile_id,
359 .tile_size_bytes_minus_1 =
frame_header->tile_size_bytes_minus1,
360 .pWidthInSbsMinus1 = ap->width_in_sbs_minus1,
361 .pHeightInSbsMinus1 = ap->height_in_sbs_minus1,
362 .pMiColStarts = ap->mi_col_starts,
363 .pMiRowStarts = ap->mi_row_starts,
366 ap->quantization = (StdVideoAV1Quantization) {
380 ap->loop_filter = (StdVideoAV1LoopFilter) {
381 .
flags = (StdVideoAV1LoopFilterFlags) {
382 .loop_filter_delta_enabled =
frame_header->loop_filter_delta_enabled,
383 .loop_filter_delta_update =
frame_header->loop_filter_delta_update,
385 .loop_filter_sharpness =
frame_header->loop_filter_sharpness,
388 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_LOOP_FILTER_STRENGTHS;
i++)
389 ap->loop_filter.loop_filter_level[
i] =
frame_header->loop_filter_level[
i];
390 for (
int i = 0;
i < STD_VIDEO_AV1_LOOP_FILTER_ADJUSTMENTS;
i++)
391 ap->loop_filter.loop_filter_mode_deltas[
i] =
frame_header->loop_filter_mode_deltas[
i];
393 ap->cdef = (StdVideoAV1CDEF) {
394 .cdef_damping_minus_3 =
frame_header->cdef_damping_minus_3,
398 ap->loop_restoration = (StdVideoAV1LoopRestoration) {
399 .FrameRestorationType[0] = remap_lr_type[
frame_header->lr_type[0]],
400 .FrameRestorationType[1] = remap_lr_type[
frame_header->lr_type[1]],
401 .FrameRestorationType[2] = remap_lr_type[
frame_header->lr_type[2]],
402 .LoopRestorationSize[0] = 1 +
frame_header->lr_unit_shift,
407 ap->film_grain = (StdVideoAV1FilmGrain) {
408 .
flags = (StdVideoAV1FilmGrainFlags) {
409 .chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma,
410 .overlap_flag = film_grain->overlap_flag,
411 .clip_to_restricted_range = film_grain->clip_to_restricted_range,
413 .grain_scaling_minus_8 = film_grain->grain_scaling_minus_8,
414 .ar_coeff_lag = film_grain->ar_coeff_lag,
415 .ar_coeff_shift_minus_6 = film_grain->ar_coeff_shift_minus_6,
416 .grain_scale_shift = film_grain->grain_scale_shift,
417 .grain_seed = film_grain->grain_seed,
418 .film_grain_params_ref_idx = film_grain->film_grain_params_ref_idx,
419 .num_y_points = film_grain->num_y_points,
420 .num_cb_points = film_grain->num_cb_points,
421 .num_cr_points = film_grain->num_cr_points,
422 .cb_mult = film_grain->cb_mult,
423 .cb_luma_mult = film_grain->cb_luma_mult,
424 .cb_offset = film_grain->cb_offset,
425 .cr_mult = film_grain->cr_mult,
426 .cr_luma_mult = film_grain->cr_luma_mult,
427 .cr_offset = film_grain->cr_offset,
431 ap->std_pic_info = (StdVideoDecodeAV1PictureInfo) {
432 .flags = (StdVideoDecodeAV1PictureInfoFlags) {
433 .error_resilient_mode =
frame_header->error_resilient_mode,
436 .render_and_frame_size_different =
frame_header->render_and_frame_size_different,
437 .allow_screen_content_tools =
frame_header->allow_screen_content_tools,
438 .is_filter_switchable =
frame_header->is_filter_switchable,
439 .force_integer_mv = pic->force_integer_mv,
440 .frame_size_override_flag =
frame_header->frame_size_override_flag,
441 .buffer_removal_time_present_flag =
frame_header->buffer_removal_time_present_flag,
443 .frame_refs_short_signaling =
frame_header->frame_refs_short_signaling,
444 .allow_high_precision_mv =
frame_header->allow_high_precision_mv,
445 .is_motion_mode_switchable =
frame_header->is_motion_mode_switchable,
447 .disable_frame_end_update_cdf =
frame_header->disable_frame_end_update_cdf,
448 .allow_warped_motion =
frame_header->allow_warped_motion,
455 .segmentation_enabled =
frame_header->segmentation_enabled,
456 .segmentation_update_map =
frame_header->segmentation_update_map,
457 .segmentation_temporal_update =
frame_header->segmentation_temporal_update,
458 .segmentation_update_data =
frame_header->segmentation_update_data,
460 .apply_grain = apply_grain,
466 .refresh_frame_flags =
frame_header->refresh_frame_flags,
467 .interpolation_filter =
frame_header->interpolation_filter,
471 .SkipModeFrame[0] =
s->cur_frame.skip_mode_frame_idx[0],
472 .SkipModeFrame[1] =
s->cur_frame.skip_mode_frame_idx[1],
474 .pTileInfo = &ap->tile_info,
475 .pQuantization = &ap->quantization,
476 .pSegmentation = &ap->segmentation,
477 .pLoopFilter = &ap->loop_filter,
479 .pLoopRestoration = &ap->loop_restoration,
480 .pGlobalMotion = &ap->global_motion,
481 .pFilmGrain = apply_grain ? &ap->film_grain :
NULL,
484 for (
int i = 0;
i < 64;
i++) {
485 ap->width_in_sbs_minus1[
i] =
frame_header->width_in_sbs_minus_1[
i];
486 ap->height_in_sbs_minus1[
i] =
frame_header->height_in_sbs_minus_1[
i];
491 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_SEGMENTS;
i++) {
492 ap->segmentation.FeatureEnabled[
i] = 0x0;
493 for (
int j = 0; j < STD_VIDEO_AV1_SEG_LVL_MAX; j++) {
494 ap->segmentation.FeatureEnabled[
i] |= (
frame_header->feature_enabled[
i][j] << j);
495 ap->segmentation.FeatureData[
i][j] =
frame_header->feature_value[
i][j];
499 if (dec->quirk_av1_offset)
500 for (
int i = 1;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++)
501 ap->std_pic_info.OrderHints[
i - 1] = pic->order_hints[
i];
503 for (
int i = 0;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++)
504 ap->std_pic_info.OrderHints[
i] = pic->order_hints[
i];
506 for (
int i = 0;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++) {
507 ap->loop_filter.loop_filter_ref_deltas[
i] =
frame_header->loop_filter_ref_deltas[
i];
508 ap->global_motion.GmType[
i] =
s->cur_frame.gm_type[
i];
509 for (
int j = 0; j < STD_VIDEO_AV1_GLOBAL_MOTION_PARAMS; j++) {
510 ap->global_motion.gm_params[
i][j] =
s->cur_frame.gm_params[
i][j];
514 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_CDEF_FILTER_STRENGTHS;
i++) {
515 ap->cdef.cdef_y_pri_strength[
i] =
frame_header->cdef_y_pri_strength[
i];
516 ap->cdef.cdef_y_sec_strength[
i] =
frame_header->cdef_y_sec_strength[
i];
517 ap->cdef.cdef_uv_pri_strength[
i] =
frame_header->cdef_uv_pri_strength[
i];
518 ap->cdef.cdef_uv_sec_strength[
i] =
frame_header->cdef_uv_sec_strength[
i];
522 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_NUM_Y_POINTS;
i++) {
523 ap->film_grain.point_y_value[
i] = film_grain->point_y_value[
i];
524 ap->film_grain.point_y_scaling[
i] = film_grain->point_y_scaling[
i];
527 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_NUM_CB_POINTS;
i++) {
528 ap->film_grain.point_cb_value[
i] = film_grain->point_cb_value[
i];
529 ap->film_grain.point_cb_scaling[
i] = film_grain->point_cb_scaling[
i];
530 ap->film_grain.point_cr_value[
i] = film_grain->point_cr_value[
i];
531 ap->film_grain.point_cr_scaling[
i] = film_grain->point_cr_scaling[
i];
534 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_NUM_POS_LUMA;
i++)
535 ap->film_grain.ar_coeffs_y_plus_128[
i] = film_grain->ar_coeffs_y_plus_128[
i];
537 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_NUM_POS_CHROMA;
i++) {
538 ap->film_grain.ar_coeffs_cb_plus_128[
i] = film_grain->ar_coeffs_cb_plus_128[
i];
539 ap->film_grain.ar_coeffs_cr_plus_128[
i] = film_grain->ar_coeffs_cr_plus_128[
i];
561 for (
int i =
s->tg_start; i <= s->tg_end;
i++) {
565 data +
s->tile_group_info[
i].tile_offset,
566 s->tile_group_info[
i].tile_size, 0,
623 .
p.
name =
"av1_vulkan",