mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2025-09-16 15:29:11 -04:00
Minor cleanup work on determining graphics and present queue family indices (#2129)
This commit is contained in:
parent
595f21ae1a
commit
ce1ffedb70
@ -422,35 +422,50 @@ namespace vk
|
|||||||
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
|
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
|
||||||
assert( queueFamilyProperties.size() < ( std::numeric_limits<uint32_t>::max )() );
|
assert( queueFamilyProperties.size() < ( std::numeric_limits<uint32_t>::max )() );
|
||||||
|
|
||||||
uint32_t graphicsQueueFamilyIndex = findGraphicsQueueFamilyIndex( queueFamilyProperties );
|
// look for a queueFamilyIndex that supports graphics and present
|
||||||
if ( physicalDevice.getSurfaceSupportKHR( graphicsQueueFamilyIndex, surface ) )
|
auto combinedIt = std::find_if( queueFamilyProperties.begin(),
|
||||||
|
queueFamilyProperties.end(),
|
||||||
|
[&physicalDevice, &surface]( vk::QueueFamilyProperties const & qfp )
|
||||||
{
|
{
|
||||||
return std::make_pair( graphicsQueueFamilyIndex,
|
static uint32_t index = 0;
|
||||||
graphicsQueueFamilyIndex ); // the first graphicsQueueFamilyIndex does also support presents
|
return ( qfp.queueFlags & vk::QueueFlagBits::eGraphics ) && physicalDevice.getSurfaceSupportKHR( index++, surface );
|
||||||
|
} );
|
||||||
|
if ( combinedIt != queueFamilyProperties.end() )
|
||||||
|
{
|
||||||
|
uint32_t index = static_cast<uint32_t>( std::distance( queueFamilyProperties.begin(), combinedIt ) );
|
||||||
|
return { index, index }; // the first index that supports graphics and present
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// the graphicsQueueFamilyIndex doesn't support present -> look for an other family index that supports both
|
|
||||||
// graphics and present
|
|
||||||
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
|
|
||||||
{
|
{
|
||||||
if ( ( queueFamilyProperties[i].queueFlags & vk::QueueFlagBits::eGraphics ) &&
|
// there's no single index that supports both graphics and present -> look for separate ones
|
||||||
physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( i ), surface ) )
|
auto graphicsIt = std::find_if( queueFamilyProperties.begin(),
|
||||||
|
queueFamilyProperties.end(),
|
||||||
|
[]( vk::QueueFamilyProperties const & qfp ) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; } );
|
||||||
|
if ( graphicsIt != queueFamilyProperties.end() )
|
||||||
{
|
{
|
||||||
return std::make_pair( static_cast<uint32_t>( i ), static_cast<uint32_t>( i ) );
|
uint32_t graphicsIndex = static_cast<uint32_t>( std::distance( queueFamilyProperties.begin(), graphicsIt ) );
|
||||||
|
auto presentIt = std::find_if( queueFamilyProperties.begin(),
|
||||||
|
queueFamilyProperties.end(),
|
||||||
|
[&physicalDevice, &surface]( vk::QueueFamilyProperties const & )
|
||||||
|
{
|
||||||
|
static uint32_t index = 0;
|
||||||
|
return physicalDevice.getSurfaceSupportKHR( index++, surface );
|
||||||
|
} );
|
||||||
|
if ( presentIt != queueFamilyProperties.end() )
|
||||||
|
{
|
||||||
|
uint32_t presentIndex = static_cast<uint32_t>( std::distance( queueFamilyProperties.begin(), presentIt ) );
|
||||||
|
return { graphicsIndex, presentIndex };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error( "Could not find a queue family index that supports present -> terminating" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// there's nothing like a single family index that supports both graphics and present -> look for an other family
|
|
||||||
// index that supports present
|
|
||||||
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
|
|
||||||
{
|
{
|
||||||
if ( physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( i ), surface ) )
|
throw std::runtime_error( "Could not find a queue family index that supports graphics -> terminating" );
|
||||||
{
|
|
||||||
return std::make_pair( graphicsQueueFamilyIndex, static_cast<uint32_t>( i ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::runtime_error( "Could not find queues for both graphics or present -> terminating" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t findMemoryType( vk::PhysicalDeviceMemoryProperties const & memoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirementsMask )
|
uint32_t findMemoryType( vk::PhysicalDeviceMemoryProperties const & memoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirementsMask )
|
||||||
@ -997,12 +1012,7 @@ namespace vk
|
|||||||
glfwContext()
|
glfwContext()
|
||||||
{
|
{
|
||||||
glfwInit();
|
glfwInit();
|
||||||
glfwSetErrorCallback(
|
glfwSetErrorCallback( []( int error, const char * msg ) { std::cerr << "glfw: " << "(" << error << ") " << msg << std::endl; } );
|
||||||
[]( int error, const char * msg )
|
|
||||||
{
|
|
||||||
std::cerr << "glfw: "
|
|
||||||
<< "(" << error << ") " << msg << std::endl;
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~glfwContext()
|
~glfwContext()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user