From patchwork Tue Jun 6 23:22:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 41986 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp718365pzb; Tue, 6 Jun 2023 16:22:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ZgWw9drFXV5e06auSHVlIPrnPsdXoPybHosPmlBN5hd9Xl7OCSr1W84iftZ3dutuE80IK X-Received: by 2002:aa7:d648:0:b0:514:a016:9cd1 with SMTP id v8-20020aa7d648000000b00514a0169cd1mr4121620edr.8.1686093762589; Tue, 06 Jun 2023 16:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686093762; cv=none; d=google.com; s=arc-20160816; b=thr+qQvf0IbtFprL5vl4pzhPF8jlcc5DFbJLEFvYtxI3SI8g9f7vBtgTec5m8VrsG6 puqb5rE2ffXFTK9D5FWGuhY3CJdAc3eVEcL8yand1kgGIVB+X6936TgiqKoDfVsCLw63 FksyCrhagiABG6mFxf5lJrL7UdCWRxkCJ7qnoA4z+x5NXLwPqaGGdLWb2QXnt8P7ljGw eJcq1aRvvybMmgWJkLU4ztt9N0o5u4VWXDfrt9DZktah9v2pVb0LZgnEE54NZllNx+3i NG8r+dREjRc0fjHl8XOo1GYtsdARHNfXnB03oJDMaq9mZfI30AlmqsNDQoJjRqaGgUFC sV4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:to:from:date:dkim-signature:delivered-to; bh=c1YWB/8Kgk4utQaHZWEPee02ben2KP82nLgczd5QXnA=; b=WXkFyqpi/8yTOiQ4698MDxGwNp8m0sD9QA5/na4fS0R8b+3Bh94Yefb31qd7SJH8X0 xY0j5FJMnQH9sCuine7OlprU2yE2E92/MW5lj2f9zvZ+FyHwdErGq8H5Ga3t1aLv/z2h V5D+0HFFpXfwVygiVh4/bo46ORUG1WsHn8fnEMtBHeNacK6fC2z73FwDK0q1b3ggXmur 90I+hFu6zr+frzRLP4ZZMR8ArEHEx+XLuyyBKGUr2KOmn3RSwiKR6WM/zayxo5cqFThz SXlz1/Ma8DZPmElScEH4zvhyIsUStaNkzqYJDJP3w3lghSS/pQb2LbilIZNS3TPzuCNU WBtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=TJ6EOXxx; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f14-20020a056402004e00b00514b3b9977bsi8156374edu.297.2023.06.06.16.22.36; Tue, 06 Jun 2023 16:22:42 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=TJ6EOXxx; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7E480680BC0; Wed, 7 Jun 2023 02:22:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 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" X-TUID: VCxjiWv070Bv vkResetFences is specified as being user-synchronized (yet vkWaitFences, is not). Patch attached. 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