MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Hpp / findGraphicsAndPresentQueueFamilyIndex

Function findGraphicsAndPresentQueueFamilyIndex

samples/utils/utils.cpp:409–458  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

407 }
408
409 std::pair<uint32_t, uint32_t> findGraphicsAndPresentQueueFamilyIndex( vk::PhysicalDevice physicalDevice, vk::SurfaceKHR const & surface )
410 {
411 std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
412 assert( queueFamilyProperties.size() < ( std::numeric_limits<uint32_t>::max )() );
413
414 // look for a queueFamilyIndex that supports graphics and present
415 auto combinedIt = std::find_if( queueFamilyProperties.begin(),
416 queueFamilyProperties.end(),
417 [&physicalDevice, &surface]( vk::QueueFamilyProperties const & qfp )
418 {
419 static uint32_t index = 0;
420 return ( qfp.queueFlags & vk::QueueFlagBits::eGraphics ) && physicalDevice.getSurfaceSupportKHR( index++, surface );
421 } );
422 if ( combinedIt != queueFamilyProperties.end() )
423 {
424 uint32_t index = static_cast<uint32_t>( std::distance( queueFamilyProperties.begin(), combinedIt ) );
425 return { index, index }; // the first index that supports graphics and present
426 }
427 else
428 {
429 // there's no single index that supports both graphics and present -> look for separate ones
430 auto graphicsIt = std::find_if( queueFamilyProperties.begin(),
431 queueFamilyProperties.end(),
432 []( vk::QueueFamilyProperties const & qfp ) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; } );
433 if ( graphicsIt != queueFamilyProperties.end() )
434 {
435 uint32_t graphicsIndex = static_cast<uint32_t>( std::distance( queueFamilyProperties.begin(), graphicsIt ) );
436 auto presentIt = std::find_if( queueFamilyProperties.begin(),
437 queueFamilyProperties.end(),
438 [&physicalDevice, &surface]( vk::QueueFamilyProperties const & )
439 {
440 static uint32_t index = 0;
441 return physicalDevice.getSurfaceSupportKHR( index++, surface );
442 } );
443 if ( presentIt != queueFamilyProperties.end() )
444 {
445 uint32_t presentIndex = static_cast<uint32_t>( std::distance( queueFamilyProperties.begin(), presentIt ) );
446 return { graphicsIndex, presentIndex };
447 }
448 else
449 {
450 throw std::runtime_error( "Could not find a queue family index that supports present -> terminating" );
451 }
452 }
453 else
454 {
455 throw std::runtime_error( "Could not find a queue family index that supports graphics -> terminating" );
456 }
457 }
458 }
459
460 uint32_t findMemoryType( vk::PhysicalDeviceMemoryProperties const & memoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirementsMask )
461 {

Callers 15

mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected