FFmpeg
Loading...
Searching...
No Matches
vf_scale_d3d12.c
Go to the documentation of this file.
1/**
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#define COBJMACROS
20
21#include "libavutil/fifo.h"
22#include "libavutil/frame.h"
23#include "libavutil/opt.h"
24#include "libavutil/pixdesc.h"
25#include "compat/w32dlfcn.h"
26
27#include "libavutil/hwcontext.h"
30
31#include "filters.h"
32#include "formats.h"
33#include "scale_eval.h"
34#include "video.h"
35
41
47
49 { AV_PIX_FMT_NV12, DXGI_FORMAT_NV12, 0 },
50 { AV_PIX_FMT_P010, DXGI_FORMAT_P010, 0 },
51 { AV_PIX_FMT_P012, DXGI_FORMAT_P016, 0 },
54 { AV_PIX_FMT_X2BGR10, DXGI_FORMAT_R10G10B10A2_UNORM, 1 },
56};
57
59{
60 for (int i = 0; i < FF_ARRAY_ELEMS(d3d12_scale_format_map); i++)
63
64 return NULL;
65}
66
67static const D3D12ScaleFormatMap *d3d12_scale_map_from_dxgi(DXGI_FORMAT fmt)
68{
69 for (int i = 0; i < FF_ARRAY_ELEMS(d3d12_scale_format_map); i++)
70 if (d3d12_scale_format_map[i].dxgi_format == fmt)
72
73 return NULL;
74}
75
76typedef struct ScaleD3D12Context {
78 char *w_expr;
79 char *h_expr;
81
89
90 /* D3D12 objects */
91 ID3D12Device *device;
92 ID3D12VideoDevice *video_device;
93 ID3D12VideoProcessor *video_processor;
94 ID3D12CommandQueue *command_queue;
95 ID3D12VideoProcessCommandList *command_list;
96
98
101
102 /* Synchronization */
103 ID3D12Fence *fence;
106
107 /* Buffer references */
110
111 /* Dimensions and formats */
114 DXGI_FORMAT input_format;
115 DXGI_FORMAT output_format;
121
122 /* Color space and frame rate */
123 DXGI_COLOR_SPACE_TYPE input_colorspace;
124 DXGI_COLOR_SPACE_TYPE output_colorspace;
126
127 /* AVFrame-facing output color properties, derived once from the first
128 * frame plus the out_* options and then reused for every frame. */
133
136
137 /* Video processor capabilities */
138 D3D12_FEATURE_DATA_VIDEO_PROCESS_SUPPORT process_support;
140
142 ScaleD3D12Context *s = ctx->priv;
143
144#define STRING_OPTION(var_name, func_name, opt_name, default_value) do { \
145 if (s->var_name ## _string) { \
146 int var = av_ ## func_name ## _from_name(s->var_name ## _string); \
147 if (var < 0) { \
148 av_log(ctx, AV_LOG_ERROR, "Invalid %s.\n", opt_name); \
149 return AVERROR(EINVAL); \
150 } \
151 s->var_name = var; \
152 } else { \
153 s->var_name = default_value; \
154 } \
155 } while (0)
156
157 STRING_OPTION(color_matrix, color_space, "out_color_matrix", AVCOL_SPC_UNSPECIFIED);
158 STRING_OPTION(color_transfer, color_transfer, "out_color_transfer", AVCOL_TRC_UNSPECIFIED);
160
161#undef STRING_OPTION
162
163 return 0;
164}
165
166static int scale_d3d12_wait_fence_exact(ID3D12Fence *fence, UINT64 target,
167 HANDLE fence_event, DWORD timeout_ms)
168{
169 int has_deadline = (timeout_ms != INFINITE);
170 ULONGLONG deadline = 0;
171
172 if (ID3D12Fence_GetCompletedValue(fence) >= target)
173 return 1;
174
175 if (FAILED(ID3D12Fence_SetEventOnCompletion(fence, target, fence_event)))
176 return 0;
177
178 if (has_deadline)
179 deadline = GetTickCount64() + timeout_ms;
180
181 for (;;) {
182 DWORD wait_result = WaitForSingleObject(fence_event, timeout_ms);
183
184 if (wait_result == WAIT_OBJECT_0) {
185 if (ID3D12Fence_GetCompletedValue(fence) >= target)
186 return 1;
187 if (has_deadline) {
188 ULONGLONG now = GetTickCount64();
189 if (now >= deadline)
190 return 0;
191 timeout_ms = (DWORD)(deadline - now);
192 }
193 continue;
194 }
195
196 return 0;
197 }
198}
199
201 ID3D12CommandAllocator **ppAllocator)
202{
203 HRESULT hr;
205
206 if (av_fifo_peek(s->allocator_queue, &allocator, 1, 0) >= 0) {
207 UINT64 completed = ID3D12Fence_GetCompletedValue(s->fence);
208 if (completed >= allocator.fence_value) {
209 *ppAllocator = allocator.command_allocator;
210 av_fifo_read(s->allocator_queue, &allocator, 1);
211 av_frame_free(&allocator.input_ref);
212 return 0;
213 }
214 }
215
216 hr = ID3D12Device_CreateCommandAllocator(s->device, D3D12_COMMAND_LIST_TYPE_VIDEO_PROCESS,
217 &IID_ID3D12CommandAllocator, (void **)ppAllocator);
218 if (FAILED(hr)) {
219 av_log(ctx, AV_LOG_ERROR, "Failed to create a new command allocator: HRESULT 0x%lX\n", hr);
220 return AVERROR_EXTERNAL;
221 }
222
223 return 0;
224}
225
227 ID3D12CommandAllocator *pAllocator,
228 UINT64 fence_value, AVFrame *input_ref)
229{
230 D3D12ScaleCommandAllocator allocator = {
231 .command_allocator = pAllocator,
232 .fence_value = fence_value,
233 .input_ref = input_ref,
234 };
235 int ret = av_fifo_write(s->allocator_queue, &allocator, 1);
236
237 if (ret < 0) {
238 int confirmed_done = s->fence && s->fence_event &&
239 scale_d3d12_wait_fence_exact(s->fence, fence_value, s->fence_event, INFINITE);
240
241 if (confirmed_done) {
242 ID3D12CommandAllocator_Release(pAllocator);
243 av_frame_free(&input_ref);
244 } else {
246 "Failed to queue a command allocator for later reuse\n");
247 }
248 }
249
250 return ret;
251}
252
254 int gpu_confirmed_done = 1;
255
256 s->configured = 0;
257
258 if (s->gpu_work_submitted && s->command_queue && s->fence && s->fence_event) {
259 UINT64 drain_value = s->fence_value + 1;
260
261 gpu_confirmed_done = 0;
262
263 if (SUCCEEDED(ID3D12CommandQueue_Signal(s->command_queue, s->fence, drain_value))) {
264 UINT64 completed;
265 /* this gives one more value as defense in depth, while cost is almost nothing */
266 s->fence_value = drain_value + 1;
267 completed = ID3D12Fence_GetCompletedValue(s->fence);
268 if (completed >= drain_value)
269 gpu_confirmed_done = 1;
270 else
271 gpu_confirmed_done = scale_d3d12_wait_fence_exact(s->fence, drain_value,
272 s->fence_event, INFINITE);
273 }
274
275 if (!gpu_confirmed_done) {
276 HRESULT removed_reason = ID3D12Device_GetDeviceRemovedReason(s->device);
277 gpu_confirmed_done = FAILED(removed_reason);
278 if (gpu_confirmed_done)
280 "D3D12 device removed (HRESULT 0x%lX) while tearing "
281 "down scale_d3d12\n", removed_reason);
282 }
283 }
284
285 if (!gpu_confirmed_done) {
287 "Could not confirm the GPU finished all scale_d3d12 work "
288 "during teardown\n");
289
290 return 0;
291 }
292
293 if (s->fence_event) {
294 CloseHandle(s->fence_event);
295 s->fence_event = NULL;
296 }
297
298 if (s->fence) {
299 ID3D12Fence_Release(s->fence);
300 s->fence = NULL;
301 }
302
303 if (s->command_list) {
304 ID3D12VideoProcessCommandList_Release(s->command_list);
305 s->command_list = NULL;
306 }
307
308 if (s->allocator_queue) {
310 while (av_fifo_read(s->allocator_queue, &allocator, 1) >= 0) {
311 ID3D12CommandAllocator_Release(allocator.command_allocator);
312 av_frame_free(&allocator.input_ref);
313 }
314 av_fifo_freep2(&s->allocator_queue);
315 }
316
317 if (s->video_processor) {
318 ID3D12VideoProcessor_Release(s->video_processor);
319 s->video_processor = NULL;
320 }
321
322 if (s->video_device) {
323 ID3D12VideoDevice_Release(s->video_device);
324 s->video_device = NULL;
325 }
326
327 if (s->command_queue) {
328 ID3D12CommandQueue_Release(s->command_queue);
329 s->command_queue = NULL;
330 }
331
332 s->gpu_work_submitted = 0;
333
334 return 1;
335}
336
338{
339 switch (spc) {
341 case AVCOL_SPC_BT709:
346 return 1;
347
348 default:
349 return 0;
350 }
351}
352
354{
355 switch (trc) {
357 case AVCOL_TRC_BT709:
365 return 1;
366
367 default:
368 return 0;
369 }
370}
371
373{
374 switch (trc) {
375 case AVCOL_TRC_BT709:
379 return 0; /* trc_bt709 */
380
382 return 1; /* trc_gamma22 */
383
385 return 2; /* trc_gamma28 */
386
388 return 3; /* trc_smpte240M */
389
391 return 4; /* trc_iec61966_2_1 (sRGB) */
392
393 default:
394 return -1;
395 }
396}
397
399 DXGI_COLOR_SPACE_TYPE input_space,
400 DXGI_COLOR_SPACE_TYPE output_space,
401 int explicit_request,
402 enum AVColorTransferCharacteristic input_trc,
404{
405 enum AVColorTransferCharacteristic canonical =
406 (output_space == DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709) ?
408 enum AVColorTransferCharacteristic canonical_input =
409 (input_trc == AVCOL_TRC_SMPTE2084 ||
410 input_trc == AVCOL_TRC_ARIB_STD_B67 ||
411 input_trc == AVCOL_TRC_LINEAR) ? input_trc :
412 (input_space == DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709) ?
414
415 if (canonical_input != canonical) {
416 if (*trc != canonical) {
417 const char *old_name = av_color_transfer_name(*trc);
418 const char *new_name = av_color_transfer_name(canonical);
420 "No exact DXGI color space; retagging transfer "
421 "characteristic from %s to %s\n",
422 old_name ? old_name : "unknown", new_name ? new_name : "unknown");
423 *trc = canonical;
424 }
425
426 return 0;
427 }
428
429 if (!explicit_request)
430 return 0;
431
432 if (d3d12_scale_trc_group(*trc) == d3d12_scale_trc_group(input_trc))
433 return 0;
434
435 const char *req_name = av_color_transfer_name(*trc);
436
437 if (input_trc == AVCOL_TRC_UNSPECIFIED) {
439 "Cannot verify requested transfer characteristic (%s); "
440 "input's curve is unspecified/unknown\n",
441 req_name ? req_name : "requested value");
442 } else {
443 const char *old_name = av_color_transfer_name(input_trc);
445 "Requested transfer characteristic (%s) differs from "
446 "input's (%s); same DXGI color space means no curve "
447 "change applies\n",
448 req_name ? req_name : "requested value",
449 old_name ? old_name : "transfer characteristic");
450 }
451
452 return AVERROR(EINVAL);
453}
454
457 enum AVColorPrimaries expected_primaries,
458 const char *space_description)
459{
460 if (*primaries != AVCOL_PRI_UNSPECIFIED && *primaries != expected_primaries) {
461 const char *old_name = av_color_primaries_name(*primaries);
462 const char *new_name = av_color_primaries_name(expected_primaries);
463 if (is_output) {
465 "%s forces fixed primaries; retagging output from "
466 "%s to %s\n",
467 space_description,
468 old_name ? old_name : "unknown", new_name ? new_name : "unknown");
469 } else {
471 "%s forces fixed primaries, which disagrees with "
472 "this input's %s primaries tag\n",
473 space_description, old_name ? old_name : "unknown");
474
475 return AVERROR(EINVAL);
476 }
477 }
478
479 *primaries = expected_primaries;
480 return 0;
481}
482
484 enum AVChromaLocation chroma_loc)
485{
486 if (chroma_loc == AVCHROMA_LOC_UNSPECIFIED || chroma_loc == AVCHROMA_LOC_LEFT)
487 return 0;
488
489 if (is_output) {
491 "This DXGI color space has no chroma entry other than "
492 "left-sited; the output will actually be left-sited\n");
493
494 return 0;
495 }
496
498 "This DXGI color space has no chroma entry other than "
499 "left-sited, but this input is tagged with a different siting\n");
500
501 return AVERROR(EINVAL);
502}
503
505 enum AVChromaLocation chroma_loc)
506{
507 if (chroma_loc == AVCHROMA_LOC_UNSPECIFIED || chroma_loc == AVCHROMA_LOC_TOPLEFT)
508 return 0;
509
510 if (is_output) {
512 "HLG has no DXGI entry with any chroma siting other than "
513 "top-left; the output will actually be top-left-sited\n");
514
515 return 0;
516 }
517
519 "HLG has no DXGI entry with any chroma siting other than "
520 "top-left, but this input is tagged with a different siting\n");
521
522 return AVERROR(EINVAL);
523}
524
526 enum AVChromaLocation chroma_loc)
527{
528 if (chroma_loc == AVCHROMA_LOC_UNSPECIFIED ||
529 chroma_loc == AVCHROMA_LOC_TOPLEFT ||
530 chroma_loc == AVCHROMA_LOC_LEFT)
531 return 0;
532
533 if (is_output) {
535 "DXGI BT.2020 only supports top-left/left chroma "
536 "siting; output will use one of those instead\n");
537
538 return 0;
539 }
540
542 "DXGI BT.2020 only supports top-left/left chroma siting, "
543 "but this input is tagged with a different siting\n");
544
545 return AVERROR(EINVAL);
546}
547
548static int d3d12_scale_get_colorspace(AVFilterContext *ctx, int is_rgb, int is_output,
549 enum AVColorSpace *spc,
550 enum AVColorRange *range,
553 enum AVChromaLocation chroma_loc,
554 enum AVColorPrimaries input_601_hint,
555 DXGI_COLOR_SPACE_TYPE *out_space)
556{
558 int ret;
559
560 if (!is_rgb && *spc == AVCOL_SPC_BT2020_CL) {
561 if (is_output) {
563 "BT.2020 constant-luminance has no DXGI color space; "
564 "retagging output as bt2020nc\n");
566 } else {
568 "BT.2020 constant-luminance matrix has no DXGI color "
569 "space; cannot process this input without misinterpreting\n");
570
571 return AVERROR(EINVAL);
572 }
573 }
574
575 if (!is_rgb && !d3d12_scale_known_matrix(*spc)) {
576 const char *name = av_color_space_name(*spc);
578 "%s matrix has no DXGI YCbCr color space; only BT.601, "
579 "BT.709 or BT.2020 are supported\n", name ? name : "this");
580
581 return AVERROR(EINVAL);
582 }
583
584 if (!is_rgb && *trc != AVCOL_TRC_SMPTE2084 && *trc != AVCOL_TRC_ARIB_STD_B67 &&
586 const char *name = av_color_transfer_name(*trc);
588 "%s transfer has no DXGI YCbCr color space; only SDR "
589 "gamma, smpte2084 or HLG (arib-std-b67) are "
590 "supported\n",
591 name ? name : "this");
592
593 return AVERROR(EINVAL);
594 }
595
596 int primaries_is_2020 = (*primaries == AVCOL_PRI_BT2020);
597 int is_2020 = (*spc == AVCOL_SPC_BT2020_NCL || *spc == AVCOL_SPC_BT2020_CL ||
598 (*spc == AVCOL_SPC_UNSPECIFIED && primaries_is_2020));
599 int is_601 = (*spc == AVCOL_SPC_BT470BG || *spc == AVCOL_SPC_SMPTE170M ||
600 (*spc == AVCOL_SPC_UNSPECIFIED &&
602
603 if (is_rgb) {
604 enum AVColorPrimaries expected_primaries;
605
606 switch (*trc) {
608 *out_space = full_range ? DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020
609 : DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020;
610 expected_primaries = AVCOL_PRI_BT2020;
611 break;
612
614 if (is_output)
616 "HLG has no RGB DXGI color space; use a YUV "
617 "output format or a supported out_color_transfer\n");
618 else
620 "HLG transfer characteristic has no RGB DXGI color "
621 "space; this RGB input cannot be processed\n");
622 return AVERROR(EINVAL);
623
624 case AVCOL_TRC_LINEAR:
625 if (!full_range) {
626 if (is_output)
628 "Studio range linear RGB has no DXGI color "
629 "space; use out_range=full, or a non-linear "
630 "out_color_transfer (e.g. bt709)\n");
631 else
633 "Studio range linear RGB has no DXGI color "
634 "space; this input cannot be processed\n");
635
636 return AVERROR(EINVAL);
637 }
638 *out_space = DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709;
639 expected_primaries = AVCOL_PRI_BT709;
640 break;
641
642 default:
643 if (!d3d12_scale_known_sdr_trc(*trc)) {
644 const char *name = av_color_transfer_name(*trc);
646 "%s transfer has no RGB DXGI color space; only "
647 "SDR gamma, linear or smpte2084 are "
648 "supported\n", name ? name : "this");
649
650 return AVERROR(EINVAL);
651 }
652 if (primaries_is_2020) {
653 *out_space = full_range ? DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020
654 : DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020;
655 expected_primaries = AVCOL_PRI_BT2020;
656 } else {
657 *out_space = full_range ? DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
658 : DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709;
659 expected_primaries = AVCOL_PRI_BT709;
660 }
661 break;
662 }
663
664 return d3d12_scale_reconcile_primaries(ctx, is_output, primaries, expected_primaries,
665 "this RGB transfer characteristic");
666 }
667
668 /* YCbCr family. */
669 if (is_2020) {
670 int want_topleft = (chroma_loc == AVCHROMA_LOC_TOPLEFT);
672 if (ret < 0)
673 return ret;
674
675 if (*trc == AVCOL_TRC_SMPTE2084) {
676 if (full_range) {
678 "No full-range smpte2084 YCbCr DXGI color space "
679 "exists; cannot process this %s\n",
680 is_output ? "output request" : "input");
681
682 return AVERROR(EINVAL);
683 }
684 *out_space = want_topleft ? DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020
685 : DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020;
686 } else if (*trc == AVCOL_TRC_ARIB_STD_B67) {
687 ret = d3d12_scale_reject_unrepresentable_left(ctx, is_output, chroma_loc);
688 if (ret < 0)
689 return ret;
690 *out_space = full_range ? DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020
691 : DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020;
692 } else {
693 if (want_topleft && full_range) {
694 if (!is_output) {
696 "Full-range BT.2020 SDR has no top-left-sited "
697 "DXGI YCbCr color space\n");
698
699 return AVERROR(EINVAL);
700 }
702 "Full-range BT.2020 SDR has no top-left-sited DXGI "
703 "YCbCr color space; falling back to left-sited\n");
704 want_topleft = 0;
705 }
706 if (want_topleft)
707 *out_space = DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020;
708 else
709 *out_space = full_range ? DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020
710 : DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020;
711 }
712
714 "a BT.2020 matrix");
715 if (ret < 0)
716 return ret;
717 } else if (is_601) {
718 if (*trc == AVCOL_TRC_SMPTE2084 || *trc == AVCOL_TRC_ARIB_STD_B67) {
719 if (is_output)
721 "%s transfer has no BT.601 DXGI color space; use "
722 "out_color_matrix=bt2020nc or an SDR transfer\n",
723 *trc == AVCOL_TRC_SMPTE2084 ? "smpte2084" : "HLG");
724 else
726 "%s transfer has no BT.601 DXGI color space; this "
727 "input cannot be processed.\n",
728 *trc == AVCOL_TRC_SMPTE2084 ? "smpte2084" : "HLG");
729
730 return AVERROR(EINVAL);
731 }
732 ret = d3d12_scale_reject_unrepresentable_nonleft(ctx, is_output, chroma_loc);
733 if (ret < 0)
734 return ret;
735 *out_space = full_range ? DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601
736 : DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601;
737
738 enum AVColorPrimaries this_601_primaries =
741 *primaries;
742
743 if (is_output && input_601_hint != AVCOL_PRI_UNSPECIFIED) {
744 if (*primaries != AVCOL_PRI_UNSPECIFIED && *primaries != input_601_hint) {
745 const char *in_name = av_color_primaries_name(input_601_hint);
746 const char *out_name = av_color_primaries_name(*primaries);
748 "DXGI's BT.601 color spaces cannot distinguish "
749 "PAL/NTSC primaries (%s input, %s output)\n",
750 in_name ? in_name : "unknown", out_name ? out_name : "unknown");
751
752 return AVERROR(EINVAL);
753 }
754 if (*primaries != input_601_hint) {
755 const char *new_name = av_color_primaries_name(input_601_hint);
757 "BT.601 cannot change primaries; tagging output "
758 "as %s\n",
759 new_name ? new_name : "unknown");
760 }
761 *primaries = input_601_hint;
762 } else if (!is_output) {
765 const char *old_name = av_color_primaries_name(*primaries);
767 "BT.601 only represents PAL/NTSC primaries, "
768 "which disagrees with this input's %s tag\n",
769 old_name ? old_name : "unknown");
770
771 return AVERROR(EINVAL);
772 }
774 *primaries = this_601_primaries;
775 } else {
776 ret = d3d12_scale_reconcile_primaries(ctx, is_output, primaries, this_601_primaries,
777 "this BT.601 matrix");
778 if (ret < 0)
779 return ret;
780 }
781 } else {
782 /* Same gap as the BT.601 case above: no smpte2084/HLG DXGI color
783 * space exists paired with a BT.709 matrix either. */
784 if (*trc == AVCOL_TRC_SMPTE2084 || *trc == AVCOL_TRC_ARIB_STD_B67) {
785 if (is_output)
787 "%s has no BT.709 DXGI space; use "
788 "out_color_matrix=bt2020nc or SDR\n",
789 *trc == AVCOL_TRC_SMPTE2084 ? "smpte2084" : "HLG");
790 else
792 "%s has no BT.709 DXGI space; retag/convert to "
793 "BT.2020 or SDR before scale_d3d12\n",
794 *trc == AVCOL_TRC_SMPTE2084 ? "smpte2084" : "HLG");
795
796 return AVERROR(EINVAL);
797 }
798 ret = d3d12_scale_reject_unrepresentable_nonleft(ctx, is_output, chroma_loc);
799 if (ret < 0)
800 return ret;
801 *out_space = full_range ? DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709
802 : DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709; ///< Default to Rec.709
803
805 "the default BT.709 matrix");
806 if (ret < 0)
807 return ret;
808 }
809
810 return 0;
811}
812
814{
815 switch (space) {
816 case DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020:
817 case DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020:
818 case DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020:
819 case DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020:
820 case DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020:
822
823 default:
824 return AVCHROMA_LOC_LEFT;
825 }
826}
827
829{
830 D3D12_FEATURE_DATA_VIDEO_PROCESS_SUPPORT probe;
831
833 return;
834
835 for (int i = 0; i < FF_ARRAY_ELEMS(d3d12_scale_format_map); i++) {
837 DXGI_COLOR_SPACE_TYPE candidate_space;
838 enum AVColorRange candidate_range = map->is_rgb ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
839 enum AVColorSpace candidate_spc = AVCOL_SPC_UNSPECIFIED;
840 enum AVColorPrimaries candidate_primaries = AVCOL_PRI_UNSPECIFIED;
842 HRESULT hr;
843
844 if (d3d12_scale_get_colorspace(ctx, map->is_rgb, 1, &candidate_spc,
845 &candidate_range, &candidate_primaries,
846 &candidate_trc, AVCHROMA_LOC_UNSPECIFIED,
848 &candidate_space) < 0)
849 continue;
850
851 probe = s->process_support;
852 probe.OutputFormat.Format = map->dxgi_format;
853 probe.OutputFormat.ColorSpace = candidate_space;
854
855 hr = ID3D12VideoDevice_CheckFeatureSupport(s->video_device, D3D12_FEATURE_VIDEO_PROCESS_SUPPORT,
856 &probe, sizeof(probe));
857
858 av_log(ctx, AV_LOG_DEBUG, "Probe output %s (DXGI %d, colorspace %d): %s\n",
859 av_get_pix_fmt_name(map->pix_fmt), map->dxgi_format, candidate_space,
860 (SUCCEEDED(hr) && (probe.SupportFlags & D3D12_VIDEO_PROCESS_SUPPORT_FLAG_SUPPORTED)) ?
861 "supported" : "unsupported");
862 }
863}
864
866{
867 AVRational framerate = {0, 0};
868 FilterLink *inl = ff_filter_link(inlink);
869
870 if (inl->frame_rate.num > 0 && inl->frame_rate.den > 0) {
871 framerate = inl->frame_rate;
872 } else if (in->duration > 0 && inlink->time_base.num > 0 && inlink->time_base.den > 0) {
873 av_reduce(&framerate.num, &framerate.den,
874 inlink->time_base.den, in->duration * inlink->time_base.num,
875 INT_MAX);
876 } else {
877 framerate.num = 30;
878 framerate.den = 1;
879 av_log(ctx, AV_LOG_WARNING, "Input framerate not determinable, defaulting to 30fps\n");
880 }
881
882 return framerate;
883}
884
886 HRESULT hr;
887 int ret;
888 ID3D12CommandAllocator *command_allocator = NULL;
889
890 if (s->video_device || s->command_queue || s->fence || s->fence_event ||
891 s->command_list || s->video_processor || s->allocator_queue) {
894 "Cannot configure a new D3D12 video processor\n");
895 return AVERROR_EXTERNAL;
896 }
897 }
898
899 if (s->output_format == DXGI_FORMAT_UNKNOWN) {
900 av_log(ctx, AV_LOG_ERROR, "Output format not initialized\n");
901 return AVERROR(EINVAL);
902 }
903
904 AVHWDeviceContext *hwctx = (AVHWDeviceContext *)s->hw_device_ctx->data;
905 AVD3D12VADeviceContext *d3d12_hwctx = (AVD3D12VADeviceContext *)hwctx->hwctx;
906 s->device = d3d12_hwctx->device;
907
908 av_log(ctx, AV_LOG_VERBOSE, "Configuring D3D12 video processor: %dx%d -> %dx%d\n",
909 s->input_width, s->input_height, s->width, s->height);
910
911 hr = ID3D12Device_QueryInterface(s->device, &IID_ID3D12VideoDevice, (void **)&s->video_device);
912 if (FAILED(hr)) {
913 av_log(ctx, AV_LOG_ERROR, "Failed to get D3D12 video device interface: HRESULT 0x%lX\n", hr);
914
915 return AVERROR_EXTERNAL;
916 }
917
918 D3D12_COMMAND_QUEUE_DESC queue_desc = {
919 .Type = D3D12_COMMAND_LIST_TYPE_VIDEO_PROCESS,
920 .Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL,
921 .Flags = D3D12_COMMAND_QUEUE_FLAG_NONE,
922 .NodeMask = 0
923 };
924
925 hr = ID3D12Device_CreateCommandQueue(s->device, &queue_desc, &IID_ID3D12CommandQueue, (void **)&s->command_queue);
926 if (FAILED(hr)) {
927 av_log(ctx, AV_LOG_ERROR, "Failed to create command queue: HRESULT 0x%lX\n", hr);
929
930 return AVERROR_EXTERNAL;
931 }
932
933 s->process_support.NodeIndex = 0;
934
935 s->process_support.InputSample.Format.Format = s->input_format;
936 s->process_support.InputSample.Format.ColorSpace = s->input_colorspace;
937 s->process_support.InputSample.Width = s->input_width;
938 s->process_support.InputSample.Height = s->input_height;
939 s->process_support.InputFrameRate.Numerator = s->input_framerate.num;
940 s->process_support.InputFrameRate.Denominator = s->input_framerate.den;
941 s->process_support.InputFieldType = D3D12_VIDEO_FIELD_TYPE_NONE;
942 s->process_support.InputStereoFormat = D3D12_VIDEO_FRAME_STEREO_FORMAT_NONE;
943
944 s->process_support.OutputFormat.Format = s->output_format;
945 s->process_support.OutputFormat.ColorSpace = s->output_colorspace;
946 s->process_support.OutputFrameRate.Numerator = s->input_framerate.num;
947 s->process_support.OutputFrameRate.Denominator = s->input_framerate.den;
948 s->process_support.OutputStereoFormat = D3D12_VIDEO_FRAME_STEREO_FORMAT_NONE;
949
950 hr = ID3D12VideoDevice_CheckFeatureSupport(
951 s->video_device,
952 D3D12_FEATURE_VIDEO_PROCESS_SUPPORT,
953 &s->process_support,
954 sizeof(s->process_support)
955 );
956
957 if (FAILED(hr)) {
958 av_log(ctx, AV_LOG_ERROR, "Video process feature not supported: HRESULT 0x%lX\n", hr);
960
961 return AVERROR_EXTERNAL;
962 }
963
964 if (!(s->process_support.SupportFlags & D3D12_VIDEO_PROCESS_SUPPORT_FLAG_SUPPORTED)) {
966 "D3D12 video processor does not support converting %s (colorspace %d) to %s "
967 "(colorspace %d) on this device\n",
969 d3d12_scale_map_from_dxgi(s->input_format)->pix_fmt : AV_PIX_FMT_NONE),
970 s->input_colorspace,
972 d3d12_scale_map_from_dxgi(s->output_format)->pix_fmt : AV_PIX_FMT_NONE),
973 s->output_colorspace);
976
977 return AVERROR(ENOSYS);
978 }
979
980 int want_alpha_passthrough = s->input_has_alpha && s->output_has_alpha;
981 if (want_alpha_passthrough &&
982 !(s->process_support.FeatureSupport & D3D12_VIDEO_PROCESS_FEATURE_FLAG_ALPHA_FILL)) {
984 "Device lacks ALPHA_FILL support; output alpha will be "
985 "forced opaque instead of preserved\n");
986 want_alpha_passthrough = 0;
987 }
988 s->alpha_passthrough = want_alpha_passthrough;
989
990 D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC processor_output_desc = {
991 .Format = s->output_format,
992 .ColorSpace = s->output_colorspace,
993 .AlphaFillMode = want_alpha_passthrough ? D3D12_VIDEO_PROCESS_ALPHA_FILL_MODE_SOURCE_STREAM
994 : D3D12_VIDEO_PROCESS_ALPHA_FILL_MODE_OPAQUE,
995 .AlphaFillModeSourceStreamIndex = 0,
996 .BackgroundColor = { 0.0f, 0.0f, 0.0f, 1.0f },
997 .FrameRate = { s->input_framerate.num, s->input_framerate.den },
998 .EnableStereo = FALSE,
999 };
1000
1001 D3D12_VIDEO_PROCESS_INPUT_STREAM_DESC processor_input_desc = {
1002 .Format = s->input_format,
1003 .ColorSpace = s->input_colorspace,
1004 .SourceAspectRatio = { 1, 1 },
1005 .DestinationAspectRatio = { 1, 1 },
1006 .FrameRate = { s->input_framerate.num, s->input_framerate.den },
1007 .StereoFormat = D3D12_VIDEO_FRAME_STEREO_FORMAT_NONE,
1008 .FieldType = D3D12_VIDEO_FIELD_TYPE_NONE,
1009 .DeinterlaceMode = D3D12_VIDEO_PROCESS_DEINTERLACE_FLAG_NONE,
1010 .EnableOrientation = FALSE,
1011 .FilterFlags = D3D12_VIDEO_PROCESS_FILTER_FLAG_NONE,
1012 .SourceSizeRange = {
1013 .MaxWidth = s->input_width,
1014 .MaxHeight = s->input_height,
1015 .MinWidth = s->input_width,
1016 .MinHeight = s->input_height
1017 },
1018 .DestinationSizeRange = {
1019 .MaxWidth = s->width,
1020 .MaxHeight = s->height,
1021 .MinWidth = s->width,
1022 .MinHeight = s->height
1023 },
1024 .EnableAlphaBlending = FALSE,
1025 .LumaKey = { .Enable = FALSE, .Lower = 0.0f, .Upper = 1.0f },
1026 .NumPastFrames = 0,
1027 .NumFutureFrames = 0,
1028 .EnableAutoProcessing = FALSE,
1029 };
1030
1031 hr = ID3D12VideoDevice_CreateVideoProcessor(
1032 s->video_device,
1033 0,
1034 &processor_output_desc,
1035 1,
1036 &processor_input_desc,
1037 &IID_ID3D12VideoProcessor,
1038 (void **)&s->video_processor
1039 );
1040
1041 if (FAILED(hr)) {
1042 av_log(ctx, AV_LOG_ERROR, "Failed to create video processor: HRESULT 0x%lX\n", hr);
1044 return AVERROR_EXTERNAL;
1045 }
1046
1047 hr = ID3D12Device_CreateFence(s->device, 0, D3D12_FENCE_FLAG_NONE, &IID_ID3D12Fence, (void **)&s->fence);
1048 if (FAILED(hr)) {
1049 av_log(ctx, AV_LOG_ERROR, "Failed to create fence: HRESULT 0x%lX\n", hr);
1051 return AVERROR_EXTERNAL;
1052 }
1053
1054 s->fence_value = 1;
1055 s->fence_event = CreateEvent(NULL, FALSE, FALSE, NULL);
1056 if (!s->fence_event) {
1057 av_log(ctx, AV_LOG_ERROR, "Failed to create fence event\n");
1059
1060 return AVERROR_EXTERNAL;
1061 }
1062
1063 s->allocator_queue = av_fifo_alloc2(2, sizeof(D3D12ScaleCommandAllocator), AV_FIFO_FLAG_AUTO_GROW);
1064 if (!s->allocator_queue) {
1066 return AVERROR(ENOMEM);
1067 }
1068
1069 ret = scale_d3d12_get_valid_command_allocator(s, ctx, &command_allocator);
1070 if (ret < 0) {
1072 return ret;
1073 }
1074
1075 hr = ID3D12Device_CreateCommandList(
1076 s->device,
1077 0,
1078 D3D12_COMMAND_LIST_TYPE_VIDEO_PROCESS,
1079 command_allocator,
1080 NULL,
1081 &IID_ID3D12VideoProcessCommandList,
1082 (void **)&s->command_list
1083 );
1084
1085 if (FAILED(hr)) {
1086 av_log(ctx, AV_LOG_ERROR, "Failed to create command list: HRESULT 0x%lX\n", hr);
1087 ID3D12CommandAllocator_Release(command_allocator);
1089
1090 return AVERROR_EXTERNAL;
1091 }
1092
1093 hr = ID3D12VideoProcessCommandList_Close(s->command_list);
1094 if (FAILED(hr)) {
1095 av_log(ctx, AV_LOG_ERROR, "Failed to close command list: HRESULT 0x%lX\n", hr);
1097 ID3D12CommandAllocator_Release(command_allocator);
1098
1099 return AVERROR_EXTERNAL;
1100 }
1101
1102 ret = scale_d3d12_discard_command_allocator(s, ctx, command_allocator, 0, NULL);
1103 if (ret < 0) {
1105 return ret;
1106 }
1107
1108 s->configured = 1;
1109
1110 av_log(ctx, AV_LOG_VERBOSE, "D3D12 video processor successfully configured\n");
1111 return 0;
1112}
1113
1115{
1116 AVFilterContext *ctx = inlink->dst;
1117 ScaleD3D12Context *s = ctx->priv;
1118 AVFilterLink *outlink = ctx->outputs[0];
1119 AVFrame *out = NULL;
1120 int ret = 0;
1121 HRESULT hr;
1122 ID3D12CommandAllocator *command_allocator = NULL;
1123 HRESULT removed_reason;
1124 int gpu_confirmed_done;
1125
1126 if (!in) {
1127 av_log(ctx, AV_LOG_ERROR, "Null input frame\n");
1128 return AVERROR(EINVAL);
1129 }
1130
1131 if (!in->hw_frames_ctx) {
1132 av_log(ctx, AV_LOG_ERROR, "No hardware frames context in input frame\n");
1133 av_frame_free(&in);
1134
1135 return AVERROR(EINVAL);
1136 }
1137
1139
1140 if (!s->hw_device_ctx) {
1141 av_log(ctx, AV_LOG_ERROR, "Filter hardware device context is uninitialized\n");
1142 av_frame_free(&in);
1143
1144 return AVERROR(EINVAL);
1145 }
1146
1147 AVHWDeviceContext *input_device_ctx = (AVHWDeviceContext *)frames_ctx->device_ref->data;
1148 AVHWDeviceContext *filter_device_ctx = (AVHWDeviceContext *)s->hw_device_ctx->data;
1149
1150 if (input_device_ctx->type != filter_device_ctx->type) {
1151 av_log(ctx, AV_LOG_ERROR, "Mismatch between input and filter hardware device types\n");
1152 av_frame_free(&in);
1153
1154 return AVERROR(EINVAL);
1155 }
1156
1157 AVD3D12VADeviceContext *input_d3d12_hwctx = (AVD3D12VADeviceContext *)input_device_ctx->hwctx;
1158 AVD3D12VADeviceContext *filter_d3d12_hwctx = (AVD3D12VADeviceContext *)filter_device_ctx->hwctx;
1159 if (input_d3d12_hwctx->device != filter_d3d12_hwctx->device) {
1161 "Input frame's hw_frames_ctx belongs to a different "
1162 "ID3D12Device than this filter's own device\n");
1163 av_frame_free(&in);
1164
1165 return AVERROR(EINVAL);
1166 }
1167
1168 out = av_frame_alloc();
1169 if (!out) {
1170 av_log(ctx, AV_LOG_ERROR, "Failed to allocate output frame\n");
1171 av_frame_free(&in);
1172
1173 return AVERROR(ENOMEM);
1174 }
1175
1176 ret = av_hwframe_get_buffer(s->hw_frames_ctx_out, out, 0);
1177 if (ret < 0) {
1178 av_log(ctx, AV_LOG_ERROR, "Failed to get output frame from pool\n");
1179 goto fail;
1180 }
1181
1182 if (!s->configured) {
1183 AVHWFramesContext *input_frames_ctx = (AVHWFramesContext *)in->hw_frames_ctx->data;
1184 const D3D12ScaleFormatMap *in_map, *out_map;
1185 enum AVColorSpace out_spc;
1186 enum AVColorRange out_range;
1187 enum AVColorPrimaries out_primaries;
1188 enum AVColorTransferCharacteristic out_trc;
1189
1190 s->input_width = in->width;
1191 s->input_height = in->height;
1192
1193 AVD3D12VAFramesContext *input_hwctx = (AVD3D12VAFramesContext *)input_frames_ctx->hwctx;
1194 s->input_format = input_hwctx->format;
1195
1196 if (s->input_format == DXGI_FORMAT_UNKNOWN) {
1197 in_map = d3d12_scale_map_from_pixfmt(input_frames_ctx->sw_format);
1198 if (!in_map) {
1199 av_log(ctx, AV_LOG_ERROR, "Unsupported input format: %s\n",
1200 av_get_pix_fmt_name(input_frames_ctx->sw_format));
1201 ret = AVERROR(EINVAL);
1202 goto fail;
1203 }
1204 s->input_format = in_map->dxgi_format;
1205 }
1206
1207 in_map = d3d12_scale_map_from_dxgi(s->input_format);
1208 s->input_is_rgb = in_map ? in_map->is_rgb : 0;
1209 const AVPixFmtDescriptor *in_desc = in_map ? av_pix_fmt_desc_get(in_map->pix_fmt) : NULL;
1210 s->input_has_alpha = in_desc && (in_desc->flags & AV_PIX_FMT_FLAG_ALPHA);
1211
1212 enum AVColorRange in_range = in->color_range != AVCOL_RANGE_UNSPECIFIED ? in->color_range
1213 : (s->input_is_rgb ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG);
1214 enum AVColorSpace in_spc = in->colorspace;
1215 enum AVColorPrimaries in_primaries = in->color_primaries;
1216 enum AVColorTransferCharacteristic in_trc = in->color_trc;
1217
1218 ret = d3d12_scale_get_colorspace(ctx, s->input_is_rgb, 0, &in_spc, &in_range,
1219 &in_primaries, &in_trc, in->chroma_location,
1220 AVCOL_PRI_UNSPECIFIED, &s->input_colorspace);
1221 if (ret < 0)
1222 goto fail;
1223
1224 s->input_av_color_primaries = in_primaries;
1225 s->input_av_color_trc = in_trc;
1226
1227 enum AVColorPrimaries input_601_hint = AVCOL_PRI_UNSPECIFIED;
1228 if (s->input_colorspace == DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 ||
1229 s->input_colorspace == DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601)
1230 input_601_hint = in_primaries;
1231
1232 /* Output color properties: options override, otherwise inherit
1233 * from the input. RGB output defaults to full range. */
1234 out_map = d3d12_scale_map_from_dxgi(s->output_format);
1235 s->output_is_rgb = out_map ? out_map->is_rgb : 0;
1236 const AVPixFmtDescriptor *out_desc = out_map ? av_pix_fmt_desc_get(out_map->pix_fmt) : NULL;
1237 s->output_has_alpha = out_desc && (out_desc->flags & AV_PIX_FMT_FLAG_ALPHA);
1238
1239 out_spc = s->color_matrix != AVCOL_SPC_UNSPECIFIED ? s->color_matrix :
1240 s->color_primaries != AVCOL_PRI_UNSPECIFIED ? AVCOL_SPC_UNSPECIFIED :
1241 in->colorspace;
1242 out_primaries = s->color_primaries != AVCOL_PRI_UNSPECIFIED ? s->color_primaries : in_primaries;
1243 out_trc = s->color_transfer != AVCOL_TRC_UNSPECIFIED ? s->color_transfer : in->color_trc;
1244 if (s->color_transfer == AVCOL_TRC_UNSPECIFIED && in->color_trc == AVCOL_TRC_UNSPECIFIED &&
1245 out_map && out_map->pix_fmt == AV_PIX_FMT_RGBAF16)
1246 out_trc = AVCOL_TRC_LINEAR;
1247 /* AVCOL_SPC_RGB has no YCbCr matrix of its own, so when converting
1248 * an RGB input frame back to a YUV output format Treat it as unspecified
1249 * instead */
1250 if (!s->output_is_rgb && out_spc == AVCOL_SPC_RGB)
1251 out_spc = AVCOL_SPC_UNSPECIFIED;
1252
1253 if (s->color_range != AVCOL_RANGE_UNSPECIFIED)
1254 out_range = s->color_range;
1255 else if (out_trc == AVCOL_TRC_LINEAR)
1256 /* Linear RGB has no studio-range DXGI color space either default
1257 * to full range and let the processor do the limited->full expansion
1258 * instead. */
1259 out_range = AVCOL_RANGE_JPEG;
1260 else if (in->color_range != AVCOL_RANGE_UNSPECIFIED)
1261 out_range = in->color_range;
1262 else
1263 out_range = s->output_is_rgb ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
1264
1265 ret = d3d12_scale_get_colorspace(ctx, s->output_is_rgb, 1, &out_spc, &out_range,
1266 &out_primaries, &out_trc, in->chroma_location,
1267 input_601_hint, &s->output_colorspace);
1268 if (ret < 0)
1269 goto fail;
1270
1271 if (out_trc != AVCOL_TRC_SMPTE2084 && out_trc != AVCOL_TRC_ARIB_STD_B67 &&
1272 out_trc != AVCOL_TRC_LINEAR) {
1273 ret = d3d12_scale_finalize_output_trc(ctx, s->input_colorspace, s->output_colorspace,
1274 s->color_transfer != AVCOL_TRC_UNSPECIFIED,
1275 in->color_trc, &out_trc);
1276 if (ret < 0)
1277 goto fail;
1278 }
1279
1280 if (s->output_is_rgb)
1281 s->output_av_colorspace = AVCOL_SPC_RGB;
1282 else if (out_spc != AVCOL_SPC_UNSPECIFIED)
1283 s->output_av_colorspace = out_spc;
1284 else if (out_primaries == AVCOL_PRI_BT2020)
1285 s->output_av_colorspace = AVCOL_SPC_BT2020_NCL;
1286 else if (out_primaries == AVCOL_PRI_BT470BG || out_primaries == AVCOL_PRI_SMPTE170M)
1287 s->output_av_colorspace = AVCOL_SPC_SMPTE170M;
1288 else
1289 s->output_av_colorspace = AVCOL_SPC_BT709;
1290 s->output_av_color_range = out_range;
1291 s->output_av_color_primaries = out_primaries;
1292 s->output_av_color_trc = out_trc;
1293
1294 /* outlink's colorspace/color_range/chroma_location describe a YUV,
1295 * subsampled surface; they do not constrain an RGB output, so these
1296 * checks only apply when the output is YUV. */
1297 if (!s->output_is_rgb && outlink->colorspace != AVCOL_SPC_UNSPECIFIED &&
1298 outlink->colorspace != s->output_av_colorspace) {
1300 "Negotiated output color space (%s) does not match the "
1301 "%s produced from this input; set an explicit "
1302 "out_color_matrix\n",
1304 av_color_space_name(s->output_av_colorspace));
1305 ret = AVERROR(EINVAL);
1306 goto fail;
1307 }
1308 if (!s->output_is_rgb && outlink->color_range != AVCOL_RANGE_UNSPECIFIED &&
1309 outlink->color_range != s->output_av_color_range) {
1311 "Negotiated output color range (%s) does not match the "
1312 "%s produced from this input; set an explicit out_range\n",
1314 av_color_range_name(s->output_av_color_range));
1315 ret = AVERROR(EINVAL);
1316 goto fail;
1317 }
1318 if (!s->output_is_rgb) {
1319 enum AVChromaLocation out_chroma_loc = d3d12_scale_dxgi_chroma_location(s->output_colorspace);
1320 if (outlink->chroma_location != AVCHROMA_LOC_UNSPECIFIED &&
1321 outlink->chroma_location != out_chroma_loc) {
1323 "Negotiated output chroma siting does not match the "
1324 "siting produced from this input\n");
1325 ret = AVERROR(EINVAL);
1326 goto fail;
1327 }
1328 }
1329
1330 s->input_framerate = get_input_framerate(ctx, inlink, in);
1331
1333 "Input format: %dx%d, DXGI format: %d, colorspace: %d -> "
1334 "Output DXGI format: %d, colorspace: %d, framerate: %d/%d\n",
1335 s->input_width, s->input_height, s->input_format, s->input_colorspace,
1336 s->output_format, s->output_colorspace,
1337 s->input_framerate.num, s->input_framerate.den);
1338
1340 if (ret < 0) {
1341 av_log(ctx, AV_LOG_ERROR, "Failed to configure processor\n");
1342 goto fail;
1343 }
1344 }
1345
1346 /* alpha_mode is a per-frame AVFrame property, not a fixed property of
1347 * the negotiated pixel formats, so this must be checked for every
1348 * frame, not just the first one. */
1349 if (s->input_has_alpha && in->alpha_mode == AVALPHA_MODE_PREMULTIPLIED &&
1350 (!s->output_has_alpha || !s->alpha_passthrough ||
1351 s->input_colorspace != s->output_colorspace)) {
1353 "Input has premultiplied alpha, which this conversion "
1354 "cannot preserve; unpremultiply before scale_d3d12\n");
1355 ret = AVERROR(EINVAL);
1356 goto fail;
1357 }
1358
1359 AVD3D12VAFrame *input_frame = (AVD3D12VAFrame *)in->data[0];
1361
1362 if (!input_frame || !output_frame) {
1363 av_log(ctx, AV_LOG_ERROR, "Invalid frame pointers\n");
1364 ret = AVERROR(EINVAL);
1365 goto fail;
1366 }
1367
1368 ID3D12Resource *input_resource = input_frame->texture;
1369 ID3D12Resource *output_resource = output_frame->texture;
1370
1371 if (!input_resource || !output_resource) {
1372 av_log(ctx, AV_LOG_ERROR, "Invalid D3D12 resources in frames\n");
1373 ret = AVERROR(EINVAL);
1374 goto fail;
1375 }
1376
1377 ret = scale_d3d12_get_valid_command_allocator(s, ctx, &command_allocator);
1378 if (ret < 0)
1379 goto fail;
1380
1381 hr = ID3D12CommandAllocator_Reset(command_allocator);
1382 if (FAILED(hr)) {
1383 av_log(ctx, AV_LOG_ERROR, "Failed to reset command allocator: HRESULT 0x%lX\n", hr);
1385 goto fail;
1386 }
1387
1388 hr = ID3D12VideoProcessCommandList_Reset(s->command_list, command_allocator);
1389 if (FAILED(hr)) {
1390 av_log(ctx, AV_LOG_ERROR, "Failed to reset command list: HRESULT 0x%lX\n", hr);
1392 goto force_reconfigure;
1393 }
1394
1395 D3D12_RESOURCE_DESC input_res_desc, output_res_desc;
1396 input_resource->lpVtbl->GetDesc(input_resource, &input_res_desc);
1397 output_resource->lpVtbl->GetDesc(output_resource, &output_res_desc);
1398
1399 int input_nb_planes = s->input_is_rgb ? 1 : 2;
1400 int output_nb_planes = s->output_is_rgb ? 1 : 2;
1401
1402 D3D12_RESOURCE_BARRIER barriers[4];
1403 int nb_barriers = 0;
1404
1405 for (int p = 0; p < input_nb_planes; p++) {
1406 D3D12_RESOURCE_BARRIER b = {
1407 .Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
1408 .Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE,
1409 .Transition = {
1410 .pResource = input_resource,
1411 .Subresource = input_frame->subresource_index + p * input_res_desc.DepthOrArraySize,
1412 .StateBefore = D3D12_RESOURCE_STATE_COMMON,
1413 .StateAfter = D3D12_RESOURCE_STATE_VIDEO_PROCESS_READ
1414 }
1415 };
1416 barriers[nb_barriers++] = b;
1417 }
1418 for (int p = 0; p < output_nb_planes; p++) {
1419 D3D12_RESOURCE_BARRIER b = {
1420 .Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
1421 .Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE,
1422 .Transition = {
1423 .pResource = output_resource,
1424 .Subresource = output_frame->subresource_index + p * output_res_desc.DepthOrArraySize,
1425 .StateBefore = D3D12_RESOURCE_STATE_COMMON,
1426 .StateAfter = D3D12_RESOURCE_STATE_VIDEO_PROCESS_WRITE
1427 }
1428 };
1429 barriers[nb_barriers++] = b;
1430 }
1431
1432 ID3D12VideoProcessCommandList_ResourceBarrier(s->command_list, nb_barriers, barriers);
1433
1434 D3D12_VIDEO_PROCESS_INPUT_STREAM_ARGUMENTS input_args = {0};
1435
1436 /* subresource_index is 0 for a plain texture, but for a texture-array
1437 * input (AV_D3D12VA_FRAME_FLAG_TEXTURE_ARRAY) it is the real array
1438 * slice and must be passed through as-is. */
1439 input_args.InputStream[0].pTexture2D = input_resource;
1440 input_args.InputStream[0].Subresource = input_frame->subresource_index;
1441 input_args.Transform.SourceRectangle.right = s->input_width;
1442 input_args.Transform.SourceRectangle.bottom = s->input_height;
1443 input_args.Transform.DestinationRectangle.right = s->width;
1444 input_args.Transform.DestinationRectangle.bottom = s->height;
1445 input_args.Transform.Orientation = D3D12_VIDEO_PROCESS_ORIENTATION_DEFAULT;
1446
1447 input_args.Flags = D3D12_VIDEO_PROCESS_INPUT_STREAM_FLAG_NONE;
1448
1449 input_args.RateInfo.OutputIndex = 0;
1450 input_args.RateInfo.InputFrameOrField = 0;
1451
1452 memset(input_args.FilterLevels, 0, sizeof(input_args.FilterLevels));
1453
1454 input_args.AlphaBlending.Enable = FALSE;
1455 input_args.AlphaBlending.Alpha = 1.0f;
1456
1457 D3D12_VIDEO_PROCESS_OUTPUT_STREAM_ARGUMENTS output_args = {0};
1458
1459 /* Same reasoning as input_args.InputStream[0].Subresource above. */
1460 output_args.OutputStream[0].pTexture2D = output_resource;
1461 output_args.OutputStream[0].Subresource = output_frame->subresource_index;
1462 output_args.TargetRectangle.right = s->width;
1463 output_args.TargetRectangle.bottom = s->height;
1464
1465 ID3D12VideoProcessCommandList_ProcessFrames(
1466 s->command_list,
1467 s->video_processor,
1468 &output_args,
1469 1,
1470 &input_args
1471 );
1472
1473 for (int i = 0; i < nb_barriers; i++) {
1474 FFSWAP(D3D12_RESOURCE_STATES, barriers[i].Transition.StateBefore, barriers[i].Transition.StateAfter);
1475 }
1476 ID3D12VideoProcessCommandList_ResourceBarrier(s->command_list, nb_barriers, barriers);
1477
1478 hr = ID3D12VideoProcessCommandList_Close(s->command_list);
1479 if (FAILED(hr)) {
1480 av_log(ctx, AV_LOG_ERROR, "Failed to close command list: HRESULT 0x%lX\n", hr);
1482 goto force_reconfigure;
1483 }
1484
1485 int wait_enqueued = 0;
1486
1487 /* Wait for the input frame's fence so prior GPU work on this
1488 * surface completes before the video processor reads it. */
1489 if (input_frame->sync_ctx.fence && input_frame->sync_ctx.fence_value > 0) {
1490 UINT64 completed = ID3D12Fence_GetCompletedValue(input_frame->sync_ctx.fence);
1491 if (completed < input_frame->sync_ctx.fence_value) {
1492 hr = ID3D12CommandQueue_Wait(s->command_queue, input_frame->sync_ctx.fence, input_frame->sync_ctx.fence_value);
1493 if (FAILED(hr)) {
1494 av_log(ctx, AV_LOG_ERROR, "Failed to wait for input fence: HRESULT 0x%lX\n", hr);
1496 goto fail;
1497 }
1498 wait_enqueued = 1;
1499 s->gpu_work_submitted = 1;
1500 }
1501 }
1502
1503 if (output_frame->sync_ctx.fence && output_frame->sync_ctx.fence_value > 0) {
1504 UINT64 completed = ID3D12Fence_GetCompletedValue(output_frame->sync_ctx.fence);
1505 if (completed < output_frame->sync_ctx.fence_value) {
1506 hr = ID3D12CommandQueue_Wait(s->command_queue, output_frame->sync_ctx.fence, output_frame->sync_ctx.fence_value);
1507 if (FAILED(hr)) {
1508 av_log(ctx, AV_LOG_ERROR, "Failed to wait for output frame fence: HRESULT 0x%lX\n", hr);
1510 if (wait_enqueued)
1511 goto submit_fail;
1512 goto fail;
1513 }
1514 s->gpu_work_submitted = 1;
1515 }
1516 }
1517
1518 ID3D12CommandList *cmd_lists[] = { (ID3D12CommandList *)s->command_list };
1519 ID3D12CommandQueue_ExecuteCommandLists(s->command_queue, 1, cmd_lists);
1520 s->gpu_work_submitted = 1;
1521
1522 UINT64 next_output_fence_value = output_frame->sync_ctx.fence_value + 1;
1523 UINT64 next_private_fence_value = s->fence_value;
1524
1525 hr = ID3D12CommandQueue_Signal(s->command_queue, output_frame->sync_ctx.fence,
1526 next_output_fence_value);
1527 if (FAILED(hr)) {
1528 av_log(ctx, AV_LOG_ERROR, "Failed to signal output frame fence: HRESULT 0x%lX\n", hr);
1530 goto submit_fail;
1531 }
1532 output_frame->sync_ctx.fence_value = next_output_fence_value;
1533
1534 hr = ID3D12CommandQueue_Signal(s->command_queue, s->fence, next_private_fence_value);
1535 if (FAILED(hr)) {
1536 av_log(ctx, AV_LOG_ERROR, "Failed to signal fence: HRESULT 0x%lX\n", hr);
1538 goto submit_fail;
1539 }
1540
1541 s->fence_value++;
1542
1543 AVFrame *input_ref = av_frame_clone(in);
1544 if (!input_ref) {
1545 ret = AVERROR(ENOMEM);
1546 goto submit_fail;
1547 }
1548
1549 ret = scale_d3d12_discard_command_allocator(s, ctx, command_allocator, next_private_fence_value,
1550 input_ref);
1551 command_allocator = NULL;
1552 if (ret < 0)
1553 goto fail;
1554
1556 if (ret < 0) {
1557 av_log(ctx, AV_LOG_ERROR, "Failed to copy frame properties\n");
1558 goto fail;
1559 }
1560
1561 int in_width = in->width;
1562 int in_height = in->height;
1563
1564 out->width = s->width;
1565 out->height = s->height;
1566 out->format = AV_PIX_FMT_D3D12;
1567
1568 if (out->width != in_width || out->height != in_height)
1569 av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
1570 (int64_t)in->sample_aspect_ratio.num * out->height * in_width,
1571 (int64_t)in->sample_aspect_ratio.den * out->width * in_height,
1572 INT_MAX);
1573
1574 if (out->width != in_width || out->height != in_height) {
1575 av_frame_side_data_remove_by_props(&out->side_data, &out->nb_side_data,
1577 out->crop_left = out->crop_right = out->crop_top = out->crop_bottom = 0;
1578 }
1579
1580 out->colorspace = s->output_av_colorspace;
1581 out->color_range = s->output_av_color_range;
1582 out->color_primaries = s->output_av_color_primaries;
1583 out->color_trc = s->output_av_color_trc;
1584
1585 if (out->color_primaries != s->input_av_color_primaries || out->color_trc != s->input_av_color_trc)
1586 av_frame_side_data_remove_by_props(&out->side_data, &out->nb_side_data,
1588
1589 if (!s->output_has_alpha)
1590 out->alpha_mode = AVALPHA_MODE_UNSPECIFIED;
1591
1592 if (s->output_is_rgb) {
1593 out->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
1594 } else {
1595 out->chroma_location = d3d12_scale_dxgi_chroma_location(s->output_colorspace);
1596 }
1597
1598 av_frame_free(&in);
1599
1600 return ff_filter_frame(outlink, out);
1601
1602submit_fail:
1603 removed_reason = ID3D12Device_GetDeviceRemovedReason(s->device);
1604 gpu_confirmed_done = FAILED(removed_reason);
1605
1606 if (gpu_confirmed_done) {
1608 "D3D12 device removed (HRESULT 0x%lX); frame "
1609 "resources are safe to release\n", removed_reason);
1610 } else if (s->command_queue && s->fence && s->fence_event) {
1611 UINT64 last_resort = s->fence_value + 1;
1612 if (SUCCEEDED(ID3D12CommandQueue_Signal(s->command_queue, s->fence, last_resort))) {
1613 UINT64 completed;
1614
1615 if (last_resort >= s->fence_value)
1616 s->fence_value = last_resort + 1;
1617
1618 completed = ID3D12Fence_GetCompletedValue(s->fence);
1619 if (completed >= last_resort) {
1620 gpu_confirmed_done = 1;
1621 } else {
1622 gpu_confirmed_done = scale_d3d12_wait_fence_exact(s->fence, last_resort,
1623 s->fence_event, 5000);
1624 if (!gpu_confirmed_done)
1626 "Post-failure GPU wait timed out; frame "
1627 "resources cannot be safely recycled\n");
1628 }
1629 } else {
1631 "Best-effort post-failure GPU sync Signal also "
1632 "failed; frame resources cannot be safely "
1633 "recycled\n");
1634 }
1635 } else {
1637 "No fence/queue for post-failure GPU sync; frame "
1638 "resources cannot be safely recycled\n");
1639 }
1640
1641 if (!gpu_confirmed_done) {
1643 "Abandoning this frame's input/output surfaces and "
1644 "command allocator without releasing them\n");
1645 return ret;
1646 }
1647
1648 goto fail;
1649
1650force_reconfigure:
1651 s->configured = 0;
1653 command_allocator = NULL;
1654
1655fail:
1656 if (command_allocator)
1657 ID3D12CommandAllocator_Release(command_allocator);
1658 av_frame_free(&in);
1660 return ret;
1661}
1662
1664{
1665 AVFilterContext *ctx = outlink->src;
1666 ScaleD3D12Context *s = ctx->priv;
1667 AVFilterLink *inlink = ctx->inputs[0];
1668 FilterLink *inl = ff_filter_link(inlink);
1669 FilterLink *outl = ff_filter_link(outlink);
1670 int ret;
1671
1672 if (!release_d3d12_resources(s, ctx)) {
1674 "Cannot (re)configure scale_d3d12: a prior configuration's "
1675 "D3D12 resources could not be confirmed released\n");
1676
1677 return AVERROR_EXTERNAL;
1678 }
1679 av_buffer_unref(&s->hw_frames_ctx_out);
1680 av_buffer_unref(&s->hw_device_ctx);
1681
1682 ret = ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink, &s->width, &s->height);
1683 if (ret < 0) {
1684 av_log(ctx, AV_LOG_ERROR, "Failed to evaluate dimensions\n");
1685 return ret;
1686 }
1687
1688 /* Adjust dimensions to meet codec/hardware alignment requirements */
1689 ret = ff_scale_adjust_dimensions(inlink, &s->width, &s->height, 0, 1, 1.f);
1690 if (ret < 0)
1691 return ret;
1692
1693 outlink->w = s->width;
1694 outlink->h = s->height;
1695
1696 if (inlink->sample_aspect_ratio.num) {
1697 AVRational q = av_div_q((AVRational){ inlink->w, inlink->h },
1698 (AVRational){ outlink->w, outlink->h });
1699 outlink->sample_aspect_ratio = av_mul_q(q, inlink->sample_aspect_ratio);
1700 } else {
1701 outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
1702 }
1703
1704 if (!inl->hw_frames_ctx) {
1705 av_log(ctx, AV_LOG_ERROR, "No hw_frames_ctx available on input link\n");
1706 return AVERROR(EINVAL);
1707 }
1708
1709 if (!s->hw_device_ctx) {
1710 AVHWFramesContext *in_frames_ctx = (AVHWFramesContext *)inl->hw_frames_ctx->data;
1711 s->hw_device_ctx = av_buffer_ref(in_frames_ctx->device_ref);
1712 if (!s->hw_device_ctx) {
1713 av_log(ctx, AV_LOG_ERROR, "Failed to initialize filter hardware device context\n");
1714 return AVERROR(ENOMEM);
1715 }
1716 }
1717
1718 AVHWDeviceContext *hwctx = (AVHWDeviceContext *)s->hw_device_ctx->data;
1719 AVD3D12VADeviceContext *d3d12_hwctx = (AVD3D12VADeviceContext *)hwctx->hwctx;
1720
1721 s->device = d3d12_hwctx->device;
1722
1723 if (!s->device) {
1724 av_log(ctx, AV_LOG_ERROR, "Failed to get valid D3D12 device\n");
1725 return AVERROR(EINVAL);
1726 }
1727
1728 s->hw_frames_ctx_out = av_hwframe_ctx_alloc(s->hw_device_ctx);
1729 if (!s->hw_frames_ctx_out)
1730 return AVERROR(ENOMEM);
1731
1732 AVHWFramesContext *frames_ctx = (AVHWFramesContext *)s->hw_frames_ctx_out->data;
1733 AVHWFramesContext *in_frames_ctx = (AVHWFramesContext *)inl->hw_frames_ctx->data;
1734
1735 enum AVPixelFormat resolved_format = s->format;
1736 if (resolved_format == AV_PIX_FMT_NONE) {
1737 /* If format is not specified, use the same format as input */
1738 resolved_format = in_frames_ctx->sw_format;
1739 av_log(ctx, AV_LOG_VERBOSE, "D3D12 scale output format not specified, using input format: %s\n",
1740 av_get_pix_fmt_name(resolved_format));
1741 }
1742 frames_ctx->sw_format = resolved_format;
1743
1744 /* Set output format based on sw_format */
1745 const D3D12ScaleFormatMap *out_map = d3d12_scale_map_from_pixfmt(frames_ctx->sw_format);
1746 if (!out_map) {
1747 av_log(ctx, AV_LOG_ERROR, "Unsupported output format: %s\n",
1748 av_get_pix_fmt_name(frames_ctx->sw_format));
1749 av_buffer_unref(&s->hw_frames_ctx_out);
1750
1751 return AVERROR(EINVAL);
1752 }
1753 s->output_format = out_map->dxgi_format;
1754 s->output_is_rgb = out_map->is_rgb;
1755
1756 const D3D12ScaleFormatMap *in_map = d3d12_scale_map_from_pixfmt(in_frames_ctx->sw_format);
1757 int input_is_rgb = in_map ? in_map->is_rgb : 0;
1758
1759 if (s->color_primaries != AVCOL_PRI_UNSPECIFIED ||
1760 s->color_transfer != AVCOL_TRC_UNSPECIFIED ||
1761 s->color_matrix != AVCOL_SPC_UNSPECIFIED ||
1762 input_is_rgb != s->output_is_rgb ||
1763 frames_ctx->sw_format == AV_PIX_FMT_RGBAF16 ||
1764 (input_is_rgb && s->color_range != AVCOL_RANGE_UNSPECIFIED))
1767
1768 frames_ctx->width = s->width;
1769 frames_ctx->height = s->height;
1770 frames_ctx->format = AV_PIX_FMT_D3D12;
1771 frames_ctx->initial_pool_size = 4;
1772
1773 if (ctx->extra_hw_frames > 0)
1774 frames_ctx->initial_pool_size += ctx->extra_hw_frames;
1775
1776 AVD3D12VAFramesContext *frames_hwctx = frames_ctx->hwctx;
1777
1778 /*
1779 * Set D3D12 resource flags for video processing
1780 * ALLOW_RENDER_TARGET is needed for video processor output
1781 */
1782 frames_hwctx->format = s->output_format;
1783 frames_hwctx->resource_flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
1784 frames_hwctx->heap_flags = D3D12_HEAP_FLAG_NONE;
1785
1786 ret = av_hwframe_ctx_init(s->hw_frames_ctx_out);
1787 if (ret < 0) {
1788 av_buffer_unref(&s->hw_frames_ctx_out);
1789 return ret;
1790 }
1791
1792 outl->hw_frames_ctx = av_buffer_ref(s->hw_frames_ctx_out);
1793 if (!outl->hw_frames_ctx)
1794 return AVERROR(ENOMEM);
1795
1796 av_log(ctx, AV_LOG_VERBOSE, "D3D12 scale config: %dx%d -> %dx%d\n",
1797 inlink->w, inlink->h, outlink->w, outlink->h);
1798
1799 return 0;
1800}
1801
1803 ScaleD3D12Context *s = ctx->priv;
1804
1806 av_buffer_unref(&s->hw_frames_ctx_out);
1807 av_buffer_unref(&s->hw_device_ctx);
1808 }
1809
1810 av_freep(&s->w_expr);
1811 av_freep(&s->h_expr);
1812
1813 av_freep(&s->color_matrix_string);
1814 av_freep(&s->color_transfer_string);
1815 av_freep(&s->color_primaries_string);
1816}
1817
1826
1828 AVFilterFormatsConfig **cfg_in,
1829 AVFilterFormatsConfig **cfg_out)
1830{
1831 static const enum AVPixelFormat pix_fmts[] = {
1833 };
1834 static const int out_chroma_locs_any[] = {
1836 };
1837 static const int out_chroma_locs_left[] = {
1839 };
1840 const ScaleD3D12Context *s = avctx->priv;
1841 AVFilterFormats *color_spaces, *color_ranges;
1842 enum AVColorSpace out_matrix;
1843 int out_matrix_known;
1844 int ret;
1845
1846 ret = ff_set_pixel_formats_from_list2(avctx, cfg_in, cfg_out, pix_fmts);
1847 if (ret < 0)
1848 return ret;
1849
1850 out_matrix_known = s->color_matrix != AVCOL_SPC_UNSPECIFIED ||
1851 s->color_primaries != AVCOL_PRI_UNSPECIFIED;
1852 if (s->color_matrix != AVCOL_SPC_UNSPECIFIED)
1853 out_matrix = s->color_matrix == AVCOL_SPC_BT2020_CL ? AVCOL_SPC_BT2020_NCL : s->color_matrix;
1854 else if (s->color_primaries != AVCOL_PRI_UNSPECIFIED)
1855 out_matrix = d3d12_scale_matrix_from_primaries(s->color_primaries);
1856 else
1857 out_matrix = AVCOL_SPC_UNSPECIFIED;
1858
1859 color_spaces = ff_all_color_spaces();
1860 if ((ret = ff_formats_ref(color_spaces, &cfg_in[0]->color_spaces)) < 0)
1861 return ret;
1862 if (out_matrix_known)
1863 color_spaces = ff_make_formats_list_singleton(out_matrix);
1864 if ((ret = ff_formats_ref(color_spaces, &cfg_out[0]->color_spaces)) < 0)
1865 return ret;
1866
1867 color_ranges = ff_all_color_ranges();
1868 if ((ret = ff_formats_ref(color_ranges, &cfg_in[0]->color_ranges)) < 0)
1869 return ret;
1870 if (s->color_range != AVCOL_RANGE_UNSPECIFIED)
1871 color_ranges = ff_make_formats_list_singleton(s->color_range);
1872 if ((ret = ff_formats_ref(color_ranges, &cfg_out[0]->color_ranges)) < 0)
1873 return ret;
1874
1875 if ((ret = ff_formats_ref(ff_all_chroma_locations(), &cfg_in[0]->chroma_locations)) < 0)
1876 return ret;
1877 if (out_matrix_known && out_matrix != AVCOL_SPC_BT2020_NCL) {
1878 if ((ret = ff_formats_ref(ff_make_format_list(out_chroma_locs_left), &cfg_out[0]->chroma_locations)) < 0)
1879 return ret;
1880 } else {
1881 if ((ret = ff_formats_ref(ff_make_format_list(out_chroma_locs_any), &cfg_out[0]->chroma_locations)) < 0)
1882 return ret;
1883 }
1884
1885 return 0;
1886}
1887
1889 {
1890 .name = "default",
1891 .type = AVMEDIA_TYPE_VIDEO,
1892 .filter_frame = scale_d3d12_filter_frame,
1893 },
1894};
1895
1897 {
1898 .name = "default",
1899 .type = AVMEDIA_TYPE_VIDEO,
1900 .config_props = scale_d3d12_config_props,
1901 },
1902};
1903
1904#define OFFSET(x) offsetof(ScaleD3D12Context, x)
1905#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
1906
1908 { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, .flags = FLAGS },
1909 { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, .flags = FLAGS },
1910 { "format", "Output video pixel format", OFFSET(format), AV_OPT_TYPE_PIXEL_FMT, { .i64 = AV_PIX_FMT_NONE }, INT_MIN, INT_MAX, .flags=FLAGS },
1911
1912 /* These color properties match the identically named ones in vf_scale_vaapi. */
1913 { "out_color_matrix", "Output color matrix coefficient set",
1914 OFFSET(color_matrix_string), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
1915 { "out_range", "Output color range",
1917 AVCOL_RANGE_UNSPECIFIED, AVCOL_RANGE_JPEG, FLAGS, .unit = "range" },
1918 { "full", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, .unit = "range" },
1919 { "limited", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
1920 { "jpeg", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, .unit = "range" },
1921 { "mpeg", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
1922 { "tv", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
1923 { "pc", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, .unit = "range" },
1924 { "out_color_primaries", "Output color primaries",
1925 OFFSET(color_primaries_string), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
1926 { "out_color_transfer", "Output color transfer characteristics",
1927 OFFSET(color_transfer_string), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
1928
1929 { NULL }
1930};
1931
1933
1935 .p.name = "scale_d3d12",
1936 .p.description = NULL_IF_CONFIG_SMALL("Scale video using Direct3D12"),
1937 .priv_size = sizeof(ScaleD3D12Context),
1938 .p.priv_class = &scale_d3d12_class,
1939 .init = scale_d3d12_init,
1940 .uninit = scale_d3d12_uninit,
1944 .p.flags = AVFILTER_FLAG_HWDEVICE,
1945 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
1946};
static int probe(const AVProbeData *p)
Definition act.c:39
static const char *const format[]
Definition af_aiir.c:445
const FFFilter ff_vf_scale_d3d12
static FILE * out
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1079
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FLAGS
Definition cmdutils.c:596
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
Definition csp.c:76
@ 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
int ret
Definition ffplay.c:391
A generic FIFO API.
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add ref as a new reference to formats.
Definition formats.c:776
AVFilterFormats * ff_all_color_spaces(void)
Construct an AVFilterFormats representing all possible color spaces.
Definition formats.c:706
AVFilterFormats * ff_make_formats_list_singleton(int fmt)
Equivalent to ff_make_format_list({const int[]}{ fmt, -1 })
Definition formats.c:605
AVFilterFormats * ff_all_color_ranges(void)
Construct an AVFilterFormats representing all possible color ranges.
Definition formats.c:722
AVFilterFormats * ff_all_chroma_locations(void)
Construct an AVFilterFormats representing all possible chroma locations.
Definition formats.c:744
int ff_set_pixel_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const enum AVPixelFormat *fmts)
Definition formats.c:1225
av_warn_unused_result AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
reference-counted frame API
#define fail
Definition test.h:479
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_PIXEL_FMT
Underlying C type is enum AVPixelFormat.
Definition opt.h:306
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition avfilter.h:193
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
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:104
#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_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd, int props)
Remove and free all side data instances that match any of the given side data properties.
Definition side_data.c:124
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:65
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:602
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:53
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition frame.c:486
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
Definition frame.h:361
@ AV_SIDE_DATA_PROP_COLOR_DEPENDENT
Side data depends on the video color space.
Definition frame.h:368
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int av_log_get_level(void)
Get the current log level.
Definition log.c:477
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition rational.c:80
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
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition rational.c:88
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
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
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition hwcontext.c:564
An API-specific header for AV_HWDEVICE_TYPE_D3D12VA.
const VDPAUPixFmtMap * map
#define b
Definition input.c:43
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
Definition h264dec.c:942
#define FILTER_INPUTS(array)
Definition filters.h:279
#define FILTER_OUTPUTS(array)
Definition filters.h:280
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition filters.h:208
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:493
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:256
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
#define FFSWAP(type, a, b)
Definition macros.h:52
enum AVColorPrimaries primaries
enum AVColorSpace space
enum AVColorRange range
AVOptions.
const char * av_color_space_name(enum AVColorSpace space)
Definition pixdesc.c:3884
const char * av_color_range_name(enum AVColorRange range)
Definition pixdesc.c:3800
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
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition pixdesc.h:147
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_MPEG
Narrow or limited range content.
Definition pixfmt.h:775
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:758
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:792
#define AV_PIX_FMT_P012
Definition pixfmt.h:614
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
Definition pixfmt.h:826
@ AVALPHA_MODE_PREMULTIPLIED
Alpha channel is multiplied into color values.
Definition pixfmt.h:827
#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_NONE
Definition pixfmt.h:72
@ 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_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition pixfmt.h:712
@ 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
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by, double w_adj)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
Definition scale_eval.c:123
int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, int *ret_w, int *ret_h)
Parse and evaluate string expressions for width and height.
Definition scale_eval.c:58
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
Describe the class of an AVClass context structure.
Definition log.h:76
This struct is allocated as AVHWDeviceContext.hwctx.
ID3D12Device * device
Device used for objects creation and access.
D3D12VA frame descriptor for pool allocation.
ID3D12Resource * texture
The texture in which the frame is located.
AVD3D12VASyncContext sync_ctx
The sync context for the texture.
int subresource_index
Index of the subresource within 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.
Definition fifo.c:35
An instance of a filter.
Definition avfilter.h:279
void * priv
private data for use by the filter
Definition avfilter.h:294
Lists of formats / etc.
Definition avfilter.h:120
A list of supported formats for one end of a filter link.
Definition formats.h:64
A filter pad used for either input or output.
Definition filters.h:40
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
enum AVChromaLocation chroma_location
Definition frame.h:746
int width
Definition frame.h:551
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
Definition frame.h:779
int height
Definition frame.h:551
enum AVColorPrimaries color_primaries
Definition frame.h:735
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition frame.h:576
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition frame.h:733
enum AVColorSpace colorspace
YUV colorspace type.
Definition frame.h:744
enum AVAlphaMode alpha_mode
Indicates how the alpha channel of the video is to be handled.
Definition frame.h:837
enum AVColorTransferCharacteristic color_trc
Definition frame.h:737
int64_t duration
Duration of the frame, in the same units as pts.
Definition frame.h:830
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition hwcontext.h:88
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition hwcontext.h:75
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
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition hwcontext.h:129
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
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
Definition pixdesc.h:94
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
enum AVPixelFormat pix_fmt
DXGI_FORMAT dxgi_format
ID3D12VideoProcessor * video_processor
AVBufferRef * hw_device_ctx
ID3D12VideoDevice * video_device
enum AVColorRange output_av_color_range
enum AVColorPrimaries color_primaries
DXGI_FORMAT output_format
enum AVPixelFormat format
AVRational input_framerate
AVBufferRef * hw_frames_ctx_out
ID3D12Device * device
enum AVColorSpace output_av_colorspace
ID3D12VideoProcessCommandList * command_list
enum AVColorPrimaries input_av_color_primaries
D3D12_FEATURE_DATA_VIDEO_PROCESS_SUPPORT process_support
enum AVColorTransferCharacteristic color_transfer
DXGI_FORMAT input_format
ID3D12Fence * fence
enum AVColorSpace color_matrix
enum AVColorPrimaries output_av_color_primaries
DXGI_COLOR_SPACE_TYPE output_colorspace
enum AVColorTransferCharacteristic input_av_color_trc
ID3D12CommandQueue * command_queue
DXGI_COLOR_SPACE_TYPE input_colorspace
enum AVColorTransferCharacteristic output_av_color_trc
const AVClass * classCtx
char * color_primaries_string
#define av_freep(p)
#define av_log(a,...)
float framerate
Definition av1_levels.c:29
static const Range full_range
static const AVFilterPad scale_d3d12_inputs[]
static int scale_d3d12_filter_frame(AVFilterLink *inlink, AVFrame *in)
static int d3d12_scale_known_matrix(enum AVColorSpace spc)
static int release_d3d12_resources(ScaleD3D12Context *s, AVFilterContext *ctx)
static av_cold int scale_d3d12_init(AVFilterContext *ctx)
static AVRational get_input_framerate(AVFilterContext *ctx, AVFilterLink *inlink, AVFrame *in)
static int scale_d3d12_query_formats(const AVFilterContext *avctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int scale_d3d12_discard_command_allocator(ScaleD3D12Context *s, AVFilterContext *ctx, ID3D12CommandAllocator *pAllocator, UINT64 fence_value, AVFrame *input_ref)
static int d3d12_scale_reconcile_primaries(AVFilterContext *ctx, int is_output, enum AVColorPrimaries *primaries, enum AVColorPrimaries expected_primaries, const char *space_description)
static const D3D12ScaleFormatMap * d3d12_scale_map_from_pixfmt(enum AVPixelFormat fmt)
static int scale_d3d12_wait_fence_exact(ID3D12Fence *fence, UINT64 target, HANDLE fence_event, DWORD timeout_ms)
static int d3d12_scale_trc_group(enum AVColorTransferCharacteristic trc)
static enum AVColorSpace d3d12_scale_matrix_from_primaries(enum AVColorPrimaries primaries)
static av_cold void scale_d3d12_uninit(AVFilterContext *ctx)
static int d3d12_scale_reject_unrepresentable_siting_2020(AVFilterContext *ctx, int is_output, enum AVChromaLocation chroma_loc)
#define STRING_OPTION(var_name, func_name, opt_name, default_value)
static const AVFilterPad scale_d3d12_outputs[]
static const D3D12ScaleFormatMap d3d12_scale_format_map[]
static int scale_d3d12_config_props(AVFilterLink *outlink)
static void scale_d3d12_report_output_support(ScaleD3D12Context *s, AVFilterContext *ctx)
static const D3D12ScaleFormatMap * d3d12_scale_map_from_dxgi(DXGI_FORMAT fmt)
static const AVOption scale_d3d12_options[]
static int d3d12_scale_known_sdr_trc(enum AVColorTransferCharacteristic trc)
static int scale_d3d12_get_valid_command_allocator(ScaleD3D12Context *s, AVFilterContext *ctx, ID3D12CommandAllocator **ppAllocator)
static int d3d12_scale_finalize_output_trc(AVFilterContext *ctx, DXGI_COLOR_SPACE_TYPE input_space, DXGI_COLOR_SPACE_TYPE output_space, int explicit_request, enum AVColorTransferCharacteristic input_trc, enum AVColorTransferCharacteristic *trc)
#define OFFSET(x)
static int d3d12_scale_reject_unrepresentable_left(AVFilterContext *ctx, int is_output, enum AVChromaLocation chroma_loc)
static int d3d12_scale_reject_unrepresentable_nonleft(AVFilterContext *ctx, int is_output, enum AVChromaLocation chroma_loc)
static int scale_d3d12_configure_processor(ScaleD3D12Context *s, AVFilterContext *ctx)
static enum AVChromaLocation d3d12_scale_dxgi_chroma_location(DXGI_COLOR_SPACE_TYPE space)
static int d3d12_scale_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)
color_range
#define WaitForSingleObject(a, b)
Definition w32pthreads.h:64