From patchwork Thu Sep 14 23:53:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 43741 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4b2f:b0:149:dfde:5c0a with SMTP id fp47csp760496pzb; Thu, 14 Sep 2023 16:53:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIw5AG0iwJ22tVN74Qz3rY/XaHy0i3CBvfZEM5fSsqUaBOqpBUwlEwPTTnFgoph3/VDBJM X-Received: by 2002:a17:906:114:b0:9a5:d710:dea5 with SMTP id 20-20020a170906011400b009a5d710dea5mr163533eje.17.1694735602508; Thu, 14 Sep 2023 16:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694735602; cv=none; d=google.com; s=arc-20160816; b=Jde5dtA6/MLFeS7mb1bGgJiBDIuiX5v82hAZOAgNG3zIYx31BCc9iVTQFmO6csfBes pxRLoXsfyfmL8Xx+ggsuoVjKd4mBUxvVGMHFh4NLUV/nbVQDtfZAIHY7jhGXVOmjVVV6 uT+EADd++ewS+gdDyTe6C/eM0NtOphyIIM1D6oJVGXV+GQdT3iKFoShyK8xzlF+lRYWW 6LOhLl3coQ3TlKXs30TjlxNKD4tIv5V61l9GeRoiH3LRxP88q9ghHcZWVG85djMfofTO AJOJqYqJiXBD5xSAikO26nBuD6tdc9BNgp2O2UJkQ67MP0IXe+Chaglw/i+E5EWEJhZJ O5Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:to:from:date:dkim-signature:delivered-to; bh=ip2fUIOygh6JTiVNB4+MoS+yOxmuDrzF2orDZmElrFQ=; fh=Q46kXK7oI5D1Jhi90JBr53c7NIaTxGaU4KPeRZyM/hI=; b=L6mPF8vVFzinKR3/w/PEbcTHjf66cOMEgDnyc0OJx2L+1TndL0DkqMd/Q227a77uyo 8m5TOJlfxJXlpdS8ydG6Uy2l+4lE+wZ/rUVl2UxMGNfPFruAjmGoToWdH3TwABXLd0jV BpPVNpU7SQhkj9vNNNAGG0fBWXEQ+WVOAD8CMfjUB+a4nZZHX42TBAbOUeTiP9LT3eqR iMouhmeuzGQpiXSMY0Sd52JPA38yuUry5LiJuL+uXnhZCYenLtHlaeE8LpzdS99z1YkU iALr5XHLzOK9gwNr+gorr0JioFa/DrK+Ln/H7bDnvVbfquAW0YORTxtDizEIvsS/nbE+ 1V1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=0uesFbJW; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f20-20020a170906049400b00992ee6da8e7si2181830eja.740.2023.09.14.16.53.22; Thu, 14 Sep 2023 16:53:22 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=0uesFbJW; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 22B7368C23A; Fri, 15 Sep 2023 02:53:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 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" X-TUID: bcW9D3e03BRz Simpler and more robust now that contexts are not shared between threads. Patch attached. 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