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 ESMTP id E4A4845D50 for ; Tue, 6 Jun 2023 23:22:36 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3E4FB68C2E2; Wed, 7 Jun 2023 02:22:32 +0300 (EEST) Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A782F68C2A8 for ; Wed, 7 Jun 2023 02:22:25 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id A116410602C4 for ; Tue, 6 Jun 2023 23:22:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1686093745; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=Cf/z+QgiCSslPsPJ3oWb0FhrYAoK5irDM25Kags28IE=; b=TJ6EOXxxROVq/JROS+QfIb617wRX7QKCw4AnW90TiWXs81Ndtoz8MFc8rh2We/B9 RH840c7ccWkgSVDtY2UlajtShFVPxzuTs2x3Ewlkwtq01zb2rXhV65BqDZuFnY2krsv uO46j80DPlohJTwpZNR/eV3bgirqCvel0Nj0TxVq1dhWeyE3y5wWqxgmrduScpfLHpe nT8j4KmEJVxDkuajIOL2bdwhtB5YPmRpfOuuTW3ISyG8joBbqR7f/E62fhX2RT490fg cbTIti+mlWpOgEVjjpTW2azZzb/fqVBcyCJp3yfD4KFx6JyTXiwo126K+JPoqjRnX3p 8UdRS215OQ== Date: Wed, 7 Jun 2023 01:22:25 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_62290_748799723.1686093745042" Subject: [FFmpeg-devel] [PATCH 1/2] vulkan: synchronize access to execution pool fences 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: ------=_Part_62290_748799723.1686093745042 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit vkResetFences is specified as being user-synchronized (yet vkWaitFences, is not). Patch attached. ------=_Part_62290_748799723.1686093745042 Content-Type: text/x-diff; charset=us-ascii; name=0001-vulkan-synchronize-access-to-execution-pool-fences.patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-vulkan-synchronize-access-to-execution-pool-fences.patch >From c79aa3ed01033f515cbb21251e83cb5bafdf83d7 Mon Sep 17 00:00:00 2001 From: Lynne Date: Wed, 7 Jun 2023 00:24:43 +0200 Subject: [PATCH 1/2] vulkan: synchronize access to execution pool fences vkResetFences is specified as being user-synchronized (yet vkWaitFences, is not). --- libavcodec/vulkan_decode.c | 2 +- libavutil/vulkan.c | 12 ++++++++++-- libavutil/vulkan.h | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index 889c67a15f..9e3ebf6770 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -1106,7 +1106,7 @@ int ff_vk_decode_init(AVCodecContext *avctx) /* Create decode exec context. * 4 async contexts per thread seems like a good number. */ - err = ff_vk_exec_pool_init(s, &qf_dec, &ctx->exec_pool, 4*avctx->thread_count, + err = ff_vk_exec_pool_init(s, &qf_dec, &ctx->exec_pool, 1, nb_q, VK_QUERY_TYPE_RESULT_STATUS_ONLY_KHR, 0, session_create.pVideoProfile); if (err < 0) diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index bc4466e6c9..4b96c0c200 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -241,6 +241,7 @@ void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool) vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); vk->DestroyFence(s->hwctx->act_dev, e->fence, s->hwctx->alloc); } + pthread_mutex_destroy(&e->lock); ff_vk_exec_discard_deps(s, e); @@ -379,12 +380,17 @@ int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, /* Init contexts */ for (int i = 0; i < pool->pool_size; i++) { FFVkExecContext *e = &pool->contexts[i]; - - /* Fence */ VkFenceCreateInfo fence_create = { .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, .flags = VK_FENCE_CREATE_SIGNALED_BIT, }; + + /* Mutex */ + err = pthread_mutex_init(&e->lock, NULL); + if (err != 0) + return AVERROR(err); + + /* Fence */ ret = vk->CreateFence(s->hwctx->act_dev, &fence_create, s->hwctx->alloc, &e->fence); if (ret != VK_SUCCESS) { @@ -489,8 +495,10 @@ int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e) }; /* Create the fence and don't wait for it initially */ + pthread_mutex_lock(&e->lock); vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); vk->ResetFences(s->hwctx->act_dev, 1, &e->fence); + pthread_mutex_unlock(&e->lock); /* Discard queue dependencies */ ff_vk_exec_discard_deps(s, e); diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h index 58da720a1c..bbbc9374ae 100644 --- a/libavutil/vulkan.h +++ b/libavutil/vulkan.h @@ -23,6 +23,7 @@ #include +#include "thread.h" #include "pixdesc.h" #include "bprint.h" #include "hwcontext.h" @@ -152,6 +153,7 @@ typedef struct FFVulkanPipeline { typedef struct FFVkExecContext { int idx; const struct FFVkExecPool *parent; + pthread_mutex_t lock; /* Queue for the execution context */ VkQueue queue; -- 2.40.1 ------=_Part_62290_748799723.1686093745042 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". ------=_Part_62290_748799723.1686093745042--