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 BF12C4DAE5 for ; Tue, 3 Jun 2025 17:46:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id BB59168D8E0; Tue, 3 Jun 2025 20:46:45 +0300 (EEST) Received: from vidala.pars.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 7153C68CC08 for ; Tue, 3 Jun 2025 20:46:39 +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=1748972797; bh=l1vg19AcPMkTGXTQ0F1+PBJ QvUn7PFXGXVbriXm7iDI=; b=FY2AaKmKJ8IX+l1wafjq1ZXiEzrUAWOLaafjCtLjqnNJZS6dAw AusWc5uSjDuhkXTv5vcNbwMFz/8q7+r11hDlEHOv9hrkA58jfdy6EWOrBoGOKM8q/wUvGi3SI4O YfaS+7FyqHKXxAcRvr34T/AsJG1hoYdwX+32ZuxdSZJ4dAatUbpSjDmfGveaLSvBz7/NxgCu+Vi 0dmmphw44fXIXBnv43aKm2fs+Hcm7lZ9hePhqomafVZR3HkG9uuNxZ9ZJhBiEN561doUGvn6XUA c7pzhD29D66K5cUhfU788E/20Zkz8oZcvA8JJ1SjoV5Yh0nuM/FJWoRVe5S0C+iL0wA==; DKIM-Signature: v=1; a=ed25519-sha256; s=202405e; d=lynne.ee; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1748972797; bh=l1vg19AcPMkTGXTQ0F1+PBJ QvUn7PFXGXVbriXm7iDI=; b=2G2IdLqx2R25K7JRii4Jzq8j1xUSXXnGTa7xtlIXNHZg2fN1mB Iefdjt96PFzurL+1MLVQXDb0yEq36Srh9dBg==; From: Lynne To: ffmpeg-devel@ffmpeg.org Date: Wed, 4 Jun 2025 02:46:28 +0900 Message-ID: <20250603174633.1626061-1-dev@lynne.ee> X-Mailer: git-send-email 2.49.0.395.g12beb8f557c MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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".