From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id B23B44CBE1 for ; Fri, 8 Aug 2025 12:48:19 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 0CB6668CCEE; Fri, 8 Aug 2025 15:48:15 +0300 (EEST) Received: from 0f9ae49ae7c8 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id F3047687ADD for ; Fri, 8 Aug 2025 15:48:12 +0300 (EEST) MIME-Version: 1.0 From: bcheng To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] =?utf-8?q?=5BPATCH=5D_vulkan=5Fvp9=3A_Fix_frame_t?= =?utf-8?q?hreading_=28PR_=2320176=29?= 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Message-Id: <20250808124815.0CB6668CCEE@ffbox0-bg.ffmpeg.org> Date: Fri, 8 Aug 2025 15:48:15 +0300 (EEST) Archived-At: List-Archive: List-Post: PR #20176 opened by bcheng URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20176 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20176.patch The original cleanup of frame_id_alloc_mask was done in free_frame_priv which may be called after the start_frame for the next few frames, causing the frame_id slots to be exhausted. Instead, decide the in-use frame_id slots by checking the frame_id present in the DPB as we need it. >From 04147adb519fd4ac9edba14628647a62fed56a00 Mon Sep 17 00:00:00 2001 From: Benjamin Cheng Date: Fri, 8 Aug 2025 08:42:57 -0400 Subject: [PATCH] vulkan_vp9: Fix frame threading The original cleanup of frame_id_alloc_mask was done in free_frame_priv which may be called after the start_frame for the next few frames, causing the frame_id slots to be exhausted. Instead, decide the in-use frame_id slots by checking the frame_id present in the DPB as we need it. --- libavcodec/vulkan_vp9.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libavcodec/vulkan_vp9.c b/libavcodec/vulkan_vp9.c index 82e26cede9..f8ce73dc90 100644 --- a/libavcodec/vulkan_vp9.c +++ b/libavcodec/vulkan_vp9.c @@ -110,6 +110,7 @@ static int vk_vp9_start_frame(AVCodecContext *avctx, int err; int ref_count = 0; const VP9SharedContext *s = avctx->priv_data; + uint32_t frame_id_alloc_mask = 0; const VP9Frame *pic = &s->frames[CUR_FRAME]; FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; @@ -118,17 +119,24 @@ static int vk_vp9_start_frame(AVCodecContext *avctx, VP9VulkanDecodePicture *ap = pic->hwaccel_picture_private; FFVulkanDecodePicture *vp = &ap->vp; + /* Use the current frame_ids in ref_frames[] to decide occupied frame_ids */ + for (int i = 0; i < STD_VIDEO_VP9_NUM_REF_FRAMES; i++) { + const VP9VulkanDecodePicture* rp = s->ref_frames[i].hwaccel_picture_private; + if (rp) + frame_id_alloc_mask |= 1 << rp->frame_id; + } + if (!ap->frame_id_set) { unsigned slot_idx = 0; for (unsigned i = 0; i < 32; i++) { - if (!(dec->frame_id_alloc_mask & (1 << i))) { + if (!(frame_id_alloc_mask & (1 << i))) { slot_idx = i; break; } } ap->frame_id = slot_idx; ap->frame_id_set = 1; - dec->frame_id_alloc_mask |= (1 << slot_idx); + frame_id_alloc_mask |= (1 << slot_idx); } for (int i = 0; i < STD_VIDEO_VP9_REFS_PER_FRAME; i++) { @@ -338,10 +346,6 @@ static void vk_vp9_free_frame_priv(AVRefStructOpaque _hwctx, void *data) AVHWDeviceContext *hwctx = _hwctx.nc; VP9VulkanDecodePicture *ap = data; - /* Workaround for a spec issue. */ - if (ap->frame_id_set) - ap->dec->frame_id_alloc_mask &= ~(1 << ap->frame_id); - /* Free frame resources, this also destroys the session parameters. */ ff_vk_decode_free_frame(hwctx, &ap->vp); } -- 2.49.1 _______________________________________________ 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".