Re: [FFmpeg-devel] [PATCH v12 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding
>From: ffmpeg-devel On Behalf Of >Michael Niedermayer >Sent: Monday, December 25, 2023 7:07 AM >To: FFmpeg development discussions and patches de...@ffmpeg.org> >Subject: Re: [FFmpeg-devel] [PATCH v12 2/9] avcodec: add D3D12VA hardware >accelerated H264 decoding > >On Tue, Dec 05, 2023 at 02:46:44PM +0800, Tong Wu wrote: >> From: Wu Jianhua >> >> 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 >> >> Signed-off-by: Wu Jianhua >> Signed-off-by: Tong Wu >> --- >[...] >> +unsigned ff_d3d12va_get_surface_index(const AVCodecContext *avctx, >> + D3D12VADecodeContext *ctx, const >> AVFrame *frame, >> + int curr) >> +{ >> +AVD3D12VAFrame *f; >> +ID3D12Resource *res; >> +unsigned i; >> + >> +f = (AVD3D12VAFrame *)frame->data[0]; >> +if (!f) >> +goto fail; >> + >> +res = f->texture; >> +if (!res) >> +goto fail; >> + >> +if (!curr) { >> +for (i = 0; i < ctx->max_num_ref; i++) { >> +if (ctx->ref_resources[i] && res == ctx->ref_resources[i]) { >> +ctx->used_mask |= 1 << i; >> +return i; >> +} >> +} >> +} else { >> +for (i = 0; i < ctx->max_num_ref; i++) { >> +if (!((ctx->used_mask >> i) & 0x1)) { >> +ctx->ref_resources[i] = res; >> +return i; >> +} >> +} >> +} >> + >> +fail: >> +assert(0); > >this should probably be some av_assert* > >thx Thanks, will send a patch to fix later. > >[...] >-- >Michael GnuPG fingerprint: >9FF2128B147EF6730BADF133611EC787040B0FAB > >If the United States is serious about tackling the national security threats >related to an insecure 5G network, it needs to rethink the extent to which it >values corporate profits and government espionage over security.-Bruce >Schneier ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v12 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding
On Tue, Dec 05, 2023 at 02:46:44PM +0800, Tong Wu wrote: > From: Wu Jianhua > > 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 > > Signed-off-by: Wu Jianhua > Signed-off-by: Tong Wu > --- [...] > +unsigned ff_d3d12va_get_surface_index(const AVCodecContext *avctx, > + D3D12VADecodeContext *ctx, const > AVFrame *frame, > + int curr) > +{ > +AVD3D12VAFrame *f; > +ID3D12Resource *res; > +unsigned i; > + > +f = (AVD3D12VAFrame *)frame->data[0]; > +if (!f) > +goto fail; > + > +res = f->texture; > +if (!res) > +goto fail; > + > +if (!curr) { > +for (i = 0; i < ctx->max_num_ref; i++) { > +if (ctx->ref_resources[i] && res == ctx->ref_resources[i]) { > +ctx->used_mask |= 1 << i; > +return i; > +} > +} > +} else { > +for (i = 0; i < ctx->max_num_ref; i++) { > +if (!((ctx->used_mask >> i) & 0x1)) { > +ctx->ref_resources[i] = res; > +return i; > +} > +} > +} > + > +fail: > +assert(0); this should probably be some av_assert* thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If the United States is serious about tackling the national security threats related to an insecure 5G network, it needs to rethink the extent to which it values corporate profits and government espionage over security.-Bruce Schneier signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v12 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding
From: Wu Jianhua 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 Signed-off-by: Wu Jianhua Signed-off-by: Tong Wu --- configure | 2 + libavcodec/Makefile | 3 + libavcodec/d3d11va.h| 3 - libavcodec/d3d12va_decode.c | 538 libavcodec/d3d12va_decode.h | 179 libavcodec/d3d12va_h264.c | 207 ++ libavcodec/dxva2.c | 29 +- libavcodec/dxva2.h | 3 - libavcodec/dxva2_av1.c | 4 +- libavcodec/dxva2_h264.c | 26 +- libavcodec/dxva2_hevc.c | 6 +- libavcodec/dxva2_internal.h | 74 ++--- libavcodec/dxva2_mpeg2.c| 6 +- libavcodec/dxva2_vc1.c | 6 +- libavcodec/dxva2_vp9.c | 6 +- libavcodec/h264_slice.c | 4 + libavcodec/h264dec.c| 3 + libavcodec/hwaccels.h | 1 + libavcodec/hwconfig.h | 2 + 19 files changed, 1036 insertions(+), 66 deletions(-) create mode 100644 libavcodec/d3d12va_decode.c create mode 100644 libavcodec/d3d12va_decode.h create mode 100644 libavcodec/d3d12va_h264.c diff --git a/configure b/configure index 1a343ac6b9..90b20da49a 100755 --- a/configure +++ b/configure @@ -3082,6 +3082,8 @@ h264_d3d11va_hwaccel_deps="d3d11va" h264_d3d11va_hwaccel_select="h264_decoder" h264_d3d11va2_hwaccel_deps="d3d11va" h264_d3d11va2_hwaccel_select="h264_decoder" +h264_d3d12va_hwaccel_deps="d3d12va" +h264_d3d12va_hwaccel_select="h264_decoder" h264_dxva2_hwaccel_deps="dxva2" h264_dxva2_hwaccel_select="h264_decoder" h264_nvdec_hwaccel_deps="nvdec" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index fd9883d2ca..ead3a4480e 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -986,6 +986,7 @@ OBJS-$(CONFIG_ADPCM_ZORK_DECODER) += adpcm.o adpcm_data.o # hardware accelerators OBJS-$(CONFIG_D3D11VA)+= dxva2.o +OBJS-$(CONFIG_D3D12VA)+= dxva2.o d3d12va_decode.o OBJS-$(CONFIG_DXVA2) += dxva2.o OBJS-$(CONFIG_NVDEC) += nvdec.o OBJS-$(CONFIG_VAAPI) += vaapi_decode.o @@ -1003,6 +1004,7 @@ OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o OBJS-$(CONFIG_H264_D3D11VA_HWACCEL) += dxva2_h264.o OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o +OBJS-$(CONFIG_H264_D3D12VA_HWACCEL) += dxva2_h264.o d3d12va_h264.o OBJS-$(CONFIG_H264_NVDEC_HWACCEL) += nvdec_h264.o OBJS-$(CONFIG_H264_QSV_HWACCEL) += qsvdec.o OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o @@ -1296,6 +1298,7 @@ SKIPHEADERS+= %_tablegen.h \ SKIPHEADERS-$(CONFIG_AMF) += amfenc.h SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h +SKIPHEADERS-$(CONFIG_D3D12VA) += d3d12va_decode.h SKIPHEADERS-$(CONFIG_DXVA2)+= dxva2.h dxva2_internal.h SKIPHEADERS-$(CONFIG_JNI) += ffjni.h SKIPHEADERS-$(CONFIG_LCMS2)+= fflcms2.h diff --git a/libavcodec/d3d11va.h b/libavcodec/d3d11va.h index 6816b6c1e6..27f40e5519 100644 --- a/libavcodec/d3d11va.h +++ b/libavcodec/d3d11va.h @@ -45,9 +45,6 @@ * @{ */ -#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for Direct3D11 and old UVD/UVD+ ATI video cards -#define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO2 ///< Work around for Direct3D11 and old Intel GPUs with ClearVideo interface - /** * This structure is used to provides the necessary configurations and data * to the Direct3D11 FFmpeg HWAccel implementation. diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c new file mode 100644 index 00..03e565066c --- /dev/null +++ b/libavcodec/d3d12va_decode.c @@ -0,0 +1,538 @@ +/* + * Direct3D 12 HW acceleration video decoder + * + * copyright (c) 2022-2023 Wu Jianhua + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along