66 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_NONE,
67 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8,
68 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_32x32,
69 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4,
70 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32,
75 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_NONE,
76 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8,
77 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_32x32,
78 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4,
79 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32,
84 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_NONE,
85 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8,
86 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_32x32,
87 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4,
88 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32,
93 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_NONE,
94 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8,
95 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_64x64,
96 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4,
97 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32,
102 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_NONE,
103 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8,
104 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_64x64,
105 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4,
106 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32,
113 { 30, D3D12_VIDEO_ENCODER_LEVELS_HEVC_1 },
114 { 60, D3D12_VIDEO_ENCODER_LEVELS_HEVC_2 },
115 { 63, D3D12_VIDEO_ENCODER_LEVELS_HEVC_21 },
116 { 90, D3D12_VIDEO_ENCODER_LEVELS_HEVC_3 },
117 { 93, D3D12_VIDEO_ENCODER_LEVELS_HEVC_31 },
118 { 120, D3D12_VIDEO_ENCODER_LEVELS_HEVC_4 },
119 { 123, D3D12_VIDEO_ENCODER_LEVELS_HEVC_41 },
120 { 150, D3D12_VIDEO_ENCODER_LEVELS_HEVC_5 },
121 { 153, D3D12_VIDEO_ENCODER_LEVELS_HEVC_51 },
122 { 156, D3D12_VIDEO_ENCODER_LEVELS_HEVC_52 },
123 { 180, D3D12_VIDEO_ENCODER_LEVELS_HEVC_6 },
124 { 183, D3D12_VIDEO_ENCODER_LEVELS_HEVC_61 },
125 { 186, D3D12_VIDEO_ENCODER_LEVELS_HEVC_62 },
128 static const D3D12_VIDEO_ENCODER_PROFILE_HEVC
profile_main = D3D12_VIDEO_ENCODER_PROFILE_HEVC_MAIN;
129 static const D3D12_VIDEO_ENCODER_PROFILE_HEVC
profile_main10 = D3D12_VIDEO_ENCODER_PROFILE_HEVC_MAIN10;
131 #define D3D_PROFILE_DESC(name) \
132 { sizeof(D3D12_VIDEO_ENCODER_PROFILE_HEVC), { .pHEVCProfile = (D3D12_VIDEO_ENCODER_PROFILE_HEVC *)&profile_ ## name } }
142 case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_8x8:
return 8;
143 case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_16x16:
return 16;
144 case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_32x32:
return 32;
145 case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_CUSIZE_64x64:
return 64;
154 case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_4x4:
return 4;
155 case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_8x8:
return 8;
156 case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_16x16:
return 16;
157 case D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_TUSIZE_32x32:
return 32;
164 char *
data,
size_t *data_len,
178 "%zu < %zu.\n", *data_len,
200 "type = %d.\n",
header->nal_unit_type);
208 char *
data,
size_t *data_len)
242 D3D12_VIDEO_ENCODER_PROFILE_HEVC
profile = D3D12_VIDEO_ENCODER_PROFILE_HEVC_MAIN;
243 D3D12_VIDEO_ENCODER_LEVEL_TIER_CONSTRAINTS_HEVC
level = { 0 };
245 uint8_t min_cu_size, max_cu_size, min_tu_size, max_tu_size;
249 D3D12_FEATURE_DATA_VIDEO_ENCODER_SUPPORT support = {
251 .Codec = D3D12_VIDEO_ENCODER_CODEC_HEVC,
252 .InputFormat = hwctx->
format,
253 .RateControl =
ctx->rc,
254 .IntraRefresh = D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_NONE,
255 .SubregionFrameEncoding = D3D12_VIDEO_ENCODER_FRAME_SUBREGION_LAYOUT_MODE_FULL_FRAME,
256 .ResolutionsListCount = 1,
257 .pResolutionList = &
ctx->resolution,
258 .CodecGopSequence =
ctx->gop,
260 .CodecConfiguration =
ctx->codec_conf,
261 .SuggestedProfile.DataSize =
sizeof(D3D12_VIDEO_ENCODER_PROFILE_HEVC),
262 .SuggestedProfile.pHEVCProfile = &
profile,
263 .SuggestedLevel.DataSize =
sizeof(D3D12_VIDEO_ENCODER_LEVEL_TIER_CONSTRAINTS_HEVC),
264 .SuggestedLevel.pHEVCLevelSetting = &
level,
265 .pResolutionDependentSupport = &
ctx->res_limits,
268 hr = ID3D12VideoDevice3_CheckFeatureSupport(
ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_SUPPORT,
269 &support,
sizeof(support));
276 if (!(support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_GENERAL_SUPPORT_OK)) {
278 support.ValidationFlags);
282 if (support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RECONSTRUCTED_FRAMES_REQUIRE_TEXTURE_ARRAYS) {
283 av_log(avctx,
AV_LOG_ERROR,
"D3D12 video encode on this device requires texture array support, "
284 "but it's not implemented.\n");
307 av_assert0(
ctx->res_limits.SubregionBlockPixelsSize % min_cu_size == 0);
310 ctx->res_limits.SubregionBlockPixelsSize);
312 ctx->res_limits.SubregionBlockPixelsSize);
314 if (avctx->
width !=
sps->pic_width_in_luma_samples ||
315 avctx->
height !=
sps->pic_height_in_luma_samples) {
316 sps->conformance_window_flag = 1;
317 sps->conf_win_left_offset = 0;
318 sps->conf_win_right_offset =
319 (
sps->pic_width_in_luma_samples - avctx->
width) >>
desc->log2_chroma_w;
320 sps->conf_win_top_offset = 0;
321 sps->conf_win_bottom_offset =
322 (
sps->pic_height_in_luma_samples - avctx->
height) >>
desc->log2_chroma_h;
324 sps->conformance_window_flag = 0;
327 sps->log2_max_pic_order_cnt_lsb_minus4 =
ctx->gop.pHEVCGroupOfPictures->log2_max_pic_order_cnt_lsb_minus4;
329 sps->log2_min_luma_coding_block_size_minus3 = (uint8_t)(
av_log2(min_cu_size) - 3);
330 sps->log2_diff_max_min_luma_coding_block_size = (uint8_t)(
av_log2(max_cu_size) -
av_log2(min_cu_size));
331 sps->log2_min_luma_transform_block_size_minus2 = (uint8_t)(
av_log2(min_tu_size) - 2);
332 sps->log2_diff_max_min_luma_transform_block_size = (uint8_t)(
av_log2(max_tu_size) -
av_log2(min_tu_size));
334 sps->max_transform_hierarchy_depth_inter =
ctx->codec_conf.pHEVCConfig->max_transform_hierarchy_depth_inter;
335 sps->max_transform_hierarchy_depth_intra =
ctx->codec_conf.pHEVCConfig->max_transform_hierarchy_depth_intra;
337 sps->amp_enabled_flag = !!(
ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
338 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_USE_ASYMETRIC_MOTION_PARTITION);
339 sps->sample_adaptive_offset_enabled_flag = !!(
ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
340 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_SAO_FILTER);
342 pps->cabac_init_present_flag = 1;
344 pps->init_qp_minus26 = 0;
346 pps->transform_skip_enabled_flag = !!(
ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
347 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_TRANSFORM_SKIPPING);
349 pps->pps_slice_chroma_qp_offsets_present_flag = 1;
351 pps->tiles_enabled_flag = 0;
353 pps->pps_loop_filter_across_slices_enabled_flag = !(
ctx->codec_conf.pHEVCConfig->ConfigurationFlags &
354 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_DISABLE_LOOP_FILTER_ACROSS_SLICES);
356 pps->deblocking_filter_control_present_flag = 1;
365 uint8_t min_cu_size, max_cu_size;
368 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC *
config;
369 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC hevc_caps;
371 D3D12_FEATURE_DATA_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT codec_caps = {
373 .Codec = D3D12_VIDEO_ENCODER_CODEC_HEVC,
374 .Profile =
ctx->profile->d3d12_profile,
375 .CodecSupportLimits.DataSize =
sizeof(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC),
380 codec_caps.CodecSupportLimits.pHEVCSupport = &hevc_caps;
381 hr = ID3D12VideoDevice3_CheckFeatureSupport(
ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT,
382 &codec_caps,
sizeof(codec_caps));
383 if (SUCCEEDED(hr) && codec_caps.IsSupported)
392 ctx->codec_conf.DataSize =
sizeof(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC);
394 if (!
ctx->codec_conf.pHEVCConfig)
399 config->ConfigurationFlags = D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_NONE;
400 config->MinLumaCodingUnitSize = hevc_caps.MinLumaCodingUnitSize;
401 config->MaxLumaCodingUnitSize = hevc_caps.MaxLumaCodingUnitSize;
402 config->MinLumaTransformUnitSize = hevc_caps.MinLumaTransformUnitSize;
403 config->MaxLumaTransformUnitSize = hevc_caps.MaxLumaTransformUnitSize;
404 config->max_transform_hierarchy_depth_inter = hevc_caps.max_transform_hierarchy_depth_inter;
405 config->max_transform_hierarchy_depth_intra = hevc_caps.max_transform_hierarchy_depth_intra;
407 if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_ASYMETRIC_MOTION_PARTITION_SUPPORT ||
408 hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_ASYMETRIC_MOTION_PARTITION_REQUIRED)
409 config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_USE_ASYMETRIC_MOTION_PARTITION;
411 if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_SAO_FILTER_SUPPORT)
412 config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_SAO_FILTER;
414 if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_DISABLING_LOOP_FILTER_ACROSS_SLICES_SUPPORT)
415 config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_DISABLE_LOOP_FILTER_ACROSS_SLICES;
417 if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_TRANSFORM_SKIP_SUPPORT)
418 config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC_FLAG_ENABLE_TRANSFORM_SKIPPING;
420 if (hevc_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC_FLAG_P_FRAMES_IMPLEMENTED_AS_LOW_DELAY_B_FRAMES)
421 ctx->bi_not_empty = 1;
428 "min CB size %dx%d.\n", max_cu_size, max_cu_size,
429 min_cu_size, min_cu_size);
442 int fixed_qp_idr, fixed_qp_p, fixed_qp_b;
450 if (
ctx->rc.Mode == D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE_CQP) {
451 D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP *cqp_ctl;
457 fixed_qp_idr = fixed_qp_p;
462 fixed_qp_b = fixed_qp_p;
465 "%d / %d / %d for IDR- / P- / B-frames.\n",
466 fixed_qp_idr, fixed_qp_p, fixed_qp_b);
468 ctx->rc.ConfigParams.DataSize =
sizeof(D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP);
473 cqp_ctl->ConstantQP_FullIntracodedFrame = fixed_qp_idr;
474 cqp_ctl->ConstantQP_InterPredictedFrame_PrevRefOnly = fixed_qp_p;
475 cqp_ctl->ConstantQP_InterPredictedFrame_BiDirectionalRef = fixed_qp_b;
477 ctx->rc.ConfigParams.pConfiguration_CQP = cqp_ctl;
481 ctx->gop.DataSize =
sizeof(D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE_HEVC);
483 if (!
ctx->gop.pHEVCGroupOfPictures)
486 ctx->gop.pHEVCGroupOfPictures->GOPLength = base_ctx->
gop_size;
487 ctx->gop.pHEVCGroupOfPictures->PPicturePeriod = base_ctx->
b_per_p + 1;
490 ctx->gop.pHEVCGroupOfPictures->log2_max_pic_order_cnt_lsb_minus4 =
493 ctx->gop.pHEVCGroupOfPictures->log2_max_pic_order_cnt_lsb_minus4 =
505 ctx->level.DataSize =
sizeof(D3D12_VIDEO_ENCODER_LEVEL_TIER_CONSTRAINTS_HEVC);
507 if (!
ctx->level.pHEVCLevelSetting)
523 D3D12_VIDEO_ENCODER_TIER_HEVC_MAIN :
524 D3D12_VIDEO_ENCODER_TIER_HEVC_HIGH;
531 if (!pic->
pic_ctl.pHEVCPicData)
536 av_freep(&pic->
pic_ctl.pHEVCPicData->pReferenceFramesReconPictureDescriptors);
547 D3D12_VIDEO_ENCODER_REFERENCE_PICTURE_DESCRIPTOR_HEVC *pd =
NULL;
548 UINT *ref_list0 =
NULL, *ref_list1 =
NULL;
551 pic->
pic_ctl.DataSize =
sizeof(D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_HEVC);
553 if (!pic->
pic_ctl.pHEVCPicData)
565 switch(base_pic->
type) {
567 pic->
pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_IDR_FRAME;
570 pic->
pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_I_FRAME;
573 pic->
pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_P_FRAME;
576 pic->
pic_ctl.pHEVCPicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_HEVC_B_FRAME;
582 pic->
pic_ctl.pHEVCPicData->slice_pic_parameter_set_id = 0;
594 pic->
pic_ctl.pHEVCPicData->List0ReferenceFramesCount = base_pic->
nb_refs[0];
600 href =
ref->codec_priv;
603 pd[idx].ReconstructedPictureResourceIndex = idx;
604 pd[idx].IsRefUsedByCurrentPic = TRUE;
615 pic->
pic_ctl.pHEVCPicData->List1ReferenceFramesCount = base_pic->
nb_refs[1];
621 href =
ref->codec_priv;
624 pd[idx].ReconstructedPictureResourceIndex = idx;
625 pd[idx].IsRefUsedByCurrentPic = TRUE;
631 pic->
pic_ctl.pHEVCPicData->pList0ReferenceFrames = ref_list0;
632 pic->
pic_ctl.pHEVCPicData->pList1ReferenceFrames = ref_list1;
633 pic->
pic_ctl.pHEVCPicData->ReferenceFramesReconPictureDescriptorsCount = idx;
634 pic->
pic_ctl.pHEVCPicData->pReferenceFramesReconPictureDescriptors = pd;
642 .d3d12_codec = D3D12_VIDEO_ENCODER_CODEC_HEVC,
648 .default_quality = 25,
681 "in 8-bit unsigned integer.\n", avctx->
level);
686 ctx->explicit_qp = priv->
qp;
705 #define OFFSET(x) offsetof(D3D12VAEncodeHEVCContext, x)
706 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
711 {
"qp",
"Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
714 {
"profile",
"Set profile (general_profile_idc)",
718 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
719 { .i64 = value }, 0, 0, FLAGS, "profile"
724 {
"tier",
"Set tier (general_tier_flag)",
726 { .i64 = 0 }, 0, 1,
FLAGS,
"tier" },
728 { .i64 = 0 }, 0, 0,
FLAGS,
"tier" },
730 { .i64 = 1 }, 0, 0,
FLAGS,
"tier" },
732 {
"level",
"Set level (general_level_idc)",
736 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
737 { .i64 = value }, 0, 0, FLAGS, "level"
740 {
LEVEL(
"2.1", 63) },
742 {
LEVEL(
"3.1", 93) },
744 {
LEVEL(
"4.1", 123) },
746 {
LEVEL(
"5.1", 153) },
747 {
LEVEL(
"5.2", 156) },
749 {
LEVEL(
"6.1", 183) },
750 {
LEVEL(
"6.2", 186) },
760 {
"i_qfactor",
"1" },
761 {
"i_qoffset",
"0" },
762 {
"b_qfactor",
"1" },
763 {
"b_qoffset",
"0" },
777 .
p.
name =
"hevc_d3d12va",
796 .p.wrapper_name =
"d3d12va",