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 )
|
||||||
@ -574,20 +589,20 @@ namespace vk
|
|||||||
switch ( oldImageLayout )
|
switch ( oldImageLayout )
|
||||||
{
|
{
|
||||||
case vk::ImageLayout::eTransferDstOptimal: sourceAccessMask = vk::AccessFlagBits::eTransferWrite; break;
|
case vk::ImageLayout::eTransferDstOptimal: sourceAccessMask = vk::AccessFlagBits::eTransferWrite; break;
|
||||||
case vk::ImageLayout::ePreinitialized: sourceAccessMask = vk::AccessFlagBits::eHostWrite; break;
|
case vk::ImageLayout::ePreinitialized : sourceAccessMask = vk::AccessFlagBits::eHostWrite; break;
|
||||||
case vk::ImageLayout::eGeneral: // sourceAccessMask is empty
|
case vk::ImageLayout::eGeneral : // sourceAccessMask is empty
|
||||||
case vk::ImageLayout::eUndefined: break;
|
case vk::ImageLayout::eUndefined : break;
|
||||||
default: assert( false ); break;
|
default : assert( false ); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::PipelineStageFlags sourceStage;
|
vk::PipelineStageFlags sourceStage;
|
||||||
switch ( oldImageLayout )
|
switch ( oldImageLayout )
|
||||||
{
|
{
|
||||||
case vk::ImageLayout::eGeneral:
|
case vk::ImageLayout::eGeneral:
|
||||||
case vk::ImageLayout::ePreinitialized: sourceStage = vk::PipelineStageFlagBits::eHost; break;
|
case vk::ImageLayout::ePreinitialized : sourceStage = vk::PipelineStageFlagBits::eHost; break;
|
||||||
case vk::ImageLayout::eTransferDstOptimal: sourceStage = vk::PipelineStageFlagBits::eTransfer; break;
|
case vk::ImageLayout::eTransferDstOptimal: sourceStage = vk::PipelineStageFlagBits::eTransfer; break;
|
||||||
case vk::ImageLayout::eUndefined: sourceStage = vk::PipelineStageFlagBits::eTopOfPipe; break;
|
case vk::ImageLayout::eUndefined : sourceStage = vk::PipelineStageFlagBits::eTopOfPipe; break;
|
||||||
default: assert( false ); break;
|
default : assert( false ); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::AccessFlags destinationAccessMask;
|
vk::AccessFlags destinationAccessMask;
|
||||||
@ -598,24 +613,24 @@ namespace vk
|
|||||||
destinationAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentRead | vk::AccessFlagBits::eDepthStencilAttachmentWrite;
|
destinationAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentRead | vk::AccessFlagBits::eDepthStencilAttachmentWrite;
|
||||||
break;
|
break;
|
||||||
case vk::ImageLayout::eGeneral: // empty destinationAccessMask
|
case vk::ImageLayout::eGeneral: // empty destinationAccessMask
|
||||||
case vk::ImageLayout::ePresentSrcKHR: break;
|
case vk::ImageLayout::ePresentSrcKHR : break;
|
||||||
case vk::ImageLayout::eShaderReadOnlyOptimal: destinationAccessMask = vk::AccessFlagBits::eShaderRead; break;
|
case vk::ImageLayout::eShaderReadOnlyOptimal: destinationAccessMask = vk::AccessFlagBits::eShaderRead; break;
|
||||||
case vk::ImageLayout::eTransferSrcOptimal: destinationAccessMask = vk::AccessFlagBits::eTransferRead; break;
|
case vk::ImageLayout::eTransferSrcOptimal : destinationAccessMask = vk::AccessFlagBits::eTransferRead; break;
|
||||||
case vk::ImageLayout::eTransferDstOptimal: destinationAccessMask = vk::AccessFlagBits::eTransferWrite; break;
|
case vk::ImageLayout::eTransferDstOptimal : destinationAccessMask = vk::AccessFlagBits::eTransferWrite; break;
|
||||||
default: assert( false ); break;
|
default : assert( false ); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::PipelineStageFlags destinationStage;
|
vk::PipelineStageFlags destinationStage;
|
||||||
switch ( newImageLayout )
|
switch ( newImageLayout )
|
||||||
{
|
{
|
||||||
case vk::ImageLayout::eColorAttachmentOptimal: destinationStage = vk::PipelineStageFlagBits::eColorAttachmentOutput; break;
|
case vk::ImageLayout::eColorAttachmentOptimal : destinationStage = vk::PipelineStageFlagBits::eColorAttachmentOutput; break;
|
||||||
case vk::ImageLayout::eDepthStencilAttachmentOptimal: destinationStage = vk::PipelineStageFlagBits::eEarlyFragmentTests; break;
|
case vk::ImageLayout::eDepthStencilAttachmentOptimal: destinationStage = vk::PipelineStageFlagBits::eEarlyFragmentTests; break;
|
||||||
case vk::ImageLayout::eGeneral: destinationStage = vk::PipelineStageFlagBits::eHost; break;
|
case vk::ImageLayout::eGeneral : destinationStage = vk::PipelineStageFlagBits::eHost; break;
|
||||||
case vk::ImageLayout::ePresentSrcKHR: destinationStage = vk::PipelineStageFlagBits::eBottomOfPipe; break;
|
case vk::ImageLayout::ePresentSrcKHR : destinationStage = vk::PipelineStageFlagBits::eBottomOfPipe; break;
|
||||||
case vk::ImageLayout::eShaderReadOnlyOptimal: destinationStage = vk::PipelineStageFlagBits::eFragmentShader; break;
|
case vk::ImageLayout::eShaderReadOnlyOptimal : destinationStage = vk::PipelineStageFlagBits::eFragmentShader; break;
|
||||||
case vk::ImageLayout::eTransferDstOptimal:
|
case vk::ImageLayout::eTransferDstOptimal :
|
||||||
case vk::ImageLayout::eTransferSrcOptimal: destinationStage = vk::PipelineStageFlagBits::eTransfer; break;
|
case vk::ImageLayout::eTransferSrcOptimal : destinationStage = vk::PipelineStageFlagBits::eTransfer; break;
|
||||||
default: assert( false ); break;
|
default : assert( false ); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::ImageAspectFlags aspectMask;
|
vk::ImageAspectFlags aspectMask;
|
||||||
@ -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