Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH 3/3] avutil/hwcontext_vulkan: add frames_sync() implementation
Date: Sat,  1 Mar 2025 17:46:21 +0100
Message-ID: <20250301164621.130530-3-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20250301164621.130530-1-ffmpeg@haasn.xyz>

From: Niklas Haas <git@haasn.dev>

Using a new internal function to wait explicitly for all execution pools
to be done executing their internal commands.
---
 libavutil/hwcontext_vulkan.c | 15 +++++++++++++++
 libavutil/vulkan.c           | 10 ++++++++++
 libavutil/vulkan.h           |  5 +++++
 3 files changed, 30 insertions(+)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 10521ce685..91f2db44cb 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2702,6 +2702,18 @@ static void vulkan_frames_uninit(AVHWFramesContext *hwfc)
     av_buffer_pool_uninit(&fp->tmp);
 }
 
+static int vulkan_frames_sync(AVHWFramesContext *hwfc)
+{
+    VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
+    VulkanFramesPriv *fp = hwfc->hwctx;
+
+    ff_vk_exec_pool_wait(&p->vkctx, &fp->compute_exec);
+    ff_vk_exec_pool_wait(&p->vkctx, &fp->upload_exec);
+    ff_vk_exec_pool_wait(&p->vkctx, &fp->download_exec);
+
+    return 0;
+}
+
 static int vulkan_frames_init(AVHWFramesContext *hwfc)
 {
     int err;
@@ -4268,6 +4280,8 @@ static int vulkan_transfer_frame(AVHWFramesContext *hwfc,
         ff_vk_exec_wait(&p->vkctx, exec);
         if (!host_mapped)
             err = copy_buffer_data(hwfc, bufs[0], swf, region, planes, 0);
+    } else if (upload) {
+        ff_vk_exec_wait(&p->vkctx, exec);
     }
 
 end:
@@ -4464,6 +4478,7 @@ const HWContextType ff_hwcontext_type_vulkan = {
     .frames_init            = vulkan_frames_init,
     .frames_get_buffer      = vulkan_get_buffer,
     .frames_uninit          = vulkan_frames_uninit,
+    .frames_sync            = vulkan_frames_sync,
 
     .transfer_get_formats   = vulkan_transfer_get_formats,
     .transfer_data_to       = vulkan_transfer_data_to,
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 1d18bf07c1..f4c51c92d6 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -230,6 +230,16 @@ AVVulkanDeviceQueueFamily *ff_vk_qf_find(FFVulkanContext *s,
     return NULL;
 }
 
+void ff_vk_exec_pool_wait(FFVulkanContext *s, FFVkExecPool *pool)
+{
+    FFVulkanFunctions *vk = &s->vkfn;
+    for (int i = 0; i < pool->pool_size; i++) {
+        FFVkExecContext *e = &pool->contexts[i];
+        if (e->had_submission)
+            ff_vk_exec_wait(s, e);
+    }
+}
+
 void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
 {
     FFVulkanFunctions *vk = &s->vkfn;
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index 617df952c4..7f4522bf16 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -408,6 +408,11 @@ int ff_vk_exec_pool_init(FFVulkanContext *s, AVVulkanDeviceQueueFamily *qf,
                          const void *query_create_pnext);
 void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool);
 
+/**
+ * Wait until all prior submissions have finished.
+ */
+void ff_vk_exec_pool_wait(FFVulkanContext *s, FFVkExecPool *pool);
+
 /**
  * Retrieve an execution pool. Threadsafe.
  */
-- 
2.47.0

_______________________________________________
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".

      parent reply	other threads:[~2025-03-01 16:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-01 16:46 [FFmpeg-devel] [PATCH 1/3] avutil/hwcontext: add av_hwframe_transfer_wait_all() Niklas Haas
2025-03-01 16:46 ` [FFmpeg-devel] [PATCH 2/3] avfilter/hwupload: wait for all pending transfers on uninit() Niklas Haas
2025-03-01 16:46 ` Niklas Haas [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=20250301164621.130530-3-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /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