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 E825345D6F for ; Wed, 7 Jun 2023 00:00:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C2F4A68C371; Wed, 7 Jun 2023 03:00:01 +0300 (EEST) Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C6B2268C14C for ; Wed, 7 Jun 2023 02:59:55 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id CF0B0106015D for ; Tue, 6 Jun 2023 23:59:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1686095995; 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:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=3g6jryRYAQC/N4gmO9T0OlzcnItE63eUdq+wtCp1B9o=; b=x3WNSn0dguJwbpCF/88C2ce8Wtq3Y0XtXQhOLtlIHZELv8HmLHiDvkHRnxtz4jNd sN5zq9fvv9q8Njn/jeSt7nr2wqsqYygipzWZr26RqkJcr/QssrghfKRx2Rab87lbzNj 86+cqKpNeAhOr4+65cjAAkxAP1EexiuiaG/N/J1lW4fCqGsPhYNCZSgqkzPwiOY0pxS F1wH+GE08KtrLrZpInfw6cAJVUnTFsHLiFF5517OCPIbhXDLrOp2D9ALi1ZsvqGi3pE XOmLL4s6MOnNcyjE1dmCKP8+Y/nGfJsERlaMrl4mAjXrEePfzT9WthA6amtLVsnBgpa I/enXH+doQ== Date: Wed, 7 Jun 2023 01:59:55 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_63726_1797350313.1686095995430" Subject: Re: [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_63726_1797350313.1686095995430 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Jun 7, 2023, 01:45 by dev@lynne.ee: > Jun 7, 2023, 01:22 by dev@lynne.ee: > >> vkResetFences is specified as being user-synchronized >> (yet vkWaitFences, is not). >> >> Patch attached. >> > > Stray change in vulkan_decode.c removed locally. > Also removed the vkWaitForFences call during the _start function from the mutex lock, as it's safe to do so, and added a comment. ------=_Part_63726_1797350313.1686095995430 Content-Type: text/x-diff; charset=us-ascii; name=v2-0001-vulkan-synchronize-access-to-execution-pool-fence.patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=v2-0001-vulkan-synchronize-access-to-execution-pool-fence.patch >From ef13ab7974ea3833e1063dfd14e92550ad27b53b Mon Sep 17 00:00:00 2001 From: Lynne Date: Wed, 7 Jun 2023 00:24:43 +0200 Subject: [PATCH v2 1/2] vulkan: synchronize access to execution pool fences vkResetFences is specified as being user-synchronized (yet vkWaitFences, is not). --- libavutil/vulkan.c | 16 +++++++++++++--- libavutil/vulkan.h | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index bc4466e6c9..b1c585292e 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) { @@ -488,9 +494,13 @@ int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e) .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, }; - /* Create the fence and don't wait for it initially */ + /* Wait for the fence to be signalled */ vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX); + + /* vkResetFences is defined as being host-synchronized */ + pthread_mutex_lock(&e->lock); 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_63726_1797350313.1686095995430 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_63726_1797350313.1686095995430--