TL;博士
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 [此处]上作为问题提出。