mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2025-09-15 15:01:01 -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();
|
||||
assert( queueFamilyProperties.size() < ( std::numeric_limits<uint32_t>::max )() );
|
||||
|
||||
uint32_t graphicsQueueFamilyIndex = findGraphicsQueueFamilyIndex( queueFamilyProperties );
|
||||
if ( physicalDevice.getSurfaceSupportKHR( graphicsQueueFamilyIndex, surface ) )
|
||||
// look for a queueFamilyIndex that supports graphics and present
|
||||
auto combinedIt = std::find_if( queueFamilyProperties.begin(),
|
||||
queueFamilyProperties.end(),
|
||||
[&physicalDevice, &surface]( vk::QueueFamilyProperties const & qfp )
|
||||
{
|
||||
return std::make_pair( graphicsQueueFamilyIndex,
|
||||
graphicsQueueFamilyIndex ); // the first graphicsQueueFamilyIndex does also support presents
|
||||
static uint32_t index = 0;
|
||||
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
|
||||
}
|
||||
|
||||
// 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++ )
|
||||
else
|
||||
{
|
||||
if ( ( queueFamilyProperties[i].queueFlags & vk::QueueFlagBits::eGraphics ) &&
|
||||
physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( i ), surface ) )
|
||||
// there's no single index that supports both graphics and present -> look for separate ones
|
||||
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" );
|
||||
}
|
||||
}
|
||||
|
||||
// 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++ )
|
||||
else
|
||||
{
|
||||
if ( physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( i ), surface ) )
|
||||
{
|
||||
return std::make_pair( graphicsQueueFamilyIndex, static_cast<uint32_t>( i ) );
|
||||
throw std::runtime_error( "Could not find a queue family index that supports graphics -> terminating" );
|
||||
}
|
||||
}
|
||||
|
||||
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 )
|
||||
@ -997,12 +1012,7 @@ namespace vk
|
||||
glfwContext()
|
||||
{
|
||||
glfwInit();
|
||||
glfwSetErrorCallback(
|
||||
[]( int error, const char * msg )
|
||||
{
|
||||
std::cerr << "glfw: "
|
||||
<< "(" << error << ") " << msg << std::endl;
|
||||
} );
|
||||
glfwSetErrorCallback( []( int error, const char * msg ) { std::cerr << "glfw: " << "(" << error << ") " << msg << std::endl; } );
|
||||
}
|
||||
|
||||
~glfwContext()
|
||||
|
Loading…
x
Reference in New Issue
Block a user