1
我正在從LunarG的教程代碼中學習Vulkan。 在本教程的03-init_device.cpp
中,它只是獲取隊列家族的計數,然後假定它只有一個隊列並創建邏輯設備。如下示例代碼:如何在Vulkan中獲得隊列數?
int sample_main(int argc, char *argv[]) {
struct sample_info info = {};
init_global_layer_properties(info);
init_instance(info, "vulkansamples_device");
init_enumerate_device(info);
/* VULKAN_KEY_START */
VkDeviceQueueCreateInfo queue_info = {};
vkGetPhysicalDeviceQueueFamilyProperties(info.gpus[0],
&info.queue_family_count, NULL);
assert(info.queue_family_count >= 1);
info.queue_props.resize(info.queue_family_count);
vkGetPhysicalDeviceQueueFamilyProperties(
info.gpus[0], &info.queue_family_count, info.queue_props.data());
assert(info.queue_family_count >= 1);
bool found = false;
for (unsigned int i = 0; i < info.queue_family_count; i++) {
if (info.queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
queue_info.queueFamilyIndex = i;
found = true;
break;
}
}
assert(found);
assert(info.queue_family_count >= 1);
float queue_priorities[1] = {0.0};
queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queue_info.pNext = NULL;
queue_info.queueCount = 1;
queue_info.pQueuePriorities = queue_priorities;
VkDeviceCreateInfo device_info = {};
device_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
device_info.pNext = NULL;
device_info.queueCreateInfoCount = 1;
device_info.pQueueCreateInfos = &queue_info;
device_info.enabledExtensionCount = 0;
device_info.ppEnabledExtensionNames = NULL;
device_info.enabledLayerCount = 0;
device_info.ppEnabledLayerNames = NULL;
device_info.pEnabledFeatures = NULL;
VkDevice device;
VkResult U_ASSERT_ONLY res =
vkCreateDevice(info.gpus[0], &device_info, NULL, &device);
assert(res == VK_SUCCESS);
vkDestroyDevice(device, NULL);
/* VULKAN_KEY_END */
destroy_instance(info);
return 0;
}
那麼,是queue family counts
同樣的事情queue count
? 或者這個示例代碼有問題嗎?
要完成此答案,'VkQueueFamilyProperties :: queueCount'包含給定隊列系列的隊列數。 – pleluron
@ratchet:你是否認爲示例代碼只是通過將1填充到'queue_info.queueCount'而不是'info.queue_props [queue_info.queueFamilyIndex] .queueCount'來謹慎行事? – naive231
@ naive231yeah如果你只需要一個隊列,那麼就沒有必要再多詢問了。 –