Re: [FFmpeg-devel] [PATCH] lavu/hwcontext_qsv: Derive bind flag from frame type if no valid surface

2024-07-29 Thread Tong Wu
>-Original Message-
>From: ffmpeg-devel  On Behalf Of
>fei.w.wang-at-intel@ffmpeg.org
>Sent: 2024年7月23日 9:27
>To: ffmpeg-devel@ffmpeg.org
>Cc: fei.w.w...@intel.com
>Subject: [FFmpeg-devel] [PATCH] lavu/hwcontext_qsv: Derive bind flag from
>frame type if no valid surface
>
>From: Fei Wang 
>
>Fix cmd:
>ffmpeg.exe -init_hw_device d3d11va=d3d -init_hw_device qsv=qsv@d3d \
>-filter_hw_device d3d -hwaccel qsv -hwaccel_output_format qsv  \
>-i in.h264 -vf "hwmap,format=d3d11,hwdownload,format=nv12" -y out.yuv
>
>Signed-off-by: Fei Wang 
>---
> libavutil/hwcontext_qsv.c | 7 +--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
>diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index
>7cec347478..09156275ec 100644
>--- a/libavutil/hwcontext_qsv.c
>+++ b/libavutil/hwcontext_qsv.c
>@@ -1549,8 +1549,11 @@ static int
>qsv_frames_derive_from(AVHWFramesContext *dst_ctx,
> dst_hwctx->texture_infos[i].texture = 
> (ID3D11Texture2D*)pair->first;
> dst_hwctx->texture_infos[i].index = pair->second ==
>(mfxMemId)MFX_INFINITE ? (intptr_t)0 : (intptr_t)pair->second;
> }
>-ID3D11Texture2D_GetDesc(dst_hwctx->texture_infos[0].texture,
>);
>-dst_hwctx->BindFlags = texDesc.BindFlags;
>+if (src_hwctx->nb_surfaces) {
>+ID3D11Texture2D_GetDesc(dst_hwctx->texture_infos[0].texture,
>);
>+dst_hwctx->BindFlags = texDesc.BindFlags;
>+} else
>+dst_hwctx->BindFlags =
>+ qsv_get_d3d11va_bind_flags(src_hwctx->frame_type);
> }
> break;
> #endif
>--
>2.34.1
>

Tested. LGTM. Thanks.
___
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 2/2] lavc/d3d12va_encode: trim header alignment at output

2024-07-29 Thread Tong Wu
Lynne:
>Subject: Re: [FFmpeg-devel] [PATCH 2/2] lavc/d3d12va_encode: trim header
>alignment at output
>
>On 28/07/2024 15:06, Tong Wu wrote:
>> Tong Wu:
>>> Subject: [FFmpeg-devel][PATCH 2/2] lavc/d3d12va_encode: trim header
>>> alignment at output
>>>
>>> It is d3d12va's requirement that the FrameStartOffset must be aligned
>>> as per hardware limitation. However, we could trim this alignment at
>>> output to reduce coded size. A aligned_header_size is added to
>D3D12VAEncodePicture.
>>>
>>> Signed-off-by: Tong Wu 
>>> ---
>>> libavcodec/d3d12va_encode.c | 18 --
>>> libavcodec/d3d12va_encode.h |  1 +
>>> 2 files changed, 13 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/libavcodec/d3d12va_encode.c
>>> b/libavcodec/d3d12va_encode.c index
>>> 9f7a42911e..9ee9da41e3 100644
>>> --- a/libavcodec/d3d12va_encode.c
>>> +++ b/libavcodec/d3d12va_encode.c
>>> @@ -308,9 +308,9 @@ static int d3d12va_encode_issue(AVCodecContext
>*avctx,
>>>  }
>>>
>>>  pic->header_size = (int)bit_len / 8;
>>> -pic->header_size = pic->header_size % ctx-
>>>> req.CompressedBitstreamBufferAccessAlignment ?
>>> -   FFALIGN(pic->header_size, ctx-
>>>> req.CompressedBitstreamBufferAccessAlignment) :
>>> -   pic->header_size;
>>> +pic->aligned_header_size = pic->header_size % ctx-
>>>> req.CompressedBitstreamBufferAccessAlignment ?
>>> +   FFALIGN(pic->header_size, ctx-
>>>> req.CompressedBitstreamBufferAccessAlignment) :
>>> +   pic->header_size;
>>>
>>>  hr = ID3D12Resource_Map(pic->output_buffer, 0, NULL, (void 
>>> **));
>>>  if (FAILED(hr)) {
>>> @@ -318,7 +318,7 @@ static int d3d12va_encode_issue(AVCodecContext
>*avctx,
>>>  goto fail;
>>>  }
>>>
>>> -memcpy(ptr, data, pic->header_size);
>>> +memcpy(ptr, data, pic->aligned_header_size);
>>>  ID3D12Resource_Unmap(pic->output_buffer, 0, NULL);
>>>  }
>>>
>>> @@ -344,10 +344,10 @@ static int d3d12va_encode_issue(AVCodecContext
>>> *avctx,
>>>
>>>  input_args.PictureControlDesc.PictureControlCodecData = pic->pic_ctl;
>>>  input_args.PictureControlDesc.ReferenceFrames = d3d12_refs;
>>> -input_args.CurrentFrameBitstreamMetadataSize  = 
>>> pic->header_size;
>>> +input_args.CurrentFrameBitstreamMetadataSize  = pic-
>>>> aligned_header_size;
>>>
>>>  output_args.Bitstream.pBuffer= 
>>> pic->output_buffer;
>>> -output_args.Bitstream.FrameStartOffset   = 
>>> pic->header_size;
>>> +output_args.Bitstream.FrameStartOffset   = pic-
>>>> aligned_header_size;
>>>  output_args.ReconstructedPicture.pReconstructedPicture   = pic-
>>>> recon_surface->texture;
>>>  output_args.ReconstructedPicture.ReconstructedPictureSubresource = 0;
>>>  output_args.EncoderOutputMetadata.pBuffer= pic-
>>>> encoded_metadata;
>>> @@ -663,6 +663,12 @@ static int
>>> d3d12va_encode_get_coded_data(AVCodecContext *avctx,
>>>  goto end;
>>>  ptr = pkt->data;
>>>
>>> +memcpy(ptr, mapped_data, pic->header_size);
>>> +
>>> +ptr += pic->header_size;
>>> +mapped_data += pic->aligned_header_size;
>>> +total_size -= pic->header_size;
>>> +
>>>  memcpy(ptr, mapped_data, total_size);
>>>
>>>  ID3D12Resource_Unmap(pic->output_buffer, 0, NULL); diff --git
>>> a/libavcodec/d3d12va_encode.h b/libavcodec/d3d12va_encode.h index
>>> 1a0abc5bd0..51440428e4 100644
>>> --- a/libavcodec/d3d12va_encode.h
>>> +++ b/libavcodec/d3d12va_encode.h
>>> @@ -43,6 +43,7 @@ typedef struct D3D12VAEncodePicture {
>>>  FFHWBaseEncodePicture base;
>>>
>>>  int header_size;
>>> +int aligned_header_size;
>>>
>>>  AVD3D12VAFrame *input_surface;
>>>  AVD3D12VAFrame *recon_surface;
>>> --
>>> 2.45.1.windows.1
>>
>>
>&

Re: [FFmpeg-devel] [PATCH 2/2] lavc/d3d12va_encode: trim header alignment at output

2024-07-28 Thread Tong Wu
Tong Wu:
>Subject: [FFmpeg-devel][PATCH 2/2] lavc/d3d12va_encode: trim header
>alignment at output
>
>It is d3d12va's requirement that the FrameStartOffset must be aligned as per
>hardware limitation. However, we could trim this alignment at output to reduce
>coded size. A aligned_header_size is added to D3D12VAEncodePicture.
>
>Signed-off-by: Tong Wu 
>---
> libavcodec/d3d12va_encode.c | 18 --
>libavcodec/d3d12va_encode.h |  1 +
> 2 files changed, 13 insertions(+), 6 deletions(-)
>
>diff --git a/libavcodec/d3d12va_encode.c b/libavcodec/d3d12va_encode.c index
>9f7a42911e..9ee9da41e3 100644
>--- a/libavcodec/d3d12va_encode.c
>+++ b/libavcodec/d3d12va_encode.c
>@@ -308,9 +308,9 @@ static int d3d12va_encode_issue(AVCodecContext *avctx,
> }
>
> pic->header_size = (int)bit_len / 8;
>-pic->header_size = pic->header_size % ctx-
>>req.CompressedBitstreamBufferAccessAlignment ?
>-   FFALIGN(pic->header_size, ctx-
>>req.CompressedBitstreamBufferAccessAlignment) :
>-   pic->header_size;
>+pic->aligned_header_size = pic->header_size % ctx-
>>req.CompressedBitstreamBufferAccessAlignment ?
>+   FFALIGN(pic->header_size, ctx-
>>req.CompressedBitstreamBufferAccessAlignment) :
>+   pic->header_size;
>
> hr = ID3D12Resource_Map(pic->output_buffer, 0, NULL, (void **));
> if (FAILED(hr)) {
>@@ -318,7 +318,7 @@ static int d3d12va_encode_issue(AVCodecContext *avctx,
> goto fail;
> }
>
>-memcpy(ptr, data, pic->header_size);
>+memcpy(ptr, data, pic->aligned_header_size);
> ID3D12Resource_Unmap(pic->output_buffer, 0, NULL);
> }
>
>@@ -344,10 +344,10 @@ static int d3d12va_encode_issue(AVCodecContext
>*avctx,
>
> input_args.PictureControlDesc.PictureControlCodecData = pic->pic_ctl;
> input_args.PictureControlDesc.ReferenceFrames = d3d12_refs;
>-input_args.CurrentFrameBitstreamMetadataSize  = pic->header_size;
>+input_args.CurrentFrameBitstreamMetadataSize  = pic-
>>aligned_header_size;
>
> output_args.Bitstream.pBuffer= 
> pic->output_buffer;
>-output_args.Bitstream.FrameStartOffset   = 
>pic->header_size;
>+output_args.Bitstream.FrameStartOffset   = pic-
>>aligned_header_size;
> output_args.ReconstructedPicture.pReconstructedPicture   = pic-
>>recon_surface->texture;
> output_args.ReconstructedPicture.ReconstructedPictureSubresource = 0;
> output_args.EncoderOutputMetadata.pBuffer= pic-
>>encoded_metadata;
>@@ -663,6 +663,12 @@ static int
>d3d12va_encode_get_coded_data(AVCodecContext *avctx,
> goto end;
> ptr = pkt->data;
>
>+memcpy(ptr, mapped_data, pic->header_size);
>+
>+ptr += pic->header_size;
>+mapped_data += pic->aligned_header_size;
>+total_size -= pic->header_size;
>+
> memcpy(ptr, mapped_data, total_size);
>
> ID3D12Resource_Unmap(pic->output_buffer, 0, NULL); diff --git
>a/libavcodec/d3d12va_encode.h b/libavcodec/d3d12va_encode.h index
>1a0abc5bd0..51440428e4 100644
>--- a/libavcodec/d3d12va_encode.h
>+++ b/libavcodec/d3d12va_encode.h
>@@ -43,6 +43,7 @@ typedef struct D3D12VAEncodePicture {
> FFHWBaseEncodePicture base;
>
> int header_size;
>+int aligned_header_size;
>
> AVD3D12VAFrame *input_surface;
> AVD3D12VAFrame *recon_surface;
>--
>2.45.1.windows.1


The first patch in this patchset has been merged earlier. Will merge this patch 
if there's no more comment.

-Tong



___
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 1/2] lavc/hw_base_encode: correct the timestamp when input_order = decode_delay

2024-07-19 Thread Tong Wu

>From: Tong Wu 
>Sent: 2024年7月8日 23:13
>To: ffmpeg-devel@ffmpeg.org
>Cc: Tong Wu 
>Subject: [FFmpeg-devel][PATCH 1/2] lavc/hw_base_encode: correct the
>timestamp when input_order = decode_delay
>
>Fixed the command line: ffmpeg -hwaccel vaapi -pix_fmt nv12 -s:v
>widthxheight -i input.yuv -vf "hwupload" -c:v hevc_vaapi -bf 10 -b_depth 3 -
>vframes 3 -f null -
>
>Signed-off-by: Tong Wu 
>---
> libavcodec/hw_base_encode.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
>index ecb4be6aa4..869096caea 100644
>--- a/libavcodec/hw_base_encode.c
>+++ b/libavcodec/hw_base_encode.c
>@@ -472,7 +472,7 @@ static int
>hw_base_encode_send_frame(AVCodecContext *avctx,
>FFHWBaseEncodeContex
>
> // Fix timestamps if we hit end-of-stream before the initial decode
> // delay has elapsed.
>-if (ctx->input_order < ctx->decode_delay)
>+if (ctx->input_order <= ctx->decode_delay)
> ctx->dts_pts_diff = ctx->pic_end->pts - ctx->first_pts;
> }
>
>--
>2.45.1.windows.1


Ping. Is there any comment on this patchset?

___
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] mailmap: add entry for myself

2024-07-13 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 .mailmap | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.mailmap b/.mailmap
index 53cb5eac26..fe019b88c7 100644
--- a/.mailmap
+++ b/.mailmap
@@ -24,3 +24,5 @@ rcombs  
  
  
 Cosmin Stejerean  Cosmin Stejerean via ffmpeg-devel 

+ 
+ 
-- 
2.45.1.windows.1

___
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] MAINTAINERS: add myself as d3d12va_encode maintainer

2024-07-12 Thread Tong Wu


Michael Niedermayer:
>Subject: Re: [FFmpeg-devel] [PATCH] MAINTAINERS: add myself as
>d3d12va_encode maintainer
>
>On Tue, Jul 09, 2024 at 02:41:20PM +0200, Michael Niedermayer wrote:
>> On Mon, Jul 08, 2024 at 03:16:28PM +, Tong Wu wrote:
>> > Ping. As the author of d3d12va_encode, I would like to get the access in 
>> > order
>maintain the code and add more new features.
>>
>> will apply
>
>Before adding your key, can you explain why your email domain changed from
>intel.com to outlook at about the time you volunteer as mainatiner ?
>
>I tried to mail the intel.com address but it bounced, which is why i am 
>posting here

Hi Michael. I left the company before the d3d12va_encode patch set was merged. 
That's why I'm using the new address since the previous domain is invalid.  


>
>Tong Wu (tong1...@intel.com)<mailto:tong1...@intel.com>
>A communication failure occurred during the delivery of this message. Please 
>try
>resending the message later. If the problem continues, contact your email 
>admin.
>
>BN2PEPF44AB.mail.protection.outlook.com gave this error:
>Recipient address rejected: Access denied.
>[BN2PEPF44AB.namprd04.prod.outlook.com 2024-07-12T19:12:51.273Z
>08DC9DE0F46B8D63]

Looks like you also have trouble reaching me through the outlook?

>
>also if you use multiple email addresses in git, best to add them to .mailmap
>

Good idea. I'll add it to map the previous commits thx.
___
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] MAINTAINERS: add myself as d3d12va_encode maintainer

2024-07-08 Thread Tong Wu
Ping. As the author of d3d12va_encode, I would like to get the access in order 
maintain the code and add more new features.

>-Original Message-
>From: wutong1...@outlook.com 
>Sent: 2024年7月2日 23:23
>To: ffmpeg-devel@ffmpeg.org
>Cc: Tong Wu 
>Subject: [FFmpeg-devel][PATCH] MAINTAINERS: add myself as d3d12va_encode
>maintainer
>
>From: Tong Wu 
>
>Signed-off-by: Tong Wu 
>---
> MAINTAINERS | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/MAINTAINERS b/MAINTAINERS
>index a82fa58c69..08f57def7d 100644
>--- a/MAINTAINERS
>+++ b/MAINTAINERS
>@@ -260,6 +260,7 @@ Codecs:
> Hardware acceleration:
>   dxva2*Hendrik Leppkes, Laurent Aimar, Steve 
> Lhomme
>   d3d11va*      Steve Lhomme
>+  d3d12va_encode*   Tong Wu
>   mediacodec*   Matthieu Bouron, Aman Gupta, Zhao 
> Zhili
>   vaapi*Haihao Xiang
>   vaapi_encode* Mark Thompson, Haihao Xiang
>--
>2.45.1.windows.1

___
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 2/2] lavc/d3d12va_encode: trim header alignment at output

2024-07-08 Thread Tong Wu
It is d3d12va's requirement that the FrameStartOffset must be aligned as
per hardware limitation. However, we could trim this alignment at output
to reduce coded size. A aligned_header_size is added to
D3D12VAEncodePicture.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_encode.c | 18 --
 libavcodec/d3d12va_encode.h |  1 +
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/libavcodec/d3d12va_encode.c b/libavcodec/d3d12va_encode.c
index 9f7a42911e..9ee9da41e3 100644
--- a/libavcodec/d3d12va_encode.c
+++ b/libavcodec/d3d12va_encode.c
@@ -308,9 +308,9 @@ static int d3d12va_encode_issue(AVCodecContext *avctx,
 }
 
 pic->header_size = (int)bit_len / 8;
-pic->header_size = pic->header_size % 
ctx->req.CompressedBitstreamBufferAccessAlignment ?
-   FFALIGN(pic->header_size, 
ctx->req.CompressedBitstreamBufferAccessAlignment) :
-   pic->header_size;
+pic->aligned_header_size = pic->header_size % 
ctx->req.CompressedBitstreamBufferAccessAlignment ?
+   FFALIGN(pic->header_size, 
ctx->req.CompressedBitstreamBufferAccessAlignment) :
+   pic->header_size;
 
 hr = ID3D12Resource_Map(pic->output_buffer, 0, NULL, (void **));
 if (FAILED(hr)) {
@@ -318,7 +318,7 @@ static int d3d12va_encode_issue(AVCodecContext *avctx,
 goto fail;
 }
 
-memcpy(ptr, data, pic->header_size);
+memcpy(ptr, data, pic->aligned_header_size);
 ID3D12Resource_Unmap(pic->output_buffer, 0, NULL);
 }
 
@@ -344,10 +344,10 @@ static int d3d12va_encode_issue(AVCodecContext *avctx,
 
 input_args.PictureControlDesc.PictureControlCodecData = pic->pic_ctl;
 input_args.PictureControlDesc.ReferenceFrames = d3d12_refs;
-input_args.CurrentFrameBitstreamMetadataSize  = pic->header_size;
+input_args.CurrentFrameBitstreamMetadataSize  = 
pic->aligned_header_size;
 
 output_args.Bitstream.pBuffer= 
pic->output_buffer;
-output_args.Bitstream.FrameStartOffset   = 
pic->header_size;
+output_args.Bitstream.FrameStartOffset   = 
pic->aligned_header_size;
 output_args.ReconstructedPicture.pReconstructedPicture   = 
pic->recon_surface->texture;
 output_args.ReconstructedPicture.ReconstructedPictureSubresource = 0;
 output_args.EncoderOutputMetadata.pBuffer= 
pic->encoded_metadata;
@@ -663,6 +663,12 @@ static int d3d12va_encode_get_coded_data(AVCodecContext 
*avctx,
 goto end;
 ptr = pkt->data;
 
+memcpy(ptr, mapped_data, pic->header_size);
+
+ptr += pic->header_size;
+mapped_data += pic->aligned_header_size;
+total_size -= pic->header_size;
+
 memcpy(ptr, mapped_data, total_size);
 
 ID3D12Resource_Unmap(pic->output_buffer, 0, NULL);
diff --git a/libavcodec/d3d12va_encode.h b/libavcodec/d3d12va_encode.h
index 1a0abc5bd0..51440428e4 100644
--- a/libavcodec/d3d12va_encode.h
+++ b/libavcodec/d3d12va_encode.h
@@ -43,6 +43,7 @@ typedef struct D3D12VAEncodePicture {
 FFHWBaseEncodePicture base;
 
 int header_size;
+int aligned_header_size;
 
 AVD3D12VAFrame *input_surface;
 AVD3D12VAFrame *recon_surface;
-- 
2.45.1.windows.1

___
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 1/2] lavc/hw_base_encode: correct the timestamp when input_order = decode_delay

2024-07-08 Thread Tong Wu
Fixed the command line: ffmpeg -hwaccel vaapi -pix_fmt nv12 -s:v
widthxheight -i input.yuv -vf "hwupload" -c:v hevc_vaapi -bf 10 -b_depth 3
-vframes 3 -f null -

Signed-off-by: Tong Wu 
---
 libavcodec/hw_base_encode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
index ecb4be6aa4..869096caea 100644
--- a/libavcodec/hw_base_encode.c
+++ b/libavcodec/hw_base_encode.c
@@ -472,7 +472,7 @@ static int hw_base_encode_send_frame(AVCodecContext *avctx, 
FFHWBaseEncodeContex
 
 // Fix timestamps if we hit end-of-stream before the initial decode
 // delay has elapsed.
-if (ctx->input_order < ctx->decode_delay)
+if (ctx->input_order <= ctx->decode_delay)
 ctx->dts_pts_diff = ctx->pic_end->pts - ctx->first_pts;
 }
 
-- 
2.45.1.windows.1

___
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] avcodec/hw_base_encode: Add missing include

2024-07-03 Thread Tong Wu
Andreas Rheinhardt:
>Subject: [FFmpeg-devel] [PATCH] avcodec/hw_base_encode: Add missing include
>
>Fixes checkheaders.
>
>Signed-off-by: Andreas Rheinhardt 
>---
> libavcodec/hw_base_encode.h | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h index
>e528f2013b..ac0cc7b80c 100644
>--- a/libavcodec/hw_base_encode.h
>+++ b/libavcodec/hw_base_encode.h
>@@ -19,6 +19,7 @@
> #ifndef AVCODEC_HW_BASE_ENCODE_H
> #define AVCODEC_HW_BASE_ENCODE_H
>
>+#include "avcodec.h"
> #include "libavutil/hwcontext.h"
> #include "libavutil/fifo.h"
>
>--


LGTM, thanks.
___
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 v13 06/15] avcodec/vaapi_encode: move the dpb logic from VAAPI to base layer

2024-06-15 Thread Tong Wu
> >> From: ffmpeg-devel  On Behalf Of
> >> Lynne via ffmpeg-devel
> >> Sent: Monday, June 10, 2024 10:01 AM
> >> To: FFmpeg development discussions and patches  >> de...@ffmpeg.org>
> >> Cc: Lynne 
> >> Subject: Re: [FFmpeg-devel] [PATCH v13 06/15] avcodec/vaapi_encode:
> >> move the dpb logic from VAAPI to base layer
> >>
> >> On 07/06/2024 18:48, Lynne wrote:
> >>> On 07/06/2024 17:22, Wu, Tong1 wrote:
> >>>>> From: ffmpeg-devel  On Behalf Of
> >> Lynne
> >>>>> via ffmpeg-devel
> >>>>> Sent: Friday, June 7, 2024 11:10 PM
> >>>>> To: ffmpeg-devel@ffmpeg.org
> >>>>> Cc: Lynne 
> >>>>> Subject: Re: [FFmpeg-devel] [PATCH v13 06/15]
> avcodec/vaapi_encode:
> >> move
> >>>>> the dpb logic from VAAPI to base layer
> >>>>>
> >>>>> On 03/06/2024 11:18, tong1.wu-at-intel@ffmpeg.org wrote:
> >>>>>> From: Tong Wu 
> >>>>>>
> >>>>>> Move receive_packet function to base. This requires adding
> >>>>>> *alloc, *issue, *output, *free as hardware callbacks.
> >>>>>> HWBaseEncodePicture is introduced as the base layer structure.
> >>>>>> The related parameters in VAAPIEncodeContext are also extracted
> >>>>>> to HWBaseEncodeContext. Then
> >> DPB
> >>>>>> management logic can be fully extracted to base layer as-is.
> >>>>>>
> >>>>>> Signed-off-by: Tong Wu 
> >>>>>> ---
> >>>>>>     libavcodec/Makefile |   2 +-
> >>>>>>     libavcodec/hw_base_encode.c | 594
> >>>>>> 
> >>>>>>     libavcodec/hw_base_encode.h | 124 +
> >>>>>>     libavcodec/vaapi_encode.c   | 793 +
> >>>>>> ---
> >>>>>>     libavcodec/vaapi_encode.h   | 102 +---
> >>>>>>     libavcodec/vaapi_encode_av1.c   |  35 +-
> >>>>>>     libavcodec/vaapi_encode_h264.c  |  84 ++--
> >>>>>>     libavcodec/vaapi_encode_h265.c  |  53 ++-
> >>>>>>     libavcodec/vaapi_encode_mjpeg.c |  13 +-
> >>>>>>     libavcodec/vaapi_encode_mpeg2.c |  33 +-
> >>>>>>     libavcodec/vaapi_encode_vp8.c   |  18 +-
> >>>>>>     libavcodec/vaapi_encode_vp9.c   |  24 +-
> >>>>>>     12 files changed, 985 insertions(+), 890 deletions(-)
> >>>>>>     create mode 100644 libavcodec/hw_base_encode.c
> >>>>>
> >>>>> This patch doesn't apply,
> >>>>>
> >>>>> error: sha1 information is lacking or useless (libavcodec/
> >>>>> hw_base_encode.c).
> >>>>> error: could not build fake ancestor
> >>>>>
> >>>>> Could you resent the patchset or link me a repo so I can work with it?
> >>>>
> >>>> https://github.com/intel-media-ci/ffmpeg/pull/689 This is the same
> >>>> as
> >>>> v13 please have a try.
> >>>
> >>> That worked, thanks.
> >>
> >> I don't think the behaviour is correct when the encoding length is
> >> less than the decode delay. In my old Vulkan code, I had this piece
> >> of code in the initialization function:
> >>
> >>> if (!src) {
> >>>  ctx->end_of_stream = 1;
> >>>  /* Fix timestamps if we hit end-of-stream before the initial
> >>>   * decode delay has elapsed. */
> >>>  if (ctx->input_order < ctx->decode_delay)
> >>>  ctx->dts_pts_diff = ctx->pic_end->pts - ctx->first_pts;
> >>>  return AVERROR_EOF;
> >>> }
> >>
> >> I think a flush function should be added, to be called by each
> >> encoder, to make sure the timestamps remain correct.
> >>
> >
> > For the current patch set, this piece is in hw_base_encode_send_frame and
> works well for vaapi and d3d12 except when the encoding length is equal to
> the decode delay, which I'll sent a fix later. Do you mean Vulkan cannot
> integrate into this part and we have to make a callback for it?
> 
> No, I was just curious. Fair enough, it can be implemented in a later patch.
> 
> >
> >> Also, the D3D12VA structures need an FF prefix, e.g.
> >> D3D12VAEncodeContext -> FFD3D12VAEncodeContext.
> >
> > The current VAAPIEncodeContext has existed for a long time. Does it have
> any difference for D3D12VAEncodeContext? I mean both
> VAAPIEncodeContext and D3D12VAEncodeContext are parallel and only
> referenced in vaapi_encode_*.c (d3d12va_encode_*.c).
> >
> > Thanks,
> > Tong
> 
> I'm finishing up on the Vulkan test implementation, I'll see to pushing this
> patch over the weekend.

Sure. Thank you.

-Tong
___
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] avcodec/d3d12va_vc1: add support for D3D12_VIDEO_DECODE_PROFILE_VC1_D2010 guid.

