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 ESMTPS id DA1354DC48 for ; Sat, 1 Mar 2025 23:03:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D933568E225; Sun, 2 Mar 2025 01:03:01 +0200 (EET) Received: from vidala.pars.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 26B4668E211 for ; Sun, 2 Mar 2025 01:02:55 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; s=202405r; d=lynne.ee; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1740870174; bh=R/mQgRZPj/qI6Br3FOAmwKG t9cWAgD/D3bIuRqKQIF8=; b=Yt1mHP0z46J/xeNRd7nR+0VNobgGU6ewB5ny9GARdarOsJmeDv R8aK5Rnzi5XW7VO6TysOnARYpGLh9Ytf5f+xwCLmphZKxYdDmBLCBhTeZpNywRXpZixxNBVRcAn 24g1gp8WGMH6CTsYPuCX0SVK5SHr6TrikDr0/cMEDxITliyf757/X+L8i//eC5ULuO0kOa4cT5K Kid0Z+Bfeeh2dMXiTPQfGCR/c4KvckD9BlZpJM5bJ9BYOJg0IfkbuuMv/CrXuInOODHb6AOLxrv 2TOnJmw5d0nJsNHq3tWPGdmIzOB6eelfu/ZTZ1bKMq7WJI6IYm6xt7/mtXqZGdyQW7Q==; DKIM-Signature: v=1; a=ed25519-sha256; s=202405e; d=lynne.ee; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1740870174; bh=R/mQgRZPj/qI6Br3FOAmwKG t9cWAgD/D3bIuRqKQIF8=; b=xh+3wQ+pnG0R6cWMrjeenAvk2Ye+7FmOH4Hm81BC1d9mUbSrBv /im87LyC5fuIw7v7sSfiq3Yft/JKZV11LXBQ==; From: Lynne To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Mar 2025 00:02:45 +0100 Message-ID: <20250301230250.1027687-1-dev@lynne.ee> X-Mailer: git-send-email 2.47.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] vulkan: take refs of frames using the regular buffer ref path 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: Lynne 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: This simplifies the code, reduces allocations, and critically, does not store references of frames, along with references to hw_frames_ctx. The issue was that storing refs to frames while transferring stored refs to hw_frames_ctx of frames, and so created a circular dependency, which caused the Vulkan device to never be terminated. This only stores what it strictly needs as a dependency, and enables the frames context to be freed, even while doing asynchronous transfers. --- libavutil/vulkan.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index 1d18bf07c1..2ae619967a 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -538,8 +538,6 @@ void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e) e->frame_locked[j] = 0; } e->frame_update[j] = 0; - if (f->buf[0]) - av_frame_free(&e->frame_deps[j]); } e->nb_frame_deps = 0; @@ -700,6 +698,7 @@ int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, uint8_t *frame_locked; uint8_t *frame_update; AVFrame **frame_deps; + AVBufferRef **buf_deps; VkImageLayout *layout_dst; uint32_t *queue_family_dst; VkAccessFlagBits *access_dst; @@ -722,12 +721,21 @@ int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, ARR_REALLOC(e, frame_update, &e->frame_update_alloc_size, e->nb_frame_deps); ARR_REALLOC(e, frame_deps, &e->frame_deps_alloc_size, e->nb_frame_deps); - e->frame_deps[e->nb_frame_deps] = f->buf[0] ? av_frame_clone(f) : f; - if (!e->frame_deps[e->nb_frame_deps]) { - ff_vk_exec_discard_deps(s, e); - return AVERROR(ENOMEM); + /* prepare_frame in hwcontext_vulkan.c uses the regular frame management + * code but has no frame yet, and it doesn't need to actually store a ref + * to the frame. */ + if (f->buf[0]) { + ARR_REALLOC(e, buf_deps, &e->buf_deps_alloc_size, e->nb_buf_deps); + e->buf_deps[e->nb_buf_deps] = av_buffer_ref(f->buf[0]); + if (!e->buf_deps[e->nb_buf_deps]) { + ff_vk_exec_discard_deps(s, e); + return AVERROR(ENOMEM); + } + e->nb_buf_deps++; } + e->frame_deps[e->nb_frame_deps] = f; + vkfc->lock_frame(hwfc, vkf); e->frame_locked[e->nb_frame_deps] = 1; e->frame_update[e->nb_frame_deps] = 0; -- 2.47.2 _______________________________________________ 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".