From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 954174DCE5 for ; Wed, 4 Jun 2025 15:54:21 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 2E5BE68CD3E; Wed, 4 Jun 2025 18:54:08 +0300 (EEST) Received: from vidala.pars.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 41B7968BFA9 for ; Wed, 4 Jun 2025 18:54:01 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; s=202405r; d=lynne.ee; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1749052440; bh=l1vg19AcPMkTGXTQ0F1+PBJ QvUn7PFXGXVbriXm7iDI=; b=e4QCQigZZTPjuNCtMrQj344evAF3S2ff4xlLKiBJrOAP4zFzmB xc9D/JgqunzWBNSOq40m4qYRX55reFCAPtM6NZZUcAfYpUbcKeQE9bsEYHOtiqifpdemxWW3v2o yP0bvBAWVD+7f+VUjmOcFyC1IMExvdPt1nm845Ev/ANtDx2XFC+7OZ4wfHAtQwwaLGJzrXbg/O4 dJ59ix3yQU2egSDvk441ERSNoCyb0sWIzuVjdFwNYsv9VHIIoatI13oyoptwnqJof/e4J8K95w1 tnk6ZyGELEvdz9DOIKqMUfmeXJGF6OLbBvsDaUvmVYSzP95vbE8grJKdX3pyUFKDfkQ==; DKIM-Signature: v=1; a=ed25519-sha256; s=202405e; d=lynne.ee; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1749052440; bh=l1vg19AcPMkTGXTQ0F1+PBJ QvUn7PFXGXVbriXm7iDI=; b=GHLbpgqq/9RcLccBycvEW/YKOX8B/41qkM0FCGSzayaY+ZfhX8 WUy1CvFpqQwOp3UtWtjjpCvu6NsJ0xv0xfDw==; From: Lynne To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Jun 2025 00:53:48 +0900 Message-ID: <20250604155355.1681074-2-dev@lynne.ee> X-Mailer: git-send-email 2.49.0.395.g12beb8f557c In-Reply-To: <20250604155355.1681074-1-dev@lynne.ee> References: <20250604155355.1681074-1-dev@lynne.ee> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/3] hwcontext_vulkan: minimize queue allocation on NVIDIA 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: Lynne 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: On NVIDIA, there's a global maximum limit of approximately 112 queues, which means it takes ONLY 7 total programs using the maximum amount of queues to cause the driver to error out/*segfault* during initialization. Also, each queue takes about 30ms to allocate, which quickly adds up. This reduces the queues allocate to the minimum that we would be happy with. Its not worth limiting decode/encode queues as they're generally not a lot, and do help. --- libavutil/hwcontext_vulkan.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index dc9d49ccb4..243d68dc44 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -1418,6 +1418,13 @@ static int setup_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd) VulkanDevicePriv *p = ctx->hwctx; AVVulkanDeviceContext *hwctx = &p->p; FFVulkanFunctions *vk = &p->vkctx.vkfn; + VkPhysicalDeviceDriverProperties dprops = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES, + }; + VkPhysicalDeviceProperties2 props2 = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, + .pNext = &dprops, + }; VkQueueFamilyProperties2 *qf = NULL; VkQueueFamilyVideoPropertiesKHR *qf_vid = NULL; @@ -1471,7 +1478,14 @@ static int setup_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd) hwctx->nb_qf = 0; - /* Pick each queue family to use */ + /* NVIDIA's proprietary drivers have stupid limits, where each queue + * you allocate takes tens of milliseconds, and the more queues you + * allocate, the less you'll have left before initializing a device + * simply fails (112 seems to be the max). GLOBALLY. + * Detect this, and minimize using queues as much as possible. */ + vk->GetPhysicalDeviceProperties2(hwctx->phys_dev, &props2); + + /* Pick each queue family to use. */ #define PICK_QF(type, vid_op) \ do { \ uint32_t i; \ @@ -1495,6 +1509,14 @@ static int setup_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd) if (i == hwctx->nb_qf) { \ hwctx->qf[i].idx = idx; \ hwctx->qf[i].num = qf[idx].queueFamilyProperties.queueCount; \ + if (dprops.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY) { \ + if (type == VK_QUEUE_GRAPHICS_BIT) \ + hwctx->qf[i].num = FFMIN(hwctx->qf[i].num, 1); \ + if (type == VK_QUEUE_COMPUTE_BIT) \ + hwctx->qf[i].num = FFMIN(hwctx->qf[i].num, 4); \ + if (type == VK_QUEUE_TRANSFER_BIT) \ + hwctx->qf[i].num = FFMIN(hwctx->qf[i].num, 2); \ + } \ hwctx->qf[i].flags = type; \ hwctx->qf[i].video_caps = vid_op; \ hwctx->nb_qf++; \ -- 2.49.0.395.g12beb8f557c _______________________________________________ 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".