2024-01-31 Thread Tong Wu
From: Aleksoid 

The VC1_D2010 profile, also known as VC1_VLD2010, has the same functionality
and specification as the VC1_D profile. Support for this profile serves only
as a positive indication that the accelerator has been designed with awareness
of the modifications specified in the August 2010 version of this specification.

Hardware accelerator drivers that expose support for this profile must not
also expose the previously specified VC1_D GUID, unless the accelerator works
properly with existing software decoders that use VC1_D and that do not 
incorporate
the corrections added to the August 2010 version of this specification.

As a result, we could give VC1_VLD2010 a higher priority and initialize
it first.

Signed-off-by: Aleksoid 
Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_vc1.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
index 3aa2743107..110926be82 100644
--- a/libavcodec/d3d12va_vc1.c
+++ b/libavcodec/d3d12va_vc1.c
@@ -164,12 +164,19 @@ static int d3d12va_vc1_end_frame(AVCodecContext *avctx)
 
 static int d3d12va_vc1_decode_init(AVCodecContext *avctx)
 {
+int ret;
 D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
-ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_VC1;
+ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_VC1_D2010;
 
 ctx->max_num_ref = 3;
 
-return ff_d3d12va_decode_init(avctx);
+ret = ff_d3d12va_decode_init(avctx);
+if (ret < 0) {
+ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_VC1;
+ret = ff_d3d12va_decode_init(avctx);
+}
+
+return ret;
 }
 
 #if CONFIG_WMV3_D3D12VA_HWACCEL
-- 
2.43.0.windows.1

___
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 2/2] d3d12va_av1|h264|hevc|vc1|vp9: input void** for ID3D12Resource_Map

2024-01-03 Thread Tong Wu
Fixes -Wincompatible-pointer-types warnings.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_av1.c  | 2 +-
 libavcodec/d3d12va_h264.c | 2 +-
 libavcodec/d3d12va_hevc.c | 2 +-
 libavcodec/d3d12va_vc1.c  | 2 +-
 libavcodec/d3d12va_vp9.c  | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
