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 9183447623 for ; Thu, 14 Sep 2023 23:53:21 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CF22368C622; Fri, 15 Sep 2023 02:53:18 +0300 (EEST) Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5770868C23A for ; Fri, 15 Sep 2023 02:53:12 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id E267D1060171 for ; Thu, 14 Sep 2023 23:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1694735591; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=Pq0QcfiIDNFfSoK+dyTnAX4yfUVP1lMEoknMuBxoDjw=; b=0uesFbJWIBQeIqSDvoXESizIzrM/6dXv4cB3feysglKkz0K9eaJxny3J1wczEiYi lPrnbcbSuqoibLXn/b+Q2j4DiJquHpDKLHrVL/apbrN4irVm1xShTYGNs7V5UyqnU4z PuThw8DGlLbDGoqPrwKQJwwZhIAQOJnaa8Z0qCJngQ+duTfacK1rjY0ZlQs10hdgfIV RoNX48cU4Ob59BQuObdK0lTGrDb+FNAmVbHKRVZWpjEfI+HwNlMX/sfLxGRW8waHOxT K+WPWy2rDiMOsV12reNFY6NC63/jltC5fSVAZk2Nc2R0WYS03kBf4p6N+jvyP10mhZb iLKyxij/vQ== Date: Fri, 15 Sep 2023 01:53:11 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_209971_488448829.1694735591737" Subject: [FFmpeg-devel] [PATCH] vulkan_hevc: switch from a buffer pool to a simple malloc 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: ------=_Part_209971_488448829.1694735591737 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Simpler and more robust now that contexts are not shared between threads. Patch attached. ------=_Part_209971_488448829.1694735591737 Content-Type: text/x-diff; charset=us-ascii; name=0001-vulkan_hevc-switch-from-a-buffer-pool-to-a-simple-ma.patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-vulkan_hevc-switch-from-a-buffer-pool-to-a-simple-ma.patch >From f476162c2b0b165f5cb23398bf6b989b4503daee Mon Sep 17 00:00:00 2001 From: Lynne Date: Fri, 15 Sep 2023 01:51:49 +0200 Subject: [PATCH] vulkan_hevc: switch from a buffer pool to a simple malloc Simpler and more robust now that contexts are not shared between threads. --- libavcodec/vulkan_decode.c | 2 +- libavcodec/vulkan_decode.h | 4 ++-- libavcodec/vulkan_hevc.c | 33 ++++++++++++++------------------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index 3986330c81..3253bf6fef 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -1075,7 +1075,7 @@ int ff_vk_decode_uninit(AVCodecContext *avctx) /* Wait on and free execution pool */ ff_vk_exec_pool_free(&ctx->s, &dec->exec_pool); - av_buffer_pool_uninit(&dec->tmp_pool); + av_freep(&dec->hevc_headers); av_buffer_unref(&dec->session_params); av_buffer_unref(&dec->shared_ref); av_freep(&dec->slice_off); diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h index c50527e5f8..65e883a044 100644 --- a/libavcodec/vulkan_decode.h +++ b/libavcodec/vulkan_decode.h @@ -64,8 +64,8 @@ typedef struct FFVulkanDecodeContext { uint32_t frame_id_alloc_mask; /* For AV1 only */ /* Thread-local state below */ - AVBufferPool *tmp_pool; /* Pool for temporary data, if needed (HEVC) */ - size_t tmp_pool_ele_size; + struct HEVCHeaderSet *hevc_headers; + size_t hevc_headers_size; uint32_t *slice_off; unsigned int slice_off_max; diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c index 672694a19d..faf8959ca5 100644 --- a/libavcodec/vulkan_hevc.c +++ b/libavcodec/vulkan_hevc.c @@ -68,10 +68,11 @@ typedef struct HEVCHeaderSet { HEVCHeaderVPS *hvps; } HEVCHeaderSet; -static int get_data_set_buf(FFVulkanDecodeContext *s, AVBufferRef **data_buf, - int nb_vps, AVBufferRef * const vps_list[HEVC_MAX_VPS_COUNT]) +static int alloc_hevc_header_structs(FFVulkanDecodeContext *s, + int nb_vps, + AVBufferRef * const vps_list[HEVC_MAX_VPS_COUNT]) { - uint8_t *data_ptr; + uintptr_t data_ptr; HEVCHeaderSet *hdr; size_t base_size = sizeof(StdVideoH265SequenceParameterSet)*HEVC_MAX_SPS_COUNT + @@ -93,22 +94,18 @@ static int get_data_set_buf(FFVulkanDecodeContext *s, AVBufferRef **data_buf, buf_size += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters; } - if (buf_size > s->tmp_pool_ele_size) { - av_buffer_pool_uninit(&s->tmp_pool); - s->tmp_pool_ele_size = 0; - s->tmp_pool = av_buffer_pool_init(buf_size, NULL); - if (!s->tmp_pool) + if (buf_size > s->hevc_headers_size) { + av_freep(&s->hevc_headers); + s->hevc_headers_size = 0; + s->hevc_headers = av_mallocz(buf_size); + if (!s->hevc_headers) return AVERROR(ENOMEM); - s->tmp_pool_ele_size = buf_size; + s->hevc_headers_size = buf_size; } - *data_buf = av_buffer_pool_get(s->tmp_pool); - if (!(*data_buf)) - return AVERROR(ENOMEM); - /* Setup pointers */ - data_ptr = (*data_buf)->data; - hdr = (HEVCHeaderSet *)data_ptr; + hdr = s->hevc_headers; + data_ptr = (uintptr_t)hdr; hdr->hvps = (HEVCHeaderVPS *)(data_ptr + base_size); data_ptr += base_size + vps_size*nb_vps; for (int i = 0; i < nb_vps; i++) { @@ -674,7 +671,6 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf) }; int nb_vps = 0; - AVBufferRef *data_set; HEVCHeaderSet *hdr; AVBufferRef *tmp; @@ -685,11 +681,11 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf) for (int i = 0; h->ps.vps_list[i]; i++) nb_vps++; - err = get_data_set_buf(dec, &data_set, nb_vps, h->ps.vps_list); + err = alloc_hevc_header_structs(dec, nb_vps, h->ps.vps_list); if (err < 0) return err; - hdr = (HEVCHeaderSet *)data_set->data; + hdr = dec->hevc_headers; h265_params_info.pStdSPSs = hdr->sps; h265_params_info.pStdPPSs = hdr->pps; @@ -728,7 +724,6 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf) /* Create session parameters */ ret = vk->CreateVideoSessionParametersKHR(ctx->s.hwctx->act_dev, &session_params_create, ctx->s.hwctx->alloc, par); - av_buffer_unref(&data_set); if (ret != VK_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Unable to create Vulkan video session parameters: %s!\n", ff_vk_ret2str(ret)); -- 2.40.1 ------=_Part_209971_488448829.1694735591737 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". ------=_Part_209971_488448829.1694735591737--