aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2025-06-04 02:43:41 +0900
committerLynne <dev@lynne.ee>2025-06-10 22:26:14 +0900
commit26d17709e7dca49d5959ca31f9626a603f0bbaee (patch)
tree56d8e39600102f0395d9fb9b6cf449b39bf9c50a
parentb5262bccdba0a86b29c6cc58f099c869df752b61 (diff)
downloadffmpeg-26d17709e7dca49d5959ca31f9626a603f0bbaee.tar.gz
hwcontext_vulkan: minimize queue allocation on NVIDIA
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.
-rw-r--r--libavutil/hwcontext_vulkan.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index dc9d49ccb4..1c298a0b18 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,10 @@ 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); \
+ } \
hwctx->qf[i].flags = type; \
hwctx->qf[i].video_caps = vid_op; \
hwctx->nb_qf++; \