From patchwork Wed Jun 21 16:50:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 42266 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be15:b0:121:b37c:e101 with SMTP id ge21csp2269703pzb; Wed, 21 Jun 2023 09:50:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4aPuJbEdLY4G55ZIbgZMlZuhC6gMeC1kgdFurytTHv/6powRx8hguMHvXIiwYHBc0ykzSH X-Received: by 2002:a17:906:58c5:b0:988:891b:28c6 with SMTP id e5-20020a17090658c500b00988891b28c6mr10391432ejs.15.1687366253497; Wed, 21 Jun 2023 09:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687366253; cv=none; d=google.com; s=arc-20160816; b=tGjGhDqgG2LNY7QoHLxkYQu2eMgJYOvf4PdpxqH7eLQq0ydND53B1OZzhCYGYuUV+3 J09AuJJpxmmrsCuztus4kLclyFDPJ2Du3q9iwGmmPMOD3U03wvcaTjrp/jfVyTylFFIH s1WM85AJElYIdrRufRBp2m8pJHRzu44d+Ukt7apptlX+o4BrJMq9qA26UdO7ZMCCu4Fl uVowmLyXi3jrajmcEhHHyV/KOneTiy5xVpwK4mOqahX5GNWpQXuscw4shT3Jr3gTOCCQ K/18vSp0DTCesMTKed4OdGNg+ODbwieD0ezIfvti3bHhyBTUug0fzuYqeQnqteAOyW7A eetg== 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=Y4O9oBx88Uw8Y+S3f6GhFYD6MKA65UGBt0cLMSxVJTI=; b=vaYERHYBgMVT72jH64rmExyKnGtS60OJSYs5xviBrQ+vluPvbkqLkBcIO7/+ZojIuh Ut0yQkO0ur6NmUZWr2ZUz569v5br0EgM3yddyglsmpqK4ZmfLGgD66hHeQbDN/I5MeTN n7vKzYhPDMBS5fwy2luMZ2SNg3Naa+RBTWibOWynSHvzhcjkNmGGtrKf+x2oG16MP/ia l4N5U/IEWho+vg/CGqPBlckvGbYAsMdwCT/eiBOYADLTCXN7bEayjek+jD2ZOUzXKlLf m+s6GTwh4lxCzt/CjWrKj93jdIdUMwSxde7p1v+uhx2mMKfcNoJQR9rFeLjcVbPedVEo gAjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=ToRR4Aoc; 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 a15-20020a170906684f00b0096f53f61cc8si2564495ejs.967.2023.06.21.09.50.52; Wed, 21 Jun 2023 09:50:53 -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=ToRR4Aoc; 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 8086268C074; Wed, 21 Jun 2023 19:50:49 +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 46BEF68AFAC for ; Wed, 21 Jun 2023 19:50:43 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 3DCEF1060170 for ; Wed, 21 Jun 2023 16:50:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1687366242; 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=QvypPReZb6NZcsX/ovSD9zky1GkKiOMUrBnaxLA3v/g=; b=ToRR4AocB+xeg9eizAEQcsyV6OHtc18EOB1akh89TRVOiyD1/Al1qVnYPAvM3mEZ C1Oy/xssbAJVtO5oJaTdvuTK2GbW38eMNsZJJnmtjEn+g9rBnm95ekDMPr+ibg+Uz2S EzNhpkZlzCImWLR3jvICnvZNPSAjpTh59FJQkRhluJM+kW+zK6EUka7jTeLbOe2DxDc B9VW6/T4HAycu1bDFG2K0NpMTsG6l14W/KeCJ66z6n4lu/PrtBC3X81CRSaQXkoicoe QVAXddP9qhMazC07TwIMbhapGtTCWk34QILwAhqNi1OHpAsC/XMNCGHkfpH02Wp27Ag pTFn7IVpQw== Date: Wed, 21 Jun 2023 18:50:42 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] vulkan_decode: simplify and make session parameter generation more robust 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: 228N6Q1jNFKU This commit scraps a bool to signal to recreate the session parameters, but instead destroys them, forcing them to be recreated. As this can happen between start_frame and end_frame, do this at both places. From eb6e92f599f8fa7689f16c3ac99f33eedf79b5a8 Mon Sep 17 00:00:00 2001 From: Lynne Date: Wed, 21 Jun 2023 18:24:55 +0200 Subject: [PATCH] vulkan_decode: simplify and make session parameter generation more robust This commit scraps a bool to signal to recreate the session parameters, but instead destroys them, forcing them to be recreated. As this can happen between start_frame and end_frame, do this at both places. --- libavcodec/vulkan_av1.c | 13 +++++++++---- libavcodec/vulkan_decode.c | 4 ++-- libavcodec/vulkan_decode.h | 5 ++--- libavcodec/vulkan_h264.c | 16 ++++++++++------ libavcodec/vulkan_hevc.c | 20 ++++++++++++++++---- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c index 91e44ba803..e6d77df7e4 100644 --- a/libavcodec/vulkan_av1.c +++ b/libavcodec/vulkan_av1.c @@ -229,12 +229,10 @@ static int vk_av1_start_frame(AVCodecContext *avctx, const int apply_grain = !(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && film_grain->apply_grain; - if (!dec->session_params || dec->params_changed) { - av_buffer_unref(&dec->session_params); + if (!dec->session_params) { err = vk_av1_create_params(avctx, &dec->session_params); if (err < 0) return err; - dec->params_changed = 0; } if (!ap->frame_id_set) { @@ -528,12 +526,19 @@ static int vk_av1_decode_slice(AVCodecContext *avctx, static int vk_av1_end_frame(AVCodecContext *avctx) { const AV1DecContext *s = avctx->priv_data; + FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; const AV1Frame *pic = &s->cur_frame; AV1VulkanDecodePicture *ap = pic->hwaccel_picture_private; FFVulkanDecodePicture *vp = &ap->vp; FFVulkanDecodePicture *rvp[AV1_NUM_REF_FRAMES] = { 0 }; AVFrame *rav[AV1_NUM_REF_FRAMES] = { 0 }; + if (!dec->session_params) { + int err = vk_av1_create_params(avctx, &dec->session_params); + if (err < 0) + return err; + } + for (int i = 0; i < vp->decode_info.referenceSlotCount; i++) { const AV1Frame *rp = ap->ref_src[i]; AV1VulkanDecodePicture *rhp = rp->hwaccel_picture_private; @@ -576,7 +581,7 @@ const AVHWAccel ff_av1_vulkan_hwaccel = { .frame_priv_data_size = sizeof(AV1VulkanDecodePicture), .init = &ff_vk_decode_init, .update_thread_context = &ff_vk_update_thread_context, - .decode_params = &ff_vk_params_changed, + .decode_params = &ff_vk_params_invalidate, .flush = &ff_vk_decode_flush, .uninit = &ff_vk_decode_uninit, .frame_params = &ff_vk_frame_params, diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index 685e300e8a..973c7ca548 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -66,10 +66,10 @@ int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) return 0; } -int ff_vk_params_changed(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s) +int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s) { FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; - dec->params_changed = 1; + av_buffer_unref(&dec->session_params); return 0; } diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h index 776538a335..4e45cbde71 100644 --- a/libavcodec/vulkan_decode.h +++ b/libavcodec/vulkan_decode.h @@ -65,7 +65,6 @@ typedef struct FFVulkanDecodeContext { /* Thread-local state below */ AVBufferPool *tmp_pool; /* Pool for temporary data, if needed (HEVC) */ size_t tmp_pool_ele_size; - int params_changed; uint32_t *slice_off; unsigned int slice_off_max; @@ -119,9 +118,9 @@ int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src); int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx); /** - * Sets FFVulkanDecodeContext.params_changed to 1. + * Removes current session parameters to recreate them */ -int ff_vk_params_changed(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s); +int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s); /** * Prepare a frame, creates the image view, and sets up the dpb fields. diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c index d0b66734d1..62e350266a 100644 --- a/libavcodec/vulkan_h264.c +++ b/libavcodec/vulkan_h264.c @@ -379,12 +379,10 @@ static int vk_h264_start_frame(AVCodecContext *avctx, H264VulkanDecodePicture *hp = pic->hwaccel_picture_private; FFVulkanDecodePicture *vp = &hp->vp; - if (!dec->session_params || dec->params_changed) { - av_buffer_unref(&dec->session_params); + if (!dec->session_params) { err = vk_h264_create_params(avctx, &dec->session_params); if (err < 0) return err; - dec->params_changed = 0; } /* Fill in main slot */ @@ -519,8 +517,14 @@ static int vk_h264_end_frame(AVCodecContext *avctx) FFVulkanDecodePicture *rvp[H264_MAX_PICTURE_COUNT] = { 0 }; AVFrame *rav[H264_MAX_PICTURE_COUNT] = { 0 }; - if (!dec->session_params) - return AVERROR(EINVAL); + if (!dec->session_params) { + int err = vk_h264_create_params(avctx, &dec->session_params); + if (err < 0) + return err; + + hp->h264pic.seq_parameter_set_id = pic->pps->sps_id; + hp->h264pic.pic_parameter_set_id = pic->pps->pps_id; + } for (int i = 0; i < vp->decode_info.referenceSlotCount; i++) { H264Picture *rp = hp->ref_src[i]; @@ -560,7 +564,7 @@ const AVHWAccel ff_h264_vulkan_hwaccel = { .frame_priv_data_size = sizeof(H264VulkanDecodePicture), .init = &ff_vk_decode_init, .update_thread_context = &ff_vk_update_thread_context, - .decode_params = &ff_vk_params_changed, + .decode_params = &ff_vk_params_invalidate, .flush = &ff_vk_decode_flush, .uninit = &ff_vk_decode_uninit, .frame_params = &ff_vk_frame_params, diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c index a1df0766fa..5894086821 100644 --- a/libavcodec/vulkan_hevc.c +++ b/libavcodec/vulkan_hevc.c @@ -767,12 +767,10 @@ static int vk_hevc_start_frame(AVCodecContext *avctx, const HEVCPPS *pps = h->ps.pps; int nb_refs = 0; - if (!dec->session_params || dec->params_changed) { - av_buffer_unref(&dec->session_params); + if (!dec->session_params) { err = vk_hevc_create_params(avctx, &dec->session_params); if (err < 0) return err; - dec->params_changed = 0; } hp->h265pic = (StdVideoDecodeH265PictureInfo) { @@ -896,12 +894,26 @@ static int vk_hevc_decode_slice(AVCodecContext *avctx, static int vk_hevc_end_frame(AVCodecContext *avctx) { const HEVCContext *h = avctx->priv_data; + FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; HEVCFrame *pic = h->ref; HEVCVulkanDecodePicture *hp = pic->hwaccel_picture_private; FFVulkanDecodePicture *vp = &hp->vp; FFVulkanDecodePicture *rvp[HEVC_MAX_REFS] = { 0 }; AVFrame *rav[HEVC_MAX_REFS] = { 0 }; + if (!dec->session_params) { + const HEVCSPS *sps = h->ps.sps; + const HEVCPPS *pps = h->ps.pps; + + int err = vk_hevc_create_params(avctx, &dec->session_params); + if (err < 0) + return err; + + hp->h265pic.sps_video_parameter_set_id = sps->vps_id; + hp->h265pic.pps_seq_parameter_set_id = pps->sps_id; + hp->h265pic.pps_pic_parameter_set_id = pps->pps_id; + } + for (int i = 0; i < vp->decode_info.referenceSlotCount; i++) { HEVCVulkanDecodePicture *rfhp = hp->ref_src[i]->hwaccel_picture_private; rav[i] = hp->ref_src[i]->frame; @@ -938,7 +950,7 @@ const AVHWAccel ff_hevc_vulkan_hwaccel = { .frame_priv_data_size = sizeof(HEVCVulkanDecodePicture), .init = &ff_vk_decode_init, .update_thread_context = &ff_vk_update_thread_context, - .decode_params = &ff_vk_params_changed, + .decode_params = &ff_vk_params_invalidate, .flush = &ff_vk_decode_flush, .uninit = &ff_vk_decode_uninit, .frame_params = &ff_vk_frame_params, -- 2.40.1