index 5f96f7da04..05cebc3148 100644
--- a/libavcodec/d3d12va_av1.c
+++ b/libavcodec/d3d12va_av1.c
@@ -110,7 +110,7 @@ static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPU
 {
 const AV1DecContext *h   = avctx->priv_data;
 AV1DecodePictureContext *ctx_pic = h->cur_frame.hwaccel_picture_private;
-uint8_t *mapped_data;
+void *mapped_data;
 
 D3D12_VIDEO_DECODE_FRAME_ARGUMENT *args = 
_args->FrameArguments[input_args->NumFrameArguments++];
 args->Type  = D3D12_VIDEO_DECODE_ARGUMENT_TYPE_SLICE_CONTROL;
diff --git a/libavcodec/d3d12va_h264.c b/libavcodec/d3d12va_h264.c
index be5cf0d527..cd02f3621e 100644
--- a/libavcodec/d3d12va_h264.c
+++ b/libavcodec/d3d12va_h264.c
@@ -113,7 +113,7 @@ static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPU
 DXVA_Slice_H264_Short *slice;
 D3D12_VIDEO_DECODE_FRAME_ARGUMENT *args;
 
-if (FAILED(ID3D12Resource_Map(buffer, 0, NULL, _data))) {
+if (FAILED(ID3D12Resource_Map(buffer, 0, NULL, (void **)_data))) {
 av_log(avctx, AV_LOG_ERROR, "Failed to map D3D12 Buffer resource!\n");
 return AVERROR(EINVAL);
 }
diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index a6a3b802f9..ca345c845f 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -107,7 +107,7 @@ static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPU
 DXVA_Slice_HEVC_Short *slice;
 D3D12_VIDEO_DECODE_FRAME_ARGUMENT *args;
 
-if (FAILED(ID3D12Resource_Map(buffer, 0, NULL, _data))) {
+if (FAILED(ID3D12Resource_Map(buffer, 0, NULL, (void **)_data))) {
 av_log(avctx, AV_LOG_ERROR, "Failed to map D3D12 Buffer resource!\n");
 return AVERROR(EINVAL);
 }
diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
index b39b03ab45..8d8834b1cc 100644
--- a/libavcodec/d3d12va_vc1.c
+++ b/libavcodec/d3d12va_vc1.c
@@ -105,7 +105,7 @@ static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPU
 
 static const uint8_t start_code[] = { 0, 0, 1, 0x0d };
 
-if (FAILED(ID3D12Resource_Map(buffer, 0, NULL, _data))) {
+if (FAILED(ID3D12Resource_Map(buffer, 0, NULL, (void **)_data))) {
 av_log(avctx, AV_LOG_ERROR, "Failed to map D3D12 Buffer resource!\n");
 return AVERROR(EINVAL);
 }
diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
index 3d8f3a4466..8b8692f68d 100644
--- a/libavcodec/d3d12va_vp9.c
+++ b/libavcodec/d3d12va_vp9.c
@@ -88,7 +88,7 @@ static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPU
 const VP9SharedContext  *h   = avctx->priv_data;
 VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
 
-uint8_t *mapped_data;
+void *mapped_data;
 D3D12_VIDEO_DECODE_FRAME_ARGUMENT *args;
 
 if (FAILED(ID3D12Resource_Map(buffer, 0, NULL, _data))) {
-- 
2.41.0.windows.1

___
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 1/2] d3d12va_decode|av1|h264|hevc|vc1|vp9: remove unused variables

2024-01-03 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_av1.c| 18 +-
 libavcodec/d3d12va_decode.c |  9 ++---
 libavcodec/d3d12va_h264.c   |  4 
 libavcodec/d3d12va_hevc.c   |  5 -
 libavcodec/d3d12va_vc1.c|  3 ---
 libavcodec/d3d12va_vp9.c|  4 
 6 files changed, 7 insertions(+), 36 deletions(-)

diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
index 6a3543353f..5f96f7da04 100644
--- a/libavcodec/d3d12va_av1.c
+++ b/libavcodec/d3d12va_av1.c
@@ -108,11 +108,8 @@ static int d3d12va_av1_decode_slice(AVCodecContext *avctx,
 
 static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
 {
-D3D12VADecodeContext*ctx  = D3D12VA_DECODE_CONTEXT(avctx);
-AVHWFramesContext   *frames_ctx   = D3D12VA_FRAMES_CONTEXT(avctx);
-AVD3D12VAFramesContext  *frames_hwctx = frames_ctx->hwctx;
-const AV1DecContext *h= avctx->priv_data;
-AV1DecodePictureContext *ctx_pic  = 
h->cur_frame.hwaccel_picture_private;
+const AV1DecContext *h   = avctx->priv_data;
+AV1DecodePictureContext *ctx_pic = h->cur_frame.hwaccel_picture_private;
 uint8_t *mapped_data;
 
 D3D12_VIDEO_DECODE_FRAME_ARGUMENT *args = 
_args->FrameArguments[input_args->NumFrameArguments++];
@@ -142,7 +139,6 @@ static int d3d12va_av1_end_frame(AVCodecContext *avctx)
 {
 int ret;
 const AV1DecContext *h   = avctx->priv_data;
-D3D12VADecodeContext*ctx = D3D12VA_DECODE_CONTEXT(avctx);
 AV1DecodePictureContext *ctx_pic = h->cur_frame.hwaccel_picture_private;
 
 if (ctx_pic->tiles <= 0 || ctx_pic->bitstream_size <= 0)
@@ -156,10 +152,8 @@ static int d3d12va_av1_end_frame(AVCodecContext *avctx)
 
 static int d3d12va_av1_decode_init(AVCodecContext *avctx)
 {
-const AV1DecContext *h   = avctx->priv_data;
-D3D12VADecodeContext*ctx = D3D12VA_DECODE_CONTEXT(avctx);
-D3D12AV1DecodeContext   *av1_ctx = D3D12_AV1_DECODE_CONTEXT(avctx);
-AV1DecodePictureContext *ctx_pic = h->cur_frame.hwaccel_picture_private;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12AV1DecodeContext *av1_ctx = D3D12_AV1_DECODE_CONTEXT(avctx);
 DXVA_PicParams_AV1 pp;
 
 int ret;
@@ -186,9 +180,7 @@ static int d3d12va_av1_decode_init(AVCodecContext *avctx)
 
 static int d3d12va_av1_decode_uninit(AVCodecContext *avctx)
 {
-const AV1DecContext *h   = avctx->priv_data;
-D3D12AV1DecodeContext   *ctx = D3D12_AV1_DECODE_CONTEXT(avctx);
-AV1DecodePictureContext *ctx_pic = h->cur_frame.hwaccel_picture_private;
+D3D12AV1DecodeContext *ctx = D3D12_AV1_DECODE_CONTEXT(avctx);
 
 if (ctx->bitstream_buffer)
 av_freep(>bitstream_buffer);
diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c
index e0b67bf964..f705002c10 100644
--- a/libavcodec/d3d12va_decode.c
+++ b/libavcodec/d3d12va_decode.c
@@ -266,8 +266,7 @@ fail:
 
 int ff_d3d12va_common_frame_params(AVCodecContext *avctx, AVBufferRef 
*hw_frames_ctx)
 {
-AVHWFramesContext  *frames_ctx   = (AVHWFramesContext 
*)hw_frames_ctx->data;
-AVHWDeviceContext  *device_ctx   = frames_ctx->device_ctx;
+AVHWFramesContext *frames_ctx = (AVHWFramesContext *)hw_frames_ctx->data;
 
 frames_ctx->format= AV_PIX_FMT_D3D12;
 frames_ctx->sw_format = avctx->sw_pix_fmt == AV_PIX_FMT_YUV420P10 ? 
AV_PIX_FMT_P010 : AV_PIX_FMT_NV12;
@@ -408,9 +407,7 @@ int ff_d3d12va_decode_uninit(AVCodecContext *avctx)
 
 static inline int d3d12va_update_reference_frames_state(AVCodecContext *avctx, 
D3D12_RESOURCE_BARRIER *barriers, int state_before, int state_end)
 {
-D3D12VADecodeContext   *ctx  = D3D12VA_DECODE_CONTEXT(avctx);
-AVHWFramesContext  *frames_ctx   = D3D12VA_FRAMES_CONTEXT(avctx);
-AVD3D12VAFramesContext *frames_hwctx = frames_ctx->hwctx;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
 
 int num_barrier = 0;
 for (int i = 0; i < ctx->max_num_ref; i++) {
@@ -437,8 +434,6 @@ int ff_d3d12va_common_end_frame(AVCodecContext *avctx, 
AVFrame *frame,
 {
 int ret;
 D3D12VADecodeContext   *ctx   = D3D12VA_DECODE_CONTEXT(avctx);
-AVHWFramesContext  *frames_ctx= D3D12VA_FRAMES_CONTEXT(avctx);
-AVD3D12VAFramesContext *frames_hwctx  = frames_ctx->hwctx;
 ID3D12Resource *buffer= NULL;
 ID3D12CommandAllocator *command_allocator = NULL;
 AVD3D12VAFrame *f = (AVD3D12VAFrame 
*)frame->data[0];
diff --git a/libavcodec/d3d12va_h264.c b/libavcodec/d3d12va_h264.c
index 5a6d6852c8..be5cf0d527 100644
--- a/libavcodec/d3d12va_h264.c
+++ b/libavcodec/d3d12va_h264.c
@@ -104,10 +104,6 @@ static int d3d12va_h264_decode_slice(AVCodecContext 
*avctx, const uint8_t 

[FFmpeg-devel] [PATCH v2 4/5] avcodec/d3d12va_decode|dxva2: add a warning to replace assertion

2023-12-27 Thread Tong Wu
Previous assertion was not useful. Now a warning is added to replace it.
For get_surface_index, we should return a zero index in case the index is not 
found.
But a warning is necessary to notify.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_decode.c | 3 +--
 libavcodec/dxva2.c  | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c
index 50d5b8d601..babb2aaa0f 100644
--- a/libavcodec/d3d12va_decode.c
+++ b/libavcodec/d3d12va_decode.c
@@ -20,7 +20,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
 #include 
 #include 
 
@@ -80,7 +79,7 @@ unsigned ff_d3d12va_get_surface_index(const AVCodecContext 
*avctx,
 }
 
 fail:
-assert(0);
+av_log(avctx, AV_LOG_WARNING, "Could not get surface index. Using 0 
instead.\n");
 return 0;
 }
 
diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index 7160a0008b..a6ad5e4dc7 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -795,7 +795,7 @@ unsigned ff_dxva2_get_surface_index(const AVCodecContext 
*avctx,
 }
 #endif
 
-assert(0);
+av_log(avctx, AV_LOG_WARNING, "Could not get surface index. Using 0 
instead.\n");
 return 0;
 }
 
-- 
2.41.0.windows.1

___
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 v2 5/5] avcodec/dxva2(h264|mpeg2|vc1): use av_assert0 instead of assert

2023-12-27 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 libavcodec/dxva2.c   |  4 ++--
 libavcodec/dxva2_h264.c  | 16 
 libavcodec/dxva2_mpeg2.c |  2 +-
 libavcodec/dxva2_vc1.c   |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index a6ad5e4dc7..ec0d9e7d1c 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -20,10 +20,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
 #include 
 #include 
 
+#include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "libavutil/log.h"
 #include "libavutil/time.h"
@@ -1012,7 +1012,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, 
AVFrame *frame,
 
 /* TODO Film Grain when possible */
 
-assert(buffer_count == 1 + (qm_size > 0) + 2);
+av_assert0(buffer_count == 1 + (qm_size > 0) + 2);
 
 #if CONFIG_D3D11VA
 if (ff_dxva2_is_d3d11(avctx))
diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c
index e0ec4878a7..0fe4152625 100644
--- a/libavcodec/dxva2_h264.c
+++ b/libavcodec/dxva2_h264.c
@@ -44,7 +44,7 @@ struct dxva2_picture_context {
 static void fill_picture_entry(DXVA_PicEntry_H264 *pic,
unsigned index, unsigned flag)
 {
-assert((index&0x7f) == index && (flag&0x01) == flag);
+av_assert0((index&0x7f) == index && (flag&0x01) == flag);
 pic->bPicEntry = index | (flag << 7);
 }
 
@@ -194,8 +194,8 @@ void ff_dxva2_h264_fill_scaling_lists(const AVCodecContext 
*avctx, AVDXVAContext
 
 static int is_slice_short(const AVCodecContext *avctx, AVDXVAContext *ctx)
 {
-assert(DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 1 ||
-   DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 2);
+av_assert0(DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 1 ||
+   DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 2);
 return DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 2;
 }
 
@@ -348,10 +348,10 @@ static int 
commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
 static const unsigned start_code_size = sizeof(start_code);
 unsigned position, size;
 
-assert(offsetof(DXVA_Slice_H264_Short, BSNALunitDataLocation) ==
-   offsetof(DXVA_Slice_H264_Long,  BSNALunitDataLocation));
-assert(offsetof(DXVA_Slice_H264_Short, SliceBytesInBuffer) ==
-   offsetof(DXVA_Slice_H264_Long,  SliceBytesInBuffer));
+av_assert0(offsetof(DXVA_Slice_H264_Short, BSNALunitDataLocation) ==
+   offsetof(DXVA_Slice_H264_Long,  BSNALunitDataLocation));
+av_assert0(offsetof(DXVA_Slice_H264_Short, SliceBytesInBuffer) ==
+   offsetof(DXVA_Slice_H264_Long,  SliceBytesInBuffer));
 
 if (is_slice_short(avctx, ctx))
 slice = _pic->slice_short[i];
@@ -453,7 +453,7 @@ static int dxva2_h264_start_frame(AVCodecContext *avctx,
 
 if (!DXVA_CONTEXT_VALID(avctx, ctx))
 return -1;
-assert(ctx_pic);
+av_assert0(ctx_pic);
 
 /* Fill up DXVA_PicParams_H264 */
 ff_dxva2_h264_fill_picture_parameters(avctx, ctx, _pic->pp);
diff --git a/libavcodec/dxva2_mpeg2.c b/libavcodec/dxva2_mpeg2.c
index 4c9ed1d761..d31a8bb872 100644
--- a/libavcodec/dxva2_mpeg2.c
+++ b/libavcodec/dxva2_mpeg2.c
@@ -264,7 +264,7 @@ static int dxva2_mpeg2_start_frame(AVCodecContext *avctx,
 
 if (!DXVA_CONTEXT_VALID(avctx, ctx))
 return -1;
-assert(ctx_pic);
+av_assert0(ctx_pic);
 
 ff_dxva2_mpeg2_fill_picture_parameters(avctx, ctx, _pic->pp);
 ff_dxva2_mpeg2_fill_quantization_matrices(avctx, ctx, _pic->qm);
diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c
index 2b1b3f97ea..f7513b2b15 100644
--- a/libavcodec/dxva2_vc1.c
+++ b/libavcodec/dxva2_vc1.c
@@ -321,7 +321,7 @@ static int dxva2_vc1_start_frame(AVCodecContext *avctx,
 
 if (!DXVA_CONTEXT_VALID(avctx, ctx))
 return -1;
-assert(ctx_pic);
+av_assert0(ctx_pic);
 
 ff_dxva2_vc1_fill_picture_parameters(avctx, ctx, _pic->pp);
 
-- 
2.41.0.windows.1

___
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 v2 1/5] avcodec/d3d12va_vp9: fix vp9 max_num_refs value

2023-12-27 Thread Tong Wu
Previous max_num_refs was based on pp.frame_refs plus 1 and it could possibly
reaches the size limit. Actually it should be the size of pp.ref_frame_map
plus 1.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_vp9.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
index bb94e18781..d6dfc905d9 100644
--- a/libavcodec/d3d12va_vp9.c
+++ b/libavcodec/d3d12va_vp9.c
@@ -148,7 +148,7 @@ static int d3d12va_vp9_decode_init(AVCodecContext *avctx)
 break;
 };
 
-ctx->max_num_ref = FF_ARRAY_ELEMS(pp.frame_refs) + 1;
+ctx->max_num_ref = FF_ARRAY_ELEMS(pp.ref_frame_map) + 1;
 
 return ff_d3d12va_decode_init(avctx);
 }
-- 
2.41.0.windows.1

___
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 v2 3/5] avcodec/d3d12va_h264: replace assert with av_assert0

2023-12-27 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_h264.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/d3d12va_h264.c b/libavcodec/d3d12va_h264.c
index 5a6d6852c8..24e1c523fa 100644
--- a/libavcodec/d3d12va_h264.c
+++ b/libavcodec/d3d12va_h264.c
@@ -60,7 +60,7 @@ static int d3d12va_h264_start_frame(AVCodecContext *avctx,
 if (!ctx)
 return -1;
 
-assert(ctx_pic);
+av_assert0(ctx_pic);
 
 ctx->used_mask = 0;
 
-- 
2.41.0.windows.1

___
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 v2 2/5] avcodec/d3d12va_decode: delete an empty line and fix a fuction alignment

2023-12-27 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_decode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c
index e0b67bf964..50d5b8d601 100644
--- a/libavcodec/d3d12va_decode.c
+++ b/libavcodec/d3d12va_decode.c
@@ -324,11 +324,10 @@ int ff_d3d12va_decode_init(AVCodecContext *avctx)
 return AVERROR(ENOMEM);
 
 ctx->objects_queue = av_fifo_alloc2(D3D12VA_VIDEO_DEC_ASYNC_DEPTH,
-  sizeof(HelperObjects), 
AV_FIFO_FLAG_AUTO_GROW);
+sizeof(HelperObjects), 
AV_FIFO_FLAG_AUTO_GROW);
 if (!ctx->objects_queue)
 return AVERROR(ENOMEM);
 
-
 DX_CHECK(ID3D12Device_CreateFence(ctx->device_ctx->device, 0, 
D3D12_FENCE_FLAG_NONE,
   _ID3D12Fence, (void 
**)>sync_ctx.fence));
 
-- 
2.41.0.windows.1

___
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 5/5] avcodec/dxva2(h264|mpeg2|vc1): use av_assert0 instead of assert

2023-12-25 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 libavcodec/dxva2.c   |  6 +++---
 libavcodec/dxva2_h264.c  | 16 
 libavcodec/dxva2_mpeg2.c |  2 +-
 libavcodec/dxva2_vc1.c   |  2 +-
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index 7160a0008b..c60393a60b 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -20,10 +20,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
 #include 
 #include 
 
+#include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "libavutil/log.h"
 #include "libavutil/time.h"
@@ -795,7 +795,7 @@ unsigned ff_dxva2_get_surface_index(const AVCodecContext 
*avctx,
 }
 #endif
 
-assert(0);
+av_assert0(0);
 return 0;
 }
 
@@ -1012,7 +1012,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, 
AVFrame *frame,
 
 /* TODO Film Grain when possible */
 
-assert(buffer_count == 1 + (qm_size > 0) + 2);
+av_assert0(buffer_count == 1 + (qm_size > 0) + 2);
 
 #if CONFIG_D3D11VA
 if (ff_dxva2_is_d3d11(avctx))
diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c
index e0ec4878a7..0fe4152625 100644
--- a/libavcodec/dxva2_h264.c
+++ b/libavcodec/dxva2_h264.c
@@ -44,7 +44,7 @@ struct dxva2_picture_context {
 static void fill_picture_entry(DXVA_PicEntry_H264 *pic,
unsigned index, unsigned flag)
 {
-assert((index&0x7f) == index && (flag&0x01) == flag);
+av_assert0((index&0x7f) == index && (flag&0x01) == flag);
 pic->bPicEntry = index | (flag << 7);
 }
 
@@ -194,8 +194,8 @@ void ff_dxva2_h264_fill_scaling_lists(const AVCodecContext 
*avctx, AVDXVAContext
 
 static int is_slice_short(const AVCodecContext *avctx, AVDXVAContext *ctx)
 {
-assert(DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 1 ||
-   DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 2);
+av_assert0(DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 1 ||
+   DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 2);
 return DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 2;
 }
 
@@ -348,10 +348,10 @@ static int 
commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
 static const unsigned start_code_size = sizeof(start_code);
 unsigned position, size;
 
-assert(offsetof(DXVA_Slice_H264_Short, BSNALunitDataLocation) ==
-   offsetof(DXVA_Slice_H264_Long,  BSNALunitDataLocation));
-assert(offsetof(DXVA_Slice_H264_Short, SliceBytesInBuffer) ==
-   offsetof(DXVA_Slice_H264_Long,  SliceBytesInBuffer));
+av_assert0(offsetof(DXVA_Slice_H264_Short, BSNALunitDataLocation) ==
+   offsetof(DXVA_Slice_H264_Long,  BSNALunitDataLocation));
+av_assert0(offsetof(DXVA_Slice_H264_Short, SliceBytesInBuffer) ==
+   offsetof(DXVA_Slice_H264_Long,  SliceBytesInBuffer));
 
 if (is_slice_short(avctx, ctx))
 slice = _pic->slice_short[i];
@@ -453,7 +453,7 @@ static int dxva2_h264_start_frame(AVCodecContext *avctx,
 
 if (!DXVA_CONTEXT_VALID(avctx, ctx))
 return -1;
-assert(ctx_pic);
+av_assert0(ctx_pic);
 
 /* Fill up DXVA_PicParams_H264 */
 ff_dxva2_h264_fill_picture_parameters(avctx, ctx, _pic->pp);
diff --git a/libavcodec/dxva2_mpeg2.c b/libavcodec/dxva2_mpeg2.c
index 4c9ed1d761..d31a8bb872 100644
--- a/libavcodec/dxva2_mpeg2.c
+++ b/libavcodec/dxva2_mpeg2.c
@@ -264,7 +264,7 @@ static int dxva2_mpeg2_start_frame(AVCodecContext *avctx,
 
 if (!DXVA_CONTEXT_VALID(avctx, ctx))
 return -1;
-assert(ctx_pic);
+av_assert0(ctx_pic);
 
 ff_dxva2_mpeg2_fill_picture_parameters(avctx, ctx, _pic->pp);
 ff_dxva2_mpeg2_fill_quantization_matrices(avctx, ctx, _pic->qm);
diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c
index 2b1b3f97ea..f7513b2b15 100644
--- a/libavcodec/dxva2_vc1.c
+++ b/libavcodec/dxva2_vc1.c
@@ -321,7 +321,7 @@ static int dxva2_vc1_start_frame(AVCodecContext *avctx,
 
 if (!DXVA_CONTEXT_VALID(avctx, ctx))
 return -1;
-assert(ctx_pic);
+av_assert0(ctx_pic);
 
 ff_dxva2_vc1_fill_picture_parameters(avctx, ctx, _pic->pp);
 
-- 
2.41.0.windows.1

___
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 4/5] avcodec/d3d12va_decode: remove assertion from get_surface_index

2023-12-25 Thread Tong Wu
Return zero for failed case and avoid aborting the program.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_decode.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c
index 50d5b8d601..20dc485284 100644
--- a/libavcodec/d3d12va_decode.c
+++ b/libavcodec/d3d12va_decode.c
@@ -20,7 +20,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
 #include 
 #include 
 
@@ -80,7 +79,6 @@ unsigned ff_d3d12va_get_surface_index(const AVCodecContext 
*avctx,
 }
 
 fail:
-assert(0);
 return 0;
 }
 
-- 
2.41.0.windows.1

___
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 3/5] avcodec/d3d12va_h264: replace assert with av_assert0

2023-12-25 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_h264.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/d3d12va_h264.c b/libavcodec/d3d12va_h264.c
index 5a6d6852c8..24e1c523fa 100644
--- a/libavcodec/d3d12va_h264.c
+++ b/libavcodec/d3d12va_h264.c
@@ -60,7 +60,7 @@ static int d3d12va_h264_start_frame(AVCodecContext *avctx,
 if (!ctx)
 return -1;
 
-assert(ctx_pic);
+av_assert0(ctx_pic);
 
 ctx->used_mask = 0;
 
-- 
2.41.0.windows.1

___
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 2/5] avcodec/d3d12va_decode: delete an empty line and fix a fuction alignment

2023-12-25 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_decode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c
index e0b67bf964..50d5b8d601 100644
--- a/libavcodec/d3d12va_decode.c
+++ b/libavcodec/d3d12va_decode.c
@@ -324,11 +324,10 @@ int ff_d3d12va_decode_init(AVCodecContext *avctx)
 return AVERROR(ENOMEM);
 
 ctx->objects_queue = av_fifo_alloc2(D3D12VA_VIDEO_DEC_ASYNC_DEPTH,
-  sizeof(HelperObjects), 
AV_FIFO_FLAG_AUTO_GROW);
+sizeof(HelperObjects), 
AV_FIFO_FLAG_AUTO_GROW);
 if (!ctx->objects_queue)
 return AVERROR(ENOMEM);
 
-
 DX_CHECK(ID3D12Device_CreateFence(ctx->device_ctx->device, 0, 
D3D12_FENCE_FLAG_NONE,
   _ID3D12Fence, (void 
**)>sync_ctx.fence));
 
-- 
2.41.0.windows.1

___
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 1/5] avcodec/d3d12va_vp9: fix vp9 max_num_refs value

2023-12-25 Thread Tong Wu
Previous max_num_refs was based on pp.frame_refs plus 1 and it could possibly
reaches the size limit. Actually it should be the size of pp.ref_frame_map
plus 1.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_vp9.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
index bb94e18781..d6dfc905d9 100644
--- a/libavcodec/d3d12va_vp9.c
+++ b/libavcodec/d3d12va_vp9.c
@@ -148,7 +148,7 @@ static int d3d12va_vp9_decode_init(AVCodecContext *avctx)
 break;
 };
 
-ctx->max_num_ref = FF_ARRAY_ELEMS(pp.frame_refs) + 1;
+ctx->max_num_ref = FF_ARRAY_ELEMS(pp.ref_frame_map) + 1;
 
 return ff_d3d12va_decode_init(avctx);
 }
-- 
2.41.0.windows.1

___
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 v2] avutil/hwcontext_d3d12va: remove an unused function

2023-12-21 Thread Tong Wu
It caused lacking a public declaration build error with
-Werror=missing-prototypes.

Since DXGI_FORMAT is moved to public since patch set V10, this function
is no longer useful. Now remove it.

Signed-off-by: Tong Wu 
---
 libavutil/hwcontext_d3d12va.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
index 1600d94cb0..4995518dbd 100644
--- a/libavutil/hwcontext_d3d12va.c
+++ b/libavutil/hwcontext_d3d12va.c
@@ -71,15 +71,6 @@ static void d3d12va_default_unlock(void *ctx)
 ReleaseMutex(ctx);
 }
 
-DXGI_FORMAT av_d3d12va_map_sw_to_hw_format(enum AVPixelFormat pix_fmt)
-{
-switch (pix_fmt) {
-case AV_PIX_FMT_NV12:return DXGI_FORMAT_NV12;
-case AV_PIX_FMT_P010:return DXGI_FORMAT_P010;
-default: return DXGI_FORMAT_UNKNOWN;
-}
-}
-
 static int d3d12va_fence_completion(AVD3D12VASyncContext *psync_ctx)
 {
 uint64_t completion = ID3D12Fence_GetCompletedValue(psync_ctx->fence);
-- 
2.41.0.windows.1

___
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] avutil/hwcontext_d3d12va: remove an unused function

2023-12-21 Thread Tong Wu
Signed-off-by: Tong Wu 
---
 libavutil/hwcontext_d3d12va.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
index 1600d94cb0..4995518dbd 100644
--- a/libavutil/hwcontext_d3d12va.c
+++ b/libavutil/hwcontext_d3d12va.c
@@ -71,15 +71,6 @@ static void d3d12va_default_unlock(void *ctx)
 ReleaseMutex(ctx);
 }
 
-DXGI_FORMAT av_d3d12va_map_sw_to_hw_format(enum AVPixelFormat pix_fmt)
-{
-switch (pix_fmt) {
-case AV_PIX_FMT_NV12:return DXGI_FORMAT_NV12;
-case AV_PIX_FMT_P010:return DXGI_FORMAT_P010;
-default: return DXGI_FORMAT_UNKNOWN;
-}
-}
-
 static int d3d12va_fence_completion(AVD3D12VASyncContext *psync_ctx)
 {
 uint64_t completion = ID3D12Fence_GetCompletedValue(psync_ctx->fence);
-- 
2.41.0.windows.1

___
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 7/9] avcodec: add D3D12VA hardware accelerated VC1 decoding

2023-12-04 Thread Tong Wu
From: Wu Jianhua 

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   |   3 +
 libavcodec/Makefile |   1 +
 libavcodec/d3d12va_vc1.c| 214 
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/dxva2_vc1.c  |  15 +--
 libavcodec/hwaccels.h   |   2 +
 libavcodec/vc1dec.c |   9 ++
 7 files changed, 241 insertions(+), 7 deletions(-)
 create mode 100644 libavcodec/d3d12va_vc1.c

diff --git a/configure b/configure
index 7981833ec3..4b8545ace2 100755
--- a/configure
+++ b/configure
@@ -3156,6 +3156,8 @@ vc1_d3d11va_hwaccel_deps="d3d11va"
 vc1_d3d11va_hwaccel_select="vc1_decoder"
 vc1_d3d11va2_hwaccel_deps="d3d11va"
 vc1_d3d11va2_hwaccel_select="vc1_decoder"
+vc1_d3d12va_hwaccel_deps="d3d12va"
+vc1_d3d12va_hwaccel_select="vc1_decoder"
 vc1_dxva2_hwaccel_deps="dxva2"
 vc1_dxva2_hwaccel_select="vc1_decoder"
 vc1_nvdec_hwaccel_deps="nvdec"
@@ -3186,6 +3188,7 @@ vp9_videotoolbox_hwaccel_deps="videotoolbox"
 vp9_videotoolbox_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
+wmv3_d3d12va_hwaccel_select="vc1_d3d12va_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
 wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 889f844031..5dd5ea68a6 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1039,6 +1039,7 @@ OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
 OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
+OBJS-$(CONFIG_VC1_D3D12VA_HWACCEL)+= dxva2_vc1.o d3d12va_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
 OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
new file mode 100644
index 00..3d15abd1f1
--- /dev/null
+++ b/libavcodec/d3d12va_vc1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D12 WMV3/VC-1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "vc1.h"
+#include "vc1data.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters pp;
+unsigned   slice_count;
+DXVA_SliceInfo slices[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const VC1Context  *v   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
v->s.current_picture_ptr->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+ff_dxva2_vc1_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_vc1_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VC1Con

[FFmpeg-devel] [PATCH v12 9/9] avcodec/d3d12va_hevc: enable allow_profile_mismatch flag for d3d12va msp profile

2023-12-04 Thread Tong Wu
Same as d3d11va, this flag enables main still picture profile for
d3d12va. User should add this flag when decoding main still picture
profile.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_hevc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index 6537e46065..7e0c295a2d 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -176,8 +176,13 @@ static int d3d12va_hevc_decode_init(AVCodecContext *avctx)
 break;
 
 case FF_PROFILE_HEVC_MAIN_STILL_PICTURE:
-av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
-return AVERROR(EINVAL);
+if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) {
+ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN;
+break;
+} else {
+av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
+return AVERROR(EINVAL);
+}
 
 case FF_PROFILE_HEVC_MAIN:
 default:
-- 
2.41.0.windows.1

___
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 8/9] Changelog: D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding

2023-12-04 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index f00bc27ca4..d4f8bd42b7 100644
--- a/Changelog
+++ b/Changelog
@@ -7,6 +7,7 @@ version :
 - EVC encoding using external library libxeve
 - QOA decoder and demuxer
 - aap filter
+- D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
 
 version 6.1:
 - libaribcaption decoder
-- 
2.41.0.windows.1

___
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 6/9] avcodec: add D3D12VA hardware accelerated MPEG-2 decoding

2023-12-04 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_mpeg2.c  | 191 
 libavcodec/dxva2_internal.h |   6 ++
 libavcodec/dxva2_mpeg2.c|  20 ++--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/mpeg12dec.c  |   6 ++
 7 files changed, 217 insertions(+), 10 deletions(-)
 create mode 100644 libavcodec/d3d12va_mpeg2.c

diff --git a/configure b/configure
index b5a096de7d..7981833ec3 100755
--- a/configure
+++ b/configure
@@ -3130,6 +3130,8 @@ mpeg2_d3d11va_hwaccel_deps="d3d11va"
 mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
 mpeg2_d3d11va2_hwaccel_deps="d3d11va"
 mpeg2_d3d11va2_hwaccel_select="mpeg2video_decoder"
+mpeg2_d3d12va_hwaccel_deps="d3d12va"
+mpeg2_d3d12va_hwaccel_select="mpeg2video_decoder"
 mpeg2_dxva2_hwaccel_deps="dxva2"
 mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
 mpeg2_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 730dcf373f..889f844031 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1027,6 +1027,7 @@ OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= 
vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
+OBJS-$(CONFIG_MPEG2_D3D12VA_HWACCEL)  += dxva2_mpeg2.o d3d12va_mpeg2.o
 OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
 OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
diff --git a/libavcodec/d3d12va_mpeg2.c b/libavcodec/d3d12va_mpeg2.c
new file mode 100644
index 00..91bf3f8b75
--- /dev/null
+++ b/libavcodec/d3d12va_mpeg2.c
@@ -0,0 +1,191 @@
+/*
+ * Direct3D12 MPEG-2 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters  pp;
+DXVA_QmatrixDataqm;
+unsignedslice_count;
+DXVA_SliceInfo  slices[MAX_SLICES];
+const uint8_t  *bitstream;
+unsignedbitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+DXVA_QmatrixData  *qm  = _pic->qm;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+ff_dxva2_mpeg2_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ff_dxva2_mpeg2_fill_quantization_matrices(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+// Post processing operations are not supported in D3D12 Video
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+
+int is_field = s->picture_structure != PICT_FRAME;
+
+if (ctx_pic

[FFmpeg-devel] [PATCH v12 5/9] avcodec: add D3D12VA hardware accelerated AV1 decoding

2023-12-04 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/av1dec.c |  10 ++
 libavcodec/d3d12va_av1.c| 214 
 libavcodec/dxva2_av1.c  |   8 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 237 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/d3d12va_av1.c

diff --git a/configure b/configure
index cb4d74a321..b5a096de7d 100755
--- a/configure
+++ b/configure
@@ -3064,6 +3064,8 @@ av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va_hwaccel_select="av1_decoder"
 av1_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va2_hwaccel_select="av1_decoder"
+av1_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_AV1"
+av1_d3d12va_hwaccel_select="av1_decoder"
 av1_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_AV1"
 av1_dxva2_hwaccel_select="av1_decoder"
 av1_nvdec_hwaccel_deps="nvdec CUVIDAV1PICPARAMS"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index dd193115d4..730dcf373f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -996,6 +996,7 @@ OBJS-$(CONFIG_VULKAN) += vulkan.o 
vulkan_video.o
 
 OBJS-$(CONFIG_AV1_D3D11VA_HWACCEL)+= dxva2_av1.o
 OBJS-$(CONFIG_AV1_DXVA2_HWACCEL)  += dxva2_av1.o
+OBJS-$(CONFIG_AV1_D3D12VA_HWACCEL)+= dxva2_av1.o d3d12va_av1.o
 OBJS-$(CONFIG_AV1_NVDEC_HWACCEL)  += nvdec_av1.o
 OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)  += vaapi_av1.o
 OBJS-$(CONFIG_AV1_VDPAU_HWACCEL)  += vdpau_av1.o
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 6114cb78e6..d23627f184 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -511,6 +511,7 @@ static int get_pixel_format(AVCodecContext *avctx)
 enum AVPixelFormat pix_fmt = get_sw_pixel_format(avctx, seq);
 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
+ CONFIG_AV1_D3D12VA_HWACCEL + \
  CONFIG_AV1_NVDEC_HWACCEL + \
  CONFIG_AV1_VAAPI_HWACCEL + \
  CONFIG_AV1_VDPAU_HWACCEL + \
@@ -529,6 +530,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -550,6 +554,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -1507,6 +1514,9 @@ const FFCodec ff_av1_decoder = {
 #if CONFIG_AV1_D3D11VA2_HWACCEL
 HWACCEL_D3D11VA2(av1),
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+HWACCEL_D3D12VA(av1),
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 HWACCEL_NVDEC(av1),
 #endif
diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
new file mode 100644
index 00..6a3543353f
--- /dev/null
+++ b/libavcodec/d3d12va_av1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D 12 AV1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "av1dec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+#define MAX_TILES 256
+
+typedef struct D3D12AV1DecodeContext {
+D3D12VADecodeContext ctx;
+uint8_t *bitstream_buffer;
+} D3D12AV1DecodeContext;
+
+#define D3D12_AV1_DECODE_CONTEXT(avctx) ((D3D12AV1DecodeContext 
*)D3D12VA_DECODE_CONTEXT(avctx))
+
+typedef struct AV1DecodePictureContext {
+DXVA_PicParams_AV1  pp;
+unsignedtile_count;
+DXVA_Tile_AV1   tiles[MAX_

[FFmpeg-devel] [PATCH v12 4/9] avcodec: add D3D12VA hardware accelerated VP9 decoding

2023-12-04 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_vp9.c| 171 
 libavcodec/dxva2_internal.h |   2 +
 libavcodec/dxva2_vp9.c  |  11 +--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/vp9.c|   7 ++
 7 files changed, 190 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/d3d12va_vp9.c

diff --git a/configure b/configure
index f1a9406123..cb4d74a321 100755
--- a/configure
+++ b/configure
@@ -3168,6 +3168,8 @@ vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va_hwaccel_select="vp9_decoder"
 vp9_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va2_hwaccel_select="vp9_decoder"
+vp9_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_VP9"
+vp9_d3d12va_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 66284b3420..dd193115d4 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1045,6 +1045,7 @@ OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)  += nvdec_vp8.o
 OBJS-$(CONFIG_VP8_VAAPI_HWACCEL)  += vaapi_vp8.o
 OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)+= dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
+OBJS-$(CONFIG_VP9_D3D12VA_HWACCEL)+= dxva2_vp9.o d3d12va_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
new file mode 100644
index 00..bb94e18781
--- /dev/null
+++ b/libavcodec/d3d12va_vp9.c
@@ -0,0 +1,171 @@
+/*
+ * Direct3D 12 VP9 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+
+#include "vp9shared.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+typedef struct VP9DecodePictureContext {
+DXVA_PicParams_VP9pp;
+DXVA_Slice_VPx_Short  slice;
+const uint8_t*bitstream;
+unsigned  bitstream_size;
+} VP9DecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_VPx_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_vp9_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+if (ff_dxva2_vp9_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp) < 0)
+return -1;
+
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream = NULL;
+
+return 0;
+}
+
+static int d3d12va_vp9_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+unsigned position;
+
+if (!ctx_pic->bitstream)
+ctx_pic->bitstream = buffer;
+ctx_pic->bitstream_size += size;
+
+position = buffer - ctx_pic->bitstream;
+fill_slice_short(_pic->slice, position, size);
+
+return 0;
+}
+
+static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
+{

[FFmpeg-devel] [PATCH v12 3/9] avcodec: add D3D12VA hardware accelerated HEVC decoding

2023-12-04 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_hevc.c   | 208 
 libavcodec/dxva2_hevc.c |  14 +--
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hevcdec.c|  10 ++
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 234 insertions(+), 6 deletions(-)
 create mode 100644 libavcodec/d3d12va_hevc.c

diff --git a/configure b/configure
index 90b20da49a..f1a9406123 100755
--- a/configure
+++ b/configure
@@ -3100,6 +3100,8 @@ hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va_hwaccel_select="hevc_decoder"
 hevc_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va2_hwaccel_select="hevc_decoder"
+hevc_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_HEVC"
+hevc_d3d12va_hwaccel_select="hevc_decoder"
 hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ead3a4480e..66284b3420 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1013,6 +1013,7 @@ OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL)  += 
videotoolbox.o
 OBJS-$(CONFIG_H264_VULKAN_HWACCEL)+= vulkan_decode.o vulkan_h264.o
 OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL)   += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
+OBJS-$(CONFIG_HEVC_D3D12VA_HWACCEL)   += dxva2_hevc.o d3d12va_hevc.o
 OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o
diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
new file mode 100644
index 00..6537e46065
--- /dev/null
+++ b/libavcodec/d3d12va_hevc.c
@@ -0,0 +1,208 @@
+/*
+ * Direct3D 12 HEVC HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "hevc_data.h"
+#include "hevcdec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+#include 
+
+#define MAX_SLICES 256
+
+typedef struct HEVCDecodePictureContext {
+DXVA_PicParams_HEVCpp;
+DXVA_Qmatrix_HEVC  qm;
+unsigned   slice_count;
+DXVA_Slice_HEVC_Short  slice_short[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} HEVCDecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_HEVC_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_hevc_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+HEVCDecodePictureContext *ctx_pic = h->ref->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+ff_dxva2_hevc_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+
+ff_dxva2_hevc_fill_scaling_lists(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+ctx_pic->slice_count= 0;
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream  = NULL;
+
+return 0;
+}
+
+static int d3d12va_hevc_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+const HEVCFrame  *current_picture = h->ref;
+HEVCDecodePictureContext *ctx_pic = 
current_picture->hwaccel_picture_private;
+unsigned position;
+
+if (ctx_pic->slice

[FFmpeg-devel] [PATCH v12 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-12-04 Thread Tong Wu
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 det

[FFmpeg-devel] [PATCH v12 1/9] libavutil: add hwcontext_d3d12va and AV_PIX_FMT_D3D12

2023-12-04 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---

Compared to v11, v12 set the initial value to 0 for the fence value,
fixing a potential dynamic pool sync issue. Hence removed the non zero 
initial_pool_size for
d3d12va decoder. 

Some other minor error message changes.



 configure  |   5 +
 doc/APIchanges |   5 +
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_d3d12va.c  | 703 +
 libavutil/hwcontext_d3d12va.h  | 134 +
 libavutil/hwcontext_d3d12va_internal.h |  59 +++
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   7 +
 libavutil/tests/hwdevice.c |   2 +
 libavutil/version.h|   2 +-
 13 files changed, 929 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/hwcontext_d3d12va.c
 create mode 100644 libavutil/hwcontext_d3d12va.h
 create mode 100644 libavutil/hwcontext_d3d12va_internal.h

diff --git a/configure b/configure
index d77c053226..1a343ac6b9 100755
--- a/configure
+++ b/configure
@@ -336,6 +336,7 @@ External library support:
   --disable-cuda-llvm  disable CUDA compilation using clang [autodetect]
   --disable-cuvid  disable Nvidia CUVID support [autodetect]
   --disable-d3d11vadisable Microsoft Direct3D 11 video acceleration 
code [autodetect]
+  --disable-d3d12vadisable Microsoft Direct3D 12 video acceleration 
code [autodetect]
   --disable-dxva2  disable Microsoft DirectX 9 video acceleration code 
[autodetect]
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
@@ -1926,6 +1927,7 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
 cuda_llvm
 cuvid
 d3d11va
+d3d12va
 dxva2
 ffnvcodec
 nvdec
@@ -3048,6 +3050,7 @@ crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 cuda_deps="ffnvcodec"
 cuvid_deps="ffnvcodec"
 d3d11va_deps="dxva_h ID3D11VideoDecoder ID3D11VideoContext"
+d3d12va_deps="dxva_h ID3D12Device ID3D12VideoDecoder"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 ffnvcodec_deps_any="libdl LoadLibrary"
 mediacodec_deps="android"
@@ -6575,6 +6578,8 @@ check_type "windows.h dxgi1_2.h" "IDXGIOutput1"
 check_type "windows.h dxgi1_5.h" "IDXGIOutput5"
 check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "windows.h d3d11.h" "ID3D11VideoContext"
+check_type "windows.h d3d12.h" "ID3D12Device"
+check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
 check_type "windows.h" "DPI_AWARENESS_CONTEXT" -D_WIN32_WINNT=0x0A00
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
diff --git a/doc/APIchanges b/doc/APIchanges
index 4a2dc1c44f..0435926d80 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-11-07 - xx - lavu 58.33.100 - pixfmt.h hwcontext.h 
hwcontext_d3d12va.h
+  Add AV_HWDEVICE_TYPE_D3D12VA and AV_PIX_FMT_D3D12.
+  Add AVD3D12VADeviceContext, AVD3D12VASyncContext, AVD3D12VAFrame and
+  AVD3D12VAFramesContext.
+
 2023-11-08 - b82957a66a7 - lavu 58.32.100 - channel_layout.h
   Add AV_CH_LAYOUT_7POINT2POINT3 and AV_CHANNEL_LAYOUT_7POINT2POINT3.
   Add AV_CH_LAYOUT_9POINT1POINT4_BACK and AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK.
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 4711f8cde8..6a8566f1d9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -42,6 +42,7 @@ HEADERS = adler32.h   
  \
   hwcontext.h   \
   hwcontext_cuda.h  \
   hwcontext_d3d11va.h   \
+  hwcontext_d3d12va.h   \
   hwcontext_drm.h   \
   hwcontext_dxva2.h \
   hwcontext_qsv.h   \
@@ -190,6 +191,7 @@ OBJS = adler32.o
\
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
+OBJS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.o
 OBJS-$(CONFIG_DXVA2)+= hwcont

[FFmpeg-devel] [PATCH v11 7/9] avcodec: add D3D12VA hardware accelerated VC1 decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

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   |   3 +
 libavcodec/Makefile |   1 +
 libavcodec/d3d12va_vc1.c| 214 
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/dxva2_vc1.c  |  15 +--
 libavcodec/hwaccels.h   |   2 +
 libavcodec/vc1dec.c |   9 ++
 7 files changed, 241 insertions(+), 7 deletions(-)
 create mode 100644 libavcodec/d3d12va_vc1.c

diff --git a/configure b/configure
index 000ea76c34..72f6edce91 100755
--- a/configure
+++ b/configure
@@ -3156,6 +3156,8 @@ vc1_d3d11va_hwaccel_deps="d3d11va"
 vc1_d3d11va_hwaccel_select="vc1_decoder"
 vc1_d3d11va2_hwaccel_deps="d3d11va"
 vc1_d3d11va2_hwaccel_select="vc1_decoder"
+vc1_d3d12va_hwaccel_deps="d3d12va"
+vc1_d3d12va_hwaccel_select="vc1_decoder"
 vc1_dxva2_hwaccel_deps="dxva2"
 vc1_dxva2_hwaccel_select="vc1_decoder"
 vc1_nvdec_hwaccel_deps="nvdec"
@@ -3186,6 +3188,7 @@ vp9_videotoolbox_hwaccel_deps="videotoolbox"
 vp9_videotoolbox_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
+wmv3_d3d12va_hwaccel_select="vc1_d3d12va_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
 wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 00c1c01cbd..cc2f922b8e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1039,6 +1039,7 @@ OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
 OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
+OBJS-$(CONFIG_VC1_D3D12VA_HWACCEL)+= dxva2_vc1.o d3d12va_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
 OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
new file mode 100644
index 00..3d15abd1f1
--- /dev/null
+++ b/libavcodec/d3d12va_vc1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D12 WMV3/VC-1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "vc1.h"
+#include "vc1data.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters pp;
+unsigned   slice_count;
+DXVA_SliceInfo slices[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const VC1Context  *v   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
v->s.current_picture_ptr->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+ff_dxva2_vc1_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_vc1_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VC1Con

[FFmpeg-devel] [PATCH v11 9/9] avcodec/d3d12va_hevc: enable allow_profile_mismatch flag for d3d12va msp profile

2023-12-02 Thread Tong Wu
Same as d3d11va, this flag enables main still picture profile for
d3d12va. User should add this flag when decoding main still picture
profile.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_hevc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index 6537e46065..7e0c295a2d 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -176,8 +176,13 @@ static int d3d12va_hevc_decode_init(AVCodecContext *avctx)
 break;
 
 case FF_PROFILE_HEVC_MAIN_STILL_PICTURE:
-av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
-return AVERROR(EINVAL);
+if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) {
+ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN;
+break;
+} else {
+av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
+return AVERROR(EINVAL);
+}
 
 case FF_PROFILE_HEVC_MAIN:
 default:
-- 
2.41.0.windows.1

___
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 v11 8/9] Changelog: D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index f00bc27ca4..d4f8bd42b7 100644
--- a/Changelog
+++ b/Changelog
@@ -7,6 +7,7 @@ version :
 - EVC encoding using external library libxeve
 - QOA decoder and demuxer
 - aap filter
+- D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
 
 version 6.1:
 - libaribcaption decoder
-- 
2.41.0.windows.1

___
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 v11 6/9] avcodec: add D3D12VA hardware accelerated MPEG-2 decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_mpeg2.c  | 191 
 libavcodec/dxva2_internal.h |   6 ++
 libavcodec/dxva2_mpeg2.c|  20 ++--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/mpeg12dec.c  |   6 ++
 7 files changed, 217 insertions(+), 10 deletions(-)
 create mode 100644 libavcodec/d3d12va_mpeg2.c

diff --git a/configure b/configure
index 7feeeddaf5..000ea76c34 100755
--- a/configure
+++ b/configure
@@ -3130,6 +3130,8 @@ mpeg2_d3d11va_hwaccel_deps="d3d11va"
 mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
 mpeg2_d3d11va2_hwaccel_deps="d3d11va"
 mpeg2_d3d11va2_hwaccel_select="mpeg2video_decoder"
+mpeg2_d3d12va_hwaccel_deps="d3d12va"
+mpeg2_d3d12va_hwaccel_select="mpeg2video_decoder"
 mpeg2_dxva2_hwaccel_deps="dxva2"
 mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
 mpeg2_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 0f152df17c..00c1c01cbd 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1027,6 +1027,7 @@ OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= 
vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
+OBJS-$(CONFIG_MPEG2_D3D12VA_HWACCEL)  += dxva2_mpeg2.o d3d12va_mpeg2.o
 OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
 OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
diff --git a/libavcodec/d3d12va_mpeg2.c b/libavcodec/d3d12va_mpeg2.c
new file mode 100644
index 00..91bf3f8b75
--- /dev/null
+++ b/libavcodec/d3d12va_mpeg2.c
@@ -0,0 +1,191 @@
+/*
+ * Direct3D12 MPEG-2 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters  pp;
+DXVA_QmatrixDataqm;
+unsignedslice_count;
+DXVA_SliceInfo  slices[MAX_SLICES];
+const uint8_t  *bitstream;
+unsignedbitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+DXVA_QmatrixData  *qm  = _pic->qm;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+ff_dxva2_mpeg2_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ff_dxva2_mpeg2_fill_quantization_matrices(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+// Post processing operations are not supported in D3D12 Video
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+
+int is_field = s->picture_structure != PICT_FRAME;
+
+if (ctx_pic

[FFmpeg-devel] [PATCH v11 5/9] avcodec: add D3D12VA hardware accelerated AV1 decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/av1dec.c |  10 ++
 libavcodec/d3d12va_av1.c| 214 
 libavcodec/dxva2_av1.c  |   8 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 237 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/d3d12va_av1.c

diff --git a/configure b/configure
index f62ab51c45..7feeeddaf5 100755
--- a/configure
+++ b/configure
@@ -3064,6 +3064,8 @@ av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va_hwaccel_select="av1_decoder"
 av1_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va2_hwaccel_select="av1_decoder"
+av1_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_AV1"
+av1_d3d12va_hwaccel_select="av1_decoder"
 av1_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_AV1"
 av1_dxva2_hwaccel_select="av1_decoder"
 av1_nvdec_hwaccel_deps="nvdec CUVIDAV1PICPARAMS"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 673f45d3b8..0f152df17c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -996,6 +996,7 @@ OBJS-$(CONFIG_VULKAN) += vulkan.o 
vulkan_video.o
 
 OBJS-$(CONFIG_AV1_D3D11VA_HWACCEL)+= dxva2_av1.o
 OBJS-$(CONFIG_AV1_DXVA2_HWACCEL)  += dxva2_av1.o
+OBJS-$(CONFIG_AV1_D3D12VA_HWACCEL)+= dxva2_av1.o d3d12va_av1.o
 OBJS-$(CONFIG_AV1_NVDEC_HWACCEL)  += nvdec_av1.o
 OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)  += vaapi_av1.o
 OBJS-$(CONFIG_AV1_VDPAU_HWACCEL)  += vdpau_av1.o
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 6114cb78e6..d23627f184 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -511,6 +511,7 @@ static int get_pixel_format(AVCodecContext *avctx)
 enum AVPixelFormat pix_fmt = get_sw_pixel_format(avctx, seq);
 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
+ CONFIG_AV1_D3D12VA_HWACCEL + \
  CONFIG_AV1_NVDEC_HWACCEL + \
  CONFIG_AV1_VAAPI_HWACCEL + \
  CONFIG_AV1_VDPAU_HWACCEL + \
@@ -529,6 +530,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -550,6 +554,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -1507,6 +1514,9 @@ const FFCodec ff_av1_decoder = {
 #if CONFIG_AV1_D3D11VA2_HWACCEL
 HWACCEL_D3D11VA2(av1),
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+HWACCEL_D3D12VA(av1),
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 HWACCEL_NVDEC(av1),
 #endif
diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
new file mode 100644
index 00..6a3543353f
--- /dev/null
+++ b/libavcodec/d3d12va_av1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D 12 AV1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "av1dec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+#define MAX_TILES 256
+
+typedef struct D3D12AV1DecodeContext {
+D3D12VADecodeContext ctx;
+uint8_t *bitstream_buffer;
+} D3D12AV1DecodeContext;
+
+#define D3D12_AV1_DECODE_CONTEXT(avctx) ((D3D12AV1DecodeContext 
*)D3D12VA_DECODE_CONTEXT(avctx))
+
+typedef struct AV1DecodePictureContext {
+DXVA_PicParams_AV1  pp;
+unsignedtile_count;
+DXVA_Tile_AV1   tiles[MAX_

[FFmpeg-devel] [PATCH v11 4/9] avcodec: add D3D12VA hardware accelerated VP9 decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_vp9.c| 171 
 libavcodec/dxva2_internal.h |   2 +
 libavcodec/dxva2_vp9.c  |  11 +--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/vp9.c|   7 ++
 7 files changed, 190 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/d3d12va_vp9.c

diff --git a/configure b/configure
index 26bd31266c..f62ab51c45 100755
--- a/configure
+++ b/configure
@@ -3168,6 +3168,8 @@ vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va_hwaccel_select="vp9_decoder"
 vp9_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va2_hwaccel_select="vp9_decoder"
+vp9_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_VP9"
+vp9_d3d12va_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 18108ebf74..673f45d3b8 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1045,6 +1045,7 @@ OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)  += nvdec_vp8.o
 OBJS-$(CONFIG_VP8_VAAPI_HWACCEL)  += vaapi_vp8.o
 OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)+= dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
+OBJS-$(CONFIG_VP9_D3D12VA_HWACCEL)+= dxva2_vp9.o d3d12va_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
new file mode 100644
index 00..bb94e18781
--- /dev/null
+++ b/libavcodec/d3d12va_vp9.c
@@ -0,0 +1,171 @@
+/*
+ * Direct3D 12 VP9 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+
+#include "vp9shared.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+typedef struct VP9DecodePictureContext {
+DXVA_PicParams_VP9pp;
+DXVA_Slice_VPx_Short  slice;
+const uint8_t*bitstream;
+unsigned  bitstream_size;
+} VP9DecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_VPx_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_vp9_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+if (ff_dxva2_vp9_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp) < 0)
+return -1;
+
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream = NULL;
+
+return 0;
+}
+
+static int d3d12va_vp9_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+unsigned position;
+
+if (!ctx_pic->bitstream)
+ctx_pic->bitstream = buffer;
+ctx_pic->bitstream_size += size;
+
+position = buffer - ctx_pic->bitstream;
+fill_slice_short(_pic->slice, position, size);
+
+return 0;
+}
+
+static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
+{

[FFmpeg-devel] [PATCH v11 3/9] avcodec: add D3D12VA hardware accelerated HEVC decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_hevc.c   | 208 
 libavcodec/dxva2_hevc.c |  14 +--
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hevcdec.c|  10 ++
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 234 insertions(+), 6 deletions(-)
 create mode 100644 libavcodec/d3d12va_hevc.c

diff --git a/configure b/configure
index 8709ec2620..26bd31266c 100755
--- a/configure
+++ b/configure
@@ -3100,6 +3100,8 @@ hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va_hwaccel_select="hevc_decoder"
 hevc_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va2_hwaccel_select="hevc_decoder"
+hevc_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_HEVC"
+hevc_d3d12va_hwaccel_select="hevc_decoder"
 hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 80a8cf5f57..18108ebf74 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1013,6 +1013,7 @@ OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL)  += 
videotoolbox.o
 OBJS-$(CONFIG_H264_VULKAN_HWACCEL)+= vulkan_decode.o vulkan_h264.o
 OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL)   += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
+OBJS-$(CONFIG_HEVC_D3D12VA_HWACCEL)   += dxva2_hevc.o d3d12va_hevc.o
 OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o
diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
new file mode 100644
index 00..6537e46065
--- /dev/null
+++ b/libavcodec/d3d12va_hevc.c
@@ -0,0 +1,208 @@
+/*
+ * Direct3D 12 HEVC HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "hevc_data.h"
+#include "hevcdec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+#include 
+
+#define MAX_SLICES 256
+
+typedef struct HEVCDecodePictureContext {
+DXVA_PicParams_HEVCpp;
+DXVA_Qmatrix_HEVC  qm;
+unsigned   slice_count;
+DXVA_Slice_HEVC_Short  slice_short[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} HEVCDecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_HEVC_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_hevc_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+HEVCDecodePictureContext *ctx_pic = h->ref->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+ff_dxva2_hevc_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+
+ff_dxva2_hevc_fill_scaling_lists(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+ctx_pic->slice_count= 0;
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream  = NULL;
+
+return 0;
+}
+
+static int d3d12va_hevc_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+const HEVCFrame  *current_picture = h->ref;
+HEVCDecodePictureContext *ctx_pic = 
current_picture->hwaccel_picture_private;
+unsigned position;
+
+if (ctx_pic->slice

[FFmpeg-devel] [PATCH v11 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-12-02 Thread Tong Wu
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 | 564 
 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, 1062 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 cdeed9bab1..8709ec2620 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 748806e702..80a8cf5f57 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..c8228fdaef
--- /dev/null
+++ b/libavcodec/d3d12va_decode.c
@@ -0,0 +1,564 @@
+/*
+ * 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 det

[FFmpeg-devel] [PATCH v11 1/9] libavutil: add hwcontext_d3d12va and AV_PIX_FMT_D3D12

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 configure  |   5 +
 doc/APIchanges |   5 +
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_d3d12va.c  | 704 +
 libavutil/hwcontext_d3d12va.h  | 134 +
 libavutil/hwcontext_d3d12va_internal.h |  59 +++
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   7 +
 libavutil/tests/hwdevice.c |   2 +
 libavutil/version.h|   2 +-
 13 files changed, 930 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/hwcontext_d3d12va.c
 create mode 100644 libavutil/hwcontext_d3d12va.h
 create mode 100644 libavutil/hwcontext_d3d12va_internal.h

diff --git a/configure b/configure
index 838e627084..cdeed9bab1 100755
--- a/configure
+++ b/configure
@@ -336,6 +336,7 @@ External library support:
   --disable-cuda-llvm  disable CUDA compilation using clang [autodetect]
   --disable-cuvid  disable Nvidia CUVID support [autodetect]
   --disable-d3d11vadisable Microsoft Direct3D 11 video acceleration 
code [autodetect]
+  --disable-d3d12vadisable Microsoft Direct3D 12 video acceleration 
code [autodetect]
   --disable-dxva2  disable Microsoft DirectX 9 video acceleration code 
[autodetect]
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
@@ -1926,6 +1927,7 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
 cuda_llvm
 cuvid
 d3d11va
+d3d12va
 dxva2
 ffnvcodec
 nvdec
@@ -3048,6 +3050,7 @@ crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 cuda_deps="ffnvcodec"
 cuvid_deps="ffnvcodec"
 d3d11va_deps="dxva_h ID3D11VideoDecoder ID3D11VideoContext"
+d3d12va_deps="dxva_h ID3D12Device ID3D12VideoDecoder"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 ffnvcodec_deps_any="libdl LoadLibrary"
 mediacodec_deps="android"
@@ -6575,6 +6578,8 @@ check_type "windows.h dxgi1_2.h" "IDXGIOutput1"
 check_type "windows.h dxgi1_5.h" "IDXGIOutput5"
 check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "windows.h d3d11.h" "ID3D11VideoContext"
+check_type "windows.h d3d12.h" "ID3D12Device"
+check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
 check_type "windows.h" "DPI_AWARENESS_CONTEXT" -D_WIN32_WINNT=0x0A00
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
diff --git a/doc/APIchanges b/doc/APIchanges
index 4a2dc1c44f..0435926d80 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-11-07 - xx - lavu 58.33.100 - pixfmt.h hwcontext.h 
hwcontext_d3d12va.h
+  Add AV_HWDEVICE_TYPE_D3D12VA and AV_PIX_FMT_D3D12.
+  Add AVD3D12VADeviceContext, AVD3D12VASyncContext, AVD3D12VAFrame and
+  AVD3D12VAFramesContext.
+
 2023-11-08 - b82957a66a7 - lavu 58.32.100 - channel_layout.h
   Add AV_CH_LAYOUT_7POINT2POINT3 and AV_CHANNEL_LAYOUT_7POINT2POINT3.
   Add AV_CH_LAYOUT_9POINT1POINT4_BACK and AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK.
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 4711f8cde8..6a8566f1d9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -42,6 +42,7 @@ HEADERS = adler32.h   
  \
   hwcontext.h   \
   hwcontext_cuda.h  \
   hwcontext_d3d11va.h   \
+  hwcontext_d3d12va.h   \
   hwcontext_drm.h   \
   hwcontext_dxva2.h \
   hwcontext_qsv.h   \
@@ -190,6 +191,7 @@ OBJS = adler32.o
\
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
+OBJS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
 OBJS-$(CONFIG_LIBDRM)   += hwcontext_drm.o
 OBJS-$(CONFIG_MACOS_KPERF)  += macos_kperf.o
@@ -213,6 +215,7 @@ SKIPHEADERS-$(HAVE_CUDA_H) += hwcontext_cuda.h
 SKIPHEADERS-$(CONFIG_CUDA) += hwcont

[FFmpeg-devel] [PATCH v10 7/9] avcodec: add D3D12VA hardware accelerated VC1 decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

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   |   3 +
 libavcodec/Makefile |   1 +
 libavcodec/d3d12va_vc1.c| 214 
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/dxva2_vc1.c  |  15 +--
 libavcodec/hwaccels.h   |   2 +
 libavcodec/vc1dec.c |   9 ++
 7 files changed, 241 insertions(+), 7 deletions(-)
 create mode 100644 libavcodec/d3d12va_vc1.c

diff --git a/configure b/configure
index 000ea76c34..72f6edce91 100755
--- a/configure
+++ b/configure
@@ -3156,6 +3156,8 @@ vc1_d3d11va_hwaccel_deps="d3d11va"
 vc1_d3d11va_hwaccel_select="vc1_decoder"
 vc1_d3d11va2_hwaccel_deps="d3d11va"
 vc1_d3d11va2_hwaccel_select="vc1_decoder"
+vc1_d3d12va_hwaccel_deps="d3d12va"
+vc1_d3d12va_hwaccel_select="vc1_decoder"
 vc1_dxva2_hwaccel_deps="dxva2"
 vc1_dxva2_hwaccel_select="vc1_decoder"
 vc1_nvdec_hwaccel_deps="nvdec"
@@ -3186,6 +3188,7 @@ vp9_videotoolbox_hwaccel_deps="videotoolbox"
 vp9_videotoolbox_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
+wmv3_d3d12va_hwaccel_select="vc1_d3d12va_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
 wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 00c1c01cbd..cc2f922b8e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1039,6 +1039,7 @@ OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
 OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
+OBJS-$(CONFIG_VC1_D3D12VA_HWACCEL)+= dxva2_vc1.o d3d12va_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
 OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
new file mode 100644
index 00..3d15abd1f1
--- /dev/null
+++ b/libavcodec/d3d12va_vc1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D12 WMV3/VC-1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "vc1.h"
+#include "vc1data.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters pp;
+unsigned   slice_count;
+DXVA_SliceInfo slices[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const VC1Context  *v   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
v->s.current_picture_ptr->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+ff_dxva2_vc1_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_vc1_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VC1Con

[FFmpeg-devel] [PATCH v10 9/9] avcodec/d3d12va_hevc: enable allow_profile_mismatch flag for d3d12va msp profile

2023-12-02 Thread Tong Wu
Same as d3d11va, this flag enables main still picture profile for
d3d12va. User should add this flag when decoding main still picture
profile.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_hevc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index 6537e46065..7e0c295a2d 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -176,8 +176,13 @@ static int d3d12va_hevc_decode_init(AVCodecContext *avctx)
 break;
 
 case FF_PROFILE_HEVC_MAIN_STILL_PICTURE:
-av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
-return AVERROR(EINVAL);
+if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) {
+ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN;
+break;
+} else {
+av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
+return AVERROR(EINVAL);
+}
 
 case FF_PROFILE_HEVC_MAIN:
 default:
-- 
2.41.0.windows.1

___
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 v10 8/9] Changelog: D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index f00bc27ca4..d4f8bd42b7 100644
--- a/Changelog
+++ b/Changelog
@@ -7,6 +7,7 @@ version :
 - EVC encoding using external library libxeve
 - QOA decoder and demuxer
 - aap filter
+- D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
 
 version 6.1:
 - libaribcaption decoder
-- 
2.41.0.windows.1

___
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 v10 6/9] avcodec: add D3D12VA hardware accelerated MPEG-2 decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_mpeg2.c  | 191 
 libavcodec/dxva2_internal.h |   6 ++
 libavcodec/dxva2_mpeg2.c|  20 ++--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/mpeg12dec.c  |   6 ++
 7 files changed, 217 insertions(+), 10 deletions(-)
 create mode 100644 libavcodec/d3d12va_mpeg2.c

diff --git a/configure b/configure
index 7feeeddaf5..000ea76c34 100755
--- a/configure
+++ b/configure
@@ -3130,6 +3130,8 @@ mpeg2_d3d11va_hwaccel_deps="d3d11va"
 mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
 mpeg2_d3d11va2_hwaccel_deps="d3d11va"
 mpeg2_d3d11va2_hwaccel_select="mpeg2video_decoder"
+mpeg2_d3d12va_hwaccel_deps="d3d12va"
+mpeg2_d3d12va_hwaccel_select="mpeg2video_decoder"
 mpeg2_dxva2_hwaccel_deps="dxva2"
 mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
 mpeg2_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 0f152df17c..00c1c01cbd 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1027,6 +1027,7 @@ OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= 
vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
+OBJS-$(CONFIG_MPEG2_D3D12VA_HWACCEL)  += dxva2_mpeg2.o d3d12va_mpeg2.o
 OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
 OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
diff --git a/libavcodec/d3d12va_mpeg2.c b/libavcodec/d3d12va_mpeg2.c
new file mode 100644
index 00..91bf3f8b75
--- /dev/null
+++ b/libavcodec/d3d12va_mpeg2.c
@@ -0,0 +1,191 @@
+/*
+ * Direct3D12 MPEG-2 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters  pp;
+DXVA_QmatrixDataqm;
+unsignedslice_count;
+DXVA_SliceInfo  slices[MAX_SLICES];
+const uint8_t  *bitstream;
+unsignedbitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+DXVA_QmatrixData  *qm  = _pic->qm;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+ff_dxva2_mpeg2_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ff_dxva2_mpeg2_fill_quantization_matrices(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+// Post processing operations are not supported in D3D12 Video
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+
+int is_field = s->picture_structure != PICT_FRAME;
+
+if (ctx_pic

[FFmpeg-devel] [PATCH v10 5/9] avcodec: add D3D12VA hardware accelerated AV1 decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/av1dec.c |  10 ++
 libavcodec/d3d12va_av1.c| 214 
 libavcodec/dxva2_av1.c  |   8 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 237 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/d3d12va_av1.c

diff --git a/configure b/configure
index f62ab51c45..7feeeddaf5 100755
--- a/configure
+++ b/configure
@@ -3064,6 +3064,8 @@ av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va_hwaccel_select="av1_decoder"
 av1_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va2_hwaccel_select="av1_decoder"
+av1_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_AV1"
+av1_d3d12va_hwaccel_select="av1_decoder"
 av1_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_AV1"
 av1_dxva2_hwaccel_select="av1_decoder"
 av1_nvdec_hwaccel_deps="nvdec CUVIDAV1PICPARAMS"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 673f45d3b8..0f152df17c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -996,6 +996,7 @@ OBJS-$(CONFIG_VULKAN) += vulkan.o 
vulkan_video.o
 
 OBJS-$(CONFIG_AV1_D3D11VA_HWACCEL)+= dxva2_av1.o
 OBJS-$(CONFIG_AV1_DXVA2_HWACCEL)  += dxva2_av1.o
+OBJS-$(CONFIG_AV1_D3D12VA_HWACCEL)+= dxva2_av1.o d3d12va_av1.o
 OBJS-$(CONFIG_AV1_NVDEC_HWACCEL)  += nvdec_av1.o
 OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)  += vaapi_av1.o
 OBJS-$(CONFIG_AV1_VDPAU_HWACCEL)  += vdpau_av1.o
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 6114cb78e6..d23627f184 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -511,6 +511,7 @@ static int get_pixel_format(AVCodecContext *avctx)
 enum AVPixelFormat pix_fmt = get_sw_pixel_format(avctx, seq);
 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
+ CONFIG_AV1_D3D12VA_HWACCEL + \
  CONFIG_AV1_NVDEC_HWACCEL + \
  CONFIG_AV1_VAAPI_HWACCEL + \
  CONFIG_AV1_VDPAU_HWACCEL + \
@@ -529,6 +530,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -550,6 +554,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -1507,6 +1514,9 @@ const FFCodec ff_av1_decoder = {
 #if CONFIG_AV1_D3D11VA2_HWACCEL
 HWACCEL_D3D11VA2(av1),
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+HWACCEL_D3D12VA(av1),
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 HWACCEL_NVDEC(av1),
 #endif
diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
new file mode 100644
index 00..6a3543353f
--- /dev/null
+++ b/libavcodec/d3d12va_av1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D 12 AV1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "av1dec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+#define MAX_TILES 256
+
+typedef struct D3D12AV1DecodeContext {
+D3D12VADecodeContext ctx;
+uint8_t *bitstream_buffer;
+} D3D12AV1DecodeContext;
+
+#define D3D12_AV1_DECODE_CONTEXT(avctx) ((D3D12AV1DecodeContext 
*)D3D12VA_DECODE_CONTEXT(avctx))
+
+typedef struct AV1DecodePictureContext {
+DXVA_PicParams_AV1  pp;
+unsignedtile_count;
+DXVA_Tile_AV1   tiles[MAX_

[FFmpeg-devel] [PATCH v10 4/9] avcodec: add D3D12VA hardware accelerated VP9 decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_vp9.c| 171 
 libavcodec/dxva2_internal.h |   2 +
 libavcodec/dxva2_vp9.c  |  11 +--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/vp9.c|   7 ++
 7 files changed, 190 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/d3d12va_vp9.c

diff --git a/configure b/configure
index 26bd31266c..f62ab51c45 100755
--- a/configure
+++ b/configure
@@ -3168,6 +3168,8 @@ vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va_hwaccel_select="vp9_decoder"
 vp9_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va2_hwaccel_select="vp9_decoder"
+vp9_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_VP9"
+vp9_d3d12va_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 18108ebf74..673f45d3b8 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1045,6 +1045,7 @@ OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)  += nvdec_vp8.o
 OBJS-$(CONFIG_VP8_VAAPI_HWACCEL)  += vaapi_vp8.o
 OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)+= dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
+OBJS-$(CONFIG_VP9_D3D12VA_HWACCEL)+= dxva2_vp9.o d3d12va_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
new file mode 100644
index 00..bb94e18781
--- /dev/null
+++ b/libavcodec/d3d12va_vp9.c
@@ -0,0 +1,171 @@
+/*
+ * Direct3D 12 VP9 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+
+#include "vp9shared.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+typedef struct VP9DecodePictureContext {
+DXVA_PicParams_VP9pp;
+DXVA_Slice_VPx_Short  slice;
+const uint8_t*bitstream;
+unsigned  bitstream_size;
+} VP9DecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_VPx_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_vp9_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+if (ff_dxva2_vp9_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp) < 0)
+return -1;
+
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream = NULL;
+
+return 0;
+}
+
+static int d3d12va_vp9_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+unsigned position;
+
+if (!ctx_pic->bitstream)
+ctx_pic->bitstream = buffer;
+ctx_pic->bitstream_size += size;
+
+position = buffer - ctx_pic->bitstream;
+fill_slice_short(_pic->slice, position, size);
+
+return 0;
+}
+
+static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
+{

[FFmpeg-devel] [PATCH v10 3/9] avcodec: add D3D12VA hardware accelerated HEVC decoding

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_hevc.c   | 208 
 libavcodec/dxva2_hevc.c |  14 +--
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hevcdec.c|  10 ++
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 234 insertions(+), 6 deletions(-)
 create mode 100644 libavcodec/d3d12va_hevc.c

diff --git a/configure b/configure
index 8709ec2620..26bd31266c 100755
--- a/configure
+++ b/configure
@@ -3100,6 +3100,8 @@ hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va_hwaccel_select="hevc_decoder"
 hevc_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va2_hwaccel_select="hevc_decoder"
+hevc_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_HEVC"
+hevc_d3d12va_hwaccel_select="hevc_decoder"
 hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 80a8cf5f57..18108ebf74 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1013,6 +1013,7 @@ OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL)  += 
videotoolbox.o
 OBJS-$(CONFIG_H264_VULKAN_HWACCEL)+= vulkan_decode.o vulkan_h264.o
 OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL)   += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
+OBJS-$(CONFIG_HEVC_D3D12VA_HWACCEL)   += dxva2_hevc.o d3d12va_hevc.o
 OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o
diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
new file mode 100644
index 00..6537e46065
--- /dev/null
+++ b/libavcodec/d3d12va_hevc.c
@@ -0,0 +1,208 @@
+/*
+ * Direct3D 12 HEVC HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "hevc_data.h"
+#include "hevcdec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+#include 
+
+#define MAX_SLICES 256
+
+typedef struct HEVCDecodePictureContext {
+DXVA_PicParams_HEVCpp;
+DXVA_Qmatrix_HEVC  qm;
+unsigned   slice_count;
+DXVA_Slice_HEVC_Short  slice_short[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} HEVCDecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_HEVC_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_hevc_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+HEVCDecodePictureContext *ctx_pic = h->ref->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ctx->used_mask = 0;
+
+ff_dxva2_hevc_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+
+ff_dxva2_hevc_fill_scaling_lists(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+ctx_pic->slice_count= 0;
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream  = NULL;
+
+return 0;
+}
+
+static int d3d12va_hevc_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+const HEVCFrame  *current_picture = h->ref;
+HEVCDecodePictureContext *ctx_pic = 
current_picture->hwaccel_picture_private;
+unsigned position;
+
+if (ctx_pic->slice

[FFmpeg-devel] [PATCH v10 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-12-02 Thread Tong Wu
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 | 564 
 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, 1061 insertions(+), 67 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 cdeed9bab1..8709ec2620 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 748806e702..80a8cf5f57 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..c8228fdaef
--- /dev/null
+++ b/libavcodec/d3d12va_decode.c
@@ -0,0 +1,564 @@
+/*
+ * 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 det

[FFmpeg-devel] [PATCH v10 1/9] libavutil: add hwcontext_d3d12va and AV_PIX_FMT_D3D12

2023-12-02 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 configure  |   5 +
 doc/APIchanges |   5 +
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_d3d12va.c  | 704 +
 libavutil/hwcontext_d3d12va.h  | 134 +
 libavutil/hwcontext_d3d12va_internal.h |  59 +++
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   7 +
 libavutil/tests/hwdevice.c |   2 +
 libavutil/version.h|   2 +-
 13 files changed, 930 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/hwcontext_d3d12va.c
 create mode 100644 libavutil/hwcontext_d3d12va.h
 create mode 100644 libavutil/hwcontext_d3d12va_internal.h

diff --git a/configure b/configure
index 838e627084..cdeed9bab1 100755
--- a/configure
+++ b/configure
@@ -336,6 +336,7 @@ External library support:
   --disable-cuda-llvm  disable CUDA compilation using clang [autodetect]
   --disable-cuvid  disable Nvidia CUVID support [autodetect]
   --disable-d3d11vadisable Microsoft Direct3D 11 video acceleration 
code [autodetect]
+  --disable-d3d12vadisable Microsoft Direct3D 12 video acceleration 
code [autodetect]
   --disable-dxva2  disable Microsoft DirectX 9 video acceleration code 
[autodetect]
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
@@ -1926,6 +1927,7 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
 cuda_llvm
 cuvid
 d3d11va
+d3d12va
 dxva2
 ffnvcodec
 nvdec
@@ -3048,6 +3050,7 @@ crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 cuda_deps="ffnvcodec"
 cuvid_deps="ffnvcodec"
 d3d11va_deps="dxva_h ID3D11VideoDecoder ID3D11VideoContext"
+d3d12va_deps="dxva_h ID3D12Device ID3D12VideoDecoder"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 ffnvcodec_deps_any="libdl LoadLibrary"
 mediacodec_deps="android"
@@ -6575,6 +6578,8 @@ check_type "windows.h dxgi1_2.h" "IDXGIOutput1"
 check_type "windows.h dxgi1_5.h" "IDXGIOutput5"
 check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "windows.h d3d11.h" "ID3D11VideoContext"
+check_type "windows.h d3d12.h" "ID3D12Device"
+check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
 check_type "windows.h" "DPI_AWARENESS_CONTEXT" -D_WIN32_WINNT=0x0A00
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
diff --git a/doc/APIchanges b/doc/APIchanges
index 4a2dc1c44f..0435926d80 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-11-07 - xx - lavu 58.33.100 - pixfmt.h hwcontext.h 
hwcontext_d3d12va.h
+  Add AV_HWDEVICE_TYPE_D3D12VA and AV_PIX_FMT_D3D12.
+  Add AVD3D12VADeviceContext, AVD3D12VASyncContext, AVD3D12VAFrame and
+  AVD3D12VAFramesContext.
+
 2023-11-08 - b82957a66a7 - lavu 58.32.100 - channel_layout.h
   Add AV_CH_LAYOUT_7POINT2POINT3 and AV_CHANNEL_LAYOUT_7POINT2POINT3.
   Add AV_CH_LAYOUT_9POINT1POINT4_BACK and AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK.
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 4711f8cde8..6a8566f1d9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -42,6 +42,7 @@ HEADERS = adler32.h   
  \
   hwcontext.h   \
   hwcontext_cuda.h  \
   hwcontext_d3d11va.h   \
+  hwcontext_d3d12va.h   \
   hwcontext_drm.h   \
   hwcontext_dxva2.h \
   hwcontext_qsv.h   \
@@ -190,6 +191,7 @@ OBJS = adler32.o
\
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
+OBJS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
 OBJS-$(CONFIG_LIBDRM)   += hwcontext_drm.o
 OBJS-$(CONFIG_MACOS_KPERF)  += macos_kperf.o
@@ -213,6 +215,7 @@ SKIPHEADERS-$(HAVE_CUDA_H) += hwcontext_cuda.h
 SKIPHEADERS-$(CONFIG_CUDA) += hwcont

[FFmpeg-devel] [PATCH v9 9/9] avcodec/d3d12va_hevc: enable allow_profile_mismatch flag for d3d12va msp profile

2023-11-07 Thread Tong Wu
Same as d3d11va, this flag enables main still picture profile for
d3d12va. User should add this flag when decoding main still picture
profile.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_hevc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index 4f6640be2f..1894fddb79 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -181,8 +181,13 @@ static int d3d12va_hevc_decode_init(AVCodecContext *avctx)
 break;
 
 case FF_PROFILE_HEVC_MAIN_STILL_PICTURE:
-av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
-return AVERROR(EINVAL);
+if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) {
+ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN;
+break;
+} else {
+av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
+return AVERROR(EINVAL);
+}
 
 case FF_PROFILE_HEVC_MAIN:
 default:
-- 
2.41.0.windows.1

___
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 v9 6/9] avcodec: add D3D12VA hardware accelerated MPEG-2 decoding

2023-11-07 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_mpeg2.c  | 191 
 libavcodec/dxva2_internal.h |   6 ++
 libavcodec/dxva2_mpeg2.c|  18 ++--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/mpeg12dec.c  |   6 ++
 7 files changed, 216 insertions(+), 9 deletions(-)
 create mode 100644 libavcodec/d3d12va_mpeg2.c

diff --git a/configure b/configure
index 3cac120b1c..2fd864f3ef 100755
--- a/configure
+++ b/configure
@@ -3123,6 +3123,8 @@ mpeg2_d3d11va_hwaccel_deps="d3d11va"
 mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
 mpeg2_d3d11va2_hwaccel_deps="d3d11va"
 mpeg2_d3d11va2_hwaccel_select="mpeg2video_decoder"
+mpeg2_d3d12va_hwaccel_deps="d3d12va"
+mpeg2_d3d12va_hwaccel_select="mpeg2video_decoder"
 mpeg2_dxva2_hwaccel_deps="dxva2"
 mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
 mpeg2_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c63982c5de..a0be346c88 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1024,6 +1024,7 @@ OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= 
vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
+OBJS-$(CONFIG_MPEG2_D3D12VA_HWACCEL)  += dxva2_mpeg2.o d3d12va_mpeg2.o
 OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
 OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
diff --git a/libavcodec/d3d12va_mpeg2.c b/libavcodec/d3d12va_mpeg2.c
new file mode 100644
index 00..fe3636d242
--- /dev/null
+++ b/libavcodec/d3d12va_mpeg2.c
@@ -0,0 +1,191 @@
+/*
+ * Direct3D12 MPEG-2 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters  pp;
+DXVA_QmatrixDataqm;
+unsignedslice_count;
+DXVA_SliceInfo  slices[MAX_SLICES];
+const uint8_t  *bitstream;
+unsignedbitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+DXVA_QmatrixData  *qm  = _pic->qm;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_mpeg2_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ff_dxva2_mpeg2_fill_quantization_matrices(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+// Post processing operations are not supported in D3D12 Video
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+
+int is_field = s->picture_structure != PICT_FRAME;
+
+if (ctx_pic->slice_count >= MAX_SLIC

[FFmpeg-devel] [PATCH v9 8/9] Changelog: D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding

2023-11-07 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 Changelog | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Changelog b/Changelog
index 8f0606fc26..c394534afb 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,9 @@
 Entries are sorted chronologically from oldest to youngest within each release,
 releases are sorted from youngest to oldest.
 
+version :
+- D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
+
 version 6.1:
 - libaribcaption decoder
 - Playdate video decoder and demuxer
-- 
2.41.0.windows.1

___
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 v9 5/9] avcodec: add D3D12VA hardware accelerated AV1 decoding

2023-11-07 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/av1dec.c |  10 ++
 libavcodec/d3d12va_av1.c| 220 
 libavcodec/dxva2_av1.c  |   5 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 241 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/d3d12va_av1.c

diff --git a/configure b/configure
index 99b6cdcb13..3cac120b1c 100755
--- a/configure
+++ b/configure
@@ -3057,6 +3057,8 @@ av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va_hwaccel_select="av1_decoder"
 av1_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va2_hwaccel_select="av1_decoder"
+av1_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_AV1"
+av1_d3d12va_hwaccel_select="av1_decoder"
 av1_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_AV1"
 av1_dxva2_hwaccel_select="av1_decoder"
 av1_nvdec_hwaccel_deps="nvdec CUVIDAV1PICPARAMS"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3d8df464ab..c63982c5de 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -993,6 +993,7 @@ OBJS-$(CONFIG_VULKAN) += vulkan.o 
vulkan_video.o
 
 OBJS-$(CONFIG_AV1_D3D11VA_HWACCEL)+= dxva2_av1.o
 OBJS-$(CONFIG_AV1_DXVA2_HWACCEL)  += dxva2_av1.o
+OBJS-$(CONFIG_AV1_D3D12VA_HWACCEL)+= dxva2_av1.o d3d12va_av1.o
 OBJS-$(CONFIG_AV1_NVDEC_HWACCEL)  += nvdec_av1.o
 OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)  += vaapi_av1.o
 OBJS-$(CONFIG_AV1_VDPAU_HWACCEL)  += vdpau_av1.o
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 6114cb78e6..d23627f184 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -511,6 +511,7 @@ static int get_pixel_format(AVCodecContext *avctx)
 enum AVPixelFormat pix_fmt = get_sw_pixel_format(avctx, seq);
 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
+ CONFIG_AV1_D3D12VA_HWACCEL + \
  CONFIG_AV1_NVDEC_HWACCEL + \
  CONFIG_AV1_VAAPI_HWACCEL + \
  CONFIG_AV1_VDPAU_HWACCEL + \
@@ -529,6 +530,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -550,6 +554,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -1507,6 +1514,9 @@ const FFCodec ff_av1_decoder = {
 #if CONFIG_AV1_D3D11VA2_HWACCEL
 HWACCEL_D3D11VA2(av1),
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+HWACCEL_D3D12VA(av1),
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 HWACCEL_NVDEC(av1),
 #endif
diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
new file mode 100644
index 00..4476f5bd8a
--- /dev/null
+++ b/libavcodec/d3d12va_av1.c
@@ -0,0 +1,220 @@
+/*
+ * Direct3D 12 AV1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "av1dec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+#define MAX_TILES 256
+
+typedef struct D3D12AV1DecodeContext {
+D3D12VADecodeContext ctx;
+uint8_t *bitstream_buffer;
+} D3D12AV1DecodeContext;
+
+#define D3D12_AV1_DECODE_CONTEXT(avctx) ((D3D12AV1DecodeContext 
*)D3D12VA_DECODE_CONTEXT(avctx))
+
+typedef struct AV1DecodePictureContext {
+DXVA_PicParams_AV1  pp;
+unsignedtile_count;
+DXVA_Tile_AV1   tiles[MAX_

[FFmpeg-devel] [PATCH v9 7/9] avcodec: add D3D12VA hardware accelerated VC1 decoding

2023-11-07 Thread Tong Wu
From: Wu Jianhua 

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   |   3 +
 libavcodec/Makefile |   1 +
 libavcodec/d3d12va_vc1.c| 214 
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/dxva2_vc1.c  |  11 +-
 libavcodec/hwaccels.h   |   2 +
 libavcodec/vc1dec.c |   9 ++
 7 files changed, 239 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/d3d12va_vc1.c

diff --git a/configure b/configure
index 2fd864f3ef..f1f8b81b51 100755
--- a/configure
+++ b/configure
@@ -3149,6 +3149,8 @@ vc1_d3d11va_hwaccel_deps="d3d11va"
 vc1_d3d11va_hwaccel_select="vc1_decoder"
 vc1_d3d11va2_hwaccel_deps="d3d11va"
 vc1_d3d11va2_hwaccel_select="vc1_decoder"
+vc1_d3d12va_hwaccel_deps="d3d12va"
+vc1_d3d12va_hwaccel_select="vc1_decoder"
 vc1_dxva2_hwaccel_deps="dxva2"
 vc1_dxva2_hwaccel_select="vc1_decoder"
 vc1_nvdec_hwaccel_deps="nvdec"
@@ -3179,6 +3181,7 @@ vp9_videotoolbox_hwaccel_deps="videotoolbox"
 vp9_videotoolbox_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
+wmv3_d3d12va_hwaccel_select="vc1_d3d12va_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
 wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a0be346c88..fb95e9d8e9 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1036,6 +1036,7 @@ OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
 OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
+OBJS-$(CONFIG_VC1_D3D12VA_HWACCEL)+= dxva2_vc1.o d3d12va_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
 OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
new file mode 100644
index 00..73887db602
--- /dev/null
+++ b/libavcodec/d3d12va_vc1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D12 WMV3/VC-1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "vc1.h"
+#include "vc1data.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters pp;
+unsigned   slice_count;
+DXVA_SliceInfo slices[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const VC1Context  *v   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
v->s.current_picture_ptr->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_vc1_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_vc1_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VC1Context  *v   = avctx-

[FFmpeg-devel] [PATCH v9 4/9] avcodec: add D3D12VA hardware accelerated VP9 decoding

2023-11-07 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_vp9.c| 176 
 libavcodec/dxva2_internal.h |   2 +
 libavcodec/dxva2_vp9.c  |   7 +-
 libavcodec/hwaccels.h   |   1 +
 libavcodec/vp9.c|   7 ++
 7 files changed, 193 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/d3d12va_vp9.c

diff --git a/configure b/configure
index dc6ebd9768..99b6cdcb13 100755
--- a/configure
+++ b/configure
@@ -3161,6 +3161,8 @@ vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va_hwaccel_select="vp9_decoder"
 vp9_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va2_hwaccel_select="vp9_decoder"
+vp9_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_VP9"
+vp9_d3d12va_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 7fdfc1801c..3d8df464ab 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1042,6 +1042,7 @@ OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)  += nvdec_vp8.o
 OBJS-$(CONFIG_VP8_VAAPI_HWACCEL)  += vaapi_vp8.o
 OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)+= dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
+OBJS-$(CONFIG_VP9_D3D12VA_HWACCEL)+= dxva2_vp9.o d3d12va_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
new file mode 100644
index 00..6ff0c5400d
--- /dev/null
+++ b/libavcodec/d3d12va_vp9.c
@@ -0,0 +1,176 @@
+/*
+ * Direct3D 12 VP9 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+
+#include "vp9shared.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+typedef struct VP9DecodePictureContext {
+DXVA_PicParams_VP9pp;
+DXVA_Slice_VPx_Short  slice;
+const uint8_t*bitstream;
+unsigned  bitstream_size;
+} VP9DecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_VPx_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_vp9_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+if (ff_dxva2_vp9_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp) < 0)
+return -1;
+
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream = NULL;
+
+return 0;
+}
+
+static int d3d12va_vp9_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+unsigned position;
+
+if (!ctx_pic->bitstream)
+ctx_pic->bitstream = buffer;
+ctx_pic->bitstream_size += size;
+
+position = buffer - ctx_pic->bitstream;
+fill_slice_short(_pic->slice, position, size);
+
+return 0;
+}
+
+static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
+{
+D3D12VADecodeContext   *ctx  

[FFmpeg-devel] [PATCH v9 3/9] avcodec: add D3D12VA hardware accelerated HEVC decoding

2023-11-07 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_hevc.c   | 211 
 libavcodec/dxva2_hevc.c |  10 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hevcdec.c|  10 ++
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 235 insertions(+), 4 deletions(-)
 create mode 100644 libavcodec/d3d12va_hevc.c

diff --git a/configure b/configure
index 28108a95b7..dc6ebd9768 100755
--- a/configure
+++ b/configure
@@ -3093,6 +3093,8 @@ hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va_hwaccel_select="hevc_decoder"
 hevc_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va2_hwaccel_select="hevc_decoder"
+hevc_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_HEVC"
+hevc_d3d12va_hwaccel_select="hevc_decoder"
 hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 0c8026db83..7fdfc1801c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1010,6 +1010,7 @@ OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL)  += 
videotoolbox.o
 OBJS-$(CONFIG_H264_VULKAN_HWACCEL)+= vulkan_decode.o vulkan_h264.o
 OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL)   += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
+OBJS-$(CONFIG_HEVC_D3D12VA_HWACCEL)   += dxva2_hevc.o d3d12va_hevc.o
 OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o
diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
new file mode 100644
index 00..4f6640be2f
--- /dev/null
+++ b/libavcodec/d3d12va_hevc.c
@@ -0,0 +1,211 @@
+/*
+ * Direct3D 12 HEVC HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "hevc_data.h"
+#include "hevcdec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+#include 
+
+#define MAX_SLICES 256
+
+typedef struct HEVCDecodePictureContext {
+DXVA_PicParams_HEVCpp;
+DXVA_Qmatrix_HEVC  qm;
+unsigned   slice_count;
+DXVA_Slice_HEVC_Short  slice_short[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} HEVCDecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_HEVC_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_hevc_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+HEVCDecodePictureContext *ctx_pic = h->ref->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_hevc_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+
+ff_dxva2_hevc_fill_scaling_lists(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+ctx_pic->slice_count= 0;
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream  = NULL;
+
+return 0;
+}
+
+static int d3d12va_hevc_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+const HEVCFrame  *current_picture = h->ref;
+HEVCDecodePictureContext *ctx_pic = 
current_picture->hwaccel_picture_private;
+unsigned position;
+
+if (ctx_pic->slice_count >= MAX_SLICES)
+ 

[FFmpeg-devel] [PATCH v9 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-11-07 Thread Tong Wu
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 | 536 
 libavcodec/d3d12va_decode.h | 176 
 libavcodec/d3d12va_h264.c   | 210 ++
 libavcodec/dxva2.c  |  27 ++
 libavcodec/dxva2.h  |   3 -
 libavcodec/dxva2_h264.c |  12 +-
 libavcodec/dxva2_internal.h |  67 ++---
 libavcodec/h264_slice.c |   4 +
 libavcodec/h264dec.c|   3 +
 libavcodec/hwaccels.h   |   1 +
 libavcodec/hwconfig.h   |   2 +
 14 files changed, 1007 insertions(+), 42 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 69d7a48280..28108a95b7 100755
--- a/configure
+++ b/configure
@@ -3075,6 +3075,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 ab7fba394a..0c8026db83 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -983,6 +983,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
@@ -1000,6 +1001,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
@@ -1291,6 +1293,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..e194adc7ed
--- /dev/null
+++ b/libavcodec/d3d12va_decode.c
@@ -0,0 +1,536 @@
+/*
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth

[FFmpeg-devel] [PATCH v9 1/9] libavutil: add hwcontext_d3d12va and AV_PIX_FMT_D3D12

2023-11-07 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 configure  |   5 +
 doc/APIchanges |   7 +
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_d3d12va.c  | 695 +
 libavutil/hwcontext_d3d12va.h  | 142 +
 libavutil/hwcontext_d3d12va_internal.h |  59 +++
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   7 +
 libavutil/tests/hwdevice.c |   2 +
 libavutil/version.h|   2 +-
 13 files changed, 931 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/hwcontext_d3d12va.c
 create mode 100644 libavutil/hwcontext_d3d12va.h
 create mode 100644 libavutil/hwcontext_d3d12va_internal.h

diff --git a/configure b/configure
index 8ab658f730..69d7a48280 100755
--- a/configure
+++ b/configure
@@ -334,6 +334,7 @@ External library support:
   --disable-cuda-llvm  disable CUDA compilation using clang [autodetect]
   --disable-cuvid  disable Nvidia CUVID support [autodetect]
   --disable-d3d11vadisable Microsoft Direct3D 11 video acceleration 
code [autodetect]
+  --disable-d3d12vadisable Microsoft Direct3D 12 video acceleration 
code [autodetect]
   --disable-dxva2  disable Microsoft DirectX 9 video acceleration code 
[autodetect]
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
@@ -1922,6 +1923,7 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
 cuda_llvm
 cuvid
 d3d11va
+d3d12va
 dxva2
 ffnvcodec
 nvdec
@@ -3041,6 +3043,7 @@ crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 cuda_deps="ffnvcodec"
 cuvid_deps="ffnvcodec"
 d3d11va_deps="dxva_h ID3D11VideoDecoder ID3D11VideoContext"
+d3d12va_deps="dxva_h ID3D12Device ID3D12VideoDecoder"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 ffnvcodec_deps_any="libdl LoadLibrary"
 mediacodec_deps="android"
@@ -6563,6 +6566,8 @@ check_type "windows.h dxgi1_2.h" "IDXGIOutput1"
 check_type "windows.h dxgi1_5.h" "IDXGIOutput5"
 check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "windows.h d3d11.h" "ID3D11VideoContext"
+check_type "windows.h d3d12.h" "ID3D12Device"
+check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
 check_type "windows.h" "DPI_AWARENESS_CONTEXT" -D_WIN32_WINNT=0x0A00
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
diff --git a/doc/APIchanges b/doc/APIchanges
index d4511ce2dd..2e71943b34 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,13 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-11-07 - xx - lavu 58.32.100 - pixfmt.h hwcontext.h 
hwcontext_d3d12va.h
+  Add AV_HWDEVICE_TYPE_D3D12VA and AV_PIX_FMT_D3D12.
+  Add AVD3D12VADeviceContext, AVD3D12VASyncContext, AVD3D12VAFrame and
+  AVD3D12VAFramesContext.
+  Add av_d3d12va_map_sw_to_hw_format, av_d3d12va_sync_context_alloc,
+  av_d3d12va_sync_context_free.
+
 2023-10-31 - xx - lavu 58.31.100 - pixdesc.h
   Add AV_PIX_FMT_FLAG_XYZ.
 
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 4711f8cde8..6a8566f1d9 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -42,6 +42,7 @@ HEADERS = adler32.h   
  \
   hwcontext.h   \
   hwcontext_cuda.h  \
   hwcontext_d3d11va.h   \
+  hwcontext_d3d12va.h   \
   hwcontext_drm.h   \
   hwcontext_dxva2.h \
   hwcontext_qsv.h   \
@@ -190,6 +191,7 @@ OBJS = adler32.o
\
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
+OBJS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
 OBJS-$(CONFIG_LIBDRM)   += hwcontext_drm.o
 OBJS-$(CONFIG_MACOS_KPERF)  += macos_kperf.o
@@ -213,6 +215,7 @@ SKIPHEADERS-$(HAVE_CUDA_H) += hwcontext_cuda.h
 SKIPHEADERS-$(CONFIG_CUDA) += hwcont

[FFmpeg-devel] [PATCH v8 8/9] Changelog: D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding

2023-08-29 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 Changelog | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index c010e86159..bdac4cb034 100644
--- a/Changelog
+++ b/Changelog
@@ -30,7 +30,7 @@ version :
 - support for the P_SKIP hinting to speed up libx264 encoding
 - Support HEVC,VP9,AV1 codec in enhanced flv format
 - apsnr and asisdr audio filters
-
+- D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
 
 version 6.0:
 - Radiance HDR image support
-- 
2.41.0.windows.1

___
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 v8 7/9] avcodec: add D3D12VA hardware accelerated VC1 decoding

2023-08-29 Thread Tong Wu
From: Wu Jianhua 

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   |   3 +
 libavcodec/Makefile |   1 +
 libavcodec/d3d12va_vc1.c| 214 
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/dxva2_vc1.c  |  11 +-
 libavcodec/hwaccels.h   |   2 +
 libavcodec/vc1dec.c |   9 ++
 7 files changed, 239 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/d3d12va_vc1.c

diff --git a/configure b/configure
index 6c443ed420..97f4b91318 100755
--- a/configure
+++ b/configure
@@ -3162,6 +3162,8 @@ vc1_d3d11va_hwaccel_deps="d3d11va"
 vc1_d3d11va_hwaccel_select="vc1_decoder"
 vc1_d3d11va2_hwaccel_deps="d3d11va"
 vc1_d3d11va2_hwaccel_select="vc1_decoder"
+vc1_d3d12va_hwaccel_deps="d3d12va"
+vc1_d3d12va_hwaccel_select="vc1_decoder"
 vc1_dxva2_hwaccel_deps="dxva2"
 vc1_dxva2_hwaccel_select="vc1_decoder"
 vc1_nvdec_hwaccel_deps="nvdec"
@@ -3192,6 +3194,7 @@ vp9_videotoolbox_hwaccel_deps="videotoolbox"
 vp9_videotoolbox_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
+wmv3_d3d12va_hwaccel_select="vc1_d3d12va_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
 wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 88925c0c5a..a7bb02de76 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1035,6 +1035,7 @@ OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
 OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
+OBJS-$(CONFIG_VC1_D3D12VA_HWACCEL)+= dxva2_vc1.o d3d12va_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
 OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
new file mode 100644
index 00..73887db602
--- /dev/null
+++ b/libavcodec/d3d12va_vc1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D12 WMV3/VC-1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "vc1.h"
+#include "vc1data.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters pp;
+unsigned   slice_count;
+DXVA_SliceInfo slices[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const VC1Context  *v   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
v->s.current_picture_ptr->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_vc1_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_vc1_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VC1Context  *v   = avctx-

[FFmpeg-devel] [PATCH v8 9/9] avcodec/d3d12va_hevc: enable allow_profile_mismatch flag for d3d12va msp profile

2023-08-29 Thread Tong Wu
Same as d3d11va, this flag enables main still picture profile for
d3d12va. User should add this flag when decoding main still picture
profile.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_hevc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index 4f6640be2f..1894fddb79 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -181,8 +181,13 @@ static int d3d12va_hevc_decode_init(AVCodecContext *avctx)
 break;
 
 case FF_PROFILE_HEVC_MAIN_STILL_PICTURE:
-av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
-return AVERROR(EINVAL);
+if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) {
+ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN;
+break;
+} else {
+av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
+return AVERROR(EINVAL);
+}
 
 case FF_PROFILE_HEVC_MAIN:
 default:
-- 
2.41.0.windows.1

___
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 v8 6/9] avcodec: add D3D12VA hardware accelerated MPEG-2 decoding

2023-08-29 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_mpeg2.c  | 191 
 libavcodec/dxva2_internal.h |   6 ++
 libavcodec/dxva2_mpeg2.c|  18 ++--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/mpeg12dec.c  |   6 ++
 7 files changed, 216 insertions(+), 9 deletions(-)
 create mode 100644 libavcodec/d3d12va_mpeg2.c

diff --git a/configure b/configure
index 940cea2f35..6c443ed420 100755
--- a/configure
+++ b/configure
@@ -3136,6 +3136,8 @@ mpeg2_d3d11va_hwaccel_deps="d3d11va"
 mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
 mpeg2_d3d11va2_hwaccel_deps="d3d11va"
 mpeg2_d3d11va2_hwaccel_select="mpeg2video_decoder"
+mpeg2_d3d12va_hwaccel_deps="d3d12va"
+mpeg2_d3d12va_hwaccel_select="mpeg2video_decoder"
 mpeg2_dxva2_hwaccel_deps="dxva2"
 mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
 mpeg2_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a4e6fd0ee1..88925c0c5a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1023,6 +1023,7 @@ OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= 
vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
+OBJS-$(CONFIG_MPEG2_D3D12VA_HWACCEL)  += dxva2_mpeg2.o d3d12va_mpeg2.o
 OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
 OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
diff --git a/libavcodec/d3d12va_mpeg2.c b/libavcodec/d3d12va_mpeg2.c
new file mode 100644
index 00..fe3636d242
--- /dev/null
+++ b/libavcodec/d3d12va_mpeg2.c
@@ -0,0 +1,191 @@
+/*
+ * Direct3D12 MPEG-2 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters  pp;
+DXVA_QmatrixDataqm;
+unsignedslice_count;
+DXVA_SliceInfo  slices[MAX_SLICES];
+const uint8_t  *bitstream;
+unsignedbitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+DXVA_QmatrixData  *qm  = _pic->qm;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_mpeg2_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ff_dxva2_mpeg2_fill_quantization_matrices(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+// Post processing operations are not supported in D3D12 Video
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+
+int is_field = s->picture_structure != PICT_FRAME;
+
+if (ctx_pic->slice_count >= MAX_SLIC

[FFmpeg-devel] [PATCH v8 5/9] avcodec: add D3D12VA hardware accelerated AV1 decoding

2023-08-29 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/av1dec.c |  10 ++
 libavcodec/d3d12va_av1.c| 220 
 libavcodec/dxva2_av1.c  |   5 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 241 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/d3d12va_av1.c

diff --git a/configure b/configure
index 572f0c3767..940cea2f35 100755
--- a/configure
+++ b/configure
@@ -3070,6 +3070,8 @@ av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va_hwaccel_select="av1_decoder"
 av1_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va2_hwaccel_select="av1_decoder"
+av1_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_AV1"
+av1_d3d12va_hwaccel_select="av1_decoder"
 av1_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_AV1"
 av1_dxva2_hwaccel_select="av1_decoder"
 av1_nvdec_hwaccel_deps="nvdec CUVIDAV1PICPARAMS"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index f0b9bdb9e6..a4e6fd0ee1 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -992,6 +992,7 @@ OBJS-$(CONFIG_VULKAN) += vulkan.o 
vulkan_video.o
 
 OBJS-$(CONFIG_AV1_D3D11VA_HWACCEL)+= dxva2_av1.o
 OBJS-$(CONFIG_AV1_DXVA2_HWACCEL)  += dxva2_av1.o
+OBJS-$(CONFIG_AV1_D3D12VA_HWACCEL)+= dxva2_av1.o d3d12va_av1.o
 OBJS-$(CONFIG_AV1_NVDEC_HWACCEL)  += nvdec_av1.o
 OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)  += vaapi_av1.o
 OBJS-$(CONFIG_AV1_VDPAU_HWACCEL)  += vdpau_av1.o
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 03283ab064..96e2c8febb 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -449,6 +449,7 @@ static int get_pixel_format(AVCodecContext *avctx)
 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
+ CONFIG_AV1_D3D12VA_HWACCEL + \
  CONFIG_AV1_NVDEC_HWACCEL + \
  CONFIG_AV1_VAAPI_HWACCEL + \
  CONFIG_AV1_VDPAU_HWACCEL + \
@@ -524,6 +525,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -545,6 +549,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -1534,6 +1541,9 @@ const FFCodec ff_av1_decoder = {
 #if CONFIG_AV1_D3D11VA2_HWACCEL
 HWACCEL_D3D11VA2(av1),
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+HWACCEL_D3D12VA(av1),
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 HWACCEL_NVDEC(av1),
 #endif
diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
new file mode 100644
index 00..4476f5bd8a
--- /dev/null
+++ b/libavcodec/d3d12va_av1.c
@@ -0,0 +1,220 @@
+/*
+ * Direct3D 12 AV1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "av1dec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+#define MAX_TILES 256
+
+typedef struct D3D12AV1DecodeContext {
+D3D12VADecodeContext ctx;
+uint8_t *bitstream_buffer;
+} D3D12AV1DecodeContext;
+
+#define D3D12_AV1_DECODE_CONTEXT(avctx) ((D3D12AV1DecodeContext 
*)D3D12VA_DECODE_CONTEXT(avctx))
+
+typedef struct AV1DecodePictureContext {
+DXVA_PicParams_AV1  pp;
+unsignedtile_count;
+DXVA_Tile_AV1   tiles[MAX_TILES];
+uint8_t  

[FFmpeg-devel] [PATCH v8 4/9] avcodec: add D3D12VA hardware accelerated VP9 decoding

2023-08-29 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_vp9.c| 176 
 libavcodec/dxva2_internal.h |   2 +
 libavcodec/dxva2_vp9.c  |   7 +-
 libavcodec/hwaccels.h   |   1 +
 libavcodec/vp9.c|   7 ++
 7 files changed, 193 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/d3d12va_vp9.c

diff --git a/configure b/configure
index 5b471e6090..572f0c3767 100755
--- a/configure
+++ b/configure
@@ -3174,6 +3174,8 @@ vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va_hwaccel_select="vp9_decoder"
 vp9_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va2_hwaccel_select="vp9_decoder"
+vp9_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_VP9"
+vp9_d3d12va_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index eaebfc27cd..f0b9bdb9e6 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1041,6 +1041,7 @@ OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)  += nvdec_vp8.o
 OBJS-$(CONFIG_VP8_VAAPI_HWACCEL)  += vaapi_vp8.o
 OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)+= dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
+OBJS-$(CONFIG_VP9_D3D12VA_HWACCEL)+= dxva2_vp9.o d3d12va_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
new file mode 100644
index 00..6ff0c5400d
--- /dev/null
+++ b/libavcodec/d3d12va_vp9.c
@@ -0,0 +1,176 @@
+/*
+ * Direct3D 12 VP9 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+
+#include "vp9shared.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+typedef struct VP9DecodePictureContext {
+DXVA_PicParams_VP9pp;
+DXVA_Slice_VPx_Short  slice;
+const uint8_t*bitstream;
+unsigned  bitstream_size;
+} VP9DecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_VPx_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_vp9_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+if (ff_dxva2_vp9_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp) < 0)
+return -1;
+
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream = NULL;
+
+return 0;
+}
+
+static int d3d12va_vp9_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+unsigned position;
+
+if (!ctx_pic->bitstream)
+ctx_pic->bitstream = buffer;
+ctx_pic->bitstream_size += size;
+
+position = buffer - ctx_pic->bitstream;
+fill_slice_short(_pic->slice, position, size);
+
+return 0;
+}
+
+static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
+{
+D3D12VADecodeContext   *ctx  

[FFmpeg-devel] [PATCH v8 3/9] avcodec: add D3D12VA hardware accelerated HEVC decoding

2023-08-29 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_hevc.c   | 211 
 libavcodec/dxva2_hevc.c |  10 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hevcdec.c|  10 ++
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 235 insertions(+), 4 deletions(-)
 create mode 100644 libavcodec/d3d12va_hevc.c

diff --git a/configure b/configure
index 339e5f35c0..5b471e6090 100755
--- a/configure
+++ b/configure
@@ -3106,6 +3106,8 @@ hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va_hwaccel_select="hevc_decoder"
 hevc_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va2_hwaccel_select="hevc_decoder"
+hevc_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_HEVC"
+hevc_d3d12va_hwaccel_select="hevc_decoder"
 hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a7808937ce..eaebfc27cd 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1009,6 +1009,7 @@ OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL)  += 
videotoolbox.o
 OBJS-$(CONFIG_H264_VULKAN_HWACCEL)+= vulkan_decode.o vulkan_h264.o
 OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL)   += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
+OBJS-$(CONFIG_HEVC_D3D12VA_HWACCEL)   += dxva2_hevc.o d3d12va_hevc.o
 OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o
diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
new file mode 100644
index 00..4f6640be2f
--- /dev/null
+++ b/libavcodec/d3d12va_hevc.c
@@ -0,0 +1,211 @@
+/*
+ * Direct3D 12 HEVC HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "hevc_data.h"
+#include "hevcdec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+#include 
+
+#define MAX_SLICES 256
+
+typedef struct HEVCDecodePictureContext {
+DXVA_PicParams_HEVCpp;
+DXVA_Qmatrix_HEVC  qm;
+unsigned   slice_count;
+DXVA_Slice_HEVC_Short  slice_short[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} HEVCDecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_HEVC_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_hevc_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+HEVCDecodePictureContext *ctx_pic = h->ref->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_hevc_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+
+ff_dxva2_hevc_fill_scaling_lists(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+ctx_pic->slice_count= 0;
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream  = NULL;
+
+return 0;
+}
+
+static int d3d12va_hevc_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+const HEVCFrame  *current_picture = h->ref;
+HEVCDecodePictureContext *ctx_pic = 
current_picture->hwaccel_picture_private;
+unsigned position;
+
+if (ctx_pic->slice_count >= MAX_SLICES)
+ 

[FFmpeg-devel] [PATCH v8 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-08-29 Thread Tong Wu
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 | 529 
 libavcodec/d3d12va_decode.h | 176 
 libavcodec/d3d12va_h264.c   | 210 ++
 libavcodec/dxva2.c  |  27 ++
 libavcodec/dxva2.h  |   3 -
 libavcodec/dxva2_h264.c |  12 +-
 libavcodec/dxva2_internal.h |  67 ++---
 libavcodec/h264_slice.c |   4 +
 libavcodec/h264dec.c|   3 +
 libavcodec/hwaccels.h   |   1 +
 libavcodec/hwconfig.h   |   2 +
 14 files changed, 1000 insertions(+), 42 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 c604302017..339e5f35c0 100755
--- a/configure
+++ b/configure
@@ -3088,6 +3088,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 f961d0abd6..a7808937ce 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -982,6 +982,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
@@ -999,6 +1000,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
@@ -1291,6 +1293,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..c42f8f3434
--- /dev/null
+++ b/libavcodec/d3d12va_decode.c
@@ -0,0 +1,529 @@
+/*
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth

[FFmpeg-devel] [PATCH v8 1/9] libavutil: add hwcontext_d3d12va and AV_PIX_FMT_D3D12

2023-08-29 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 configure  |   5 +
 doc/APIchanges |   7 +
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_d3d12va.c  | 691 +
 libavutil/hwcontext_d3d12va.h  | 141 +
 libavutil/hwcontext_d3d12va_internal.h |  59 +++
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   7 +
 libavutil/tests/hwdevice.c |   2 +
 libavutil/version.h|   2 +-
 13 files changed, 926 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/hwcontext_d3d12va.c
 create mode 100644 libavutil/hwcontext_d3d12va.h
 create mode 100644 libavutil/hwcontext_d3d12va_internal.h

diff --git a/configure b/configure
index bd7f7697c8..c604302017 100755
--- a/configure
+++ b/configure
@@ -338,6 +338,7 @@ External library support:
   --disable-cuda-llvm  disable CUDA compilation using clang [autodetect]
   --disable-cuvid  disable Nvidia CUVID support [autodetect]
   --disable-d3d11vadisable Microsoft Direct3D 11 video acceleration 
code [autodetect]
+  --disable-d3d12vadisable Microsoft Direct3D 12 video acceleration 
code [autodetect]
   --disable-dxva2  disable Microsoft DirectX 9 video acceleration code 
[autodetect]
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
@@ -1926,6 +1927,7 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
 cuda_llvm
 cuvid
 d3d11va
+d3d12va
 dxva2
 ffnvcodec
 nvdec
@@ -3054,6 +3056,7 @@ crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 cuda_deps="ffnvcodec"
 cuvid_deps="ffnvcodec"
 d3d11va_deps="dxva_h ID3D11VideoDecoder ID3D11VideoContext"
+d3d12va_deps="dxva_h ID3D12Device ID3D12VideoDecoder"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 ffnvcodec_deps_any="libdl LoadLibrary"
 mediacodec_deps="android"
@@ -6547,6 +6550,8 @@ check_type "windows.h dxgi1_2.h" "IDXGIOutput1"
 check_type "windows.h dxgi1_5.h" "IDXGIOutput5"
 check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "windows.h d3d11.h" "ID3D11VideoContext"
+check_type "windows.h d3d12.h" "ID3D12Device"
+check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
 check_type "windows.h" "DPI_AWARENESS_CONTEXT" -D_WIN32_WINNT=0x0A00
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
diff --git a/doc/APIchanges b/doc/APIchanges
index ad1efe708d..5004a11267 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,13 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-07-xx - xx - lavu 58.18.100 - pixfmt.h hwcontext.h 
hwcontext_d3d12va.h
+  Add AV_HWDEVICE_TYPE_D3D12VA and AV_PIX_FMT_D3D12.
+  Add AVD3D12VADeviceContext, AVD3D12VASyncContext, AVD3D12VAFrame and
+  AVD3D12VAFramesContext.
+  Add av_d3d12va_map_sw_to_hw_format, av_d3d12va_sync_context_alloc,
+  av_d3d12va_sync_context_free.
+
 2023-08-18 - xx - lavu 58.17.100 - channel_layout.h
   All AV_CHANNEL_LAYOUT_* macros are now compatible with C++ 17 and older.
 
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 7828c94dc5..db318534eb 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -41,6 +41,7 @@ HEADERS = adler32.h   
  \
   hwcontext.h   \
   hwcontext_cuda.h  \
   hwcontext_d3d11va.h   \
+  hwcontext_d3d12va.h   \
   hwcontext_drm.h   \
   hwcontext_dxva2.h \
   hwcontext_qsv.h   \
@@ -188,6 +189,7 @@ OBJS = adler32.o
\
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
+OBJS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
 OBJS-$(CONFIG_LIBDRM)   += hwcontext_drm.o
 OBJS-$(CONFIG_MACOS_KPERF)  += macos_kperf.o
@@ -211,6 +213,7 @@ SKIPHEADERS-$(HAVE_CUDA_H) += hwcontext_cuda.h
 SKIPHEADERS-$(CONFIG

[FFmpeg-devel] [PATCH v7 8/9] Changelog: D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding

2023-08-28 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 Changelog | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index c010e86159..bdac4cb034 100644
--- a/Changelog
+++ b/Changelog
@@ -30,7 +30,7 @@ version :
 - support for the P_SKIP hinting to speed up libx264 encoding
 - Support HEVC,VP9,AV1 codec in enhanced flv format
 - apsnr and asisdr audio filters
-
+- D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
 
 version 6.0:
 - Radiance HDR image support
-- 
2.41.0.windows.1

___
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 v7 7/9] avcodec: add D3D12VA hardware accelerated VC1 decoding

2023-08-28 Thread Tong Wu
From: Wu Jianhua 

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   |   3 +
 libavcodec/Makefile |   1 +
 libavcodec/d3d12va_vc1.c| 214 
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/dxva2_vc1.c  |  11 +-
 libavcodec/hwaccels.h   |   2 +
 libavcodec/vc1dec.c |   9 ++
 7 files changed, 239 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/d3d12va_vc1.c

diff --git a/configure b/configure
index 6c443ed420..97f4b91318 100755
--- a/configure
+++ b/configure
@@ -3162,6 +3162,8 @@ vc1_d3d11va_hwaccel_deps="d3d11va"
 vc1_d3d11va_hwaccel_select="vc1_decoder"
 vc1_d3d11va2_hwaccel_deps="d3d11va"
 vc1_d3d11va2_hwaccel_select="vc1_decoder"
+vc1_d3d12va_hwaccel_deps="d3d12va"
+vc1_d3d12va_hwaccel_select="vc1_decoder"
 vc1_dxva2_hwaccel_deps="dxva2"
 vc1_dxva2_hwaccel_select="vc1_decoder"
 vc1_nvdec_hwaccel_deps="nvdec"
@@ -3192,6 +3194,7 @@ vp9_videotoolbox_hwaccel_deps="videotoolbox"
 vp9_videotoolbox_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
+wmv3_d3d12va_hwaccel_select="vc1_d3d12va_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
 wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 88925c0c5a..a7bb02de76 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1035,6 +1035,7 @@ OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
 OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
+OBJS-$(CONFIG_VC1_D3D12VA_HWACCEL)+= dxva2_vc1.o d3d12va_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
 OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
new file mode 100644
index 00..73887db602
--- /dev/null
+++ b/libavcodec/d3d12va_vc1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D12 WMV3/VC-1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "vc1.h"
+#include "vc1data.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters pp;
+unsigned   slice_count;
+DXVA_SliceInfo slices[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const VC1Context  *v   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
v->s.current_picture_ptr->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_vc1_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_vc1_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VC1Context  *v   = avctx-

[FFmpeg-devel] [PATCH v7 9/9] avcodec/d3d12va_hevc: enable allow_profile_mismatch flag for d3d12va msp profile

2023-08-28 Thread Tong Wu
Same as d3d11va, this flag enables main still picture profile for
d3d12va. User should add this flag when decoding main still picture
profile.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_hevc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index 4f6640be2f..1894fddb79 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -181,8 +181,13 @@ static int d3d12va_hevc_decode_init(AVCodecContext *avctx)
 break;
 
 case FF_PROFILE_HEVC_MAIN_STILL_PICTURE:
-av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
-return AVERROR(EINVAL);
+if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) {
+ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN;
+break;
+} else {
+av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
+return AVERROR(EINVAL);
+}
 
 case FF_PROFILE_HEVC_MAIN:
 default:
-- 
2.41.0.windows.1

___
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 v7 6/9] avcodec: add D3D12VA hardware accelerated MPEG-2 decoding

2023-08-28 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_mpeg2.c  | 191 
 libavcodec/dxva2_internal.h |   6 ++
 libavcodec/dxva2_mpeg2.c|  18 ++--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/mpeg12dec.c  |   6 ++
 7 files changed, 216 insertions(+), 9 deletions(-)
 create mode 100644 libavcodec/d3d12va_mpeg2.c

diff --git a/configure b/configure
index 940cea2f35..6c443ed420 100755
--- a/configure
+++ b/configure
@@ -3136,6 +3136,8 @@ mpeg2_d3d11va_hwaccel_deps="d3d11va"
 mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
 mpeg2_d3d11va2_hwaccel_deps="d3d11va"
 mpeg2_d3d11va2_hwaccel_select="mpeg2video_decoder"
+mpeg2_d3d12va_hwaccel_deps="d3d12va"
+mpeg2_d3d12va_hwaccel_select="mpeg2video_decoder"
 mpeg2_dxva2_hwaccel_deps="dxva2"
 mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
 mpeg2_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a4e6fd0ee1..88925c0c5a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1023,6 +1023,7 @@ OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= 
vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
+OBJS-$(CONFIG_MPEG2_D3D12VA_HWACCEL)  += dxva2_mpeg2.o d3d12va_mpeg2.o
 OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
 OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
diff --git a/libavcodec/d3d12va_mpeg2.c b/libavcodec/d3d12va_mpeg2.c
new file mode 100644
index 00..fe3636d242
--- /dev/null
+++ b/libavcodec/d3d12va_mpeg2.c
@@ -0,0 +1,191 @@
+/*
+ * Direct3D12 MPEG-2 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters  pp;
+DXVA_QmatrixDataqm;
+unsignedslice_count;
+DXVA_SliceInfo  slices[MAX_SLICES];
+const uint8_t  *bitstream;
+unsignedbitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+DXVA_QmatrixData  *qm  = _pic->qm;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_mpeg2_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ff_dxva2_mpeg2_fill_quantization_matrices(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+// Post processing operations are not supported in D3D12 Video
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+
+int is_field = s->picture_structure != PICT_FRAME;
+
+if (ctx_pic->slice_count >= MAX_SLIC

[FFmpeg-devel] [PATCH v7 5/9] avcodec: add D3D12VA hardware accelerated AV1 decoding

2023-08-28 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/av1dec.c |  10 ++
 libavcodec/d3d12va_av1.c| 220 
 libavcodec/dxva2_av1.c  |   5 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 241 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/d3d12va_av1.c

diff --git a/configure b/configure
index 572f0c3767..940cea2f35 100755
--- a/configure
+++ b/configure
@@ -3070,6 +3070,8 @@ av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va_hwaccel_select="av1_decoder"
 av1_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va2_hwaccel_select="av1_decoder"
+av1_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_AV1"
+av1_d3d12va_hwaccel_select="av1_decoder"
 av1_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_AV1"
 av1_dxva2_hwaccel_select="av1_decoder"
 av1_nvdec_hwaccel_deps="nvdec CUVIDAV1PICPARAMS"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index f0b9bdb9e6..a4e6fd0ee1 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -992,6 +992,7 @@ OBJS-$(CONFIG_VULKAN) += vulkan.o 
vulkan_video.o
 
 OBJS-$(CONFIG_AV1_D3D11VA_HWACCEL)+= dxva2_av1.o
 OBJS-$(CONFIG_AV1_DXVA2_HWACCEL)  += dxva2_av1.o
+OBJS-$(CONFIG_AV1_D3D12VA_HWACCEL)+= dxva2_av1.o d3d12va_av1.o
 OBJS-$(CONFIG_AV1_NVDEC_HWACCEL)  += nvdec_av1.o
 OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)  += vaapi_av1.o
 OBJS-$(CONFIG_AV1_VDPAU_HWACCEL)  += vdpau_av1.o
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 03283ab064..96e2c8febb 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -449,6 +449,7 @@ static int get_pixel_format(AVCodecContext *avctx)
 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
+ CONFIG_AV1_D3D12VA_HWACCEL + \
  CONFIG_AV1_NVDEC_HWACCEL + \
  CONFIG_AV1_VAAPI_HWACCEL + \
  CONFIG_AV1_VDPAU_HWACCEL + \
@@ -524,6 +525,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -545,6 +549,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -1534,6 +1541,9 @@ const FFCodec ff_av1_decoder = {
 #if CONFIG_AV1_D3D11VA2_HWACCEL
 HWACCEL_D3D11VA2(av1),
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+HWACCEL_D3D12VA(av1),
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 HWACCEL_NVDEC(av1),
 #endif
diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
new file mode 100644
index 00..4476f5bd8a
--- /dev/null
+++ b/libavcodec/d3d12va_av1.c
@@ -0,0 +1,220 @@
+/*
+ * Direct3D 12 AV1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "av1dec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+#define MAX_TILES 256
+
+typedef struct D3D12AV1DecodeContext {
+D3D12VADecodeContext ctx;
+uint8_t *bitstream_buffer;
+} D3D12AV1DecodeContext;
+
+#define D3D12_AV1_DECODE_CONTEXT(avctx) ((D3D12AV1DecodeContext 
*)D3D12VA_DECODE_CONTEXT(avctx))
+
+typedef struct AV1DecodePictureContext {
+DXVA_PicParams_AV1  pp;
+unsignedtile_count;
+DXVA_Tile_AV1   tiles[MAX_TILES];
+uint8_t  

[FFmpeg-devel] [PATCH v7 4/9] avcodec: add D3D12VA hardware accelerated VP9 decoding

2023-08-28 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_vp9.c| 176 
 libavcodec/dxva2_internal.h |   2 +
 libavcodec/dxva2_vp9.c  |   7 +-
 libavcodec/hwaccels.h   |   1 +
 libavcodec/vp9.c|   7 ++
 7 files changed, 193 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/d3d12va_vp9.c

diff --git a/configure b/configure
index 5b471e6090..572f0c3767 100755
--- a/configure
+++ b/configure
@@ -3174,6 +3174,8 @@ vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va_hwaccel_select="vp9_decoder"
 vp9_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va2_hwaccel_select="vp9_decoder"
+vp9_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_VP9"
+vp9_d3d12va_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index eaebfc27cd..f0b9bdb9e6 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1041,6 +1041,7 @@ OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)  += nvdec_vp8.o
 OBJS-$(CONFIG_VP8_VAAPI_HWACCEL)  += vaapi_vp8.o
 OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)+= dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
+OBJS-$(CONFIG_VP9_D3D12VA_HWACCEL)+= dxva2_vp9.o d3d12va_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
new file mode 100644
index 00..6ff0c5400d
--- /dev/null
+++ b/libavcodec/d3d12va_vp9.c
@@ -0,0 +1,176 @@
+/*
+ * Direct3D 12 VP9 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+
+#include "vp9shared.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+typedef struct VP9DecodePictureContext {
+DXVA_PicParams_VP9pp;
+DXVA_Slice_VPx_Short  slice;
+const uint8_t*bitstream;
+unsigned  bitstream_size;
+} VP9DecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_VPx_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_vp9_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+if (ff_dxva2_vp9_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp) < 0)
+return -1;
+
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream = NULL;
+
+return 0;
+}
+
+static int d3d12va_vp9_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+unsigned position;
+
+if (!ctx_pic->bitstream)
+ctx_pic->bitstream = buffer;
+ctx_pic->bitstream_size += size;
+
+position = buffer - ctx_pic->bitstream;
+fill_slice_short(_pic->slice, position, size);
+
+return 0;
+}
+
+static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
+{
+D3D12VADecodeContext   *ctx  

[FFmpeg-devel] [PATCH v7 3/9] avcodec: add D3D12VA hardware accelerated HEVC decoding

2023-08-28 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_hevc.c   | 211 
 libavcodec/dxva2_hevc.c |  10 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hevcdec.c|  10 ++
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 235 insertions(+), 4 deletions(-)
 create mode 100644 libavcodec/d3d12va_hevc.c

diff --git a/configure b/configure
index 339e5f35c0..5b471e6090 100755
--- a/configure
+++ b/configure
@@ -3106,6 +3106,8 @@ hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va_hwaccel_select="hevc_decoder"
 hevc_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va2_hwaccel_select="hevc_decoder"
+hevc_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_HEVC"
+hevc_d3d12va_hwaccel_select="hevc_decoder"
 hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a7808937ce..eaebfc27cd 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1009,6 +1009,7 @@ OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL)  += 
videotoolbox.o
 OBJS-$(CONFIG_H264_VULKAN_HWACCEL)+= vulkan_decode.o vulkan_h264.o
 OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL)   += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
+OBJS-$(CONFIG_HEVC_D3D12VA_HWACCEL)   += dxva2_hevc.o d3d12va_hevc.o
 OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o
diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
new file mode 100644
index 00..4f6640be2f
--- /dev/null
+++ b/libavcodec/d3d12va_hevc.c
@@ -0,0 +1,211 @@
+/*
+ * Direct3D 12 HEVC HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "hevc_data.h"
+#include "hevcdec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+#include 
+
+#define MAX_SLICES 256
+
+typedef struct HEVCDecodePictureContext {
+DXVA_PicParams_HEVCpp;
+DXVA_Qmatrix_HEVC  qm;
+unsigned   slice_count;
+DXVA_Slice_HEVC_Short  slice_short[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} HEVCDecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_HEVC_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_hevc_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+HEVCDecodePictureContext *ctx_pic = h->ref->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_hevc_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+
+ff_dxva2_hevc_fill_scaling_lists(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+ctx_pic->slice_count= 0;
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream  = NULL;
+
+return 0;
+}
+
+static int d3d12va_hevc_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+const HEVCFrame  *current_picture = h->ref;
+HEVCDecodePictureContext *ctx_pic = 
current_picture->hwaccel_picture_private;
+unsigned position;
+
+if (ctx_pic->slice_count >= MAX_SLICES)
+ 

[FFmpeg-devel] [PATCH v7 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-08-28 Thread Tong Wu
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 | 535 
 libavcodec/d3d12va_decode.h | 176 
 libavcodec/d3d12va_h264.c   | 210 ++
 libavcodec/dxva2.c  |  27 ++
 libavcodec/dxva2.h  |   3 -
 libavcodec/dxva2_h264.c |  12 +-
 libavcodec/dxva2_internal.h |  67 ++---
 libavcodec/h264_slice.c |   4 +
 libavcodec/h264dec.c|   3 +
 libavcodec/hwaccels.h   |   1 +
 libavcodec/hwconfig.h   |   2 +
 14 files changed, 1006 insertions(+), 42 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 c604302017..339e5f35c0 100755
--- a/configure
+++ b/configure
@@ -3088,6 +3088,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 f961d0abd6..a7808937ce 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -982,6 +982,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
@@ -999,6 +1000,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
@@ -1291,6 +1293,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..5d467c9dea
--- /dev/null
+++ b/libavcodec/d3d12va_decode.c
@@ -0,0 +1,535 @@
+/*
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth

[FFmpeg-devel] [PATCH v7 1/9] libavutil: add hwcontext_d3d12va and AV_PIX_FMT_D3D12

2023-08-28 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 configure  |   5 +
 doc/APIchanges |   7 +
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_d3d12va.c  | 693 +
 libavutil/hwcontext_d3d12va.h  | 148 ++
 libavutil/hwcontext_d3d12va_internal.h |  59 +++
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   7 +
 libavutil/tests/hwdevice.c |   2 +
 libavutil/version.h|   2 +-
 13 files changed, 935 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/hwcontext_d3d12va.c
 create mode 100644 libavutil/hwcontext_d3d12va.h
 create mode 100644 libavutil/hwcontext_d3d12va_internal.h

diff --git a/configure b/configure
index bd7f7697c8..c604302017 100755
--- a/configure
+++ b/configure
@@ -338,6 +338,7 @@ External library support:
   --disable-cuda-llvm  disable CUDA compilation using clang [autodetect]
   --disable-cuvid  disable Nvidia CUVID support [autodetect]
   --disable-d3d11vadisable Microsoft Direct3D 11 video acceleration 
code [autodetect]
+  --disable-d3d12vadisable Microsoft Direct3D 12 video acceleration 
code [autodetect]
   --disable-dxva2  disable Microsoft DirectX 9 video acceleration code 
[autodetect]
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
@@ -1926,6 +1927,7 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
 cuda_llvm
 cuvid
 d3d11va
+d3d12va
 dxva2
 ffnvcodec
 nvdec
@@ -3054,6 +3056,7 @@ crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 cuda_deps="ffnvcodec"
 cuvid_deps="ffnvcodec"
 d3d11va_deps="dxva_h ID3D11VideoDecoder ID3D11VideoContext"
+d3d12va_deps="dxva_h ID3D12Device ID3D12VideoDecoder"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 ffnvcodec_deps_any="libdl LoadLibrary"
 mediacodec_deps="android"
@@ -6547,6 +6550,8 @@ check_type "windows.h dxgi1_2.h" "IDXGIOutput1"
 check_type "windows.h dxgi1_5.h" "IDXGIOutput5"
 check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "windows.h d3d11.h" "ID3D11VideoContext"
+check_type "windows.h d3d12.h" "ID3D12Device"
+check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
 check_type "windows.h" "DPI_AWARENESS_CONTEXT" -D_WIN32_WINNT=0x0A00
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
diff --git a/doc/APIchanges b/doc/APIchanges
index ad1efe708d..5004a11267 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,13 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-07-xx - xx - lavu 58.18.100 - pixfmt.h hwcontext.h 
hwcontext_d3d12va.h
+  Add AV_HWDEVICE_TYPE_D3D12VA and AV_PIX_FMT_D3D12.
+  Add AVD3D12VADeviceContext, AVD3D12VASyncContext, AVD3D12VAFrame and
+  AVD3D12VAFramesContext.
+  Add av_d3d12va_map_sw_to_hw_format, av_d3d12va_sync_context_alloc,
+  av_d3d12va_sync_context_free.
+
 2023-08-18 - xx - lavu 58.17.100 - channel_layout.h
   All AV_CHANNEL_LAYOUT_* macros are now compatible with C++ 17 and older.
 
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 7828c94dc5..db318534eb 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -41,6 +41,7 @@ HEADERS = adler32.h   
  \
   hwcontext.h   \
   hwcontext_cuda.h  \
   hwcontext_d3d11va.h   \
+  hwcontext_d3d12va.h   \
   hwcontext_drm.h   \
   hwcontext_dxva2.h \
   hwcontext_qsv.h   \
@@ -188,6 +189,7 @@ OBJS = adler32.o
\
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
+OBJS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
 OBJS-$(CONFIG_LIBDRM)   += hwcontext_drm.o
 OBJS-$(CONFIG_MACOS_KPERF)  += macos_kperf.o
@@ -211,6 +213,7 @@ SKIPHEADERS-$(HAVE_CUDA_H) += hwcontext_cuda.h
 SKIPHEADERS-$(CONFIG

[FFmpeg-devel] [PATCH] avcodec/jpegxl_parser: fix a compile error

2023-08-28 Thread Tong Wu
Compiler: MSVC 14.35.32215
Error type: error C2099: initializer is not a constant
Related commit: 0c0dd23 avcodec/jpegxl_parser: add JPEG XL parser

Signed-off-by: Tong Wu 
---
 libavcodec/jpegxl_parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/jpegxl_parser.c b/libavcodec/jpegxl_parser.c
index 66e64b1074..20c8a41a89 100644
--- a/libavcodec/jpegxl_parser.c
+++ b/libavcodec/jpegxl_parser.c
@@ -49,7 +49,7 @@
 #define clog1p(x) (ff_log2(x) + !!(x))
 #define unpack_signed(x) (((x) & 1 ? -(x)-1 : (x))/2)
 #define div_ceil(x, y) (((x) - 1) / (y) + 1)
-#define vlm(a,b) (VLCElem){.sym = (a), .len = (b)}
+#define vlm(a,b) {.sym = (a), .len = (b)}
 
 typedef struct JXLHybridUintConf {
 int split_exponent;
-- 
2.41.0.windows.1

___
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 v6 8/9] Changelog: D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding

2023-08-25 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 Changelog | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index c010e86159..bdac4cb034 100644
--- a/Changelog
+++ b/Changelog
@@ -30,7 +30,7 @@ version :
 - support for the P_SKIP hinting to speed up libx264 encoding
 - Support HEVC,VP9,AV1 codec in enhanced flv format
 - apsnr and asisdr audio filters
-
+- D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
 
 version 6.0:
 - Radiance HDR image support
-- 
2.41.0.windows.1

___
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 v6 9/9] avcodec/d3d12va_hevc: enable allow_profile_mismatch flag for d3d12va msp profile

2023-08-25 Thread Tong Wu
Same as d3d11va, this flag enables main still picture profile for
d3d12va. User should add this flag when decoding main still picture
profile.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_hevc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index 4f6640be2f..1894fddb79 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -181,8 +181,13 @@ static int d3d12va_hevc_decode_init(AVCodecContext *avctx)
 break;
 
 case FF_PROFILE_HEVC_MAIN_STILL_PICTURE:
-av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
-return AVERROR(EINVAL);
+if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) {
+ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN;
+break;
+} else {
+av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
+return AVERROR(EINVAL);
+}
 
 case FF_PROFILE_HEVC_MAIN:
 default:
-- 
2.41.0.windows.1

___
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 v6 7/9] avcodec: add D3D12VA hardware accelerated VC1 decoding

2023-08-25 Thread Tong Wu
From: Wu Jianhua 

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   |   3 +
 libavcodec/Makefile |   1 +
 libavcodec/d3d12va_vc1.c| 214 
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/dxva2_vc1.c  |  11 +-
 libavcodec/hwaccels.h   |   2 +
 libavcodec/vc1dec.c |   9 ++
 7 files changed, 239 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/d3d12va_vc1.c

diff --git a/configure b/configure
index fd950e0a46..41c6912583 100755
--- a/configure
+++ b/configure
@@ -3161,6 +3161,8 @@ vc1_d3d11va_hwaccel_deps="d3d11va"
 vc1_d3d11va_hwaccel_select="vc1_decoder"
 vc1_d3d11va2_hwaccel_deps="d3d11va"
 vc1_d3d11va2_hwaccel_select="vc1_decoder"
+vc1_d3d12va_hwaccel_deps="d3d12va"
+vc1_d3d12va_hwaccel_select="vc1_decoder"
 vc1_dxva2_hwaccel_deps="dxva2"
 vc1_dxva2_hwaccel_select="vc1_decoder"
 vc1_nvdec_hwaccel_deps="nvdec"
@@ -3191,6 +3193,7 @@ vp9_videotoolbox_hwaccel_deps="videotoolbox"
 vp9_videotoolbox_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
+wmv3_d3d12va_hwaccel_select="vc1_d3d12va_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
 wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 30928a4c1d..b1f7dde3da 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1035,6 +1035,7 @@ OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
 OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
+OBJS-$(CONFIG_VC1_D3D12VA_HWACCEL)+= dxva2_vc1.o d3d12va_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
 OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
new file mode 100644
index 00..73887db602
--- /dev/null
+++ b/libavcodec/d3d12va_vc1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D12 WMV3/VC-1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "vc1.h"
+#include "vc1data.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters pp;
+unsigned   slice_count;
+DXVA_SliceInfo slices[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const VC1Context  *v   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
v->s.current_picture_ptr->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_vc1_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_vc1_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VC1Context  *v   = avctx-

[FFmpeg-devel] [PATCH v6 6/9] avcodec: add D3D12VA hardware accelerated MPEG-2 decoding

2023-08-25 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_mpeg2.c  | 191 
 libavcodec/dxva2_internal.h |   6 ++
 libavcodec/dxva2_mpeg2.c|  18 ++--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/mpeg12dec.c  |   6 ++
 7 files changed, 216 insertions(+), 9 deletions(-)
 create mode 100644 libavcodec/d3d12va_mpeg2.c

diff --git a/configure b/configure
index 80e9e91b81..fd950e0a46 100755
--- a/configure
+++ b/configure
@@ -3135,6 +3135,8 @@ mpeg2_d3d11va_hwaccel_deps="d3d11va"
 mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
 mpeg2_d3d11va2_hwaccel_deps="d3d11va"
 mpeg2_d3d11va2_hwaccel_select="mpeg2video_decoder"
+mpeg2_d3d12va_hwaccel_deps="d3d12va"
+mpeg2_d3d12va_hwaccel_select="mpeg2video_decoder"
 mpeg2_dxva2_hwaccel_deps="dxva2"
 mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
 mpeg2_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fb5ec2ee2d..30928a4c1d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1023,6 +1023,7 @@ OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= 
vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
+OBJS-$(CONFIG_MPEG2_D3D12VA_HWACCEL)  += dxva2_mpeg2.o d3d12va_mpeg2.o
 OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
 OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
diff --git a/libavcodec/d3d12va_mpeg2.c b/libavcodec/d3d12va_mpeg2.c
new file mode 100644
index 00..fe3636d242
--- /dev/null
+++ b/libavcodec/d3d12va_mpeg2.c
@@ -0,0 +1,191 @@
+/*
+ * Direct3D12 MPEG-2 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters  pp;
+DXVA_QmatrixDataqm;
+unsignedslice_count;
+DXVA_SliceInfo  slices[MAX_SLICES];
+const uint8_t  *bitstream;
+unsignedbitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+DXVA_QmatrixData  *qm  = _pic->qm;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_mpeg2_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ff_dxva2_mpeg2_fill_quantization_matrices(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+// Post processing operations are not supported in D3D12 Video
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+
+int is_field = s->picture_structure != PICT_FRAME;
+
+if (ctx_pic->slice_count >= MAX_SLIC

[FFmpeg-devel] [PATCH v6 5/9] avcodec: add D3D12VA hardware accelerated AV1 decoding

2023-08-25 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/av1dec.c |  10 ++
 libavcodec/d3d12va_av1.c| 220 
 libavcodec/dxva2_av1.c  |   5 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 241 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/d3d12va_av1.c

diff --git a/configure b/configure
index 756be03af6..80e9e91b81 100755
--- a/configure
+++ b/configure
@@ -3069,6 +3069,8 @@ av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va_hwaccel_select="av1_decoder"
 av1_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va2_hwaccel_select="av1_decoder"
+av1_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_AV1"
+av1_d3d12va_hwaccel_select="av1_decoder"
 av1_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_AV1"
 av1_dxva2_hwaccel_select="av1_decoder"
 av1_nvdec_hwaccel_deps="nvdec CUVIDAV1PICPARAMS"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9ef49a8da5..fb5ec2ee2d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -992,6 +992,7 @@ OBJS-$(CONFIG_VULKAN) += vulkan.o 
vulkan_video.o
 
 OBJS-$(CONFIG_AV1_D3D11VA_HWACCEL)+= dxva2_av1.o
 OBJS-$(CONFIG_AV1_DXVA2_HWACCEL)  += dxva2_av1.o
+OBJS-$(CONFIG_AV1_D3D12VA_HWACCEL)+= dxva2_av1.o d3d12va_av1.o
 OBJS-$(CONFIG_AV1_NVDEC_HWACCEL)  += nvdec_av1.o
 OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)  += vaapi_av1.o
 OBJS-$(CONFIG_AV1_VDPAU_HWACCEL)  += vdpau_av1.o
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 03283ab064..96e2c8febb 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -449,6 +449,7 @@ static int get_pixel_format(AVCodecContext *avctx)
 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
+ CONFIG_AV1_D3D12VA_HWACCEL + \
  CONFIG_AV1_NVDEC_HWACCEL + \
  CONFIG_AV1_VAAPI_HWACCEL + \
  CONFIG_AV1_VDPAU_HWACCEL + \
@@ -524,6 +525,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -545,6 +549,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -1534,6 +1541,9 @@ const FFCodec ff_av1_decoder = {
 #if CONFIG_AV1_D3D11VA2_HWACCEL
 HWACCEL_D3D11VA2(av1),
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+HWACCEL_D3D12VA(av1),
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 HWACCEL_NVDEC(av1),
 #endif
diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
new file mode 100644
index 00..4476f5bd8a
--- /dev/null
+++ b/libavcodec/d3d12va_av1.c
@@ -0,0 +1,220 @@
+/*
+ * Direct3D 12 AV1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "av1dec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+#define MAX_TILES 256
+
+typedef struct D3D12AV1DecodeContext {
+D3D12VADecodeContext ctx;
+uint8_t *bitstream_buffer;
+} D3D12AV1DecodeContext;
+
+#define D3D12_AV1_DECODE_CONTEXT(avctx) ((D3D12AV1DecodeContext 
*)D3D12VA_DECODE_CONTEXT(avctx))
+
+typedef struct AV1DecodePictureContext {
+DXVA_PicParams_AV1  pp;
+unsignedtile_count;
+DXVA_Tile_AV1   tiles[MAX_TILES];
+uint8_t  

[FFmpeg-devel] [PATCH v6 4/9] avcodec: add D3D12VA hardware accelerated VP9 decoding

2023-08-25 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_vp9.c| 176 
 libavcodec/dxva2_internal.h |   2 +
 libavcodec/dxva2_vp9.c  |   7 +-
 libavcodec/hwaccels.h   |   1 +
 libavcodec/vp9.c|   7 ++
 7 files changed, 193 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/d3d12va_vp9.c

diff --git a/configure b/configure
index 64607a4d9a..756be03af6 100755
--- a/configure
+++ b/configure
@@ -3173,6 +3173,8 @@ vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va_hwaccel_select="vp9_decoder"
 vp9_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va2_hwaccel_select="vp9_decoder"
+vp9_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_VP9"
+vp9_d3d12va_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 033bb5d505..9ef49a8da5 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1041,6 +1041,7 @@ OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)  += nvdec_vp8.o
 OBJS-$(CONFIG_VP8_VAAPI_HWACCEL)  += vaapi_vp8.o
 OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)+= dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
+OBJS-$(CONFIG_VP9_D3D12VA_HWACCEL)+= dxva2_vp9.o d3d12va_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
new file mode 100644
index 00..6ff0c5400d
--- /dev/null
+++ b/libavcodec/d3d12va_vp9.c
@@ -0,0 +1,176 @@
+/*
+ * Direct3D 12 VP9 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+
+#include "vp9shared.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+typedef struct VP9DecodePictureContext {
+DXVA_PicParams_VP9pp;
+DXVA_Slice_VPx_Short  slice;
+const uint8_t*bitstream;
+unsigned  bitstream_size;
+} VP9DecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_VPx_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_vp9_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+if (ff_dxva2_vp9_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp) < 0)
+return -1;
+
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream = NULL;
+
+return 0;
+}
+
+static int d3d12va_vp9_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+unsigned position;
+
+if (!ctx_pic->bitstream)
+ctx_pic->bitstream = buffer;
+ctx_pic->bitstream_size += size;
+
+position = buffer - ctx_pic->bitstream;
+fill_slice_short(_pic->slice, position, size);
+
+return 0;
+}
+
+static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
+{
+D3D12VADecodeContext   *ctx  

[FFmpeg-devel] [PATCH v6 3/9] avcodec: add D3D12VA hardware accelerated HEVC decoding

2023-08-25 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_hevc.c   | 211 
 libavcodec/dxva2_hevc.c |  10 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hevcdec.c|  10 ++
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 235 insertions(+), 4 deletions(-)
 create mode 100644 libavcodec/d3d12va_hevc.c

diff --git a/configure b/configure
index 78511ca54f..64607a4d9a 100755
--- a/configure
+++ b/configure
@@ -3105,6 +3105,8 @@ hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va_hwaccel_select="hevc_decoder"
 hevc_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va2_hwaccel_select="hevc_decoder"
+hevc_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_HEVC"
+hevc_d3d12va_hwaccel_select="hevc_decoder"
 hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 8d45b02334..033bb5d505 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1009,6 +1009,7 @@ OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL)  += 
videotoolbox.o
 OBJS-$(CONFIG_H264_VULKAN_HWACCEL)+= vulkan_decode.o vulkan_h264.o
 OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL)   += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
+OBJS-$(CONFIG_HEVC_D3D12VA_HWACCEL)   += dxva2_hevc.o d3d12va_hevc.o
 OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o
diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
new file mode 100644
index 00..4f6640be2f
--- /dev/null
+++ b/libavcodec/d3d12va_hevc.c
@@ -0,0 +1,211 @@
+/*
+ * Direct3D 12 HEVC HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "hevc_data.h"
+#include "hevcdec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+#include 
+
+#define MAX_SLICES 256
+
+typedef struct HEVCDecodePictureContext {
+DXVA_PicParams_HEVCpp;
+DXVA_Qmatrix_HEVC  qm;
+unsigned   slice_count;
+DXVA_Slice_HEVC_Short  slice_short[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} HEVCDecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_HEVC_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_hevc_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+HEVCDecodePictureContext *ctx_pic = h->ref->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_hevc_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+
+ff_dxva2_hevc_fill_scaling_lists(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+ctx_pic->slice_count= 0;
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream  = NULL;
+
+return 0;
+}
+
+static int d3d12va_hevc_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+const HEVCFrame  *current_picture = h->ref;
+HEVCDecodePictureContext *ctx_pic = 
current_picture->hwaccel_picture_private;
+unsigned position;
+
+if (ctx_pic->slice_count >= MAX_SLICES)
+ 

[FFmpeg-devel] [PATCH v6 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-08-25 Thread Tong Wu
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 | 522 
 libavcodec/d3d12va_decode.h | 176 
 libavcodec/d3d12va_h264.c   | 210 +++
 libavcodec/dxva2.c  |  27 ++
 libavcodec/dxva2.h  |   3 -
 libavcodec/dxva2_h264.c |  12 +-
 libavcodec/dxva2_internal.h |  67 ++---
 libavcodec/h264_slice.c |   4 +
 libavcodec/h264dec.c|   3 +
 libavcodec/hwaccels.h   |   1 +
 libavcodec/hwconfig.h   |   2 +
 14 files changed, 993 insertions(+), 42 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 b74a668f87..78511ca54f 100755
--- a/configure
+++ b/configure
@@ -3087,6 +3087,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 3c16b51462..8d45b02334 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -982,6 +982,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
@@ -999,6 +1000,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
@@ -1288,6 +1290,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..b0a5b0987d
--- /dev/null
+++ b/libavcodec/d3d12va_decode.c
@@ -0,0 +1,522 @@
+/*
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth

[FFmpeg-devel] [PATCH v6 1/9] libavutil: add hwcontext_d3d12va and AV_PIX_FMT_D3D12

2023-08-25 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 configure  |   5 +
 doc/APIchanges |   7 +
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_d3d12va.c  | 693 +
 libavutil/hwcontext_d3d12va.h  | 155 ++
 libavutil/hwcontext_d3d12va_internal.h |  59 +++
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   7 +
 libavutil/tests/hwdevice.c |   2 +
 libavutil/version.h|   2 +-
 13 files changed, 942 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/hwcontext_d3d12va.c
 create mode 100644 libavutil/hwcontext_d3d12va.h
 create mode 100644 libavutil/hwcontext_d3d12va_internal.h

diff --git a/configure b/configure
index 04bb9fe9dd..b74a668f87 100755
--- a/configure
+++ b/configure
@@ -338,6 +338,7 @@ External library support:
   --disable-cuda-llvm  disable CUDA compilation using clang [autodetect]
   --disable-cuvid  disable Nvidia CUVID support [autodetect]
   --disable-d3d11vadisable Microsoft Direct3D 11 video acceleration 
code [autodetect]
+  --disable-d3d12vadisable Microsoft Direct3D 12 video acceleration 
code [autodetect]
   --disable-dxva2  disable Microsoft DirectX 9 video acceleration code 
[autodetect]
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
@@ -1926,6 +1927,7 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
 cuda_llvm
 cuvid
 d3d11va
+d3d12va
 dxva2
 ffnvcodec
 nvdec
@@ -3053,6 +3055,7 @@ crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 cuda_deps="ffnvcodec"
 cuvid_deps="ffnvcodec"
 d3d11va_deps="dxva_h ID3D11VideoDecoder ID3D11VideoContext"
+d3d12va_deps="dxva_h ID3D12Device ID3D12VideoDecoder"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 ffnvcodec_deps_any="libdl LoadLibrary"
 mediacodec_deps="android"
@@ -6546,6 +6549,8 @@ check_type "windows.h dxgi1_2.h" "IDXGIOutput1"
 check_type "windows.h dxgi1_5.h" "IDXGIOutput5"
 check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "windows.h d3d11.h" "ID3D11VideoContext"
+check_type "windows.h d3d12.h" "ID3D12Device"
+check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
 check_type "windows.h" "DPI_AWARENESS_CONTEXT" -D_WIN32_WINNT=0x0A00
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
diff --git a/doc/APIchanges b/doc/APIchanges
index ad1efe708d..37ce29323d 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,13 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-07-xx - xx - lavu 58.18.100 - pixfmt.h hwcontext.h 
hwcontext_d3d12va.h
+  Add AV_HWDEVICE_TYPE_D3D12VA and AV_PIX_FMT_D3D12.
+  Add AVD3D12VADeviceContext, AVD3D12VASyncContext, AVD3D12VAFrame and
+  AVD3D12VAFramesContext.
+  Add av_d3d12va_map_sw_to_hw_format, av_d3d12va_sync_context_alloc,
+  av_d3d12va_sync_context_free, av_d3d12va_wait_idle.
+
 2023-08-18 - xx - lavu 58.17.100 - channel_layout.h
   All AV_CHANNEL_LAYOUT_* macros are now compatible with C++ 17 and older.
 
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 7828c94dc5..db318534eb 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -41,6 +41,7 @@ HEADERS = adler32.h   
  \
   hwcontext.h   \
   hwcontext_cuda.h  \
   hwcontext_d3d11va.h   \
+  hwcontext_d3d12va.h   \
   hwcontext_drm.h   \
   hwcontext_dxva2.h \
   hwcontext_qsv.h   \
@@ -188,6 +189,7 @@ OBJS = adler32.o
\
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
+OBJS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
 OBJS-$(CONFIG_LIBDRM)   += hwcontext_drm.o
 OBJS-$(CONFIG_MACOS_KPERF)  += macos_kperf.o
@@ -211,6 +213,7 @@ SKIPHEADERS-$(HAVE_CUDA_H) += hwcon

[FFmpeg-devel] [PATCH v5 8/9] Changelog: D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding

2023-08-04 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index bbda4f4fd4..5b21103b29 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - Bitstream filter for converting VVC from MP4 to Annex B
 - scale_vt filter for videotoolbox
 - transpose_vt filter for videotoolbox
+- D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
 
 version 6.0:
 - Radiance HDR image support
-- 
2.41.0.windows.1

___
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 v5 7/9] avcodec: add D3D12VA hardware accelerated VC1 decoding

2023-08-04 Thread Tong Wu
From: Wu Jianhua 

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   |   3 +
 libavcodec/Makefile |   1 +
 libavcodec/d3d12va_vc1.c| 214 
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/dxva2_vc1.c  |  11 +-
 libavcodec/hwaccels.h   |   2 +
 libavcodec/vc1dec.c |   9 ++
 7 files changed, 239 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/d3d12va_vc1.c

diff --git a/configure b/configure
index 67b5b36eea..ecdd1e2afc 100755
--- a/configure
+++ b/configure
@@ -3161,6 +3161,8 @@ vc1_d3d11va_hwaccel_deps="d3d11va"
 vc1_d3d11va_hwaccel_select="vc1_decoder"
 vc1_d3d11va2_hwaccel_deps="d3d11va"
 vc1_d3d11va2_hwaccel_select="vc1_decoder"
+vc1_d3d12va_hwaccel_deps="d3d12va"
+vc1_d3d12va_hwaccel_select="vc1_decoder"
 vc1_dxva2_hwaccel_deps="dxva2"
 vc1_dxva2_hwaccel_select="vc1_decoder"
 vc1_nvdec_hwaccel_deps="nvdec"
@@ -3191,6 +3193,7 @@ vp9_videotoolbox_hwaccel_deps="videotoolbox"
 vp9_videotoolbox_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
+wmv3_d3d12va_hwaccel_select="vc1_d3d12va_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
 wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 30928a4c1d..b1f7dde3da 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1035,6 +1035,7 @@ OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
 OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
+OBJS-$(CONFIG_VC1_D3D12VA_HWACCEL)+= dxva2_vc1.o d3d12va_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
 OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
new file mode 100644
index 00..b89cc6527d
--- /dev/null
+++ b/libavcodec/d3d12va_vc1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D12 WMV3/VC-1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "vc1.h"
+#include "vc1data.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters pp;
+unsigned   slice_count;
+DXVA_SliceInfo slices[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const VC1Context  *v   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
v->s.current_picture_ptr->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_vc1_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_vc1_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VC1Context  *v   = avctx-

[FFmpeg-devel] [PATCH v5 9/9] avcodec/d3d12va_hevc: enable allow_profile_mismatch flag for d3d12va msp profile

2023-08-04 Thread Tong Wu
Same as d3d11va, this flag enables main still picture profile for
d3d12va. User should add this flag when decoding main still picture
profile.

Signed-off-by: Tong Wu 
---
 libavcodec/d3d12va_hevc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index 894fa73d60..a56d038a40 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -181,8 +181,13 @@ static int d3d12va_hevc_decode_init(AVCodecContext *avctx)
 break;
 
 case FF_PROFILE_HEVC_MAIN_STILL_PICTURE:
-av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
-return AVERROR(EINVAL);
+if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) {
+ctx->cfg.DecodeProfile = D3D12_VIDEO_DECODE_PROFILE_HEVC_MAIN;
+break;
+} else {
+av_log(avctx, AV_LOG_ERROR, "D3D12 doesn't support 
PROFILE_HEVC_MAIN_STILL_PICTURE!\n");
+return AVERROR(EINVAL);
+}
 
 case FF_PROFILE_HEVC_MAIN:
 default:
-- 
2.41.0.windows.1

___
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 v5 6/9] avcodec: add D3D12VA hardware accelerated MPEG-2 decoding

2023-08-04 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_mpeg2.c  | 191 
 libavcodec/dxva2_internal.h |   6 ++
 libavcodec/dxva2_mpeg2.c|  18 ++--
 libavcodec/hwaccels.h   |   1 +
 libavcodec/mpeg12dec.c  |   6 ++
 7 files changed, 216 insertions(+), 9 deletions(-)
 create mode 100644 libavcodec/d3d12va_mpeg2.c

diff --git a/configure b/configure
index c97d7a4874..67b5b36eea 100755
--- a/configure
+++ b/configure
@@ -3135,6 +3135,8 @@ mpeg2_d3d11va_hwaccel_deps="d3d11va"
 mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
 mpeg2_d3d11va2_hwaccel_deps="d3d11va"
 mpeg2_d3d11va2_hwaccel_select="mpeg2video_decoder"
+mpeg2_d3d12va_hwaccel_deps="d3d12va"
+mpeg2_d3d12va_hwaccel_select="mpeg2video_decoder"
 mpeg2_dxva2_hwaccel_deps="dxva2"
 mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
 mpeg2_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fb5ec2ee2d..30928a4c1d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1023,6 +1023,7 @@ OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= 
vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
+OBJS-$(CONFIG_MPEG2_D3D12VA_HWACCEL)  += dxva2_mpeg2.o d3d12va_mpeg2.o
 OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
 OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
diff --git a/libavcodec/d3d12va_mpeg2.c b/libavcodec/d3d12va_mpeg2.c
new file mode 100644
index 00..83aca620b3
--- /dev/null
+++ b/libavcodec/d3d12va_mpeg2.c
@@ -0,0 +1,191 @@
+/*
+ * Direct3D12 MPEG-2 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters  pp;
+DXVA_QmatrixDataqm;
+unsignedslice_count;
+DXVA_SliceInfo  slices[MAX_SLICES];
+const uint8_t  *bitstream;
+unsignedbitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+DXVA_QmatrixData  *qm  = _pic->qm;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_mpeg2_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ff_dxva2_mpeg2_fill_quantization_matrices(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+// Post processing operations are not supported in D3D12 Video
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const MpegEncContext  *s   = avctx->priv_data;
+D3D12DecodePictureContext *ctx_pic = 
s->current_picture_ptr->hwaccel_picture_private;
+
+int is_field = s->picture_structure != PICT_FRAME;
+
+if (ctx_pic->slice_count >= MAX_SLIC

[FFmpeg-devel] [PATCH v5 5/9] avcodec: add D3D12VA hardware accelerated AV1 decoding

2023-08-04 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/av1dec.c |  10 ++
 libavcodec/d3d12va_av1.c| 220 
 libavcodec/dxva2_av1.c  |   5 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 241 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/d3d12va_av1.c

diff --git a/configure b/configure
index 0339630e7e..c97d7a4874 100755
--- a/configure
+++ b/configure
@@ -3069,6 +3069,8 @@ av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va_hwaccel_select="av1_decoder"
 av1_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
 av1_d3d11va2_hwaccel_select="av1_decoder"
+av1_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_AV1"
+av1_d3d12va_hwaccel_select="av1_decoder"
 av1_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_AV1"
 av1_dxva2_hwaccel_select="av1_decoder"
 av1_nvdec_hwaccel_deps="nvdec CUVIDAV1PICPARAMS"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9ef49a8da5..fb5ec2ee2d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -992,6 +992,7 @@ OBJS-$(CONFIG_VULKAN) += vulkan.o 
vulkan_video.o
 
 OBJS-$(CONFIG_AV1_D3D11VA_HWACCEL)+= dxva2_av1.o
 OBJS-$(CONFIG_AV1_DXVA2_HWACCEL)  += dxva2_av1.o
+OBJS-$(CONFIG_AV1_D3D12VA_HWACCEL)+= dxva2_av1.o d3d12va_av1.o
 OBJS-$(CONFIG_AV1_NVDEC_HWACCEL)  += nvdec_av1.o
 OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)  += vaapi_av1.o
 OBJS-$(CONFIG_AV1_VDPAU_HWACCEL)  += vdpau_av1.o
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index cc178464b9..2067d67c68 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -448,6 +448,7 @@ static int get_pixel_format(AVCodecContext *avctx)
 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
+ CONFIG_AV1_D3D12VA_HWACCEL + \
  CONFIG_AV1_NVDEC_HWACCEL + \
  CONFIG_AV1_VAAPI_HWACCEL + \
  CONFIG_AV1_VDPAU_HWACCEL + \
@@ -523,6 +524,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -544,6 +548,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
 *fmtp++ = AV_PIX_FMT_D3D11;
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+*fmtp++ = AV_PIX_FMT_D3D12;
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 *fmtp++ = AV_PIX_FMT_CUDA;
 #endif
@@ -1541,6 +1548,9 @@ const FFCodec ff_av1_decoder = {
 #if CONFIG_AV1_D3D11VA2_HWACCEL
 HWACCEL_D3D11VA2(av1),
 #endif
+#if CONFIG_AV1_D3D12VA_HWACCEL
+HWACCEL_D3D12VA(av1),
+#endif
 #if CONFIG_AV1_NVDEC_HWACCEL
 HWACCEL_NVDEC(av1),
 #endif
diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
new file mode 100644
index 00..7544e97eae
--- /dev/null
+++ b/libavcodec/d3d12va_av1.c
@@ -0,0 +1,220 @@
+/*
+ * Direct3D 12 AV1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "av1dec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+#define MAX_TILES 256
+
+typedef struct D3D12AV1DecodeContext {
+D3D12VADecodeContext ctx;
+uint8_t *bitstream_buffer;
+} D3D12AV1DecodeContext;
+
+#define D3D12_AV1_DECODE_CONTEXT(avctx) ((D3D12AV1DecodeContext 
*)D3D12VA_DECODE_CONTEXT(avctx))
+
+typedef struct AV1DecodePictureContext {
+DXVA_PicParams_AV1  pp;
+unsignedtile_count;
+DXVA_Tile_AV1   tiles[MAX_TILES];
+uint8_t  

[FFmpeg-devel] [PATCH v5 4/9] avcodec: add D3D12VA hardware accelerated VP9 decoding

2023-08-04 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_vp9.c| 176 
 libavcodec/dxva2_internal.h |   2 +
 libavcodec/dxva2_vp9.c  |   7 +-
 libavcodec/hwaccels.h   |   1 +
 libavcodec/vp9.c|   7 ++
 7 files changed, 193 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/d3d12va_vp9.c

diff --git a/configure b/configure
index fc82bbc3a7..0339630e7e 100755
--- a/configure
+++ b/configure
@@ -3173,6 +3173,8 @@ vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va_hwaccel_select="vp9_decoder"
 vp9_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va2_hwaccel_select="vp9_decoder"
+vp9_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_VP9"
+vp9_d3d12va_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 033bb5d505..9ef49a8da5 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1041,6 +1041,7 @@ OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)  += nvdec_vp8.o
 OBJS-$(CONFIG_VP8_VAAPI_HWACCEL)  += vaapi_vp8.o
 OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)+= dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)  += dxva2_vp9.o
+OBJS-$(CONFIG_VP9_D3D12VA_HWACCEL)+= dxva2_vp9.o d3d12va_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)  += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
diff --git a/libavcodec/d3d12va_vp9.c b/libavcodec/d3d12va_vp9.c
new file mode 100644
index 00..5535c8bad0
--- /dev/null
+++ b/libavcodec/d3d12va_vp9.c
@@ -0,0 +1,176 @@
+/*
+ * Direct3D 12 VP9 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+
+#include "vp9shared.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+
+typedef struct VP9DecodePictureContext {
+DXVA_PicParams_VP9pp;
+DXVA_Slice_VPx_Short  slice;
+const uint8_t*bitstream;
+unsigned  bitstream_size;
+} VP9DecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_VPx_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_vp9_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+if (ff_dxva2_vp9_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp) < 0)
+return -1;
+
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream = NULL;
+
+return 0;
+}
+
+static int d3d12va_vp9_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VP9SharedContext  *h   = avctx->priv_data;
+VP9DecodePictureContext *ctx_pic = 
h->frames[CUR_FRAME].hwaccel_picture_private;
+unsigned position;
+
+if (!ctx_pic->bitstream)
+ctx_pic->bitstream = buffer;
+ctx_pic->bitstream_size += size;
+
+position = buffer - ctx_pic->bitstream;
+fill_slice_short(_pic->slice, position, size);
+
+return 0;
+}
+
+static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
+{
+D3D12VADecodeContext   *ctx  

[FFmpeg-devel] [PATCH v5 3/9] avcodec: add D3D12VA hardware accelerated HEVC decoding

2023-08-04 Thread Tong Wu
From: Wu Jianhua 

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 |   1 +
 libavcodec/d3d12va_hevc.c   | 211 
 libavcodec/dxva2_hevc.c |  10 +-
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/hevcdec.c|  10 ++
 libavcodec/hwaccels.h   |   1 +
 7 files changed, 235 insertions(+), 4 deletions(-)
 create mode 100644 libavcodec/d3d12va_hevc.c

diff --git a/configure b/configure
index 8c5790b046..fc82bbc3a7 100755
--- a/configure
+++ b/configure
@@ -3105,6 +3105,8 @@ hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va_hwaccel_select="hevc_decoder"
 hevc_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
 hevc_d3d11va2_hwaccel_select="hevc_decoder"
+hevc_d3d12va_hwaccel_deps="d3d12va DXVA_PicParams_HEVC"
+hevc_d3d12va_hwaccel_select="hevc_decoder"
 hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 8d45b02334..033bb5d505 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1009,6 +1009,7 @@ OBJS-$(CONFIG_H264_VIDEOTOOLBOX_HWACCEL)  += 
videotoolbox.o
 OBJS-$(CONFIG_H264_VULKAN_HWACCEL)+= vulkan_decode.o vulkan_h264.o
 OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL)   += dxva2_hevc.o
 OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o
+OBJS-$(CONFIG_HEVC_D3D12VA_HWACCEL)   += dxva2_hevc.o d3d12va_hevc.o
 OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_HWACCEL)   += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o
diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
new file mode 100644
index 00..894fa73d60
--- /dev/null
+++ b/libavcodec/d3d12va_hevc.c
@@ -0,0 +1,211 @@
+/*
+ * Direct3D 12 HEVC HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "hevc_data.h"
+#include "hevcdec.h"
+#include "dxva2_internal.h"
+#include "d3d12va_decode.h"
+#include 
+
+#define MAX_SLICES 256
+
+typedef struct HEVCDecodePictureContext {
+DXVA_PicParams_HEVCpp;
+DXVA_Qmatrix_HEVC  qm;
+unsigned   slice_count;
+DXVA_Slice_HEVC_Short  slice_short[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} HEVCDecodePictureContext;
+
+static void fill_slice_short(DXVA_Slice_HEVC_Short *slice, unsigned position, 
unsigned size)
+{
+memset(slice, 0, sizeof(*slice));
+slice->BSNALunitDataLocation = position;
+slice->SliceBytesInBuffer= size;
+slice->wBadSliceChopping = 0;
+}
+
+static int d3d12va_hevc_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+HEVCDecodePictureContext *ctx_pic = h->ref->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_hevc_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+
+ff_dxva2_hevc_fill_scaling_lists(avctx, (AVDXVAContext *)ctx, 
_pic->qm);
+
+ctx_pic->slice_count= 0;
+ctx_pic->bitstream_size = 0;
+ctx_pic->bitstream  = NULL;
+
+return 0;
+}
+
+static int d3d12va_hevc_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const HEVCContext*h   = avctx->priv_data;
+const HEVCFrame  *current_picture = h->ref;
+HEVCDecodePictureContext *ctx_pic = 
current_picture->hwaccel_picture_private;
+unsigned position;
+
+if (ctx_pic->slice_count >= MAX_SLICES)
+ 

[FFmpeg-devel] [PATCH v5 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-08-04 Thread Tong Wu
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 | 533 
 libavcodec/d3d12va_decode.h | 182 
 libavcodec/d3d12va_h264.c   | 210 ++
 libavcodec/dxva2.c  |  24 ++
 libavcodec/dxva2.h  |   3 -
 libavcodec/dxva2_h264.c |  12 +-
 libavcodec/dxva2_internal.h |  67 ++---
 libavcodec/h264_slice.c |   4 +
 libavcodec/h264dec.c|   3 +
 libavcodec/hwaccels.h   |   1 +
 libavcodec/hwconfig.h   |   2 +
 14 files changed, 1007 insertions(+), 42 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 9919551ad0..8c5790b046 100755
--- a/configure
+++ b/configure
@@ -3087,6 +3087,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 3c16b51462..8d45b02334 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -982,6 +982,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
@@ -999,6 +1000,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
@@ -1288,6 +1290,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..7e516eb7dc
--- /dev/null
+++ b/libavcodec/d3d12va_decode.c
@@ -0,0 +1,533 @@
+/*
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth

[FFmpeg-devel] [PATCH v5 1/9] libavutil: add hwcontext_d3d12va and AV_PIX_FMT_D3D12

2023-08-04 Thread Tong Wu
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
Signed-off-by: Tong Wu 
---
 configure  |   5 +
 doc/APIchanges |   7 +
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_d3d12va.c  | 703 +
 libavutil/hwcontext_d3d12va.h  | 169 ++
 libavutil/hwcontext_d3d12va_internal.h |  59 +++
 libavutil/hwcontext_internal.h |   1 +
 libavutil/pixdesc.c|   4 +
 libavutil/pixfmt.h |   9 +
 libavutil/tests/hwdevice.c |   2 +
 libavutil/version.h|   2 +-
 13 files changed, 968 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/hwcontext_d3d12va.c
 create mode 100644 libavutil/hwcontext_d3d12va.h
 create mode 100644 libavutil/hwcontext_d3d12va_internal.h

diff --git a/configure b/configure
index 99388e7664..9919551ad0 100755
--- a/configure
+++ b/configure
@@ -338,6 +338,7 @@ External library support:
   --disable-cuda-llvm  disable CUDA compilation using clang [autodetect]
   --disable-cuvid  disable Nvidia CUVID support [autodetect]
   --disable-d3d11vadisable Microsoft Direct3D 11 video acceleration 
code [autodetect]
+  --disable-d3d12vadisable Microsoft Direct3D 12 video acceleration 
code [autodetect]
   --disable-dxva2  disable Microsoft DirectX 9 video acceleration code 
[autodetect]
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
@@ -1926,6 +1927,7 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
 cuda_llvm
 cuvid
 d3d11va
+d3d12va
 dxva2
 ffnvcodec
 nvdec
@@ -3053,6 +3055,7 @@ crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 cuda_deps="ffnvcodec"
 cuvid_deps="ffnvcodec"
 d3d11va_deps="dxva_h ID3D11VideoDecoder ID3D11VideoContext"
+d3d12va_deps="dxva_h ID3D12Device ID3D12VideoDecoder"
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 ffnvcodec_deps_any="libdl LoadLibrary"
 mediacodec_deps="android"
@@ -6543,6 +6546,8 @@ check_type "windows.h dxgi1_2.h" "IDXGIOutput1"
 check_type "windows.h dxgi1_5.h" "IDXGIOutput5"
 check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "windows.h d3d11.h" "ID3D11VideoContext"
+check_type "windows.h d3d12.h" "ID3D12Device"
+check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
 check_type "windows.h" "DPI_AWARENESS_CONTEXT" -D_WIN32_WINNT=0x0A00
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
diff --git a/doc/APIchanges b/doc/APIchanges
index 5afe8bcb75..c14ab0b394 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,13 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-07-xx - xx - lavu 58.15.100 - pixfmt.h hwcontext.h 
hwcontext_d3d12va.h
+  Add AV_HWDEVICE_TYPE_D3D12VA and AV_PIX_FMT_D3D12.
+  Add AVD3D12VADeviceContext, AVD3D12VASyncContext, AVD3D12FrameDescriptor,
+  and AVD3D12VAFramesContext.
+  Add av_d3d12va_map_sw_to_hw_format, av_d3d12va_create_sync_context,
+  av_d3d12va_release_sync_context, av_d3d12va_wait_idle, and 
av_d3d12va_wait_queue_idle.
+
 2023-07-xx - xx - lavc 60 - avcodec.h
   Deprecate AV_CODEC_FLAG_DROPCHANGED without replacement.
 
diff --git a/libavutil/Makefile b/libavutil/Makefile
index bd9c6f9e32..40d49d76dd 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -41,6 +41,7 @@ HEADERS = adler32.h   
  \
   hwcontext.h   \
   hwcontext_cuda.h  \
   hwcontext_d3d11va.h   \
+  hwcontext_d3d12va.h   \
   hwcontext_drm.h   \
   hwcontext_dxva2.h \
   hwcontext_qsv.h   \
@@ -186,6 +187,7 @@ OBJS = adler32.o
\
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
+OBJS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
 OBJS-$(CONFIG_LIBDRM)   += hwcontext_drm.o
 OBJS-$(CONFIG_MACOS_KPERF)  += macos_kperf.o
@@ -209,6 +211,7 @@ SKIPHEADERS-$(HAVE_CUDA_H)

[FFmpeg-devel] [PATCH v4 7/9] avcodec: add D3D12VA hardware accelerated VC1 decoding

2023-07-19 Thread Tong Wu
From: Wu Jianhua 

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   |   3 +
 libavcodec/Makefile |   1 +
 libavcodec/d3d12va_vc1.c| 214 
 libavcodec/dxva2_internal.h |   4 +
 libavcodec/dxva2_vc1.c  |  11 +-
 libavcodec/hwaccels.h   |   2 +
 libavcodec/vc1dec.c |   9 ++
 7 files changed, 239 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/d3d12va_vc1.c

diff --git a/configure b/configure
index 63c3cfbb3d..5bc96932da 100755
--- a/configure
+++ b/configure
@@ -3162,6 +3162,8 @@ vc1_d3d11va_hwaccel_deps="d3d11va"
 vc1_d3d11va_hwaccel_select="vc1_decoder"
 vc1_d3d11va2_hwaccel_deps="d3d11va"
 vc1_d3d11va2_hwaccel_select="vc1_decoder"
+vc1_d3d12va_hwaccel_deps="d3d12va"
+vc1_d3d12va_hwaccel_select="vc1_decoder"
 vc1_dxva2_hwaccel_deps="dxva2"
 vc1_dxva2_hwaccel_select="vc1_decoder"
 vc1_nvdec_hwaccel_deps="nvdec"
@@ -3192,6 +3194,7 @@ vp9_videotoolbox_hwaccel_deps="videotoolbox"
 vp9_videotoolbox_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
+wmv3_d3d12va_hwaccel_select="vc1_d3d12va_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
 wmv3_nvdec_hwaccel_select="vc1_nvdec_hwaccel"
 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ad7b81292f..f461eeac1e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1035,6 +1035,7 @@ OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
 OBJS-$(CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
 OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL)+= dxva2_vc1.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)  += dxva2_vc1.o
+OBJS-$(CONFIG_VC1_D3D12VA_HWACCEL)+= dxva2_vc1.o d3d12va_vc1.o
 OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)  += nvdec_vc1.o
 OBJS-$(CONFIG_VC1_QSV_HWACCEL)+= qsvdec.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)  += vaapi_vc1.o
diff --git a/libavcodec/d3d12va_vc1.c b/libavcodec/d3d12va_vc1.c
new file mode 100644
index 00..b89cc6527d
--- /dev/null
+++ b/libavcodec/d3d12va_vc1.c
@@ -0,0 +1,214 @@
+/*
+ * Direct3D12 WMV3/VC-1 HW acceleration
+ *
+ * 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 with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+#include "mpegutils.h"
+#include "mpegvideodec.h"
+#include "vc1.h"
+#include "vc1data.h"
+#include "d3d12va_decode.h"
+#include "dxva2_internal.h"
+
+#define MAX_SLICES  1024
+#define INVALID_REF 0x
+
+#define REF_RESOURCE(index) if (index != INVALID_REF) { \
+ctx->ref_resources[index] = frames_hwctx->texture_infos[index].texture; \
+}
+
+typedef struct D3D12DecodePictureContext {
+DXVA_PictureParameters pp;
+unsigned   slice_count;
+DXVA_SliceInfo slices[MAX_SLICES];
+const uint8_t *bitstream;
+unsigned   bitstream_size;
+} D3D12DecodePictureContext;
+
+static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+{
+const VC1Context  *v   = avctx->priv_data;
+D3D12VADecodeContext  *ctx = D3D12VA_DECODE_CONTEXT(avctx);
+D3D12DecodePictureContext *ctx_pic = 
v->s.current_picture_ptr->hwaccel_picture_private;
+
+if (!ctx)
+return -1;
+
+av_assert0(ctx_pic);
+
+ff_dxva2_vc1_fill_picture_parameters(avctx, (AVDXVAContext *)ctx, 
_pic->pp);
+ctx_pic->pp.wDeblockedPictureIndex = INVALID_REF;
+
+ctx_pic->bitstream  = NULL;
+ctx_pic->bitstream_size = 0;
+ctx_pic->slice_count= 0;
+
+return 0;
+}
+
+static int d3d12va_vc1_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
+{
+const VC1Context  *v   = avctx-

  1   2   >