| 1590 | } |
| 1591 | |
| 1592 | static int d3d12va_encode_create_command_objects(AVCodecContext *avctx) |
| 1593 | { |
| 1594 | D3D12VAEncodeContext *ctx = avctx->priv_data; |
| 1595 | ID3D12CommandAllocator *command_allocator = NULL; |
| 1596 | int err = AVERROR_UNKNOWN; |
| 1597 | HRESULT hr; |
| 1598 | |
| 1599 | D3D12_COMMAND_QUEUE_DESC queue_desc = { |
| 1600 | .Type = D3D12_COMMAND_LIST_TYPE_VIDEO_ENCODE, |
| 1601 | .Priority = 0, |
| 1602 | .Flags = D3D12_COMMAND_QUEUE_FLAG_NONE, |
| 1603 | .NodeMask = 0, |
| 1604 | }; |
| 1605 | |
| 1606 | ctx->allocator_queue = av_fifo_alloc2(D3D12VA_VIDEO_ENC_ASYNC_DEPTH, |
| 1607 | sizeof(CommandAllocator), AV_FIFO_FLAG_AUTO_GROW); |
| 1608 | if (!ctx->allocator_queue) |
| 1609 | return AVERROR(ENOMEM); |
| 1610 | |
| 1611 | hr = ID3D12Device_CreateFence(ctx->hwctx->device, 0, D3D12_FENCE_FLAG_NONE, |
| 1612 | &IID_ID3D12Fence, (void **)&ctx->sync_ctx.fence); |
| 1613 | if (FAILED(hr)) { |
| 1614 | av_log(avctx, AV_LOG_ERROR, "Failed to create fence(%lx)\n", (long)hr); |
| 1615 | err = AVERROR_UNKNOWN; |
| 1616 | goto fail; |
| 1617 | } |
| 1618 | |
| 1619 | ctx->sync_ctx.event = CreateEvent(NULL, FALSE, FALSE, NULL); |
| 1620 | if (!ctx->sync_ctx.event) |
| 1621 | goto fail; |
| 1622 | |
| 1623 | err = d3d12va_get_valid_command_allocator(avctx, &command_allocator); |
| 1624 | if (err < 0) |
| 1625 | goto fail; |
| 1626 | |
| 1627 | hr = ID3D12Device_CreateCommandQueue(ctx->hwctx->device, &queue_desc, |
| 1628 | &IID_ID3D12CommandQueue, (void **)&ctx->command_queue); |
| 1629 | if (FAILED(hr)) { |
| 1630 | av_log(avctx, AV_LOG_ERROR, "Failed to create command queue(%lx)\n", (long)hr); |
| 1631 | err = AVERROR_UNKNOWN; |
| 1632 | goto fail; |
| 1633 | } |
| 1634 | |
| 1635 | hr = ID3D12Device_CreateCommandList(ctx->hwctx->device, 0, queue_desc.Type, |
| 1636 | command_allocator, NULL, &IID_ID3D12CommandList, |
| 1637 | (void **)&ctx->command_list); |
| 1638 | if (FAILED(hr)) { |
| 1639 | av_log(avctx, AV_LOG_ERROR, "Failed to create command list(%lx)\n", (long)hr); |
| 1640 | err = AVERROR_UNKNOWN; |
| 1641 | goto fail; |
| 1642 | } |
| 1643 | |
| 1644 | hr = ID3D12VideoEncodeCommandList2_Close(ctx->command_list); |
| 1645 | if (FAILED(hr)) { |
| 1646 | av_log(avctx, AV_LOG_ERROR, "Failed to close the command list(%lx)\n", (long)hr); |
| 1647 | err = AVERROR_UNKNOWN; |
| 1648 | goto fail; |
| 1649 | } |
no test coverage detected