From 634467acf3c3de7efe198cd02601534390dc8530 Mon Sep 17 00:00:00 2001 From: Andrii Pauk Date: Thu, 25 Nov 2021 18:43:43 +0200 Subject: [PATCH] vkr: Use vkGetDeviceQueue with queues that created with flags zero This is a fix for segfault issue, because of usage of uninitialized vkQueue handle. Spec [1] states that vkGetDeviceQueue must only be used to get queues that were created with the flags parameter of VkDeviceQueueCreateInfo set to zero. To get queues that were created with a non-zero flags parameter use vkGetDeviceQueue2. The problem that in case queue was created with flags set to zero following vkGetDeviceQueue2 call will fail. By failing I mean that pQueue set to NULL, which later leads to segfault. This problem was also reported by vulkan validation layer: vkr: vkGetDeviceQueue2: value of pQueueInfo->flags must not be 0. The Vulkan spec states: flags must not be 0 (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkDeviceQueueInfo2-flags-requiredbitmask) [1]: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDeviceQueue.html Signed-off-by: Andrii Pauk Reviewed-by: Chia-I Wu --- src/venus/vkr_device.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/venus/vkr_device.c b/src/venus/vkr_device.c index 4b069f2..5b7f2ea 100644 --- a/src/venus/vkr_device.c +++ b/src/venus/vkr_device.c @@ -32,7 +32,14 @@ vkr_device_create_queues(struct vkr_context *ctx, .queueIndex = j, }; VkQueue handle = VK_NULL_HANDLE; - vkGetDeviceQueue2(dev->base.handle.device, &info, &handle); + /* There was a bug in spec which forbids usage of vkGetDeviceQueue2 + * with flags set to zero. It was fixed in spec version 1.1.130. + * Work around drivers that are implementing this buggy behavior + */ + if (info.flags) + vkGetDeviceQueue2(dev->base.handle.device, &info, &handle); + else + vkGetDeviceQueue(dev->base.handle.device, info.queueFamilyIndex, info.queueIndex, &handle); struct vkr_queue *queue = vkr_queue_create( ctx, dev, info.flags, info.queueFamilyIndex, info.queueIndex, handle);