FFmpeg
Loading...
Searching...
No Matches
d3d12_filter.c
Go to the documentation of this file.
1/*
2 * D3D12VA filter helpers
3 *
4 * Copyright (c) 2026 Advanced Micro Devices, Inc.
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#define COBJMACROS
24
25#include <stdint.h>
26#include <string.h>
27
28#include "libavutil/avassert.h"
29#include "libavutil/fifo.h"
30#include "libavutil/frame.h"
31#include "libavutil/hwcontext.h"
33#include "libavutil/pixdesc.h"
34
35#include "d3d12_filter.h"
36#include "filters.h"
37
44
46 { AV_PIX_FMT_NV12, DXGI_FORMAT_NV12, 0 },
47 { AV_PIX_FMT_P010, DXGI_FORMAT_P010, 0 },
48 { AV_PIX_FMT_P012, DXGI_FORMAT_P016, 0 },
51 { AV_PIX_FMT_X2BGR10, DXGI_FORMAT_R10G10B10A2_UNORM, 1 },
53};
54
56{
57 for (int i = 0; i < FF_ARRAY_ELEMS(d3d12_filter_formats); i++)
58 if (d3d12_filter_formats[i].pix_fmt == fmt)
59 return &d3d12_filter_formats[i];
60
61 return NULL;
62}
63
65{
66 for (int i = 0; i < FF_ARRAY_ELEMS(d3d12_filter_formats); i++)
67 if (d3d12_filter_formats[i].dxgi_format == fmt)
68 return &d3d12_filter_formats[i];
69
70 return NULL;
71}
72
74{
75 uintptr_t i = (uintptr_t)*opaque;
76
78 return NULL;
79
80 *opaque = (void *)(i + 1);
81
82 return &d3d12_filter_formats[i];
83}
84
86{
87 switch (spc) {
89 case AVCOL_SPC_BT709:
94 return 1;
95
96 default:
97 return 0;
98 }
99}
100
102{
103 switch (trc) {
105 case AVCOL_TRC_BT709:
113 return 1;
114
115 default:
116 return 0;
117 }
118}
119
122 enum AVColorPrimaries expected_primaries,
123 const char *space_description)
124{
125 if (*primaries != AVCOL_PRI_UNSPECIFIED && *primaries != expected_primaries) {
126 const char *old_name = av_color_primaries_name(*primaries);
127 const char *new_name = av_color_primaries_name(expected_primaries);
128 if (is_output) {
130 "%s forces fixed primaries; retagging output from "
131 "%s to %s\n",
132 space_description,
133 old_name ? old_name : "unknown", new_name ? new_name : "unknown");
134 } else {
136 "%s forces fixed primaries, which disagrees with "
137 "this input's %s primaries tag\n",
138 space_description, old_name ? old_name : "unknown");
139
140 return AVERROR(EINVAL);
141 }
142 }
143
144 *primaries = expected_primaries;
145 return 0;
146}
147
149 enum AVChromaLocation chroma_loc)
150{
151 if (chroma_loc == AVCHROMA_LOC_UNSPECIFIED || chroma_loc == AVCHROMA_LOC_LEFT)
152 return 0;
153
154 if (is_output) {
156 "This DXGI color space has no chroma entry other than "
157 "left-sited; the output will actually be left-sited\n");
158
159 return 0;
160 }
161
163 "This DXGI color space has no chroma entry other than "
164 "left-sited, but this input is tagged with a different siting\n");
165
166 return AVERROR(EINVAL);
167}
168
170 enum AVChromaLocation chroma_loc)
171{
172 if (chroma_loc == AVCHROMA_LOC_UNSPECIFIED || chroma_loc == AVCHROMA_LOC_TOPLEFT)
173 return 0;
174
175 if (is_output) {
177 "HLG has no DXGI entry with any chroma siting other than "
178 "top-left; the output will actually be top-left-sited\n");
179
180 return 0;
181 }
182
184 "HLG has no DXGI entry with any chroma siting other than "
185 "top-left, but this input is tagged with a different siting\n");
186
187 return AVERROR(EINVAL);
188}
189
191 enum AVChromaLocation chroma_loc)
192{
193 if (chroma_loc == AVCHROMA_LOC_UNSPECIFIED ||
194 chroma_loc == AVCHROMA_LOC_TOPLEFT ||
195 chroma_loc == AVCHROMA_LOC_LEFT)
196 return 0;
197
198 if (is_output) {
200 "DXGI BT.2020 only supports top-left/left chroma "
201 "siting; output will use one of those instead\n");
202
203 return 0;
204 }
205
207 "DXGI BT.2020 only supports top-left/left chroma siting, "
208 "but this input is tagged with a different siting\n");
209
210 return AVERROR(EINVAL);
211}
212
213int ff_d3d12_filter_get_colorspace(AVFilterContext *ctx, int is_rgb, int is_output,
214 enum AVColorSpace *spc,
215 enum AVColorRange *range,
218 enum AVChromaLocation chroma_loc,
219 enum AVColorPrimaries input_601_hint,
220 DXGI_COLOR_SPACE_TYPE *out_space)
221{
223 int ret;
224
225 if (!is_rgb && *spc == AVCOL_SPC_BT2020_CL) {
226 if (is_output) {
228 "BT.2020 constant-luminance has no DXGI color space; "
229 "retagging output as bt2020nc\n");
231 } else {
233 "BT.2020 constant-luminance matrix has no DXGI color "
234 "space; cannot process this input without misinterpreting\n");
235
236 return AVERROR(EINVAL);
237 }
238 }
239
240 if (!is_rgb && !d3d12_filter_known_matrix(*spc)) {
241 const char *name = av_color_space_name(*spc);
243 "%s matrix has no DXGI YCbCr color space; only BT.601, "
244 "BT.709 or BT.2020 are supported\n", name ? name : "this");
245
246 return AVERROR(EINVAL);
247 }
248
249 if (!is_rgb && *trc != AVCOL_TRC_SMPTE2084 && *trc != AVCOL_TRC_ARIB_STD_B67 &&
251 const char *name = av_color_transfer_name(*trc);
253 "%s transfer has no DXGI YCbCr color space; only SDR "
254 "gamma, smpte2084 or HLG (arib-std-b67) are "
255 "supported\n",
256 name ? name : "this");
257
258 return AVERROR(EINVAL);
259 }
260
261 int primaries_is_2020 = (*primaries == AVCOL_PRI_BT2020);
262 int is_2020 = (*spc == AVCOL_SPC_BT2020_NCL || *spc == AVCOL_SPC_BT2020_CL ||
263 (*spc == AVCOL_SPC_UNSPECIFIED && primaries_is_2020));
264 int is_601 = (*spc == AVCOL_SPC_BT470BG || *spc == AVCOL_SPC_SMPTE170M ||
265 (*spc == AVCOL_SPC_UNSPECIFIED &&
267
268 if (is_rgb) {
269 enum AVColorPrimaries expected_primaries;
270
271 switch (*trc) {
273 *out_space = full_range ? DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020
274 : DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020;
275 expected_primaries = AVCOL_PRI_BT2020;
276 break;
277
279 if (is_output)
281 "HLG has no RGB DXGI color space; use a YUV "
282 "output format or a supported out_color_transfer\n");
283 else
285 "HLG transfer characteristic has no RGB DXGI color "
286 "space; this RGB input cannot be processed\n");
287 return AVERROR(EINVAL);
288
289 case AVCOL_TRC_LINEAR:
290 if (!full_range) {
291 if (is_output)
293 "Studio range linear RGB has no DXGI color "
294 "space; use out_range=full, or a non-linear "
295 "out_color_transfer (e.g. bt709)\n");
296 else
298 "Studio range linear RGB has no DXGI color "
299 "space; this input cannot be processed\n");
300
301 return AVERROR(EINVAL);
302 }
303 *out_space = DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709;
304 expected_primaries = AVCOL_PRI_BT709;
305 break;
306
307 default:
308 if (!d3d12_filter_known_sdr_trc(*trc)) {
309 const char *name = av_color_transfer_name(*trc);
311 "%s transfer has no RGB DXGI color space; only "
312 "SDR gamma, linear or smpte2084 are "
313 "supported\n", name ? name : "this");
314
315 return AVERROR(EINVAL);
316 }
317 if (primaries_is_2020) {
318 *out_space = full_range ? DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020
319 : DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020;
320 expected_primaries = AVCOL_PRI_BT2020;
321 } else {
322 *out_space = full_range ? DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
323 : DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709;
324 expected_primaries = AVCOL_PRI_BT709;
325 }
326 break;
327 }
328
329 return d3d12_filter_reconcile_primaries(ctx, is_output, primaries, expected_primaries,
330 "this RGB transfer characteristic");
331 }
332
333 /* YCbCr family. */
334 if (is_2020) {
335 int want_topleft = (chroma_loc == AVCHROMA_LOC_TOPLEFT);
337 if (ret < 0)
338 return ret;
339
340 if (*trc == AVCOL_TRC_SMPTE2084) {
341 if (full_range) {
343 "No full-range smpte2084 YCbCr DXGI color space "
344 "exists; cannot process this %s\n",
345 is_output ? "output request" : "input");
346
347 return AVERROR(EINVAL);
348 }
349 *out_space = want_topleft ? DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020
350 : DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020;
351 } else if (*trc == AVCOL_TRC_ARIB_STD_B67) {
352 ret = d3d12_filter_reject_unrepresentable_left(ctx, is_output, chroma_loc);
353 if (ret < 0)
354 return ret;
355 *out_space = full_range ? DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020
356 : DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020;
357 } else {
358 if (want_topleft && full_range) {
359 if (!is_output) {
361 "Full-range BT.2020 SDR has no top-left-sited "
362 "DXGI YCbCr color space\n");
363
364 return AVERROR(EINVAL);
365 }
367 "Full-range BT.2020 SDR has no top-left-sited DXGI "
368 "YCbCr color space; falling back to left-sited\n");
369 want_topleft = 0;
370 }
371 if (want_topleft)
372 *out_space = DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020;
373 else
374 *out_space = full_range ? DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020
375 : DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020;
376 }
377
379 "a BT.2020 matrix");
380 if (ret < 0)
381 return ret;
382 } else if (is_601) {
383 if (*trc == AVCOL_TRC_SMPTE2084 || *trc == AVCOL_TRC_ARIB_STD_B67) {
384 if (is_output)
386 "%s transfer has no BT.601 DXGI color space; use "
387 "out_color_matrix=bt2020nc or an SDR transfer\n",
388 *trc == AVCOL_TRC_SMPTE2084 ? "smpte2084" : "HLG");
389 else
391 "%s transfer has no BT.601 DXGI color space; this "
392 "input cannot be processed.\n",
393 *trc == AVCOL_TRC_SMPTE2084 ? "smpte2084" : "HLG");
394
395 return AVERROR(EINVAL);
396 }
397 ret = d3d12_filter_reject_unrepresentable_nonleft(ctx, is_output, chroma_loc);
398 if (ret < 0)
399 return ret;
400 *out_space = full_range ? DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601
401 : DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601;
402
403 enum AVColorPrimaries this_601_primaries =
406 *primaries;
407
408 if (is_output && input_601_hint != AVCOL_PRI_UNSPECIFIED) {
409 if (*primaries != AVCOL_PRI_UNSPECIFIED && *primaries != input_601_hint) {
410 const char *in_name = av_color_primaries_name(input_601_hint);
411 const char *out_name = av_color_primaries_name(*primaries);
413 "DXGI's BT.601 color spaces cannot distinguish "
414 "PAL/NTSC primaries (%s input, %s output)\n",
415 in_name ? in_name : "unknown", out_name ? out_name : "unknown");
416
417 return AVERROR(EINVAL);
418 }
419 if (*primaries != input_601_hint) {
420 const char *new_name = av_color_primaries_name(input_601_hint);
422 "BT.601 cannot change primaries; tagging output "
423 "as %s\n",
424 new_name ? new_name : "unknown");
425 }
426 *primaries = input_601_hint;
427 } else if (!is_output) {
430 const char *old_name = av_color_primaries_name(*primaries);
432 "BT.601 only represents PAL/NTSC primaries, "
433 "which disagrees with this input's %s tag\n",
434 old_name ? old_name : "unknown");
435
436 return AVERROR(EINVAL);
437 }
439 *primaries = this_601_primaries;
440 } else {
441 ret = d3d12_filter_reconcile_primaries(ctx, is_output, primaries, this_601_primaries,
442 "this BT.601 matrix");
443 if (ret < 0)
444 return ret;
445 }
446 } else {
447 /* Same gap as the BT.601 case above: no smpte2084/HLG DXGI color
448 * space exists paired with a BT.709 matrix either. */
449 if (*trc == AVCOL_TRC_SMPTE2084 || *trc == AVCOL_TRC_ARIB_STD_B67) {
450 if (is_output)
452 "%s has no BT.709 DXGI space; use "
453 "out_color_matrix=bt2020nc or SDR\n",
454 *trc == AVCOL_TRC_SMPTE2084 ? "smpte2084" : "HLG");
455 else
457 "%s has no BT.709 DXGI space; retag/convert to "
458 "BT.2020 or SDR before %s\n",
459 *trc == AVCOL_TRC_SMPTE2084 ? "smpte2084" : "HLG",
460 ctx->filter->name);
461
462 return AVERROR(EINVAL);
463 }
464 ret = d3d12_filter_reject_unrepresentable_nonleft(ctx, is_output, chroma_loc);
465 if (ret < 0)
466 return ret;
467 *out_space = full_range ? DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709
468 : DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709; ///< Default to Rec.709
469
471 "the default BT.709 matrix");
472 if (ret < 0)
473 return ret;
474 }
475
476 return 0;
477}
478
480{
481 switch (space) {
482 case DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020:
483 case DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020:
484 case DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020:
485 case DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020:
486 case DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020:
488
489 default:
490 return AVCHROMA_LOC_LEFT;
491 }
492}
493
495 const AVFrame *in)
496{
497 AVRational framerate = {0, 0};
498 FilterLink *inl = ff_filter_link(inlink);
499
500 if (inl->frame_rate.num > 0 && inl->frame_rate.den > 0) {
501 framerate = inl->frame_rate;
502 } else if (in->duration > 0 && inlink->time_base.num > 0 && inlink->time_base.den > 0) {
503 av_reduce(&framerate.num, &framerate.den,
504 inlink->time_base.den, in->duration * inlink->time_base.num,
505 INT_MAX);
506 } else {
507 framerate.num = 30;
508 framerate.den = 1;
509 av_log(ctx, AV_LOG_WARNING, "Input framerate not determinable, defaulting to 30fps\n");
510 }
511
512 return framerate;
513}
514
515int ff_d3d12_filter_wait_fence(ID3D12Fence *fence, UINT64 target,
516 HANDLE fence_event, DWORD timeout_ms)
517{
518 int has_deadline = (timeout_ms != INFINITE);
519 ULONGLONG deadline = 0;
520
521 if (ID3D12Fence_GetCompletedValue(fence) >= target)
522 return 1;
523
524 if (FAILED(ID3D12Fence_SetEventOnCompletion(fence, target, fence_event)))
525 return 0;
526
527 if (has_deadline)
528 deadline = GetTickCount64() + timeout_ms;
529
530 for (;;) {
531 DWORD wait_result = WaitForSingleObject(fence_event, timeout_ms);
532
533 if (wait_result == WAIT_OBJECT_0) {
534 if (ID3D12Fence_GetCompletedValue(fence) >= target)
535 return 1;
536 if (has_deadline) {
537 ULONGLONG now = GetTickCount64();
538 if (now >= deadline)
539 return 0;
540 timeout_ms = (DWORD)(deadline - now);
541 }
542 continue;
543 }
544
545 return 0;
546 }
547}
548
549void ff_d3d12_filter_add_frame_barriers(D3D12_RESOURCE_BARRIER *barriers, int *nb_barriers,
550 const AVD3D12VAFrame *frame, int nb_planes,
551 D3D12_RESOURCE_STATES state_before,
552 D3D12_RESOURCE_STATES state_after)
553{
554 ID3D12Resource *resource = frame->texture;
555 D3D12_RESOURCE_DESC desc;
556
557 resource->lpVtbl->GetDesc(resource, &desc);
558
559 for (int p = 0; p < nb_planes; p++) {
560 D3D12_RESOURCE_BARRIER b = {
561 .Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
562 .Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE,
563 .Transition = {
564 .pResource = resource,
565 .Subresource = frame->subresource_index + p * desc.DepthOrArraySize,
566 .StateBefore = state_before,
567 .StateAfter = state_after
568 }
569 };
570 barriers[(*nb_barriers)++] = b;
571 }
572}
573
575 enum AVPixelFormat sw_format, int width, int height,
576 int initial_pool_size, AVBufferRef **frames_ref)
577{
579 AVHWFramesContext *frames_ctx;
580 AVD3D12VAFramesContext *frames_hwctx;
582 int ret;
583
584 if (!map) {
585 av_log(ctx, AV_LOG_ERROR, "Unsupported output format: %s\n",
586 av_get_pix_fmt_name(sw_format));
587 return AVERROR(EINVAL);
588 }
589
590 ref = av_hwframe_ctx_alloc(device_ref);
591 if (!ref)
592 return AVERROR(ENOMEM);
593
594 frames_ctx = (AVHWFramesContext *)ref->data;
595 frames_ctx->format = AV_PIX_FMT_D3D12;
596 frames_ctx->sw_format = sw_format;
597 frames_ctx->width = width;
598 frames_ctx->height = height;
599 frames_ctx->initial_pool_size = initial_pool_size;
600 if (ctx->extra_hw_frames > 0)
601 frames_ctx->initial_pool_size += ctx->extra_hw_frames;
602
603 frames_hwctx = frames_ctx->hwctx;
604 frames_hwctx->format = map->dxgi_format;
605 frames_hwctx->resource_flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
606 frames_hwctx->heap_flags = D3D12_HEAP_FLAG_NONE;
607
609 if (ret < 0) {
611 return ret;
612 }
613
614 *frames_ref = ref;
615
616 return 0;
617}
618
619static ID3D12CommandList *d3d12_cmd_get_list(const D3D12CommandContext *cmd)
620{
621 switch (cmd->type) {
622 case D3D12_COMMAND_LIST_TYPE_DIRECT:
623 return (ID3D12CommandList *)cmd->list.graphics;
624 case D3D12_COMMAND_LIST_TYPE_VIDEO_PROCESS:
625 return (ID3D12CommandList *)cmd->list.video_process;
626#if HAVE_ID3D12VIDEOENCODECOMMANDLIST
627 case D3D12_COMMAND_LIST_TYPE_VIDEO_ENCODE:
628 return (ID3D12CommandList *)cmd->list.video_encode;
629#endif
630 default:
631 return NULL;
632 }
633}
634
635static HRESULT d3d12_cmd_reset_list(D3D12CommandContext *cmd, ID3D12CommandAllocator *allocator)
636{
637 switch (cmd->type) {
638 case D3D12_COMMAND_LIST_TYPE_DIRECT:
639 return ID3D12GraphicsCommandList_Reset(cmd->list.graphics, allocator, NULL);
640 case D3D12_COMMAND_LIST_TYPE_VIDEO_PROCESS:
641 return ID3D12VideoProcessCommandList_Reset(cmd->list.video_process, allocator);
642#if HAVE_ID3D12VIDEOENCODECOMMANDLIST
643 case D3D12_COMMAND_LIST_TYPE_VIDEO_ENCODE:
644 return ID3D12VideoEncodeCommandList_Reset(cmd->list.video_encode, allocator);
645#endif
646 default:
647 return E_INVALIDARG;
648 }
649}
650
652{
653 switch (cmd->type) {
654 case D3D12_COMMAND_LIST_TYPE_DIRECT:
655 return ID3D12GraphicsCommandList_Close(cmd->list.graphics);
656 case D3D12_COMMAND_LIST_TYPE_VIDEO_PROCESS:
657 return ID3D12VideoProcessCommandList_Close(cmd->list.video_process);
658#if HAVE_ID3D12VIDEOENCODECOMMANDLIST
659 case D3D12_COMMAND_LIST_TYPE_VIDEO_ENCODE:
660 return ID3D12VideoEncodeCommandList_Close(cmd->list.video_encode);
661#endif
662 default:
663 return E_INVALIDARG;
664 }
665}
666
668{
669 for (int i = 0; i < allocator->nb_input_refs; i++)
670 av_frame_free(&allocator->input_refs[i]);
671 allocator->nb_input_refs = 0;
672}
673
675 ID3D12CommandAllocator **ppAllocator)
676{
677 HRESULT hr;
678 D3D12CommandAllocator allocator;
679
680 if (av_fifo_peek(cmd->allocator_queue, &allocator, 1, 0) >= 0) {
681 UINT64 completed = ID3D12Fence_GetCompletedValue(cmd->fence);
682 if (completed >= allocator.fence_value) {
683 *ppAllocator = allocator.command_allocator;
684 av_fifo_read(cmd->allocator_queue, &allocator, 1);
685 d3d12_cmd_free_input_refs(&allocator);
686 return 0;
687 }
688 }
689
690 hr = ID3D12Device_CreateCommandAllocator(cmd->device, cmd->type,
691 &IID_ID3D12CommandAllocator, (void **)ppAllocator);
692 if (FAILED(hr)) {
693 av_log(ctx, AV_LOG_ERROR, "Failed to create a new command allocator: HRESULT 0x%lX\n", hr);
694 return AVERROR_EXTERNAL;
695 }
696
697 return 0;
698}
699
700/* Takes ownership of the command allocator and input references. */
702 D3D12CommandAllocator *allocator)
703{
704 int ret = av_fifo_write(cmd->allocator_queue, allocator, 1);
705
706 if (ret < 0) {
707 int confirmed_done = cmd->fence && cmd->fence_event &&
708 ff_d3d12_filter_wait_fence(cmd->fence, allocator->fence_value, cmd->fence_event, INFINITE);
709
710 if (confirmed_done) {
711 ID3D12CommandAllocator_Release(allocator->command_allocator);
712 d3d12_cmd_free_input_refs(allocator);
713 } else {
715 "Failed to queue a command allocator for later reuse\n");
716 }
717 }
718
719 return ret;
720}
721
723{
724 int gpu_confirmed_done = 1;
725
726 cmd->ready = 0;
727
728 if (cmd->gpu_work_submitted && cmd->queue && cmd->fence && cmd->fence_event) {
729 UINT64 drain_value = cmd->fence_value + 1;
730
731 gpu_confirmed_done = 0;
732
733 if (SUCCEEDED(ID3D12CommandQueue_Signal(cmd->queue, cmd->fence, drain_value))) {
734 UINT64 completed;
735 /* this gives one more value as defense in depth, while cost is almost nothing */
736 cmd->fence_value = drain_value + 1;
737 completed = ID3D12Fence_GetCompletedValue(cmd->fence);
738 if (completed >= drain_value)
739 gpu_confirmed_done = 1;
740 else
741 gpu_confirmed_done = ff_d3d12_filter_wait_fence(cmd->fence, drain_value,
742 cmd->fence_event, INFINITE);
743 }
744
745 if (!gpu_confirmed_done) {
746 HRESULT removed_reason = ID3D12Device_GetDeviceRemovedReason(cmd->device);
747 gpu_confirmed_done = FAILED(removed_reason);
748 if (gpu_confirmed_done)
750 "D3D12 device removed (HRESULT 0x%lX) while tearing "
751 "down %s\n", removed_reason, ctx->filter->name);
752 }
753 }
754
755 if (!gpu_confirmed_done) {
757 "Could not confirm the GPU finished all %s work "
758 "during teardown\n", ctx->filter->name);
759
760 return AVERROR_EXTERNAL;
761 }
762
763 if (cmd->fence_event) {
764 CloseHandle(cmd->fence_event);
765 cmd->fence_event = NULL;
766 }
767
768 if (cmd->fence) {
769 ID3D12Fence_Release(cmd->fence);
770 cmd->fence = NULL;
771 }
772
773 if (d3d12_cmd_get_list(cmd)) {
774 ID3D12CommandList_Release(d3d12_cmd_get_list(cmd));
775 memset(&cmd->list, 0, sizeof(cmd->list));
776 }
777
778 if (cmd->command_allocator) {
779 ID3D12CommandAllocator_Release(cmd->command_allocator);
780 cmd->command_allocator = NULL;
781 }
782
783 if (cmd->allocator_queue) {
784 D3D12CommandAllocator allocator;
785 while (av_fifo_read(cmd->allocator_queue, &allocator, 1) >= 0) {
786 ID3D12CommandAllocator_Release(allocator.command_allocator);
787 d3d12_cmd_free_input_refs(&allocator);
788 }
789 av_fifo_freep2(&cmd->allocator_queue);
790 }
791
792 if (cmd->queue) {
793 ID3D12CommandQueue_Release(cmd->queue);
794 cmd->queue = NULL;
795 }
796
797 cmd->gpu_work_submitted = 0;
798
799 return 0;
800}
801
803 ID3D12Device *device, D3D12_COMMAND_LIST_TYPE type)
804{
805 D3D12CommandAllocator allocator = { 0 };
806 const IID *list_iid;
807 HRESULT hr;
808 int ret;
809
810 switch (type) {
811 case D3D12_COMMAND_LIST_TYPE_DIRECT:
812 list_iid = &IID_ID3D12GraphicsCommandList;
813 break;
814 case D3D12_COMMAND_LIST_TYPE_VIDEO_PROCESS:
815 list_iid = &IID_ID3D12VideoProcessCommandList;
816 break;
817#if HAVE_ID3D12VIDEOENCODECOMMANDLIST
818 case D3D12_COMMAND_LIST_TYPE_VIDEO_ENCODE:
819 list_iid = &IID_ID3D12VideoEncodeCommandList;
820 break;
821#endif
822 default:
823 av_log(ctx, AV_LOG_ERROR, "Unsupported command list type %d\n", type);
824 return AVERROR(EINVAL);
825 }
826
827 if (ff_d3d12_cmd_uninit(ctx, cmd) < 0) {
829 "Cannot configure a new D3D12 command queue\n");
830 return AVERROR_EXTERNAL;
831 }
832
833 cmd->device = device;
834 cmd->type = type;
835
836 D3D12_COMMAND_QUEUE_DESC queue_desc = {
837 .Type = type,
838 .Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL,
839 .Flags = D3D12_COMMAND_QUEUE_FLAG_NONE,
840 .NodeMask = 0
841 };
842
843 hr = ID3D12Device_CreateCommandQueue(cmd->device, &queue_desc, &IID_ID3D12CommandQueue, (void **)&cmd->queue);
844 if (FAILED(hr)) {
845 av_log(ctx, AV_LOG_ERROR, "Failed to create command queue: HRESULT 0x%lX\n", hr);
847
848 return AVERROR_EXTERNAL;
849 }
850
851 hr = ID3D12Device_CreateFence(cmd->device, 0, D3D12_FENCE_FLAG_NONE, &IID_ID3D12Fence, (void **)&cmd->fence);
852 if (FAILED(hr)) {
853 av_log(ctx, AV_LOG_ERROR, "Failed to create fence: HRESULT 0x%lX\n", hr);
855 return AVERROR_EXTERNAL;
856 }
857
858 cmd->fence_value = 1;
859 cmd->fence_event = CreateEvent(NULL, FALSE, FALSE, NULL);
860 if (!cmd->fence_event) {
861 av_log(ctx, AV_LOG_ERROR, "Failed to create fence event\n");
863
864 return AVERROR_EXTERNAL;
865 }
866
867 cmd->allocator_queue = av_fifo_alloc2(2, sizeof(D3D12CommandAllocator), AV_FIFO_FLAG_AUTO_GROW);
868 if (!cmd->allocator_queue) {
870 return AVERROR(ENOMEM);
871 }
872
874 if (ret < 0) {
876 return ret;
877 }
878
879 hr = ID3D12Device_CreateCommandList(
880 cmd->device,
881 0,
882 cmd->type,
883 allocator.command_allocator,
884 NULL,
885 list_iid,
886 (void **)&cmd->list
887 );
888
889 if (FAILED(hr)) {
890 av_log(ctx, AV_LOG_ERROR, "Failed to create command list: HRESULT 0x%lX\n", hr);
891 ID3D12CommandAllocator_Release(allocator.command_allocator);
893
894 return AVERROR_EXTERNAL;
895 }
896
897 hr = d3d12_cmd_close_list(cmd);
898 if (FAILED(hr)) {
899 av_log(ctx, AV_LOG_ERROR, "Failed to close command list: HRESULT 0x%lX\n", hr);
900 if (ff_d3d12_cmd_uninit(ctx, cmd) >= 0)
901 ID3D12CommandAllocator_Release(allocator.command_allocator);
902
903 return AVERROR_EXTERNAL;
904 }
905
906 ret = d3d12_cmd_discard_command_allocator(cmd, ctx, &allocator);
907 if (ret < 0) {
909 return ret;
910 }
911
912 cmd->ready = 1;
913
914 return 0;
915}
916
917/* Called after a command list error: release everything so the caller
918 * configures a new context. */
920 ID3D12CommandAllocator *command_allocator)
921{
922 if (ff_d3d12_cmd_uninit(ctx, cmd) >= 0)
923 ID3D12CommandAllocator_Release(command_allocator);
924}
925
927{
928 ID3D12CommandAllocator *command_allocator = NULL;
929 HRESULT hr;
930 int ret;
931
932 ret = d3d12_cmd_get_valid_command_allocator(cmd, ctx, &command_allocator);
933 if (ret < 0)
934 return ret;
935
936 hr = ID3D12CommandAllocator_Reset(command_allocator);
937 if (FAILED(hr)) {
938 av_log(ctx, AV_LOG_ERROR, "Failed to reset command allocator: HRESULT 0x%lX\n", hr);
939 ID3D12CommandAllocator_Release(command_allocator);
940 return AVERROR_EXTERNAL;
941 }
942
943 hr = d3d12_cmd_reset_list(cmd, command_allocator);
944 if (FAILED(hr)) {
945 av_log(ctx, AV_LOG_ERROR, "Failed to reset command list: HRESULT 0x%lX\n", hr);
946 d3d12_cmd_force_reconfigure(ctx, cmd, command_allocator);
947 return AVERROR_EXTERNAL;
948 }
949
950 cmd->command_allocator = command_allocator;
951
952 return 0;
953}
954
956 const D3D12CommandContext *other)
957{
958 UINT64 last_value;
959 HRESULT hr;
960
961 if (!other->fence || other->fence_value <= 1)
962 return 0;
963
964 last_value = other->fence_value - 1;
965 if (ID3D12Fence_GetCompletedValue(other->fence) >= last_value)
966 return 0;
967
968 hr = ID3D12CommandQueue_Wait(cmd->queue, other->fence, last_value);
969 if (FAILED(hr)) {
970 av_log(ctx, AV_LOG_ERROR, "Failed to wait for another command queue: HRESULT 0x%lX\n", hr);
971 return AVERROR_EXTERNAL;
972 }
973 cmd->gpu_work_submitted = 1;
974
975 return 0;
976}
977
979{
980 if (!cmd->fence || cmd->fence_value <= 1)
981 return 0;
982
983 if (!ff_d3d12_filter_wait_fence(cmd->fence, cmd->fence_value - 1,
984 cmd->fence_event, timeout_ms)) {
985 av_log(ctx, AV_LOG_ERROR, "Failed to wait for %s GPU work\n", ctx->filter->name);
986 return AVERROR_EXTERNAL;
987 }
988
989 return 0;
990}
991
992/* Make the queue wait for prior GPU work on frame before this submission
993 * accesses it. Returns 1 if a wait was enqueued, 0 if none was needed. */
995 const AVFrame *frame, const char *fence_name)
996{
997 AVD3D12VAFrame *d3d12_frame = (AVD3D12VAFrame *)frame->data[0];
998 HRESULT hr;
999
1000 if (!d3d12_frame->sync_ctx.fence || !d3d12_frame->sync_ctx.fence_value)
1001 return 0;
1002
1003 if (ID3D12Fence_GetCompletedValue(d3d12_frame->sync_ctx.fence) >= d3d12_frame->sync_ctx.fence_value)
1004 return 0;
1005
1006 hr = ID3D12CommandQueue_Wait(cmd->queue, d3d12_frame->sync_ctx.fence,
1007 d3d12_frame->sync_ctx.fence_value);
1008 if (FAILED(hr)) {
1009 av_log(ctx, AV_LOG_ERROR, "Failed to wait for %s: HRESULT 0x%lX\n", fence_name, hr);
1010 return AVERROR_EXTERNAL;
1011 }
1012 cmd->gpu_work_submitted = 1;
1013
1014 return 1;
1015}
1016
1017/* After a failure with work possibly queued, try to confirm the GPU is idle
1018 * so the frames and the command allocator can be released. */
1020{
1021 HRESULT removed_reason = ID3D12Device_GetDeviceRemovedReason(cmd->device);
1022 int gpu_confirmed_done = FAILED(removed_reason);
1023
1024 if (gpu_confirmed_done) {
1026 "D3D12 device removed (HRESULT 0x%lX); frame "
1027 "resources are safe to release\n", removed_reason);
1028 } else if (cmd->queue && cmd->fence && cmd->fence_event) {
1029 UINT64 last_resort = cmd->fence_value + 1;
1030 if (SUCCEEDED(ID3D12CommandQueue_Signal(cmd->queue, cmd->fence, last_resort))) {
1031 UINT64 completed;
1032
1033 if (last_resort >= cmd->fence_value)
1034 cmd->fence_value = last_resort + 1;
1035
1036 completed = ID3D12Fence_GetCompletedValue(cmd->fence);
1037 if (completed >= last_resort) {
1038 gpu_confirmed_done = 1;
1039 } else {
1040 gpu_confirmed_done = ff_d3d12_filter_wait_fence(cmd->fence, last_resort,
1041 cmd->fence_event, 5000);
1042 if (!gpu_confirmed_done)
1044 "Post-failure GPU wait timed out; frame "
1045 "resources cannot be safely recycled\n");
1046 }
1047 } else {
1049 "Best-effort post-failure GPU sync Signal also "
1050 "failed; frame resources cannot be safely "
1051 "recycled\n");
1052 }
1053 } else {
1055 "No fence/queue for post-failure GPU sync; frame "
1056 "resources cannot be safely recycled\n");
1057 }
1058
1059 return gpu_confirmed_done;
1060}
1061
1063 AVFrame *const *inputs, int nb_inputs, AVFrame *output,
1064 int *frames_in_use)
1065{
1066 D3D12CommandAllocator allocator = {
1067 .command_allocator = cmd->command_allocator,
1068 };
1069 AVD3D12VAFrame *output_frame = output ? (AVD3D12VAFrame *)output->data[0] : NULL;
1070 UINT64 next_output_fence_value, next_private_fence_value;
1071 int wait_enqueued = 0;
1072 HRESULT hr;
1073 int ret;
1074
1075 av_assert0(nb_inputs <= D3D12_FILTER_MAX_INPUTS);
1076
1077 cmd->command_allocator = NULL;
1078 *frames_in_use = 0;
1079
1080 hr = d3d12_cmd_close_list(cmd);
1081 if (FAILED(hr)) {
1082 av_log(ctx, AV_LOG_ERROR, "Failed to close command list: HRESULT 0x%lX\n", hr);
1084 return AVERROR_EXTERNAL;
1085 }
1086
1087 /* Wait for the input frames' fences so prior GPU work on these
1088 * surfaces completes before the command list reads them. */
1089 for (int i = 0; i < nb_inputs; i++) {
1090 ret = d3d12_cmd_wait_frame(ctx, cmd, inputs[i], "input fence");
1091 if (ret < 0)
1092 goto wait_fail;
1093 wait_enqueued |= ret;
1094 }
1095
1096 if (output) {
1097 ret = d3d12_cmd_wait_frame(ctx, cmd, output, "output frame fence");
1098 if (ret < 0)
1099 goto wait_fail;
1100 }
1101
1102 ID3D12CommandList *cmd_lists[] = { d3d12_cmd_get_list(cmd) };
1103 ID3D12CommandQueue_ExecuteCommandLists(cmd->queue, 1, cmd_lists);
1104 cmd->gpu_work_submitted = 1;
1105
1106 next_private_fence_value = cmd->fence_value;
1107
1108 if (output_frame) {
1109 next_output_fence_value = output_frame->sync_ctx.fence_value + 1;
1110
1111 hr = ID3D12CommandQueue_Signal(cmd->queue, output_frame->sync_ctx.fence,
1112 next_output_fence_value);
1113 if (FAILED(hr)) {
1114 av_log(ctx, AV_LOG_ERROR, "Failed to signal output frame fence: HRESULT 0x%lX\n", hr);
1116 goto submit_fail;
1117 }
1118 output_frame->sync_ctx.fence_value = next_output_fence_value;
1119 }
1120
1121 hr = ID3D12CommandQueue_Signal(cmd->queue, cmd->fence, next_private_fence_value);
1122 if (FAILED(hr)) {
1123 av_log(ctx, AV_LOG_ERROR, "Failed to signal fence: HRESULT 0x%lX\n", hr);
1125 goto submit_fail;
1126 }
1127
1128 cmd->fence_value++;
1129
1130 allocator.fence_value = next_private_fence_value;
1131 for (int i = 0; i < nb_inputs; i++) {
1132 allocator.input_refs[i] = av_frame_clone(inputs[i]);
1133 if (!allocator.input_refs[i]) {
1134 ret = AVERROR(ENOMEM);
1135 goto submit_fail;
1136 }
1137 allocator.nb_input_refs++;
1138 }
1139
1140 return d3d12_cmd_discard_command_allocator(cmd, ctx, &allocator);
1141
1142wait_fail:
1143 if (!wait_enqueued)
1144 goto fail;
1145
1146submit_fail:
1147 if (!d3d12_cmd_sync_after_failure(ctx, cmd)) {
1149 "Abandoning this frame's input/output surfaces and "
1150 "command allocator without releasing them\n");
1151 *frames_in_use = 1;
1152 return ret;
1153 }
1154
1155fail:
1156 ID3D12CommandAllocator_Release(allocator.command_allocator);
1157 d3d12_cmd_free_input_refs(&allocator);
1158 return ret;
1159}
static const AVFilterPad inputs[]
Definition af_aap.c:299
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
static const D3D12FilterFormat d3d12_filter_formats[]
int ff_d3d12_cmd_uninit(AVFilterContext *ctx, D3D12CommandContext *cmd)
Wait for the GPU to finish all submitted work, then release all D3D12 objects and clear cmd->ready.
static void d3d12_cmd_force_reconfigure(AVFilterContext *ctx, D3D12CommandContext *cmd, ID3D12CommandAllocator *command_allocator)
AVRational ff_d3d12_filter_get_input_framerate(AVFilterContext *ctx, AVFilterLink *inlink, const AVFrame *in)
int ff_d3d12_filter_get_colorspace(AVFilterContext *ctx, int is_rgb, int is_output, enum AVColorSpace *spc, enum AVColorRange *range, enum AVColorPrimaries *primaries, enum AVColorTransferCharacteristic *trc, enum AVChromaLocation chroma_loc, enum AVColorPrimaries input_601_hint, DXGI_COLOR_SPACE_TYPE *out_space)
Map AVFrame color properties to a DXGI color space.
static ID3D12CommandList * d3d12_cmd_get_list(const D3D12CommandContext *cmd)
int ff_d3d12_cmd_sync(AVFilterContext *ctx, D3D12CommandContext *cmd, DWORD timeout_ms)
Wait on the CPU until the latest submission has completed.
static int d3d12_filter_known_sdr_trc(enum AVColorTransferCharacteristic trc)
int ff_d3d12_cmd_wait_context(AVFilterContext *ctx, D3D12CommandContext *cmd, const D3D12CommandContext *other)
Make the queue of cmd wait, on the GPU, until the latest submission of other has completed.
const D3D12FilterFormat * ff_d3d12_filter_format_from_dxgi(DXGI_FORMAT fmt)
static HRESULT d3d12_cmd_close_list(D3D12CommandContext *cmd)
static int d3d12_filter_reject_unrepresentable_siting_2020(AVFilterContext *ctx, int is_output, enum AVChromaLocation chroma_loc)
const D3D12FilterFormat * ff_d3d12_filter_format_from_pix_fmt(enum AVPixelFormat fmt)
static int d3d12_filter_reject_unrepresentable_nonleft(AVFilterContext *ctx, int is_output, enum AVChromaLocation chroma_loc)
int ff_d3d12_cmd_submit(AVFilterContext *ctx, D3D12CommandContext *cmd, AVFrame *const *inputs, int nb_inputs, AVFrame *output, int *frames_in_use)
Close and execute the command list.
int ff_d3d12_cmd_begin(AVFilterContext *ctx, D3D12CommandContext *cmd)
Get a command allocator the GPU is done with, and reset it together with the command list for recordi...
static void d3d12_cmd_free_input_refs(D3D12CommandAllocator *allocator)
int ff_d3d12_filter_wait_fence(ID3D12Fence *fence, UINT64 target, HANDLE fence_event, DWORD timeout_ms)
Wait until fence reaches target, or until timeout_ms expires.
int ff_d3d12_filter_init_output_frames(AVFilterContext *ctx, AVBufferRef *device_ref, enum AVPixelFormat sw_format, int width, int height, int initial_pool_size, AVBufferRef **frames_ref)
Allocate and initialize a pool of D3D12 frames that can be used as render targets.
static int d3d12_cmd_discard_command_allocator(D3D12CommandContext *cmd, AVFilterContext *ctx, D3D12CommandAllocator *allocator)
const D3D12FilterFormat * ff_d3d12_filter_format_iterate(void **opaque)
Iterate over all supported formats.
enum AVChromaLocation ff_d3d12_filter_chroma_location(DXGI_COLOR_SPACE_TYPE space)
static int d3d12_cmd_sync_after_failure(AVFilterContext *ctx, D3D12CommandContext *cmd)
static HRESULT d3d12_cmd_reset_list(D3D12CommandContext *cmd, ID3D12CommandAllocator *allocator)
static int d3d12_cmd_get_valid_command_allocator(D3D12CommandContext *cmd, AVFilterContext *ctx, ID3D12CommandAllocator **ppAllocator)
static int d3d12_filter_reject_unrepresentable_left(AVFilterContext *ctx, int is_output, enum AVChromaLocation chroma_loc)
static int d3d12_filter_reconcile_primaries(AVFilterContext *ctx, int is_output, enum AVColorPrimaries *primaries, enum AVColorPrimaries expected_primaries, const char *space_description)
void ff_d3d12_filter_add_frame_barriers(D3D12_RESOURCE_BARRIER *barriers, int *nb_barriers, const AVD3D12VAFrame *frame, int nb_planes, D3D12_RESOURCE_STATES state_before, D3D12_RESOURCE_STATES state_after)
Append one transition barrier per plane of a D3D12 frame.
static int d3d12_filter_known_matrix(enum AVColorSpace spc)
static int d3d12_cmd_wait_frame(AVFilterContext *ctx, D3D12CommandContext *cmd, const AVFrame *frame, const char *fence_name)
int ff_d3d12_cmd_init(AVFilterContext *ctx, D3D12CommandContext *cmd, ID3D12Device *device, D3D12_COMMAND_LIST_TYPE type)
Create the command queue, the fence and a closed command list of the given type, after releasing any ...
#define D3D12_FILTER_MAX_INPUTS
Maximum number of input frames (including reference frames) that one submission can read.
@ DXGI_FORMAT_B8G8R8A8_UNORM
Definition dds.c:92
@ DXGI_FORMAT_R16G16B16A16_FLOAT
Definition dds.c:63
@ DXGI_FORMAT_R8G8B8A8_UNORM
Definition dds.c:70
static enum AVPixelFormat pix_fmt
static AVFrame * frame
int ret
Definition ffplay.c:391
A generic FIFO API.
reference-counted frame API
#define fail
Definition test.h:479
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:140
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AVERROR(e)
Definition error.h:45
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition fifo.c:47
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition fifo.c:286
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
Definition fifo.h:63
int av_fifo_peek(const AVFifo *f, void *buf, size_t nb_elems, size_t offset)
Read data from a FIFO without modifying FIFO state.
Definition fifo.c:255
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition fifo.c:188
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition fifo.c:240
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:65
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition frame.c:486
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition rational.c:35
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition hwcontext.c:347
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition hwcontext.c:267
An API-specific header for AV_HWDEVICE_TYPE_D3D12VA.
const VDPAUPixFmtMap * map
#define b
Definition input.c:43
enum MPFType type
Definition jpegmpfenc.c:55
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
Definition h264dec.c:942
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
const char * desc
Definition libsvtav1.c:83
enum AVColorPrimaries primaries
enum AVColorSpace space
enum AVColorRange range
const char * av_color_space_name(enum AVColorSpace space)
Definition pixdesc.c:3884
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition pixdesc.c:3404
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition pixdesc.c:3851
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition pixdesc.c:3818
AVChromaLocation
Location of chroma samples.
Definition pixfmt.h:811
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition pixfmt.h:815
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition pixfmt.h:813
@ AVCHROMA_LOC_UNSPECIFIED
Definition pixfmt.h:812
#define AV_PIX_FMT_RGBAF16
Definition pixfmt.h:635
AVColorRange
Visual content value range.
Definition pixfmt.h:757
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:792
#define AV_PIX_FMT_P012
Definition pixfmt.h:614
#define AV_PIX_FMT_P010
Definition pixfmt.h:613
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:96
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
Definition pixfmt.h:440
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
#define AV_PIX_FMT_X2BGR10
Definition pixfmt.h:625
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition pixfmt.h:647
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition pixfmt.h:654
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition pixfmt.h:649
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:650
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition pixfmt.h:655
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition pixfmt.h:658
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition pixfmt.h:677
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition pixfmt.h:684
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition pixfmt.h:694
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition pixfmt.h:682
@ AVCOL_TRC_SMPTE240M
Definition pixfmt.h:685
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition pixfmt.h:686
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition pixfmt.h:683
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition pixfmt.h:698
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition pixfmt.h:693
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition pixfmt.h:691
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition pixfmt.h:692
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:680
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition pixfmt.h:679
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:711
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:713
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition pixfmt.h:717
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition pixfmt.h:723
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition pixfmt.h:722
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:714
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition pixfmt.h:718
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition buffer.h:82
D3D12VA frame descriptor for pool allocation.
AVD3D12VASyncContext sync_ctx
The sync context for the texture.
This struct is allocated as AVHWFramesContext.hwctx.
D3D12_RESOURCE_FLAGS resource_flags
Options for working with resources.
D3D12_HEAP_FLAGS heap_flags
Options for working with heaps allocation when creating resources.
DXGI_FORMAT format
DXGI_FORMAT format.
ID3D12Fence * fence
D3D12 fence object.
uint64_t fence_value
The fence value used for sync.
An instance of a filter.
Definition avfilter.h:279
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:500
int64_t duration
Duration of the frame, in the same units as pts.
Definition frame.h:830
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition hwcontext.h:200
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition hwcontext.h:153
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition hwcontext.h:213
int initial_pool_size
Initial size of the frame pool.
Definition hwcontext.h:190
int width
The allocated dimensions of the frames in this pool.
Definition hwcontext.h:220
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
ID3D12CommandAllocator * command_allocator
AVFrame * input_refs[D3D12_FILTER_MAX_INPUTS]
One command queue with its command list, a pool of command allocators and a private fence.
ID3D12Fence * fence
#define av_log(a,...)
float framerate
Definition av1_levels.c:29
static int ref[MAX_W *MAX_W]
#define height
Definition dsp.h:99
#define width
Definition dsp.h:99
static const Range full_range
#define WaitForSingleObject(a, b)
Definition w32pthreads.h:64