History

avcodec: add D3D12VA hardware accelerated H264 decoding

The implementation is based on: https://learn.microsoft.com/en-us/windows/win32/medfound/direct3d-12-video-overview With the Direct3D 12 video decoding support, we can render or process the decoded images by the pixel shaders or compute shaders directly without the extra copy overhead, which is beneficial especially if you are trying to render or post-process a 4K or 8K video. The command below is how to enable d3d12va: ffmpeg -hwaccel d3d12va -i input.mp4 output.mp4

Wu Jianhua committed 2 years ago

Commit 349ce301 parent 142f72719 files · +1036 −66Browse files

Showing the changes to libavcodec (18 of 19 files). Show all

Unified · Split

18 files
  1. libavcodec/Makefile +3 −0
  2. libavcodec/d3d11va.h +0 −3
  3. libavcodec/d3d12va_decode.c +538 −0
  4. libavcodec/d3d12va_decode.h +179 −0
  5. libavcodec/d3d12va_h264.c +207 −0
  6. libavcodec/dxva2.c +27 −2
  7. libavcodec/dxva2.h +0 −3
  8. libavcodec/dxva2_av1.c +2 −2
  9. libavcodec/dxva2_h264.c +14 −12
  10. libavcodec/dxva2_hevc.c +3 −3
  11. libavcodec/dxva2_internal.h +42 −32
  12. libavcodec/dxva2_mpeg2.c +3 −3
  13. libavcodec/dxva2_vc1.c +3 −3
  14. libavcodec/dxva2_vp9.c +3 −3
  15. libavcodec/h264_slice.c +4 −0
  16. libavcodec/h264dec.c +3 −0
  17. libavcodec/hwaccels.h +1 −0
  18. libavcodec/hwconfig.h +2 −0
