Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers
@ 2024-04-28  7:26 David Rosca
  2024-04-28  7:26 ` [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times David Rosca
  2024-05-07  6:59 ` [FFmpeg-devel] [PATCH 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers Xiang, Haihao
  0 siblings, 2 replies; 5+ messages in thread
From: David Rosca @ 2024-04-28  7:26 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: David Rosca

---
 libavcodec/vaapi_av1.c    | 2 +-
 libavcodec/vaapi_decode.c | 3 ++-
 libavcodec/vaapi_decode.h | 1 +
 libavcodec/vaapi_h264.c   | 2 +-
 libavcodec/vaapi_hevc.c   | 4 ++--
 libavcodec/vaapi_mjpeg.c  | 2 +-
 libavcodec/vaapi_mpeg2.c  | 2 +-
 libavcodec/vaapi_mpeg4.c  | 2 +-
 libavcodec/vaapi_vc1.c    | 2 +-
 libavcodec/vaapi_vp8.c    | 2 +-
 libavcodec/vaapi_vp9.c    | 2 +-
 11 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
index 1f563483b9..4a90db1e09 100644
--- a/libavcodec/vaapi_av1.c
+++ b/libavcodec/vaapi_av1.c
@@ -409,7 +409,7 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
             .tg_end            = s->tg_end,
         };
 
-        err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param,
+        err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param, 1,
                                                 sizeof(VASliceParameterBufferAV1),
                                                 buffer,
                                                 size);
diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 21b273cd0f..8e9f647c20 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -63,6 +63,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
 int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
                                       VAAPIDecodePicture *pic,
                                       const void *params_data,
+                                      int nb_params,
                                       size_t params_size,
                                       const void *slice_data,
                                       size_t slice_size)
@@ -88,7 +89,7 @@ int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
 
     vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
                          VASliceParameterBufferType,
-                         params_size, 1, (void*)params_data,
+                         params_size, nb_params, (void*)params_data,
                          &pic->slice_buffers[index]);
     if (vas != VA_STATUS_SUCCESS) {
         av_log(avctx, AV_LOG_ERROR, "Failed to create slice "
diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h
index 6beda14e52..702171e108 100644
--- a/libavcodec/vaapi_decode.h
+++ b/libavcodec/vaapi_decode.h
@@ -73,6 +73,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
 int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
                                       VAAPIDecodePicture *pic,
                                       const void *params_data,
+                                      int nb_params,
                                       size_t params_size,
                                       const void *slice_data,
                                       size_t slice_size);
diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
index 55cf5a05ee..b47531ce1c 100644
--- a/libavcodec/vaapi_h264.c
+++ b/libavcodec/vaapi_h264.c
@@ -375,7 +375,7 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
                                        slice_param.chroma_offset_l1);
 
     err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
-                                            &slice_param, sizeof(slice_param),
+                                            &slice_param, 1, sizeof(slice_param),
                                             buffer, size);
     if (err) {
         ff_vaapi_decode_cancel(avctx, pic);
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 3bdd2dd1b8..3937b7574a 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -353,7 +353,7 @@ static int vaapi_hevc_end_frame(AVCodecContext *avctx)
     if (pic->last_size) {
         last_slice_param->LongSliceFlags.fields.LastSliceOfPic = 1;
         ret = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic,
-                                                &pic->last_slice_param, slice_param_size,
+                                                &pic->last_slice_param, 1, slice_param_size,
                                                 pic->last_buffer, pic->last_size);
         if (ret < 0)
             goto fail;
@@ -471,7 +471,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
 
     if (!sh->first_slice_in_pic_flag) {
         err = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic,
-                                                &pic->last_slice_param, slice_param_size,
+                                                &pic->last_slice_param, 1, slice_param_size,
                                                 pic->last_buffer, pic->last_size);
         pic->last_buffer = NULL;
         pic->last_size   = 0;
diff --git a/libavcodec/vaapi_mjpeg.c b/libavcodec/vaapi_mjpeg.c
index 5b8d47bb2a..9557cf5f9b 100644
--- a/libavcodec/vaapi_mjpeg.c
+++ b/libavcodec/vaapi_mjpeg.c
@@ -131,7 +131,7 @@ static int vaapi_mjpeg_decode_slice(AVCodecContext *avctx,
         sp.components[i].ac_table_selector  = s->ac_index[i];
     }
 
-    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, sizeof(sp), buffer, size);
+    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, 1, sizeof(sp), buffer, size);
     if (err)
         goto fail;
 
