Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ethan-tqa/3efc278190642b774e7ca62ce75f7f1a to your computer and use it in GitHub Desktop.

Select an option

Save ethan-tqa/3efc278190642b774e7ca62ce75f7f1a to your computer and use it in GitHub Desktop.
uint32_t graphicsQueueFamIndex = UINT_MAX;
uint32_t transferQueueFamIndex = UINT_MAX;
uint32_t computeQueueFamIndex = UINT_MAX;
// TODO: are there other ways to pick queue family?
for (uint32_t i = 0; i < queueFamCount; i++)
{
if (graphicsQueueFamIndex == UINT_MAX && supportsPresent[i] == VK_TRUE && queueFamProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
graphicsQueueFamIndex = i;
}
if (computeQueueFamIndex == UINT_MAX && queueFamProps[i].queueFlags & VK_QUEUE_COMPUTE_BIT) {
computeQueueFamIndex = i;
}
if (transferQueueFamIndex == UINT_MAX && queueFamProps[i].queueFlags & VK_QUEUE_TRANSFER_BIT) {
transferQueueFamIndex = i;
}
}
float graphicsPriority = 1.0f;
float computePriority = 0.5f;
float transferPriority = 0.0f;
VkDeviceQueueCreateInfo queueCreateInfos[3];
// we use 1 queue for each type for now
queueCreateInfos[0] = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, nullptr, 0, graphicsQueueFamIndex, 1, &graphicsPriority };
queueCreateInfos[1] = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, nullptr, 0, computeQueueFamIndex, 1, &computePriority };
queueCreateInfos[2] = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, nullptr, 0, transferQueueFamIndex, 1, &transferPriority };
const char *deviceExtensions[] = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
// TODO: if queueCreateInfoCount is more than 1, vkCreateDevice fails
VkDevice device;
VkDeviceCreateInfo devCreateInfo{ VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, nullptr, 0, 3, queueCreateInfos, 1, layers, 1, deviceExtensions, nullptr};
VK_CHECK_RESULT(vkCreateDevice(physDevice, &devCreateInfo, nullptr, &device));
VkQueue graphicsQueue;
vkGetDeviceQueue(device, graphicsQueueFamIndex, 0, &graphicsQueue);
VkQueue computeQueue;
vkGetDeviceQueue(device, computeQueueFamIndex, 0, &computeQueue);
VkQueue transferQueue;
vkGetDeviceQueue(device, transferQueueFamIndex, 0, &transferQueue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment