| 1283 | } |
| 1284 | |
| 1285 | static int d3d12va_encode_init_gop_structure(AVCodecContext *avctx) |
| 1286 | { |
| 1287 | FFHWBaseEncodeContext *base_ctx = avctx->priv_data; |
| 1288 | D3D12VAEncodeContext *ctx = avctx->priv_data; |
| 1289 | uint32_t ref_l0, ref_l1; |
| 1290 | int err; |
| 1291 | HRESULT hr; |
| 1292 | D3D12_FEATURE_DATA_VIDEO_ENCODER_CODEC_PICTURE_CONTROL_SUPPORT support; |
| 1293 | union { |
| 1294 | D3D12_VIDEO_ENCODER_CODEC_PICTURE_CONTROL_SUPPORT_H264 h264; |
| 1295 | D3D12_VIDEO_ENCODER_CODEC_PICTURE_CONTROL_SUPPORT_HEVC hevc; |
| 1296 | #if CONFIG_AV1_D3D12VA_ENCODER |
| 1297 | D3D12_VIDEO_ENCODER_CODEC_AV1_PICTURE_CONTROL_SUPPORT av1; |
| 1298 | #endif |
| 1299 | } codec_support; |
| 1300 | |
| 1301 | support.NodeIndex = 0; |
| 1302 | support.Codec = ctx->codec->d3d12_codec; |
| 1303 | support.Profile = ctx->profile->d3d12_profile; |
| 1304 | |
| 1305 | switch (ctx->codec->d3d12_codec) { |
| 1306 | case D3D12_VIDEO_ENCODER_CODEC_H264: |
| 1307 | support.PictureSupport.DataSize = sizeof(codec_support.h264); |
| 1308 | support.PictureSupport.pH264Support = &codec_support.h264; |
| 1309 | break; |
| 1310 | |
| 1311 | case D3D12_VIDEO_ENCODER_CODEC_HEVC: |
| 1312 | support.PictureSupport.DataSize = sizeof(codec_support.hevc); |
| 1313 | support.PictureSupport.pHEVCSupport = &codec_support.hevc; |
| 1314 | break; |
| 1315 | |
| 1316 | #if CONFIG_AV1_D3D12VA_ENCODER |
| 1317 | case D3D12_VIDEO_ENCODER_CODEC_AV1: |
| 1318 | memset(&codec_support.av1, 0, sizeof(codec_support.av1)); |
| 1319 | support.PictureSupport.DataSize = sizeof(codec_support.av1); |
| 1320 | support.PictureSupport.pAV1Support = &codec_support.av1; |
| 1321 | break; |
| 1322 | #endif |
| 1323 | default: |
| 1324 | av_assert0(0); |
| 1325 | } |
| 1326 | |
| 1327 | hr = ID3D12VideoDevice3_CheckFeatureSupport(ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_CODEC_PICTURE_CONTROL_SUPPORT, |
| 1328 | &support, sizeof(support)); |
| 1329 | if (FAILED(hr)) |
| 1330 | return AVERROR(EINVAL); |
| 1331 | |
| 1332 | if (support.IsSupported) { |
| 1333 | switch (ctx->codec->d3d12_codec) { |
| 1334 | case D3D12_VIDEO_ENCODER_CODEC_H264: |
| 1335 | ref_l0 = FFMIN(support.PictureSupport.pH264Support->MaxL0ReferencesForP, |
| 1336 | support.PictureSupport.pH264Support->MaxL1ReferencesForB ? |
| 1337 | support.PictureSupport.pH264Support->MaxL1ReferencesForB : UINT_MAX); |
| 1338 | ref_l1 = support.PictureSupport.pH264Support->MaxL1ReferencesForB; |
| 1339 | break; |
| 1340 | |
| 1341 | case D3D12_VIDEO_ENCODER_CODEC_HEVC: |
| 1342 | ref_l0 = FFMIN(support.PictureSupport.pHEVCSupport->MaxL0ReferencesForP, |
no test coverage detected