From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id 864374CB40
	for <ffmpegdev@gitmailbox.com>; Thu, 13 Mar 2025 17:06:29 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1688068E76A;
	Thu, 13 Mar 2025 19:04:16 +0200 (EET)
Received: from vidala.pars.ee (vidala.pars.ee [116.203.72.101])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E6F7068E56A
 for <ffmpeg-devel@ffmpeg.org>; Thu, 13 Mar 2025 19:03:58 +0200 (EET)
DKIM-Signature: v=1; a=rsa-sha256; s=202405r; d=lynne.ee; c=relaxed/relaxed;
 h=Message-ID:Date:Subject:To:From; t=1741885438; bh=6plga3w1Phe64uqWvmUkdRr
 Ln5BKeHuOCVPA9+mTzug=; b=ku10KlIFm0nWQzhFdCWR5S+Uyi/CHADYAImOUEwZNg2ogzebfH
 1IGGRM95mXUFCSIjeE/YUc0EJ6UDvS7++yMmXQUI5eECN2ZPSq4LNqPKE8yL/0ixtQ/vYDIITOz
 33AA0AUwoAOSdafiSRX1KMEgqK9fODiOUjQM/DVYu7DT40pi6t5YvttJgFDjHcJyTBPYs8mWF/8
 MLAbgRITAUbimzHkwJCxmfwQIw+StNdIdp2nuNThVmW9K3/Z4l9tcbtRINQWU9AgEiUhCnCsieR
 CtouU4HPuQcdNY2mlf+CcI+mDz7eXHhCbZJdXke9ywGHqw84ZwJpdtEGQLIOsxbu+Xg==;
DKIM-Signature: v=1; a=ed25519-sha256; s=202405e; d=lynne.ee; c=relaxed/relaxed;
 h=Message-ID:Date:Subject:To:From; t=1741885438; bh=6plga3w1Phe64uqWvmUkdRr
 Ln5BKeHuOCVPA9+mTzug=; b=WP+69A+3YR5KTOUyN2kffoGtHxidTwi9ddt/eUYgngJF4Betr9
 oPApNZPowGMHJb8jskivXKkwXHCebu3D79Aw==;
From: Lynne <dev@lynne.ee>
To: ffmpeg-devel@ffmpeg.org
Date: Thu, 13 Mar 2025 18:03:41 +0100
Message-ID: <20250313170355.92290-10-dev@lynne.ee>
X-Mailer: git-send-email 2.47.2
In-Reply-To: <20250313170355.92290-1-dev@lynne.ee>
References: <20250313170355.92290-1-dev@lynne.ee>
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH v4 09/16] vulkan_decode: adjust number of
 async contexts created
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Lynne <dev@lynne.ee>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250313170355.92290-10-dev@lynne.ee/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

This caps the number of contexts we create based on thread count.
This saves VRAM and filters out cases where more async is of lesser
benefit.
---
 libavcodec/vulkan_decode.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index 7f638d6fc6..cd77e10e12 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -1122,6 +1122,7 @@ int ff_vk_decode_init(AVCodecContext *avctx)
     FFVulkanDecodeShared *ctx;
     FFVulkanContext *s;
     FFVulkanFunctions *vk;
+    int async_depth;
     const VkVideoProfileInfoKHR *profile;
     const FFVulkanDecodeDescriptor *vk_desc;
     const VkPhysicalDeviceDriverProperties *driver_props;
@@ -1191,9 +1192,14 @@ int ff_vk_decode_init(AVCodecContext *avctx)
     /* Create decode exec context for this specific main thread.
      * 2 async contexts per thread was experimentally determined to be optimal
      * for a majority of streams. */
+    async_depth = 2*ctx->qf->num;
+    /* We don't need more than 2 per thread context */
+    async_depth = FFMIN(async_depth, 2*avctx->thread_count);
+    /* Make sure there are enough async contexts for each thread */
+    async_depth = FFMAX(async_depth, avctx->thread_count);
+
     err = ff_vk_exec_pool_init(s, ctx->qf, &ctx->exec_pool,
-                               FFMAX(2*ctx->qf->num, avctx->thread_count),
-                               0, 0, 0, profile);
+                               async_depth, 0, 0, 0, profile);
     if (err < 0)
         goto fail;
 
-- 
2.47.2
_______________________________________________
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".