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 7E71F4B7EB for ; Sat, 1 Mar 2025 16:47:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6200B68E149; Sat, 1 Mar 2025 18:46:36 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A488468DA46 for ; Sat, 1 Mar 2025 18:46:24 +0200 (EET) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with ESMTP id 6015642471; Sat, 1 Mar 2025 17:46:24 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Mar 2025 17:46:21 +0100 Message-ID: <20250301164621.130530-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250301164621.130530-1-ffmpeg@haasn.xyz> References: <20250301164621.130530-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avutil/hwcontext_vulkan: add frames_sync() implementation 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: Niklas Haas 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: From: Niklas Haas 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".