From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 11BFA4AA5A for ; Wed, 8 May 2024 07:13:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0776868D5D4; Wed, 8 May 2024 10:13:16 +0300 (EEST) Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8ED3B68D5C6 for ; Wed, 8 May 2024 10:13:09 +0300 (EEST) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a59a934ad50so920836666b.1 for ; Wed, 08 May 2024 00:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715152388; x=1715757188; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2gr9y0ycJUz7g/8locnNp/xbvm4Xt9bm5oGOJk63n1Q=; b=OypvhYGiEgVBtlATeDRoSQ8uoRlMpZj4OZFdaLx8eHWuZ+dnUTUL04V8v+psg5iqL9 A53WZ9lLffgZpj3KrBtoMKXb4wdW7gf4xM5/PKTx5VPQdK6BRLXEKVLSaRzFBWHFu/9b bkQfxnsTF+tKwKnuxomZEnZKdtxK9GzoMx5uPJnT27LqxU6DGSWe4OY9or5BO4iRGThe suvUHkZ7K3MRjncUVtPcm2CF8wIXlbDsD2MROp/GnG7UWUwCZlVIwNiyDlfrygvGSqrb 5hToNlkEs+yKgcH3mQsYQQOOS7zPWj3OZ+3xHufHNmYxXvwlf/l2NVxED2RpgPFHLTIe mYEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715152388; x=1715757188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2gr9y0ycJUz7g/8locnNp/xbvm4Xt9bm5oGOJk63n1Q=; b=Bd1s9ViPxXl4TdTBYOfQAT9wrkmI1uBRar/MUyJEIHHv1GVO6yy0mGvKXzK9dA7JRf ADq8nqUSLuJm7HVqX03X8vNl8lhQzOHeq0lnTNP8OWU3WLn+8vgINDqrg7u2TBhVJChu fk0aAuG361EckiGCujtlnjWPmUmjaCyWwVqDoPGJQW31L8jqPklOKIEr2Le6Zc7+eX67 1tU4u4MMWZqo4UPVdhYopV1em2EVLvq9eu3PdqK9Bx4Q+DwCYyC3KPxZEJm5xt9EAir0 b4k642TSP4uTtbQCPt/qDI32CsnA+nvz1p5iCJIS3n6WWrKBha+I+Bl1nvtLwQCRCRSP Ap5A== X-Gm-Message-State: AOJu0YyCCVm0AjHkgA3h1/7JMutpn1Aexcggxj5vAwjMMJVANDxR5Prh oeODe3Hr6qmpyzUfxgYYzOINyE0APs4dadLz45mg5zgYptS+BHmNCBegTQ== X-Google-Smtp-Source: AGHT+IE+A8OFs84nmLJcjjHQ92+DkVh7JTHn19bJ7wRzFZEtnmVOOme7ib2g0R6RzE0hICXQ7VY9zQ== X-Received: by 2002:a17:906:80c2:b0:a55:5e89:a158 with SMTP id a640c23a62f3a-a59fb9e7628mr98238166b.68.1715152388430; Wed, 08 May 2024 00:13:08 -0700 (PDT) Received: from mitsuki.. (ip-78-45-35-87.bb.vodafone.cz. [78.45.35.87]) by smtp.gmail.com with ESMTPSA id t16-20020a170906609000b00a59d7505366sm2872828ejj.62.2024.05.08.00.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:13:08 -0700 (PDT) From: David Rosca To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 May 2024 09:11:13 +0200 Message-ID: <20240508071247.133615-4-nowrep@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508071247.133615-2-nowrep@gmail.com> References: <20240508071247.133615-2-nowrep@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: David Rosca Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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. --- v2: Avoid allocations every slice. libavcodec/vaapi_av1.c | 47 +++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c index 4a90db1e09..4ee33a3ae3 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" @@ -42,6 +43,9 @@ typedef struct VAAPIAV1DecContext { */ VAAPIAV1FrameRef ref_tab[AV1_NUM_REF_FRAMES]; AVFrame *tmp_frame; + + int nb_slice_params; + VASliceParameterBufferAV1 *slice_params; } VAAPIAV1DecContext; static VASurfaceID vaapi_av1_surface_id(AV1Frame *vf) @@ -97,6 +101,8 @@ static int vaapi_av1_decode_uninit(AVCodecContext *avctx) for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) av_frame_free(&ctx->ref_tab[i].frame); + av_freep(&ctx->slice_params); + return ff_vaapi_decode_uninit(avctx); } @@ -393,13 +399,24 @@ 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; + VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data; + int err, nb_params; + + nb_params = s->tg_end - s->tg_start + 1; + if (ctx->nb_slice_params < nb_params) { + ctx->slice_params = av_realloc_array(ctx->slice_params, + nb_params, + sizeof(*ctx->slice_params)); + if (!ctx->slice_params) { + ctx->nb_slice_params = 0; + err = AVERROR(ENOMEM); + goto fail; + } + ctx->nb_slice_params = nb_params; + } for (int i = s->tg_start; i <= s->tg_end; i++) { - memset(&slice_param, 0, sizeof(VASliceParameterBufferAV1)); - - slice_param = (VASliceParameterBufferAV1) { + ctx->slice_params[i - s->tg_start] = (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 +425,20 @@ 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, ctx->slice_params, nb_params, + sizeof(VASliceParameterBufferAV1), + buffer, + size); + if (err) + goto fail; + return 0; + +fail: + ff_vaapi_decode_cancel(avctx, pic); + return err; } const FFHWAccel ff_av1_vaapi_hwaccel = { -- 2.45.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".