* [FFmpeg-devel] [PATCH 2/2] lavc/d3d12va_encode: trim header alignment at output
[not found] <20240708151323.312-1-wutong1208@outlook.com>
@ 2024-07-08 15:13 ` Tong Wu
2024-07-28 13:06 ` Tong Wu
0 siblings, 1 reply; 4+ messages in thread
From: Tong Wu @ 2024-07-08 15:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 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 <wutong1208@outlook.com>
---
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 **)&ptr);
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2] lavc/d3d12va_encode: trim header alignment at output
2024-07-08 15:13 ` [FFmpeg-devel] [PATCH 2/2] lavc/d3d12va_encode: trim header alignment at output Tong Wu
@ 2024-07-28 13:06 ` Tong Wu
2024-07-28 15:55 ` Lynne via ffmpeg-devel
0 siblings, 1 reply; 4+ messages in thread
From: Tong Wu @ 2024-07-28 13:06 UTC (permalink / raw)
To: Tong Wu, ffmpeg-devel
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 <wutong1208@outlook.com>
>---
> 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 **)&ptr);
> 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2] lavc/d3d12va_encode: trim header alignment at output
2024-07-28 13:06 ` Tong Wu
@ 2024-07-28 15:55 ` Lynne via ffmpeg-devel
2024-07-29 14:36 ` Tong Wu
0 siblings, 1 reply; 4+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-07-28 15:55 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Lynne
[-- Attachment #1.1.1.1: Type: text/plain, Size: 4418 bytes --]
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 <wutong1208@outlook.com>
>> ---
>> 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 **)&ptr);
>> 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-request@ffmpeg.org with subject "unsubscribe".
Somehow I missed that patch. You should've ping me when I pushed the
first one.
Pushed.
In Vulkan, we expose the raw packet we've just encoded by wrapping it as
an AVBufferRef, you should consider doing this.
[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 624 bytes --]
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2] lavc/d3d12va_encode: trim header alignment at output
2024-07-28 15:55 ` Lynne via ffmpeg-devel
@ 2024-07-29 14:36 ` Tong Wu
0 siblings, 0 replies; 4+ messages in thread
From: Tong Wu @ 2024-07-29 14:36 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Lynne
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 <wutong1208@outlook.com>
>>> ---
>>> 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 **)&ptr);
>>> 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-request@ffmpeg.org with subject "unsubscribe".
>
>Somehow I missed that patch. You should've ping me when I pushed the first one.
>
>Pushed.
>In Vulkan, we expose the raw packet we've just encoded by wrapping it as an
>AVBufferRef, you should consider doing this.
Thank you very much!
There's already a AVBufferRef of output buffer in D3D12VAEncodePicture. I guess you might mean that.
Thanks,
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-29 14:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20240708151323.312-1-wutong1208@outlook.com>
2024-07-08 15:13 ` [FFmpeg-devel] [PATCH 2/2] lavc/d3d12va_encode: trim header alignment at output Tong Wu
2024-07-28 13:06 ` Tong Wu
2024-07-28 15:55 ` Lynne via ffmpeg-devel
2024-07-29 14:36 ` Tong Wu
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git