From: Lynne <dev@lynne.ee>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH] vulkan: take refs of frames using the regular buffer ref path
Date: Mon, 3 Mar 2025 19:44:34 +0100
Message-ID: <be59981a-04ac-48a0-8458-ea3508b16f0c@lynne.ee> (raw)
In-Reply-To: <20250301230250.1027687-1-dev@lynne.ee>
[-- Attachment #1.1.1.1: Type: text/plain, Size: 2697 bytes --]
On 02/03/2025 00:02, Lynne wrote:
> 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;
Pushed.
[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 637 bytes --]
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
prev parent reply other threads:[~2025-03-03 18:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-01 23:02 Lynne
2025-03-03 18:44 ` Lynne [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=be59981a-04ac-48a0-8458-ea3508b16f0c@lynne.ee \
--to=dev@lynne.ee \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git