29 .queue_flags = VK_QUEUE_VIDEO_DECODE_BIT_KHR,
30 .decode_op = VK_VIDEO_CODEC_OPERATION_DECODE_AV1_BIT_KHR,
32 .extensionName = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_EXTENSION_NAME,
33 .specVersion = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_SPEC_VERSION,
75 VkVideoReferenceSlotInfoKHR *ref_slot,
76 VkVideoPictureResourceInfoKHR *
ref,
77 StdVideoDecodeAV1ReferenceInfo *vkav1_std_ref,
78 VkVideoDecodeAV1DpbSlotInfoKHR *vkav1_ref,
79 const AV1Frame *pic,
int is_current,
int has_grain,
80 const uint8_t *saved_order_hints)
92 *vkav1_std_ref = (StdVideoDecodeAV1ReferenceInfo) {
93 .flags = (StdVideoDecodeAV1ReferenceInfoFlags) {
102 if (saved_order_hints) {
104 for (
int i = 1;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++)
105 vkav1_std_ref->SavedOrderHints[
i - 1] = saved_order_hints[
i];
107 for (
int i = 0;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++)
108 vkav1_std_ref->SavedOrderHints[
i] = saved_order_hints[
i];
111 *vkav1_ref = (VkVideoDecodeAV1DpbSlotInfoKHR) {
112 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_DPB_SLOT_INFO_KHR,
113 .pStdReferenceInfo = vkav1_std_ref,
120 *
ref = (VkVideoPictureResourceInfoKHR) {
121 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
122 .codedOffset = (VkOffset2D){ 0, 0 },
123 .codedExtent = (VkExtent2D){ pic->
f->
width, pic->
f->
height },
124 .baseArrayLayer = ((has_grain || dec->
dedicated_dpb) &&
ctx->common.layered_dpb) ?
126 .imageViewBinding = vkpic->
view.
ref[0],
129 *ref_slot = (VkVideoReferenceSlotInfoKHR) {
130 .sType = VK_STRUCTURE_TYPE_VIDEO_REFERENCE_SLOT_INFO_KHR,
133 .pPictureResource =
ref,
143 StdVideoAV1TimingInfo *av1_timing_info,
144 StdVideoAV1ColorConfig *av1_color_config,
145 StdVideoAV1SequenceHeader *av1_sequence_header)
150 *av1_timing_info = (StdVideoAV1TimingInfo) {
151 .flags = (StdVideoAV1TimingInfoFlags) {
159 *av1_color_config = (StdVideoAV1ColorConfig) {
160 .flags = (StdVideoAV1ColorConfigFlags) {
174 *av1_sequence_header = (StdVideoAV1SequenceHeader) {
175 .flags = (StdVideoAV1SequenceHeaderFlags) {
206 .pTimingInfo = av1_timing_info,
207 .pColorConfig = av1_color_config,
218 StdVideoAV1SequenceHeader av1_sequence_header;
219 StdVideoAV1TimingInfo av1_timing_info;
220 StdVideoAV1ColorConfig av1_color_config;
221 VkVideoDecodeAV1SessionParametersCreateInfoKHR av1_params;
222 VkVideoSessionParametersCreateInfoKHR session_params_create;
225 &av1_sequence_header);
227 av1_params = (VkVideoDecodeAV1SessionParametersCreateInfoKHR) {
228 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_SESSION_PARAMETERS_CREATE_INFO_KHR,
229 .pStdSequenceHeader = &av1_sequence_header,
231 session_params_create = (VkVideoSessionParametersCreateInfoKHR) {
232 .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
233 .pNext = &av1_params,
234 .videoSession =
ctx->common.session,
235 .videoSessionParametersTemplate = VK_NULL_HANDLE,
267 StdVideoAV1FrameRestorationType remap_lr_type[4] = { STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_NONE,
268 STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_SWITCHABLE,
269 STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_WIENER,
270 STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_SGRPROJ };
272 if (!dec->session_params &&
279 if (!ap->frame_id_set) {
280 unsigned slot_idx = 0;
281 for (
unsigned i = 0;
i < 32;
i++) {
282 if (!(dec->frame_id_alloc_mask & (1 <<
i))) {
287 ap->frame_id = slot_idx;
288 ap->frame_id_set = 1;
289 dec->frame_id_alloc_mask |= (1 << slot_idx);
292 ap->ref_frame_sign_bias_mask = 0x0;
293 for (
int i = 0;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++)
294 ap->ref_frame_sign_bias_mask |= pic->ref_frame_sign_bias[
i] <<
i;
296 for (
int i = 0;
i < STD_VIDEO_AV1_REFS_PER_FRAME;
i++) {
297 const int idx = pic->raw_frame_header->ref_frame_idx[
i];
305 for (
int j = 0; j < ref_count; j++) {
306 if (vp->ref_slots[j].slotIndex == hp->
frame_id) {
314 err =
vk_av1_fill_pict(avctx, &ap->ref_src[ref_count], &vp->ref_slots[ref_count],
315 &vp->refs[ref_count], &ap->std_refs[ref_count], &ap->vkav1_refs[ref_count],
326 pic, 1, apply_grain,
NULL);
330 ap->av1_pic_info = (VkVideoDecodeAV1PictureInfoKHR) {
331 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PICTURE_INFO_KHR,
332 .pStdPictureInfo = &ap->std_pic_info,
333 .frameHeaderOffset = 0,
335 .pTileOffsets =
NULL,
336 .pTileSizes = ap->tile_sizes,
339 for (
int i = 0;
i < STD_VIDEO_AV1_REFS_PER_FRAME;
i++) {
340 const int idx = pic->raw_frame_header->ref_frame_idx[
i];
347 ap->av1_pic_info.referenceNameSlotIndices[
i] = hp->
frame_id;
350 vp->decode_info = (VkVideoDecodeInfoKHR) {
351 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR,
352 .pNext = &ap->av1_pic_info,
354 .pSetupReferenceSlot = &vp->ref_slot,
355 .referenceSlotCount = ref_count,
356 .pReferenceSlots = vp->ref_slots,
357 .dstPictureResource = (VkVideoPictureResourceInfoKHR) {
358 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
359 .codedOffset = (VkOffset2D){ 0, 0 },
360 .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },
362 .imageViewBinding = vp->view.out[0],
366 ap->tile_info = (StdVideoAV1TileInfo) {
367 .flags = (StdVideoAV1TileInfoFlags) {
368 .uniform_tile_spacing_flag =
frame_header->uniform_tile_spacing_flag,
372 .context_update_tile_id =
frame_header->context_update_tile_id,
373 .tile_size_bytes_minus_1 =
frame_header->tile_size_bytes_minus1,
374 .pWidthInSbsMinus1 = ap->width_in_sbs_minus1,
375 .pHeightInSbsMinus1 = ap->height_in_sbs_minus1,
376 .pMiColStarts = ap->mi_col_starts,
377 .pMiRowStarts = ap->mi_row_starts,
380 ap->quantization = (StdVideoAV1Quantization) {
394 ap->loop_filter = (StdVideoAV1LoopFilter) {
395 .
flags = (StdVideoAV1LoopFilterFlags) {
396 .loop_filter_delta_enabled =
frame_header->loop_filter_delta_enabled,
397 .loop_filter_delta_update =
frame_header->loop_filter_delta_update,
399 .loop_filter_sharpness =
frame_header->loop_filter_sharpness,
402 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_LOOP_FILTER_STRENGTHS;
i++)
403 ap->loop_filter.loop_filter_level[
i] =
frame_header->loop_filter_level[
i];
404 for (
int i = 0;
i < STD_VIDEO_AV1_LOOP_FILTER_ADJUSTMENTS;
i++)
405 ap->loop_filter.loop_filter_mode_deltas[
i] =
frame_header->loop_filter_mode_deltas[
i];
407 ap->cdef = (StdVideoAV1CDEF) {
408 .cdef_damping_minus_3 =
frame_header->cdef_damping_minus_3,
412 ap->loop_restoration = (StdVideoAV1LoopRestoration) {
413 .FrameRestorationType[0] = remap_lr_type[
frame_header->lr_type[0]],
414 .FrameRestorationType[1] = remap_lr_type[
frame_header->lr_type[1]],
415 .FrameRestorationType[2] = remap_lr_type[
frame_header->lr_type[2]],
416 .LoopRestorationSize[0] = 1 +
frame_header->lr_unit_shift,
421 ap->film_grain = (StdVideoAV1FilmGrain) {
422 .
flags = (StdVideoAV1FilmGrainFlags) {
423 .chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma,
424 .overlap_flag = film_grain->overlap_flag,
425 .clip_to_restricted_range = film_grain->clip_to_restricted_range,
427 .grain_scaling_minus_8 = film_grain->grain_scaling_minus_8,
428 .ar_coeff_lag = film_grain->ar_coeff_lag,
429 .ar_coeff_shift_minus_6 = film_grain->ar_coeff_shift_minus_6,
430 .grain_scale_shift = film_grain->grain_scale_shift,
431 .grain_seed = film_grain->grain_seed,
432 .film_grain_params_ref_idx = film_grain->film_grain_params_ref_idx,
433 .num_y_points = film_grain->num_y_points,
434 .num_cb_points = film_grain->num_cb_points,
435 .num_cr_points = film_grain->num_cr_points,
436 .cb_mult = film_grain->cb_mult,
437 .cb_luma_mult = film_grain->cb_luma_mult,
438 .cb_offset = film_grain->cb_offset,
439 .cr_mult = film_grain->cr_mult,
440 .cr_luma_mult = film_grain->cr_luma_mult,
441 .cr_offset = film_grain->cr_offset,
445 ap->std_pic_info = (StdVideoDecodeAV1PictureInfo) {
446 .flags = (StdVideoDecodeAV1PictureInfoFlags) {
447 .error_resilient_mode =
frame_header->error_resilient_mode,
450 .render_and_frame_size_different =
frame_header->render_and_frame_size_different,
451 .allow_screen_content_tools =
frame_header->allow_screen_content_tools,
452 .is_filter_switchable =
frame_header->is_filter_switchable,
453 .force_integer_mv = pic->force_integer_mv,
454 .frame_size_override_flag =
frame_header->frame_size_override_flag,
455 .buffer_removal_time_present_flag =
frame_header->buffer_removal_time_present_flag,
457 .frame_refs_short_signaling =
frame_header->frame_refs_short_signaling,
458 .allow_high_precision_mv =
frame_header->allow_high_precision_mv,
459 .is_motion_mode_switchable =
frame_header->is_motion_mode_switchable,
461 .disable_frame_end_update_cdf =
frame_header->disable_frame_end_update_cdf,
462 .allow_warped_motion =
frame_header->allow_warped_motion,
469 .segmentation_enabled =
frame_header->segmentation_enabled,
470 .segmentation_update_map =
frame_header->segmentation_update_map,
471 .segmentation_temporal_update =
frame_header->segmentation_temporal_update,
472 .segmentation_update_data =
frame_header->segmentation_update_data,
474 .apply_grain = apply_grain,
480 .refresh_frame_flags =
frame_header->refresh_frame_flags,
481 .interpolation_filter =
frame_header->interpolation_filter,
485 .SkipModeFrame[0] =
s->cur_frame.skip_mode_frame_idx[0],
486 .SkipModeFrame[1] =
s->cur_frame.skip_mode_frame_idx[1],
488 .pTileInfo = &ap->tile_info,
489 .pQuantization = &ap->quantization,
490 .pSegmentation = &ap->segmentation,
491 .pLoopFilter = &ap->loop_filter,
493 .pLoopRestoration = &ap->loop_restoration,
494 .pGlobalMotion = &ap->global_motion,
495 .pFilmGrain = apply_grain ? &ap->film_grain :
NULL,
498 for (
int i = 0;
i < 64;
i++) {
499 ap->width_in_sbs_minus1[
i] =
frame_header->width_in_sbs_minus_1[
i];
500 ap->height_in_sbs_minus1[
i] =
frame_header->height_in_sbs_minus_1[
i];
505 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_SEGMENTS;
i++) {
506 ap->segmentation.FeatureEnabled[
i] = 0x0;
507 for (
int j = 0; j < STD_VIDEO_AV1_SEG_LVL_MAX; j++) {
508 ap->segmentation.FeatureEnabled[
i] |= (
frame_header->feature_enabled[
i][j] << j);
509 ap->segmentation.FeatureData[
i][j] =
frame_header->feature_value[
i][j];
513 if (dec->quirk_av1_offset)
514 for (
int i = 1;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++)
515 ap->std_pic_info.OrderHints[
i - 1] = pic->order_hints[
i];
517 for (
int i = 0;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++)
518 ap->std_pic_info.OrderHints[
i] = pic->order_hints[
i];
520 for (
int i = 0;
i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME;
i++) {
521 ap->loop_filter.loop_filter_ref_deltas[
i] =
frame_header->loop_filter_ref_deltas[
i];
522 ap->global_motion.GmType[
i] =
s->cur_frame.gm_type[
i];
523 for (
int j = 0; j < STD_VIDEO_AV1_GLOBAL_MOTION_PARAMS; j++) {
524 ap->global_motion.gm_params[
i][j] =
s->cur_frame.gm_params[
i][j];
528 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_CDEF_FILTER_STRENGTHS;
i++) {
529 ap->cdef.cdef_y_pri_strength[
i] =
frame_header->cdef_y_pri_strength[
i];
530 ap->cdef.cdef_y_sec_strength[
i] =
frame_header->cdef_y_sec_strength[
i];
531 ap->cdef.cdef_uv_pri_strength[
i] =
frame_header->cdef_uv_pri_strength[
i];
532 ap->cdef.cdef_uv_sec_strength[
i] =
frame_header->cdef_uv_sec_strength[
i];
536 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_NUM_Y_POINTS;
i++) {
537 ap->film_grain.point_y_value[
i] = film_grain->point_y_value[
i];
538 ap->film_grain.point_y_scaling[
i] = film_grain->point_y_scaling[
i];
541 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_NUM_CB_POINTS;
i++) {
542 ap->film_grain.point_cb_value[
i] = film_grain->point_cb_value[
i];
543 ap->film_grain.point_cb_scaling[
i] = film_grain->point_cb_scaling[
i];
544 ap->film_grain.point_cr_value[
i] = film_grain->point_cr_value[
i];
545 ap->film_grain.point_cr_scaling[
i] = film_grain->point_cr_scaling[
i];
548 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_NUM_POS_LUMA;
i++)
549 ap->film_grain.ar_coeffs_y_plus_128[
i] = film_grain->ar_coeffs_y_plus_128[
i];
551 for (
int i = 0;
i < STD_VIDEO_AV1_MAX_NUM_POS_CHROMA;
i++) {
552 ap->film_grain.ar_coeffs_cb_plus_128[
i] = film_grain->ar_coeffs_cb_plus_128[
i];
553 ap->film_grain.ar_coeffs_cr_plus_128[
i] = film_grain->ar_coeffs_cr_plus_128[
i];
575 for (
int i =
s->tg_start; i <= s->tg_end;
i++) {
579 data +
s->tile_group_info[
i].tile_offset,
580 s->tile_group_info[
i].tile_size, 0,
602 #ifdef VK_KHR_video_maintenance2
603 StdVideoAV1SequenceHeader av1_sequence_header;
604 StdVideoAV1TimingInfo av1_timing_info;
605 StdVideoAV1ColorConfig av1_color_config;
606 VkVideoDecodeAV1InlineSessionParametersInfoKHR av1_params;
610 &av1_sequence_header);
611 av1_params = (VkVideoDecodeAV1InlineSessionParametersInfoKHR) {
612 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_INLINE_SESSION_PARAMETERS_INFO_KHR,
613 .pStdSequenceHeader = &av1_sequence_header,
657 .
p.
name =
"av1_vulkan",