libavcodec/Makefile+3−0
@@ -986,6 +986,7 @@ OBJS-$(CONFIG_ADPCM_ZORK_DECODER) += adpcm.o adpcm_data.o · 985 unmodified lines
986986
987987 # hardware accelerators
988988 OBJS-$(CONFIG_D3D11VA) += dxva2.o
989+OBJS-$(CONFIG_D3D12VA) += dxva2.o d3d12va_decode.o
989990 OBJS-$(CONFIG_DXVA2) += dxva2.o
990991 OBJS-$(CONFIG_NVDEC) += nvdec.o
991992 OBJS-$(CONFIG_VAAPI) += vaapi_decode.o
@@ -1003,6 +1004,7 @@ OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o · 11 unmodified lines
10031004 OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
10041005 OBJS-$(CONFIG_H264_D3D11VA_HWACCEL) += dxva2_h264.o
10051006 OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o
1007+OBJS-$(CONFIG_H264_D3D12VA_HWACCEL) += dxva2_h264.o d3d12va_h264.o
10061008 OBJS-$(CONFIG_H264_NVDEC_HWACCEL) += nvdec_h264.o
10071009 OBJS-$(CONFIG_H264_QSV_HWACCEL) += qsvdec.o
10081010 OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o
@@ -1296,6 +1298,7 @@ SKIPHEADERS += %_tablegen.h \ · 287 unmodified lines
12961298
12971299 SKIPHEADERS-$(CONFIG_AMF) += amfenc.h
12981300 SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h
1301+SKIPHEADERS-$(CONFIG_D3D12VA) += d3d12va_decode.h
12991302 SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h
13001303 SKIPHEADERS-$(CONFIG_JNI) += ffjni.h
13011304 SKIPHEADERS-$(CONFIG_LCMS2) += fflcms2.h
libavcodec/d3d11va.h+0−3
@@ -45,9 +45,6 @@ · 44 unmodified lines
4545 * @{
4646 */
4747
48−#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for Direct3D11 and old UVD/UVD+ ATI video cards
49−#define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO 2 ///< Work around for Direct3D11 and old Intel GPUs with ClearVideo interface
50−
5148 /**
5249 * This structure is used to provides the necessary configurations and data
5350 * to the Direct3D11 FFmpeg HWAccel implementation.
libavcodec/d3d12va_decode.c+538−0
@@ -0,0 +1,538 @@
1+/*
2+ * Direct3D 12 HW acceleration video decoder
3+ *
4+ * copyright (c) 2022-2023 Wu Jianhua <toqsxw@outlook.com>
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+#include <assert.h>
24+#include <string.h>
25+#include <initguid.h>
26+
27+#include "libavutil/common.h"
28+#include "libavutil/log.h"
29+#include "libavutil/time.h"
30+#include "libavutil/imgutils.h"
31+#include "libavutil/hwcontext_d3d12va_internal.h"
32+#include "libavutil/hwcontext_d3d12va.h"
33+#include "avcodec.h"
34+#include "decode.h"
35+#include "d3d12va_decode.h"
36+
37+typedef struct HelperObjects {
38+ ID3D12CommandAllocator *command_allocator;
39+ ID3D12Resource *buffer;
40+ uint64_t fence_value;
41+} HelperObjects;
42+
43+int ff_d3d12va_get_suitable_max_bitstream_size(AVCodecContext *avctx)
44+{
45+ AVHWFramesContext *frames_ctx = D3D12VA_FRAMES_CONTEXT(avctx);
46+ return av_image_get_buffer_size(frames_ctx->sw_format, avctx->coded_width, avctx->coded_height, 1);
47+}
48+
49+unsigned ff_d3d12va_get_surface_index(const AVCodecContext *avctx,
50+ D3D12VADecodeContext *ctx, const AVFrame *frame,
51+ int curr)
52+{
53+ AVD3D12VAFrame *f;
54+ ID3D12Resource *res;
55+ unsigned i;
56+
57+ f = (AVD3D12VAFrame *)frame->data[0];
58+ if (!f)
59+ goto fail;
60+
61+ res = f->texture;
62+ if (!res)
63+ goto fail;
64+
65+ if (!curr) {
66+ for (i = 0; i < ctx->max_num_ref; i++) {
67+ if (ctx->ref_resources[i] && res == ctx->ref_resources[i]) {
68+ ctx->used_mask |= 1 << i;
69+ return i;
70+ }
71+ }
72+ } else {
73+ for (i = 0; i < ctx->max_num_ref; i++) {
74+ if (!((ctx->used_mask >> i) & 0x1)) {
75+ ctx->ref_resources[i] = res;
76+ return i;
77+ }
78+ }
79+ }
80+
81+fail:
82+ assert(0);
83+ return 0;
84+}
85+
86+static int d3d12va_get_valid_helper_objects(AVCodecContext *avctx, ID3D12CommandAllocator **ppAllocator,
87+ ID3D12Resource **ppBuffer)
88+{
89+ HRESULT hr;
90+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
91+ HelperObjects obj = { 0 };
92+ D3D12_HEAP_PROPERTIES heap_props = { .Type = D3D12_HEAP_TYPE_UPLOAD };
93+
94+ D3D12_RESOURCE_DESC desc = {
95+ .Dimension = D3D12_RESOURCE_DIMENSION_BUFFER,
96+ .Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT,
97+ .Width = ctx->bitstream_size,
98+ .Height = 1,
99+ .DepthOrArraySize = 1,
100+ .MipLevels = 1,
101+ .Format = DXGI_FORMAT_UNKNOWN,
102+ .SampleDesc = { .Count = 1, .Quality = 0 },
103+ .Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
104+ .Flags = D3D12_RESOURCE_FLAG_NONE,
105+ };
106+
107+ if (av_fifo_peek(ctx->objects_queue, &obj, 1, 0) >= 0) {
108+ uint64_t completion = ID3D12Fence_GetCompletedValue(ctx->sync_ctx.fence);
109+ if (completion >= obj.fence_value) {
110+ *ppAllocator = obj.command_allocator;
111+ *ppBuffer = obj.buffer;
112+ av_fifo_read(ctx->objects_queue, &obj, 1);
113+ return 0;
114+ }
115+ }
116+
117+ hr = ID3D12Device_CreateCommandAllocator(ctx->device_ctx->device, D3D12_COMMAND_LIST_TYPE_VIDEO_DECODE,
118+ &IID_ID3D12CommandAllocator, (void **)ppAllocator);
119+ if (FAILED(hr)) {
120+ av_log(avctx, AV_LOG_ERROR, "Failed to create a new command allocator!\n");
121+ return AVERROR(EINVAL);
122+ }
123+
124+ hr = ID3D12Device_CreateCommittedResource(ctx->device_ctx->device, &heap_props, D3D12_HEAP_FLAG_NONE,
125+ &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL,
126+ &IID_ID3D12Resource, (void **)ppBuffer);
127+
128+ if (FAILED(hr)) {
129+ av_log(avctx, AV_LOG_ERROR, "Failed to create a new d3d12 buffer!\n");
130+ return AVERROR(EINVAL);
131+ }
132+
133+ return 0;
134+}
135+
136+static int d3d12va_discard_helper_objects(AVCodecContext *avctx, ID3D12CommandAllocator *pAllocator,
137+ ID3D12Resource *pBuffer, uint64_t fence_value)
138+{
139+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
140+
141+ HelperObjects obj = {
142+ .command_allocator = pAllocator,
143+ .buffer = pBuffer,
144+ .fence_value = fence_value,
145+ };
146+
147+ if (av_fifo_write(ctx->objects_queue, &obj, 1) < 0) {
148+ D3D12_OBJECT_RELEASE(pAllocator);
149+ D3D12_OBJECT_RELEASE(pBuffer);
150+ return AVERROR(ENOMEM);
151+ }
152+
153+ return 0;
154+}
155+
156+static int d3d12va_fence_completion(AVD3D12VASyncContext *psync_ctx)
157+{
158+ uint64_t completion = ID3D12Fence_GetCompletedValue(psync_ctx->fence);
159+ if (completion < psync_ctx->fence_value) {
160+ if (FAILED(ID3D12Fence_SetEventOnCompletion(psync_ctx->fence, psync_ctx->fence_value, psync_ctx->event)))
161+ return AVERROR(EINVAL);
162+
163+ WaitForSingleObjectEx(psync_ctx->event, INFINITE, FALSE);
164+ }
165+
166+ return 0;
167+}
168+
169+static void bufref_free_interface(void *opaque, uint8_t *data)
170+{
171+ D3D12_OBJECT_RELEASE(opaque);
172+}
173+
174+static AVBufferRef *bufref_wrap_interface(IUnknown *iface)
175+{
176+ return av_buffer_create((uint8_t*)iface, 1, bufref_free_interface, iface, 0);
177+}
178+
179+static int d3d12va_sync_with_gpu(AVCodecContext *avctx)
180+{
181+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
182+
183+ DX_CHECK(ID3D12CommandQueue_Signal(ctx->command_queue, ctx->sync_ctx.fence, ++ctx->sync_ctx.fence_value));
184+ return d3d12va_fence_completion(&ctx->sync_ctx);
185+
186+fail:
187+ return AVERROR(EINVAL);
188+}
189+
190+static int d3d12va_create_decoder_heap(AVCodecContext *avctx)
191+{
192+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
193+ AVHWFramesContext *frames_ctx = D3D12VA_FRAMES_CONTEXT(avctx);
194+ AVD3D12VADeviceContext *device_hwctx = ctx->device_ctx;
195+ AVD3D12VAFramesContext *frames_hwctx = frames_ctx->hwctx;
196+
197+ D3D12_VIDEO_DECODER_HEAP_DESC desc = {
198+ .NodeMask = 0,
199+ .Configuration = ctx->cfg,
200+ .DecodeWidth = frames_ctx->width,
201+ .DecodeHeight = frames_ctx->height,
202+ .Format = frames_hwctx->format,
203+ .FrameRate = { avctx->framerate.num, avctx->framerate.den },
204+ .BitRate = avctx->bit_rate,
205+ .MaxDecodePictureBufferCount = ctx->max_num_ref,
206+ };
207+
208+ DX_CHECK(ID3D12VideoDevice_CreateVideoDecoderHeap(device_hwctx->video_device, &desc,
209+ &IID_ID3D12VideoDecoderHeap, (void **)&ctx->decoder_heap));
210+
211+ return 0;
212+
213+fail:
214+ if (ctx->decoder) {
215+ av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support decoding frames with an extent "
216+ "[width(%d), height(%d)], on your device!\n", frames_ctx->width, frames_ctx->height);
217+ }
218+
219+ return AVERROR(EINVAL);
220+}
221+
222+static int d3d12va_create_decoder(AVCodecContext *avctx)
223+{
224+ D3D12_VIDEO_DECODER_DESC desc;
225+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
226+ AVHWFramesContext *frames_ctx = D3D12VA_FRAMES_CONTEXT(avctx);
227+ AVD3D12VADeviceContext *device_hwctx = ctx->device_ctx;
228+ AVD3D12VAFramesContext *frames_hwctx = frames_ctx->hwctx;
229+
230+ D3D12_FEATURE_DATA_VIDEO_DECODE_SUPPORT feature = {
231+ .NodeIndex = 0,
232+ .Configuration = ctx->cfg,
233+ .Width = frames_ctx->width,
234+ .Height = frames_ctx->height,
235+ .DecodeFormat = frames_hwctx->format,
236+ .FrameRate = { avctx->framerate.num, avctx->framerate.den },
237+ .BitRate = avctx->bit_rate,
238+ };
239+
240+ DX_CHECK(ID3D12VideoDevice_CheckFeatureSupport(device_hwctx->video_device, D3D12_FEATURE_VIDEO_DECODE_SUPPORT,
241+ &feature, sizeof(feature)));
242+ if (!(feature.SupportFlags & D3D12_VIDEO_DECODE_SUPPORT_FLAG_SUPPORTED) ||
243+ !(feature.DecodeTier >= D3D12_VIDEO_DECODE_TIER_2)) {
244+ av_log(avctx, AV_LOG_ERROR, "D3D12 decoder doesn't support on this device\n");
245+ return AVERROR(EINVAL);
246+ }
247+
248+ desc = (D3D12_VIDEO_DECODER_DESC) {
249+ .NodeMask = 0,
250+ .Configuration = ctx->cfg,
251+ };
252+
253+ DX_CHECK(ID3D12VideoDevice_CreateVideoDecoder(device_hwctx->video_device, &desc, &IID_ID3D12VideoDecoder,
254+ (void **)&ctx->decoder));
255+
256+ ctx->decoder_ref = bufref_wrap_interface((IUnknown *)ctx->decoder);
257+ if (!ctx->decoder_ref)
258+ return AVERROR(ENOMEM);
259+
260+ return 0;
261+
262+fail:
263+ return AVERROR(EINVAL);
264+}
265+
266+int ff_d3d12va_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
267+{
268+ AVHWFramesContext *frames_ctx = (AVHWFramesContext *)hw_frames_ctx->data;
269+ AVHWDeviceContext *device_ctx = frames_ctx->device_ctx;
270+
271+ frames_ctx->format = AV_PIX_FMT_D3D12;
272+ frames_ctx->sw_format = avctx->sw_pix_fmt == AV_PIX_FMT_YUV420P10 ? AV_PIX_FMT_P010 : AV_PIX_FMT_NV12;
273+ frames_ctx->width = avctx->width;
274+ frames_ctx->height = avctx->height;
275+
276+ return 0;
277+}
278+
279+int ff_d3d12va_decode_init(AVCodecContext *avctx)
280+{
281+ int ret;
282+ AVHWFramesContext *frames_ctx;
283+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
284+ ID3D12Resource *buffer = NULL;
285+ ID3D12CommandAllocator *command_allocator = NULL;
286+ D3D12_COMMAND_QUEUE_DESC queue_desc = {
287+ .Type = D3D12_COMMAND_LIST_TYPE_VIDEO_DECODE,
288+ .Priority = 0,
289+ .Flags = D3D12_COMMAND_QUEUE_FLAG_NONE,
290+ .NodeMask = 0,
291+ };
292+
293+ ctx->pix_fmt = avctx->hwaccel->pix_fmt;
294+
295+ ret = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_D3D12VA);
296+ if (ret < 0)
297+ return ret;
298+
299+ frames_ctx = D3D12VA_FRAMES_CONTEXT(avctx);
300+ ctx->device_ctx = (AVD3D12VADeviceContext *)frames_ctx->device_ctx->hwctx;
301+
302+ if (frames_ctx->format != ctx->pix_fmt) {
303+ av_log(avctx, AV_LOG_ERROR, "Invalid pixfmt for hwaccel!\n");
304+ goto fail;
305+ }
306+
307+ ret = d3d12va_create_decoder(avctx);
308+ if (ret < 0)
309+ goto fail;
310+
311+ ret = d3d12va_create_decoder_heap(avctx);
312+ if (ret < 0)
313+ goto fail;
314+
315+ ctx->bitstream_size = ff_d3d12va_get_suitable_max_bitstream_size(avctx);
316+
317+ ctx->ref_resources = av_calloc(ctx->max_num_ref, sizeof(*ctx->ref_resources));
318+ if (!ctx->ref_resources)
319+ return AVERROR(ENOMEM);
320+
321+ ctx->ref_subresources = av_calloc(ctx->max_num_ref, sizeof(*ctx->ref_subresources));
322+ if (!ctx->ref_subresources)
323+ return AVERROR(ENOMEM);
324+
325+ ctx->objects_queue = av_fifo_alloc2(D3D12VA_VIDEO_DEC_ASYNC_DEPTH,
326+ sizeof(HelperObjects), AV_FIFO_FLAG_AUTO_GROW);
327+ if (!ctx->objects_queue)
328+ return AVERROR(ENOMEM);
329+
330+
331+ DX_CHECK(ID3D12Device_CreateFence(ctx->device_ctx->device, 0, D3D12_FENCE_FLAG_NONE,
332+ &IID_ID3D12Fence, (void **)&ctx->sync_ctx.fence));
333+
334+ ctx->sync_ctx.event = CreateEvent(NULL, FALSE, FALSE, NULL);
335+ if (!ctx->sync_ctx.event)
336+ goto fail;
337+
338+ ret = d3d12va_get_valid_helper_objects(avctx, &command_allocator, &buffer);
339+ if (ret < 0)
340+ goto fail;
341+
342+ DX_CHECK(ID3D12Device_CreateCommandQueue(ctx->device_ctx->device, &queue_desc,
343+ &IID_ID3D12CommandQueue, (void **)&ctx->command_queue));
344+
345+ DX_CHECK(ID3D12Device_CreateCommandList(ctx->device_ctx->device, 0, queue_desc.Type,
346+ command_allocator, NULL, &IID_ID3D12CommandList, (void **)&ctx->command_list));
347+
348+ DX_CHECK(ID3D12VideoDecodeCommandList_Close(ctx->command_list));
349+
350+ ID3D12CommandQueue_ExecuteCommandLists(ctx->command_queue, 1, (ID3D12CommandList **)&ctx->command_list);
351+
352+ ret = d3d12va_sync_with_gpu(avctx);
353+ if (ret < 0)
354+ goto fail;
355+
356+ d3d12va_discard_helper_objects(avctx, command_allocator, buffer, ctx->sync_ctx.fence_value);
357+ if (ret < 0)
358+ goto fail;
359+
360+ return 0;
361+
362+fail:
363+ D3D12_OBJECT_RELEASE(command_allocator);
364+ D3D12_OBJECT_RELEASE(buffer);
365+ ff_d3d12va_decode_uninit(avctx);
366+
367+ return AVERROR(EINVAL);
368+}
369+
370+int ff_d3d12va_decode_uninit(AVCodecContext *avctx)
371+{
372+ int num_allocator = 0;
373+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
374+ HelperObjects obj;
375+
376+ if (ctx->sync_ctx.fence)
377+ d3d12va_sync_with_gpu(avctx);
378+
379+ av_freep(&ctx->ref_resources);
380+ av_freep(&ctx->ref_subresources);
381+
382+ D3D12_OBJECT_RELEASE(ctx->command_list);
383+ D3D12_OBJECT_RELEASE(ctx->command_queue);
384+
385+ if (ctx->objects_queue) {
386+ while (av_fifo_read(ctx->objects_queue, &obj, 1) >= 0) {
387+ num_allocator++;
388+ D3D12_OBJECT_RELEASE(obj.buffer);
389+ D3D12_OBJECT_RELEASE(obj.command_allocator);
390+ }
391+
392+ av_log(avctx, AV_LOG_VERBOSE, "Total number of command allocators reused: %d\n", num_allocator);
393+ }
394+
395+ av_fifo_freep2(&ctx->objects_queue);
396+
397+ D3D12_OBJECT_RELEASE(ctx->sync_ctx.fence);
398+ if (ctx->sync_ctx.event)
399+ CloseHandle(ctx->sync_ctx.event);
400+
401+ D3D12_OBJECT_RELEASE(ctx->decoder_heap);
402+
403+ av_buffer_unref(&ctx->decoder_ref);
404+
405+ return 0;
406+}
407+
408+static inline int d3d12va_update_reference_frames_state(AVCodecContext *avctx, D3D12_RESOURCE_BARRIER *barriers, int state_before, int state_end)
409+{
410+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
411+ AVHWFramesContext *frames_ctx = D3D12VA_FRAMES_CONTEXT(avctx);
412+ AVD3D12VAFramesContext *frames_hwctx = frames_ctx->hwctx;
413+
414+ int num_barrier = 0;
415+ for (int i = 0; i < ctx->max_num_ref; i++) {
416+ if (((ctx->used_mask >> i) & 0x1) && ctx->ref_resources[i]) {
417+ barriers[num_barrier].Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
418+ barriers[num_barrier].Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
419+ barriers[num_barrier].Transition = (D3D12_RESOURCE_TRANSITION_BARRIER){
420+ .pResource = ctx->ref_resources[i],
421+ .Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
422+ .StateBefore = state_before,
423+ .StateAfter = state_end,
424+ };
425+ num_barrier++;
426+ }
427+ }
428+
429+ return num_barrier;
430+}
431+
432+int ff_d3d12va_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
433+ const void *pp, unsigned pp_size,
434+ const void *qm, unsigned qm_size,
435+ int(*update_input_arguments)(AVCodecContext *, D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *, ID3D12Resource *))
436+{
437+ int ret;
438+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
439+ AVHWFramesContext *frames_ctx = D3D12VA_FRAMES_CONTEXT(avctx);
440+ AVD3D12VAFramesContext *frames_hwctx = frames_ctx->hwctx;
441+ ID3D12Resource *buffer = NULL;
442+ ID3D12CommandAllocator *command_allocator = NULL;
443+ AVD3D12VAFrame *f = (AVD3D12VAFrame *)frame->data[0];
444+ ID3D12Resource *resource = (ID3D12Resource *)f->texture;
445+
446+ ID3D12VideoDecodeCommandList *cmd_list = ctx->command_list;
447+ D3D12_RESOURCE_BARRIER barriers[32] = { 0 };
448+
449+ D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS input_args = {
450+ .NumFrameArguments = 2,
451+ .FrameArguments = {
452+ [0] = {
453+ .Type = D3D12_VIDEO_DECODE_ARGUMENT_TYPE_PICTURE_PARAMETERS,
454+ .Size = pp_size,
455+ .pData = (void *)pp,
456+ },
457+ [1] = {
458+ .Type = D3D12_VIDEO_DECODE_ARGUMENT_TYPE_INVERSE_QUANTIZATION_MATRIX,
459+ .Size = qm_size,
460+ .pData = (void *)qm,
461+ },
462+ },
463+ .pHeap = ctx->decoder_heap,
464+ };
465+
466+ D3D12_VIDEO_DECODE_OUTPUT_STREAM_ARGUMENTS output_args = {
467+ .ConversionArguments = { 0 },
468+ .OutputSubresource = 0,
469+ .pOutputTexture2D = resource,
470+ };
471+
472+ UINT num_barrier = 1;
473+ barriers[0] = (D3D12_RESOURCE_BARRIER) {
474+ .Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
475+ .Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE,
476+ .Transition = {
477+ .pResource = resource,
478+ .Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
479+ .StateBefore = D3D12_RESOURCE_STATE_COMMON,
480+ .StateAfter = D3D12_RESOURCE_STATE_VIDEO_DECODE_WRITE,
481+ },
482+ };
483+
484+ memset(ctx->ref_subresources, 0, sizeof(UINT) * ctx->max_num_ref);
485+ input_args.ReferenceFrames.NumTexture2Ds = ctx->max_num_ref;
486+ input_args.ReferenceFrames.ppTexture2Ds = ctx->ref_resources;
487+ input_args.ReferenceFrames.pSubresources = ctx->ref_subresources;
488+
489+ ret = d3d12va_fence_completion(&f->sync_ctx);
490+ if (ret < 0)
491+ goto fail;
492+
493+ if (!qm)
494+ input_args.NumFrameArguments = 1;
495+
496+ ret = d3d12va_get_valid_helper_objects(avctx, &command_allocator, &buffer);
497+ if (ret < 0)
498+ goto fail;
499+
500+ ret = update_input_arguments(avctx, &input_args, buffer);
501+ if (ret < 0)
502+ goto fail;
503+
504+ DX_CHECK(ID3D12CommandAllocator_Reset(command_allocator));
505+
506+ DX_CHECK(ID3D12VideoDecodeCommandList_Reset(cmd_list, command_allocator));
507+
508+ num_barrier += d3d12va_update_reference_frames_state(avctx, &barriers[1], D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_VIDEO_DECODE_READ);
509+
510+ ID3D12VideoDecodeCommandList_ResourceBarrier(cmd_list, num_barrier, barriers);
511+
512+ ID3D12VideoDecodeCommandList_DecodeFrame(cmd_list, ctx->decoder, &output_args, &input_args);
513+
514+ barriers[0].Transition.StateBefore = barriers[0].Transition.StateAfter;
515+ barriers[0].Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
516+ d3d12va_update_reference_frames_state(avctx, &barriers[1], D3D12_RESOURCE_STATE_VIDEO_DECODE_READ, D3D12_RESOURCE_STATE_COMMON);
517+
518+ ID3D12VideoDecodeCommandList_ResourceBarrier(cmd_list, num_barrier, barriers);
519+
520+ DX_CHECK(ID3D12VideoDecodeCommandList_Close(cmd_list));
521+
522+ ID3D12CommandQueue_ExecuteCommandLists(ctx->command_queue, 1, (ID3D12CommandList **)&ctx->command_list);
523+
524+ DX_CHECK(ID3D12CommandQueue_Signal(ctx->command_queue, f->sync_ctx.fence, ++f->sync_ctx.fence_value));
525+
526+ DX_CHECK(ID3D12CommandQueue_Signal(ctx->command_queue, ctx->sync_ctx.fence, ++ctx->sync_ctx.fence_value));
527+
528+ ret = d3d12va_discard_helper_objects(avctx, command_allocator, buffer, ctx->sync_ctx.fence_value);
529+ if (ret < 0)
530+ return ret;
531+
532+ return 0;
533+
534+fail:
535+ if (command_allocator)
536+ d3d12va_discard_helper_objects(avctx, command_allocator, buffer, ctx->sync_ctx.fence_value);
537+ return AVERROR(EINVAL);
538+}
libavcodec/d3d12va_decode.h+179−0
@@ -0,0 +1,179 @@
1+/*
2+ * Direct3D 12 HW acceleration video decoder
3+ *
4+ * copyright (c) 2022-2023 Wu Jianhua <toqsxw@outlook.com>
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+#ifndef AVCODEC_D3D12VA_DECODE_H
24+#define AVCODEC_D3D12VA_DECODE_H
25+
26+#include "libavutil/fifo.h"
27+#include "libavutil/hwcontext.h"
28+#include "libavutil/hwcontext_d3d12va.h"
29+#include "avcodec.h"
30+#include "internal.h"
31+#include "hwaccel_internal.h"
32+
33+/**
34+ * @brief This structure is used to provide the necessary configurations and data
35+ * to the FFmpeg Direct3D 12 HWAccel implementation for video decoder.
36+ */
37+typedef struct D3D12VADecodeContext {
38+ AVBufferRef *decoder_ref;
39+
40+ /**
41+ * D3D12 video decoder
42+ */
43+ ID3D12VideoDecoder *decoder;
44+
45+ /**
46+ * D3D12 video decoder heap
47+ */
48+ ID3D12VideoDecoderHeap *decoder_heap;
49+
50+ /**
51+ * D3D12 configuration used to create the decoder
52+ *
53+ * Specified by decoders
54+ */
55+ D3D12_VIDEO_DECODE_CONFIGURATION cfg;
56+
57+ /**
58+ * A cached queue for reusing the D3D12 command allocators and upload buffers
59+ *
60+ * @see https://learn.microsoft.com/en-us/windows/win32/direct3d12/recording-command-lists-and-bundles#id3d12commandallocator
61+ */
62+ AVFifo *objects_queue;
63+
64+ /**
65+ * D3D12 command queue
66+ */
67+ ID3D12CommandQueue *command_queue;
68+
69+ /**
70+ * D3D12 video decode command list
71+ */
72+ ID3D12VideoDecodeCommandList *command_list;
73+
74+ /**
75+ * The array of resources used for reference frames
76+ *
77+ * The ref_resources.length is the same as D3D12VADecodeContext.max_num_ref
78+ */
79+ ID3D12Resource **ref_resources;
80+
81+ /**
82+ * The array of subresources used for reference frames
83+ *
84+ * The ref_subresources.length is the same as D3D12VADecodeContext.max_num_ref
85+ */
86+ UINT *ref_subresources;
87+
88+ /**
89+ * Maximum number of reference frames
90+ */
91+ UINT max_num_ref;
92+
93+ /**
94+ * Used mask used to record reference frames indices
95+ */
96+ UINT used_mask;
97+
98+ /**
99+ * Bitstream size for each frame
100+ */
101+ UINT bitstream_size;
102+
103+ /**
104+ * The sync context used to sync command queue
105+ */
106+ AVD3D12VASyncContext sync_ctx;
107+
108+ /**
109+ * A pointer to AVD3D12VADeviceContext used to create D3D12 objects
110+ */
111+ AVD3D12VADeviceContext *device_ctx;
112+
113+ /**
114+ * Pixel format
115+ */
116+ enum AVPixelFormat pix_fmt;
117+
118+ /**
119+ * Private to the FFmpeg AVHWAccel implementation
120+ */
121+ unsigned report_id;
122+} D3D12VADecodeContext;
123+
124+/**
125+ * @}
126+ */
127+#define D3D12VA_VIDEO_DEC_ASYNC_DEPTH 36
128+#define D3D12VA_DECODE_CONTEXT(avctx) ((D3D12VADecodeContext *)((avctx)->internal->hwaccel_priv_data))
129+#define D3D12VA_FRAMES_CONTEXT(avctx) ((AVHWFramesContext *)(avctx)->hw_frames_ctx->data)
130+
131+/**
132+ * @brief Get a suitable maximum bitstream size
133+ *
134+ * Creating and destroying a resource on d3d12 needs sync and reallocation, so use this function
135+ * to help allocate a big enough bitstream buffer to avoid recreating resources when decoding.
136+ *
137+ * @return the suitable size
138+ */
139+int ff_d3d12va_get_suitable_max_bitstream_size(AVCodecContext *avctx);
140+
141+/**
142+ * @brief init D3D12VADecodeContext
143+ *
144+ * @return Error code (ret < 0 if failed)
145+ */
146+int ff_d3d12va_decode_init(AVCodecContext *avctx);
147+
148+/**
149+ * @brief uninit D3D12VADecodeContext
150+ *
151+ * @return Error code (ret < 0 if failed)
152+ */
153+int ff_d3d12va_decode_uninit(AVCodecContext *avctx);
154+
155+/**
156+ * @brief d3d12va common frame params
157+ *
158+ * @return Error code (ret < 0 if failed)
159+ */
160+int ff_d3d12va_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
161+
162+/**
163+ * @brief d3d12va common end frame
164+ *
165+ * @param avctx codec context
166+ * @param frame current output frame
167+ * @param pp picture parameters
168+ * @param pp_size the size of the picture parameters
169+ * @param qm quantization matrix
170+ * @param qm_size the size of the quantization matrix
171+ * @param callback update decoder-specified input stream arguments
172+ * @return Error code (ret < 0 if failed)
173+ */
174+int ff_d3d12va_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
175+ const void *pp, unsigned pp_size,
176+ const void *qm, unsigned qm_size,
177+ int(*)(AVCodecContext *, D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *, ID3D12Resource *));
178+
179+#endif /* AVCODEC_D3D12VA_DEC_H */
libavcodec/d3d12va_h264.c+207−0
@@ -0,0 +1,207 @@
1+/*
2+ * Direct3D 12 h264 HW acceleration
3+ *
4+ * copyright (c) 2022-2023 Wu Jianhua <toqsxw@outlook.com>
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+#include "config_components.h"
24+#include "libavutil/avassert.h"
25+#include "h264dec.h"
26+#include "h264data.h"
27+#include "h264_ps.h"
28+#include "mpegutils.h"
29+#include "dxva2_internal.h"
30+#include "d3d12va_decode.h"
31+#include "libavutil/hwcontext_d3d12va_internal.h"
32+#include <dxva.h>
33+
34+typedef struct H264DecodePictureContext {
35+ DXVA_PicParams_H264 pp;
36+ DXVA_Qmatrix_H264 qm;
37+ unsigned slice_count;
38+ DXVA_Slice_H264_Short slice_short[MAX_SLICES];
39+ const uint8_t *bitstream;
40+ unsigned bitstream_size;
41+} H264DecodePictureContext;
42+
43+static void fill_slice_short(DXVA_Slice_H264_Short *slice,
44+ unsigned position, unsigned size)
45+{
46+ memset(slice, 0, sizeof(*slice));
47+ slice->BSNALunitDataLocation = position;
48+ slice->SliceBytesInBuffer = size;
49+ slice->wBadSliceChopping = 0;
50+}
51+
52+static int d3d12va_h264_start_frame(AVCodecContext *avctx,
53+ av_unused const uint8_t *buffer,
54+ av_unused uint32_t size)
55+{
56+ const H264Context *h = avctx->priv_data;
57+ H264DecodePictureContext *ctx_pic = h->cur_pic_ptr->hwaccel_picture_private;
58+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
59+
60+ if (!ctx)
61+ return -1;
62+
63+ assert(ctx_pic);
64+
65+ ctx->used_mask = 0;
66+
67+ ff_dxva2_h264_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, &ctx_pic->pp);
68+
69+ ff_dxva2_h264_fill_scaling_lists(avctx, (AVDXVAContext *)ctx, &ctx_pic->qm);
70+
71+ ctx_pic->slice_count = 0;
72+ ctx_pic->bitstream_size = 0;
73+ ctx_pic->bitstream = NULL;
74+
75+ return 0;
76+}
77+
78+static int d3d12va_h264_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
79+{
80+ unsigned position;
81+ const H264Context *h = avctx->priv_data;
82+ const H264SliceContext *sl = &h->slice_ctx[0];
83+ const H264Picture *current_picture = h->cur_pic_ptr;
84+ H264DecodePictureContext *ctx_pic = current_picture->hwaccel_picture_private;
85+
86+ if (ctx_pic->slice_count >= MAX_SLICES)
87+ return AVERROR(ERANGE);
88+
89+ if (!ctx_pic->bitstream)
90+ ctx_pic->bitstream = buffer;
91+ ctx_pic->bitstream_size += size;
92+
93+ position = buffer - ctx_pic->bitstream;
94+ fill_slice_short(&ctx_pic->slice_short[ctx_pic->slice_count], position, size);
95+ ctx_pic->slice_count++;
96+
97+ if (sl->slice_type != AV_PICTURE_TYPE_I && sl->slice_type != AV_PICTURE_TYPE_SI)
98+ ctx_pic->pp.wBitFields &= ~(1 << 15); /* Set IntraPicFlag to 0 */
99+
100+ return 0;
101+}
102+
103+#define START_CODE 65536
104+#define START_CODE_SIZE 3
105+static int update_input_arguments(AVCodecContext *avctx, D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
106+{
107+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
108+ AVHWFramesContext *frames_ctx = D3D12VA_FRAMES_CONTEXT(avctx);
109+ AVD3D12VAFramesContext *frames_hwctx = frames_ctx->hwctx;
110+
111+ const H264Context *h = avctx->priv_data;
112+ const H264Picture *current_picture = h->cur_pic_ptr;
113+ H264DecodePictureContext *ctx_pic = current_picture->hwaccel_picture_private;
114+
115+ int i;
116+ uint8_t *mapped_data, *mapped_ptr;
117+ DXVA_Slice_H264_Short *slice;
118+ D3D12_VIDEO_DECODE_FRAME_ARGUMENT *args;
119+
120+ if (FAILED(ID3D12Resource_Map(buffer, 0, NULL, &mapped_data))) {
121+ av_log(avctx, AV_LOG_ERROR, "Failed to map D3D12 Buffer resource!\n");
122+ return AVERROR(EINVAL);
123+ }
124+
125+ mapped_ptr = mapped_data;
126+ for (i = 0; i < ctx_pic->slice_count; i++) {
127+ UINT position, size;
128+ slice = &ctx_pic->slice_short[i];
129+
130+ position = slice->BSNALunitDataLocation;
131+ size = slice->SliceBytesInBuffer;
132+
133+ slice->SliceBytesInBuffer += START_CODE_SIZE;
134+ slice->BSNALunitDataLocation = mapped_ptr - mapped_data;
135+
136+ *(uint32_t *)mapped_ptr = START_CODE;
137+ mapped_ptr += START_CODE_SIZE;
138+
139+ memcpy(mapped_ptr, &ctx_pic->bitstream[position], size);
140+ mapped_ptr += size;
141+ }
142+
143+ ID3D12Resource_Unmap(buffer, 0, NULL);
144+
145+ input_args->CompressedBitstream = (D3D12_VIDEO_DECODE_COMPRESSED_BITSTREAM){
146+ .pBuffer = buffer,
147+ .Offset = 0,
148+ .Size = mapped_ptr - mapped_data,
149+ };
150+
151+ args = &input_args->FrameArguments[input_args->NumFrameArguments++];
152+ args->Type = D3D12_VIDEO_DECODE_ARGUMENT_TYPE_SLICE_CONTROL;
153+ args->Size = sizeof(DXVA_Slice_H264_Short) * ctx_pic->slice_count;
154+ args->pData = ctx_pic->slice_short;
155+
156+ return 0;
157+}
158+
159+static int d3d12va_h264_end_frame(AVCodecContext *avctx)
160+{
161+ H264Context *h = avctx->priv_data;
162+ H264DecodePictureContext *ctx_pic = h->cur_pic_ptr->hwaccel_picture_private;
163+ H264SliceContext *sl = &h->slice_ctx[0];
164+
165+ int ret;
166+
167+ if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
168+ return -1;
169+
170+ ret = ff_d3d12va_common_end_frame(avctx, h->cur_pic_ptr->f,
171+ &ctx_pic->pp, sizeof(ctx_pic->pp),
172+ &ctx_pic->qm, sizeof(ctx_pic->qm),
173+ update_input_arguments);
174+ if (!ret)
175+ ff_h264_draw_horiz_band(h, sl, 0, h->avctx->height);
176+
177+ return ret;
178+}
179+
180+static int d3d12va_h264_decode_init(AVCodecContext *avctx)
181+{
182+ D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
183+ DXVA_PicParams_H264 pp;
184+
185+ ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_H264;
186+
187+ ctx->max_num_ref = FF_ARRAY_ELEMS(pp.RefFrameList) + 1;
188+
189+ return ff_d3d12va_decode_init(avctx);
190+}
191+
192+#if CONFIG_H264_D3D12VA_HWACCEL
193+const FFHWAccel ff_h264_d3d12va_hwaccel = {
194+ .p.name = "h264_d3d12va",
195+ .p.type = AVMEDIA_TYPE_VIDEO,
196+ .p.id = AV_CODEC_ID_H264,
197+ .p.pix_fmt = AV_PIX_FMT_D3D12,
198+ .init = d3d12va_h264_decode_init,
199+ .uninit = ff_d3d12va_decode_uninit,
200+ .start_frame = d3d12va_h264_start_frame,
201+ .decode_slice = d3d12va_h264_decode_slice,
202+ .end_frame = d3d12va_h264_end_frame,
203+ .frame_params = ff_d3d12va_common_frame_params,
204+ .frame_priv_data_size = sizeof(H264DecodePictureContext),
205+ .priv_data_size = sizeof(D3D12VADecodeContext),
206+};
207+#endif
libavcodec/dxva2.c+27−2
@@ -768,12 +768,17 @@ static void *get_surface(const AVCodecContext *avctx, const AVFrame *frame) · 767 unmodified lines
768768 }
769769
770770 unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
771− const AVDXVAContext *ctx,
772− const AVFrame *frame)
771+ AVDXVAContext *ctx, const AVFrame *frame,
772+ int curr)
773773 {
774774 void *surface = get_surface(avctx, frame);
775775 unsigned i;
776776
777+#if CONFIG_D3D12VA
778+ if (avctx->pix_fmt == AV_PIX_FMT_D3D12) {
779+ return ff_d3d12va_get_surface_index(avctx, (D3D12VADecodeContext *)ctx, frame, curr);
780+ }
781+#endif
777782 #if CONFIG_D3D11VA
778783 if (avctx->pix_fmt == AV_PIX_FMT_D3D11)
779784 return (intptr_t)frame->data[1];
@@ -1056,3 +1061,23 @@ int ff_dxva2_is_d3d11(const AVCodecContext *avctx) · 276 unmodified lines
10561061 else
10571062 return 0;
10581063 }
1064+
1065+unsigned *ff_dxva2_get_report_id(const AVCodecContext *avctx, AVDXVAContext *ctx)
1066+{
1067+ unsigned *report_id = NULL;
1068+
1069+#if CONFIG_D3D12VA
1070+ if (avctx->pix_fmt == AV_PIX_FMT_D3D12)
1071+ report_id = &ctx->d3d12va.report_id;
1072+#endif
1073+#if CONFIG_D3D11VA
1074+ if (ff_dxva2_is_d3d11(avctx))
1075+ report_id = &ctx->d3d11va.report_id;
1076+#endif
1077+#if CONFIG_DXVA2
1078+ if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
1079+ report_id = &ctx->dxva2.report_id;
1080+#endif
1081+
1082+ return report_id;
1083+}
libavcodec/dxva2.h+0−3
@@ -45,9 +45,6 @@ · 44 unmodified lines
4545 * @{
4646 */
4747
48−#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for DXVA2 and old UVD/UVD+ ATI video cards
49−#define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO 2 ///< Work around for DXVA2 and old Intel GPUs with ClearVideo interface
50−
5148 /**
5249 * This structure is used to provides the necessary configurations and data
5350 * to the DXVA2 FFmpeg HWAccel implementation.
libavcodec/dxva2_av1.c+2−2
@@ -75,7 +75,7 @@ static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c · 74 unmodified lines
7575 pp->max_width = seq->max_frame_width_minus_1 + 1;
7676 pp->max_height = seq->max_frame_height_minus_1 + 1;
7777
78− pp->CurrPicTextureIndex = ff_dxva2_get_surface_index(avctx, ctx, h->cur_frame.f);
78+ pp->CurrPicTextureIndex = ff_dxva2_get_surface_index(avctx, ctx, h->cur_frame.f, 1);
7979 pp->superres_denom = frame_header->use_superres ? frame_header->coded_denom + AV1_SUPERRES_DENOM_MIN : AV1_SUPERRES_NUM;
8080 pp->bitdepth = get_bit_depth_from_seq(seq);
8181 pp->seq_profile = seq->seq_profile;
@@ -151,7 +151,7 @@ static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c · 69 unmodified lines
151151 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
152152 AVFrame *ref_frame = h->ref[i].f;
153153 if (ref_frame->buf[0])
154− pp->RefFrameMapTextureIndex[i] = ff_dxva2_get_surface_index(avctx, ctx, ref_frame);
154+ pp->RefFrameMapTextureIndex[i] = ff_dxva2_get_surface_index(avctx, ctx, ref_frame, 0);
155155 }
156156
157157 /* Loop filter parameters */
libavcodec/dxva2_h264.c+14−12
@@ -48,19 +48,16 @@ static void fill_picture_entry(DXVA_PicEntry_H264 *pic, · 47 unmodified lines
4848 pic->bPicEntry = index | (flag << 7);
4949 }
5050
51−static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, const H264Context *h,
51+void ff_dxva2_h264_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx,
5252 DXVA_PicParams_H264 *pp)
5353 {
54+ const H264Context *h = avctx->priv_data;
5455 const H264Picture *current_picture = h->cur_pic_ptr;
5556 const SPS *sps = h->ps.sps;
5657 const PPS *pps = h->ps.pps;
5758 int i, j;
5859
5960 memset(pp, 0, sizeof(*pp));
60− /* Configure current picture */
61− fill_picture_entry(&pp->CurrPic,
62− ff_dxva2_get_surface_index(avctx, ctx, current_picture->f),
63− h->picture_structure == PICT_BOTTOM_FIELD);
6461 /* Configure the set of references */
6562 pp->UsedForReferenceFlags = 0;
6663 pp->NonExistingFrameFlags = 0;
@@ -75,7 +72,7 @@ static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext * · 8 unmodified lines
7572 }
7673 if (r) {
7774 fill_picture_entry(&pp->RefFrameList[i],
78− ff_dxva2_get_surface_index(avctx, ctx, r->f),
75+ ff_dxva2_get_surface_index(avctx, ctx, r->f, 0),
7976 r->long_ref != 0);
8077
8178 if ((r->reference & PICT_TOP_FIELD) && r->field_poc[0] != INT_MAX)
@@ -95,6 +92,10 @@ static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext * · 13 unmodified lines
9592 pp->FrameNumList[i] = 0;
9693 }
9794 }
95+ /* Configure current picture */
96+ fill_picture_entry(&pp->CurrPic,
97+ ff_dxva2_get_surface_index(avctx, ctx, current_picture->f, 1),
98+ h->picture_structure == PICT_BOTTOM_FIELD);
9899
99100 pp->wFrameWidthInMbsMinus1 = h->mb_width - 1;
100101 pp->wFrameHeightInMbsMinus1 = h->mb_height - 1;
@@ -164,9 +165,10 @@ static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext * · 63 unmodified lines
164165 //pp->SliceGroupMap[810]; /* XXX not implemented by FFmpeg */
165166 }
166167
167−static void fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, const H264Context *h, DXVA_Qmatrix_H264 *qm)
168+void ff_dxva2_h264_fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_Qmatrix_H264 *qm)
168169 {
169− const PPS *pps = h->ps.pps;
170+ const H264Context *h = avctx->priv_data;
171+ const PPS *pps = h->ps.pps;
170172 unsigned i, j;
171173 memset(qm, 0, sizeof(*qm));
172174 if (DXVA_CONTEXT_WORKAROUND(avctx, ctx) & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG) {
@@ -253,9 +255,9 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, · 80 unmodified lines
253255 unsigned plane;
254256 unsigned index;
255257 if (DXVA_CONTEXT_WORKAROUND(avctx, ctx) & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO)
256− index = ff_dxva2_get_surface_index(avctx, ctx, r->f);
258+ index = ff_dxva2_get_surface_index(avctx, ctx, r->f, 0);
257259 else
258− index = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, r->f));
260+ index = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, r->f, 0));
259261 fill_picture_entry(&slice->RefPicList[list][i], index,
260262 sl->ref_list[list][i].reference == PICT_BOTTOM_FIELD);
261263 for (plane = 0; plane < 3; plane++) {
@@ -454,10 +456,10 @@ static int dxva2_h264_start_frame(AVCodecContext *avctx, · 192 unmodified lines
454456 assert(ctx_pic);
455457
456458 /* Fill up DXVA_PicParams_H264 */
457− fill_picture_parameters(avctx, ctx, h, &ctx_pic->pp);
459+ ff_dxva2_h264_fill_picture_parameters(avctx, ctx, &ctx_pic->pp);
458460
459461 /* Fill up DXVA_Qmatrix_H264 */
460− fill_scaling_lists(avctx, ctx, h, &ctx_pic->qm);
462+ ff_dxva2_h264_fill_scaling_lists(avctx, ctx, &ctx_pic->qm);
461463
462464 ctx_pic->slice_count = 0;
463465 ctx_pic->bitstream_size = 0;
libavcodec/dxva2_hevc.c+3−3
@@ -79,7 +79,7 @@ static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext * · 78 unmodified lines
7979 (0 << 14) |
8080 (0 << 15);
8181
82− fill_picture_entry(&pp->CurrPic, ff_dxva2_get_surface_index(avctx, ctx, current_picture->frame), 0);
82+ fill_picture_entry(&pp->CurrPic, ff_dxva2_get_surface_index(avctx, ctx, current_picture->frame, 1), 0);
8383
8484 pp->sps_max_dec_pic_buffering_minus1 = sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
8585 pp->log2_min_luma_coding_block_size_minus3 = sps->log2_min_cb_size - 3;
@@ -171,7 +171,7 @@ static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext * · 85 unmodified lines
171171 }
172172
173173 if (frame) {
174− fill_picture_entry(&pp->RefPicList[i], ff_dxva2_get_surface_index(avctx, ctx, frame->frame), !!(frame->flags & HEVC_FRAME_FLAG_LONG_REF));
174+ fill_picture_entry(&pp->RefPicList[i], ff_dxva2_get_surface_index(avctx, ctx, frame->frame, 0), !!(frame->flags & HEVC_FRAME_FLAG_LONG_REF));
175175 pp->PicOrderCntValList[i] = frame->poc;
176176 } else {
177177 pp->RefPicList[i].bPicEntry = 0xff;
@@ -186,7 +186,7 @@ static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext * · 8 unmodified lines
186186 while (!frame && j < rpl->nb_refs) \
187187 frame = rpl->ref[j++]; \
188188 if (frame && frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF)) \
189− pp->ref_list[i] = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, frame->frame)); \
189+ pp->ref_list[i] = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, frame->frame, 0)); \
190190 else \
191191 pp->ref_list[i] = 0xff; \
192192 } \
libavcodec/dxva2_internal.h+42−32
@@ -26,18 +26,34 @@ · 25 unmodified lines
2626 #define COBJMACROS
2727
2828 #include "config.h"
29+#include "config_components.h"
2930
3031 /* define the proper COM entries before forcing desktop APIs */
3132 #include <objbase.h>
3233
34+#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for DXVA2/Direct3D11 and old UVD/UVD+ ATI video cards
35+#define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO 2 ///< Work around for DXVA2/Direct3D11 and old Intel GPUs with ClearVideo interface
36+
3337 #if CONFIG_DXVA2
3438 #include "dxva2.h"
3539 #include "libavutil/hwcontext_dxva2.h"
40+#define DXVA2_VAR(ctx, var) ctx->dxva2.var
41+#else
42+#define DXVA2_VAR(ctx, var) 0
3643 #endif
44+
3745 #if CONFIG_D3D11VA
3846 #include "d3d11va.h"
3947 #include "libavutil/hwcontext_d3d11va.h"
48+#define D3D11VA_VAR(ctx, var) ctx->d3d11va.var
49+#else
50+#define D3D11VA_VAR(ctx, var) 0
51+#endif
52+
53+#if CONFIG_D3D12VA
54+#include "d3d12va_decode.h"
4055 #endif
56+
4157 #if HAVE_DXVA_H
4258 /* When targeting WINAPI_FAMILY_PHONE_APP or WINAPI_FAMILY_APP, dxva.h
4359 * defines nothing. Force the struct definitions to be visible. */
@@ -62,6 +78,9 @@ typedef union { · 18 unmodified lines
6278 #if CONFIG_DXVA2
6379 struct dxva_context dxva2;
6480 #endif
81+#if CONFIG_D3D12VA
82+ struct D3D12VADecodeContext d3d12va;
83+#endif
6584 } AVDXVAContext;
6685
6786 typedef struct FFDXVASharedContext {
@@ -101,43 +120,28 @@ typedef struct FFDXVASharedContext { · 33 unmodified lines
101120 #define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va)
102121 #define DXVA2_CONTEXT(ctx) (&ctx->dxva2)
103122
104−#if CONFIG_D3D11VA && CONFIG_DXVA2
105−#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.workaround : ctx->dxva2.workaround)
106−#define DXVA_CONTEXT_COUNT(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.surface_count : ctx->dxva2.surface_count)
107−#define DXVA_CONTEXT_DECODER(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? (void *)ctx->d3d11va.decoder : (void *)ctx->dxva2.decoder)
108−#define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(ff_dxva2_is_d3d11(avctx) ? &ctx->d3d11va.report_id : &ctx->dxva2.report_id))
109−#define DXVA_CONTEXT_CFG(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? (void *)ctx->d3d11va.cfg : (void *)ctx->dxva2.cfg)
110−#define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigBitstreamRaw : ctx->dxva2.cfg->ConfigBitstreamRaw)
111−#define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigIntraResidUnsigned : ctx->dxva2.cfg->ConfigIntraResidUnsigned)
112−#define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigResidDiffAccelerator : ctx->dxva2.cfg->ConfigResidDiffAccelerator)
123+#define DXVA2_CONTEXT_VAR(avctx, ctx, var) (avctx->pix_fmt == AV_PIX_FMT_D3D12 ? 0 : (ff_dxva2_is_d3d11(avctx) ? D3D11VA_VAR(ctx, var) : DXVA2_VAR(ctx, var)))
124+
125+#define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*ff_dxva2_get_report_id(avctx, ctx))
126+#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, workaround)
127+#define DXVA_CONTEXT_COUNT(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, surface_count)
128+#define DXVA_CONTEXT_DECODER(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D12 ? 0 : (ff_dxva2_is_d3d11(avctx) ? (void *)D3D11VA_VAR(ctx, decoder) : (void *)DXVA2_VAR(ctx, decoder)))
129+#define DXVA_CONTEXT_CFG(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D12 ? 0 : (ff_dxva2_is_d3d11(avctx) ? (void *)D3D11VA_VAR(ctx, cfg) : (void *)DXVA2_VAR(ctx, cfg)))
130+#define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, cfg->ConfigBitstreamRaw)
131+#define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, cfg->ConfigIntraResidUnsigned)
132+#define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, cfg->ConfigResidDiffAccelerator)
113133 #define DXVA_CONTEXT_VALID(avctx, ctx) (DXVA_CONTEXT_DECODER(avctx, ctx) && \
114134 DXVA_CONTEXT_CFG(avctx, ctx) && \
115− (ff_dxva2_is_d3d11(avctx) || ctx->dxva2.surface_count))
116−#elif CONFIG_DXVA2
117−#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ctx->dxva2.workaround)
118−#define DXVA_CONTEXT_COUNT(avctx, ctx) (ctx->dxva2.surface_count)
119−#define DXVA_CONTEXT_DECODER(avctx, ctx) (ctx->dxva2.decoder)
120−#define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(&ctx->dxva2.report_id))
121−#define DXVA_CONTEXT_CFG(avctx, ctx) (ctx->dxva2.cfg)
122−#define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) (ctx->dxva2.cfg->ConfigBitstreamRaw)
123−#define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ctx->dxva2.cfg->ConfigIntraResidUnsigned)
124−#define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ctx->dxva2.cfg->ConfigResidDiffAccelerator)
125−#define DXVA_CONTEXT_VALID(avctx, ctx) (ctx->dxva2.decoder && ctx->dxva2.cfg && ctx->dxva2.surface_count)
126−#elif CONFIG_D3D11VA
127−#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ctx->d3d11va.workaround)
128−#define DXVA_CONTEXT_COUNT(avctx, ctx) (ctx->d3d11va.surface_count)
129−#define DXVA_CONTEXT_DECODER(avctx, ctx) (ctx->d3d11va.decoder)
130−#define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(&ctx->d3d11va.report_id))
131−#define DXVA_CONTEXT_CFG(avctx, ctx) (ctx->d3d11va.cfg)
132−#define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) (ctx->d3d11va.cfg->ConfigBitstreamRaw)
133−#define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ctx->d3d11va.cfg->ConfigIntraResidUnsigned)
134−#define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ctx->d3d11va.cfg->ConfigResidDiffAccelerator)
135−#define DXVA_CONTEXT_VALID(avctx, ctx) (ctx->d3d11va.decoder && ctx->d3d11va.cfg)
135+ (ff_dxva2_is_d3d11(avctx) || DXVA2_VAR(ctx, surface_count)))
136+
137+#if CONFIG_D3D12VA
138+unsigned ff_d3d12va_get_surface_index(const AVCodecContext *avctx,
139+ D3D12VADecodeContext *ctx, const AVFrame *frame,
140+ int curr);
136141 #endif
137142
138143 unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
139− const AVDXVAContext *,
140− const AVFrame *frame);
144+ AVDXVAContext *, const AVFrame *frame, int curr);
141145
142146 int ff_dxva2_commit_buffer(AVCodecContext *, AVDXVAContext *,
143147 DECODER_BUFFER_DESC *,
@@ -161,4 +165,10 @@ int ff_dxva2_common_frame_params(AVCodecContext *avctx, · 17 unmodified lines
161165
162166 int ff_dxva2_is_d3d11(const AVCodecContext *avctx);
163167
168+unsigned *ff_dxva2_get_report_id(const AVCodecContext *avctx, AVDXVAContext *ctx);
169+
170+void ff_dxva2_h264_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PicParams_H264 *pp);
171+
172+void ff_dxva2_h264_fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_Qmatrix_H264 *qm);
173+
164174 #endif /* AVCODEC_DXVA2_INTERNAL_H */
libavcodec/dxva2_mpeg2.c+3−3
@@ -49,14 +49,14 @@ static void fill_picture_parameters(AVCodecContext *avctx, · 48 unmodified lines
4949 int is_field = s->picture_structure != PICT_FRAME;
5050
5151 memset(pp, 0, sizeof(*pp));
52− pp->wDecodedPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, current_picture->f);
52+ pp->wDecodedPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, current_picture->f, 1);
5353 pp->wDeblockedPictureIndex = 0;
5454 if (s->pict_type != AV_PICTURE_TYPE_I)
55− pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_picture.f);
55+ pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_picture.f, 0);
5656 else
5757 pp->wForwardRefPictureIndex = 0xffff;
5858 if (s->pict_type == AV_PICTURE_TYPE_B)
59− pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_picture.f);
59+ pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_picture.f, 0);
6060 else
6161 pp->wBackwardRefPictureIndex = 0xffff;
6262 pp->wPicWidthInMBminus1 = s->mb_width - 1;
libavcodec/dxva2_vc1.c+3−3
@@ -58,13 +58,13 @@ static void fill_picture_parameters(AVCodecContext *avctx, · 57 unmodified lines
5858
5959 memset(pp, 0, sizeof(*pp));
6060 pp->wDecodedPictureIndex =
61− pp->wDeblockedPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, current_picture->f);
61+ pp->wDeblockedPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, current_picture->f, 1);
6262 if (s->pict_type != AV_PICTURE_TYPE_I && !v->bi_type)
63− pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_picture.f);
63+ pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_picture.f, 0);
6464 else
6565 pp->wForwardRefPictureIndex = 0xffff;
6666 if (s->pict_type == AV_PICTURE_TYPE_B && !v->bi_type)
67− pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_picture.f);
67+ pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_picture.f, 0);
6868 else
6969 pp->wBackwardRefPictureIndex = 0xffff;
7070 if (v->profile == PROFILE_ADVANCED) {
libavcodec/dxva2_vp9.c+3−3
@@ -54,7 +54,7 @@ static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c · 53 unmodified lines
5454
5555 memset(pp, 0, sizeof(*pp));
5656
57− fill_picture_entry(&pp->CurrPic, ff_dxva2_get_surface_index(avctx, ctx, h->frames[CUR_FRAME].tf.f), 0);
57+ fill_picture_entry(&pp->CurrPic, ff_dxva2_get_surface_index(avctx, ctx, h->frames[CUR_FRAME].tf.f, 1), 0);
5858
5959 pp->profile = h->h.profile;
6060 pp->wFormatAndPictureInfoFlags = ((h->h.keyframe == 0) << 0) |
@@ -81,7 +81,7 @@ static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c · 20 unmodified lines
8181
8282 for (i = 0; i < 8; i++) {
8383 if (h->refs[i].f->buf[0]) {
84− fill_picture_entry(&pp->ref_frame_map[i], ff_dxva2_get_surface_index(avctx, ctx, h->refs[i].f), 0);
84+ fill_picture_entry(&pp->ref_frame_map[i], ff_dxva2_get_surface_index(avctx, ctx, h->refs[i].f, 0), 0);
8585 pp->ref_frame_coded_width[i] = h->refs[i].f->width;
8686 pp->ref_frame_coded_height[i] = h->refs[i].f->height;
8787 } else
@@ -91,7 +91,7 @@ static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c · 3 unmodified lines
9191 for (i = 0; i < 3; i++) {
9292 uint8_t refidx = h->h.refidx[i];
9393 if (h->refs[refidx].f->buf[0])
94− fill_picture_entry(&pp->frame_refs[i], ff_dxva2_get_surface_index(avctx, ctx, h->refs[refidx].f), 0);
94+ fill_picture_entry(&pp->frame_refs[i], ff_dxva2_get_surface_index(avctx, ctx, h->refs[refidx].f, 0), 0);
9595 else
9696 pp->frame_refs[i].bPicEntry = 0xFF;
9797
libavcodec/h264_slice.c+4−0
@@ -784,6 +784,7 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) · 783 unmodified lines
784784 {
785785 #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
786786 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
787+ CONFIG_H264_D3D12VA_HWACCEL + \
787788 CONFIG_H264_NVDEC_HWACCEL + \
788789 CONFIG_H264_VAAPI_HWACCEL + \
789790 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
@@ -887,6 +888,9 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) · 97 unmodified lines
887888 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
888889 *fmt++ = AV_PIX_FMT_D3D11;
889890 #endif
891+#if CONFIG_H264_D3D12VA_HWACCEL
892+ *fmt++ = AV_PIX_FMT_D3D12;
893+#endif
890894 #if CONFIG_H264_VAAPI_HWACCEL
891895 *fmt++ = AV_PIX_FMT_VAAPI;
892896 #endif
libavcodec/h264dec.c+3−0
@@ -1131,6 +1131,9 @@ const FFCodec ff_h264_decoder = { · 1130 unmodified lines
11311131 #if CONFIG_H264_D3D11VA2_HWACCEL
11321132 HWACCEL_D3D11VA2(h264),
11331133 #endif
1134+#if CONFIG_H264_D3D12VA_HWACCEL
1135+ HWACCEL_D3D12VA(h264),
1136+#endif
11341137 #if CONFIG_H264_NVDEC_HWACCEL
11351138 HWACCEL_NVDEC(h264),
11361139 #endif
libavcodec/hwaccels.h+1−0
@@ -30,6 +30,7 @@ extern const struct FFHWAccel ff_h263_vaapi_hwaccel; · 29 unmodified lines
3030 extern const struct FFHWAccel ff_h263_videotoolbox_hwaccel;
3131 extern const struct FFHWAccel ff_h264_d3d11va_hwaccel;
3232 extern const struct FFHWAccel ff_h264_d3d11va2_hwaccel;
33+extern const struct FFHWAccel ff_h264_d3d12va_hwaccel;
3334 extern const struct FFHWAccel ff_h264_dxva2_hwaccel;
3435 extern const struct FFHWAccel ff_h264_nvdec_hwaccel;
3536 extern const struct FFHWAccel ff_h264_vaapi_hwaccel;
libavcodec/hwconfig.h+2−0
@@ -77,6 +77,8 @@ void ff_hwaccel_uninit(AVCodecContext *avctx); · 76 unmodified lines
7777 HW_CONFIG_HWACCEL(1, 1, 1, VULKAN, VULKAN, ff_ ## codec ## _vulkan_hwaccel)
7878 #define HWACCEL_D3D11VA(codec) \
7979 HW_CONFIG_HWACCEL(0, 0, 1, D3D11VA_VLD, NONE, ff_ ## codec ## _d3d11va_hwaccel)
80+#define HWACCEL_D3D12VA(codec) \
81+ HW_CONFIG_HWACCEL(1, 1, 0, D3D12, D3D12VA, ff_ ## codec ## _d3d12va_hwaccel)
8082
8183 #define HW_CONFIG_ENCODER(device, frames, ad_hoc, format, device_type_) \
8284 &(const AVCodecHWConfigInternal) { \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t