| 263 | } |
| 264 | |
| 265 | static int d3d12va_encode_create_metadata_buffers(AVCodecContext *avctx, |
| 266 | D3D12VAEncodePicture *pic) |
| 267 | { |
| 268 | D3D12VAEncodeContext *ctx = avctx->priv_data; |
| 269 | int width = sizeof(D3D12_VIDEO_ENCODER_OUTPUT_METADATA) + sizeof(D3D12_VIDEO_ENCODER_FRAME_SUBREGION_METADATA); |
| 270 | #if CONFIG_AV1_D3D12VA_ENCODER |
| 271 | if (ctx->codec->d3d12_codec == D3D12_VIDEO_ENCODER_CODEC_AV1) { |
| 272 | width += sizeof(D3D12_VIDEO_ENCODER_AV1_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA_TILES) |
| 273 | + sizeof(D3D12_VIDEO_ENCODER_AV1_POST_ENCODE_VALUES); |
| 274 | } |
| 275 | #endif |
| 276 | D3D12_HEAP_PROPERTIES encoded_meta_props = { .Type = D3D12_HEAP_TYPE_DEFAULT }, resolved_meta_props; |
| 277 | D3D12_HEAP_TYPE resolved_heap_type = D3D12_HEAP_TYPE_READBACK; |
| 278 | HRESULT hr; |
| 279 | |
| 280 | D3D12_RESOURCE_DESC meta_desc = { |
| 281 | .Dimension = D3D12_RESOURCE_DIMENSION_BUFFER, |
| 282 | .Alignment = 0, |
| 283 | .Width = ctx->req.MaxEncoderOutputMetadataBufferSize, |
| 284 | .Height = 1, |
| 285 | .DepthOrArraySize = 1, |
| 286 | .MipLevels = 1, |
| 287 | .Format = DXGI_FORMAT_UNKNOWN, |
| 288 | .SampleDesc = { .Count = 1, .Quality = 0 }, |
| 289 | .Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR, |
| 290 | .Flags = D3D12_RESOURCE_FLAG_NONE, |
| 291 | }; |
| 292 | |
| 293 | hr = ID3D12Device_CreateCommittedResource(ctx->hwctx->device, &encoded_meta_props, D3D12_HEAP_FLAG_NONE, |
| 294 | &meta_desc, D3D12_RESOURCE_STATE_COMMON, NULL, |
| 295 | &IID_ID3D12Resource, (void **)&pic->encoded_metadata); |
| 296 | if (FAILED(hr)) { |
| 297 | av_log(avctx, AV_LOG_ERROR, "Failed to create metadata buffer.\n"); |
| 298 | return AVERROR_UNKNOWN; |
| 299 | } |
| 300 | |
| 301 | ctx->hwctx->device->lpVtbl->GetCustomHeapProperties(ctx->hwctx->device, &resolved_meta_props, 0, resolved_heap_type); |
| 302 | |
| 303 | meta_desc.Width = width; |
| 304 | |
| 305 | hr = ID3D12Device_CreateCommittedResource(ctx->hwctx->device, &resolved_meta_props, D3D12_HEAP_FLAG_NONE, |
| 306 | &meta_desc, D3D12_RESOURCE_STATE_COMMON, NULL, |
| 307 | &IID_ID3D12Resource, (void **)&pic->resolved_metadata); |
| 308 | |
| 309 | if (FAILED(hr)) { |
| 310 | av_log(avctx, AV_LOG_ERROR, "Failed to create output metadata buffer.\n"); |
| 311 | return AVERROR_UNKNOWN; |
| 312 | } |
| 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | static int d3d12va_encode_issue(AVCodecContext *avctx, |
| 318 | FFHWBaseEncodePicture *base_pic) |
no test coverage detected