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

Unified · Split

19 files
  1. configure +2 −0
  2. libavcodec/Makefile +3 −0
  3. libavcodec/d3d11va.h +0 −3
  4. libavcodec/d3d12va_decode.c +538 −0
  5. libavcodec/d3d12va_decode.h +179 −0
  6. libavcodec/d3d12va_h264.c +207 −0
  7. libavcodec/dxva2.c +27 −2
  8. libavcodec/dxva2.h +0 −3
  9. libavcodec/dxva2_av1.c +2 −2
  10. libavcodec/dxva2_h264.c +14 −12
  11. libavcodec/dxva2_hevc.c +3 −3
  12. libavcodec/dxva2_internal.h +42 −32
  13. libavcodec/dxva2_mpeg2.c +3 −3
  14. libavcodec/dxva2_vc1.c +3 −3
  15. libavcodec/dxva2_vp9.c +3 −3
  16. libavcodec/h264_slice.c +4 −0
  17. libavcodec/h264dec.c +3 −0
  18. libavcodec/hwaccels.h +1 −0
  19. libavcodec/hwconfig.h +2 −0
configure+2−0
@@ -3084,6 +3084,8 @@ h264_d3d11va_hwaccel_deps="d3d11va" · 3083 unmodified lines
3084h264_d3d11va_hwaccel_select="h264_decoder"3084h264_d3d11va_hwaccel_select="h264_decoder"
3085h264_d3d11va2_hwaccel_deps="d3d11va"3085h264_d3d11va2_hwaccel_deps="d3d11va"
3086h264_d3d11va2_hwaccel_select="h264_decoder"3086h264_d3d11va2_hwaccel_select="h264_decoder"
3087h264_d3d12va_hwaccel_deps="d3d12va"
3088h264_d3d12va_hwaccel_select="h264_decoder"
3087h264_dxva2_hwaccel_deps="dxva2"3089h264_dxva2_hwaccel_deps="dxva2"
3088h264_dxva2_hwaccel_select="h264_decoder"3090h264_dxva2_hwaccel_select="h264_decoder"
3089h264_nvdec_hwaccel_deps="nvdec"3091h264_nvdec_hwaccel_deps="nvdec"
libavcodec/Makefile+3−0
@@ -986,6 +986,7 @@ OBJS-$(CONFIG_ADPCM_ZORK_DECODER) += adpcm.o adpcm_data.o · 985 unmodified lines
986 986
987# hardware accelerators987# hardware accelerators
988OBJS-$(CONFIG_D3D11VA) += dxva2.o988OBJS-$(CONFIG_D3D11VA) += dxva2.o
989OBJS-$(CONFIG_D3D12VA) += dxva2.o d3d12va_decode.o
989OBJS-$(CONFIG_DXVA2) += dxva2.o990OBJS-$(CONFIG_DXVA2) += dxva2.o
990OBJS-$(CONFIG_NVDEC) += nvdec.o991OBJS-$(CONFIG_NVDEC) += nvdec.o
991OBJS-$(CONFIG_VAAPI) += vaapi_decode.o992OBJS-$(CONFIG_VAAPI) += vaapi_decode.o
@@ -1003,6 +1004,7 @@ OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o · 11 unmodified lines
1003OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o1004OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
1004OBJS-$(CONFIG_H264_D3D11VA_HWACCEL) += dxva2_h264.o1005OBJS-$(CONFIG_H264_D3D11VA_HWACCEL) += dxva2_h264.o
1005OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o1006OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o
1007OBJS-$(CONFIG_H264_D3D12VA_HWACCEL) += dxva2_h264.o d3d12va_h264.o
1006OBJS-$(CONFIG_H264_NVDEC_HWACCEL) += nvdec_h264.o1008OBJS-$(CONFIG_H264_NVDEC_HWACCEL) += nvdec_h264.o
1007OBJS-$(CONFIG_H264_QSV_HWACCEL) += qsvdec.o1009OBJS-$(CONFIG_H264_QSV_HWACCEL) += qsvdec.o
1008OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o1010OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o
@@ -1296,6 +1298,7 @@ SKIPHEADERS += %_tablegen.h \ · 287 unmodified lines
1296 1298
1297SKIPHEADERS-$(CONFIG_AMF) += amfenc.h1299SKIPHEADERS-$(CONFIG_AMF) += amfenc.h
1298SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h1300SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h
1301SKIPHEADERS-$(CONFIG_D3D12VA) += d3d12va_decode.h
1299SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h1302SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h
1300SKIPHEADERS-$(CONFIG_JNI) += ffjni.h1303SKIPHEADERS-$(CONFIG_JNI) += ffjni.h
1301SKIPHEADERS-$(CONFIG_LCMS2) += fflcms2.h1304SKIPHEADERS-$(CONFIG_LCMS2) += fflcms2.h
libavcodec/d3d11va.h+0−3
@@ -45,9 +45,6 @@ · 44 unmodified lines
45 * @{45 * @{
46 */46 */
47 47
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
51/**48/**
52 * This structure is used to provides the necessary configurations and data49 * This structure is used to provides the necessary configurations and data
53 * to the Direct3D11 FFmpeg HWAccel implementation.50 * 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
37typedef struct HelperObjects {
38 ID3D12CommandAllocator *command_allocator;
39 ID3D12Resource *buffer;
40 uint64_t fence_value;
41} HelperObjects;
42
43int 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
49unsigned 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
81fail:
82 assert(0);
83 return 0;
84}
85
86static 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
136static 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
156static 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
169static void bufref_free_interface(void *opaque, uint8_t *data)
170{
171 D3D12_OBJECT_RELEASE(opaque);
172}
173
174static AVBufferRef *bufref_wrap_interface(IUnknown *iface)
175{
176 return av_buffer_create((uint8_t*)iface, 1, bufref_free_interface, iface, 0);
177}
178
179static 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
186fail:
187 return AVERROR(EINVAL);
188}
189
190static 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
213fail:
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
222static 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
262fail:
263 return AVERROR(EINVAL);
264}
265
266int 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
279int 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
362fail:
363 D3D12_OBJECT_RELEASE(command_allocator);
364 D3D12_OBJECT_RELEASE(buffer);
365 ff_d3d12va_decode_uninit(avctx);
366
367 return AVERROR(EINVAL);
368}
369
370int 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
408static 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
432int 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
534fail:
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 */
37typedef 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 */
139int 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 */
146int ff_d3d12va_decode_init(AVCodecContext *avctx);
147
148/**
149 * @brief uninit D3D12VADecodeContext
150 *
151 * @return Error code (ret < 0 if failed)
152 */
153int ff_d3d12va_decode_uninit(AVCodecContext *avctx);
154
155/**
156 * @brief d3d12va common frame params
157 *
158 * @return Error code (ret < 0 if failed)
159 */
160int 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 */
174int 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
34typedef 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
43static 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
52static 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
78static 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
105static 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
159static 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
180static 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
193const 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
768}768}
769 769
770unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,770unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
771 const AVDXVAContext *ctx,771 AVDXVAContext *ctx, const AVFrame *frame,
772 const AVFrame *frame)772 int curr)
773{773{
774 void *surface = get_surface(avctx, frame);774 void *surface = get_surface(avctx, frame);
775 unsigned i;775 unsigned i;
776 776
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
777#if CONFIG_D3D11VA782#if CONFIG_D3D11VA
778 if (avctx->pix_fmt == AV_PIX_FMT_D3D11)783 if (avctx->pix_fmt == AV_PIX_FMT_D3D11)
779 return (intptr_t)frame->data[1];784 return (intptr_t)frame->data[1];
@@ -1056,3 +1061,23 @@ int ff_dxva2_is_d3d11(const AVCodecContext *avctx) · 276 unmodified lines
1056 else1061 else
1057 return 0;1062 return 0;
1058}1063}
1064
1065unsigned *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
45 * @{45 * @{
46 */46 */
47 47
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
51/**48/**
52 * This structure is used to provides the necessary configurations and data49 * This structure is used to provides the necessary configurations and data
53 * to the DXVA2 FFmpeg HWAccel implementation.50 * 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
75 pp->max_width = seq->max_frame_width_minus_1 + 1;75 pp->max_width = seq->max_frame_width_minus_1 + 1;
76 pp->max_height = seq->max_frame_height_minus_1 + 1;76 pp->max_height = seq->max_frame_height_minus_1 + 1;
77 77
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);
79 pp->superres_denom = frame_header->use_superres ? frame_header->coded_denom + AV1_SUPERRES_DENOM_MIN : AV1_SUPERRES_NUM;79 pp->superres_denom = frame_header->use_superres ? frame_header->coded_denom + AV1_SUPERRES_DENOM_MIN : AV1_SUPERRES_NUM;
80 pp->bitdepth = get_bit_depth_from_seq(seq);80 pp->bitdepth = get_bit_depth_from_seq(seq);
81 pp->seq_profile = seq->seq_profile;81 pp->seq_profile = seq->seq_profile;
@@ -151,7 +151,7 @@ static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c · 69 unmodified lines
151 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {151 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
152 AVFrame *ref_frame = h->ref[i].f;152 AVFrame *ref_frame = h->ref[i].f;
153 if (ref_frame->buf[0])153 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);
155 }155 }
156 156
157 /* Loop filter parameters */157 /* 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
48 pic->bPicEntry = index | (flag << 7);48 pic->bPicEntry = index | (flag << 7);
49}49}
50 50
51static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, const H264Context *h,51void ff_dxva2_h264_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx,
52 DXVA_PicParams_H264 *pp)52 DXVA_PicParams_H264 *pp)
53{53{
54 const H264Context *h = avctx->priv_data;
54 const H264Picture *current_picture = h->cur_pic_ptr;55 const H264Picture *current_picture = h->cur_pic_ptr;
55 const SPS *sps = h->ps.sps;56 const SPS *sps = h->ps.sps;
56 const PPS *pps = h->ps.pps;57 const PPS *pps = h->ps.pps;
57 int i, j;58 int i, j;
58 59
59 memset(pp, 0, sizeof(*pp));60 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);
64 /* Configure the set of references */61 /* Configure the set of references */
65 pp->UsedForReferenceFlags = 0;62 pp->UsedForReferenceFlags = 0;
66 pp->NonExistingFrameFlags = 0;63 pp->NonExistingFrameFlags = 0;
@@ -75,7 +72,7 @@ static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext * · 8 unmodified lines
75 }72 }
76 if (r) {73 if (r) {
77 fill_picture_entry(&pp->RefFrameList[i],74 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),
79 r->long_ref != 0);76 r->long_ref != 0);
80 77
81 if ((r->reference & PICT_TOP_FIELD) && r->field_poc[0] != INT_MAX)78 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
95 pp->FrameNumList[i] = 0;92 pp->FrameNumList[i] = 0;
96 }93 }
97 }94 }
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);
98 99
99 pp->wFrameWidthInMbsMinus1 = h->mb_width - 1;100 pp->wFrameWidthInMbsMinus1 = h->mb_width - 1;
100 pp->wFrameHeightInMbsMinus1 = h->mb_height - 1;101 pp->wFrameHeightInMbsMinus1 = h->mb_height - 1;
@@ -164,9 +165,10 @@ static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext * · 63 unmodified lines
164 //pp->SliceGroupMap[810]; /* XXX not implemented by FFmpeg */165 //pp->SliceGroupMap[810]; /* XXX not implemented by FFmpeg */
165}166}
166 167
167static void fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, const H264Context *h, DXVA_Qmatrix_H264 *qm)168void ff_dxva2_h264_fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_Qmatrix_H264 *qm)
168{169{
169 const PPS *pps = h->ps.pps;170 const H264Context *h = avctx->priv_data;
171 const PPS *pps = h->ps.pps;
170 unsigned i, j;172 unsigned i, j;
171 memset(qm, 0, sizeof(*qm));173 memset(qm, 0, sizeof(*qm));
172 if (DXVA_CONTEXT_WORKAROUND(avctx, ctx) & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG) {174 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
253 unsigned plane;255 unsigned plane;
254 unsigned index;256 unsigned index;
255 if (DXVA_CONTEXT_WORKAROUND(avctx, ctx) & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO)257 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);
257 else259 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));
259 fill_picture_entry(&slice->RefPicList[list][i], index,261 fill_picture_entry(&slice->RefPicList[list][i], index,
260 sl->ref_list[list][i].reference == PICT_BOTTOM_FIELD);262 sl->ref_list[list][i].reference == PICT_BOTTOM_FIELD);
261 for (plane = 0; plane < 3; plane++) {263 for (plane = 0; plane < 3; plane++) {
@@ -454,10 +456,10 @@ static int dxva2_h264_start_frame(AVCodecContext *avctx, · 192 unmodified lines
454 assert(ctx_pic);456 assert(ctx_pic);
455 457
456 /* Fill up DXVA_PicParams_H264 */458 /* 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);
458 460
459 /* Fill up DXVA_Qmatrix_H264 */461 /* 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);
461 463
462 ctx_pic->slice_count = 0;464 ctx_pic->slice_count = 0;
463 ctx_pic->bitstream_size = 0;465 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
79 (0 << 14) |79 (0 << 14) |
80 (0 << 15);80 (0 << 15);
81 81
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);
83 83
84 pp->sps_max_dec_pic_buffering_minus1 = sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering - 1;84 pp->sps_max_dec_pic_buffering_minus1 = sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
85 pp->log2_min_luma_coding_block_size_minus3 = sps->log2_min_cb_size - 3;85 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
171 }171 }
172 172
173 if (frame) {173 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));
175 pp->PicOrderCntValList[i] = frame->poc;175 pp->PicOrderCntValList[i] = frame->poc;
176 } else {176 } else {
177 pp->RefPicList[i].bPicEntry = 0xff;177 pp->RefPicList[i].bPicEntry = 0xff;
@@ -186,7 +186,7 @@ static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext * · 8 unmodified lines
186 while (!frame && j < rpl->nb_refs) \186 while (!frame && j < rpl->nb_refs) \
187 frame = rpl->ref[j++]; \187 frame = rpl->ref[j++]; \
188 if (frame && frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF)) \188 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)); \
190 else \190 else \
191 pp->ref_list[i] = 0xff; \191 pp->ref_list[i] = 0xff; \
192 } \192 } \
libavcodec/dxva2_internal.h+42−32
@@ -26,18 +26,34 @@ · 25 unmodified lines
26#define COBJMACROS26#define COBJMACROS
27 27
28#include "config.h"28#include "config.h"
29#include "config_components.h"
29 30
30/* define the proper COM entries before forcing desktop APIs */31/* define the proper COM entries before forcing desktop APIs */
31#include <objbase.h>32#include <objbase.h>
32 33
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
33#if CONFIG_DXVA237#if CONFIG_DXVA2
34#include "dxva2.h"38#include "dxva2.h"
35#include "libavutil/hwcontext_dxva2.h"39#include "libavutil/hwcontext_dxva2.h"
40#define DXVA2_VAR(ctx, var) ctx->dxva2.var
41#else
42#define DXVA2_VAR(ctx, var) 0
36#endif43#endif
44
37#if CONFIG_D3D11VA45#if CONFIG_D3D11VA
38#include "d3d11va.h"46#include "d3d11va.h"
39#include "libavutil/hwcontext_d3d11va.h"47#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"
40#endif55#endif
56
41#if HAVE_DXVA_H57#if HAVE_DXVA_H
42/* When targeting WINAPI_FAMILY_PHONE_APP or WINAPI_FAMILY_APP, dxva.h58/* When targeting WINAPI_FAMILY_PHONE_APP or WINAPI_FAMILY_APP, dxva.h
43 * defines nothing. Force the struct definitions to be visible. */59 * defines nothing. Force the struct definitions to be visible. */
@@ -62,6 +78,9 @@ typedef union { · 18 unmodified lines
62#if CONFIG_DXVA278#if CONFIG_DXVA2
63 struct dxva_context dxva2;79 struct dxva_context dxva2;
64#endif80#endif
81#if CONFIG_D3D12VA
82 struct D3D12VADecodeContext d3d12va;
83#endif
65} AVDXVAContext;84} AVDXVAContext;
66 85
67typedef struct FFDXVASharedContext {86typedef struct FFDXVASharedContext {
@@ -101,43 +120,28 @@ typedef struct FFDXVASharedContext { · 33 unmodified lines
101#define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va)120#define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va)
102#define DXVA2_CONTEXT(ctx) (&ctx->dxva2)121#define DXVA2_CONTEXT(ctx) (&ctx->dxva2)
103 122
104#if CONFIG_D3D11VA && CONFIG_DXVA2123#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)))
105#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.workaround : ctx->dxva2.workaround)124
106#define DXVA_CONTEXT_COUNT(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.surface_count : ctx->dxva2.surface_count)125#define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*ff_dxva2_get_report_id(avctx, ctx))
107#define DXVA_CONTEXT_DECODER(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? (void *)ctx->d3d11va.decoder : (void *)ctx->dxva2.decoder)126#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, workaround)
108#define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(ff_dxva2_is_d3d11(avctx) ? &ctx->d3d11va.report_id : &ctx->dxva2.report_id))127#define DXVA_CONTEXT_COUNT(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, surface_count)
109#define DXVA_CONTEXT_CFG(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? (void *)ctx->d3d11va.cfg : (void *)ctx->dxva2.cfg)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)))
110#define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigBitstreamRaw : ctx->dxva2.cfg->ConfigBitstreamRaw)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)))
111#define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigIntraResidUnsigned : ctx->dxva2.cfg->ConfigIntraResidUnsigned)130#define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, cfg->ConfigBitstreamRaw)
112#define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigResidDiffAccelerator : ctx->dxva2.cfg->ConfigResidDiffAccelerator)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)
113#define DXVA_CONTEXT_VALID(avctx, ctx) (DXVA_CONTEXT_DECODER(avctx, ctx) && \133#define DXVA_CONTEXT_VALID(avctx, ctx) (DXVA_CONTEXT_DECODER(avctx, ctx) && \
114 DXVA_CONTEXT_CFG(avctx, ctx) && \134 DXVA_CONTEXT_CFG(avctx, ctx) && \
115 (ff_dxva2_is_d3d11(avctx) || ctx->dxva2.surface_count))135 (ff_dxva2_is_d3d11(avctx) || DXVA2_VAR(ctx, surface_count)))
116#elif CONFIG_DXVA2136
117#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ctx->dxva2.workaround)137#if CONFIG_D3D12VA
118#define DXVA_CONTEXT_COUNT(avctx, ctx) (ctx->dxva2.surface_count)138unsigned ff_d3d12va_get_surface_index(const AVCodecContext *avctx,
119#define DXVA_CONTEXT_DECODER(avctx, ctx) (ctx->dxva2.decoder)139 D3D12VADecodeContext *ctx, const AVFrame *frame,
120#define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(&ctx->dxva2.report_id))140 int curr);
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)
136#endif141#endif
137 142
138unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,143unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
139 const AVDXVAContext *,144 AVDXVAContext *, const AVFrame *frame, int curr);
140 const AVFrame *frame);
141 145
142int ff_dxva2_commit_buffer(AVCodecContext *, AVDXVAContext *,146int ff_dxva2_commit_buffer(AVCodecContext *, AVDXVAContext *,
143 DECODER_BUFFER_DESC *,147 DECODER_BUFFER_DESC *,
@@ -161,4 +165,10 @@ int ff_dxva2_common_frame_params(AVCodecContext *avctx, · 17 unmodified lines
161 165
162int ff_dxva2_is_d3d11(const AVCodecContext *avctx);166int ff_dxva2_is_d3d11(const AVCodecContext *avctx);
163 167
168unsigned *ff_dxva2_get_report_id(const AVCodecContext *avctx, AVDXVAContext *ctx);
169
170void ff_dxva2_h264_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PicParams_H264 *pp);
171
172void ff_dxva2_h264_fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_Qmatrix_H264 *qm);
173
164#endif /* AVCODEC_DXVA2_INTERNAL_H */174#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
49 int is_field = s->picture_structure != PICT_FRAME;49 int is_field = s->picture_structure != PICT_FRAME;
50 50
51 memset(pp, 0, sizeof(*pp));51 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);
53 pp->wDeblockedPictureIndex = 0;53 pp->wDeblockedPictureIndex = 0;
54 if (s->pict_type != AV_PICTURE_TYPE_I)54 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);
56 else56 else
57 pp->wForwardRefPictureIndex = 0xffff;57 pp->wForwardRefPictureIndex = 0xffff;
58 if (s->pict_type == AV_PICTURE_TYPE_B)58 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);
60 else60 else
61 pp->wBackwardRefPictureIndex = 0xffff;61 pp->wBackwardRefPictureIndex = 0xffff;
62 pp->wPicWidthInMBminus1 = s->mb_width - 1;62 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
58 58
59 memset(pp, 0, sizeof(*pp));59 memset(pp, 0, sizeof(*pp));
60 pp->wDecodedPictureIndex =60 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);
62 if (s->pict_type != AV_PICTURE_TYPE_I && !v->bi_type)62 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);
64 else64 else
65 pp->wForwardRefPictureIndex = 0xffff;65 pp->wForwardRefPictureIndex = 0xffff;
66 if (s->pict_type == AV_PICTURE_TYPE_B && !v->bi_type)66 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);
68 else68 else
69 pp->wBackwardRefPictureIndex = 0xffff;69 pp->wBackwardRefPictureIndex = 0xffff;
70 if (v->profile == PROFILE_ADVANCED) {70 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
54 54
55 memset(pp, 0, sizeof(*pp));55 memset(pp, 0, sizeof(*pp));
56 56
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);
58 58
59 pp->profile = h->h.profile;59 pp->profile = h->h.profile;
60 pp->wFormatAndPictureInfoFlags = ((h->h.keyframe == 0) << 0) |60 pp->wFormatAndPictureInfoFlags = ((h->h.keyframe == 0) << 0) |
@@ -81,7 +81,7 @@ static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c · 20 unmodified lines
81 81
82 for (i = 0; i < 8; i++) {82 for (i = 0; i < 8; i++) {
83 if (h->refs[i].f->buf[0]) {83 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);
85 pp->ref_frame_coded_width[i] = h->refs[i].f->width;85 pp->ref_frame_coded_width[i] = h->refs[i].f->width;
86 pp->ref_frame_coded_height[i] = h->refs[i].f->height;86 pp->ref_frame_coded_height[i] = h->refs[i].f->height;
87 } else87 } else
@@ -91,7 +91,7 @@ static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c · 3 unmodified lines
91 for (i = 0; i < 3; i++) {91 for (i = 0; i < 3; i++) {
92 uint8_t refidx = h->h.refidx[i];92 uint8_t refidx = h->h.refidx[i];
93 if (h->refs[refidx].f->buf[0])93 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);
95 else95 else
96 pp->frame_refs[i].bPicEntry = 0xFF;96 pp->frame_refs[i].bPicEntry = 0xFF;
97 97
libavcodec/h264_slice.c+4−0
@@ -784,6 +784,7 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) · 783 unmodified lines
784{784{
785#define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \785#define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
786 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \786 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
787 CONFIG_H264_D3D12VA_HWACCEL + \
787 CONFIG_H264_NVDEC_HWACCEL + \788 CONFIG_H264_NVDEC_HWACCEL + \
788 CONFIG_H264_VAAPI_HWACCEL + \789 CONFIG_H264_VAAPI_HWACCEL + \
789 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \790 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
@@ -887,6 +888,9 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) · 97 unmodified lines
887 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;888 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
888 *fmt++ = AV_PIX_FMT_D3D11;889 *fmt++ = AV_PIX_FMT_D3D11;
889#endif890#endif
891#if CONFIG_H264_D3D12VA_HWACCEL
892 *fmt++ = AV_PIX_FMT_D3D12;
893#endif
890#if CONFIG_H264_VAAPI_HWACCEL894#if CONFIG_H264_VAAPI_HWACCEL
891 *fmt++ = AV_PIX_FMT_VAAPI;895 *fmt++ = AV_PIX_FMT_VAAPI;
892#endif896#endif
libavcodec/h264dec.c+3−0
@@ -1131,6 +1131,9 @@ const FFCodec ff_h264_decoder = { · 1130 unmodified lines
1131#if CONFIG_H264_D3D11VA2_HWACCEL1131#if CONFIG_H264_D3D11VA2_HWACCEL
1132 HWACCEL_D3D11VA2(h264),1132 HWACCEL_D3D11VA2(h264),
1133#endif1133#endif
1134#if CONFIG_H264_D3D12VA_HWACCEL
1135 HWACCEL_D3D12VA(h264),
1136#endif
1134#if CONFIG_H264_NVDEC_HWACCEL1137#if CONFIG_H264_NVDEC_HWACCEL
1135 HWACCEL_NVDEC(h264),1138 HWACCEL_NVDEC(h264),
1136#endif1139#endif
libavcodec/hwaccels.h+1−0
@@ -30,6 +30,7 @@ extern const struct FFHWAccel ff_h263_vaapi_hwaccel; · 29 unmodified lines
30extern const struct FFHWAccel ff_h263_videotoolbox_hwaccel;30extern const struct FFHWAccel ff_h263_videotoolbox_hwaccel;
31extern const struct FFHWAccel ff_h264_d3d11va_hwaccel;31extern const struct FFHWAccel ff_h264_d3d11va_hwaccel;
32extern const struct FFHWAccel ff_h264_d3d11va2_hwaccel;32extern const struct FFHWAccel ff_h264_d3d11va2_hwaccel;
33extern const struct FFHWAccel ff_h264_d3d12va_hwaccel;
33extern const struct FFHWAccel ff_h264_dxva2_hwaccel;34extern const struct FFHWAccel ff_h264_dxva2_hwaccel;
34extern const struct FFHWAccel ff_h264_nvdec_hwaccel;35extern const struct FFHWAccel ff_h264_nvdec_hwaccel;
35extern const struct FFHWAccel ff_h264_vaapi_hwaccel;36extern 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
77 HW_CONFIG_HWACCEL(1, 1, 1, VULKAN, VULKAN, ff_ ## codec ## _vulkan_hwaccel)77 HW_CONFIG_HWACCEL(1, 1, 1, VULKAN, VULKAN, ff_ ## codec ## _vulkan_hwaccel)
78#define HWACCEL_D3D11VA(codec) \78#define HWACCEL_D3D11VA(codec) \
79 HW_CONFIG_HWACCEL(0, 0, 1, D3D11VA_VLD, NONE, ff_ ## codec ## _d3d11va_hwaccel)79 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)
80 82
81#define HW_CONFIG_ENCODER(device, frames, ad_hoc, format, device_type_) \83#define HW_CONFIG_ENCODER(device, frames, ad_hoc, format, device_type_) \
82 &(const AVCodecHWConfigInternal) { \84 &(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