Skip to content

Commit

Permalink
[Vulkan] Improve get_queue_family_index()
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Sep 19, 2023
1 parent d92a663 commit 3822115
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions runtime/RHI/Vulkan/Vulkan_Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,33 +185,37 @@ namespace Spartan

static uint32_t get_queue_family_index(const vector<VkQueueFamilyProperties>& queue_families, VkQueueFlags queue_flags)
{
// based on Sascha Willems' Vulkan examples

// try to find a queue family index that supports compute but not graphics
// compute only queue family index
if ((queue_flags & VK_QUEUE_COMPUTE_BIT) == queue_flags)
{
for (uint32_t i = 0; i < static_cast<uint32_t>(queue_families.size()); i++)
{
if (i == index_graphics)
continue;

if ((queue_families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) && ((queue_families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0))
{
return i;
}
}
}

// try to find a queue family index that supports transfer but not graphics and compute
// transfer only queue family index
if ((queue_flags & VK_QUEUE_TRANSFER_BIT) == queue_flags)
{
for (uint32_t i = 0; i < static_cast<uint32_t>(queue_families.size()); i++)
{
if (i == index_graphics || i == index_compute)
continue;

if ((queue_families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) && ((queue_families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) && ((queue_families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0))
{
return i;
}
}
}

// for other queue types or if no separate compute queue is present, return the first one to support the requested flags
// first available graphics queue family index
for (uint32_t i = 0; i < static_cast<uint32_t>(queue_families.size()); i++)
{
if ((queue_families[i].queueFlags & queue_flags) == queue_flags)
Expand Down

0 comments on commit 3822115

Please sign in to comment.