diff --git a/libavcodec/vaapi_mpeg2.c b/libavcodec/vaapi_mpeg2.c
index eeb4e87321..171a742c7f 100644
--- a/libavcodec/vaapi_mpeg2.c
+++ b/libavcodec/vaapi_mpeg2.c
@@ -162,7 +162,7 @@ static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer
     };
 
     err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
-                                            &slice_param, sizeof(slice_param),
+                                            &slice_param, 1, sizeof(slice_param),
                                             buffer, size);
     if (err < 0) {
         ff_vaapi_decode_cancel(avctx, pic);
diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
index 363b686e42..612de10cd7 100644
--- a/libavcodec/vaapi_mpeg4.c
+++ b/libavcodec/vaapi_mpeg4.c
@@ -169,7 +169,7 @@ static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer
     };
 
     err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
-                                            &slice_param, sizeof(slice_param),
+                                            &slice_param, 1, sizeof(slice_param),
                                             buffer, size);
     if (err < 0) {
         ff_vaapi_decode_cancel(avctx, pic);
diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
index 5594118a69..abbe877dd8 100644
--- a/libavcodec/vaapi_vc1.c
+++ b/libavcodec/vaapi_vc1.c
@@ -490,7 +490,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
     };
 
     err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
-                                            &slice_param, sizeof(slice_param),
+                                            &slice_param, 1, sizeof(slice_param),
                                             buffer, size);
     if (err < 0) {
         ff_vaapi_decode_cancel(avctx, pic);
diff --git a/libavcodec/vaapi_vp8.c b/libavcodec/vaapi_vp8.c
index 31137a45bd..66fdde1f39 100644
--- a/libavcodec/vaapi_vp8.c
+++ b/libavcodec/vaapi_vp8.c
@@ -209,7 +209,7 @@ static int vaapi_vp8_decode_slice(AVCodecContext *avctx,
     for (i = 0; i < 8; i++)
         sp.partition_size[i+1] = s->coeff_partition_size[i];
 
-    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, sizeof(sp), data, data_size);
+    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, 1, sizeof(sp), data, data_size);
     if (err)
         goto fail;
 
diff --git a/libavcodec/vaapi_vp9.c b/libavcodec/vaapi_vp9.c
index b8e760c807..a28fc75a59 100644
--- a/libavcodec/vaapi_vp9.c
+++ b/libavcodec/vaapi_vp9.c
@@ -158,7 +158,7 @@ static int vaapi_vp9_decode_slice(AVCodecContext *avctx,
     }
 
     err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
-                                            &slice_param, sizeof(slice_param),
+                                            &slice_param, 1, sizeof(slice_param),
                                             buffer, size);
     if (err) {
         ff_vaapi_decode_cancel(avctx, pic);
-- 
2.44.0

_______________________________________________
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] 5+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times
  2024-04-28  7:26 [FFmpeg-devel] [PATCH 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers David Rosca
@ 2024-04-28  7:26 ` David Rosca
  2024-05-07 20:01   ` Mark Thompson
  2024-05-07  6:59 ` [FFmpeg-devel] [PATCH 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers Xiang, Haihao
  1 sibling, 1 reply; 5+ messages in thread
From: David Rosca @ 2024-04-28  7:26 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: David Rosca

When there are multiple tiles in one slice buffer, use multiple slice
params to avoid sending the same slice buffer multiple times and thus
increasing the bitstream size the driver will need to upload to hw.
---
 libavcodec/vaapi_av1.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
index 4a90db1e09..567f505fbd 100644
--- a/libavcodec/vaapi_av1.c
+++ b/libavcodec/vaapi_av1.c
@@ -19,6 +19,7 @@
  */
 
 #include "libavutil/frame.h"
+#include "libavutil/mem.h"
 #include "hwaccel_internal.h"
 #include "vaapi_decode.h"
 #include "internal.h"
@@ -393,13 +394,17 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
 {
     const AV1DecContext *s = avctx->priv_data;
     VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private;
-    VASliceParameterBufferAV1 slice_param;
-    int err = 0;
+    VASliceParameterBufferAV1 *slice_params;
+    int err = 0, nb_params = 0;
 
-    for (int i = s->tg_start; i <= s->tg_end; i++) {
-        memset(&slice_param, 0, sizeof(VASliceParameterBufferAV1));
+    slice_params = av_calloc(s->tg_end - s->tg_start + 1, sizeof(*slice_params));
+    if (!slice_params) {
+        err = AVERROR(ENOMEM);
+        goto fail;
+    }
 
-        slice_param = (VASliceParameterBufferAV1) {
+    for (int i = s->tg_start; i <= s->tg_end; i++) {
+        slice_params[nb_params++] = (VASliceParameterBufferAV1) {
             .slice_data_size   = s->tile_group_info[i].tile_size,
             .slice_data_offset = s->tile_group_info[i].tile_offset,
             .slice_data_flag   = VA_SLICE_DATA_FLAG_ALL,
@@ -408,18 +413,22 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
             .tg_start          = s->tg_start,
             .tg_end            = s->tg_end,
         };
-
-        err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param, 1,
-                                                sizeof(VASliceParameterBufferAV1),
-                                                buffer,
-                                                size);
-        if (err) {
-            ff_vaapi_decode_cancel(avctx, pic);
-            return err;
-        }
     }
 
+    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, slice_params, nb_params,
+                                            sizeof(VASliceParameterBufferAV1),
+                                            buffer,
+                                            size);
+    av_free(slice_params);
+
+    if (err)
+        goto fail;
+
     return 0;
+
+fail:
+    ff_vaapi_decode_cancel(avctx, pic);
+    return err;
 }
 
 const FFHWAccel ff_av1_vaapi_hwaccel = {
-- 
2.44.0

_______________________________________________
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] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers
  2024-04-28  7:26 [FFmpeg-devel] [PATCH 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers David Rosca
  2024-04-28  7:26 ` [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times David Rosca
@ 2024-05-07  6:59 ` Xiang, Haihao
  1 sibling, 0 replies; 5+ messages in thread
From: Xiang, Haihao @ 2024-05-07  6:59 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: nowrep

On So, 2024-04-28 at 09:26 +0200, David Rosca wrote:
> ---
>  libavcodec/vaapi_av1.c    | 2 +-
>  libavcodec/vaapi_decode.c | 3 ++-
>  libavcodec/vaapi_decode.h | 1 +
>  libavcodec/vaapi_h264.c   | 2 +-
>  libavcodec/vaapi_hevc.c   | 4 ++--
>  libavcodec/vaapi_mjpeg.c  | 2 +-
>  libavcodec/vaapi_mpeg2.c  | 2 +-
>  libavcodec/vaapi_mpeg4.c  | 2 +-
>  libavcodec/vaapi_vc1.c    | 2 +-
>  libavcodec/vaapi_vp8.c    | 2 +-
>  libavcodec/vaapi_vp9.c    | 2 +-
>  11 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> index 1f563483b9..4a90db1e09 100644
> --- a/libavcodec/vaapi_av1.c
> +++ b/libavcodec/vaapi_av1.c
> @@ -409,7 +409,7 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
>              .tg_end            = s->tg_end,
>          };
>  
> -        err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param,
> +        err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param, 1,
>                                                 
> sizeof(VASliceParameterBufferAV1),
>                                                  buffer,
>                                                  size);
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 21b273cd0f..8e9f647c20 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -63,6 +63,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
>  int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
>                                        VAAPIDecodePicture *pic,
>                                        const void *params_data,
> +                                      int nb_params,
>                                        size_t params_size,
>                                        const void *slice_data,
>                                        size_t slice_size)
> @@ -88,7 +89,7 @@ int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
>  
>      vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
>                           VASliceParameterBufferType,
> -                         params_size, 1, (void*)params_data,
> +                         params_size, nb_params, (void*)params_data,
>                           &pic->slice_buffers[index]);
>      if (vas != VA_STATUS_SUCCESS) {
>          av_log(avctx, AV_LOG_ERROR, "Failed to create slice "
> diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h
> index 6beda14e52..702171e108 100644
> --- a/libavcodec/vaapi_decode.h
> +++ b/libavcodec/vaapi_decode.h
> @@ -73,6 +73,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
>  int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
>                                        VAAPIDecodePicture *pic,
>                                        const void *params_data,
> +                                      int nb_params,
>                                        size_t params_size,
>                                        const void *slice_data,
>                                        size_t slice_size);
> diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
> index 55cf5a05ee..b47531ce1c 100644
> --- a/libavcodec/vaapi_h264.c
> +++ b/libavcodec/vaapi_h264.c
> @@ -375,7 +375,7 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
>                                         slice_param.chroma_offset_l1);
>  
>      err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
> -                                            &slice_param,
> sizeof(slice_param),
> +                                            &slice_param, 1,
> sizeof(slice_param),
>                                              buffer, size);
>      if (err) {
>          ff_vaapi_decode_cancel(avctx, pic);
> diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
> index 3bdd2dd1b8..3937b7574a 100644
> --- a/libavcodec/vaapi_hevc.c
> +++ b/libavcodec/vaapi_hevc.c
> @@ -353,7 +353,7 @@ static int vaapi_hevc_end_frame(AVCodecContext *avctx)
>      if (pic->last_size) {
>          last_slice_param->LongSliceFlags.fields.LastSliceOfPic = 1;
>          ret = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic,
> -                                                &pic->last_slice_param,
> slice_param_size,
> +                                                &pic->last_slice_param, 1,
> slice_param_size,
>                                                  pic->last_buffer, pic-
> >last_size);
>          if (ret < 0)
>              goto fail;
> @@ -471,7 +471,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
>  
>      if (!sh->first_slice_in_pic_flag) {
>          err = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic,
> -                                                &pic->last_slice_param,
> slice_param_size,
> +                                                &pic->last_slice_param, 1,
> slice_param_size,
>                                                  pic->last_buffer, pic-
> >last_size);
>          pic->last_buffer = NULL;
>          pic->last_size   = 0;
> diff --git a/libavcodec/vaapi_mjpeg.c b/libavcodec/vaapi_mjpeg.c
> index 5b8d47bb2a..9557cf5f9b 100644
> --- a/libavcodec/vaapi_mjpeg.c
> +++ b/libavcodec/vaapi_mjpeg.c
> @@ -131,7 +131,7 @@ static int vaapi_mjpeg_decode_slice(AVCodecContext *avctx,
>          sp.components[i].ac_table_selector  = s->ac_index[i];
>      }
>  
> -    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, sizeof(sp),
> buffer, size);
> +    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, 1, sizeof(sp),
> buffer, size);
>      if (err)
>          goto fail;
>  
> diff --git a/libavcodec/vaapi_mpeg2.c b/libavcodec/vaapi_mpeg2.c
> index eeb4e87321..171a742c7f 100644
> --- a/libavcodec/vaapi_mpeg2.c
> +++ b/libavcodec/vaapi_mpeg2.c
> @@ -162,7 +162,7 @@ static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx,
> const uint8_t *buffer
>      };
>  
>      err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
> -                                            &slice_param,
> sizeof(slice_param),
> +                                            &slice_param, 1,
> sizeof(slice_param),
>                                              buffer, size);
>      if (err < 0) {
>          ff_vaapi_decode_cancel(avctx, pic);
> diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
> index 363b686e42..612de10cd7 100644
> --- a/libavcodec/vaapi_mpeg4.c
> +++ b/libavcodec/vaapi_mpeg4.c
> @@ -169,7 +169,7 @@ static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx,
> const uint8_t *buffer
>      };
>  
>      err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
> -                                            &slice_param,
> sizeof(slice_param),
> +                                            &slice_param, 1,
> sizeof(slice_param),
>                                              buffer, size);
>      if (err < 0) {
>          ff_vaapi_decode_cancel(avctx, pic);
> diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
> index 5594118a69..abbe877dd8 100644
> --- a/libavcodec/vaapi_vc1.c
> +++ b/libavcodec/vaapi_vc1.c
> @@ -490,7 +490,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx,
> const uint8_t *buffer,
>      };
>  
>      err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
> -                                            &slice_param,
> sizeof(slice_param),
> +                                            &slice_param, 1,
> sizeof(slice_param),
>                                              buffer, size);
>      if (err < 0) {
>          ff_vaapi_decode_cancel(avctx, pic);
> diff --git a/libavcodec/vaapi_vp8.c b/libavcodec/vaapi_vp8.c
> index 31137a45bd..66fdde1f39 100644
> --- a/libavcodec/vaapi_vp8.c
> +++ b/libavcodec/vaapi_vp8.c
> @@ -209,7 +209,7 @@ static int vaapi_vp8_decode_slice(AVCodecContext *avctx,
>      for (i = 0; i < 8; i++)
>          sp.partition_size[i+1] = s->coeff_partition_size[i];
>  
> -    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, sizeof(sp),
> data, data_size);
> +    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, 1, sizeof(sp),
> data, data_size);
>      if (err)
>          goto fail;
>  
> diff --git a/libavcodec/vaapi_vp9.c b/libavcodec/vaapi_vp9.c
> index b8e760c807..a28fc75a59 100644
> --- a/libavcodec/vaapi_vp9.c
> +++ b/libavcodec/vaapi_vp9.c
> @@ -158,7 +158,7 @@ static int vaapi_vp9_decode_slice(AVCodecContext *avctx,
>      }
>  
>      err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
> -                                            &slice_param,
> sizeof(slice_param),
> +                                            &slice_param, 1,
> sizeof(slice_param),
>                                              buffer, size);
>      if (err) {
>          ff_vaapi_decode_cancel(avctx, pic);

Patchset LGTM and it works well for me. I'll merge it if no one objects.

Thanks
Haihao


_______________________________________________
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] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times
  2024-04-28  7:26 ` [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times David Rosca
@ 2024-05-07 20:01   ` Mark Thompson
  2024-05-08  7:17     ` David Rosca
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Thompson @ 2024-05-07 20:01 UTC (permalink / raw)
  To: ffmpeg-devel

On 28/04/2024 08:26, David Rosca wrote:
> When there are multiple tiles in one slice buffer, use multiple slice
> params to avoid sending the same slice buffer multiple times and thus
> increasing the bitstream size the driver will need to upload to hw.
> ---
>  libavcodec/vaapi_av1.c | 37 +++++++++++++++++++++++--------------
>  1 file changed, 23 insertions(+), 14 deletions(-)

Can you confirm that this works on at least iHD (Intel) and Mesa (AMD)?  (I don't expect any issue, but it's good to check in case of something strange going on matching up to what this was previously doing.)

> diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> index 4a90db1e09..567f505fbd 100644
> --- a/libavcodec/vaapi_av1.c
> +++ b/libavcodec/vaapi_av1.c
> @@ -19,6 +19,7 @@
>   */
>  
>  #include "libavutil/frame.h"
> +#include "libavutil/mem.h"
>  #include "hwaccel_internal.h"
>  #include "vaapi_decode.h"
>  #include "internal.h"
> @@ -393,13 +394,17 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
>  {
>      const AV1DecContext *s = avctx->priv_data;
>      VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private;
> -    VASliceParameterBufferAV1 slice_param;
> -    int err = 0;
> +    VASliceParameterBufferAV1 *slice_params;
> +    int err = 0, nb_params = 0;

Remove the spurious initialisation on err?

>  
> -    for (int i = s->tg_start; i <= s->tg_end; i++) {
> -        memset(&slice_param, 0, sizeof(VASliceParameterBufferAV1));
> +    slice_params = av_calloc(s->tg_end - s->tg_start + 1, sizeof(*slice_params));

I suggest allocating this into VAAPIAV1DecContext to avoid the alloc/free on every call.  (Only reallocate if it needs to be bigger than the previous maximum.)

> +    if (!slice_params) {
> +        err = AVERROR(ENOMEM);
> +        goto fail;
> +    }
>  
> -        slice_param = (VASliceParameterBufferAV1) {
> +    for (int i = s->tg_start; i <= s->tg_end; i++) {
> +        slice_params[nb_params++] = (VASliceParameterBufferAV1) {
>              .slice_data_size   = s->tile_group_info[i].tile_size,
>              .slice_data_offset = s->tile_group_info[i].tile_offset,
>              .slice_data_flag   = VA_SLICE_DATA_FLAG_ALL,
> @@ -408,18 +413,22 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
>              .tg_start          = s->tg_start,
>              .tg_end            = s->tg_end,
>          };
> -
> -        err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param, 1,
> -                                                sizeof(VASliceParameterBufferAV1),
> -                                                buffer,
> -                                                size);
> -        if (err) {
> -            ff_vaapi_decode_cancel(avctx, pic);
> -            return err;
> -        }
>      }
>  
> +    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, slice_params, nb_params,
> +                                            sizeof(VASliceParameterBufferAV1),
> +                                            buffer,
> +                                            size);
> +    av_free(slice_params);
> +
> +    if (err)
> +        goto fail;
> +
>      return 0;
> +
> +fail:
> +    ff_vaapi_decode_cancel(avctx, pic);
> +    return err;
>  }
>  
>  const FFHWAccel ff_av1_vaapi_hwaccel = {

It's amusing that this quadratic behaviour was around for so long!  (I guess people don't use many tiles.)

Thanks,

- Mark
_______________________________________________
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] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times
  2024-05-07 20:01   ` Mark Thompson
@ 2024-05-08  7:17     ` David Rosca
  0 siblings, 0 replies; 5+ messages in thread
From: David Rosca @ 2024-05-08  7:17 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Tue, May 7, 2024 at 10:01 PM Mark Thompson <sw@jkqxz.net> wrote:
>
> On 28/04/2024 08:26, David Rosca wrote:
> > When there are multiple tiles in one slice buffer, use multiple slice
> > params to avoid sending the same slice buffer multiple times and thus
> > increasing the bitstream size the driver will need to upload to hw.
> > ---
> >  libavcodec/vaapi_av1.c | 37 +++++++++++++++++++++++--------------
> >  1 file changed, 23 insertions(+), 14 deletions(-)
>
> Can you confirm that this works on at least iHD (Intel) and Mesa (AMD)?  (I don't expect any issue, but it's good to check in case of something strange going on matching up to what this was previously doing.)

I've tested with Mesa and it works correctly. Gstreamer also does the same.

https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/da35ed69164ba8c8599d337b00ba54074215f7e7/subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c#L891-L912

>
> > diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> > index 4a90db1e09..567f505fbd 100644
> > --- a/libavcodec/vaapi_av1.c
> > +++ b/libavcodec/vaapi_av1.c
> > @@ -19,6 +19,7 @@
> >   */
> >
> >  #include "libavutil/frame.h"
> > +#include "libavutil/mem.h"
> >  #include "hwaccel_internal.h"
> >  #include "vaapi_decode.h"
> >  #include "internal.h"
> > @@ -393,13 +394,17 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
> >  {
> >      const AV1DecContext *s = avctx->priv_data;
> >      VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private;
> > -    VASliceParameterBufferAV1 slice_param;
> > -    int err = 0;
> > +    VASliceParameterBufferAV1 *slice_params;
> > +    int err = 0, nb_params = 0;
>
> Remove the spurious initialisation on err?

Done in v2.

>
> >
> > -    for (int i = s->tg_start; i <= s->tg_end; i++) {
> > -        memset(&slice_param, 0, sizeof(VASliceParameterBufferAV1));
> > +    slice_params = av_calloc(s->tg_end - s->tg_start + 1, sizeof(*slice_params));
>
> I suggest allocating this into VAAPIAV1DecContext to avoid the alloc/free on every call.  (Only reallocate if it needs to be bigger than the previous maximum.)

Done in v2.

Thanks,
David

>
> > +    if (!slice_params) {
> > +        err = AVERROR(ENOMEM);
> > +        goto fail;
> > +    }
> >
> > -        slice_param = (VASliceParameterBufferAV1) {
> > +    for (int i = s->tg_start; i <= s->tg_end; i++) {
> > +        slice_params[nb_params++] = (VASliceParameterBufferAV1) {
> >              .slice_data_size   = s->tile_group_info[i].tile_size,
> >              .slice_data_offset = s->tile_group_info[i].tile_offset,
> >              .slice_data_flag   = VA_SLICE_DATA_FLAG_ALL,
> > @@ -408,18 +413,22 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
> >              .tg_start          = s->tg_start,
> >              .tg_end            = s->tg_end,
> >          };
> > -
> > -        err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param, 1,
> > -                                                sizeof(VASliceParameterBufferAV1),
> > -                                                buffer,
> > -                                                size);
> > -        if (err) {
> > -            ff_vaapi_decode_cancel(avctx, pic);
> > -            return err;
> > -        }
> >      }
> >
> > +    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, slice_params, nb_params,
> > +                                            sizeof(VASliceParameterBufferAV1),
> > +                                            buffer,
> > +                                            size);
> > +    av_free(slice_params);
> > +
> > +    if (err)
> > +        goto fail;
> > +
> >      return 0;
> > +
> > +fail:
> > +    ff_vaapi_decode_cancel(avctx, pic);
> > +    return err;
> >  }
> >
> >  const FFHWAccel ff_av1_vaapi_hwaccel = {
>
> It's amusing that this quadratic behaviour was around for so long!  (I guess people don't use many tiles.)
>
> Thanks,
>
> - Mark
> _______________________________________________
> 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".
_______________________________________________
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] 5+ messages in thread

end of thread, other threads:[~2024-05-08  7:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-28  7:26 [FFmpeg-devel] [PATCH 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers David Rosca
2024-04-28  7:26 ` [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times David Rosca
2024-05-07 20:01   ` Mark Thompson
2024-05-08  7:17     ` David Rosca
2024-05-07  6:59 ` [FFmpeg-devel] [PATCH 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers Xiang, Haihao

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