【发布时间】:2019-12-02 11:39:04
【问题描述】:
TL;DR
vkAcquireNextImageKHR 在使用某些队列族时抛出 std::out_of_range。这是预期的行为吗?如何调试?
详细说明
我使用的 Vulkan 程序基于vulkan-tutorial.com。我发现我的VkPhysicalDevice 有三个队列系列,每个都标有VK_QUEUE_GRAPHICS_BIT 并提供支持:
uint32_t queueFamilyCount;
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr);
std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount);
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, queueFamilies.data());
std::vector<uint32_t> graphicsQueueFamilyIndices;
std::vector<uint32_t> presentQueueFamilyIndices;
int i = 0;
for (const auto& queueFamily : queueFamilies)
{
if (queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT)
{
graphicsQueueFamilyIndices.push_back(i);
}
VkBool32 presentSupport = false;
vkGetPhysicalDeviceSurfaceSupportKHR(
device,
i,
surface,
&presentSupport
);
if (presentSupport)
{
presentQueueFamilyIndices.push_back(i);
}
++i;
}
// graphicsQueueFamilyIndices = {0, 1, 2}
// presentQueueFamilyIndices = {0, 1, 2}
这些稍后在创建逻辑设备、交换链(队列系列都具有当前功能)和命令池时使用。稍后程序调用
vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, semaphore, VK_NULL_HANDLE, &imageIndex);
但是使用
但是使用以下的当前和图形队列索引的任意组合会导致此 API 调用抛出未捕获的0 以外的任何其他参数都会导致此 API 调用抛出未捕获的 std::out_of_range(输出是 lldb 的输出):std::out_of_range:(1, 1)、(1, 2)、(2, 1)、(2, 2)。
lldb输出如下:
2019-12-01 11:36:35.599882+0100 main[22130:167876] flock failed to lock maps file: errno = 35
2019-12-01 11:36:35.600165+0100 main[22130:167876] flock failed to lock maps file: errno = 35
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: Index out of range
Process 22130 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00007fff675c949a libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
-> 0x7fff675c949a <+10>: jae 0x7fff675c94a4 ; <+20>
0x7fff675c949c <+12>: movq %rax, %rdi
0x7fff675c949f <+15>: jmp 0x7fff675c33b7 ; cerror_nocancel
0x7fff675c94a4 <+20>: retq
Target 0: (main) stopped.
使用甚至不引用队列的索引时也会导致相同的错误,例如123。我正在使用VK_LAYER_KHRONOS_validation 层,它没有任何抱怨。
问题
(1) 这是将错误的队列族索引传递给 Vk 的预期行为吗?
(2) 是否有能够捕获此错误并使其更详细的验证层?
(3) 为什么这些队列族的选择会导致这个错误?
详情
对图形使用队列族索引(1, 1) 并在逻辑设备创建期间显示队列族,而对其他所有事物使用索引0 已经导致vkAcquireNextImage 引发错误。当然,VK_LAYER_KHRONOS_validation 在创建命令池时会引发以下警告:
Validation layer: vkCreateCommandPool: pCreateInfo->queueFamilyIndex (= 0) is not one of the queue families given via VkDeviceQueueCreateInfo structures when the device was created. The Vulkan spec states: pCreateInfo::queueFamilyIndex must be the index of a queue family available in the logical device device. (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-vkCreateCommandPool-queueFamilyIndex-01937)
我在 macOS Catalina 10.15.1 上使用 MoltenVK(来自 Vulkan SDK,版本 1.1.126.0)。
解决方法
使用 SDK 1.1.121.1 版本可防止发生抛出异常。
创建索引为
0的设备队列系列以及可能需要的任何其他设备队列可防止发生抛出。
GitHub 上的问题
这已在 GitHub [here] 上作为问题提出。
【问题讨论】:
-
"但使用 0 以外的任何值" 您将这些值放在哪里?
-
您的意思是我在哪些 API 调用中使用这些队列索引?那将是 (1)
vkGetDeviceQueue,一次用于图形,一次用于当前; (2)在createInfo.pQueueFamilyIndices中,其中createInfo作为pCreateInfo参数传递给vkCreateSwapchainKHR; (3) 在poolInfo.queueFamilyIndex中,其中poolInfo被延迟传递给vkCreateCommandPool作为pCreateInfo参数。 -
Vulkan 甚至不是 C++ API。它不能抛出
std::任何东西。你的回溯看起来很奇怪;我需要查看函数名称和异常来源。我不确定“com.apple”是什么意思,这是 MoltenVK 吗? -
我浏览了一下源代码,MoltenVK 似乎总是隐式地使用队列系列 0 来获取。如果你使用栅栏而没有信号量会发生什么?如果您在
vkCreateDevice与其他队列一起创建队列族 0(但否则不使用它)会发生什么?