27 .decode_op = VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR,
29 .extensionName = VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME,
30 .specVersion = VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_SPEC_VERSION,
54 VkVideoReferenceSlotInfoKHR *ref_slot,
55 VkVideoPictureResourceInfoKHR *
ref,
56 VkVideoDecodeH264DpbSlotInfoKHR *vkh264_ref,
57 StdVideoDecodeH264ReferenceInfo *h264_ref,
59 int is_field,
int picture_structure,
72 *h264_ref = (StdVideoDecodeH264ReferenceInfo) {
75 .flags = (StdVideoDecodeH264ReferenceInfoFlags) {
76 .top_field_flag = is_field ? !!(picture_structure &
PICT_TOP_FIELD) : 0,
90 *vkh264_ref = (VkVideoDecodeH264DpbSlotInfoKHR) {
91 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_DPB_SLOT_INFO_KHR,
92 .pStdReferenceInfo = h264_ref,
95 *
ref = (VkVideoPictureResourceInfoKHR) {
96 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
97 .codedOffset = (VkOffset2D){ 0, 0 },
99 .baseArrayLayer =
ctx->common.layered_dpb ? dpb_slot_index : 0,
103 *ref_slot = (VkVideoReferenceSlotInfoKHR) {
104 .sType = VK_STRUCTURE_TYPE_VIDEO_REFERENCE_SLOT_INFO_KHR,
106 .slotIndex = dpb_slot_index,
107 .pPictureResource =
ref,
119 case 10:
return STD_VIDEO_H264_LEVEL_IDC_1_0;
120 case 11:
return STD_VIDEO_H264_LEVEL_IDC_1_1;
121 case 12:
return STD_VIDEO_H264_LEVEL_IDC_1_2;
122 case 13:
return STD_VIDEO_H264_LEVEL_IDC_1_3;
123 case 20:
return STD_VIDEO_H264_LEVEL_IDC_2_0;
124 case 21:
return STD_VIDEO_H264_LEVEL_IDC_2_1;
125 case 22:
return STD_VIDEO_H264_LEVEL_IDC_2_2;
126 case 30:
return STD_VIDEO_H264_LEVEL_IDC_3_0;
127 case 31:
return STD_VIDEO_H264_LEVEL_IDC_3_1;
128 case 32:
return STD_VIDEO_H264_LEVEL_IDC_3_2;
129 case 40:
return STD_VIDEO_H264_LEVEL_IDC_4_0;
130 case 41:
return STD_VIDEO_H264_LEVEL_IDC_4_1;
131 case 42:
return STD_VIDEO_H264_LEVEL_IDC_4_2;
132 case 50:
return STD_VIDEO_H264_LEVEL_IDC_5_0;
133 case 51:
return STD_VIDEO_H264_LEVEL_IDC_5_1;
134 case 52:
return STD_VIDEO_H264_LEVEL_IDC_5_2;
135 case 60:
return STD_VIDEO_H264_LEVEL_IDC_6_0;
136 case 61:
return STD_VIDEO_H264_LEVEL_IDC_6_1;
138 case 62:
return STD_VIDEO_H264_LEVEL_IDC_6_2;
143 StdVideoH264ScalingLists *vksps_scaling,
144 StdVideoH264HrdParameters *vksps_vui_header,
145 StdVideoH264SequenceParameterSetVui *vksps_vui,
146 StdVideoH264SequenceParameterSet *vksps)
148 *vksps_scaling = (StdVideoH264ScalingLists) {
149 .scaling_list_present_mask =
sps->scaling_matrix_present_mask,
150 .use_default_scaling_matrix_mask = 0,
153 for (
int i = 0;
i < STD_VIDEO_H264_SCALING_LIST_4X4_NUM_LISTS;
i++)
154 for (
int j = 0; j < STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS; j++)
157 for (
int i = 0;
i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS;
i++)
158 for (
int j = 0; j < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS; j++)
159 vksps_scaling->ScalingList8x8[
i][j] =
162 *vksps_vui_header = (StdVideoH264HrdParameters) {
163 .cpb_cnt_minus1 =
sps->cpb_cnt - 1,
164 .bit_rate_scale =
sps->bit_rate_scale,
165 .initial_cpb_removal_delay_length_minus1 =
sps->initial_cpb_removal_delay_length - 1,
166 .cpb_removal_delay_length_minus1 =
sps->cpb_removal_delay_length - 1,
167 .dpb_output_delay_length_minus1 =
sps->dpb_output_delay_length - 1,
168 .time_offset_length =
sps->time_offset_length,
171 for (
int i = 0;
i <
sps->cpb_cnt;
i++) {
172 vksps_vui_header->bit_rate_value_minus1[
i] =
sps->bit_rate_value[
i] - 1;
173 vksps_vui_header->cpb_size_value_minus1[
i] =
sps->cpb_size_value[
i] - 1;
174 vksps_vui_header->cbr_flag[
i] = (
sps->cpr_flag >>
i) & 0x1;
177 *vksps_vui = (StdVideoH264SequenceParameterSetVui) {
178 .aspect_ratio_idc =
sps->vui.aspect_ratio_idc,
179 .sar_width =
sps->vui.sar.num,
180 .sar_height =
sps->vui.sar.den,
181 .video_format =
sps->vui.video_format,
182 .colour_primaries =
sps->vui.colour_primaries,
183 .transfer_characteristics =
sps->vui.transfer_characteristics,
184 .matrix_coefficients =
sps->vui.matrix_coeffs,
185 .num_units_in_tick =
sps->num_units_in_tick,
186 .time_scale =
sps->time_scale,
187 .pHrdParameters = vksps_vui_header,
188 .max_num_reorder_frames =
sps->num_reorder_frames,
189 .max_dec_frame_buffering =
sps->max_dec_frame_buffering,
190 .flags = (StdVideoH264SpsVuiFlags) {
191 .aspect_ratio_info_present_flag =
sps->vui.aspect_ratio_info_present_flag,
192 .overscan_info_present_flag =
sps->vui.overscan_info_present_flag,
193 .overscan_appropriate_flag =
sps->vui.overscan_appropriate_flag,
194 .video_signal_type_present_flag =
sps->vui.video_signal_type_present_flag,
195 .video_full_range_flag =
sps->vui.video_full_range_flag,
196 .color_description_present_flag =
sps->vui.colour_description_present_flag,
197 .chroma_loc_info_present_flag =
sps->vui.chroma_location,
198 .timing_info_present_flag =
sps->timing_info_present_flag,
199 .fixed_frame_rate_flag =
sps->fixed_frame_rate_flag,
200 .bitstream_restriction_flag =
sps->bitstream_restriction_flag,
201 .nal_hrd_parameters_present_flag =
sps->nal_hrd_parameters_present_flag,
202 .vcl_hrd_parameters_present_flag =
sps->vcl_hrd_parameters_present_flag,
206 *vksps = (StdVideoH264SequenceParameterSet) {
207 .profile_idc =
sps->profile_idc,
209 .seq_parameter_set_id =
sps->sps_id,
210 .chroma_format_idc =
sps->chroma_format_idc,
211 .bit_depth_luma_minus8 =
sps->bit_depth_luma - 8,
212 .bit_depth_chroma_minus8 =
sps->bit_depth_chroma - 8,
213 .log2_max_frame_num_minus4 =
sps->log2_max_frame_num - 4,
214 .pic_order_cnt_type =
sps->poc_type,
215 .log2_max_pic_order_cnt_lsb_minus4 =
sps->poc_type ? 0 :
sps->log2_max_poc_lsb - 4,
216 .offset_for_non_ref_pic =
sps->offset_for_non_ref_pic,
217 .offset_for_top_to_bottom_field =
sps->offset_for_top_to_bottom_field,
218 .num_ref_frames_in_pic_order_cnt_cycle =
sps->poc_cycle_length,
219 .max_num_ref_frames =
sps->ref_frame_count,
220 .pic_width_in_mbs_minus1 =
sps->mb_width - 1,
221 .pic_height_in_map_units_minus1 = (
sps->mb_height/(2 -
sps->frame_mbs_only_flag)) - 1,
222 .frame_crop_left_offset =
sps->crop_left,
223 .frame_crop_right_offset =
sps->crop_right,
224 .frame_crop_top_offset =
sps->crop_top,
225 .frame_crop_bottom_offset =
sps->crop_bottom,
226 .flags = (StdVideoH264SpsFlags) {
227 .constraint_set0_flag = (
sps->constraint_set_flags >> 0) & 0x1,
228 .constraint_set1_flag = (
sps->constraint_set_flags >> 1) & 0x1,
229 .constraint_set2_flag = (
sps->constraint_set_flags >> 2) & 0x1,
230 .constraint_set3_flag = (
sps->constraint_set_flags >> 3) & 0x1,
231 .constraint_set4_flag = (
sps->constraint_set_flags >> 4) & 0x1,
232 .constraint_set5_flag = (
sps->constraint_set_flags >> 5) & 0x1,
233 .direct_8x8_inference_flag =
sps->direct_8x8_inference_flag,
234 .mb_adaptive_frame_field_flag =
sps->mb_aff,
235 .frame_mbs_only_flag =
sps->frame_mbs_only_flag,
236 .delta_pic_order_always_zero_flag =
sps->delta_pic_order_always_zero_flag,
237 .separate_colour_plane_flag =
sps->residual_color_transform_flag,
238 .gaps_in_frame_num_value_allowed_flag =
sps->gaps_in_frame_num_allowed_flag,
239 .qpprime_y_zero_transform_bypass_flag =
sps->transform_bypass,
240 .frame_cropping_flag =
sps->crop,
241 .seq_scaling_matrix_present_flag =
sps->scaling_matrix_present,
242 .vui_parameters_present_flag =
sps->vui_parameters_present_flag,
244 .pOffsetForRefFrame =
sps->offset_for_ref_frame,
245 .pScalingLists = vksps_scaling,
246 .pSequenceParameterSetVui = vksps_vui,
251 StdVideoH264ScalingLists *vkpps_scaling,
252 StdVideoH264PictureParameterSet *vkpps)
254 *vkpps_scaling = (StdVideoH264ScalingLists) {
255 .scaling_list_present_mask =
pps->pic_scaling_matrix_present_mask,
256 .use_default_scaling_matrix_mask = 0,
259 for (
int i = 0;
i < STD_VIDEO_H264_SCALING_LIST_4X4_NUM_LISTS;
i++)
260 for (
int j = 0; j < STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS; j++)
263 for (
int i = 0;
i < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS;
i++)
264 for (
int j = 0; j < STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS; j++)
265 vkpps_scaling->ScalingList8x8[
i][j] =
268 *vkpps = (StdVideoH264PictureParameterSet) {
269 .seq_parameter_set_id =
pps->sps_id,
270 .pic_parameter_set_id =
pps->pps_id,
271 .num_ref_idx_l0_default_active_minus1 =
pps->ref_count[0] - 1,
272 .num_ref_idx_l1_default_active_minus1 =
pps->ref_count[1] - 1,
273 .weighted_bipred_idc =
pps->weighted_bipred_idc,
274 .pic_init_qp_minus26 =
pps->init_qp - 26,
275 .pic_init_qs_minus26 =
pps->init_qs - 26,
276 .chroma_qp_index_offset =
pps->chroma_qp_index_offset[0],
277 .second_chroma_qp_index_offset =
pps->chroma_qp_index_offset[1],
278 .flags = (StdVideoH264PpsFlags) {
279 .transform_8x8_mode_flag =
pps->transform_8x8_mode,
280 .redundant_pic_cnt_present_flag =
pps->redundant_pic_cnt_present,
281 .constrained_intra_pred_flag =
pps->constrained_intra_pred,
282 .deblocking_filter_control_present_flag =
pps->deblocking_filter_parameters_present,
283 .weighted_pred_flag =
pps->weighted_pred,
284 .bottom_field_pic_order_in_frame_present_flag =
pps->pic_order_present,
285 .entropy_coding_mode_flag =
pps->cabac,
286 .pic_scaling_matrix_present_flag =
pps->pic_scaling_matrix_present_flag,
288 .pScalingLists = vkpps_scaling,
302 StdVideoH264SequenceParameterSetVui vksps_vui[
MAX_SPS_COUNT];
309 VkVideoDecodeH264SessionParametersAddInfoKHR h264_params_info = {
310 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_SESSION_PARAMETERS_ADD_INFO_KHR,
316 VkVideoDecodeH264SessionParametersCreateInfoKHR h264_params = {
317 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_SESSION_PARAMETERS_CREATE_INFO_KHR,
318 .pParametersAddInfo = &h264_params_info,
320 VkVideoSessionParametersCreateInfoKHR session_params_create = {
321 .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
322 .pNext = &h264_params,
323 .videoSession =
ctx->common.session,
324 .videoSessionParametersTemplate = VK_NULL_HANDLE,
329 if (
h->ps.sps_list[
i]) {
330 const SPS *sps_l =
h->ps.sps_list[
i];
331 int idx = h264_params_info.stdSPSCount;
332 set_sps(sps_l, &vksps_scaling[idx], &vksps_vui_header[idx], &vksps_vui[idx], &vksps[idx]);
333 h264_params_info.stdSPSCount++;
339 if (
h->ps.pps_list[
i]) {
340 const PPS *pps_l =
h->ps.pps_list[
i];
341 int idx = h264_params_info.stdPPSCount;
342 set_pps(pps_l, pps_l->
sps, &vkpps_scaling[idx], &vkpps[idx]);
343 h264_params_info.stdPPSCount++;
347 h264_params.maxStdSPSCount = h264_params_info.stdSPSCount;
348 h264_params.maxStdPPSCount = h264_params_info.stdPPSCount;
355 h264_params_info.stdSPSCount, h264_params_info.stdPPSCount);
365 int dpb_slot_index = 0;
381 if (pic == &
h->DPB[slot]) {
382 dpb_slot_index = slot;
389 h->DPB[dpb_slot_index].field_picture,
390 h->DPB[dpb_slot_index].reference,
396 for (
int i = 0;
i <
h->short_ref_count;
i++) {
399 if (
h->short_ref[
i] == &
h->DPB[slot]) {
400 dpb_slot_index = slot;
407 h->DPB[dpb_slot_index].field_picture,
408 h->DPB[dpb_slot_index].reference,
416 i < h->short_ref_count +
h->long_ref_count;
r++) {
421 for (
unsigned slot = 0; slot < 16; slot++) {
422 if (
h->long_ref[
r] == &
h->DPB[slot]) {
423 dpb_slot_index = slot;
430 h->DPB[dpb_slot_index].field_picture,
431 h->DPB[dpb_slot_index].reference,
438 hp->
h264pic = (StdVideoDecodeH264PictureInfo) {
439 .seq_parameter_set_id = pic->
pps->
sps_id,
440 .pic_parameter_set_id = pic->
pps->
pps_id,
445 .flags = (StdVideoDecodeH264PictureInfoFlags) {
448 .IdrPicFlag =
h->picture_idr,
449 .bottom_field_flag =
h->picture_structure !=
PICT_FRAME &&
451 .is_reference =
h->nal_ref_idc != 0,
457 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_PICTURE_INFO_KHR,
458 .pStdPictureInfo = &hp->
h264pic,
462 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR,
465 .pSetupReferenceSlot = &vp->
ref_slot,
466 .referenceSlotCount =
h->short_ref_count +
h->long_ref_count,
468 .dstPictureResource = (VkVideoPictureResourceInfoKHR) {
469 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
470 .codedOffset = (VkOffset2D){ 0, 0 },
471 .codedExtent = (VkExtent2D){ pic->
f->
width, pic->
f->
height },
500 hp->
h264pic.flags.is_intra = 0;
554 .
p.
name =
"h264_vulkan",