Merge pull request #1217 from asuessenbach/160

Change ColumnLimit with clang-format from 120 to 160.
This commit is contained in:
Andreas Süßenbach 2022-02-28 13:01:14 +01:00 committed by GitHub
commit 417991599d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
127 changed files with 37432 additions and 57496 deletions

View File

@ -44,7 +44,7 @@ BreakBeforeTernaryOperators : true
BreakConstructorInitializers : BeforeComma BreakConstructorInitializers : BeforeComma
BreakInheritanceList : BeforeComma BreakInheritanceList : BeforeComma
BreakStringLiterals : false BreakStringLiterals : false
ColumnLimit : 120 ColumnLimit : 160
CompactNamespaces : false CompactNamespaces : false
ConstructorInitializerAllOnOneLineOrOnePerLine : true ConstructorInitializerAllOnOneLineOrOnePerLine : true
ConstructorInitializerIndentWidth : 2 ConstructorInitializerIndentWidth : 2

View File

@ -38,7 +38,7 @@ BreakBeforeTernaryOperators : true
BreakConstructorInitializers : BeforeComma BreakConstructorInitializers : BeforeComma
BreakInheritanceList : BeforeComma BreakInheritanceList : BeforeComma
BreakStringLiterals : false BreakStringLiterals : false
ColumnLimit : 120 ColumnLimit : 160
CompactNamespaces : false CompactNamespaces : false
ConstructorInitializerAllOnOneLineOrOnePerLine : true ConstructorInitializerAllOnOneLineOrOnePerLine : true
ConstructorInitializerIndentWidth : 2 ConstructorInitializerIndentWidth : 2

View File

@ -36,8 +36,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
// find the index of the first queue family that supports graphics // find the index of the first queue family that supports graphics
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
// create a Device // create a Device
float queuePriority = 0.0f; float queuePriority = 0.0f;

View File

@ -33,9 +33,8 @@ int main( int /*argc*/, char ** /*argv*/ )
#endif #endif
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() ); vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
@ -45,8 +44,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// allocate a CommandBuffer from the CommandPool // allocate a CommandBuffer from the CommandPool
vk::CommandBufferAllocateInfo commandBufferAllocateInfo( *commandPool, vk::CommandBufferLevel::ePrimary, 1 ); vk::CommandBufferAllocateInfo commandBufferAllocateInfo( *commandPool, vk::CommandBufferLevel::ePrimary, 1 );
vk::raii::CommandBuffer commandBuffer = vk::raii::CommandBuffer commandBuffer = std::move( vk::raii::CommandBuffers( device, commandBufferAllocateInfo ).front() );
std::move( vk::raii::CommandBuffers( device, commandBufferAllocateInfo ).front() );
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }

View File

@ -27,15 +27,14 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() ); vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties(); std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( queueFamilyProperties ); uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( queueFamilyProperties );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
@ -79,31 +78,26 @@ int main( int /*argc*/, char ** /*argv*/ )
} }
} }
} }
if ( ( graphicsQueueFamilyIndex == queueFamilyProperties.size() ) || if ( ( graphicsQueueFamilyIndex == queueFamilyProperties.size() ) || ( presentQueueFamilyIndex == queueFamilyProperties.size() ) )
( presentQueueFamilyIndex == queueFamilyProperties.size() ) )
{ {
throw std::runtime_error( "Could not find a queue for graphics or present -> terminating" ); throw std::runtime_error( "Could not find a queue for graphics or present -> terminating" );
} }
// create a device // create a device
vk::raii::Device device = vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex, vk::su::getDeviceExtensions() );
vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex, vk::su::getDeviceExtensions() );
// get the supported VkFormats // get the supported VkFormats
std::vector<vk::SurfaceFormatKHR> formats = physicalDevice.getSurfaceFormatsKHR( *surface ); std::vector<vk::SurfaceFormatKHR> formats = physicalDevice.getSurfaceFormatsKHR( *surface );
assert( !formats.empty() ); assert( !formats.empty() );
vk::Format format = vk::Format format = ( formats[0].format == vk::Format::eUndefined ) ? vk::Format::eB8G8R8A8Unorm : formats[0].format;
( formats[0].format == vk::Format::eUndefined ) ? vk::Format::eB8G8R8A8Unorm : formats[0].format;
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( *surface ); vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( *surface );
vk::Extent2D swapchainExtent; vk::Extent2D swapchainExtent;
if ( surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max() ) if ( surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max() )
{ {
// If the surface size is undefined, the size is set to the size of the images requested. // If the surface size is undefined, the size is set to the size of the images requested.
swapchainExtent.width = swapchainExtent.width = vk::su::clamp( width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width );
vk::su::clamp( width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width ); swapchainExtent.height = vk::su::clamp( height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height );
swapchainExtent.height =
vk::su::clamp( height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height );
} }
else else
{ {
@ -114,19 +108,15 @@ int main( int /*argc*/, char ** /*argv*/ )
// The FIFO present mode is guaranteed by the spec to be supported // The FIFO present mode is guaranteed by the spec to be supported
vk::PresentModeKHR swapchainPresentMode = vk::PresentModeKHR::eFifo; vk::PresentModeKHR swapchainPresentMode = vk::PresentModeKHR::eFifo;
vk::SurfaceTransformFlagBitsKHR preTransform = vk::SurfaceTransformFlagBitsKHR preTransform = ( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity )
( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity ) ? vk::SurfaceTransformFlagBitsKHR::eIdentity
? vk::SurfaceTransformFlagBitsKHR::eIdentity : surfaceCapabilities.currentTransform;
: surfaceCapabilities.currentTransform;
vk::CompositeAlphaFlagBitsKHR compositeAlpha = vk::CompositeAlphaFlagBitsKHR compositeAlpha =
( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied
? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit ) ? vk::CompositeAlphaFlagBitsKHR::eInherit
? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied : vk::CompositeAlphaFlagBitsKHR::eOpaque;
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit )
? vk::CompositeAlphaFlagBitsKHR::eInherit
: vk::CompositeAlphaFlagBitsKHR::eOpaque;
vk::SwapchainCreateInfoKHR swapChainCreateInfo( vk::SwapchainCreateFlagsKHR(), vk::SwapchainCreateInfoKHR swapChainCreateInfo( vk::SwapchainCreateFlagsKHR(),
*surface, *surface,
@ -160,8 +150,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::raii::ImageView> imageViews; std::vector<vk::raii::ImageView> imageViews;
imageViews.reserve( swapChainImages.size() ); imageViews.reserve( swapChainImages.size() );
vk::ImageViewCreateInfo imageViewCreateInfo( vk::ImageViewCreateInfo imageViewCreateInfo( {}, {}, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
{}, {}, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
for ( auto image : swapChainImages ) for ( auto image : swapChainImages )
{ {
imageViewCreateInfo.image = static_cast<vk::Image>( image ); imageViewCreateInfo.image = static_cast<vk::Image>( image );

View File

@ -27,8 +27,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -38,8 +37,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
@ -78,8 +76,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++ ) for ( uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++ )
{ {
if ( ( typeBits & 1 ) && if ( ( typeBits & 1 ) &&
( ( memoryProperties.memoryTypes[i].propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal ) == ( ( memoryProperties.memoryTypes[i].propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal ) == vk::MemoryPropertyFlagBits::eDeviceLocal ) )
vk::MemoryPropertyFlagBits::eDeviceLocal ) )
{ {
typeIndex = i; typeIndex = i;
break; break;
@ -92,9 +89,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::DeviceMemory depthMemory( device, memoryAllocateInfo ); vk::raii::DeviceMemory depthMemory( device, memoryAllocateInfo );
depthImage.bindMemory( *depthMemory, 0 ); depthImage.bindMemory( *depthMemory, 0 );
vk::ImageViewCreateInfo imageViewCreateInfo( vk::ImageViewCreateInfo imageViewCreateInfo( {}, *depthImage, vk::ImageViewType::e2D, depthFormat, {}, { vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1 } );
{}, *depthImage, vk::ImageViewType::e2D, depthFormat, {}, { vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1 } ); vk::raii::ImageView depthView( device, imageViewCreateInfo );
vk::raii::ImageView depthView( device, imageViewCreateInfo );
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
} }

View File

@ -40,22 +40,19 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() ); vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
glm::mat4x4 model = glm::mat4x4( 1.0f ); glm::mat4x4 model = glm::mat4x4( 1.0f );
glm::mat4x4 view = glm::mat4x4 view = glm::lookAt( glm::vec3( -5.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
glm::lookAt( glm::vec3( -5.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
glm::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f ); glm::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f );
// clang-format off // clang-format off
glm::mat4x4 clip = glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f, glm::mat4x4 clip = glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f,
@ -69,10 +66,9 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::Buffer uniformDataBuffer( device, bufferCreateInfo ); vk::raii::Buffer uniformDataBuffer( device, bufferCreateInfo );
vk::MemoryRequirements memoryRequirements = uniformDataBuffer.getMemoryRequirements(); vk::MemoryRequirements memoryRequirements = uniformDataBuffer.getMemoryRequirements();
uint32_t typeIndex = uint32_t typeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits,
memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, typeIndex ); vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, typeIndex );
vk::raii::DeviceMemory uniformDataMemory( device, memoryAllocateInfo ); vk::raii::DeviceMemory uniformDataMemory( device, memoryAllocateInfo );

View File

@ -27,22 +27,19 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() ); vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
// create a DescriptorSetLayout // create a DescriptorSetLayout
vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding( vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, descriptorSetLayoutBinding ); vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, descriptorSetLayoutBinding );
vk::raii::DescriptorSetLayout descriptorSetLayout( device, descriptorSetLayoutCreateInfo ); vk::raii::DescriptorSetLayout descriptorSetLayout( device, descriptorSetLayoutCreateInfo );

View File

@ -40,41 +40,35 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() ); vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( vk::Extent2D( 0, 0 ) );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( vk::Extent2D( 0, 0 ) );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::raii::su::makeDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
// create a descriptor pool // create a descriptor pool
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 ); vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 );
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize );
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ); vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// allocate a descriptor set // allocate a descriptor set
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet = vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
vk::DescriptorBufferInfo descriptorBufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo descriptorBufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::WriteDescriptorSet writeDescriptorSet( vk::WriteDescriptorSet writeDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo );
*descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr ); device.updateDescriptorSets( writeDescriptorSet, nullptr );
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */

View File

@ -39,8 +39,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -50,11 +49,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::Format depthFormat = vk::Format::eD16Unorm; vk::Format depthFormat = vk::Format::eD16Unorm;
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */

View File

@ -29,16 +29,14 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() ); vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
@ -46,8 +44,8 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<unsigned int> vertexShaderSPV; std::vector<unsigned int> vertexShaderSPV;
#if !defined( NDEBUG ) #if !defined( NDEBUG )
bool ok = bool ok =
#endif #endif
vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C, vertexShaderSPV ); vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C, vertexShaderSPV );
assert( ok ); assert( ok );

View File

@ -27,8 +27,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -38,23 +37,20 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::SwapChainData swapChainData( physicalDevice, vk::raii::su::SwapChainData swapChainData( physicalDevice,
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::RenderPass renderPass = vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
vk::raii::su::makeRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -66,8 +62,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( auto const & view : swapChainData.imageViews ) for ( auto const & view : swapChainData.imageViews )
{ {
attachments[0] = *view; attachments[0] = *view;
vk::FramebufferCreateInfo framebufferCreateInfo( vk::FramebufferCreateInfo framebufferCreateInfo( {}, *renderPass, attachments, surfaceData.extent.width, surfaceData.extent.height, 1 );
{}, *renderPass, attachments, surfaceData.extent.width, surfaceData.extent.height, 1 );
framebuffers.push_back( vk::raii::Framebuffer( device, framebufferCreateInfo ) ); framebuffers.push_back( vk::raii::Framebuffer( device, framebufferCreateInfo ) );
} }

View File

@ -38,8 +38,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -49,11 +48,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -62,19 +60,17 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::RenderPass renderPass = vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
vk::raii::su::makeRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -84,10 +80,9 @@ int main( int /*argc*/, char ** /*argv*/ )
// allocate device memory for that buffer // allocate device memory for that buffer
vk::MemoryRequirements memoryRequirements = vertexBuffer.getMemoryRequirements(); vk::MemoryRequirements memoryRequirements = vertexBuffer.getMemoryRequirements();
uint32_t memoryTypeIndex = uint32_t memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits,
memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ); vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
vk::raii::DeviceMemory deviceMemory( device, memoryAllocateInfo ); vk::raii::DeviceMemory deviceMemory( device, memoryAllocateInfo );
@ -103,8 +98,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -114,8 +108,7 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( {} ); commandBuffer.begin( {} );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindVertexBuffers( 0, { *vertexBuffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBuffer }, { 0 } );

View File

@ -41,8 +41,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -52,22 +51,18 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, vk::Format::eD16Unorm );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, vk::Format::eD16Unorm );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::raii::su::makeDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -82,87 +77,78 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ), vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 ) vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
}; };
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( {}, // flags
{}, // flags vertexInputBindingDescription, // vertexBindingDescriptions
vertexInputBindingDescription, // vertexBindingDescriptions vertexInputAttributeDescriptions // vertexAttributeDescriptions
vertexInputAttributeDescriptions // vertexAttributeDescriptions
); );
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( {}, vk::PrimitiveTopology::eTriangleList );
{}, vk::PrimitiveTopology::eTriangleList );
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( {}, 1, nullptr, 1, nullptr ); vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( {}, 1, nullptr, 1, nullptr );
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( {}, // flags
{}, // flags false, // depthClampEnable
false, // depthClampEnable false, // rasterizerDiscardEnable
false, // rasterizerDiscardEnable vk::PolygonMode::eFill, // polygonMode
vk::PolygonMode::eFill, // polygonMode vk::CullModeFlagBits::eBack, // cullMode
vk::CullModeFlagBits::eBack, // cullMode vk::FrontFace::eClockwise, // frontFace
vk::FrontFace::eClockwise, // frontFace false, // depthBiasEnable
false, // depthBiasEnable 0.0f, // depthBiasConstantFactor
0.0f, // depthBiasConstantFactor 0.0f, // depthBiasClamp
0.0f, // depthBiasClamp 0.0f, // depthBiasSlopeFactor
0.0f, // depthBiasSlopeFactor 1.0f // lineWidth
1.0f // lineWidth
); );
vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( {}, // flags
{}, // flags vk::SampleCountFlagBits::e1 // rasterizationSamples
vk::SampleCountFlagBits::e1 // rasterizationSamples // other values can be default
// other values can be default
); );
vk::StencilOpState stencilOpState( vk::StencilOpState stencilOpState( vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways ); vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo( {}, // flags
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo( true, // depthTestEnable
{}, // flags true, // depthWriteEnable
true, // depthTestEnable vk::CompareOp::eLessOrEqual, // depthCompareOp
true, // depthWriteEnable false, // depthBoundTestEnable
vk::CompareOp::eLessOrEqual, // depthCompareOp false, // stencilTestEnable
false, // depthBoundTestEnable stencilOpState, // front
false, // stencilTestEnable stencilOpState // back
stencilOpState, // front
stencilOpState // back
); );
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB |
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA ); vk::ColorComponentFlagBits::eA );
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false, // blendEnable
false, // blendEnable vk::BlendFactor::eZero, // srcColorBlendFactor
vk::BlendFactor::eZero, // srcColorBlendFactor vk::BlendFactor::eZero, // dstColorBlendFactor
vk::BlendFactor::eZero, // dstColorBlendFactor vk::BlendOp::eAdd, // colorBlendOp
vk::BlendOp::eAdd, // colorBlendOp vk::BlendFactor::eZero, // srcAlphaBlendFactor
vk::BlendFactor::eZero, // srcAlphaBlendFactor vk::BlendFactor::eZero, // dstAlphaBlendFactor
vk::BlendFactor::eZero, // dstAlphaBlendFactor vk::BlendOp::eAdd, // alphaBlendOp
vk::BlendOp::eAdd, // alphaBlendOp colorComponentFlags // colorWriteMask
colorComponentFlags // colorWriteMask
); );
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( {}, // flags
{}, // flags false, // logicOpEnable
false, // logicOpEnable vk::LogicOp::eNoOp, // logicOp
vk::LogicOp::eNoOp, // logicOp pipelineColorBlendAttachmentState, // attachments
pipelineColorBlendAttachmentState, // attachments { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( {}, dynamicStates ); vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( {}, dynamicStates );
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( {}, // flags
{}, // flags pipelineShaderStageCreateInfos, // stages
pipelineShaderStageCreateInfos, // stages &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState nullptr, // pTessellationState
nullptr, // pTessellationState &pipelineViewportStateCreateInfo, // pViewportState
&pipelineViewportStateCreateInfo, // pViewportState &pipelineRasterizationStateCreateInfo, // pRasterizationState
&pipelineRasterizationStateCreateInfo, // pRasterizationState &pipelineMultisampleStateCreateInfo, // pMultisampleState
&pipelineMultisampleStateCreateInfo, // pMultisampleState &pipelineDepthStencilStateCreateInfo, // pDepthStencilState
&pipelineDepthStencilStateCreateInfo, // pDepthStencilState &pipelineColorBlendStateCreateInfo, // pColorBlendState
&pipelineColorBlendStateCreateInfo, // pColorBlendState &pipelineDynamicStateCreateInfo, // pDynamicState
&pipelineDynamicStateCreateInfo, // pDynamicState *pipelineLayout, // layout
*pipelineLayout, // layout *renderPass // renderPass
*renderPass // renderPass
); );
vk::raii::Pipeline pipeline( device, nullptr, graphicsPipelineCreateInfo ); vk::raii::Pipeline pipeline( device, nullptr, graphicsPipelineCreateInfo );

View File

@ -42,8 +42,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -53,11 +52,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -67,63 +65,53 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::raii::su::makeDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::raii::DescriptorPool descriptorPool = vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } ); vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::DescriptorSet descriptorSet = vk::raii::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, {} );
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets(
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, {} );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( vk::raii::Pipeline graphicsPipeline =
device, vk::raii::su::makeGraphicsPipeline( device,
pipelineCache, pipelineCache,
vertexShaderModule, vertexShaderModule,
nullptr, nullptr,
fragmentShaderModule, fragmentShaderModule,
nullptr, nullptr,
vk::su::checked_cast<uint32_t>( sizeof( coloredCubeData[0] ) ), vk::su::checked_cast<uint32_t>( sizeof( coloredCubeData[0] ) ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } }, { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise, vk::FrontFace::eClockwise,
true, true,
pipelineLayout, pipelineLayout,
renderPass ); renderPass );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -132,8 +120,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -142,21 +129,14 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -177,9 +157,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -49,16 +49,13 @@ int main( int /*argc*/, char ** /*argv*/ )
// Translate the version into major/minor for easier comparison // Translate the version into major/minor for easier comparison
uint32_t loader_major_version = VK_VERSION_MAJOR( apiVersion ); uint32_t loader_major_version = VK_VERSION_MAJOR( apiVersion );
uint32_t loader_minor_version = VK_VERSION_MINOR( apiVersion ); uint32_t loader_minor_version = VK_VERSION_MINOR( apiVersion );
std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version << "\n";
<< "\n";
// Check current version against what we want to run // Check current version against what we want to run
if ( loader_major_version > desiredMajorVersion || if ( loader_major_version > desiredMajorVersion || ( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
{ {
// Create the instance // Create the instance
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -91,13 +88,12 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( usingMinorVersion < desiredMinorVersion ) if ( usingMinorVersion < desiredMinorVersion )
{ {
std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString << " instead of desired version "
<< " instead of desired version " << desiredVersionString << std::endl; << desiredVersionString << std::endl;
} }
else else
{ {
std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString << std::endl;
<< std::endl;
} }
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */

View File

@ -27,8 +27,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -45,11 +44,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -59,8 +57,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc |
vk::ImageUsageFlagBits::eTransferSrc |
vk::ImageUsageFlagBits::eTransferDst, vk::ImageUsageFlagBits::eTransferDst,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
@ -69,8 +66,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( swapChainData.colorFormat ); vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( swapChainData.colorFormat );
assert( ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc ) && assert( ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc ) && "Format cannot be used as transfer source" );
"Format cannot be used as transfer source" );
#endif #endif
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
@ -78,8 +74,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -104,18 +99,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties(); vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties();
vk::MemoryRequirements memoryRequirements = blitSourceImage.getMemoryRequirements(); vk::MemoryRequirements memoryRequirements = blitSourceImage.getMemoryRequirements();
uint32_t memoryTypeIndex = vk::su::findMemoryType( uint32_t memoryTypeIndex = vk::su::findMemoryType( memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible );
memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ); vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
vk::raii::DeviceMemory deviceMemory( device, memoryAllocateInfo ); vk::raii::DeviceMemory deviceMemory( device, memoryAllocateInfo );
blitSourceImage.bindMemory( *deviceMemory, 0 ); blitSourceImage.bindMemory( *deviceMemory, 0 );
vk::raii::su::setImageLayout( commandBuffer, vk::raii::su::setImageLayout( commandBuffer, *blitSourceImage, swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eGeneral );
*blitSourceImage,
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eGeneral );
commandBuffer.end(); commandBuffer.end();
@ -154,27 +144,18 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
// Intend to blit from this image, set the layout accordingly // Intend to blit from this image, set the layout accordingly
vk::raii::su::setImageLayout( commandBuffer, vk::raii::su::setImageLayout( commandBuffer, *blitSourceImage, swapChainData.colorFormat, vk::ImageLayout::eGeneral, vk::ImageLayout::eTransferSrcOptimal );
*blitSourceImage,
swapChainData.colorFormat,
vk::ImageLayout::eGeneral,
vk::ImageLayout::eTransferSrcOptimal );
vk::Image blitDestinationImage = static_cast<vk::Image>( swapChainData.images[imageIndex] ); vk::Image blitDestinationImage = static_cast<vk::Image>( swapChainData.images[imageIndex] );
// Do a 32x32 blit to all of the dst image - should get big squares // Do a 32x32 blit to all of the dst image - should get big squares
vk::ImageSubresourceLayers imageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 ); vk::ImageSubresourceLayers imageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 );
vk::ImageBlit imageBlit( vk::ImageBlit imageBlit( imageSubresourceLayers,
imageSubresourceLayers, { { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 32, 32, 1 ) } },
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 32, 32, 1 ) } }, imageSubresourceLayers,
imageSubresourceLayers, { { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( surfaceData.extent.width, surfaceData.extent.height, 1 ) } } );
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( surfaceData.extent.width, surfaceData.extent.height, 1 ) } } ); commandBuffer.blitImage(
commandBuffer.blitImage( *blitSourceImage, *blitSourceImage, vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageBlit, vk::Filter::eLinear );
vk::ImageLayout::eTransferSrcOptimal,
blitDestinationImage,
vk::ImageLayout::eTransferDstOptimal,
imageBlit,
vk::Filter::eLinear );
// Use a barrier to make sure the blit is finished before the copy starts // Use a barrier to make sure the blit is finished before the copy starts
vk::ImageMemoryBarrier memoryBarrier( vk::AccessFlagBits::eTransferWrite, vk::ImageMemoryBarrier memoryBarrier( vk::AccessFlagBits::eTransferWrite,
@ -185,36 +166,21 @@ int main( int /*argc*/, char ** /*argv*/ )
VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED,
blitDestinationImage, blitDestinationImage,
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) ); vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
commandBuffer.pipelineBarrier( commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, {}, nullptr, nullptr, memoryBarrier );
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, {}, nullptr, nullptr, memoryBarrier );
// Do a image copy to part of the dst image - checks should stay small // Do a image copy to part of the dst image - checks should stay small
vk::ImageCopy imageCopy( imageSubresourceLayers, vk::ImageCopy imageCopy( imageSubresourceLayers, vk::Offset3D(), imageSubresourceLayers, vk::Offset3D( 256, 256, 0 ), vk::Extent3D( 128, 128, 1 ) );
vk::Offset3D(), commandBuffer.copyImage( *blitSourceImage, vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageCopy );
imageSubresourceLayers,
vk::Offset3D( 256, 256, 0 ),
vk::Extent3D( 128, 128, 1 ) );
commandBuffer.copyImage( *blitSourceImage,
vk::ImageLayout::eTransferSrcOptimal,
blitDestinationImage,
vk::ImageLayout::eTransferDstOptimal,
imageCopy );
vk::ImageMemoryBarrier prePresentBarrier( vk::ImageMemoryBarrier prePresentBarrier( vk::AccessFlagBits::eTransferWrite,
vk::AccessFlagBits::eTransferWrite, vk::AccessFlagBits::eMemoryRead,
vk::AccessFlagBits::eMemoryRead, vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::ePresentSrcKHR,
vk::ImageLayout::ePresentSrcKHR, VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED, blitDestinationImage,
blitDestinationImage, vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) ); commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTopOfPipe, {}, nullptr, nullptr, prePresentBarrier );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer,
vk::PipelineStageFlagBits::eTopOfPipe,
{},
nullptr,
nullptr,
prePresentBarrier );
commandBuffer.end(); commandBuffer.end();
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() ); vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
@ -232,9 +198,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -67,8 +67,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc( VkDebugUtilsMessageSeverityFlag
message << "\t\t" message << "\t\t"
<< "Object " << i << "\n"; << "Object " << i << "\n";
message << "\t\t\t" message << "\t\t\t"
<< "objectType = " << "objectType = " << vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) << "\n";
<< vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) << "\n";
message << "\t\t\t" message << "\t\t\t"
<< "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n"; << "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n";
if ( pCallbackData->pObjects[i].pObjectName ) if ( pCallbackData->pObjects[i].pObjectName )
@ -98,14 +97,11 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::ExtensionProperties> props = context.enumerateInstanceExtensionProperties(); std::vector<vk::ExtensionProperties> props = context.enumerateInstanceExtensionProperties();
auto propsIterator = std::find_if( props.begin(), auto propsIterator = std::find_if(
props.end(), props.begin(), props.end(), []( vk::ExtensionProperties const & ep ) { return strcmp( ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) == 0; } );
[]( vk::ExtensionProperties const & ep )
{ return strcmp( ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) == 0; } );
if ( propsIterator == props.end() ) if ( propsIterator == props.end() )
{ {
std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension" std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension" << std::endl;
<< std::endl;
exit( 1 ); exit( 1 );
} }
@ -116,12 +112,10 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
vk::DebugUtilsMessageSeverityFlagBitsEXT::eError ); vk::DebugUtilsMessageSeverityFlagBitsEXT::eError );
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation ); vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfoEXT( vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc );
{}, severityFlags, messageTypeFlags, &debugMessageFunc ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, debugUtilsMessengerCreateInfoEXT );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, debugUtilsMessengerCreateInfoEXT );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }

View File

@ -31,8 +31,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -40,17 +39,15 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PhysicalDevices physicalDevices( instance ); vk::raii::PhysicalDevices physicalDevices( instance );
assert( !physicalDevices.empty() ); assert( !physicalDevices.empty() );
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevices[0].getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevices[0].getQueueFamilyProperties() ); vk::raii::Device device = vk::raii::su::makeDevice( physicalDevices[0], graphicsQueueFamilyIndex );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevices[0], graphicsQueueFamilyIndex );
// create an image // create an image
vk::raii::Image image = vk::raii::su::makeImage( device ); vk::raii::Image image = vk::raii::su::makeImage( device );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
vk::DebugUtilsObjectNameInfoEXT debugUtilsObjectNameInfo( vk::DebugUtilsObjectNameInfoEXT debugUtilsObjectNameInfo( vk::ObjectType::eImage, NON_DISPATCHABLE_HANDLE_TO_UINT64_CAST( VkImage, *image ), "Image name" );
vk::ObjectType::eImage, NON_DISPATCHABLE_HANDLE_TO_UINT64_CAST( VkImage, *image ), "Image name" );
device.setDebugUtilsObjectNameEXT( debugUtilsObjectNameInfo ); device.setDebugUtilsObjectNameEXT( debugUtilsObjectNameInfo );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */

View File

@ -33,8 +33,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -44,11 +43,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -58,8 +56,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -71,60 +68,49 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() ); textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, vk::raii::su::makeDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( vk::raii::DescriptorPool descriptorPool =
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::raii::DescriptorSet descriptorSet = vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets( device, vk::raii::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, { textureData } );
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } },
{ textureData } );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
vk::raii::su::makeGraphicsPipeline( device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -132,8 +118,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -142,22 +127,15 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -178,9 +156,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -37,8 +37,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -48,11 +47,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -62,32 +60,26 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -100,9 +92,8 @@ int main( int /*argc*/, char ** /*argv*/ )
/* Set up uniform buffer with 2 transform matrices in it */ /* Set up uniform buffer with 2 transform matrices in it */
glm::mat4x4 mvpcs[2]; glm::mat4x4 mvpcs[2];
glm::mat4x4 model = glm::mat4x4( 1.0f ); glm::mat4x4 model = glm::mat4x4( 1.0f );
glm::mat4x4 view = glm::mat4x4 view = glm::lookAt( glm::vec3( 0.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
glm::lookAt( glm::vec3( 0.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
glm::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f ); glm::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f );
// clang-format off // clang-format off
glm::mat4x4 clip = glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f, glm::mat4x4 clip = glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f,
@ -118,49 +109,42 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DeviceSize bufferSize = sizeof( glm::mat4x4 ); vk::DeviceSize bufferSize = sizeof( glm::mat4x4 );
if ( limits.minUniformBufferOffsetAlignment ) if ( limits.minUniformBufferOffsetAlignment )
{ {
bufferSize = bufferSize = ( bufferSize + limits.minUniformBufferOffsetAlignment - 1 ) & ~( limits.minUniformBufferOffsetAlignment - 1 );
( bufferSize + limits.minUniformBufferOffsetAlignment - 1 ) & ~( limits.minUniformBufferOffsetAlignment - 1 );
} }
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcs, 2, bufferSize ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcs, 2, bufferSize );
// create a DescriptorSetLayout with vk::DescriptorType::eUniformBufferDynamic // create a DescriptorSetLayout with vk::DescriptorType::eUniformBufferDynamic
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::raii::su::makeDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
// create a DescriptorPool with vk::DescriptorType::eUniformBufferDynamic // create a DescriptorPool with vk::DescriptorType::eUniformBufferDynamic
vk::raii::DescriptorPool descriptorPool = vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } ); vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets( vk::raii::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, nullptr } }, {} );
device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, nullptr } }, {} );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
vk::raii::su::makeGraphicsPipeline( device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( coloredCubeData[0] ),
sizeof( coloredCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -169,32 +153,24 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
/* The first draw should use the first matrix in the buffer */ /* The first draw should use the first matrix in the buffer */
uint32_t dynamicOffset = 0; uint32_t dynamicOffset = 0;
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, dynamicOffset );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, dynamicOffset );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
// the second draw should use the second matrix in the buffer; // the second draw should use the second matrix in the buffer;
dynamicOffset = (uint32_t)bufferSize; dynamicOffset = (uint32_t)bufferSize;
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, dynamicOffset );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, dynamicOffset );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass(); commandBuffer.endRenderPass();
@ -214,9 +190,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -46,9 +46,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT( VkInstance
return pfnVkCreateDebugUtilsMessengerEXT( instance, pCreateInfo, pAllocator, pMessenger ); return pfnVkCreateDebugUtilsMessengerEXT( instance, pCreateInfo, pAllocator, pMessenger );
} }
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance, VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator )
VkDebugUtilsMessengerEXT messenger,
VkAllocationCallbacks const * pAllocator )
{ {
return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator ); return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator );
} }
@ -86,10 +84,8 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc( VkDebugUtilsMessageSeverityFlag
for ( uint32_t i = 0; i < pCallbackData->objectCount; i++ ) for ( uint32_t i = 0; i < pCallbackData->objectCount; i++ )
{ {
message += std::string( "\t" ) + "Object " + std::to_string( i ) + "\n"; message += std::string( "\t" ) + "Object " + std::to_string( i ) + "\n";
message += std::string( "\t\t" ) + "objectType = " + message += std::string( "\t\t" ) + "objectType = " + vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) + "\n";
vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) + "\n"; message += std::string( "\t\t" ) + "objectHandle = " + std::to_string( pCallbackData->pObjects[i].objectHandle ) + "\n";
message +=
std::string( "\t\t" ) + "objectHandle = " + std::to_string( pCallbackData->pObjects[i].objectHandle ) + "\n";
if ( pCallbackData->pObjects[i].pObjectName ) if ( pCallbackData->pObjects[i].pObjectName )
{ {
message += std::string( "\t\t" ) + "objectName = <" + pCallbackData->pObjects[i].pObjectName + ">\n"; message += std::string( "\t\t" ) + "objectName = <" + pCallbackData->pObjects[i].pObjectName + ">\n";
@ -147,16 +143,14 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::InstanceCreateInfo instanceCreateInfo( {}, &applicationInfo, instanceLayerNames, instanceExtensionNames ); vk::InstanceCreateInfo instanceCreateInfo( {}, &applicationInfo, instanceLayerNames, instanceExtensionNames );
vk::raii::Instance instance( context, instanceCreateInfo ); vk::raii::Instance instance( context, instanceCreateInfo );
pfnVkCreateDebugUtilsMessengerEXT = pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
if ( !pfnVkCreateDebugUtilsMessengerEXT ) if ( !pfnVkCreateDebugUtilsMessengerEXT )
{ {
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl; std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
exit( 1 ); exit( 1 );
} }
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>( pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>( instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
if ( !pfnVkDestroyDebugUtilsMessengerEXT ) if ( !pfnVkDestroyDebugUtilsMessengerEXT )
{ {
std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl; std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl;
@ -165,18 +159,15 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
vk::DebugUtilsMessageSeverityFlagBitsEXT::eError ); vk::DebugUtilsMessageSeverityFlagBitsEXT::eError );
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation ); vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfoEXT( vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc );
{}, severityFlags, messageTypeFlags, &debugMessageFunc ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, debugUtilsMessengerCreateInfoEXT );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, debugUtilsMessengerCreateInfoEXT );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() ); vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
// get the index of the first queue family that supports graphics // get the index of the first queue family that supports graphics
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( {}, graphicsQueueFamilyIndex, 1, &queuePriority ); vk::DeviceQueueCreateInfo deviceQueueCreateInfo( {}, graphicsQueueFamilyIndex, 1, &queuePriority );
@ -185,8 +176,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// Create a vk::CommandPool (not a vk::raii::CommandPool, for testing purposes!) // Create a vk::CommandPool (not a vk::raii::CommandPool, for testing purposes!)
vk::CommandPoolCreateInfo commandPoolCreateInfo( {}, graphicsQueueFamilyIndex ); vk::CommandPoolCreateInfo commandPoolCreateInfo( {}, graphicsQueueFamilyIndex );
vk::CommandPool commandPool = vk::CommandPool commandPool = ( *device ).createCommandPool( commandPoolCreateInfo, nullptr, *device.getDispatcher() );
( *device ).createCommandPool( commandPoolCreateInfo, nullptr, *device.getDispatcher() );
// The commandPool is not destroyed automatically (as it's not a UniqueCommandPool. // The commandPool is not destroyed automatically (as it's not a UniqueCommandPool.
// That is, the device is destroyed before the commmand pool and will trigger a validation error. // That is, the device is destroyed before the commmand pool and will trigger a validation error.

View File

@ -29,8 +29,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif

View File

@ -28,20 +28,16 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() ); vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex, vk::su::getDeviceExtensions() );
vk::raii::Device device =
vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool commandPool = vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsQueueFamilyIndex } );
vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsQueueFamilyIndex } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsQueueFamilyIndex, 0 ); vk::raii::Queue graphicsQueue( device, graphicsQueueFamilyIndex, 0 );
@ -78,12 +74,7 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.reset( vk::CommandBufferResetFlags() ); commandBuffer.reset( vk::CommandBufferResetFlags() );
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
commandBuffer.waitEvents( { *event }, commandBuffer.waitEvents( { *event }, vk::PipelineStageFlagBits::eHost, vk::PipelineStageFlagBits::eBottomOfPipe, nullptr, nullptr, nullptr );
vk::PipelineStageFlagBits::eHost,
vk::PipelineStageFlagBits::eBottomOfPipe,
nullptr,
nullptr,
nullptr );
commandBuffer.end(); commandBuffer.end();
device.resetFences( { *fence } ); device.resetFences( { *fence } );

View File

@ -45,8 +45,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -56,11 +55,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -70,37 +68,30 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -111,8 +102,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::DescriptorSetLayoutBinding, 2> bindings = { std::array<vk::DescriptorSetLayoutBinding, 2> bindings = {
vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ), vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ),
vk::DescriptorSetLayoutBinding( vk::DescriptorSetLayoutBinding( 1, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, *textureData.sampler )
1, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, *textureData.sampler )
}; };
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, bindings ); vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, bindings );
vk::raii::DescriptorSetLayout descriptorSetLayout( device, descriptorSetLayoutCreateInfo ); vk::raii::DescriptorSetLayout descriptorSetLayout( device, descriptorSetLayoutCreateInfo );
@ -123,20 +113,16 @@ int main( int /*argc*/, char ** /*argv*/ )
// Create a single pool to contain data for our descriptor set // Create a single pool to contain data for our descriptor set
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorType::eCombinedImageSampler, 1 ) }; vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// Populate descriptor sets // Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet = vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo( vk::DescriptorImageInfo imageInfo( *textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = { std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
vk::WriteDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ), vk::WriteDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( *descriptorSet, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo ) vk::WriteDescriptorSet( *descriptorSet, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
@ -146,46 +132,37 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
vk::raii::su::makeGraphicsPipeline( device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -199,9 +176,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -42,8 +42,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -53,11 +52,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -71,28 +69,25 @@ int main( int /*argc*/, char ** /*argv*/ )
// See if we can use a linear tiled image for a texture, if not, we will need a staging buffer for the texture data // See if we can use a linear tiled image for a texture, if not, we will need a staging buffer for the texture data
bool needsStaging = !( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eSampledImage ); bool needsStaging = !( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eSampledImage );
vk::ImageCreateInfo imageCreateInfo( vk::ImageCreateInfo imageCreateInfo( {},
{}, vk::ImageType::e2D,
vk::ImageType::e2D, format,
format, vk::Extent3D( surfaceData.extent, 1 ),
vk::Extent3D( surfaceData.extent, 1 ), 1,
1, 1,
1, vk::SampleCountFlagBits::e1,
vk::SampleCountFlagBits::e1, needsStaging ? vk::ImageTiling::eOptimal : vk::ImageTiling::eLinear,
needsStaging ? vk::ImageTiling::eOptimal : vk::ImageTiling::eLinear, vk::ImageUsageFlagBits::eSampled | ( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ),
vk::ImageUsageFlagBits::eSampled | vk::SharingMode::eExclusive,
( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ), {},
vk::SharingMode::eExclusive, needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized );
{}, vk::raii::Image image( device, imageCreateInfo );
needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized );
vk::raii::Image image( device, imageCreateInfo );
vk::MemoryRequirements memoryRequirements = image.getMemoryRequirements(); vk::MemoryRequirements memoryRequirements = image.getMemoryRequirements();
uint32_t memoryTypeIndex = vk::su::findMemoryType( uint32_t memoryTypeIndex = vk::su::findMemoryType(
physicalDevice.getMemoryProperties(), physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits, memoryRequirements.memoryTypeBits,
needsStaging ? vk::MemoryPropertyFlags() needsStaging ? vk::MemoryPropertyFlags() : ( vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ) );
: ( vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ) );
// allocate memory // allocate memory
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ); vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
@ -106,15 +101,13 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( needsStaging ) if ( needsStaging )
{ {
// Need a staging buffer to map and copy texture into // Need a staging buffer to map and copy texture into
vk::BufferCreateInfo bufferCreateInfo( vk::BufferCreateInfo bufferCreateInfo( {}, surfaceData.extent.width * surfaceData.extent.height * 4, vk::BufferUsageFlagBits::eTransferSrc );
{}, surfaceData.extent.width * surfaceData.extent.height * 4, vk::BufferUsageFlagBits::eTransferSrc );
textureBuffer = vk::raii::Buffer( device, bufferCreateInfo ); textureBuffer = vk::raii::Buffer( device, bufferCreateInfo );
memoryRequirements = textureBuffer.getMemoryRequirements(); memoryRequirements = textureBuffer.getMemoryRequirements();
memoryTypeIndex = memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits,
memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
// allocate memory // allocate memory
memoryAllocateInfo = vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ); memoryAllocateInfo = vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
@ -125,8 +118,7 @@ int main( int /*argc*/, char ** /*argv*/ )
} }
else else
{ {
vk::SubresourceLayout subresourceLayout = vk::SubresourceLayout subresourceLayout = image.getSubresourceLayout( vk::ImageSubresource( vk::ImageAspectFlagBits::eColor ) );
image.getSubresourceLayout( vk::ImageSubresource( vk::ImageAspectFlagBits::eColor ) );
} }
void * data = needsStaging ? textureBufferMemory.mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() ) void * data = needsStaging ? textureBufferMemory.mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() )
@ -153,8 +145,7 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( needsStaging ) if ( needsStaging )
{ {
// Since we're going to blit to the texture image, set its layout to eTransferDstOptimal // Since we're going to blit to the texture image, set its layout to eTransferDstOptimal
vk::raii::su::setImageLayout( vk::raii::su::setImageLayout( commandBuffer, *image, format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
commandBuffer, *image, format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
vk::BufferImageCopy copyRegion( 0, vk::BufferImageCopy copyRegion( 0,
surfaceData.extent.width, surfaceData.extent.width,
surfaceData.extent.height, surfaceData.extent.height,
@ -163,14 +154,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Extent3D( surfaceData.extent, 1 ) ); vk::Extent3D( surfaceData.extent, 1 ) );
commandBuffer.copyBufferToImage( *textureBuffer, *image, vk::ImageLayout::eTransferDstOptimal, copyRegion ); commandBuffer.copyBufferToImage( *textureBuffer, *image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
// Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY // Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY
vk::raii::su::setImageLayout( vk::raii::su::setImageLayout( commandBuffer, *image, format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
commandBuffer, *image, format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
} }
else else
{ {
// If we can use the linear tiled image as a texture, just do it // If we can use the linear tiled image as a texture, just do it
vk::raii::su::setImageLayout( vk::raii::su::setImageLayout( commandBuffer, *image, format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal );
commandBuffer, *image, format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal );
} }
commandBuffer.end(); commandBuffer.end();
@ -193,9 +182,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::BorderColor::eFloatOpaqueWhite ); vk::BorderColor::eFloatOpaqueWhite );
vk::raii::Sampler sampler( device, samplerCreateInfo ); vk::raii::Sampler sampler( device, samplerCreateInfo );
vk::ImageViewCreateInfo imageViewCreateInfo( vk::ImageViewCreateInfo imageViewCreateInfo( {}, *image, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
{}, *image, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } ); vk::raii::ImageView imageView( device, imageViewCreateInfo );
vk::raii::ImageView imageView( device, imageViewCreateInfo );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
} }

View File

@ -71,8 +71,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -89,11 +88,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -103,8 +101,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -125,48 +122,33 @@ int main( int /*argc*/, char ** /*argv*/ )
1, 1,
vk::SampleCountFlagBits::e1, vk::SampleCountFlagBits::e1,
vk::ImageTiling::eOptimal, vk::ImageTiling::eOptimal,
vk::ImageUsageFlagBits::eInputAttachment | vk::ImageUsageFlagBits::eInputAttachment | vk::ImageUsageFlagBits::eTransferDst );
vk::ImageUsageFlagBits::eTransferDst );
vk::raii::Image inputImage( device, imageCreateInfo ); vk::raii::Image inputImage( device, imageCreateInfo );
vk::MemoryRequirements memoryRequirements = inputImage.getMemoryRequirements(); vk::MemoryRequirements memoryRequirements = inputImage.getMemoryRequirements();
uint32_t memoryTypeIndex = uint32_t memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, {} );
vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, {} );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ); vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
vk::raii::DeviceMemory inputMemory( device, memoryAllocateInfo ); vk::raii::DeviceMemory inputMemory( device, memoryAllocateInfo );
inputImage.bindMemory( *inputMemory, 0 ); inputImage.bindMemory( *inputMemory, 0 );
// Set the image layout to TRANSFER_DST_OPTIMAL to be ready for clear // Set the image layout to TRANSFER_DST_OPTIMAL to be ready for clear
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
vk::raii::su::setImageLayout( commandBuffer, vk::raii::su::setImageLayout( commandBuffer, *inputImage, swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
*inputImage,
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eTransferDstOptimal );
commandBuffer.clearColorImage( commandBuffer.clearColorImage( *inputImage,
*inputImage, vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eTransferDstOptimal, { std::array<float, 4>( { { 1.0f, 1.0f, 0.0f, 0.0f } } ) },
{ std::array<float, 4>( { { 1.0f, 1.0f, 0.0f, 0.0f } } ) }, { { vk::ImageAspectFlagBits::eColor, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS } } );
{ { vk::ImageAspectFlagBits::eColor, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS } } );
// Set the image layout to SHADER_READONLY_OPTIMAL for use by the shaders // Set the image layout to SHADER_READONLY_OPTIMAL for use by the shaders
vk::raii::su::setImageLayout( commandBuffer, vk::raii::su::setImageLayout(
*inputImage, commandBuffer, *inputImage, swapChainData.colorFormat, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
swapChainData.colorFormat,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eShaderReadOnlyOptimal );
vk::ImageViewCreateInfo imageViewCreateInfo( {}, vk::ImageViewCreateInfo imageViewCreateInfo(
*inputImage, {}, *inputImage, vk::ImageViewType::e2D, swapChainData.colorFormat, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::ImageViewType::e2D,
swapChainData.colorFormat,
{},
{ vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::raii::ImageView inputAttachmentView( device, imageViewCreateInfo ); vk::raii::ImageView inputAttachmentView( device, imageViewCreateInfo );
vk::DescriptorSetLayoutBinding layoutBinding( vk::DescriptorSetLayoutBinding layoutBinding( 0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment );
0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment );
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, layoutBinding ); vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, layoutBinding );
vk::raii::DescriptorSetLayout descriptorSetLayout( device, descriptorSetLayoutCreateInfo ); vk::raii::DescriptorSetLayout descriptorSetLayout( device, descriptorSetLayoutCreateInfo );
@ -205,67 +187,44 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::RenderPass renderPass( device, renderPassCreateInfo ); vk::raii::RenderPass renderPass( device, renderPassCreateInfo );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &inputAttachmentView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &inputAttachmentView, surfaceData.extent );
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eInputAttachment, 1 ); vk::DescriptorPoolSize poolSize( vk::DescriptorType::eInputAttachment, 1 );
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize );
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ); vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet = vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
vk::DescriptorImageInfo inputImageInfo( nullptr, *inputAttachmentView, vk::ImageLayout::eShaderReadOnlyOptimal ); vk::DescriptorImageInfo inputImageInfo( nullptr, *inputAttachmentView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::WriteDescriptorSet writeDescriptorSet( vk::WriteDescriptorSet writeDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eInputAttachment, inputImageInfo );
*descriptorSet, 0, 0, vk::DescriptorType::eInputAttachment, inputImageInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr ); device.updateDescriptorSets( writeDescriptorSet, nullptr );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device, vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline(
pipelineCache, device, pipelineCache, vertexShaderModule, nullptr, fragmentShaderModule, nullptr, 0, {}, vk::FrontFace::eClockwise, false, pipelineLayout, renderPass );
vertexShaderModule,
nullptr,
fragmentShaderModule,
nullptr,
0,
{},
vk::FrontFace::eClockwise,
false,
pipelineLayout,
renderPass );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
vk::ClearValue clearValue; vk::ClearValue clearValue;
clearValue.color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValue.color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValue );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValue );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 3, 1, 0, 0 ); commandBuffer.draw( 3, 1, 0, 0 );
@ -281,9 +240,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -35,8 +35,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::sort( extensionProperties.begin(), std::sort( extensionProperties.begin(),
extensionProperties.end(), extensionProperties.end(),
[]( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) []( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) { return strcmp( a.extensionName, b.extensionName ) < 0; } );
{ return strcmp( a.extensionName, b.extensionName ) < 0; } );
std::cout << "Instance Extensions:" << std::endl; std::cout << "Instance Extensions:" << std::endl;
for ( auto const & ep : extensionProperties ) for ( auto const & ep : extensionProperties )

View File

@ -23,8 +23,7 @@
struct PropertyData struct PropertyData
{ {
PropertyData( vk::LayerProperties const & layerProperties_, PropertyData( vk::LayerProperties const & layerProperties_, std::vector<vk::ExtensionProperties> const & extensionProperties_ )
std::vector<vk::ExtensionProperties> const & extensionProperties_ )
: layerProperties( layerProperties_ ), extensionProperties( extensionProperties_ ) : layerProperties( layerProperties_ ), extensionProperties( extensionProperties_ )
{} {}

View File

@ -40,8 +40,8 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
std::cout << lp.layerName << ":" << std::endl; std::cout << lp.layerName << ":" << std::endl;
std::cout << "\tVersion: " << lp.implementationVersion << std::endl; std::cout << "\tVersion: " << lp.implementationVersion << std::endl;
std::cout << "\tAPI Version: (" << ( lp.specVersion >> 22 ) << "." << ( ( lp.specVersion >> 12 ) & 0x03FF ) << "." std::cout << "\tAPI Version: (" << ( lp.specVersion >> 22 ) << "." << ( ( lp.specVersion >> 12 ) & 0x03FF ) << "." << ( lp.specVersion & 0xFFF ) << ")"
<< ( lp.specVersion & 0xFFF ) << ")" << std::endl; << std::endl;
std::cout << "\tDescription: " << lp.description << std::endl; std::cout << "\tDescription: " << lp.description << std::endl;
std::cout << std::endl; std::cout << std::endl;
} }

View File

@ -22,8 +22,8 @@
std::string decodeAPIVersion( uint32_t apiVersion ) std::string decodeAPIVersion( uint32_t apiVersion )
{ {
return std::to_string( VK_VERSION_MAJOR( apiVersion ) ) + "." + std::to_string( VK_VERSION_MINOR( apiVersion ) ) + return std::to_string( VK_VERSION_MAJOR( apiVersion ) ) + "." + std::to_string( VK_VERSION_MINOR( apiVersion ) ) + "." +
"." + std::to_string( VK_VERSION_PATCH( apiVersion ) ); std::to_string( VK_VERSION_PATCH( apiVersion ) );
} }
int main( int /*argc*/, char ** /*argv*/ ) int main( int /*argc*/, char ** /*argv*/ )

View File

@ -95,8 +95,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -113,11 +112,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -127,8 +125,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -140,41 +137,33 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) ); textureData.setImage( commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
// Create first layout to contain uniform buffer data // Create first layout to contain uniform buffer data
vk::DescriptorSetLayoutBinding uniformBinding( vk::DescriptorSetLayoutBinding uniformBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, uniformBinding ); vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, uniformBinding );
vk::raii::DescriptorSetLayout uniformLayout( device, descriptorSetLayoutCreateInfo ); vk::raii::DescriptorSetLayout uniformLayout( device, descriptorSetLayoutCreateInfo );
// Create second layout containing combined sampler/image data // Create second layout containing combined sampler/image data
vk::DescriptorSetLayoutBinding sampler2DBinding( vk::DescriptorSetLayoutBinding sampler2DBinding( 0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex );
0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex );
descriptorSetLayoutCreateInfo.pBindings = &sampler2DBinding; descriptorSetLayoutCreateInfo.pBindings = &sampler2DBinding;
vk::raii::DescriptorSetLayout samplerLayout( device, descriptorSetLayoutCreateInfo ); vk::raii::DescriptorSetLayout samplerLayout( device, descriptorSetLayoutCreateInfo );
@ -185,72 +174,59 @@ int main( int /*argc*/, char ** /*argv*/ )
// Create a single pool to contain data for our two descriptor sets // Create a single pool to contain data for our two descriptor sets
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorType::eCombinedImageSampler, 1 ) }; vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, poolSizes );
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, poolSizes );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// Populate descriptor sets // Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, descriptorSetLayouts ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, descriptorSetLayouts );
vk::raii::DescriptorSets descriptorSets( device, descriptorSetAllocateInfo ); vk::raii::DescriptorSets descriptorSets( device, descriptorSetAllocateInfo );
// Populate with info about our uniform buffer // Populate with info about our uniform buffer
vk::DescriptorBufferInfo uniformBufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo uniformBufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo textureImageInfo( vk::DescriptorImageInfo textureImageInfo( *textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = { std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
{ vk::WriteDescriptorSet( *descriptorSets[0], 0, 0, vk::DescriptorType::eUniformBuffer, {}, uniformBufferInfo ), { vk::WriteDescriptorSet( *descriptorSets[0], 0, 0, vk::DescriptorType::eUniformBuffer, {}, uniformBufferInfo ),
vk::WriteDescriptorSet( vk::WriteDescriptorSet( *descriptorSets[1], 0, 0, vk::DescriptorType::eCombinedImageSampler, textureImageInfo ) }
*descriptorSets[1], 0, 0, vk::DescriptorType::eCombinedImageSampler, textureImageInfo ) }
}; };
device.updateDescriptorSets( writeDescriptorSets, nullptr ); device.updateDescriptorSets( writeDescriptorSets, nullptr );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
vk::raii::su::makeGraphicsPipeline( device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSets[0], *descriptorSets[1] }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSets[0], *descriptorSets[1] }, nullptr );
vk::Buffer buffer = *vertexBufferData.buffer; vk::Buffer buffer = *vertexBufferData.buffer;
commandBuffer.bindVertexBuffers( 0, buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, buffer, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -271,9 +247,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -33,8 +33,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -51,11 +50,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -65,64 +63,53 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::raii::su::makeDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::raii::DescriptorPool descriptorPool = vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } ); vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets( vk::raii::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, {} );
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, {} );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
vk::raii::su::makeGraphicsPipeline( device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( coloredCubeData[0] ),
sizeof( coloredCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -131,21 +118,18 @@ int main( int /*argc*/, char ** /*argv*/ )
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
/* Allocate a uniform buffer that will take query results. */ /* Allocate a uniform buffer that will take query results. */
vk::BufferCreateInfo bufferCreateInfo( vk::BufferCreateInfo bufferCreateInfo( {}, 4 * sizeof( uint64_t ), vk::BufferUsageFlagBits::eUniformBuffer | vk::BufferUsageFlagBits::eTransferDst );
{}, 4 * sizeof( uint64_t ), vk::BufferUsageFlagBits::eUniformBuffer | vk::BufferUsageFlagBits::eTransferDst ); vk::raii::Buffer queryResultBuffer( device, bufferCreateInfo );
vk::raii::Buffer queryResultBuffer( device, bufferCreateInfo );
vk::MemoryRequirements memoryRequirements = queryResultBuffer.getMemoryRequirements(); vk::MemoryRequirements memoryRequirements = queryResultBuffer.getMemoryRequirements();
uint32_t memoryTypeIndex = uint32_t memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits,
memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ); vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
vk::raii::DeviceMemory queryResultMemory( device, memoryAllocateInfo ); vk::raii::DeviceMemory queryResultMemory( device, memoryAllocateInfo );
@ -161,21 +145,15 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer.beginRenderPass( commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo( vk::RenderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, {} ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, {} );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.beginQuery( *queryPool, 0, vk::QueryControlFlags() ); commandBuffer.beginQuery( *queryPool, 0, vk::QueryControlFlags() );
@ -186,13 +164,8 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.endRenderPass(); commandBuffer.endRenderPass();
commandBuffer.endQuery( *queryPool, 1 ); commandBuffer.endQuery( *queryPool, 1 );
commandBuffer.copyQueryPoolResults( *queryPool, commandBuffer.copyQueryPoolResults(
0, *queryPool, 0, 2, *queryResultBuffer, 0, sizeof( uint64_t ), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
2,
*queryResultBuffer,
0,
sizeof( uint64_t ),
vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
commandBuffer.end(); commandBuffer.end();
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() ); vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
@ -204,14 +177,12 @@ int main( int /*argc*/, char ** /*argv*/ )
graphicsQueue.waitIdle(); graphicsQueue.waitIdle();
std::vector<uint64_t> poolResults; std::vector<uint64_t> poolResults;
std::tie( result, poolResults ) = queryPool.getResults<uint64_t>( std::tie( result, poolResults ) =
0, 2, 2 * sizeof( uint64_t ), sizeof( uint64_t ), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait ); queryPool.getResults<uint64_t>( 0, 2, 2 * sizeof( uint64_t ), sizeof( uint64_t ), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eNotReady: case vk::Result::eNotReady: std::cout << "vk::Device::getQueryPoolResults returned vk::Result::eNotReady !\n"; break;
std::cout << "vk::Device::getQueryPoolResults returned vk::Result::eNotReady !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
@ -220,8 +191,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "samples_passed[1] = " << poolResults[1] << "\n"; std::cout << "samples_passed[1] = " << poolResults[1] << "\n";
/* Read back query result from buffer */ /* Read back query result from buffer */
uint64_t * samplesPassedPtr = uint64_t * samplesPassedPtr = static_cast<uint64_t *>( queryResultMemory.mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() ) );
static_cast<uint64_t *>( queryResultMemory.mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() ) );
std::cout << "vkCmdCopyQueryPoolResults data\n"; std::cout << "vkCmdCopyQueryPoolResults data\n";
std::cout << "samples_passed[0] = " << samplesPassedPtr[0] << "\n"; std::cout << "samples_passed[0] = " << samplesPassedPtr[0] << "\n";
@ -237,9 +207,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -40,15 +40,13 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ ) for ( size_t i = 0; i < physicalDevices.size(); i++ )
{ {
std::vector<vk::ExtensionProperties> extensionProperties = std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << " : " << extensionProperties.size() << " extensions:\n"; std::cout << "PhysicalDevice " << i << " : " << extensionProperties.size() << " extensions:\n";
// sort the extensions alphabetically // sort the extensions alphabetically
std::sort( extensionProperties.begin(), std::sort( extensionProperties.begin(),
extensionProperties.end(), extensionProperties.end(),
[]( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) []( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) { return strcmp( a.extensionName, b.extensionName ) < 0; } );
{ return strcmp( a.extensionName, b.extensionName ) < 0; } );
for ( auto const & ep : extensionProperties ) for ( auto const & ep : extensionProperties )
{ {
std::cout << "\t" << ep.extensionName << ":" << std::endl; std::cout << "\t" << ep.extensionName << ":" << std::endl;

View File

@ -37,8 +37,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -52,8 +51,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ ) for ( size_t i = 0; i < physicalDevices.size(); i++ )
{ {
// some features are only valid, if a corresponding extension is available! // some features are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties = std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << " :\n"; std::cout << "PhysicalDevice " << i << " :\n";
auto features2 = physicalDevices[i] auto features2 = physicalDevices[i]
@ -140,23 +138,15 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "\t\tshaderInt64 : " << !!features.shaderInt64 << "\n"; std::cout << "\t\tshaderInt64 : " << !!features.shaderInt64 << "\n";
std::cout << "\t\tshaderResourceMinLod : " << !!features.shaderResourceMinLod << "\n"; std::cout << "\t\tshaderResourceMinLod : " << !!features.shaderResourceMinLod << "\n";
std::cout << "\t\tshaderResourceResidency : " << !!features.shaderResourceResidency << "\n"; std::cout << "\t\tshaderResourceResidency : " << !!features.shaderResourceResidency << "\n";
std::cout << "\t\tshaderSampledImageArrayDynamicIndexing : " << !!features.shaderSampledImageArrayDynamicIndexing std::cout << "\t\tshaderSampledImageArrayDynamicIndexing : " << !!features.shaderSampledImageArrayDynamicIndexing << "\n";
<< "\n"; std::cout << "\t\tshaderStorageBufferArrayDynamicIndexing : " << !!features.shaderStorageBufferArrayDynamicIndexing << "\n";
std::cout << "\t\tshaderStorageBufferArrayDynamicIndexing : " std::cout << "\t\tshaderStorageImageArrayDynamicIndexing : " << !!features.shaderStorageImageArrayDynamicIndexing << "\n";
<< !!features.shaderStorageBufferArrayDynamicIndexing << "\n"; std::cout << "\t\tshaderStorageImageExtendedFormats : " << !!features.shaderStorageImageExtendedFormats << "\n";
std::cout << "\t\tshaderStorageImageArrayDynamicIndexing : " << !!features.shaderStorageImageArrayDynamicIndexing
<< "\n";
std::cout << "\t\tshaderStorageImageExtendedFormats : " << !!features.shaderStorageImageExtendedFormats
<< "\n";
std::cout << "\t\tshaderStorageImageMultisample : " << !!features.shaderStorageImageMultisample << "\n"; std::cout << "\t\tshaderStorageImageMultisample : " << !!features.shaderStorageImageMultisample << "\n";
std::cout << "\t\tshaderStorageImageReadWithoutFormat : " << !!features.shaderStorageImageReadWithoutFormat std::cout << "\t\tshaderStorageImageReadWithoutFormat : " << !!features.shaderStorageImageReadWithoutFormat << "\n";
<< "\n"; std::cout << "\t\tshaderStorageImageWriteWithoutFormat : " << !!features.shaderStorageImageWriteWithoutFormat << "\n";
std::cout << "\t\tshaderStorageImageWriteWithoutFormat : " << !!features.shaderStorageImageWriteWithoutFormat std::cout << "\t\tshaderTessellationAndGeometryPointSize : " << !!features.shaderTessellationAndGeometryPointSize << "\n";
<< "\n"; std::cout << "\t\tshaderUniformBufferArrayDynamicIndexing : " << !!features.shaderUniformBufferArrayDynamicIndexing << "\n";
std::cout << "\t\tshaderTessellationAndGeometryPointSize : " << !!features.shaderTessellationAndGeometryPointSize
<< "\n";
std::cout << "\t\tshaderUniformBufferArrayDynamicIndexing : "
<< !!features.shaderUniformBufferArrayDynamicIndexing << "\n";
std::cout << "\t\tsparseBinding : " << !!features.sparseBinding << "\n"; std::cout << "\t\tsparseBinding : " << !!features.sparseBinding << "\n";
std::cout << "\t\tsparseResidency16Samples : " << !!features.sparseResidency16Samples << "\n"; std::cout << "\t\tsparseResidency16Samples : " << !!features.sparseResidency16Samples << "\n";
std::cout << "\t\tsparseResidency2Samples : " << !!features.sparseResidency2Samples << "\n"; std::cout << "\t\tsparseResidency2Samples : " << !!features.sparseResidency2Samples << "\n";
@ -171,42 +161,31 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "\t\ttextureCompressionBC : " << !!features.textureCompressionBC << "\n"; std::cout << "\t\ttextureCompressionBC : " << !!features.textureCompressionBC << "\n";
std::cout << "\t\ttextureCompressionETC2 : " << !!features.textureCompressionETC2 << "\n"; std::cout << "\t\ttextureCompressionETC2 : " << !!features.textureCompressionETC2 << "\n";
std::cout << "\t\tvariableMultisampleRate : " << !!features.variableMultisampleRate << "\n"; std::cout << "\t\tvariableMultisampleRate : " << !!features.variableMultisampleRate << "\n";
std::cout << "\t\tvertexPipelineStoresAndAtomics : " << !!features.vertexPipelineStoresAndAtomics std::cout << "\t\tvertexPipelineStoresAndAtomics : " << !!features.vertexPipelineStoresAndAtomics << "\n";
<< "\n";
std::cout << "\t\twideLines : " << !!features.wideLines << "\n"; std::cout << "\t\twideLines : " << !!features.wideLines << "\n";
std::cout << "\n"; std::cout << "\n";
vk::PhysicalDevice16BitStorageFeatures const & sixteenBitStorageFeatures = vk::PhysicalDevice16BitStorageFeatures const & sixteenBitStorageFeatures = features2.get<vk::PhysicalDevice16BitStorageFeatures>();
features2.get<vk::PhysicalDevice16BitStorageFeatures>();
std::cout << "\t16BitStorageFeatures:\n"; std::cout << "\t16BitStorageFeatures:\n";
std::cout << "\t\tstorageBuffer16BitAccess : " << !!sixteenBitStorageFeatures.storageBuffer16BitAccess std::cout << "\t\tstorageBuffer16BitAccess : " << !!sixteenBitStorageFeatures.storageBuffer16BitAccess << "\n";
<< "\n"; std::cout << "\t\tstorageInputOutput16 : " << !!sixteenBitStorageFeatures.storageInputOutput16 << "\n";
std::cout << "\t\tstorageInputOutput16 : " << !!sixteenBitStorageFeatures.storageInputOutput16 std::cout << "\t\tstoragePushConstant16 : " << !!sixteenBitStorageFeatures.storagePushConstant16 << "\n";
<< "\n"; std::cout << "\t\tuniformAndStorageBuffer16BitAccess : " << !!sixteenBitStorageFeatures.uniformAndStorageBuffer16BitAccess << "\n";
std::cout << "\t\tstoragePushConstant16 : " << !!sixteenBitStorageFeatures.storagePushConstant16
<< "\n";
std::cout << "\t\tuniformAndStorageBuffer16BitAccess : "
<< !!sixteenBitStorageFeatures.uniformAndStorageBuffer16BitAccess << "\n";
std::cout << "\n"; std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_KHR_8bit_storage" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_8bit_storage" ) )
{ {
vk::PhysicalDevice8BitStorageFeaturesKHR const & eightBitStorageFeatures = vk::PhysicalDevice8BitStorageFeaturesKHR const & eightBitStorageFeatures = features2.get<vk::PhysicalDevice8BitStorageFeaturesKHR>();
features2.get<vk::PhysicalDevice8BitStorageFeaturesKHR>();
std::cout << "\t8BitStorageFeatures:\n"; std::cout << "\t8BitStorageFeatures:\n";
std::cout << "\t\tstorageBuffer8BitAccess : " << !!eightBitStorageFeatures.storageBuffer8BitAccess std::cout << "\t\tstorageBuffer8BitAccess : " << !!eightBitStorageFeatures.storageBuffer8BitAccess << "\n";
<< "\n"; std::cout << "\t\tstoragePushConstant8 : " << !!eightBitStorageFeatures.storagePushConstant8 << "\n";
std::cout << "\t\tstoragePushConstant8 : " << !!eightBitStorageFeatures.storagePushConstant8 std::cout << "\t\tuniformAndStorageBuffer8BitAccess : " << !!eightBitStorageFeatures.uniformAndStorageBuffer8BitAccess << "\n";
<< "\n";
std::cout << "\t\tuniformAndStorageBuffer8BitAccess : "
<< !!eightBitStorageFeatures.uniformAndStorageBuffer8BitAccess << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_astc_decode_mode" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_astc_decode_mode" ) )
{ {
vk::PhysicalDeviceASTCDecodeFeaturesEXT const & astcDecodeFeatures = vk::PhysicalDeviceASTCDecodeFeaturesEXT const & astcDecodeFeatures = features2.get<vk::PhysicalDeviceASTCDecodeFeaturesEXT>();
features2.get<vk::PhysicalDeviceASTCDecodeFeaturesEXT>();
std::cout << "\tASTCDecodeFeature:\n"; std::cout << "\tASTCDecodeFeature:\n";
std::cout << "\t\tdecodeModeSharedExponent : " << !!astcDecodeFeatures.decodeModeSharedExponent << "\n"; std::cout << "\t\tdecodeModeSharedExponent : " << !!astcDecodeFeatures.decodeModeSharedExponent << "\n";
std::cout << "\n"; std::cout << "\n";
@ -217,8 +196,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT const & blendOperationAdvancedFeatures = vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT const & blendOperationAdvancedFeatures =
features2.get<vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT>(); features2.get<vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT>();
std::cout << "\tBlendOperationAdvancedFeatures:\n"; std::cout << "\tBlendOperationAdvancedFeatures:\n";
std::cout << "\t\tadvancedBlendCoherentOperations : " std::cout << "\t\tadvancedBlendCoherentOperations : " << !!blendOperationAdvancedFeatures.advancedBlendCoherentOperations << "\n";
<< !!blendOperationAdvancedFeatures.advancedBlendCoherentOperations << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -227,19 +205,15 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT const & bufferDeviceAddressFeatures = vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT const & bufferDeviceAddressFeatures =
features2.get<vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT>(); features2.get<vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT>();
std::cout << "\tBufferDeviceAddressFeatures:\n"; std::cout << "\tBufferDeviceAddressFeatures:\n";
std::cout << "\t\tbufferDeviceAddress : " << !!bufferDeviceAddressFeatures.bufferDeviceAddress std::cout << "\t\tbufferDeviceAddress : " << !!bufferDeviceAddressFeatures.bufferDeviceAddress << "\n";
<< "\n"; std::cout << "\t\tbufferDeviceAddressCaptureReplay : " << !!bufferDeviceAddressFeatures.bufferDeviceAddressCaptureReplay << "\n";
std::cout << "\t\tbufferDeviceAddressCaptureReplay : " std::cout << "\t\tbufferDeviceAddressMultiDevice : " << !!bufferDeviceAddressFeatures.bufferDeviceAddressMultiDevice << "\n";
<< !!bufferDeviceAddressFeatures.bufferDeviceAddressCaptureReplay << "\n";
std::cout << "\t\tbufferDeviceAddressMultiDevice : "
<< !!bufferDeviceAddressFeatures.bufferDeviceAddressMultiDevice << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_AMD_device_coherent_memory" ) ) if ( vk::su::contains( extensionProperties, "VK_AMD_device_coherent_memory" ) )
{ {
vk::PhysicalDeviceCoherentMemoryFeaturesAMD const & coherentMemoryFeatures = vk::PhysicalDeviceCoherentMemoryFeaturesAMD const & coherentMemoryFeatures = features2.get<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>();
features2.get<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>();
std::cout << "\tCoherentMemoryFeatures:\n"; std::cout << "\tCoherentMemoryFeatures:\n";
std::cout << "\t\tdeviceCoherentMemory : " << !!coherentMemoryFeatures.deviceCoherentMemory << "\n"; std::cout << "\t\tdeviceCoherentMemory : " << !!coherentMemoryFeatures.deviceCoherentMemory << "\n";
std::cout << "\n"; std::cout << "\n";
@ -250,10 +224,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV const & computeShaderDerivativesFeatures = vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV const & computeShaderDerivativesFeatures =
features2.get<vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV>(); features2.get<vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV>();
std::cout << "\tComputeShaderDerivativeFeatures:\n"; std::cout << "\tComputeShaderDerivativeFeatures:\n";
std::cout << "\t\tcomputeDerivativeGroupLinear : " std::cout << "\t\tcomputeDerivativeGroupLinear : " << !!computeShaderDerivativesFeatures.computeDerivativeGroupLinear << "\n";
<< !!computeShaderDerivativesFeatures.computeDerivativeGroupLinear << "\n"; std::cout << "\t\tcomputeDerivativeGroupQuads : " << !!computeShaderDerivativesFeatures.computeDerivativeGroupQuads << "\n";
std::cout << "\t\tcomputeDerivativeGroupQuads : "
<< !!computeShaderDerivativesFeatures.computeDerivativeGroupQuads << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -262,29 +234,23 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceConditionalRenderingFeaturesEXT const & conditionalRenderingFeatures = vk::PhysicalDeviceConditionalRenderingFeaturesEXT const & conditionalRenderingFeatures =
features2.get<vk::PhysicalDeviceConditionalRenderingFeaturesEXT>(); features2.get<vk::PhysicalDeviceConditionalRenderingFeaturesEXT>();
std::cout << "\tConditionalRenderingFeatures:\n"; std::cout << "\tConditionalRenderingFeatures:\n";
std::cout << "\t\tconditionalRendering : " << !!conditionalRenderingFeatures.conditionalRendering std::cout << "\t\tconditionalRendering : " << !!conditionalRenderingFeatures.conditionalRendering << "\n";
<< "\n"; std::cout << "\t\tinheritedConditionalRendering : " << !!conditionalRenderingFeatures.inheritedConditionalRendering << "\n";
std::cout << "\t\tinheritedConditionalRendering : "
<< !!conditionalRenderingFeatures.inheritedConditionalRendering << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_NV_cooperative_matrix" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_cooperative_matrix" ) )
{ {
vk::PhysicalDeviceCooperativeMatrixFeaturesNV const & cooperativeMatrixFeatures = vk::PhysicalDeviceCooperativeMatrixFeaturesNV const & cooperativeMatrixFeatures = features2.get<vk::PhysicalDeviceCooperativeMatrixFeaturesNV>();
features2.get<vk::PhysicalDeviceCooperativeMatrixFeaturesNV>();
std::cout << "\tCooperativeMatrixFeatures:\n"; std::cout << "\tCooperativeMatrixFeatures:\n";
std::cout << "\t\tcooperativeMatrix : " << !!cooperativeMatrixFeatures.cooperativeMatrix std::cout << "\t\tcooperativeMatrix : " << !!cooperativeMatrixFeatures.cooperativeMatrix << "\n";
<< "\n"; std::cout << "\t\tcooperativeMatrixRobustBufferAccess : " << !!cooperativeMatrixFeatures.cooperativeMatrixRobustBufferAccess << "\n";
std::cout << "\t\tcooperativeMatrixRobustBufferAccess : "
<< !!cooperativeMatrixFeatures.cooperativeMatrixRobustBufferAccess << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_NV_corner_sampled_image" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_corner_sampled_image" ) )
{ {
vk::PhysicalDeviceCornerSampledImageFeaturesNV const & cornerSampledImageFeatures = vk::PhysicalDeviceCornerSampledImageFeaturesNV const & cornerSampledImageFeatures = features2.get<vk::PhysicalDeviceCornerSampledImageFeaturesNV>();
features2.get<vk::PhysicalDeviceCornerSampledImageFeaturesNV>();
std::cout << "\tCornerSampledImageFeatures:\n"; std::cout << "\tCornerSampledImageFeatures:\n";
std::cout << "\t\tcornerSampledImage : " << !!cornerSampledImageFeatures.cornerSampledImage << "\n"; std::cout << "\t\tcornerSampledImage : " << !!cornerSampledImageFeatures.cornerSampledImage << "\n";
std::cout << "\n"; std::cout << "\n";
@ -304,15 +270,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV const & dedicatedAllocationImageAliasingFeatures = vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV const & dedicatedAllocationImageAliasingFeatures =
features2.get<vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(); features2.get<vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>();
std::cout << "\tDedicatedAllocationAliasingFeatures:\n"; std::cout << "\tDedicatedAllocationAliasingFeatures:\n";
std::cout << "\t\tdedicatedAllocationImageAliasing : " std::cout << "\t\tdedicatedAllocationImageAliasing : " << !!dedicatedAllocationImageAliasingFeatures.dedicatedAllocationImageAliasing << "\n";
<< !!dedicatedAllocationImageAliasingFeatures.dedicatedAllocationImageAliasing << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_depth_clip_enable" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_depth_clip_enable" ) )
{ {
vk::PhysicalDeviceDepthClipEnableFeaturesEXT const & depthClipEnabledFeatures = vk::PhysicalDeviceDepthClipEnableFeaturesEXT const & depthClipEnabledFeatures = features2.get<vk::PhysicalDeviceDepthClipEnableFeaturesEXT>();
features2.get<vk::PhysicalDeviceDepthClipEnableFeaturesEXT>();
std::cout << "\tDepthClipEnabledFeatures:\n"; std::cout << "\tDepthClipEnabledFeatures:\n";
std::cout << "\t\tdepthClipEnable : " << !!depthClipEnabledFeatures.depthClipEnable << "\n"; std::cout << "\t\tdepthClipEnable : " << !!depthClipEnabledFeatures.depthClipEnable << "\n";
std::cout << "\n"; std::cout << "\n";
@ -320,47 +284,44 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_descriptor_indexing" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_descriptor_indexing" ) )
{ {
vk::PhysicalDeviceDescriptorIndexingFeaturesEXT const & descriptorIndexingFeatures = vk::PhysicalDeviceDescriptorIndexingFeaturesEXT const & descriptorIndexingFeatures = features2.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
features2.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
std::cout << "\tDescriptorIndexingFeatures:\n"; std::cout << "\tDescriptorIndexingFeatures:\n";
std::cout << "\t\tdescriptorBindingPartiallyBound : " std::cout << "\t\tdescriptorBindingPartiallyBound : " << !!descriptorIndexingFeatures.descriptorBindingPartiallyBound << "\n";
<< !!descriptorIndexingFeatures.descriptorBindingPartiallyBound << "\n"; std::cout << "\t\tdescriptorBindingSampledImageUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingSampledImageUpdateAfterBind
std::cout << "\t\tdescriptorBindingSampledImageUpdateAfterBind : " << "\n";
<< !!descriptorIndexingFeatures.descriptorBindingSampledImageUpdateAfterBind << "\n"; std::cout << "\t\tdescriptorBindingStorageBufferUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingStorageBufferUpdateAfterBind
std::cout << "\t\tdescriptorBindingStorageBufferUpdateAfterBind : " << "\n";
<< !!descriptorIndexingFeatures.descriptorBindingStorageBufferUpdateAfterBind << "\n"; std::cout << "\t\tdescriptorBindingStorageImageUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingStorageImageUpdateAfterBind
std::cout << "\t\tdescriptorBindingStorageImageUpdateAfterBind : " << "\n";
<< !!descriptorIndexingFeatures.descriptorBindingStorageImageUpdateAfterBind << "\n";
std::cout << "\t\tdescriptorBindingStorageTexelBufferUpdateAfterBind : " std::cout << "\t\tdescriptorBindingStorageTexelBufferUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingStorageTexelBufferUpdateAfterBind << "\n"; << !!descriptorIndexingFeatures.descriptorBindingStorageTexelBufferUpdateAfterBind << "\n";
std::cout << "\t\tdescriptorBindingUniformBufferUpdateAfterBind : " std::cout << "\t\tdescriptorBindingUniformBufferUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingUniformBufferUpdateAfterBind
<< !!descriptorIndexingFeatures.descriptorBindingUniformBufferUpdateAfterBind << "\n"; << "\n";
std::cout << "\t\tdescriptorBindingUniformTexelBufferUpdateAfterBind : " std::cout << "\t\tdescriptorBindingUniformTexelBufferUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingUniformTexelBufferUpdateAfterBind << "\n"; << !!descriptorIndexingFeatures.descriptorBindingUniformTexelBufferUpdateAfterBind << "\n";
std::cout << "\t\tdescriptorBindingUpdateUnusedWhilePending : " std::cout << "\t\tdescriptorBindingUpdateUnusedWhilePending : " << !!descriptorIndexingFeatures.descriptorBindingUpdateUnusedWhilePending
<< !!descriptorIndexingFeatures.descriptorBindingUpdateUnusedWhilePending << "\n"; << "\n";
std::cout << "\t\tdescriptorBindingVariableDescriptorCount : " std::cout << "\t\tdescriptorBindingVariableDescriptorCount : " << !!descriptorIndexingFeatures.descriptorBindingVariableDescriptorCount
<< !!descriptorIndexingFeatures.descriptorBindingVariableDescriptorCount << "\n"; << "\n";
std::cout << "\t\truntimeDescriptorArray : " std::cout << "\t\truntimeDescriptorArray : " << !!descriptorIndexingFeatures.runtimeDescriptorArray << "\n";
<< !!descriptorIndexingFeatures.runtimeDescriptorArray << "\n"; std::cout << "\t\tshaderInputAttachmentArrayDynamicIndexing : " << !!descriptorIndexingFeatures.shaderInputAttachmentArrayDynamicIndexing
std::cout << "\t\tshaderInputAttachmentArrayDynamicIndexing : " << "\n";
<< !!descriptorIndexingFeatures.shaderInputAttachmentArrayDynamicIndexing << "\n"; std::cout << "\t\tshaderInputAttachmentArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderInputAttachmentArrayNonUniformIndexing
std::cout << "\t\tshaderInputAttachmentArrayNonUniformIndexing : " << "\n";
<< !!descriptorIndexingFeatures.shaderInputAttachmentArrayNonUniformIndexing << "\n"; std::cout << "\t\tshaderSampledImageArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderSampledImageArrayNonUniformIndexing
std::cout << "\t\tshaderSampledImageArrayNonUniformIndexing : " << "\n";
<< !!descriptorIndexingFeatures.shaderSampledImageArrayNonUniformIndexing << "\n"; std::cout << "\t\tshaderStorageBufferArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderStorageBufferArrayNonUniformIndexing
std::cout << "\t\tshaderStorageBufferArrayNonUniformIndexing : " << "\n";
<< !!descriptorIndexingFeatures.shaderStorageBufferArrayNonUniformIndexing << "\n"; std::cout << "\t\tshaderStorageImageArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderStorageImageArrayNonUniformIndexing
std::cout << "\t\tshaderStorageImageArrayNonUniformIndexing : " << "\n";
<< !!descriptorIndexingFeatures.shaderStorageImageArrayNonUniformIndexing << "\n"; std::cout << "\t\tshaderStorageTexelBufferArrayDynamicIndexing : " << !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayDynamicIndexing
std::cout << "\t\tshaderStorageTexelBufferArrayDynamicIndexing : " << "\n";
<< !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayDynamicIndexing << "\n";
std::cout << "\t\tshaderStorageTexelBufferArrayNonUniformIndexing : " std::cout << "\t\tshaderStorageTexelBufferArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayNonUniformIndexing << "\n"; << !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayNonUniformIndexing << "\n";
std::cout << "\t\tshaderUniformBufferArrayNonUniformIndexing : " std::cout << "\t\tshaderUniformBufferArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderUniformBufferArrayNonUniformIndexing
<< !!descriptorIndexingFeatures.shaderUniformBufferArrayNonUniformIndexing << "\n"; << "\n";
std::cout << "\t\tshaderUniformTexelBufferArrayDynamicIndexing : " std::cout << "\t\tshaderUniformTexelBufferArrayDynamicIndexing : " << !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayDynamicIndexing
<< !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayDynamicIndexing << "\n"; << "\n";
std::cout << "\t\tshaderUniformTexelBufferArrayNonUniformIndexing : " std::cout << "\t\tshaderUniformTexelBufferArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayNonUniformIndexing << "\n"; << !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayNonUniformIndexing << "\n";
std::cout << "\n"; std::cout << "\n";
@ -368,8 +329,7 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_NV_scissor_exclusive" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_scissor_exclusive" ) )
{ {
vk::PhysicalDeviceExclusiveScissorFeaturesNV const & exclusiveScissorFeatures = vk::PhysicalDeviceExclusiveScissorFeaturesNV const & exclusiveScissorFeatures = features2.get<vk::PhysicalDeviceExclusiveScissorFeaturesNV>();
features2.get<vk::PhysicalDeviceExclusiveScissorFeaturesNV>();
std::cout << "\tExclusiveScissorFeatures:\n"; std::cout << "\tExclusiveScissorFeatures:\n";
std::cout << "\t\texclusiveScissor : " << !!exclusiveScissorFeatures.exclusiveScissor << "\n"; std::cout << "\t\texclusiveScissor : " << !!exclusiveScissorFeatures.exclusiveScissor << "\n";
std::cout << "\n"; std::cout << "\n";
@ -377,15 +337,11 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_fragment_density_map" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_fragment_density_map" ) )
{ {
vk::PhysicalDeviceFragmentDensityMapFeaturesEXT const & fragmentDensityMapFeatures = vk::PhysicalDeviceFragmentDensityMapFeaturesEXT const & fragmentDensityMapFeatures = features2.get<vk::PhysicalDeviceFragmentDensityMapFeaturesEXT>();
features2.get<vk::PhysicalDeviceFragmentDensityMapFeaturesEXT>();
std::cout << "\tFragmentDensityMapFeatures:\n"; std::cout << "\tFragmentDensityMapFeatures:\n";
std::cout << "\t\tfragmentDensityMap : " << !!fragmentDensityMapFeatures.fragmentDensityMap std::cout << "\t\tfragmentDensityMap : " << !!fragmentDensityMapFeatures.fragmentDensityMap << "\n";
<< "\n"; std::cout << "\t\tfragmentDensityMapDynamic : " << !!fragmentDensityMapFeatures.fragmentDensityMapDynamic << "\n";
std::cout << "\t\tfragmentDensityMapDynamic : " std::cout << "\t\tfragmentDensityMapNonSubsampledImages : " << !!fragmentDensityMapFeatures.fragmentDensityMapNonSubsampledImages << "\n";
<< !!fragmentDensityMapFeatures.fragmentDensityMapDynamic << "\n";
std::cout << "\t\tfragmentDensityMapNonSubsampledImages : "
<< !!fragmentDensityMapFeatures.fragmentDensityMapNonSubsampledImages << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -394,8 +350,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV const & fragmentShaderBarycentricFeatures = vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV const & fragmentShaderBarycentricFeatures =
features2.get<vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV>(); features2.get<vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV>();
std::cout << "\tFragmentShaderBarycentricFeatures:\n"; std::cout << "\tFragmentShaderBarycentricFeatures:\n";
std::cout << "\t\tfragmentShaderBarycentric : " << !!fragmentShaderBarycentricFeatures.fragmentShaderBarycentric std::cout << "\t\tfragmentShaderBarycentric : " << !!fragmentShaderBarycentricFeatures.fragmentShaderBarycentric << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -404,19 +359,15 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT const & fragmentShaderInterlockFeatures = vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT const & fragmentShaderInterlockFeatures =
features2.get<vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT>(); features2.get<vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT>();
std::cout << "\tFragmentShaderInterlockFeatures:\n"; std::cout << "\tFragmentShaderInterlockFeatures:\n";
std::cout << "\t\tfragmentShaderPixelInterlock : " std::cout << "\t\tfragmentShaderPixelInterlock : " << !!fragmentShaderInterlockFeatures.fragmentShaderPixelInterlock << "\n";
<< !!fragmentShaderInterlockFeatures.fragmentShaderPixelInterlock << "\n"; std::cout << "\t\tfragmentShaderSampleInterlock : " << !!fragmentShaderInterlockFeatures.fragmentShaderSampleInterlock << "\n";
std::cout << "\t\tfragmentShaderSampleInterlock : " std::cout << "\t\tfragmentShaderShadingRateInterlock : " << !!fragmentShaderInterlockFeatures.fragmentShaderShadingRateInterlock << "\n";
<< !!fragmentShaderInterlockFeatures.fragmentShaderSampleInterlock << "\n";
std::cout << "\t\tfragmentShaderShadingRateInterlock : "
<< !!fragmentShaderInterlockFeatures.fragmentShaderShadingRateInterlock << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_host_query_reset" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_host_query_reset" ) )
{ {
vk::PhysicalDeviceHostQueryResetFeaturesEXT const & hostQueryResetFeatures = vk::PhysicalDeviceHostQueryResetFeaturesEXT const & hostQueryResetFeatures = features2.get<vk::PhysicalDeviceHostQueryResetFeaturesEXT>();
features2.get<vk::PhysicalDeviceHostQueryResetFeaturesEXT>();
std::cout << "\tHostQueryResetFeatures:\n"; std::cout << "\tHostQueryResetFeatures:\n";
std::cout << "\t\thostQueryReset : " << !!hostQueryResetFeatures.hostQueryReset << "\n"; std::cout << "\t\thostQueryReset : " << !!hostQueryResetFeatures.hostQueryReset << "\n";
std::cout << "\n"; std::cout << "\n";
@ -433,8 +384,7 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_index_type_uint8" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_index_type_uint8" ) )
{ {
vk::PhysicalDeviceIndexTypeUint8FeaturesEXT const & indexTypeUint8Features = vk::PhysicalDeviceIndexTypeUint8FeaturesEXT const & indexTypeUint8Features = features2.get<vk::PhysicalDeviceIndexTypeUint8FeaturesEXT>();
features2.get<vk::PhysicalDeviceIndexTypeUint8FeaturesEXT>();
std::cout << "\tIndexTypeUint8Features:\n"; std::cout << "\tIndexTypeUint8Features:\n";
std::cout << "\t\tindexTypeUint8 : " << !!indexTypeUint8Features.indexTypeUint8 << "\n"; std::cout << "\t\tindexTypeUint8 : " << !!indexTypeUint8Features.indexTypeUint8 << "\n";
std::cout << "\n"; std::cout << "\n";
@ -442,20 +392,17 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_inline_uniform_block" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_inline_uniform_block" ) )
{ {
vk::PhysicalDeviceInlineUniformBlockFeaturesEXT const & inlineUniformBlockFeatures = vk::PhysicalDeviceInlineUniformBlockFeaturesEXT const & inlineUniformBlockFeatures = features2.get<vk::PhysicalDeviceInlineUniformBlockFeaturesEXT>();
features2.get<vk::PhysicalDeviceInlineUniformBlockFeaturesEXT>();
std::cout << "\tInlineUniformBlockFeatures:\n"; std::cout << "\tInlineUniformBlockFeatures:\n";
std::cout << "\t\tdescriptorBindingInlineUniformBlockUpdateAfterBind : " std::cout << "\t\tdescriptorBindingInlineUniformBlockUpdateAfterBind : "
<< !!inlineUniformBlockFeatures.descriptorBindingInlineUniformBlockUpdateAfterBind << "\n"; << !!inlineUniformBlockFeatures.descriptorBindingInlineUniformBlockUpdateAfterBind << "\n";
std::cout << "\t\tinlineUniformBlock : " std::cout << "\t\tinlineUniformBlock : " << !!inlineUniformBlockFeatures.inlineUniformBlock << "\n";
<< !!inlineUniformBlockFeatures.inlineUniformBlock << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_line_rasterization" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_line_rasterization" ) )
{ {
vk::PhysicalDeviceLineRasterizationFeaturesEXT const & lineRasterizationFeatures = vk::PhysicalDeviceLineRasterizationFeaturesEXT const & lineRasterizationFeatures = features2.get<vk::PhysicalDeviceLineRasterizationFeaturesEXT>();
features2.get<vk::PhysicalDeviceLineRasterizationFeaturesEXT>();
std::cout << "\tLineRasterizationFeatures:\n"; std::cout << "\tLineRasterizationFeatures:\n";
std::cout << "\t\tbresenhamLines : " << !!lineRasterizationFeatures.bresenhamLines << "\n"; std::cout << "\t\tbresenhamLines : " << !!lineRasterizationFeatures.bresenhamLines << "\n";
std::cout << "\t\trectangularLines : " << !!lineRasterizationFeatures.rectangularLines << "\n"; std::cout << "\t\trectangularLines : " << !!lineRasterizationFeatures.rectangularLines << "\n";
@ -468,8 +415,7 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_memory_priority" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_memory_priority" ) )
{ {
vk::PhysicalDeviceMemoryPriorityFeaturesEXT const & memoryPriorityFeatures = vk::PhysicalDeviceMemoryPriorityFeaturesEXT const & memoryPriorityFeatures = features2.get<vk::PhysicalDeviceMemoryPriorityFeaturesEXT>();
features2.get<vk::PhysicalDeviceMemoryPriorityFeaturesEXT>();
std::cout << "\tMemoryPriorityFeatures:\n"; std::cout << "\tMemoryPriorityFeatures:\n";
std::cout << "\t\tmemoryPriority : " << !!memoryPriorityFeatures.memoryPriority << "\n"; std::cout << "\t\tmemoryPriority : " << !!memoryPriorityFeatures.memoryPriority << "\n";
std::cout << "\n"; std::cout << "\n";
@ -477,16 +423,14 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_NV_mesh_shader" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_mesh_shader" ) )
{ {
vk::PhysicalDeviceMeshShaderFeaturesNV const & meshShaderFeatures = vk::PhysicalDeviceMeshShaderFeaturesNV const & meshShaderFeatures = features2.get<vk::PhysicalDeviceMeshShaderFeaturesNV>();
features2.get<vk::PhysicalDeviceMeshShaderFeaturesNV>();
std::cout << "\tMeshShaderFeatures:\n"; std::cout << "\tMeshShaderFeatures:\n";
std::cout << "\t\tmeshShader : " << !!meshShaderFeatures.meshShader << "\n"; std::cout << "\t\tmeshShader : " << !!meshShaderFeatures.meshShader << "\n";
std::cout << "\t\ttaskShader : " << !!meshShaderFeatures.taskShader << "\n"; std::cout << "\t\ttaskShader : " << !!meshShaderFeatures.taskShader << "\n";
std::cout << "\n"; std::cout << "\n";
} }
vk::PhysicalDeviceMultiviewFeatures const & multiviewFeatures = vk::PhysicalDeviceMultiviewFeatures const & multiviewFeatures = features2.get<vk::PhysicalDeviceMultiviewFeatures>();
features2.get<vk::PhysicalDeviceMultiviewFeatures>();
std::cout << "\tMultiviewFeatures:\n"; std::cout << "\tMultiviewFeatures:\n";
std::cout << "\t\tmultiview : " << !!multiviewFeatures.multiview << "\n"; std::cout << "\t\tmultiview : " << !!multiviewFeatures.multiview << "\n";
std::cout << "\t\tmultiviewGeometryShader : " << !!multiviewFeatures.multiviewGeometryShader << "\n"; std::cout << "\t\tmultiviewGeometryShader : " << !!multiviewFeatures.multiviewGeometryShader << "\n";
@ -498,13 +442,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR const & pipelineExecutablePropertiesFeatures = vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR const & pipelineExecutablePropertiesFeatures =
features2.get<vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(); features2.get<vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR>();
std::cout << "\tPipelineExectuablePropertiesFeatures:\n"; std::cout << "\tPipelineExectuablePropertiesFeatures:\n";
std::cout << "\t\tpipelineExecutableInfo : " << !!pipelineExecutablePropertiesFeatures.pipelineExecutableInfo std::cout << "\t\tpipelineExecutableInfo : " << !!pipelineExecutablePropertiesFeatures.pipelineExecutableInfo << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
vk::PhysicalDeviceProtectedMemoryFeatures const & protectedMemoryFeatures = vk::PhysicalDeviceProtectedMemoryFeatures const & protectedMemoryFeatures = features2.get<vk::PhysicalDeviceProtectedMemoryFeatures>();
features2.get<vk::PhysicalDeviceProtectedMemoryFeatures>();
std::cout << "\tProtectedMemoryFeatures:\n"; std::cout << "\tProtectedMemoryFeatures:\n";
std::cout << "\t\tprotectedMemory : " << !!protectedMemoryFeatures.protectedMemory << "\n"; std::cout << "\t\tprotectedMemory : " << !!protectedMemoryFeatures.protectedMemory << "\n";
std::cout << "\n"; std::cout << "\n";
@ -514,8 +456,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV const & representativeFragmentTestFeatures = vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV const & representativeFragmentTestFeatures =
features2.get<vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV>(); features2.get<vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV>();
std::cout << "\tRepresentativeFragmentTestFeatures:\n"; std::cout << "\tRepresentativeFragmentTestFeatures:\n";
std::cout << "\t\trepresentativeFragmentTest : " std::cout << "\t\trepresentativeFragmentTest : " << !!representativeFragmentTestFeatures.representativeFragmentTest << "\n";
<< !!representativeFragmentTestFeatures.representativeFragmentTest << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -527,8 +468,7 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_scalar_block_layout" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_scalar_block_layout" ) )
{ {
vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT const & scalarBlockLayoutFeatures = vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT const & scalarBlockLayoutFeatures = features2.get<vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT>();
features2.get<vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT>();
std::cout << "\tScalarBlockLayoutFeatures:\n"; std::cout << "\tScalarBlockLayoutFeatures:\n";
std::cout << "\t\tscalarBlockLayout : " << !!scalarBlockLayoutFeatures.scalarBlockLayout << "\n"; std::cout << "\t\tscalarBlockLayout : " << !!scalarBlockLayoutFeatures.scalarBlockLayout << "\n";
std::cout << "\n"; std::cout << "\n";
@ -536,8 +476,7 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_KHR_shader_atomic_int64" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_shader_atomic_int64" ) )
{ {
vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR const & shaderAtomicInt64Features = vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR const & shaderAtomicInt64Features = features2.get<vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR>();
features2.get<vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR>();
std::cout << "\tShaderAtomicInt64Features:\n"; std::cout << "\tShaderAtomicInt64Features:\n";
std::cout << "\t\tshaderBufferInt64Atomics : " << !!shaderAtomicInt64Features.shaderBufferInt64Atomics << "\n"; std::cout << "\t\tshaderBufferInt64Atomics : " << !!shaderAtomicInt64Features.shaderBufferInt64Atomics << "\n";
std::cout << "\t\tshaderSharedInt64Atomics : " << !!shaderAtomicInt64Features.shaderSharedInt64Atomics << "\n"; std::cout << "\t\tshaderSharedInt64Atomics : " << !!shaderAtomicInt64Features.shaderSharedInt64Atomics << "\n";
@ -549,21 +488,18 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT const & shaderDemoteToHelperInvocationFeatures = vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT const & shaderDemoteToHelperInvocationFeatures =
features2.get<vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(); features2.get<vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>();
std::cout << "\tShaderDemoteToHelperInvocationFeatures:\n"; std::cout << "\tShaderDemoteToHelperInvocationFeatures:\n";
std::cout << "\t\tshaderDemoteToHelperInvocation : " std::cout << "\t\tshaderDemoteToHelperInvocation : " << !!shaderDemoteToHelperInvocationFeatures.shaderDemoteToHelperInvocation << "\n";
<< !!shaderDemoteToHelperInvocationFeatures.shaderDemoteToHelperInvocation << "\n";
std::cout << "\n"; std::cout << "\n";
} }
vk::PhysicalDeviceShaderDrawParametersFeatures const & shaderDrawParametersFeature = vk::PhysicalDeviceShaderDrawParametersFeatures const & shaderDrawParametersFeature = features2.get<vk::PhysicalDeviceShaderDrawParametersFeatures>();
features2.get<vk::PhysicalDeviceShaderDrawParametersFeatures>();
std::cout << "\tShaderDrawParametersFeature:\n"; std::cout << "\tShaderDrawParametersFeature:\n";
std::cout << "\t\tshaderDrawParameters : " << !!shaderDrawParametersFeature.shaderDrawParameters << "\n"; std::cout << "\t\tshaderDrawParameters : " << !!shaderDrawParametersFeature.shaderDrawParameters << "\n";
std::cout << "\n"; std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_KHR_shader_float16_int8" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_shader_float16_int8" ) )
{ {
vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR const & shaderFloat16Int8Features = vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR const & shaderFloat16Int8Features = features2.get<vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR>();
features2.get<vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR>();
std::cout << "\tShaderFloat16Int8Features:\n"; std::cout << "\tShaderFloat16Int8Features:\n";
std::cout << "\t\tshaderFloat16 : " << !!shaderFloat16Int8Features.shaderFloat16 << "\n"; std::cout << "\t\tshaderFloat16 : " << !!shaderFloat16Int8Features.shaderFloat16 << "\n";
std::cout << "\t\tshaderInt8 : " << !!shaderFloat16Int8Features.shaderInt8 << "\n"; std::cout << "\t\tshaderInt8 : " << !!shaderFloat16Int8Features.shaderInt8 << "\n";
@ -584,15 +520,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL const & shaderIntegerFunctions2Features = vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL const & shaderIntegerFunctions2Features =
features2.get<vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(); features2.get<vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>();
std::cout << "\tShaderIntegerFunctions2Features:\n"; std::cout << "\tShaderIntegerFunctions2Features:\n";
std::cout << "\t\tshaderIntegerFunctions2 : " << !!shaderIntegerFunctions2Features.shaderIntegerFunctions2 std::cout << "\t\tshaderIntegerFunctions2 : " << !!shaderIntegerFunctions2Features.shaderIntegerFunctions2 << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_NV_shader_sm_builtins" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_shader_sm_builtins" ) )
{ {
vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV const & shaderSMBuiltinsFeatures = vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV const & shaderSMBuiltinsFeatures = features2.get<vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV>();
features2.get<vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV>();
std::cout << "\tShaderSMBuiltinsFeatures:\n"; std::cout << "\tShaderSMBuiltinsFeatures:\n";
std::cout << "\t\tshaderSMBuiltins : " << !!shaderSMBuiltinsFeatures.shaderSMBuiltins << "\n"; std::cout << "\t\tshaderSMBuiltins : " << !!shaderSMBuiltinsFeatures.shaderSMBuiltins << "\n";
std::cout << "\n"; std::cout << "\n";
@ -603,18 +537,15 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR const & shaderSubgroupExtendedTypesFeatures = vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR const & shaderSubgroupExtendedTypesFeatures =
features2.get<vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR>(); features2.get<vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR>();
std::cout << "\tShaderSubgroupExtendedTypeFeatures:\n"; std::cout << "\tShaderSubgroupExtendedTypeFeatures:\n";
std::cout << "\t\tshaderSubgroupExtendedTypes : " std::cout << "\t\tshaderSubgroupExtendedTypes : " << !!shaderSubgroupExtendedTypesFeatures.shaderSubgroupExtendedTypes << "\n";
<< !!shaderSubgroupExtendedTypesFeatures.shaderSubgroupExtendedTypes << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_NV_shading_rate_image" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_shading_rate_image" ) )
{ {
vk::PhysicalDeviceShadingRateImageFeaturesNV const & shadingRateImageFeatures = vk::PhysicalDeviceShadingRateImageFeaturesNV const & shadingRateImageFeatures = features2.get<vk::PhysicalDeviceShadingRateImageFeaturesNV>();
features2.get<vk::PhysicalDeviceShadingRateImageFeaturesNV>();
std::cout << "\tShadingRateImageFeatures:\n"; std::cout << "\tShadingRateImageFeatures:\n";
std::cout << "\t\tshadingRateCoarseSampleOrder : " << !!shadingRateImageFeatures.shadingRateCoarseSampleOrder std::cout << "\t\tshadingRateCoarseSampleOrder : " << !!shadingRateImageFeatures.shadingRateCoarseSampleOrder << "\n";
<< "\n";
std::cout << "\t\tshadingRateImage : " << !!shadingRateImageFeatures.shadingRateImage << "\n"; std::cout << "\t\tshadingRateImage : " << !!shadingRateImageFeatures.shadingRateImage << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -643,15 +574,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT const & textureCompressionASTCHDRFeatures = vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT const & textureCompressionASTCHDRFeatures =
features2.get<vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT>(); features2.get<vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT>();
std::cout << "\tTextureCompressionASTCHHRFeatures:\n"; std::cout << "\tTextureCompressionASTCHHRFeatures:\n";
std::cout << "\t\ttextureCompressionASTC_HDR : " std::cout << "\t\ttextureCompressionASTC_HDR : " << !!textureCompressionASTCHDRFeatures.textureCompressionASTC_HDR << "\n";
<< !!textureCompressionASTCHDRFeatures.textureCompressionASTC_HDR << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_KHR_timeline_semaphore" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_timeline_semaphore" ) )
{ {
vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR const & timelineSemaphoreFeatures = vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR const & timelineSemaphoreFeatures = features2.get<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
features2.get<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
std::cout << "\tTimelineSemaphoreFeatures:\n"; std::cout << "\tTimelineSemaphoreFeatures:\n";
std::cout << "\t\ttimelineSemaphore :" << !!timelineSemaphoreFeatures.timelineSemaphore << "\n"; std::cout << "\t\ttimelineSemaphore :" << !!timelineSemaphoreFeatures.timelineSemaphore << "\n";
std::cout << "\n"; std::cout << "\n";
@ -659,8 +588,7 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_transform_feedback" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_transform_feedback" ) )
{ {
vk::PhysicalDeviceTransformFeedbackFeaturesEXT const & transformFeedbackFeatures = vk::PhysicalDeviceTransformFeedbackFeaturesEXT const & transformFeedbackFeatures = features2.get<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>();
features2.get<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>();
std::cout << "\tTransformFeedbackFeatures:\n"; std::cout << "\tTransformFeedbackFeatures:\n";
std::cout << "\t\tgeometryStreams : " << !!transformFeedbackFeatures.geometryStreams << "\n"; std::cout << "\t\tgeometryStreams : " << !!transformFeedbackFeatures.geometryStreams << "\n";
std::cout << "\t\ttransformFeedback : " << !!transformFeedbackFeatures.transformFeedback << "\n"; std::cout << "\t\ttransformFeedback : " << !!transformFeedbackFeatures.transformFeedback << "\n";
@ -672,19 +600,16 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR const & uniformBufferStandardLayoutFeatures = vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR const & uniformBufferStandardLayoutFeatures =
features2.get<vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR>(); features2.get<vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR>();
std::cout << "\tUniformBufferStandardLayoutFeatures:\n"; std::cout << "\tUniformBufferStandardLayoutFeatures:\n";
std::cout << "\t\tuniformBufferStandardLayout : " std::cout << "\t\tuniformBufferStandardLayout : " << !!uniformBufferStandardLayoutFeatures.uniformBufferStandardLayout << "\n";
<< !!uniformBufferStandardLayoutFeatures.uniformBufferStandardLayout << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_KHR_variable_pointers" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_variable_pointers" ) )
{ {
vk::PhysicalDeviceVariablePointersFeatures const & variablePointersFeatures = vk::PhysicalDeviceVariablePointersFeatures const & variablePointersFeatures = features2.get<vk::PhysicalDeviceVariablePointersFeatures>();
features2.get<vk::PhysicalDeviceVariablePointersFeatures>();
std::cout << "\tVariablePointersFeatures:\n"; std::cout << "\tVariablePointersFeatures:\n";
std::cout << "\t\tvariablePointers : " << !!variablePointersFeatures.variablePointers << "\n"; std::cout << "\t\tvariablePointers : " << !!variablePointersFeatures.variablePointers << "\n";
std::cout << "\t\tvariablePointersStorageBuffer : " << !!variablePointersFeatures.variablePointersStorageBuffer std::cout << "\t\tvariablePointersStorageBuffer : " << !!variablePointersFeatures.variablePointersStorageBuffer << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -693,31 +618,25 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT const & vertexAttributeDivisorFeatures = vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT const & vertexAttributeDivisorFeatures =
features2.get<vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT>(); features2.get<vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT>();
std::cout << "\tVertexAttributeDivisorFeature:\n"; std::cout << "\tVertexAttributeDivisorFeature:\n";
std::cout << "\t\tvertexAttributeInstanceRateDivisor : " std::cout << "\t\tvertexAttributeInstanceRateDivisor : " << !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateDivisor << "\n";
<< !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateDivisor << "\n"; std::cout << "\t\tvertexAttributeInstanceRateZeroDivisor : " << !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateZeroDivisor << "\n";
std::cout << "\t\tvertexAttributeInstanceRateZeroDivisor : "
<< !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateZeroDivisor << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_KHR_vulkan_memory_model" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_vulkan_memory_model" ) )
{ {
vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR const & vulkanMemoryModelFeatures = vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR const & vulkanMemoryModelFeatures = features2.get<vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR>();
features2.get<vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR>();
std::cout << "\tVulkanMemoryModelFeatures:\n"; std::cout << "\tVulkanMemoryModelFeatures:\n";
std::cout << "\t\tvulkanMemoryModel : " std::cout << "\t\tvulkanMemoryModel : " << !!vulkanMemoryModelFeatures.vulkanMemoryModel << "\n";
<< !!vulkanMemoryModelFeatures.vulkanMemoryModel << "\n"; std::cout << "\t\tvulkanMemoryModelAvailabilityVisibilityChains : " << !!vulkanMemoryModelFeatures.vulkanMemoryModelAvailabilityVisibilityChains
std::cout << "\t\tvulkanMemoryModelAvailabilityVisibilityChains : " << "\n";
<< !!vulkanMemoryModelFeatures.vulkanMemoryModelAvailabilityVisibilityChains << "\n"; std::cout << "\t\tvulkanMemoryModelDeviceScope : " << !!vulkanMemoryModelFeatures.vulkanMemoryModelDeviceScope << "\n";
std::cout << "\t\tvulkanMemoryModelDeviceScope : "
<< !!vulkanMemoryModelFeatures.vulkanMemoryModelDeviceScope << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_KHR_sampler_ycbcr_conversion" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_sampler_ycbcr_conversion" ) )
{ {
vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT const & ycbcrImageArraysFeatures = vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT const & ycbcrImageArraysFeatures = features2.get<vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT>();
features2.get<vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT>();
std::cout << "\tYcbcrImageArraysFeatures:\n"; std::cout << "\tYcbcrImageArraysFeatures:\n";
std::cout << "\t\tycbcrImageArrays : " << !!ycbcrImageArraysFeatures.ycbcrImageArrays << "\n"; std::cout << "\t\tycbcrImageArrays : " << !!ycbcrImageArraysFeatures.ycbcrImageArrays << "\n";
std::cout << "\n"; std::cout << "\n";

View File

@ -28,8 +28,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -48,8 +47,7 @@ int main( int /*argc*/, char ** /*argv*/ )
<< "physicalDevices:\n"; << "physicalDevices:\n";
for ( size_t j = 0; j < groupProperties[i].physicalDeviceCount; j++ ) for ( size_t j = 0; j < groupProperties[i].physicalDeviceCount; j++ )
{ {
vk::raii::PhysicalDevice physicalDevice( vk::raii::PhysicalDevice physicalDevice( instance, static_cast<VkPhysicalDevice>( groupProperties[i].physicalDevices[j] ) );
instance, static_cast<VkPhysicalDevice>( groupProperties[i].physicalDevices[j] ) );
std::cout << "\t\t" << j << " : " << physicalDevice.getProperties().deviceName << "\n"; std::cout << "\t\t" << j << " : " << physicalDevice.getProperties().deviceName << "\n";
} }
std::cout << "\t" std::cout << "\t"
@ -58,8 +56,7 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( 1 < groupProperties[i].physicalDeviceCount ) if ( 1 < groupProperties[i].physicalDeviceCount )
{ {
vk::raii::PhysicalDevice physicalDevice( vk::raii::PhysicalDevice physicalDevice( instance, static_cast<VkPhysicalDevice>( groupProperties[i].physicalDevices[0] ) );
instance, static_cast<VkPhysicalDevice>( groupProperties[i].physicalDevices[0] ) );
// get the QueueFamilyProperties of the first PhysicalDevice // get the QueueFamilyProperties of the first PhysicalDevice
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties(); std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
@ -67,18 +64,15 @@ int main( int /*argc*/, char ** /*argv*/ )
// get the first index into queueFamiliyProperties which supports graphics // get the first index into queueFamiliyProperties which supports graphics
auto propertyIterator = std::find_if( queueFamilyProperties.begin(), auto propertyIterator = std::find_if( queueFamilyProperties.begin(),
queueFamilyProperties.end(), queueFamilyProperties.end(),
[]( vk::QueueFamilyProperties const & qfp ) []( vk::QueueFamilyProperties const & qfp ) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; } );
{ return qfp.queueFlags & vk::QueueFlagBits::eGraphics; } );
size_t graphicsQueueFamilyIndex = std::distance( queueFamilyProperties.begin(), propertyIterator ); size_t graphicsQueueFamilyIndex = std::distance( queueFamilyProperties.begin(), propertyIterator );
assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() ); assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() );
// create a Device // create a Device
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateInfo deviceQueueCreateInfo( {}, static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
{}, static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
vk::StructureChain<vk::DeviceCreateInfo, vk::DeviceGroupDeviceCreateInfo> deviceCreateInfoChain( vk::StructureChain<vk::DeviceCreateInfo, vk::DeviceGroupDeviceCreateInfo> deviceCreateInfoChain(
{ {}, deviceQueueCreateInfo }, { {}, deviceQueueCreateInfo }, { groupProperties[i].physicalDeviceCount, groupProperties[i].physicalDevices } );
{ groupProperties[i].physicalDeviceCount, groupProperties[i].physicalDevices } );
vk::raii::Device device( physicalDevice, deviceCreateInfoChain.get<vk::DeviceCreateInfo>() ); vk::raii::Device device( physicalDevice, deviceCreateInfoChain.get<vk::DeviceCreateInfo>() );
} }

View File

@ -51,8 +51,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -65,18 +64,13 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ ) for ( size_t i = 0; i < physicalDevices.size(); i++ )
{ {
// some properties are only valid, if a corresponding extension is available! // some properties are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties = std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
physicalDevices[i].enumerateDeviceExtensionProperties(); bool containsMemoryBudget = vk::su::contains( extensionProperties, "VK_EXT_memory_budget" );
bool containsMemoryBudget = vk::su::contains( extensionProperties, "VK_EXT_memory_budget" );
std::cout << "PhysicalDevice " << i << " :\n"; std::cout << "PhysicalDevice " << i << " :\n";
auto memoryProperties2 = auto memoryProperties2 = physicalDevices[i].getMemoryProperties2<vk::PhysicalDeviceMemoryProperties2, vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
physicalDevices[i] vk::PhysicalDeviceMemoryProperties const & memoryProperties = memoryProperties2.get<vk::PhysicalDeviceMemoryProperties2>().memoryProperties;
.getMemoryProperties2<vk::PhysicalDeviceMemoryProperties2, vk::PhysicalDeviceMemoryBudgetPropertiesEXT>(); vk::PhysicalDeviceMemoryBudgetPropertiesEXT const & memoryBudgetProperties = memoryProperties2.get<vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
vk::PhysicalDeviceMemoryProperties const & memoryProperties =
memoryProperties2.get<vk::PhysicalDeviceMemoryProperties2>().memoryProperties;
vk::PhysicalDeviceMemoryBudgetPropertiesEXT const & memoryBudgetProperties =
memoryProperties2.get<vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
std::cout << "memoryHeapCount: " << memoryProperties.memoryHeapCount << "\n"; std::cout << "memoryHeapCount: " << memoryProperties.memoryHeapCount << "\n";
for ( uint32_t j = 0; j < memoryProperties.memoryHeapCount; j++ ) for ( uint32_t j = 0; j < memoryProperties.memoryHeapCount; j++ )
{ {

View File

@ -30,8 +30,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -45,35 +44,30 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ ) for ( size_t i = 0; i < physicalDevices.size(); i++ )
{ {
// some features are only valid, if a corresponding extension is available! // some features are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties = std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << " :" << std::endl; std::cout << "PhysicalDevice " << i << " :" << std::endl;
// need to explicitly specify all the template arguments for getQueueFamilyProperties2 to make the compiler happy // need to explicitly specify all the template arguments for getQueueFamilyProperties2 to make the compiler happy
using Chain = vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyCheckpointPropertiesNV>; using Chain = vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyCheckpointPropertiesNV>;
auto queueFamilyProperties2 = physicalDevices[i].getQueueFamilyProperties2<Chain>(); auto queueFamilyProperties2 = physicalDevices[i].getQueueFamilyProperties2<Chain>();
for ( size_t j = 0; j < queueFamilyProperties2.size(); j++ ) for ( size_t j = 0; j < queueFamilyProperties2.size(); j++ )
{ {
std::cout << "\tQueueFamily " << j << " :" << std::endl; std::cout << "\tQueueFamily " << j << " :" << std::endl;
vk::QueueFamilyProperties const & properties = vk::QueueFamilyProperties const & properties = queueFamilyProperties2[j].get<vk::QueueFamilyProperties2>().queueFamilyProperties;
queueFamilyProperties2[j].get<vk::QueueFamilyProperties2>().queueFamilyProperties;
std::cout << "\t\tQueueFamilyProperties:" << std::endl; std::cout << "\t\tQueueFamilyProperties:" << std::endl;
std::cout << "\t\t\tqueueFlags = " << vk::to_string( properties.queueFlags ) << std::endl; std::cout << "\t\t\tqueueFlags = " << vk::to_string( properties.queueFlags ) << std::endl;
std::cout << "\t\t\tqueueCount = " << properties.queueCount << std::endl; std::cout << "\t\t\tqueueCount = " << properties.queueCount << std::endl;
std::cout << "\t\t\ttimestampValidBits = " << properties.timestampValidBits << std::endl; std::cout << "\t\t\ttimestampValidBits = " << properties.timestampValidBits << std::endl;
std::cout << "\t\t\tminImageTransferGranularity = " << properties.minImageTransferGranularity.width << " x " std::cout << "\t\t\tminImageTransferGranularity = " << properties.minImageTransferGranularity.width << " x "
<< properties.minImageTransferGranularity.height << " x " << properties.minImageTransferGranularity.height << " x " << properties.minImageTransferGranularity.depth << std::endl;
<< properties.minImageTransferGranularity.depth << std::endl;
std::cout << std::endl; std::cout << std::endl;
if ( vk::su::contains( extensionProperties, "VK_NV_device_diagnostic_checkpoints" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_device_diagnostic_checkpoints" ) )
{ {
vk::QueueFamilyCheckpointPropertiesNV const & checkpointProperties = vk::QueueFamilyCheckpointPropertiesNV const & checkpointProperties = queueFamilyProperties2[j].get<vk::QueueFamilyCheckpointPropertiesNV>();
queueFamilyProperties2[j].get<vk::QueueFamilyCheckpointPropertiesNV>();
std::cout << "\t\tCheckPointPropertiesNV:" << std::endl; std::cout << "\t\tCheckPointPropertiesNV:" << std::endl;
std::cout << "\t\t\tcheckpointExecutionStageMask = " std::cout << "\t\t\tcheckpointExecutionStageMask = " << vk::to_string( checkpointProperties.checkpointExecutionStageMask ) << std::endl;
<< vk::to_string( checkpointProperties.checkpointExecutionStageMask ) << std::endl;
std::cout << std::endl; std::cout << std::endl;
} }
} }

View File

@ -73,8 +73,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -85,11 +84,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -99,8 +97,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -112,45 +109,35 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) ); textureData.setImage( commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, vk::raii::su::makeDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( vk::raii::DescriptorPool descriptorPool =
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::raii::DescriptorSet descriptorSet = vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets( device, vk::raii::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, { textureData } );
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } },
{ textureData } );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -293,21 +280,20 @@ int main( int /*argc*/, char ** /*argv*/ )
startCacheData = NULL; startCacheData = NULL;
// Time (roughly) taken to create the graphics pipeline // Time (roughly) taken to create the graphics pipeline
timestamp_t start = getMilliseconds(); timestamp_t start = getMilliseconds();
vk::raii::Pipeline graphicsPipeline = vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
vk::raii::su::makeGraphicsPipeline( device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass ); timestamp_t elapsed = getMilliseconds() - start;
timestamp_t elapsed = getMilliseconds() - start;
std::cout << " vkCreateGraphicsPipeline time: " << (double)elapsed << " ms\n"; std::cout << " vkCreateGraphicsPipeline time: " << (double)elapsed << " ms\n";
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
@ -315,8 +301,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -325,20 +310,14 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer.beginRenderPass( commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo( vk::RenderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, {} ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, {} );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -359,9 +338,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -41,22 +41,20 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() ); vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -66,58 +64,47 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::TextureData textureData( physicalDevice, device ); vk::raii::su::TextureData textureData( physicalDevice, device );
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() ); textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, vk::raii::su::makeDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( vk::raii::DescriptorPool descriptorPool =
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::raii::DescriptorSet descriptorSet = vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets( device, vk::raii::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, { textureData } );
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } },
{ textureData } );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
@ -133,40 +120,28 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, *fragmentShaderModule, "main" ) vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, *fragmentShaderModule, "main" )
}; };
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( texturedCubeData[0] ) ); vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( texturedCubeData[0] ) );
std::array<vk::VertexInputAttributeDescription, 2> vertexInputAttributeDescriptions = { std::array<vk::VertexInputAttributeDescription, 2> vertexInputAttributeDescriptions = {
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ), vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 ) vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
}; };
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( {}, vertexInputBindingDescription, vertexInputAttributeDescriptions );
{}, vertexInputBindingDescription, vertexInputAttributeDescriptions );
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( {}, vk::PrimitiveTopology::eTriangleList );
{}, vk::PrimitiveTopology::eTriangleList );
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( {}, 1, nullptr, 1, nullptr ); vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( {}, 1, nullptr, 1, nullptr );
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( {}, vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo(
false, {}, false, false, vk::PolygonMode::eFill, vk::CullModeFlagBits::eBack, vk::FrontFace::eClockwise, false, 0.0f, 0.0f, 0.0f, 1.0f );
false,
vk::PolygonMode::eFill,
vk::CullModeFlagBits::eBack,
vk::FrontFace::eClockwise,
false,
0.0f,
0.0f,
0.0f,
1.0f );
vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( {}, vk::SampleCountFlagBits::e1 ); vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( {}, vk::SampleCountFlagBits::e1 );
vk::StencilOpState stencilOpState( vk::StencilOpState stencilOpState( vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo( vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(
{}, true, true, vk::CompareOp::eLessOrEqual, false, false, stencilOpState, stencilOpState ); {}, true, true, vk::CompareOp::eLessOrEqual, false, false, stencilOpState, stencilOpState );
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB |
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA ); vk::ColorComponentFlagBits::eA );
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false, vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false,
vk::BlendFactor::eZero, vk::BlendFactor::eZero,
vk::BlendFactor::eZero, vk::BlendFactor::eZero,
@ -222,13 +197,11 @@ void main()
// Convert GLSL to SPIR-V // Convert GLSL to SPIR-V
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule fragmentShaderModule2 = vk::raii::ShaderModule fragmentShaderModule2 = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C_2 );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C_2 );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
// Modify pipeline info to reflect derivation // Modify pipeline info to reflect derivation
pipelineShaderStageCreateInfos[1] = pipelineShaderStageCreateInfos[1] = vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, *fragmentShaderModule2, "main" );
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, *fragmentShaderModule2, "main" );
graphicsPipelineCreateInfo.flags = vk::PipelineCreateFlagBits::eDerivative; graphicsPipelineCreateInfo.flags = vk::PipelineCreateFlagBits::eDerivative;
graphicsPipelineCreateInfo.basePipelineHandle = *basePipeline; graphicsPipelineCreateInfo.basePipelineHandle = *basePipeline;
graphicsPipelineCreateInfo.basePipelineIndex = -1; graphicsPipelineCreateInfo.basePipelineIndex = -1;
@ -251,8 +224,7 @@ void main()
// Get the index of the next available swapchain image // Get the index of the next available swapchain image
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -261,20 +233,14 @@ void main()
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer.beginRenderPass( commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo( vk::RenderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *derivedPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *derivedPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, {} ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, {} );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -295,9 +261,7 @@ void main()
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -83,8 +83,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -94,11 +93,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -108,42 +106,35 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
// Create binding and layout for the following, matching contents of shader // Create binding and layout for the following, matching contents of shader
// binding 0 = uniform buffer (MVP) // binding 0 = uniform buffer (MVP)
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::raii::su::makeDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -154,54 +145,47 @@ int main( int /*argc*/, char ** /*argv*/ )
// Create a single pool to contain data for our descriptor set // Create a single pool to contain data for our descriptor set
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorType::eCombinedImageSampler, 1 ) }; vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// Populate descriptor sets // Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet = vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
// Populate with info about our uniform buffer for MVP // Populate with info about our uniform buffer for MVP
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::WriteDescriptorSet writeDescriptorSet( vk::WriteDescriptorSet writeDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo );
*descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr ); device.updateDescriptorSets( writeDescriptorSet, nullptr );
// Create our push constant data, which matches shader expectations // Create our push constant data, which matches shader expectations
std::array<unsigned, 2> pushConstants = { { (unsigned)2, (unsigned)0x3F800000 } }; std::array<unsigned, 2> pushConstants = { { (unsigned)2, (unsigned)0x3F800000 } };
// Ensure we have enough room for push constant data // Ensure we have enough room for push constant data
assert( ( sizeof( pushConstants ) <= physicalDevice.getProperties().limits.maxPushConstantsSize ) && assert( ( sizeof( pushConstants ) <= physicalDevice.getProperties().limits.maxPushConstantsSize ) && "Too many push constants" );
"Too many push constants" );
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
commandBuffer.pushConstants<unsigned>( *pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, pushConstants ); commandBuffer.pushConstants<unsigned>( *pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, pushConstants );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
vk::raii::su::makeGraphicsPipeline( device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -209,21 +193,14 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -244,9 +221,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -40,9 +40,9 @@ int main( int /*argc*/, char ** /*argv*/ )
// To use PUSH_DESCRIPTOR, you must also specify GET_PHYSICAL_DEVICE_PROPERTIES_2 // To use PUSH_DESCRIPTOR, you must also specify GET_PHYSICAL_DEVICE_PROPERTIES_2
std::vector<vk::ExtensionProperties> extensionProperties = context.enumerateInstanceExtensionProperties(); std::vector<vk::ExtensionProperties> extensionProperties = context.enumerateInstanceExtensionProperties();
auto propertyIterator = auto propertyIterator =
std::find_if( extensionProperties.begin(), extensionProperties.end(), []( vk::ExtensionProperties ep ) { std::find_if( extensionProperties.begin(),
return ( strcmp( ep.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ) == 0 ); extensionProperties.end(),
} ); []( vk::ExtensionProperties ep ) { return ( strcmp( ep.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ) == 0 ); } );
if ( propertyIterator == extensionProperties.end() ) if ( propertyIterator == extensionProperties.end() )
{ {
std::cout << "No GET_PHYSICAL_DEVICE_PROPERTIES_2 extension" << std::endl; std::cout << "No GET_PHYSICAL_DEVICE_PROPERTIES_2 extension" << std::endl;
@ -52,19 +52,17 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<std::string> instanceExtensions = vk::su::getInstanceExtensions(); std::vector<std::string> instanceExtensions = vk::su::getInstanceExtensions();
instanceExtensions.push_back( VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ); instanceExtensions.push_back( VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME );
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, instanceExtensions );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, instanceExtensions );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() ); vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
// Once instance is created, need to make sure the extension is available // Once instance is created, need to make sure the extension is available
extensionProperties = physicalDevice.enumerateDeviceExtensionProperties(); extensionProperties = physicalDevice.enumerateDeviceExtensionProperties();
propertyIterator = propertyIterator = std::find_if( extensionProperties.begin(),
std::find_if( extensionProperties.begin(), extensionProperties.end(), []( vk::ExtensionProperties ep ) { extensionProperties.end(),
return ( strcmp( ep.extensionName, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME ) == 0 ); []( vk::ExtensionProperties ep ) { return ( strcmp( ep.extensionName, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME ) == 0 ); } );
} );
if ( propertyIterator == extensionProperties.end() ) if ( propertyIterator == extensionProperties.end() )
{ {
std::cout << "No extension for push descriptors" << std::endl; std::cout << "No extension for push descriptors" << std::endl;
@ -78,13 +76,11 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions );
vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -93,105 +89,84 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::TextureData textureData( physicalDevice, device ); vk::raii::su::TextureData textureData( physicalDevice, device );
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() ); textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
// Need to specify that descriptor set layout will be for push descriptors // Need to specify that descriptor set layout will be for push descriptors
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, vk::raii::su::makeDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } }, { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } },
vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR ); vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass =
vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo( vk::DescriptorImageInfo imageInfo( *textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal ); vk::WriteDescriptorSet writeDescriptorSets[2] = { vk::WriteDescriptorSet( {}, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet writeDescriptorSets[2] = { vk::WriteDescriptorSet( {}, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo ) };
vk::WriteDescriptorSet( {}, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( {}, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
};
// this call is from an extension and needs the dynamic dispatcher !! // this call is from an extension and needs the dynamic dispatcher !!
commandBuffer.pushDescriptorSetKHR( commandBuffer.pushDescriptorSetKHR( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { 2, writeDescriptorSets } );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { 2, writeDescriptorSets } );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -212,9 +187,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -105,15 +105,13 @@ namespace vk
return m_windowSize; return m_windowSize;
} }
CameraManipulator::Action CameraManipulator::Action CameraManipulator::mouseMove( glm::ivec2 const & position, MouseButton mouseButton, ModifierFlags & modifiers )
CameraManipulator::mouseMove( glm::ivec2 const & position, MouseButton mouseButton, ModifierFlags & modifiers )
{ {
Action curAction = Action::None; Action curAction = Action::None;
switch ( mouseButton ) switch ( mouseButton )
{ {
case MouseButton::Left: case MouseButton::Left:
if ( ( ( modifiers & ModifierFlagBits::Ctrl ) && ( modifiers & ModifierFlagBits::Shift ) ) || if ( ( ( modifiers & ModifierFlagBits::Ctrl ) && ( modifiers & ModifierFlagBits::Shift ) ) || ( modifiers & ModifierFlagBits::Alt ) )
( modifiers & ModifierFlagBits::Alt ) )
{ {
curAction = m_mode == Mode::Examine ? Action::LookAround : Action::Orbit; curAction = m_mode == Mode::Examine ? Action::LookAround : Action::Orbit;
} }
@ -140,9 +138,7 @@ namespace vk
return curAction; return curAction;
} }
void CameraManipulator::setLookat( const glm::vec3 & cameraPosition, void CameraManipulator::setLookat( const glm::vec3 & cameraPosition, const glm::vec3 & centerPosition, const glm::vec3 & upVector )
const glm::vec3 & centerPosition,
const glm::vec3 & upVector )
{ {
m_cameraPosition = cameraPosition; m_cameraPosition = cameraPosition;
m_centerPosition = centerPosition; m_centerPosition = centerPosition;

View File

@ -47,56 +47,80 @@ namespace vk
{ {
class CameraManipulator class CameraManipulator
{ {
public: public:
enum class Action { None, Orbit, Dolly, Pan, LookAround }; enum class Action
enum class Mode { Examine, Fly, Walk, Trackball }; {
enum class MouseButton { None, Left, Middle, Right }; None,
enum class ModifierFlagBits : uint32_t { Shift = 1, Ctrl = 2, Alt = 4 }; Orbit,
using ModifierFlags = vk::Flags<ModifierFlagBits>; Dolly,
Pan,
LookAround
};
enum class Mode
{
Examine,
Fly,
Walk,
Trackball
};
enum class MouseButton
{
None,
Left,
Middle,
Right
};
enum class ModifierFlagBits : uint32_t
{
Shift = 1,
Ctrl = 2,
Alt = 4
};
using ModifierFlags = vk::Flags<ModifierFlagBits>;
public: public:
CameraManipulator(); CameraManipulator();
glm::vec3 const& getCameraPosition() const; glm::vec3 const & getCameraPosition() const;
glm::vec3 const& getCenterPosition() const; glm::vec3 const & getCenterPosition() const;
glm::mat4 const& getMatrix() const; glm::mat4 const & getMatrix() const;
Mode getMode() const; Mode getMode() const;
glm::ivec2 const& getMousePosition() const; glm::ivec2 const & getMousePosition() const;
float getRoll() const; float getRoll() const;
float getSpeed() const; float getSpeed() const;
glm::vec3 const& getUpVector() const; glm::vec3 const & getUpVector() const;
glm::u32vec2 const& getWindowSize() const; glm::u32vec2 const & getWindowSize() const;
Action mouseMove(glm::ivec2 const& position, MouseButton mouseButton, ModifierFlags & modifiers); Action mouseMove( glm::ivec2 const & position, MouseButton mouseButton, ModifierFlags & modifiers );
void setLookat(const glm::vec3& cameraPosition, const glm::vec3& centerPosition, const glm::vec3& upVector); void setLookat( const glm::vec3 & cameraPosition, const glm::vec3 & centerPosition, const glm::vec3 & upVector );
void setMode(Mode mode); void setMode( Mode mode );
void setMousePosition(glm::ivec2 const& position); void setMousePosition( glm::ivec2 const & position );
void setRoll(float roll); // roll in radians void setRoll( float roll ); // roll in radians
void setSpeed(float speed); void setSpeed( float speed );
void setWindowSize(glm::ivec2 const& size); void setWindowSize( glm::ivec2 const & size );
void wheel(int value); void wheel( int value );
private: private:
void dolly(glm::vec2 const& delta); void dolly( glm::vec2 const & delta );
void motion(glm::ivec2 const& position, Action action = Action::None); void motion( glm::ivec2 const & position, Action action = Action::None );
void orbit(glm::vec2 const& delta, bool invert = false); void orbit( glm::vec2 const & delta, bool invert = false );
void pan(glm::vec2 const& delta); void pan( glm::vec2 const & delta );
double projectOntoTBSphere(const glm::vec2& p); double projectOntoTBSphere( const glm::vec2 & p );
void trackball(glm::ivec2 const& position); void trackball( glm::ivec2 const & position );
void update(); void update();
private: private:
glm::vec3 m_cameraPosition = glm::vec3(10, 10, 10); glm::vec3 m_cameraPosition = glm::vec3( 10, 10, 10 );
glm::vec3 m_centerPosition = glm::vec3(0, 0, 0); glm::vec3 m_centerPosition = glm::vec3( 0, 0, 0 );
glm::vec3 m_upVector = glm::vec3(0, 1, 0); glm::vec3 m_upVector = glm::vec3( 0, 1, 0 );
float m_roll = 0; // Rotation around the Z axis in RAD float m_roll = 0; // Rotation around the Z axis in RAD
glm::mat4 m_matrix = glm::mat4(1); glm::mat4 m_matrix = glm::mat4( 1 );
glm::u32vec2 m_windowSize = glm::u32vec2(1, 1); glm::u32vec2 m_windowSize = glm::u32vec2( 1, 1 );
float m_speed = 30.0f; float m_speed = 30.0f;
glm::ivec2 m_mousePosition = glm::ivec2(0, 0); glm::ivec2 m_mousePosition = glm::ivec2( 0, 0 );
Mode m_mode = Mode::Examine; Mode m_mode = Mode::Examine;
}; };
} // namespace su } // namespace su
} // namespace vk } // namespace vk

View File

@ -56,17 +56,9 @@ static char const * EngineName = "Vulkan.hpp";
struct GeometryInstanceData struct GeometryInstanceData
{ {
GeometryInstanceData( glm::mat4x4 const & transform_, GeometryInstanceData(
uint32_t instanceID_, glm::mat4x4 const & transform_, uint32_t instanceID_, uint8_t mask_, uint32_t instanceOffset_, uint8_t flags_, uint64_t accelerationStructureHandle_ )
uint8_t mask_, : instanceId( instanceID_ ), mask( mask_ ), instanceOffset( instanceOffset_ ), flags( flags_ ), accelerationStructureHandle( accelerationStructureHandle_ )
uint32_t instanceOffset_,
uint8_t flags_,
uint64_t accelerationStructureHandle_ )
: instanceId( instanceID_ )
, mask( mask_ )
, instanceOffset( instanceOffset_ )
, flags( flags_ )
, accelerationStructureHandle( accelerationStructureHandle_ )
{ {
assert( !( instanceID_ & 0xFF000000 ) && !( instanceOffset_ & 0xFF000000 ) ); assert( !( instanceID_ & 0xFF000000 ) && !( instanceOffset_ & 0xFF000000 ) );
memcpy( transform, &transform_, 12 * sizeof( float ) ); memcpy( transform, &transform_, 12 * sizeof( float ) );
@ -89,12 +81,11 @@ struct AccelerationStructureData
vk::raii::su::BufferData instanceBufferData = nullptr; vk::raii::su::BufferData instanceBufferData = nullptr;
}; };
AccelerationStructureData createAccelerationStructureData( AccelerationStructureData createAccelerationStructureData( vk::raii::PhysicalDevice const & physicalDevice,
vk::raii::PhysicalDevice const & physicalDevice, vk::raii::Device const & device,
vk::raii::Device const & device, vk::raii::CommandBuffer const & commandBuffer,
vk::raii::CommandBuffer const & commandBuffer, std::vector<std::pair<vk::raii::AccelerationStructureNV &, glm::mat4x4 &>> const & instances,
std::vector<std::pair<vk::raii::AccelerationStructureNV &, glm::mat4x4 &>> const & instances, std::vector<vk::GeometryNV> const & geometries )
std::vector<vk::GeometryNV> const & geometries )
{ {
assert( instances.empty() ^ geometries.empty() ); assert( instances.empty() ^ geometries.empty() );
@ -102,46 +93,32 @@ AccelerationStructureData createAccelerationStructureData(
vk::AccelerationStructureTypeNV accelerationStructureType = vk::AccelerationStructureTypeNV accelerationStructureType =
instances.empty() ? vk::AccelerationStructureTypeNV::eBottomLevel : vk::AccelerationStructureTypeNV::eTopLevel; instances.empty() ? vk::AccelerationStructureTypeNV::eBottomLevel : vk::AccelerationStructureTypeNV::eTopLevel;
vk::AccelerationStructureInfoNV accelerationStructureInfo( vk::AccelerationStructureInfoNV accelerationStructureInfo( accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
vk::AccelerationStructureCreateInfoNV accelerationStructureCreateInfoNV( 0, accelerationStructureInfo ); vk::AccelerationStructureCreateInfoNV accelerationStructureCreateInfoNV( 0, accelerationStructureInfo );
accelerationStructureData.acclerationStructure = accelerationStructureData.acclerationStructure = vk::raii::AccelerationStructureNV( device, accelerationStructureCreateInfoNV );
vk::raii::AccelerationStructureNV( device, accelerationStructureCreateInfoNV );
vk::AccelerationStructureMemoryRequirementsInfoNV objectRequirements( vk::AccelerationStructureMemoryRequirementsInfoNV objectRequirements( vk::AccelerationStructureMemoryRequirementsTypeNV::eObject,
vk::AccelerationStructureMemoryRequirementsTypeNV::eObject, *accelerationStructureData.acclerationStructure ); *accelerationStructureData.acclerationStructure );
vk::DeviceSize resultSizeInBytes = vk::DeviceSize resultSizeInBytes = device.getAccelerationStructureMemoryRequirementsNV( objectRequirements ).memoryRequirements.size;
device.getAccelerationStructureMemoryRequirementsNV( objectRequirements ).memoryRequirements.size;
assert( 0 < resultSizeInBytes ); assert( 0 < resultSizeInBytes );
accelerationStructureData.resultBufferData = vk::raii::su::BufferData( physicalDevice, accelerationStructureData.resultBufferData =
device, vk::raii::su::BufferData( physicalDevice, device, resultSizeInBytes, vk::BufferUsageFlagBits::eRayTracingNV, vk::MemoryPropertyFlagBits::eDeviceLocal );
resultSizeInBytes,
vk::BufferUsageFlagBits::eRayTracingNV,
vk::MemoryPropertyFlagBits::eDeviceLocal );
vk::AccelerationStructureMemoryRequirementsInfoNV buildScratchRequirements( vk::AccelerationStructureMemoryRequirementsInfoNV buildScratchRequirements( vk::AccelerationStructureMemoryRequirementsTypeNV::eBuildScratch,
vk::AccelerationStructureMemoryRequirementsTypeNV::eBuildScratch, *accelerationStructureData.acclerationStructure ); *accelerationStructureData.acclerationStructure );
vk::AccelerationStructureMemoryRequirementsInfoNV updateScratchRequirements( vk::AccelerationStructureMemoryRequirementsInfoNV updateScratchRequirements( vk::AccelerationStructureMemoryRequirementsTypeNV::eUpdateScratch,
vk::AccelerationStructureMemoryRequirementsTypeNV::eUpdateScratch, *accelerationStructureData.acclerationStructure );
*accelerationStructureData.acclerationStructure ); vk::DeviceSize scratchSizeInBytes = std::max( device.getAccelerationStructureMemoryRequirementsNV( buildScratchRequirements ).memoryRequirements.size,
vk::DeviceSize scratchSizeInBytes = std::max( device.getAccelerationStructureMemoryRequirementsNV( updateScratchRequirements ).memoryRequirements.size );
device.getAccelerationStructureMemoryRequirementsNV( buildScratchRequirements ).memoryRequirements.size,
device.getAccelerationStructureMemoryRequirementsNV( updateScratchRequirements ).memoryRequirements.size );
assert( 0 < scratchSizeInBytes ); assert( 0 < scratchSizeInBytes );
accelerationStructureData.scratchBufferData = vk::raii::su::BufferData( physicalDevice, accelerationStructureData.scratchBufferData =
device, vk::raii::su::BufferData( physicalDevice, device, scratchSizeInBytes, vk::BufferUsageFlagBits::eRayTracingNV, vk::MemoryPropertyFlagBits::eDeviceLocal );
scratchSizeInBytes,
vk::BufferUsageFlagBits::eRayTracingNV,
vk::MemoryPropertyFlagBits::eDeviceLocal );
if ( !instances.empty() ) if ( !instances.empty() )
{ {
accelerationStructureData.instanceBufferData = accelerationStructureData.instanceBufferData =
vk::raii::su::BufferData( physicalDevice, vk::raii::su::BufferData( physicalDevice, device, instances.size() * sizeof( GeometryInstanceData ), vk::BufferUsageFlagBits::eRayTracingNV );
device,
instances.size() * sizeof( GeometryInstanceData ),
vk::BufferUsageFlagBits::eRayTracingNV );
std::vector<GeometryInstanceData> geometryInstanceData; std::vector<GeometryInstanceData> geometryInstanceData;
for ( size_t i = 0; i < instances.size(); i++ ) for ( size_t i = 0; i < instances.size(); i++ )
@ -163,16 +140,15 @@ AccelerationStructureData createAccelerationStructureData(
accelerationStructureData.instanceBufferData.upload( geometryInstanceData ); accelerationStructureData.instanceBufferData.upload( geometryInstanceData );
} }
device.bindAccelerationStructureMemoryNV( vk::BindAccelerationStructureMemoryInfoNV( device.bindAccelerationStructureMemoryNV(
*accelerationStructureData.acclerationStructure, *accelerationStructureData.resultBufferData.deviceMemory ) ); vk::BindAccelerationStructureMemoryInfoNV( *accelerationStructureData.acclerationStructure, *accelerationStructureData.resultBufferData.deviceMemory ) );
vk::Buffer instanceData; vk::Buffer instanceData;
if ( *accelerationStructureData.instanceBufferData.buffer ) if ( *accelerationStructureData.instanceBufferData.buffer )
{ {
instanceData = *accelerationStructureData.instanceBufferData.buffer; instanceData = *accelerationStructureData.instanceBufferData.buffer;
} }
vk::AccelerationStructureInfoNV accelerationStructureInfoNV( vk::AccelerationStructureInfoNV accelerationStructureInfoNV( accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
commandBuffer.buildAccelerationStructureNV( accelerationStructureInfoNV, commandBuffer.buildAccelerationStructureNV( accelerationStructureInfoNV,
instanceData, instanceData,
0, 0,
@ -182,15 +158,10 @@ AccelerationStructureData createAccelerationStructureData(
*accelerationStructureData.scratchBufferData.buffer, *accelerationStructureData.scratchBufferData.buffer,
0 ); 0 );
vk::MemoryBarrier memoryBarrier( vk::MemoryBarrier memoryBarrier( vk::AccessFlagBits::eAccelerationStructureWriteNV | vk::AccessFlagBits::eAccelerationStructureReadNV,
vk::AccessFlagBits::eAccelerationStructureWriteNV | vk::AccessFlagBits::eAccelerationStructureReadNV, vk::AccessFlagBits::eAccelerationStructureWriteNV | vk::AccessFlagBits::eAccelerationStructureReadNV );
vk::AccessFlagBits::eAccelerationStructureWriteNV | vk::AccessFlagBits::eAccelerationStructureReadNV ); commandBuffer.pipelineBarrier(
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eAccelerationStructureBuildNV, vk::PipelineStageFlagBits::eAccelerationStructureBuildNV, vk::PipelineStageFlagBits::eAccelerationStructureBuildNV, {}, memoryBarrier, {}, {} );
vk::PipelineStageFlagBits::eAccelerationStructureBuildNV,
{},
memoryBarrier,
{},
{} );
return accelerationStructureData; return accelerationStructureData;
} }
@ -231,9 +202,7 @@ const size_t MaterialStride = ( ( sizeof( Material ) + 15 ) / 16 ) * 16;
struct Vertex struct Vertex
{ {
Vertex( glm::vec3 const & p, glm::vec3 const & n, glm::vec2 const & tc, int m = 0 ) Vertex( glm::vec3 const & p, glm::vec3 const & n, glm::vec2 const & tc, int m = 0 ) : pos( p ), nrm( n ), texCoord( tc ), matID( m ) {}
: pos( p ), nrm( n ), texCoord( tc ), matID( m )
{}
glm::vec3 pos; glm::vec3 pos;
glm::vec3 nrm; glm::vec3 nrm;
@ -564,13 +533,10 @@ static void check_vk_result( VkResult err )
static void cursorPosCallback( GLFWwindow * window, double mouseX, double mouseY ) static void cursorPosCallback( GLFWwindow * window, double mouseX, double mouseY )
{ {
vk::su::CameraManipulator::MouseButton mouseButton = vk::su::CameraManipulator::MouseButton mouseButton =
( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_LEFT ) == GLFW_PRESS ) ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_LEFT ) == GLFW_PRESS ) ? vk::su::CameraManipulator::MouseButton::Left
? vk::su::CameraManipulator::MouseButton::Left : ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_MIDDLE ) == GLFW_PRESS ) ? vk::su::CameraManipulator::MouseButton::Middle
: ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_MIDDLE ) == GLFW_PRESS ) : ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_RIGHT ) == GLFW_PRESS ) ? vk::su::CameraManipulator::MouseButton::Right
? vk::su::CameraManipulator::MouseButton::Middle : vk::su::CameraManipulator::MouseButton::None;
: ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_RIGHT ) == GLFW_PRESS )
? vk::su::CameraManipulator::MouseButton::Right
: vk::su::CameraManipulator::MouseButton::None;
if ( mouseButton != vk::su::CameraManipulator::MouseButton::None ) if ( mouseButton != vk::su::CameraManipulator::MouseButton::None )
{ {
vk::su::CameraManipulator::ModifierFlags modifiers; vk::su::CameraManipulator::ModifierFlags modifiers;
@ -587,10 +553,8 @@ static void cursorPosCallback( GLFWwindow * window, double mouseX, double mouseY
modifiers |= vk::su::CameraManipulator::ModifierFlagBits::Shift; modifiers |= vk::su::CameraManipulator::ModifierFlagBits::Shift;
} }
vk::su::CameraManipulator & cameraManipulator = vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator; cameraManipulator.mouseMove( glm::ivec2( static_cast<int>( mouseX ), static_cast<int>( mouseY ) ), mouseButton, modifiers );
cameraManipulator.mouseMove(
glm::ivec2( static_cast<int>( mouseX ), static_cast<int>( mouseY ) ), mouseButton, modifiers );
} }
} }
@ -601,8 +565,7 @@ static void errorCallback( int error, const char * description )
static void framebufferSizeCallback( GLFWwindow * window, int w, int h ) static void framebufferSizeCallback( GLFWwindow * window, int w, int h )
{ {
vk::su::CameraManipulator & cameraManipulator = vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
cameraManipulator.setWindowSize( glm::ivec2( w, h ) ); cameraManipulator.setWindowSize( glm::ivec2( w, h ) );
} }
@ -629,15 +592,13 @@ static void mouseButtonCallback( GLFWwindow * window, int /*button*/, int /*acti
double xpos, ypos; double xpos, ypos;
glfwGetCursorPos( window, &xpos, &ypos ); glfwGetCursorPos( window, &xpos, &ypos );
vk::su::CameraManipulator & cameraManipulator = vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
cameraManipulator.setMousePosition( glm::ivec2( static_cast<int>( xpos ), static_cast<int>( ypos ) ) ); cameraManipulator.setMousePosition( glm::ivec2( static_cast<int>( xpos ), static_cast<int>( ypos ) ) );
} }
static void scrollCallback( GLFWwindow * window, double /*xoffset*/, double yoffset ) static void scrollCallback( GLFWwindow * window, double /*xoffset*/, double yoffset )
{ {
vk::su::CameraManipulator & cameraManipulator = vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
cameraManipulator.wheel( static_cast<int>( yoffset ) ); cameraManipulator.wheel( static_cast<int>( yoffset ) );
} }
@ -658,9 +619,7 @@ glm::vec3 randomVec3( float minValue, float maxValue )
{ {
std::uniform_real_distribution<float> randomDistribution( minValue, maxValue ); std::uniform_real_distribution<float> randomDistribution( minValue, maxValue );
return glm::vec3( randomDistribution( randomGenerator ), return glm::vec3( randomDistribution( randomGenerator ), randomDistribution( randomGenerator ), randomDistribution( randomGenerator ) );
randomDistribution( randomGenerator ),
randomDistribution( randomGenerator ) );
} }
uint32_t roundUp( uint32_t value, uint32_t alignment ) uint32_t roundUp( uint32_t value, uint32_t alignment )
@ -706,8 +665,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// Setup camera and make it available as the userPointer in the glfw window // Setup camera and make it available as the userPointer in the glfw window
appInfo.cameraManipulator.setWindowSize( glm::u32vec2( windowExtent.width, windowExtent.height ) ); appInfo.cameraManipulator.setWindowSize( glm::u32vec2( windowExtent.width, windowExtent.height ) );
glm::vec3 diagonal = glm::vec3 diagonal = 3.0f * glm::vec3( static_cast<float>( xMax ), static_cast<float>( yMax ), static_cast<float>( zMax ) );
3.0f * glm::vec3( static_cast<float>( xMax ), static_cast<float>( yMax ), static_cast<float>( zMax ) );
appInfo.cameraManipulator.setLookat( 1.5f * diagonal, 0.5f * diagonal, glm::vec3( 0, 1, 0 ) ); appInfo.cameraManipulator.setLookat( 1.5f * diagonal, 0.5f * diagonal, glm::vec3( 0, 1, 0 ) );
glfwSetWindowUserPointer( window, &appInfo ); glfwSetWindowUserPointer( window, &appInfo );
@ -725,11 +683,9 @@ int main( int /*argc*/, char ** /*argv*/ )
#if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL #if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL
vk::raii::Context context; vk::raii::Context context;
#else #else
vk::raii::Context context( vk::raii::Context context( reinterpret_cast<PFN_vkGetInstanceProcAddr>( glfwGetInstanceProcAddress( NULL, "vkGetInstanceProcAddr" ) ) );
reinterpret_cast<PFN_vkGetInstanceProcAddr>( glfwGetInstanceProcAddress( NULL, "vkGetInstanceProcAddr" ) ) );
#endif #endif
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, instanceExtensions, VK_API_VERSION_1_2 );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, instanceExtensions, VK_API_VERSION_1_2 );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -751,18 +707,14 @@ int main( int /*argc*/, char ** /*argv*/ )
check_vk_result( err ); check_vk_result( err );
vk::raii::SurfaceKHR surface( instance, glfwSurface ); vk::raii::SurfaceKHR surface( instance, glfwSurface );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surface );
// Create a Device with ray tracing support (besides some other extensions needed) and needed features // Create a Device with ray tracing support (besides some other extensions needed) and needed features
auto supportedFeatures = auto supportedFeatures = physicalDevice.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
physicalDevice.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
vk::raii::Device device = vk::raii::Device device =
vk::raii::su::makeDevice( physicalDevice, vk::raii::su::makeDevice( physicalDevice,
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
{ VK_KHR_SWAPCHAIN_EXTENSION_NAME, { VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_NV_RAY_TRACING_EXTENSION_NAME, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME },
VK_NV_RAY_TRACING_EXTENSION_NAME,
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME },
&supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features, &supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features,
&supportedFeatures.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>() ); &supportedFeatures.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>() );
@ -789,20 +741,19 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surface, surface,
windowExtent, windowExtent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage,
vk::ImageUsageFlagBits::eStorage,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::SurfaceFormatKHR surfaceFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surface ) ); vk::SurfaceFormatKHR surfaceFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surface ) );
vk::Format depthFormat = vk::raii::su::pickDepthFormat( physicalDevice ); vk::Format depthFormat = vk::raii::su::pickDepthFormat( physicalDevice );
// setup a render pass // setup a render pass
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, surfaceFormat.format, depthFormat ); vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, surfaceFormat.format, depthFormat );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, depthFormat, windowExtent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, depthFormat, windowExtent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, windowExtent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, windowExtent );
bool samplerAnisotropy = !!supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features.samplerAnisotropy; bool samplerAnisotropy = !!supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features.samplerAnisotropy;
@ -828,9 +779,8 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( auto & t : textures ) for ( auto & t : textures )
{ {
t.setImage( commandBuffer, t.setImage( commandBuffer,
vk::su::CheckerboardImageGenerator( vk::su::CheckerboardImageGenerator( { random<uint8_t>(), random<uint8_t>(), random<uint8_t>() },
{ random<uint8_t>(), random<uint8_t>(), random<uint8_t>() }, { random<uint8_t>(), random<uint8_t>(), random<uint8_t>() } ) );
{ random<uint8_t>(), random<uint8_t>(), random<uint8_t>() } ) );
} }
} ); } );
@ -843,8 +793,7 @@ int main( int /*argc*/, char ** /*argv*/ )
materials[i].diffuse = randomVec3( 0.0f, 1.0f ); materials[i].diffuse = randomVec3( 0.0f, 1.0f );
materials[i].textureID = vk::su::checked_cast<uint32_t>( i ); materials[i].textureID = vk::su::checked_cast<uint32_t>( i );
} }
vk::raii::su::BufferData materialBufferData( vk::raii::su::BufferData materialBufferData( physicalDevice, device, materialCount * MaterialStride, vk::BufferUsageFlagBits::eStorageBuffer );
physicalDevice, device, materialCount * MaterialStride, vk::BufferUsageFlagBits::eStorageBuffer );
materialBufferData.upload( materials, MaterialStride ); materialBufferData.upload( materials, MaterialStride );
// create a a 3D-array of cubes, randomly jittered, using a random material // create a a 3D-array of cubes, randomly jittered, using a random material
@ -861,8 +810,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( auto const & v : cubeData ) for ( auto const & v : cubeData )
{ {
vertices.push_back( v ); vertices.push_back( v );
vertices.back().pos += vertices.back().pos += 3.0f * glm::vec3( static_cast<float>( x ), static_cast<float>( y ), static_cast<float>( z ) ) + jitter;
3.0f * glm::vec3( static_cast<float>( x ), static_cast<float>( y ), static_cast<float>( z ) ) + jitter;
vertices.back().matID = static_cast<int>( m ); vertices.back().matID = static_cast<int>( m );
} }
} }
@ -874,26 +822,16 @@ int main( int /*argc*/, char ** /*argv*/ )
std::iota( indices.begin(), indices.end(), 0 ); std::iota( indices.begin(), indices.end(), 0 );
// there's just one vertex- and one index-buffer, but with more complex scene loaders there might be more! // there's just one vertex- and one index-buffer, but with more complex scene loaders there might be more!
vk::BufferUsageFlags bufferUsageFlags = vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlags bufferUsageFlags =
vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eStorageBuffer;
vk::BufferUsageFlagBits::eStorageBuffer; vk::raii::su::BufferData vertexBufferData(
vk::raii::su::BufferData vertexBufferData( physicalDevice, physicalDevice, device, vertices.size() * VertexStride, bufferUsageFlags, vk::MemoryPropertyFlagBits::eDeviceLocal );
device, vertexBufferData.upload( physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, vertices, VertexStride );
vertices.size() * VertexStride,
bufferUsageFlags,
vk::MemoryPropertyFlagBits::eDeviceLocal );
vertexBufferData.upload(
physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, vertices, VertexStride );
bufferUsageFlags = vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eIndexBuffer | bufferUsageFlags = vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eStorageBuffer;
vk::BufferUsageFlagBits::eStorageBuffer; vk::raii::su::BufferData indexBufferData(
vk::raii::su::BufferData indexBufferData( physicalDevice, physicalDevice, device, indices.size() * sizeof( uint32_t ), bufferUsageFlags, vk::MemoryPropertyFlagBits::eDeviceLocal );
device, indexBufferData.upload( physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, indices, sizeof( uint32_t ) );
indices.size() * sizeof( uint32_t ),
bufferUsageFlags,
vk::MemoryPropertyFlagBits::eDeviceLocal );
indexBufferData.upload(
physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, indices, sizeof( uint32_t ) );
// clang-format off // clang-format off
glm::mat4x4 transform( glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f, glm::mat4x4 transform( glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f,
@ -905,49 +843,41 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(
device, device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eStorageBuffer, { vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment },
1, { vk::DescriptorType::eCombinedImageSampler, static_cast<uint32_t>( textures.size() ), vk::ShaderStageFlagBits::eFragment } } );
vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment },
{ vk::DescriptorType::eCombinedImageSampler,
static_cast<uint32_t>( textures.size() ),
vk::ShaderStageFlagBits::eFragment } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
fragmentShaderModule,
nullptr,
VertexStride,
{ { vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, pos ) ) },
{ vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, nrm ) ) },
{ vk::Format::eR32G32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, texCoord ) ) },
{ vk::Format::eR32Sint, vk::su::checked_cast<uint32_t>( offsetof( Vertex, matID ) ) } },
vk::FrontFace::eCounterClockwise,
true,
pipelineLayout,
renderPass );
vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( UniformBufferObject ), vk::BufferUsageFlagBits::eUniformBuffer );
vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets(
device, device,
pipelineCache, descriptorSet,
vertexShaderModule, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} }, { vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, {} } },
nullptr, textures );
fragmentShaderModule,
nullptr,
VertexStride,
{ { vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, pos ) ) },
{ vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, nrm ) ) },
{ vk::Format::eR32G32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, texCoord ) ) },
{ vk::Format::eR32Sint, vk::su::checked_cast<uint32_t>( offsetof( Vertex, matID ) ) } },
vk::FrontFace::eCounterClockwise,
true,
pipelineLayout,
renderPass );
vk::raii::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( UniformBufferObject ), vk::BufferUsageFlagBits::eUniformBuffer );
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets( device,
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} },
{ vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, {} } },
textures );
// RayTracing specific stuff // RayTracing specific stuff
@ -970,64 +900,39 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::IndexType::eUint32 ), vk::IndexType::eUint32 ),
{} ); {} );
bottomLevelAS = bottomLevelAS =
createAccelerationStructureData( physicalDevice, createAccelerationStructureData( physicalDevice, device, commandBuffer, {}, { vk::GeometryNV( vk::GeometryTypeNV::eTriangles, geometryDataNV ) } );
device,
commandBuffer,
{},
{ vk::GeometryNV( vk::GeometryTypeNV::eTriangles, geometryDataNV ) } );
topLevelAS = createAccelerationStructureData( topLevelAS = createAccelerationStructureData( physicalDevice,
physicalDevice, device,
device, commandBuffer,
commandBuffer, { std::make_pair( std::ref( bottomLevelAS.acclerationStructure ), std::ref( transform ) ) },
{ std::make_pair( std::ref( bottomLevelAS.acclerationStructure ), std::ref( transform ) ) }, std::vector<vk::GeometryNV>() );
std::vector<vk::GeometryNV>() );
} ); } );
// create raytracing descriptor set // create raytracing descriptor set
vk::raii::su::oneTimeSubmit( device, vk::raii::su::oneTimeSubmit(
perFrameData[0].commandPool, device,
graphicsQueue, perFrameData[0].commandPool,
[&]( vk::raii::CommandBuffer const & commandBuffer ) graphicsQueue,
{ [&]( vk::raii::CommandBuffer const & commandBuffer )
vk::BufferMemoryBarrier bufferMemoryBarrier( {}, {
vk::AccessFlagBits::eShaderRead, vk::BufferMemoryBarrier bufferMemoryBarrier(
VK_QUEUE_FAMILY_IGNORED, {}, vk::AccessFlagBits::eShaderRead, VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, *vertexBufferData.buffer, 0, VK_WHOLE_SIZE );
VK_QUEUE_FAMILY_IGNORED, commandBuffer.pipelineBarrier(
*vertexBufferData.buffer, vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, nullptr, bufferMemoryBarrier, nullptr );
0,
VK_WHOLE_SIZE );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eAllCommands,
vk::PipelineStageFlagBits::eAllCommands,
{},
nullptr,
bufferMemoryBarrier,
nullptr );
bufferMemoryBarrier.buffer = *indexBufferData.buffer; bufferMemoryBarrier.buffer = *indexBufferData.buffer;
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eAllCommands, commandBuffer.pipelineBarrier(
vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, nullptr, bufferMemoryBarrier, nullptr );
{}, } );
nullptr,
bufferMemoryBarrier,
nullptr );
} );
std::vector<vk::DescriptorSetLayoutBinding> bindings; std::vector<vk::DescriptorSetLayoutBinding> bindings;
bindings.emplace_back( 0, bindings.emplace_back( 0, vk::DescriptorType::eAccelerationStructureNV, 1, vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV );
vk::DescriptorType::eAccelerationStructureNV, bindings.emplace_back( 1, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eRaygenNV ); // raytracing output
1, bindings.emplace_back( 2, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eRaygenNV ); // camera information
vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV ); bindings.emplace_back( 3, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // vertex buffer
bindings.emplace_back( bindings.emplace_back( 4, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // index buffer
1, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eRaygenNV ); // raytracing output bindings.emplace_back( 5, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // material buffer
bindings.emplace_back(
2, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eRaygenNV ); // camera information
bindings.emplace_back(
3, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // vertex buffer
bindings.emplace_back(
4, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // index buffer
bindings.emplace_back(
5, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // material buffer
bindings.emplace_back( 6, bindings.emplace_back( 6,
vk::DescriptorType::eCombinedImageSampler, vk::DescriptorType::eCombinedImageSampler,
vk::su::checked_cast<uint32_t>( textures.size() ), vk::su::checked_cast<uint32_t>( textures.size() ),
@ -1037,13 +942,10 @@ int main( int /*argc*/, char ** /*argv*/ )
descriptorPoolSizes.reserve( bindings.size() ); descriptorPoolSizes.reserve( bindings.size() );
for ( const auto & b : bindings ) for ( const auto & b : bindings )
{ {
descriptorPoolSizes.emplace_back( descriptorPoolSizes.emplace_back( b.descriptorType, vk::su::checked_cast<uint32_t>( swapChainData.images.size() ) * b.descriptorCount );
b.descriptorType, vk::su::checked_cast<uint32_t>( swapChainData.images.size() ) * b.descriptorCount );
} }
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, vk::su::checked_cast<uint32_t>( swapChainData.images.size() ), descriptorPoolSizes );
vk::su::checked_cast<uint32_t>( swapChainData.images.size() ),
descriptorPoolSizes );
vk::raii::DescriptorPool rayTracingDescriptorPool( device, descriptorPoolCreateInfo ); vk::raii::DescriptorPool rayTracingDescriptorPool( device, descriptorPoolCreateInfo );
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, bindings ); vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, bindings );
vk::raii::DescriptorSetLayout rayTracingDescriptorSetLayout( device, descriptorSetLayoutCreateInfo ); vk::raii::DescriptorSetLayout rayTracingDescriptorSetLayout( device, descriptorSetLayoutCreateInfo );
@ -1056,8 +958,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::DescriptorSets rayTracingDescriptorSets( device, descriptorSetAllocateInfo ); vk::raii::DescriptorSets rayTracingDescriptorSets( device, descriptorSetAllocateInfo );
// Bind ray tracing specific descriptor sets into pNext of a vk::WriteDescriptorSet // Bind ray tracing specific descriptor sets into pNext of a vk::WriteDescriptorSet
vk::WriteDescriptorSetAccelerationStructureNV writeDescriptorSetAcceleration( 1, vk::WriteDescriptorSetAccelerationStructureNV writeDescriptorSetAcceleration( 1, &*topLevelAS.acclerationStructure );
&*topLevelAS.acclerationStructure );
std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets; std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets;
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ ) for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
{ {
@ -1082,14 +983,10 @@ int main( int /*argc*/, char ** /*argv*/ )
// create the ray-tracing shader modules // create the ray-tracing shader modules
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule raygenShaderModule = vk::raii::ShaderModule raygenShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eRaygenNV, raygenShaderText );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eRaygenNV, raygenShaderText ); vk::raii::ShaderModule missShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eMissNV, missShaderText );
vk::raii::ShaderModule missShaderModule = vk::raii::ShaderModule shadowMissShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eMissNV, shadowMissShaderText );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eMissNV, missShaderText ); vk::raii::ShaderModule closestHitShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eClosestHitNV, closestHitShaderText );
vk::raii::ShaderModule shadowMissShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eMissNV, shadowMissShaderText );
vk::raii::ShaderModule closestHitShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eClosestHitNV, closestHitShaderText );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
// create the ray tracing pipeline // create the ray tracing pipeline
@ -1097,42 +994,28 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::RayTracingShaderGroupCreateInfoNV> shaderGroups; std::vector<vk::RayTracingShaderGroupCreateInfoNV> shaderGroups;
// We use only one ray generation, that will implement the camera model // We use only one ray generation, that will implement the camera model
shaderStages.emplace_back( shaderStages.emplace_back( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eRaygenNV, *raygenShaderModule, "main" );
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eRaygenNV, *raygenShaderModule, "main" ); shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eGeneral, 0, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
shaderGroups.emplace_back(
vk::RayTracingShaderGroupTypeNV::eGeneral, 0, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
// The first miss shader is used to look-up the environment in case the rays from the camera miss the geometry // The first miss shader is used to look-up the environment in case the rays from the camera miss the geometry
shaderStages.emplace_back( shaderStages.emplace_back( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eMissNV, *missShaderModule, "main" );
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eMissNV, *missShaderModule, "main" ); shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eGeneral, 1, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
shaderGroups.emplace_back(
vk::RayTracingShaderGroupTypeNV::eGeneral, 1, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
// The second miss shader is invoked when a shadow ray misses the geometry. It simply indicates that no occlusion // The second miss shader is invoked when a shadow ray misses the geometry. It simply indicates that no occlusion
// has been found // has been found
shaderStages.emplace_back( shaderStages.emplace_back( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eMissNV, *shadowMissShaderModule, "main" );
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eMissNV, *shadowMissShaderModule, "main" ); shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eGeneral, 2, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
shaderGroups.emplace_back(
vk::RayTracingShaderGroupTypeNV::eGeneral, 2, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
// The first hit group defines the shaders invoked when a ray shot from the camera hit the geometry. In this case we // The first hit group defines the shaders invoked when a ray shot from the camera hit the geometry. In this case we
// only specify the closest hit shader, and rely on the build-in triangle intersection and pass-through any-hit // only specify the closest hit shader, and rely on the build-in triangle intersection and pass-through any-hit
// shader. However, explicit intersection and any hit shaders could be added as well. // shader. However, explicit intersection and any hit shaders could be added as well.
shaderStages.emplace_back( shaderStages.emplace_back( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eClosestHitNV, *closestHitShaderModule, "main" );
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eClosestHitNV, *closestHitShaderModule, "main" ); shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup, VK_SHADER_UNUSED_NV, 3, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup,
VK_SHADER_UNUSED_NV,
3,
VK_SHADER_UNUSED_NV,
VK_SHADER_UNUSED_NV );
// The second hit group defines the shaders invoked when a shadow ray hits the geometry. For simple shadows we do // The second hit group defines the shaders invoked when a shadow ray hits the geometry. For simple shadows we do
// not need any shader in that group: we will rely on initializing the payload and update it only in the miss shader // not need any shader in that group: we will rely on initializing the payload and update it only in the miss shader
shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup, shaderGroups.emplace_back(
VK_SHADER_UNUSED_NV, vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
VK_SHADER_UNUSED_NV,
VK_SHADER_UNUSED_NV,
VK_SHADER_UNUSED_NV );
// Create the layout of the pipeline following the provided descriptor set layout // Create the layout of the pipeline following the provided descriptor set layout
vk::raii::PipelineLayout rayTracingPipelineLayout( device, { {}, *rayTracingDescriptorSetLayout } ); vk::raii::PipelineLayout rayTracingPipelineLayout( device, { {}, *rayTracingDescriptorSetLayout } );
@ -1143,9 +1026,8 @@ int main( int /*argc*/, char ** /*argv*/ )
// as possible for performance reasons. Even recursive ray tracing should be flattened into a loop // as possible for performance reasons. Even recursive ray tracing should be flattened into a loop
// in the ray generation to avoid deep recursion. // in the ray generation to avoid deep recursion.
uint32_t maxRecursionDepth = 2; uint32_t maxRecursionDepth = 2;
vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo( vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo( {}, shaderStages, shaderGroups, maxRecursionDepth, *rayTracingPipelineLayout );
{}, shaderStages, shaderGroups, maxRecursionDepth, *rayTracingPipelineLayout ); vk::raii::Pipeline rayTracingPipeline( device, nullptr, rayTracingPipelineCreateInfo );
vk::raii::Pipeline rayTracingPipeline( device, nullptr, rayTracingPipelineCreateInfo );
switch ( rayTracingPipeline.getConstructorSuccessCode() ) switch ( rayTracingPipeline.getConstructorSuccessCode() )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
@ -1157,21 +1039,17 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV> propertiesChain = vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV> propertiesChain =
physicalDevice.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV>(); physicalDevice.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV>();
uint32_t shaderGroupBaseAlignment = uint32_t shaderGroupBaseAlignment = propertiesChain.get<vk::PhysicalDeviceRayTracingPropertiesNV>().shaderGroupBaseAlignment;
propertiesChain.get<vk::PhysicalDeviceRayTracingPropertiesNV>().shaderGroupBaseAlignment; uint32_t shaderGroupHandleSize = propertiesChain.get<vk::PhysicalDeviceRayTracingPropertiesNV>().shaderGroupHandleSize;
uint32_t shaderGroupHandleSize =
propertiesChain.get<vk::PhysicalDeviceRayTracingPropertiesNV>().shaderGroupHandleSize;
uint32_t raygenShaderBindingOffset = 0; // starting with raygen uint32_t raygenShaderBindingOffset = 0; // starting with raygen
uint32_t raygenShaderTableSize = shaderGroupHandleSize; // one raygen shader uint32_t raygenShaderTableSize = shaderGroupHandleSize; // one raygen shader
uint32_t missShaderBindingOffset = uint32_t missShaderBindingOffset = raygenShaderBindingOffset + roundUp( raygenShaderTableSize, shaderGroupBaseAlignment );
raygenShaderBindingOffset + roundUp( raygenShaderTableSize, shaderGroupBaseAlignment ); uint32_t missShaderBindingStride = shaderGroupHandleSize;
uint32_t missShaderBindingStride = shaderGroupHandleSize; uint32_t missShaderTableSize = 2 * missShaderBindingStride; // two raygen shaders
uint32_t missShaderTableSize = 2 * missShaderBindingStride; // two raygen shaders uint32_t hitShaderBindingOffset = missShaderBindingOffset + roundUp( missShaderTableSize, shaderGroupBaseAlignment );
uint32_t hitShaderBindingOffset = uint32_t hitShaderBindingStride = shaderGroupHandleSize;
missShaderBindingOffset + roundUp( missShaderTableSize, shaderGroupBaseAlignment ); uint32_t hitShaderTableSize = 2 * hitShaderBindingStride; // two hit shaders
uint32_t hitShaderBindingStride = shaderGroupHandleSize;
uint32_t hitShaderTableSize = 2 * hitShaderBindingStride; // two hit shaders
uint32_t shaderBindingTableSize = hitShaderBindingOffset + hitShaderTableSize; uint32_t shaderBindingTableSize = hitShaderBindingOffset + hitShaderTableSize;
std::vector<uint8_t> shaderHandleStorage( shaderBindingTableSize ); std::vector<uint8_t> shaderHandleStorage( shaderBindingTableSize );
@ -1186,11 +1064,8 @@ int main( int /*argc*/, char ** /*argv*/ )
hitShaderTableSize ); hitShaderTableSize );
assert( shaderHandleStorage.size() == shaderBindingTableSize ); assert( shaderHandleStorage.size() == shaderBindingTableSize );
vk::raii::su::BufferData shaderBindingTableBufferData( physicalDevice, vk::raii::su::BufferData shaderBindingTableBufferData(
device, physicalDevice, device, shaderBindingTableSize, vk::BufferUsageFlagBits::eTransferDst, vk::MemoryPropertyFlagBits::eHostVisible );
shaderBindingTableSize,
vk::BufferUsageFlagBits::eTransferDst,
vk::MemoryPropertyFlagBits::eHostVisible );
shaderBindingTableBufferData.upload( shaderHandleStorage ); shaderBindingTableBufferData.upload( shaderHandleStorage );
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
@ -1219,38 +1094,32 @@ int main( int /*argc*/, char ** /*argv*/ )
windowExtent.width = w; windowExtent.width = w;
windowExtent.height = h; windowExtent.height = h;
device.waitIdle(); device.waitIdle();
swapChainData = swapChainData = vk::raii::su::SwapChainData( physicalDevice,
vk::raii::su::SwapChainData( physicalDevice, device,
device, surface,
surface, windowExtent,
windowExtent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage, &swapChainData.swapChain,
&swapChainData.swapChain, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second );
graphicsAndPresentQueueFamilyIndex.second ); depthBufferData = vk::raii::su::DepthBufferData( physicalDevice, device, vk::su::pickDepthFormat( *physicalDevice ), windowExtent );
depthBufferData = vk::raii::su::DepthBufferData(
physicalDevice, device, vk::su::pickDepthFormat( *physicalDevice ), windowExtent );
vk::raii::su::oneTimeSubmit( commandBuffer, vk::raii::su::oneTimeSubmit(
graphicsQueue, commandBuffer,
[&]( vk::raii::CommandBuffer const & commandBuffer ) graphicsQueue,
{ [&]( vk::raii::CommandBuffer const & commandBuffer )
vk::raii::su::setImageLayout( commandBuffer, {
*depthBufferData.image, vk::raii::su::setImageLayout(
depthFormat, commandBuffer, *depthBufferData.image, depthFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilAttachmentOptimal );
vk::ImageLayout::eUndefined, } );
vk::ImageLayout::eDepthStencilAttachmentOptimal );
} );
framebuffers = vk::raii::su::makeFramebuffers( framebuffers = vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, windowExtent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, windowExtent );
} }
// update the uniformBufferObject // update the uniformBufferObject
assert( 0 < windowExtent.height ); assert( 0 < windowExtent.height );
uniformBufferObject.view = appInfo.cameraManipulator.getMatrix(); uniformBufferObject.view = appInfo.cameraManipulator.getMatrix();
uniformBufferObject.proj = glm::perspective( uniformBufferObject.proj = glm::perspective( glm::radians( 65.0f ), windowExtent.width / static_cast<float>( windowExtent.height ), 0.1f, 1000.0f );
glm::radians( 65.0f ), windowExtent.width / static_cast<float>( windowExtent.height ), 0.1f, 1000.0f );
uniformBufferObject.proj[1][1] *= -1; // Inverting Y for Vulkan uniformBufferObject.proj[1][1] *= -1; // Inverting Y for Vulkan
uniformBufferObject.viewInverse = glm::inverse( uniformBufferObject.view ); uniformBufferObject.viewInverse = glm::inverse( uniformBufferObject.view );
uniformBufferObject.projInverse = glm::inverse( uniformBufferObject.proj ); uniformBufferObject.projInverse = glm::inverse( uniformBufferObject.proj );
@ -1259,12 +1128,11 @@ int main( int /*argc*/, char ** /*argv*/ )
// frame begin // frame begin
vk::Result result; vk::Result result;
uint32_t backBufferIndex; uint32_t backBufferIndex;
std::tie( result, backBufferIndex ) = swapChainData.swapChain.acquireNextImage( std::tie( result, backBufferIndex ) =
vk::su::FenceTimeout, *perFrameData[frameIndex].presentCompleteSemaphore ); swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *perFrameData[frameIndex].presentCompleteSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
while ( vk::Result::eTimeout == while ( vk::Result::eTimeout == device.waitForFences( { *perFrameData[frameIndex].fence }, VK_TRUE, vk::su::FenceTimeout ) )
device.waitForFences( { *perFrameData[frameIndex].fence }, VK_TRUE, vk::su::FenceTimeout ) )
; ;
device.resetFences( { *perFrameData[frameIndex].fence } ); device.resetFences( { *perFrameData[frameIndex].fence } );
@ -1277,16 +1145,10 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( windowExtent.width ), static_cast<float>( windowExtent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( windowExtent.width ),
static_cast<float>( windowExtent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ) );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
@ -1297,10 +1159,8 @@ int main( int /*argc*/, char ** /*argv*/ )
} }
else else
{ {
vk::DescriptorImageInfo imageInfo( vk::DescriptorImageInfo imageInfo( nullptr, *swapChainData.imageViews[backBufferIndex], vk::ImageLayout::eGeneral );
nullptr, *swapChainData.imageViews[backBufferIndex], vk::ImageLayout::eGeneral ); vk::WriteDescriptorSet writeDescriptorSet( *rayTracingDescriptorSets[backBufferIndex], 1, 0, bindings[1].descriptorType, imageInfo );
vk::WriteDescriptorSet writeDescriptorSet(
*rayTracingDescriptorSets[backBufferIndex], 1, 0, bindings[1].descriptorType, imageInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr ); device.updateDescriptorSets( writeDescriptorSet, nullptr );
vk::raii::su::setImageLayout( commandBuffer, vk::raii::su::setImageLayout( commandBuffer,
@ -1311,11 +1171,8 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.bindPipeline( vk::PipelineBindPoint::eRayTracingNV, *rayTracingPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eRayTracingNV, *rayTracingPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eRayTracingNV, commandBuffer.bindDescriptorSets(
*rayTracingPipelineLayout, vk::PipelineBindPoint::eRayTracingNV, *rayTracingPipelineLayout, 0, { *rayTracingDescriptorSets[backBufferIndex] }, nullptr );
0,
{ *rayTracingDescriptorSets[backBufferIndex] },
nullptr );
commandBuffer.traceRaysNV( *shaderBindingTableBufferData.buffer, commandBuffer.traceRaysNV( *shaderBindingTableBufferData.buffer,
raygenShaderBindingOffset, raygenShaderBindingOffset,
@ -1350,15 +1207,12 @@ int main( int /*argc*/, char ** /*argv*/ )
1, 1,
&*perFrameData[frameIndex].renderCompleteSemaphore ); &*perFrameData[frameIndex].renderCompleteSemaphore );
graphicsQueue.submit( submitInfo, *perFrameData[frameIndex].fence ); graphicsQueue.submit( submitInfo, *perFrameData[frameIndex].fence );
vk::PresentInfoKHR presentInfoKHR( vk::PresentInfoKHR presentInfoKHR( *perFrameData[frameIndex].renderCompleteSemaphore, *swapChainData.swapChain, backBufferIndex );
*perFrameData[frameIndex].renderCompleteSemaphore, *swapChainData.swapChain, backBufferIndex );
result = presentQueue.presentKHR( presentInfoKHR ); result = presentQueue.presentKHR( presentInfoKHR );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
frameIndex = ( frameIndex + 1 ) % IMGUI_VK_QUEUED_FRAMES; frameIndex = ( frameIndex + 1 ) % IMGUI_VK_QUEUED_FRAMES;
@ -1371,9 +1225,8 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( 0 < frameCount ); assert( 0 < frameCount );
std::ostringstream oss; std::ostringstream oss;
oss << AppName << ": " << vertices.size() << " Vertices " oss << AppName << ": " << vertices.size() << " Vertices " << ( appInfo.useRasterRender ? "Rastering" : "RayTracing" ) << " ( "
<< ( appInfo.useRasterRender ? "Rastering" : "RayTracing" ) << " ( " << frameCount / accumulatedTime << frameCount / accumulatedTime << " fps)";
<< " fps)";
glfwSetWindowTitle( window, oss.str().c_str() ); glfwSetWindowTitle( window, oss.str().c_str() );
accumulatedTime = 0.0; accumulatedTime = 0.0;

View File

@ -43,8 +43,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -54,11 +53,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -68,62 +66,51 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, vk::raii::su::makeDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass =
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format, vk::AttachmentLoadOp::eClear, vk::ImageLayout::eColorAttachmentOptimal );
colorFormat,
depthBufferData.format,
vk::AttachmentLoadOp::eClear,
vk::ImageLayout::eColorAttachmentOptimal );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
vk::raii::su::makeGraphicsPipeline( device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
@ -134,22 +121,17 @@ int main( int /*argc*/, char ** /*argv*/ )
checkeredTextureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() ); checkeredTextureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
// create two identical descriptor sets, each with a different texture but identical UBOs // create two identical descriptor sets, each with a different texture but identical UBOs
vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( vk::raii::DescriptorPool descriptorPool =
device, { { vk::DescriptorType::eUniformBuffer, 2 }, { vk::DescriptorType::eCombinedImageSampler, 2 } } ); vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 2 }, { vk::DescriptorType::eCombinedImageSampler, 2 } } );
std::array<vk::DescriptorSetLayout, 2> layouts = { *descriptorSetLayout, *descriptorSetLayout }; std::array<vk::DescriptorSetLayout, 2> layouts = { *descriptorSetLayout, *descriptorSetLayout };
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, layouts ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, layouts );
vk::raii::DescriptorSets descriptorSets( device, descriptorSetAllocateInfo ); vk::raii::DescriptorSets descriptorSets( device, descriptorSetAllocateInfo );
assert( descriptorSets.size() == 2 ); assert( descriptorSets.size() == 2 );
vk::raii::su::updateDescriptorSets( device, vk::raii::su::updateDescriptorSets( device, descriptorSets[0], { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, greenTextureData );
descriptorSets[0], vk::raii::su::updateDescriptorSets(
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, device, descriptorSets[1], { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, checkeredTextureData );
greenTextureData );
vk::raii::su::updateDescriptorSets( device,
descriptorSets[1],
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
checkeredTextureData );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -161,8 +143,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -178,8 +159,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// now we record four separate command buffers, one for each quadrant of the screen // now we record four separate command buffers, one for each quadrant of the screen
vk::CommandBufferInheritanceInfo commandBufferInheritanceInfo( *renderPass, 0, *framebuffers[imageIndex] ); vk::CommandBufferInheritanceInfo commandBufferInheritanceInfo( *renderPass, 0, *framebuffers[imageIndex] );
vk::CommandBufferBeginInfo secondaryBeginInfo( vk::CommandBufferUsageFlagBits::eOneTimeSubmit | vk::CommandBufferBeginInfo secondaryBeginInfo( vk::CommandBufferUsageFlagBits::eOneTimeSubmit | vk::CommandBufferUsageFlagBits::eRenderPassContinue,
vk::CommandBufferUsageFlagBits::eRenderPassContinue,
&commandBufferInheritanceInfo ); &commandBufferInheritanceInfo );
std::array<vk::CommandBuffer, 4> executeCommandBuffers; std::array<vk::CommandBuffer, 4> executeCommandBuffers;
@ -190,8 +170,7 @@ int main( int /*argc*/, char ** /*argv*/ )
secondaryCommandBuffers[i].begin( secondaryBeginInfo ); secondaryCommandBuffers[i].begin( secondaryBeginInfo );
secondaryCommandBuffers[i].bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); secondaryCommandBuffers[i].bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
secondaryCommandBuffers[i].bindDescriptorSets( secondaryCommandBuffers[i].bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSets[i == 0 || i == 3] }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSets[i == 0 || i == 3] }, nullptr );
secondaryCommandBuffers[i].bindVertexBuffers( 0, { *vertexBufferData.buffer }, offset ); secondaryCommandBuffers[i].bindVertexBuffers( 0, { *vertexBufferData.buffer }, offset );
secondaryCommandBuffers[i].setViewport( 0, viewport ); secondaryCommandBuffers[i].setViewport( 0, viewport );
secondaryCommandBuffers[i].setScissor( 0, scissor ); secondaryCommandBuffers[i].setScissor( 0, scissor );
@ -204,8 +183,7 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
// specifying VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS means this render pass may ONLY call // specifying VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS means this render pass may ONLY call
// vkCmdExecuteCommands // vkCmdExecuteCommands
@ -222,12 +200,8 @@ int main( int /*argc*/, char ** /*argv*/ )
VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED,
static_cast<vk::Image>( swapChainData.images[imageIndex] ), static_cast<vk::Image>( swapChainData.images[imageIndex] ),
imageSubresourceRange ); imageSubresourceRange );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eColorAttachmentOutput, commandBuffer.pipelineBarrier(
vk::PipelineStageFlagBits::eBottomOfPipe, vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eBottomOfPipe, vk::DependencyFlags(), nullptr, nullptr, prePresentBarrier );
vk::DependencyFlags(),
nullptr,
nullptr,
prePresentBarrier );
commandBuffer.end(); commandBuffer.end();
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() ); vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
@ -243,9 +217,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -71,8 +71,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -82,11 +81,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -96,37 +94,30 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderTextTS_T_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderTextTS_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -171,54 +162,46 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, pipelineLayoutCreateInfo ); vk::raii::PipelineLayout pipelineLayout( device, pipelineLayoutCreateInfo );
// Create a single pool to contain data for the descriptor set // Create a single pool to contain data for the descriptor set
std::array<vk::DescriptorPoolSize, 3> poolSizes = { std::array<vk::DescriptorPoolSize, 3> poolSizes = { { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
{ vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), vk::DescriptorPoolSize( vk::DescriptorType::eSampledImage, 1 ),
vk::DescriptorPoolSize( vk::DescriptorType::eSampledImage, 1 ), vk::DescriptorPoolSize( vk::DescriptorType::eSampler, 1 ) } };
vk::DescriptorPoolSize( vk::DescriptorType::eSampler, 1 ) } vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
}; vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// Populate descriptor sets // Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet = vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo( vk::DescriptorImageInfo imageInfo( *textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::DescriptorImageInfo samplerInfo( *sampler, {}, {} ); vk::DescriptorImageInfo samplerInfo( *sampler, {}, {} );
std::array<vk::WriteDescriptorSet, 3> descriptorWrites = { std::array<vk::WriteDescriptorSet, 3> descriptorWrites = { { vk::WriteDescriptorSet(
{ vk::WriteDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ), *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( *descriptorSet, 1, 0, vk::DescriptorType::eSampledImage, imageInfo ), vk::WriteDescriptorSet( *descriptorSet, 1, 0, vk::DescriptorType::eSampledImage, imageInfo ),
vk::WriteDescriptorSet( *descriptorSet, 2, 0, vk::DescriptorType::eSampler, samplerInfo ) } vk::WriteDescriptorSet( *descriptorSet, 2, 0, vk::DescriptorType::eSampler, samplerInfo ) } };
};
device.updateDescriptorSets( descriptorWrites, nullptr ); device.updateDescriptorSets( descriptorWrites, nullptr );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
vk::raii::su::makeGraphicsPipeline( device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -226,22 +209,15 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -262,9 +238,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -29,8 +29,7 @@ void cout( vk::SurfaceCapabilitiesKHR const & surfaceCapabilities )
{ {
std::cout << "\tCapabilities:\n"; std::cout << "\tCapabilities:\n";
std::cout << "\t\t" std::cout << "\t\t"
<< "currentExtent = " << surfaceCapabilities.currentExtent.width << " x " << "currentExtent = " << surfaceCapabilities.currentExtent.width << " x " << surfaceCapabilities.currentExtent.height << "\n";
<< surfaceCapabilities.currentExtent.height << "\n";
std::cout << "\t\t" std::cout << "\t\t"
<< "currentTransform = " << vk::to_string( surfaceCapabilities.currentTransform ) << "\n"; << "currentTransform = " << vk::to_string( surfaceCapabilities.currentTransform ) << "\n";
std::cout << "\t\t" std::cout << "\t\t"
@ -38,13 +37,11 @@ void cout( vk::SurfaceCapabilitiesKHR const & surfaceCapabilities )
std::cout << "\t\t" std::cout << "\t\t"
<< "maxImageCount = " << surfaceCapabilities.maxImageCount << "\n"; << "maxImageCount = " << surfaceCapabilities.maxImageCount << "\n";
std::cout << "\t\t" std::cout << "\t\t"
<< "maxImageExtent = " << surfaceCapabilities.maxImageExtent.width << " x " << "maxImageExtent = " << surfaceCapabilities.maxImageExtent.width << " x " << surfaceCapabilities.maxImageExtent.height << "\n";
<< surfaceCapabilities.maxImageExtent.height << "\n";
std::cout << "\t\t" std::cout << "\t\t"
<< "minImageCount = " << surfaceCapabilities.minImageCount << "\n"; << "minImageCount = " << surfaceCapabilities.minImageCount << "\n";
std::cout << "\t\t" std::cout << "\t\t"
<< "minImageExtent = " << surfaceCapabilities.minImageExtent.width << " x " << "minImageExtent = " << surfaceCapabilities.minImageExtent.width << " x " << surfaceCapabilities.minImageExtent.height << "\n";
<< surfaceCapabilities.minImageExtent.height << "\n";
std::cout << "\t\t" std::cout << "\t\t"
<< "supportedCompositeAlpha = " << vk::to_string( surfaceCapabilities.supportedCompositeAlpha ) << "\n"; << "supportedCompositeAlpha = " << vk::to_string( surfaceCapabilities.supportedCompositeAlpha ) << "\n";
std::cout << "\t\t" std::cout << "\t\t"
@ -60,13 +57,12 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::raii::Context context; vk::raii::Context context;
std::vector<vk::ExtensionProperties> instanceExtensionProperties = context.enumerateInstanceExtensionProperties(); std::vector<vk::ExtensionProperties> instanceExtensionProperties = context.enumerateInstanceExtensionProperties();
bool supportsGetSurfaceCapabilities2 = bool supportsGetSurfaceCapabilities2 = ( std::find_if( instanceExtensionProperties.begin(),
( std::find_if( instanceExtensionProperties.begin(), instanceExtensionProperties.end(),
instanceExtensionProperties.end(), []( vk::ExtensionProperties const & ep ) {
[]( vk::ExtensionProperties const & ep ) { return strcmp( ep.extensionName, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME ) == 0;
return strcmp( ep.extensionName, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME ) == 0; } ) != instanceExtensionProperties.end() );
} ) != instanceExtensionProperties.end() );
std::vector<std::string> extensions = vk::su::getInstanceExtensions(); std::vector<std::string> extensions = vk::su::getInstanceExtensions();
if ( supportsGetSurfaceCapabilities2 ) if ( supportsGetSurfaceCapabilities2 )
@ -90,22 +86,19 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ ) for ( size_t i = 0; i < physicalDevices.size(); i++ )
{ {
// some properties are only valid, if a corresponding extension is available! // some properties are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties = std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << "\n"; std::cout << "PhysicalDevice " << i << "\n";
if ( supportsGetSurfaceCapabilities2 ) if ( supportsGetSurfaceCapabilities2 )
{ {
auto surfaceCapabilities2 = auto surfaceCapabilities2 = physicalDevices[i]
physicalDevices[i] .getSurfaceCapabilities2KHR<vk::SurfaceCapabilities2KHR,
.getSurfaceCapabilities2KHR<vk::SurfaceCapabilities2KHR, vk::DisplayNativeHdrSurfaceCapabilitiesAMD,
vk::DisplayNativeHdrSurfaceCapabilitiesAMD, vk::SharedPresentSurfaceCapabilitiesKHR,
vk::SharedPresentSurfaceCapabilitiesKHR, vk::SurfaceCapabilitiesFullScreenExclusiveEXT,
vk::SurfaceCapabilitiesFullScreenExclusiveEXT, vk::SurfaceProtectedCapabilitiesKHR>( { *surfaceData.surface } );
vk::SurfaceProtectedCapabilitiesKHR>( { *surfaceData.surface } );
vk::SurfaceCapabilitiesKHR const & surfaceCapabilities = vk::SurfaceCapabilitiesKHR const & surfaceCapabilities = surfaceCapabilities2.get<vk::SurfaceCapabilities2KHR>().surfaceCapabilities;
surfaceCapabilities2.get<vk::SurfaceCapabilities2KHR>().surfaceCapabilities;
cout( surfaceCapabilities ); cout( surfaceCapabilities );
if ( vk::su::contains( extensionProperties, "VK_AMD_display_native_hdr" ) ) if ( vk::su::contains( extensionProperties, "VK_AMD_display_native_hdr" ) )
@ -120,12 +113,10 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_KHR_shared_presentable_image" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_shared_presentable_image" ) )
{ {
vk::SharedPresentSurfaceCapabilitiesKHR sharedPresentSurfaceCapabilities = vk::SharedPresentSurfaceCapabilitiesKHR sharedPresentSurfaceCapabilities = surfaceCapabilities2.get<vk::SharedPresentSurfaceCapabilitiesKHR>();
surfaceCapabilities2.get<vk::SharedPresentSurfaceCapabilitiesKHR>();
std::cout << "\tSharedPresentSurfaceCapabilitiesKHR:\n"; std::cout << "\tSharedPresentSurfaceCapabilitiesKHR:\n";
std::cout << "\t\t" std::cout << "\t\t"
<< "sharedPresentSupportedUsageFlags = " << "sharedPresentSupportedUsageFlags = " << vk::to_string( sharedPresentSurfaceCapabilities.sharedPresentSupportedUsageFlags ) << "\n";
<< vk::to_string( sharedPresentSurfaceCapabilities.sharedPresentSupportedUsageFlags ) << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -135,15 +126,13 @@ int main( int /*argc*/, char ** /*argv*/ )
surfaceCapabilities2.get<vk::SurfaceCapabilitiesFullScreenExclusiveEXT>(); surfaceCapabilities2.get<vk::SurfaceCapabilitiesFullScreenExclusiveEXT>();
std::cout << "\tSurfaceCapabilitiesFullScreenExclusiveEXT:\n"; std::cout << "\tSurfaceCapabilitiesFullScreenExclusiveEXT:\n";
std::cout << "\t\t" std::cout << "\t\t"
<< "fullScreenExclusiveSupported = " << "fullScreenExclusiveSupported = " << !!surfaceCapabilitiesFullScreenExclusive.fullScreenExclusiveSupported << "\n";
<< !!surfaceCapabilitiesFullScreenExclusive.fullScreenExclusiveSupported << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_KHR_surface_protected_capabilities" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_surface_protected_capabilities" ) )
{ {
vk::SurfaceProtectedCapabilitiesKHR surfaceProtectedCapabilities = vk::SurfaceProtectedCapabilitiesKHR surfaceProtectedCapabilities = surfaceCapabilities2.get<vk::SurfaceProtectedCapabilitiesKHR>();
surfaceCapabilities2.get<vk::SurfaceProtectedCapabilitiesKHR>();
std::cout << "\tSurfaceProtectedCapabilitiesKHR:\n"; std::cout << "\tSurfaceProtectedCapabilitiesKHR:\n";
std::cout << "\t\t" std::cout << "\t\t"
<< "supportsProtected = " << !!surfaceProtectedCapabilities.supportsProtected << "\n"; << "supportsProtected = " << !!surfaceProtectedCapabilities.supportsProtected << "\n";
@ -152,8 +141,7 @@ int main( int /*argc*/, char ** /*argv*/ )
} }
else else
{ {
vk::SurfaceCapabilitiesKHR surfaceCapabilities = vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevices[i].getSurfaceCapabilitiesKHR( *surfaceData.surface );
physicalDevices[i].getSurfaceCapabilitiesKHR( *surfaceData.surface );
cout( surfaceCapabilities ); cout( surfaceCapabilities );
} }
} }

View File

@ -29,9 +29,8 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -47,8 +46,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ ) for ( size_t i = 0; i < physicalDevices.size(); i++ )
{ {
std::cout << "PhysicalDevice " << i << "\n"; std::cout << "PhysicalDevice " << i << "\n";
std::vector<vk::SurfaceFormatKHR> surfaceFormats = std::vector<vk::SurfaceFormatKHR> surfaceFormats = physicalDevices[i].getSurfaceFormatsKHR( *surfaceData.surface );
physicalDevices[i].getSurfaceFormatsKHR( *surfaceData.surface );
for ( size_t j = 0; j < surfaceFormats.size(); j++ ) for ( size_t j = 0; j < surfaceFormats.size(); j++ )
{ {
std::cout << "\tFormat " << j << "\n"; std::cout << "\tFormat " << j << "\n";

View File

@ -33,8 +33,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -44,11 +43,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -58,8 +56,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -71,89 +68,70 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() ); textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::raii::su::BufferData uniformBufferData( vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix ); vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, vk::raii::su::makeDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers( std::vector<vk::raii::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData( vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( vk::raii::DescriptorPool descriptorPool =
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::raii::DescriptorSet descriptorSet = vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets( device, vk::raii::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, { textureData } );
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } },
{ textureData } );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
vk::raii::su::makeGraphicsPipeline( device, pipelineCache,
pipelineCache, vertexShaderModule,
vertexShaderModule, nullptr,
nullptr, fragmentShaderModule,
fragmentShaderModule, nullptr,
nullptr, sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } ); commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -174,9 +152,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -60,8 +60,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try try
{ {
vk::raii::Context context; vk::raii::Context context;
vk::raii::Instance instance = vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
@ -86,11 +85,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( vk::raii::CommandPool commandPool =
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } ); vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -100,61 +98,40 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::BufferData texelBufferData( vk::raii::su::BufferData texelBufferData( physicalDevice, device, sizeof( texels ), vk::BufferUsageFlagBits::eUniformTexelBuffer );
physicalDevice, device, sizeof( texels ), vk::BufferUsageFlagBits::eUniformTexelBuffer );
texelBufferData.upload( texels ); texelBufferData.upload( texels );
vk::BufferViewCreateInfo bufferViewCreateInfo( {}, *texelBufferData.buffer, texelFormat, 0, sizeof( texels ) ); vk::BufferViewCreateInfo bufferViewCreateInfo( {}, *texelBufferData.buffer, texelFormat, 0, sizeof( texels ) );
vk::raii::BufferView texelBufferView( device, bufferViewCreateInfo ); vk::raii::BufferView texelBufferView( device, bufferViewCreateInfo );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout( vk::raii::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformTexelBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::raii::su::makeDescriptorSetLayout( device, { { vk::DescriptorType::eUniformTexelBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } ); vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format; vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, vk::Format::eUndefined );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, vk::Format::eUndefined );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule = vk::raii::ShaderModule vertexShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText ); vk::raii::ShaderModule fragmentShaderModule = vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
vk::raii::ShaderModule fragmentShaderModule =
vk::raii::su::makeShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = std::vector<vk::raii::Framebuffer> framebuffers =
vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, nullptr, surfaceData.extent ); vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, nullptr, surfaceData.extent );
vk::raii::DescriptorPool descriptorPool = vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformTexelBuffer, 1 } } );
vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformTexelBuffer, 1 } } ); vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets( vk::raii::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformTexelBuffer, texelBufferData.buffer, &texelBufferView } }, {} );
device,
descriptorSet,
{ { vk::DescriptorType::eUniformTexelBuffer, texelBufferData.buffer, &texelBufferView } },
{} );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() ); vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device, vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline(
pipelineCache, device, pipelineCache, vertexShaderModule, nullptr, fragmentShaderModule, nullptr, 0, {}, vk::FrontFace::eClockwise, true, pipelineLayout, renderPass );
vertexShaderModule,
nullptr,
fragmentShaderModule,
nullptr,
0,
{},
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -162,8 +139,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() ); vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result; vk::Result result;
uint32_t imageIndex; uint32_t imageIndex;
std::tie( result, imageIndex ) = std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() ); assert( imageIndex < swapChainData.images.size() );
@ -171,21 +147,14 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ClearValue clearValue; vk::ClearValue clearValue;
clearValue.color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValue.color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
vk::RenderPassBeginInfo renderPassBeginInfo( vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValue );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValue );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 3, 1, 0, 0 ); commandBuffer.draw( 3, 1, 0, 0 );
@ -206,9 +175,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -23,9 +23,7 @@ namespace vk
namespace su namespace su
{ {
template <typename Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> template <typename Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
vk::raii::ShaderModule makeShaderModule( vk::raii::Device const & device, vk::raii::ShaderModule makeShaderModule( vk::raii::Device const & device, vk::ShaderStageFlagBits shaderStage, std::string const & shaderText )
vk::ShaderStageFlagBits shaderStage,
std::string const & shaderText )
{ {
std::vector<unsigned int> shaderSPV; std::vector<unsigned int> shaderSPV;
if ( !vk::su::GLSLtoSPV( shaderStage, shaderText, shaderSPV ) ) if ( !vk::su::GLSLtoSPV( shaderStage, shaderText, shaderSPV ) )

View File

@ -41,17 +41,13 @@ namespace vk
vk::MemoryRequirements const & memoryRequirements, vk::MemoryRequirements const & memoryRequirements,
vk::MemoryPropertyFlags memoryPropertyFlags ) vk::MemoryPropertyFlags memoryPropertyFlags )
{ {
uint32_t memoryTypeIndex = uint32_t memoryTypeIndex = vk::su::findMemoryType( memoryProperties, memoryRequirements.memoryTypeBits, memoryPropertyFlags );
vk::su::findMemoryType( memoryProperties, memoryRequirements.memoryTypeBits, memoryPropertyFlags );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ); vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
return vk::raii::DeviceMemory( device, memoryAllocateInfo ); return vk::raii::DeviceMemory( device, memoryAllocateInfo );
} }
template <typename T> template <typename T>
void copyToDevice( vk::raii::DeviceMemory const & deviceMemory, void copyToDevice( vk::raii::DeviceMemory const & deviceMemory, T const * pData, size_t count, vk::DeviceSize stride = sizeof( T ) )
T const * pData,
size_t count,
vk::DeviceSize stride = sizeof( T ) )
{ {
assert( sizeof( T ) <= stride ); assert( sizeof( T ) <= stride );
uint8_t * deviceData = static_cast<uint8_t *>( deviceMemory.mapMemory( 0, count * stride ) ); uint8_t * deviceData = static_cast<uint8_t *>( deviceMemory.mapMemory( 0, count * stride ) );
@ -87,8 +83,7 @@ namespace vk
} }
template <typename Func> template <typename Func>
void void oneTimeSubmit( vk::raii::CommandBuffer const & commandBuffer, vk::raii::Queue const & queue, Func const & func )
oneTimeSubmit( vk::raii::CommandBuffer const & commandBuffer, vk::raii::Queue const & queue, Func const & func )
{ {
commandBuffer.begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlagBits::eOneTimeSubmit ) ); commandBuffer.begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlagBits::eOneTimeSubmit ) );
func( commandBuffer ); func( commandBuffer );
@ -99,20 +94,14 @@ namespace vk
} }
template <typename Func> template <typename Func>
void oneTimeSubmit( vk::raii::Device const & device, void oneTimeSubmit( vk::raii::Device const & device, vk::raii::CommandPool const & commandPool, vk::raii::Queue const & queue, Func const & func )
vk::raii::CommandPool const & commandPool,
vk::raii::Queue const & queue,
Func const & func )
{ {
vk::raii::CommandBuffers commandBuffers( device, { *commandPool, vk::CommandBufferLevel::ePrimary, 1 } ); vk::raii::CommandBuffers commandBuffers( device, { *commandPool, vk::CommandBufferLevel::ePrimary, 1 } );
oneTimeSubmit( commandBuffers.front(), queue, func ); oneTimeSubmit( commandBuffers.front(), queue, func );
} }
void setImageLayout( vk::raii::CommandBuffer const & commandBuffer, void setImageLayout(
vk::Image image, vk::raii::CommandBuffer const & commandBuffer, vk::Image image, vk::Format format, vk::ImageLayout oldImageLayout, vk::ImageLayout newImageLayout )
vk::Format format,
vk::ImageLayout oldImageLayout,
vk::ImageLayout newImageLayout )
{ {
vk::AccessFlags sourceAccessMask; vk::AccessFlags sourceAccessMask;
switch ( oldImageLayout ) switch ( oldImageLayout )
@ -137,12 +126,9 @@ namespace vk
vk::AccessFlags destinationAccessMask; vk::AccessFlags destinationAccessMask;
switch ( newImageLayout ) switch ( newImageLayout )
{ {
case vk::ImageLayout::eColorAttachmentOptimal: case vk::ImageLayout::eColorAttachmentOptimal: destinationAccessMask = vk::AccessFlagBits::eColorAttachmentWrite; break;
destinationAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
break;
case vk::ImageLayout::eDepthStencilAttachmentOptimal: case vk::ImageLayout::eDepthStencilAttachmentOptimal:
destinationAccessMask = destinationAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentRead | vk::AccessFlagBits::eDepthStencilAttachmentWrite;
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;
@ -155,17 +141,11 @@ namespace vk
vk::PipelineStageFlags destinationStage; vk::PipelineStageFlags destinationStage;
switch ( newImageLayout ) switch ( newImageLayout )
{ {
case vk::ImageLayout::eColorAttachmentOptimal: case vk::ImageLayout::eColorAttachmentOptimal: destinationStage = vk::PipelineStageFlagBits::eColorAttachmentOutput; break;
destinationStage = vk::PipelineStageFlagBits::eColorAttachmentOutput; case vk::ImageLayout::eDepthStencilAttachmentOptimal: destinationStage = vk::PipelineStageFlagBits::eEarlyFragmentTests; break;
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: case vk::ImageLayout::eShaderReadOnlyOptimal: destinationStage = vk::PipelineStageFlagBits::eFragmentShader; break;
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;
@ -203,11 +183,9 @@ namespace vk
vk::raii::Device const & device, vk::raii::Device const & device,
vk::DeviceSize size, vk::DeviceSize size,
vk::BufferUsageFlags usage, vk::BufferUsageFlags usage,
vk::MemoryPropertyFlags propertyFlags = vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlags propertyFlags = vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent )
vk::MemoryPropertyFlagBits::eHostCoherent )
: buffer( device, vk::BufferCreateInfo( {}, size, usage ) ) : buffer( device, vk::BufferCreateInfo( {}, size, usage ) )
, deviceMemory( vk::raii::su::allocateDeviceMemory( , deviceMemory( vk::raii::su::allocateDeviceMemory( device, physicalDevice.getMemoryProperties(), buffer.getMemoryRequirements(), propertyFlags ) )
device, physicalDevice.getMemoryProperties(), buffer.getMemoryRequirements(), propertyFlags ) )
#if !defined( NDEBUG ) #if !defined( NDEBUG )
, m_size( size ) , m_size( size )
, m_usage( usage ) , m_usage( usage )
@ -222,8 +200,7 @@ namespace vk
template <typename DataType> template <typename DataType>
void upload( DataType const & data ) const void upload( DataType const & data ) const
{ {
assert( ( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent ) && assert( ( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent ) && ( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible ) );
( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible ) );
assert( sizeof( DataType ) <= m_size ); assert( sizeof( DataType ) <= m_size );
void * dataPtr = deviceMemory.mapMemory( 0, sizeof( DataType ) ); void * dataPtr = deviceMemory.mapMemory( 0, sizeof( DataType ) );
@ -259,16 +236,14 @@ namespace vk
size_t dataSize = data.size() * elementSize; size_t dataSize = data.size() * elementSize;
assert( dataSize <= m_size ); assert( dataSize <= m_size );
vk::raii::su::BufferData stagingBuffer( vk::raii::su::BufferData stagingBuffer( physicalDevice, device, dataSize, vk::BufferUsageFlagBits::eTransferSrc );
physicalDevice, device, dataSize, vk::BufferUsageFlagBits::eTransferSrc );
copyToDevice( stagingBuffer.deviceMemory, data.data(), data.size(), elementSize ); copyToDevice( stagingBuffer.deviceMemory, data.data(), data.size(), elementSize );
vk::raii::su::oneTimeSubmit( vk::raii::su::oneTimeSubmit( device,
device, commandPool,
commandPool, queue,
queue, [&]( vk::raii::CommandBuffer const & commandBuffer )
[&]( vk::raii::CommandBuffer const & commandBuffer ) { commandBuffer.copyBuffer( *stagingBuffer.buffer, *this->buffer, vk::BufferCopy( 0, 0, dataSize ) ); } );
{ commandBuffer.copyBuffer( *stagingBuffer.buffer, *this->buffer, vk::BufferCopy( 0, 0, dataSize ) ); } );
} }
// the order of buffer and deviceMemory here is important to get the constructor running ! // the order of buffer and deviceMemory here is important to get the constructor running !
@ -307,13 +282,10 @@ namespace vk
vk::SharingMode::eExclusive, vk::SharingMode::eExclusive,
{}, {},
initialLayout } ) initialLayout } )
, deviceMemory( vk::raii::su::allocateDeviceMemory( , deviceMemory( vk::raii::su::allocateDeviceMemory( device, physicalDevice.getMemoryProperties(), image.getMemoryRequirements(), memoryProperties ) )
device, physicalDevice.getMemoryProperties(), image.getMemoryRequirements(), memoryProperties ) )
{ {
image.bindMemory( *deviceMemory, 0 ); image.bindMemory( *deviceMemory, 0 );
imageView = vk::raii::ImageView( imageView = vk::raii::ImageView( device, vk::ImageViewCreateInfo( {}, *image, vk::ImageViewType::e2D, format, {}, { aspectMask, 0, 1, 0, 1 } ) );
device,
vk::ImageViewCreateInfo( {}, *image, vk::ImageViewType::e2D, format, {}, { aspectMask, 0, 1, 0, 1 } ) );
} }
ImageData( std::nullptr_t ) {} ImageData( std::nullptr_t ) {}
@ -326,10 +298,7 @@ namespace vk
struct DepthBufferData : public ImageData struct DepthBufferData : public ImageData
{ {
DepthBufferData( vk::raii::PhysicalDevice const & physicalDevice, DepthBufferData( vk::raii::PhysicalDevice const & physicalDevice, vk::raii::Device const & device, vk::Format format, vk::Extent2D const & extent )
vk::raii::Device const & device,
vk::Format format,
vk::Extent2D const & extent )
: ImageData( physicalDevice, : ImageData( physicalDevice,
device, device,
format, format,
@ -348,8 +317,7 @@ namespace vk
: extent( extent_ ), window( vk::su::createWindow( windowName, extent ) ) : extent( extent_ ), window( vk::su::createWindow( windowName, extent ) )
{ {
VkSurfaceKHR _surface; VkSurfaceKHR _surface;
VkResult err = VkResult err = glfwCreateWindowSurface( static_cast<VkInstance>( *instance ), window.handle, nullptr, &_surface );
glfwCreateWindowSurface( static_cast<VkInstance>( *instance ), window.handle, nullptr, &_surface );
if ( err != VK_SUCCESS ) if ( err != VK_SUCCESS )
throw std::runtime_error( "Failed to create window!" ); throw std::runtime_error( "Failed to create window!" );
surface = vk::raii::SurfaceKHR( instance, _surface ); surface = vk::raii::SurfaceKHR( instance, _surface );
@ -371,39 +339,31 @@ namespace vk
uint32_t graphicsQueueFamilyIndex, uint32_t graphicsQueueFamilyIndex,
uint32_t presentQueueFamilyIndex ) uint32_t presentQueueFamilyIndex )
{ {
vk::SurfaceFormatKHR surfaceFormat = vk::SurfaceFormatKHR surfaceFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surface ) );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surface ) ); colorFormat = surfaceFormat.format;
colorFormat = surfaceFormat.format;
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( *surface ); vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( *surface );
vk::Extent2D swapchainExtent; vk::Extent2D swapchainExtent;
if ( surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max() ) if ( surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max() )
{ {
// If the surface size is undefined, the size is set to the size of the images requested. // If the surface size is undefined, the size is set to the size of the images requested.
swapchainExtent.width = vk::su::clamp( swapchainExtent.width = vk::su::clamp( extent.width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width );
extent.width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width ); swapchainExtent.height = vk::su::clamp( extent.height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height );
swapchainExtent.height = vk::su::clamp(
extent.height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height );
} }
else else
{ {
// If the surface size is defined, the swap chain size must match // If the surface size is defined, the swap chain size must match
swapchainExtent = surfaceCapabilities.currentExtent; swapchainExtent = surfaceCapabilities.currentExtent;
} }
vk::SurfaceTransformFlagBitsKHR preTransform = vk::SurfaceTransformFlagBitsKHR preTransform = ( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity )
( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity ) ? vk::SurfaceTransformFlagBitsKHR::eIdentity
? vk::SurfaceTransformFlagBitsKHR::eIdentity : surfaceCapabilities.currentTransform;
: surfaceCapabilities.currentTransform; vk::CompositeAlphaFlagBitsKHR compositeAlpha =
vk::CompositeAlphaFlagBitsKHR compositeAlpha = ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied
( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied
? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit ) ? vk::CompositeAlphaFlagBitsKHR::eInherit
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) : vk::CompositeAlphaFlagBitsKHR::eOpaque;
? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied vk::PresentModeKHR presentMode = vk::su::pickPresentMode( physicalDevice.getSurfacePresentModesKHR( *surface ) );
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit )
? vk::CompositeAlphaFlagBitsKHR::eInherit
: vk::CompositeAlphaFlagBitsKHR::eOpaque;
vk::PresentModeKHR presentMode =
vk::su::pickPresentMode( physicalDevice.getSurfacePresentModesKHR( *surface ) );
vk::SwapchainCreateInfoKHR swapChainCreateInfo( {}, vk::SwapchainCreateInfoKHR swapChainCreateInfo( {},
*surface, *surface,
surfaceCapabilities.minImageCount, surfaceCapabilities.minImageCount,
@ -434,8 +394,7 @@ namespace vk
images = swapChain.getImages(); images = swapChain.getImages();
imageViews.reserve( images.size() ); imageViews.reserve( images.size() );
vk::ImageViewCreateInfo imageViewCreateInfo( vk::ImageViewCreateInfo imageViewCreateInfo( {}, {}, vk::ImageViewType::e2D, colorFormat, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
{}, {}, vk::ImageViewType::e2D, colorFormat, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
for ( auto image : images ) for ( auto image : images )
{ {
imageViewCreateInfo.image = static_cast<vk::Image>( image ); imageViewCreateInfo.image = static_cast<vk::Image>( image );
@ -480,17 +439,15 @@ namespace vk
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( format ); vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( format );
formatFeatureFlags |= vk::FormatFeatureFlagBits::eSampledImage; formatFeatureFlags |= vk::FormatFeatureFlagBits::eSampledImage;
needsStaging = needsStaging = forceStaging || ( ( formatProperties.linearTilingFeatures & formatFeatureFlags ) != formatFeatureFlags );
forceStaging || ( ( formatProperties.linearTilingFeatures & formatFeatureFlags ) != formatFeatureFlags );
vk::ImageTiling imageTiling; vk::ImageTiling imageTiling;
vk::ImageLayout initialLayout; vk::ImageLayout initialLayout;
vk::MemoryPropertyFlags requirements; vk::MemoryPropertyFlags requirements;
if ( needsStaging ) if ( needsStaging )
{ {
assert( ( formatProperties.optimalTilingFeatures & formatFeatureFlags ) == formatFeatureFlags ); assert( ( formatProperties.optimalTilingFeatures & formatFeatureFlags ) == formatFeatureFlags );
stagingBufferData = BufferData( stagingBufferData = BufferData( physicalDevice, device, extent.width * extent.height * 4, vk::BufferUsageFlagBits::eTransferSrc );
physicalDevice, device, extent.width * extent.height * 4, vk::BufferUsageFlagBits::eTransferSrc ); imageTiling = vk::ImageTiling::eOptimal;
imageTiling = vk::ImageTiling::eOptimal;
usageFlags |= vk::ImageUsageFlagBits::eTransferDst; usageFlags |= vk::ImageUsageFlagBits::eTransferDst;
initialLayout = vk::ImageLayout::eUndefined; initialLayout = vk::ImageLayout::eUndefined;
} }
@ -514,44 +471,32 @@ namespace vk
template <typename ImageGenerator> template <typename ImageGenerator>
void setImage( vk::raii::CommandBuffer const & commandBuffer, ImageGenerator const & imageGenerator ) void setImage( vk::raii::CommandBuffer const & commandBuffer, ImageGenerator const & imageGenerator )
{ {
void * data = void * data = needsStaging ? stagingBufferData.deviceMemory.mapMemory( 0, stagingBufferData.buffer.getMemoryRequirements().size )
needsStaging : imageData.deviceMemory.mapMemory( 0, imageData.image.getMemoryRequirements().size );
? stagingBufferData.deviceMemory.mapMemory( 0, stagingBufferData.buffer.getMemoryRequirements().size )
: imageData.deviceMemory.mapMemory( 0, imageData.image.getMemoryRequirements().size );
imageGenerator( data, extent ); imageGenerator( data, extent );
needsStaging ? stagingBufferData.deviceMemory.unmapMemory() : imageData.deviceMemory.unmapMemory(); needsStaging ? stagingBufferData.deviceMemory.unmapMemory() : imageData.deviceMemory.unmapMemory();
if ( needsStaging ) if ( needsStaging )
{ {
// Since we're going to blit to the texture image, set its layout to eTransferDstOptimal // Since we're going to blit to the texture image, set its layout to eTransferDstOptimal
vk::raii::su::setImageLayout( commandBuffer, vk::raii::su::setImageLayout(
*imageData.image, commandBuffer, *imageData.image, imageData.format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
imageData.format,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eTransferDstOptimal );
vk::BufferImageCopy copyRegion( 0, vk::BufferImageCopy copyRegion( 0,
extent.width, extent.width,
extent.height, extent.height,
vk::ImageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 ), vk::ImageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 ),
vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 0, 0, 0 ),
vk::Extent3D( extent, 1 ) ); vk::Extent3D( extent, 1 ) );
commandBuffer.copyBufferToImage( commandBuffer.copyBufferToImage( *stagingBufferData.buffer, *imageData.image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
*stagingBufferData.buffer, *imageData.image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
// Set the layout for the texture image from eTransferDstOptimal to eShaderReadOnlyOptimal // Set the layout for the texture image from eTransferDstOptimal to eShaderReadOnlyOptimal
vk::raii::su::setImageLayout( commandBuffer, vk::raii::su::setImageLayout(
*imageData.image, commandBuffer, *imageData.image, imageData.format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
imageData.format,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eShaderReadOnlyOptimal );
} }
else else
{ {
// If we can use the linear tiled image as a texture, just do it // If we can use the linear tiled image as a texture, just do it
vk::raii::su::setImageLayout( commandBuffer, vk::raii::su::setImageLayout(
*imageData.image, commandBuffer, *imageData.image, imageData.format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal );
imageData.format,
vk::ImageLayout::ePreinitialized,
vk::ImageLayout::eShaderReadOnlyOptimal );
} }
} }
@ -563,9 +508,8 @@ namespace vk
vk::raii::Sampler sampler; vk::raii::Sampler sampler;
}; };
std::pair<uint32_t, uint32_t> std::pair<uint32_t, uint32_t> findGraphicsAndPresentQueueFamilyIndex( vk::raii::PhysicalDevice const & physicalDevice,
findGraphicsAndPresentQueueFamilyIndex( vk::raii::PhysicalDevice const & physicalDevice, vk::raii::SurfaceKHR const & surface )
vk::raii::SurfaceKHR const & surface )
{ {
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() );
@ -573,9 +517,8 @@ namespace vk
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( queueFamilyProperties ); uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( queueFamilyProperties );
if ( physicalDevice.getSurfaceSupportKHR( graphicsQueueFamilyIndex, *surface ) ) if ( physicalDevice.getSurfaceSupportKHR( graphicsQueueFamilyIndex, *surface ) )
{ {
return std::make_pair( return std::make_pair( graphicsQueueFamilyIndex,
graphicsQueueFamilyIndex, graphicsQueueFamilyIndex ); // the first graphicsQueueFamilyIndex does also support presents
graphicsQueueFamilyIndex ); // the first graphicsQueueFamilyIndex does also support presents
} }
// the graphicsQueueFamilyIndex doesn't support present -> look for an other family index that supports both // the graphicsQueueFamilyIndex doesn't support present -> look for an other family index that supports both
@ -602,41 +545,32 @@ namespace vk
throw std::runtime_error( "Could not find queues for both graphics or present -> terminating" ); throw std::runtime_error( "Could not find queues for both graphics or present -> terminating" );
} }
vk::raii::CommandBuffer makeCommandBuffer( vk::raii::Device const & device, vk::raii::CommandBuffer makeCommandBuffer( vk::raii::Device const & device, vk::raii::CommandPool const & commandPool )
vk::raii::CommandPool const & commandPool )
{ {
vk::CommandBufferAllocateInfo commandBufferAllocateInfo( *commandPool, vk::CommandBufferLevel::ePrimary, 1 ); vk::CommandBufferAllocateInfo commandBufferAllocateInfo( *commandPool, vk::CommandBufferLevel::ePrimary, 1 );
return std::move( vk::raii::CommandBuffers( device, commandBufferAllocateInfo ).front() ); return std::move( vk::raii::CommandBuffers( device, commandBufferAllocateInfo ).front() );
} }
vk::raii::DescriptorPool makeDescriptorPool( vk::raii::Device const & device, vk::raii::DescriptorPool makeDescriptorPool( vk::raii::Device const & device, std::vector<vk::DescriptorPoolSize> const & poolSizes )
std::vector<vk::DescriptorPoolSize> const & poolSizes )
{ {
assert( !poolSizes.empty() ); assert( !poolSizes.empty() );
uint32_t maxSets = std::accumulate( poolSizes.begin(), uint32_t maxSets = std::accumulate(
poolSizes.end(), poolSizes.begin(), poolSizes.end(), 0, []( uint32_t sum, vk::DescriptorPoolSize const & dps ) { return sum + dps.descriptorCount; } );
0,
[]( uint32_t sum, vk::DescriptorPoolSize const & dps )
{ return sum + dps.descriptorCount; } );
assert( 0 < maxSets ); assert( 0 < maxSets );
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, maxSets, poolSizes );
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, maxSets, poolSizes );
return vk::raii::DescriptorPool( device, descriptorPoolCreateInfo ); return vk::raii::DescriptorPool( device, descriptorPoolCreateInfo );
} }
vk::raii::DescriptorSetLayout makeDescriptorSetLayout( vk::raii::DescriptorSetLayout makeDescriptorSetLayout( vk::raii::Device const & device,
vk::raii::Device const & device, std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const & bindingData,
std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const & bindingData, vk::DescriptorSetLayoutCreateFlags flags = {} )
vk::DescriptorSetLayoutCreateFlags flags = {} )
{ {
std::vector<vk::DescriptorSetLayoutBinding> bindings( bindingData.size() ); std::vector<vk::DescriptorSetLayoutBinding> bindings( bindingData.size() );
for ( size_t i = 0; i < bindingData.size(); i++ ) for ( size_t i = 0; i < bindingData.size(); i++ )
{ {
bindings[i] = vk::DescriptorSetLayoutBinding( vk::su::checked_cast<uint32_t>( i ), bindings[i] = vk::DescriptorSetLayoutBinding(
std::get<0>( bindingData[i] ), vk::su::checked_cast<uint32_t>( i ), std::get<0>( bindingData[i] ), std::get<1>( bindingData[i] ), std::get<2>( bindingData[i] ) );
std::get<1>( bindingData[i] ),
std::get<2>( bindingData[i] ) );
} }
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( flags, bindings ); vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( flags, bindings );
return vk::raii::DescriptorSetLayout( device, descriptorSetLayoutCreateInfo ); return vk::raii::DescriptorSetLayout( device, descriptorSetLayoutCreateInfo );
@ -656,10 +590,8 @@ namespace vk
} }
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority );
vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority ); vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo, {}, enabledExtensions, physicalDeviceFeatures );
vk::DeviceCreateInfo deviceCreateInfo(
vk::DeviceCreateFlags(), deviceQueueCreateInfo, {}, enabledExtensions, physicalDeviceFeatures );
deviceCreateInfo.pNext = pNext; deviceCreateInfo.pNext = pNext;
return vk::raii::Device( physicalDevice, deviceCreateInfo ); return vk::raii::Device( physicalDevice, deviceCreateInfo );
} }
@ -673,13 +605,8 @@ namespace vk
vk::ImageView attachments[2]; vk::ImageView attachments[2];
attachments[1] = pDepthImageView ? **pDepthImageView : vk::ImageView(); attachments[1] = pDepthImageView ? **pDepthImageView : vk::ImageView();
vk::FramebufferCreateInfo framebufferCreateInfo( vk::FramebufferCreateFlags(), vk::FramebufferCreateInfo framebufferCreateInfo(
*renderPass, vk::FramebufferCreateFlags(), *renderPass, pDepthImageView ? 2 : 1, attachments, extent.width, extent.height, 1 );
pDepthImageView ? 2 : 1,
attachments,
extent.width,
extent.height,
1 );
std::vector<vk::raii::Framebuffer> framebuffers; std::vector<vk::raii::Framebuffer> framebuffers;
framebuffers.reserve( imageViews.size() ); framebuffers.reserve( imageViews.size() );
for ( auto const & imageView : imageViews ) for ( auto const & imageView : imageViews )
@ -691,25 +618,22 @@ namespace vk
return framebuffers; return framebuffers;
} }
vk::raii::Pipeline vk::raii::Pipeline makeGraphicsPipeline( vk::raii::Device const & device,
makeGraphicsPipeline( vk::raii::Device const & device, vk::raii::PipelineCache const & pipelineCache,
vk::raii::PipelineCache const & pipelineCache, vk::raii::ShaderModule const & vertexShaderModule,
vk::raii::ShaderModule const & vertexShaderModule, vk::SpecializationInfo const * vertexShaderSpecializationInfo,
vk::SpecializationInfo const * vertexShaderSpecializationInfo, vk::raii::ShaderModule const & fragmentShaderModule,
vk::raii::ShaderModule const & fragmentShaderModule, vk::SpecializationInfo const * fragmentShaderSpecializationInfo,
vk::SpecializationInfo const * fragmentShaderSpecializationInfo, uint32_t vertexStride,
uint32_t vertexStride, std::vector<std::pair<vk::Format, uint32_t>> const & vertexInputAttributeFormatOffset,
std::vector<std::pair<vk::Format, uint32_t>> const & vertexInputAttributeFormatOffset, vk::FrontFace frontFace,
vk::FrontFace frontFace, bool depthBuffered,
bool depthBuffered, vk::raii::PipelineLayout const & pipelineLayout,
vk::raii::PipelineLayout const & pipelineLayout, vk::raii::RenderPass const & renderPass )
vk::raii::RenderPass const & renderPass )
{ {
std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = { std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eVertex, *vertexShaderModule, "main", vertexShaderSpecializationInfo ),
{}, vk::ShaderStageFlagBits::eVertex, *vertexShaderModule, "main", vertexShaderSpecializationInfo ), vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, *fragmentShaderModule, "main", fragmentShaderSpecializationInfo )
vk::PipelineShaderStageCreateInfo(
{}, vk::ShaderStageFlagBits::eFragment, *fragmentShaderModule, "main", fragmentShaderSpecializationInfo )
}; };
std::vector<vk::VertexInputAttributeDescription> vertexInputAttributeDescriptions; std::vector<vk::VertexInputAttributeDescription> vertexInputAttributeDescriptions;
@ -721,48 +645,37 @@ namespace vk
vertexInputAttributeDescriptions.reserve( vertexInputAttributeFormatOffset.size() ); vertexInputAttributeDescriptions.reserve( vertexInputAttributeFormatOffset.size() );
for ( uint32_t i = 0; i < vertexInputAttributeFormatOffset.size(); i++ ) for ( uint32_t i = 0; i < vertexInputAttributeFormatOffset.size(); i++ )
{ {
vertexInputAttributeDescriptions.emplace_back( vertexInputAttributeDescriptions.emplace_back( i, 0, vertexInputAttributeFormatOffset[i].first, vertexInputAttributeFormatOffset[i].second );
i, 0, vertexInputAttributeFormatOffset[i].first, vertexInputAttributeFormatOffset[i].second );
} }
pipelineVertexInputStateCreateInfo.setVertexBindingDescriptions( vertexInputBindingDescription ); pipelineVertexInputStateCreateInfo.setVertexBindingDescriptions( vertexInputBindingDescription );
pipelineVertexInputStateCreateInfo.setVertexAttributeDescriptions( vertexInputAttributeDescriptions ); pipelineVertexInputStateCreateInfo.setVertexAttributeDescriptions( vertexInputAttributeDescriptions );
} }
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateFlags(),
vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList ); vk::PrimitiveTopology::eTriangleList );
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( vk::PipelineRasterizationStateCreateFlags(),
vk::PipelineRasterizationStateCreateFlags(), false,
false, false,
false, vk::PolygonMode::eFill,
vk::PolygonMode::eFill, vk::CullModeFlagBits::eBack,
vk::CullModeFlagBits::eBack, frontFace,
frontFace, false,
false, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f );
1.0f );
vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( {}, vk::SampleCountFlagBits::e1 ); vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( {}, vk::SampleCountFlagBits::e1 );
vk::StencilOpState stencilOpState( vk::StencilOpState stencilOpState( vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo( vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(
vk::PipelineDepthStencilStateCreateFlags(), vk::PipelineDepthStencilStateCreateFlags(), depthBuffered, depthBuffered, vk::CompareOp::eLessOrEqual, false, false, stencilOpState, stencilOpState );
depthBuffered,
depthBuffered,
vk::CompareOp::eLessOrEqual,
false,
false,
stencilOpState,
stencilOpState );
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB |
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA ); vk::ColorComponentFlagBits::eA );
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false, vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false,
vk::BlendFactor::eZero, vk::BlendFactor::eZero,
vk::BlendFactor::eZero, vk::BlendFactor::eZero,
@ -772,15 +685,10 @@ namespace vk
vk::BlendOp::eAdd, vk::BlendOp::eAdd,
colorComponentFlags ); colorComponentFlags );
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(
vk::PipelineColorBlendStateCreateFlags(), vk::PipelineColorBlendStateCreateFlags(), false, vk::LogicOp::eNoOp, pipelineColorBlendAttachmentState, { { 1.0f, 1.0f, 1.0f, 1.0f } } );
false,
vk::LogicOp::eNoOp,
pipelineColorBlendAttachmentState,
{ { 1.0f, 1.0f, 1.0f, 1.0f } } );
std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(), vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(), dynamicStates );
dynamicStates );
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlags(), vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlags(),
pipelineShaderStageCreateInfos, pipelineShaderStageCreateInfos,
@ -827,20 +735,18 @@ namespace vk
context.enumerateInstanceLayerProperties() context.enumerateInstanceLayerProperties()
#endif #endif
); );
std::vector<char const *> enabledExtensions = std::vector<char const *> enabledExtensions = vk::su::gatherExtensions( extensions
vk::su::gatherExtensions( extensions
#if !defined( NDEBUG ) #if !defined( NDEBUG )
, ,
context.enumerateInstanceExtensionProperties() context.enumerateInstanceExtensionProperties()
#endif #endif
); );
#if defined( NDEBUG ) #if defined( NDEBUG )
vk::StructureChain<vk::InstanceCreateInfo> vk::StructureChain<vk::InstanceCreateInfo>
#else #else
vk::StructureChain<vk::InstanceCreateInfo, vk::DebugUtilsMessengerCreateInfoEXT> vk::StructureChain<vk::InstanceCreateInfo, vk::DebugUtilsMessengerCreateInfoEXT>
#endif #endif
instanceCreateInfoChain = instanceCreateInfoChain = vk::su::makeInstanceCreateInfoChain( applicationInfo, enabledLayers, enabledExtensions );
vk::su::makeInstanceCreateInfoChain( applicationInfo, enabledLayers, enabledExtensions );
return vk::raii::Instance( context, instanceCreateInfoChain.get<vk::InstanceCreateInfo>() ); return vk::raii::Instance( context, instanceCreateInfoChain.get<vk::InstanceCreateInfo>() );
} }
@ -881,18 +787,14 @@ namespace vk
{}, {},
colorAttachment, colorAttachment,
{}, {},
( depthFormat != vk::Format::eUndefined ) ? &depthAttachment ( depthFormat != vk::Format::eUndefined ) ? &depthAttachment : nullptr );
: nullptr ); vk::RenderPassCreateInfo renderPassCreateInfo( vk::RenderPassCreateFlags(), attachmentDescriptions, subpassDescription );
vk::RenderPassCreateInfo renderPassCreateInfo(
vk::RenderPassCreateFlags(), attachmentDescriptions, subpassDescription );
return vk::raii::RenderPass( device, renderPassCreateInfo ); return vk::raii::RenderPass( device, renderPassCreateInfo );
} }
vk::Format pickDepthFormat( vk::raii::PhysicalDevice const & physicalDevice ) vk::Format pickDepthFormat( vk::raii::PhysicalDevice const & physicalDevice )
{ {
std::vector<vk::Format> candidates = { vk::Format::eD32Sfloat, std::vector<vk::Format> candidates = { vk::Format::eD32Sfloat, vk::Format::eD32SfloatS8Uint, vk::Format::eD24UnormS8Uint };
vk::Format::eD32SfloatS8Uint,
vk::Format::eD24UnormS8Uint };
for ( vk::Format format : candidates ) for ( vk::Format format : candidates )
{ {
vk::FormatProperties props = physicalDevice.getFormatProperties( format ); vk::FormatProperties props = physicalDevice.getFormatProperties( format );
@ -905,9 +807,7 @@ namespace vk
throw std::runtime_error( "failed to find supported format!" ); throw std::runtime_error( "failed to find supported format!" );
} }
void submitAndWait( vk::raii::Device const & device, void submitAndWait( vk::raii::Device const & device, vk::raii::Queue const & queue, vk::raii::CommandBuffer const & commandBuffer )
vk::raii::Queue const & queue,
vk::raii::CommandBuffer const & commandBuffer )
{ {
vk::raii::Fence fence( device, vk::FenceCreateInfo() ); vk::raii::Fence fence( device, vk::FenceCreateInfo() );
queue.submit( vk::SubmitInfo( nullptr, nullptr, *commandBuffer ), *fence ); queue.submit( vk::SubmitInfo( nullptr, nullptr, *commandBuffer ), *fence );
@ -915,13 +815,11 @@ namespace vk
; ;
} }
void updateDescriptorSets( void updateDescriptorSets( vk::raii::Device const & device,
vk::raii::Device const & device, vk::raii::DescriptorSet const & descriptorSet,
vk::raii::DescriptorSet const & descriptorSet, std::vector<std::tuple<vk::DescriptorType, vk::raii::Buffer const &, vk::raii::BufferView const *>> const & bufferData,
std::vector<std::tuple<vk::DescriptorType, vk::raii::Buffer const &, vk::raii::BufferView const *>> const & vk::raii::su::TextureData const & textureData,
bufferData, uint32_t bindingOffset = 0 )
vk::raii::su::TextureData const & textureData,
uint32_t bindingOffset = 0 )
{ {
std::vector<vk::DescriptorBufferInfo> bufferInfos; std::vector<vk::DescriptorBufferInfo> bufferInfos;
bufferInfos.reserve( bufferData.size() ); bufferInfos.reserve( bufferData.size() );
@ -937,31 +835,21 @@ namespace vk
{ {
bufferView = **std::get<2>( bhd ); bufferView = **std::get<2>( bhd );
} }
writeDescriptorSets.emplace_back( *descriptorSet, writeDescriptorSets.emplace_back(
dstBinding++, *descriptorSet, dstBinding++, 0, 1, std::get<0>( bhd ), nullptr, &bufferInfos.back(), std::get<2>( bhd ) ? &bufferView : nullptr );
0,
1,
std::get<0>( bhd ),
nullptr,
&bufferInfos.back(),
std::get<2>( bhd ) ? &bufferView : nullptr );
} }
vk::DescriptorImageInfo imageInfo( vk::DescriptorImageInfo imageInfo( *textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal ); writeDescriptorSets.emplace_back( *descriptorSet, dstBinding, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo, nullptr, nullptr );
writeDescriptorSets.emplace_back(
*descriptorSet, dstBinding, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo, nullptr, nullptr );
device.updateDescriptorSets( writeDescriptorSets, nullptr ); device.updateDescriptorSets( writeDescriptorSets, nullptr );
} }
void updateDescriptorSets( void updateDescriptorSets( vk::raii::Device const & device,
vk::raii::Device const & device, vk::raii::DescriptorSet const & descriptorSet,
vk::raii::DescriptorSet const & descriptorSet, std::vector<std::tuple<vk::DescriptorType, vk::raii::Buffer const &, vk::raii::BufferView const *>> const & bufferData,
std::vector<std::tuple<vk::DescriptorType, vk::raii::Buffer const &, vk::raii::BufferView const *>> const & std::vector<vk::raii::su::TextureData> const & textureData,
bufferData, uint32_t bindingOffset = 0 )
std::vector<vk::raii::su::TextureData> const & textureData,
uint32_t bindingOffset = 0 )
{ {
std::vector<vk::DescriptorBufferInfo> bufferInfos; std::vector<vk::DescriptorBufferInfo> bufferInfos;
bufferInfos.reserve( bufferData.size() ); bufferInfos.reserve( bufferData.size() );
@ -977,14 +865,8 @@ namespace vk
{ {
bufferView = **std::get<2>( bhd ); bufferView = **std::get<2>( bhd );
} }
writeDescriptorSets.emplace_back( *descriptorSet, writeDescriptorSets.emplace_back(
dstBinding++, *descriptorSet, dstBinding++, 0, 1, std::get<0>( bhd ), nullptr, &bufferInfos.back(), std::get<2>( bhd ) ? &bufferView : nullptr );
0,
1,
std::get<0>( bhd ),
nullptr,
&bufferInfos.back(),
std::get<2>( bhd ) ? &bufferView : nullptr );
} }
std::vector<vk::DescriptorImageInfo> imageInfos; std::vector<vk::DescriptorImageInfo> imageInfos;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -29,8 +29,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName ); vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
@ -41,19 +40,16 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties(); std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
// get the first index into queueFamiliyProperties which supports graphics // get the first index into queueFamiliyProperties which supports graphics
auto propertyIterator = std::find_if( auto propertyIterator = std::find_if( queueFamilyProperties.begin(),
queueFamilyProperties.begin(), queueFamilyProperties.end(), []( vk::QueueFamilyProperties const & qfp ) { queueFamilyProperties.end(),
return qfp.queueFlags & vk::QueueFlagBits::eGraphics; []( vk::QueueFamilyProperties const & qfp ) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; } );
} );
size_t graphicsQueueFamilyIndex = std::distance( queueFamilyProperties.begin(), propertyIterator ); size_t graphicsQueueFamilyIndex = std::distance( queueFamilyProperties.begin(), propertyIterator );
assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() ); assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() );
// create a Device // create a Device
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority ); vk::Device device = physicalDevice.createDevice( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) );
vk::Device device =
physicalDevice.createDevice( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) );
// destroy the device // destroy the device
device.destroy(); device.destroy();

View File

@ -29,26 +29,22 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName ); vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
// create a CommandPool to allocate a CommandBuffer from // create a CommandPool to allocate a CommandBuffer from
vk::CommandPool commandPool = vk::CommandPool commandPool = device.createCommandPool( vk::CommandPoolCreateInfo( vk::CommandPoolCreateFlags(), graphicsQueueFamilyIndex ) );
device.createCommandPool( vk::CommandPoolCreateInfo( vk::CommandPoolCreateFlags(), graphicsQueueFamilyIndex ) );
// allocate a CommandBuffer from the CommandPool // allocate a CommandBuffer from the CommandPool
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
// freeing the commandBuffer is optional, as it will automatically freed when the corresponding CommandPool is // freeing the commandBuffer is optional, as it will automatically freed when the corresponding CommandPool is
// destroyed. // destroyed.

View File

@ -29,14 +29,13 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties(); std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( queueFamilyProperties ); uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( queueFamilyProperties );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
@ -52,10 +51,9 @@ int main( int /*argc*/, char ** /*argv*/ )
// determine a queueFamilyIndex that suports present // determine a queueFamilyIndex that suports present
// first check if the graphicsQueueFamiliyIndex is good enough // first check if the graphicsQueueFamiliyIndex is good enough
size_t presentQueueFamilyIndex = size_t presentQueueFamilyIndex = physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( graphicsQueueFamilyIndex ), surface )
physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( graphicsQueueFamilyIndex ), surface ) ? graphicsQueueFamilyIndex
? graphicsQueueFamilyIndex : queueFamilyProperties.size();
: queueFamilyProperties.size();
if ( presentQueueFamilyIndex == queueFamilyProperties.size() ) if ( presentQueueFamilyIndex == queueFamilyProperties.size() )
{ {
// the graphicsQueueFamilyIndex doesn't support present -> look for an other family index that supports both // the graphicsQueueFamilyIndex doesn't support present -> look for an other family index that supports both
@ -84,8 +82,7 @@ int main( int /*argc*/, char ** /*argv*/ )
} }
} }
} }
if ( ( graphicsQueueFamilyIndex == queueFamilyProperties.size() ) || if ( ( graphicsQueueFamilyIndex == queueFamilyProperties.size() ) || ( presentQueueFamilyIndex == queueFamilyProperties.size() ) )
( presentQueueFamilyIndex == queueFamilyProperties.size() ) )
{ {
throw std::runtime_error( "Could not find a queue for graphics or present -> terminating" ); throw std::runtime_error( "Could not find a queue for graphics or present -> terminating" );
} }
@ -96,18 +93,15 @@ int main( int /*argc*/, char ** /*argv*/ )
// get the supported VkFormats // get the supported VkFormats
std::vector<vk::SurfaceFormatKHR> formats = physicalDevice.getSurfaceFormatsKHR( surface ); std::vector<vk::SurfaceFormatKHR> formats = physicalDevice.getSurfaceFormatsKHR( surface );
assert( !formats.empty() ); assert( !formats.empty() );
vk::Format format = vk::Format format = ( formats[0].format == vk::Format::eUndefined ) ? vk::Format::eB8G8R8A8Unorm : formats[0].format;
( formats[0].format == vk::Format::eUndefined ) ? vk::Format::eB8G8R8A8Unorm : formats[0].format;
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface ); vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface );
vk::Extent2D swapchainExtent; vk::Extent2D swapchainExtent;
if ( surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max() ) if ( surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max() )
{ {
// If the surface size is undefined, the size is set to the size of the images requested. // If the surface size is undefined, the size is set to the size of the images requested.
swapchainExtent.width = swapchainExtent.width = vk::su::clamp( width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width );
vk::su::clamp( width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width ); swapchainExtent.height = vk::su::clamp( height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height );
swapchainExtent.height =
vk::su::clamp( height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height );
} }
else else
{ {
@ -118,19 +112,15 @@ int main( int /*argc*/, char ** /*argv*/ )
// The FIFO present mode is guaranteed by the spec to be supported // The FIFO present mode is guaranteed by the spec to be supported
vk::PresentModeKHR swapchainPresentMode = vk::PresentModeKHR::eFifo; vk::PresentModeKHR swapchainPresentMode = vk::PresentModeKHR::eFifo;
vk::SurfaceTransformFlagBitsKHR preTransform = vk::SurfaceTransformFlagBitsKHR preTransform = ( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity )
( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity ) ? vk::SurfaceTransformFlagBitsKHR::eIdentity
? vk::SurfaceTransformFlagBitsKHR::eIdentity : surfaceCapabilities.currentTransform;
: surfaceCapabilities.currentTransform;
vk::CompositeAlphaFlagBitsKHR compositeAlpha = vk::CompositeAlphaFlagBitsKHR compositeAlpha =
( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied
? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit ) ? vk::CompositeAlphaFlagBitsKHR::eInherit
? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied : vk::CompositeAlphaFlagBitsKHR::eOpaque;
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit )
? vk::CompositeAlphaFlagBitsKHR::eInherit
: vk::CompositeAlphaFlagBitsKHR::eOpaque;
vk::SwapchainCreateInfoKHR swapChainCreateInfo( vk::SwapchainCreateFlagsKHR(), vk::SwapchainCreateInfoKHR swapChainCreateInfo( vk::SwapchainCreateFlagsKHR(),
surface, surface,
@ -148,8 +138,7 @@ int main( int /*argc*/, char ** /*argv*/ )
true, true,
nullptr ); nullptr );
uint32_t queueFamilyIndices[2] = { static_cast<uint32_t>( graphicsQueueFamilyIndex ), uint32_t queueFamilyIndices[2] = { static_cast<uint32_t>( graphicsQueueFamilyIndex ), static_cast<uint32_t>( presentQueueFamilyIndex ) };
static_cast<uint32_t>( presentQueueFamilyIndex ) };
if ( graphicsQueueFamilyIndex != presentQueueFamilyIndex ) if ( graphicsQueueFamilyIndex != presentQueueFamilyIndex )
{ {
// If the graphics and present queues are from different queue families, we either have to explicitly transfer // If the graphics and present queues are from different queue families, we either have to explicitly transfer
@ -166,8 +155,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::ImageView> imageViews; std::vector<vk::ImageView> imageViews;
imageViews.reserve( swapChainImages.size() ); imageViews.reserve( swapChainImages.size() );
vk::ImageViewCreateInfo imageViewCreateInfo( vk::ImageViewCreateInfo imageViewCreateInfo( {}, {}, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
{}, {}, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
for ( auto image : swapChainImages ) for ( auto image : swapChainImages )
{ {
imageViewCreateInfo.image = image; imageViewCreateInfo.image = image;

View File

@ -29,18 +29,15 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
@ -78,8 +75,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++ ) for ( uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++ )
{ {
if ( ( typeBits & 1 ) && if ( ( typeBits & 1 ) &&
( ( memoryProperties.memoryTypes[i].propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal ) == ( ( memoryProperties.memoryTypes[i].propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal ) == vk::MemoryPropertyFlagBits::eDeviceLocal ) )
vk::MemoryPropertyFlagBits::eDeviceLocal ) )
{ {
typeIndex = i; typeIndex = i;
break; break;
@ -87,18 +83,12 @@ int main( int /*argc*/, char ** /*argv*/ )
typeBits >>= 1; typeBits >>= 1;
} }
assert( typeIndex != uint32_t( ~0 ) ); assert( typeIndex != uint32_t( ~0 ) );
vk::DeviceMemory depthMemory = vk::DeviceMemory depthMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, typeIndex ) );
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, typeIndex ) );
device.bindImageMemory( depthImage, depthMemory, 0 ); device.bindImageMemory( depthImage, depthMemory, 0 );
vk::ImageView depthView = vk::ImageView depthView = device.createImageView( vk::ImageViewCreateInfo(
device.createImageView( vk::ImageViewCreateInfo( vk::ImageViewCreateFlags(), vk::ImageViewCreateFlags(), depthImage, vk::ImageViewType::e2D, depthFormat, {}, { vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1 } ) );
depthImage,
vk::ImageViewType::e2D,
depthFormat,
{},
{ vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1 } ) );
// destroy depthView, depthMemory, and depthImage // destroy depthView, depthMemory, and depthImage
device.destroyImageView( depthView ); device.destroyImageView( depthView );

View File

@ -42,21 +42,18 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName ); vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
glm::mat4x4 model = glm::mat4x4( 1.0f ); glm::mat4x4 model = glm::mat4x4( 1.0f );
glm::mat4x4 view = glm::mat4x4 view = glm::lookAt( glm::vec3( -5.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
glm::lookAt( glm::vec3( -5.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
glm::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f ); glm::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f );
// clang-format off // clang-format off
glm::mat4x4 clip = glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f, glm::mat4x4 clip = glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f,
@ -66,16 +63,14 @@ int main( int /*argc*/, char ** /*argv*/ )
// clang-format on // clang-format on
glm::mat4x4 mvpc = clip * projection * view * model; glm::mat4x4 mvpc = clip * projection * view * model;
vk::Buffer uniformDataBuffer = device.createBuffer( vk::Buffer uniformDataBuffer =
vk::BufferCreateInfo( vk::BufferCreateFlags(), sizeof( mvpc ), vk::BufferUsageFlagBits::eUniformBuffer ) ); device.createBuffer( vk::BufferCreateInfo( vk::BufferCreateFlags(), sizeof( mvpc ), vk::BufferUsageFlagBits::eUniformBuffer ) );
vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements( uniformDataBuffer ); vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements( uniformDataBuffer );
uint32_t typeIndex = uint32_t typeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits,
memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ); vk::DeviceMemory uniformDataMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, typeIndex ) );
vk::DeviceMemory uniformDataMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, typeIndex ) );
uint8_t * pData = static_cast<uint8_t *>( device.mapMemory( uniformDataMemory, 0, memoryRequirements.size ) ); uint8_t * pData = static_cast<uint8_t *>( device.mapMemory( uniformDataMemory, 0, memoryRequirements.size ) );
memcpy( pData, &mvpc, sizeof( mvpc ) ); memcpy( pData, &mvpc, sizeof( mvpc ) );

View File

@ -29,27 +29,23 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName ); vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
// create a DescriptorSetLayout // create a DescriptorSetLayout
vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding( vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ); vk::DescriptorSetLayout descriptorSetLayout =
vk::DescriptorSetLayout descriptorSetLayout = device.createDescriptorSetLayout( device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), descriptorSetLayoutBinding ) );
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), descriptorSetLayoutBinding ) );
// create a PipelineLayout using that DescriptorSetLayout // create a PipelineLayout using that DescriptorSetLayout
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
// destroy the pipelineLayout and the descriptorSetLayout // destroy the pipelineLayout and the descriptorSetLayout
device.destroyPipelineLayout( pipelineLayout ); device.destroyPipelineLayout( pipelineLayout );

View File

@ -42,38 +42,34 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName ); vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( vk::Extent2D( 0, 0 ) );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( vk::Extent2D( 0, 0 ) );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
// create a descriptor pool // create a descriptor pool
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 ); vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 );
vk::DescriptorPool descriptorPool = device.createDescriptorPool( vk::DescriptorPool descriptorPool =
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) ); device.createDescriptorPool( vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) );
// allocate a descriptor set // allocate a descriptor set
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front(); vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::DescriptorBufferInfo descriptorBufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo descriptorBufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::WriteDescriptorSet writeDescriptorSet( vk::WriteDescriptorSet writeDescriptorSet( descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo );
descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr ); device.updateDescriptorSets( writeDescriptorSet, nullptr );
device.freeDescriptorSets( descriptorPool, descriptorSet ); device.freeDescriptorSets( descriptorPool, descriptorSet );

View File

@ -41,21 +41,17 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Format colorFormat = vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format;
vk::Format depthFormat = vk::Format::eD16Unorm; vk::Format depthFormat = vk::Format::eD16Unorm;
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
@ -82,11 +78,9 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal ); vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal );
vk::AttachmentReference depthReference( 1, vk::ImageLayout::eDepthStencilAttachmentOptimal ); vk::AttachmentReference depthReference( 1, vk::ImageLayout::eDepthStencilAttachmentOptimal );
vk::SubpassDescription subpass( vk::SubpassDescription subpass( vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, {}, colorReference, {}, &depthReference );
vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, {}, colorReference, {}, &depthReference );
vk::RenderPass renderPass = device.createRenderPass( vk::RenderPass renderPass = device.createRenderPass( vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachmentDescriptions, subpass ) );
vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachmentDescriptions, subpass ) );
device.destroyRenderPass( renderPass ); device.destroyRenderPass( renderPass );

View File

@ -31,15 +31,13 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
@ -47,7 +45,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<unsigned int> vertexShaderSPV; std::vector<unsigned int> vertexShaderSPV;
#if !defined( NDEBUG ) #if !defined( NDEBUG )
bool ok = bool ok =
#endif #endif
vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C, vertexShaderSPV ); vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C, vertexShaderSPV );
assert( ok ); assert( ok );
@ -57,7 +55,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<unsigned int> fragmentShaderSPV; std::vector<unsigned int> fragmentShaderSPV;
#if !defined( NDEBUG ) #if !defined( NDEBUG )
ok = ok =
#endif #endif
vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C, fragmentShaderSPV ); vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C, fragmentShaderSPV );
assert( ok ); assert( ok );

View File

@ -29,25 +29,21 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::su::SwapChainData swapChainData( physicalDevice, vk::su::SwapChainData swapChainData( physicalDevice,
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
nullptr, nullptr,
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );

View File

@ -30,23 +30,19 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -54,8 +50,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -64,23 +59,21 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::RenderPass renderPass = vk::su::createRenderPass( device, swapChainData.colorFormat, depthBufferData.format ); vk::RenderPass renderPass = vk::su::createRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
// create a vertex buffer for some vertex and color data // create a vertex buffer for some vertex and color data
vk::Buffer vertexBuffer = device.createBuffer( vk::BufferCreateInfo( vk::Buffer vertexBuffer =
vk::BufferCreateFlags(), sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ) ); device.createBuffer( vk::BufferCreateInfo( vk::BufferCreateFlags(), sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ) );
// allocate device memory for that buffer // allocate device memory for that buffer
vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements( vertexBuffer ); vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements( vertexBuffer );
uint32_t memoryTypeIndex = uint32_t memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits,
memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ); vk::DeviceMemory deviceMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
vk::DeviceMemory deviceMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
// copy the vertex and color data into that device memory // copy the vertex and color data into that device memory
uint8_t * pData = static_cast<uint8_t *>( device.mapMemory( deviceMemory, 0, memoryRequirements.size ) ); uint8_t * pData = static_cast<uint8_t *>( device.mapMemory( deviceMemory, 0, memoryRequirements.size ) );
@ -90,10 +83,8 @@ int main( int /*argc*/, char ** /*argv*/ )
// and bind the device memory to the vertex buffer // and bind the device memory to the vertex buffer
device.bindBufferMemory( vertexBuffer, deviceMemory, 0 ); device.bindBufferMemory( vertexBuffer, deviceMemory, 0 );
vk::Semaphore imageAcquiredSemaphore = vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) ); vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR(
swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
@ -103,10 +94,8 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) ); commandBuffer.begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass, vk::RenderPassBeginInfo renderPassBeginInfo(
framebuffers[currentBuffer.value], renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindVertexBuffers( 0, vertexBuffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBuffer, { 0 } );

View File

@ -43,43 +43,33 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass =
device, vk::su::createRenderPass( device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, vk::Format::eD16Unorm );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
vk::Format::eD16Unorm );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = { std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "main" ), vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule, "main" )
vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule, "main" )
}; };
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( coloredCubeData[0] ) ); vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( coloredCubeData[0] ) );
@ -87,89 +77,79 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ), vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 ) vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
}; };
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateFlags(), // flags
vk::PipelineVertexInputStateCreateFlags(), // flags vertexInputBindingDescription, // vertexBindingDescriptions
vertexInputBindingDescription, // vertexBindingDescriptions vertexInputAttributeDescriptions // vertexAttributeDescriptions
vertexInputAttributeDescriptions // vertexAttributeDescriptions
); );
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateFlags(),
vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList ); vk::PrimitiveTopology::eTriangleList );
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( vk::PipelineRasterizationStateCreateFlags(), // flags
vk::PipelineRasterizationStateCreateFlags(), // flags false, // depthClampEnable
false, // depthClampEnable false, // rasterizerDiscardEnable
false, // rasterizerDiscardEnable vk::PolygonMode::eFill, // polygonMode
vk::PolygonMode::eFill, // polygonMode vk::CullModeFlagBits::eBack, // cullMode
vk::CullModeFlagBits::eBack, // cullMode vk::FrontFace::eClockwise, // frontFace
vk::FrontFace::eClockwise, // frontFace false, // depthBiasEnable
false, // depthBiasEnable 0.0f, // depthBiasConstantFactor
0.0f, // depthBiasConstantFactor 0.0f, // depthBiasClamp
0.0f, // depthBiasClamp 0.0f, // depthBiasSlopeFactor
0.0f, // depthBiasSlopeFactor 1.0f // lineWidth
1.0f // lineWidth
); );
vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( vk::PipelineMultisampleStateCreateFlags(), // flags
vk::PipelineMultisampleStateCreateFlags(), // flags vk::SampleCountFlagBits::e1 // rasterizationSamples
vk::SampleCountFlagBits::e1 // rasterizationSamples // other values can be default
// other values can be default
); );
vk::StencilOpState stencilOpState( vk::StencilOpState stencilOpState( vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways ); vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo( vk::PipelineDepthStencilStateCreateFlags(), // flags
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo( true, // depthTestEnable
vk::PipelineDepthStencilStateCreateFlags(), // flags true, // depthWriteEnable
true, // depthTestEnable vk::CompareOp::eLessOrEqual, // depthCompareOp
true, // depthWriteEnable false, // depthBoundTestEnable
vk::CompareOp::eLessOrEqual, // depthCompareOp false, // stencilTestEnable
false, // depthBoundTestEnable stencilOpState, // front
false, // stencilTestEnable stencilOpState // back
stencilOpState, // front
stencilOpState // back
); );
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB |
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA ); vk::ColorComponentFlagBits::eA );
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false, // blendEnable
false, // blendEnable vk::BlendFactor::eZero, // srcColorBlendFactor
vk::BlendFactor::eZero, // srcColorBlendFactor vk::BlendFactor::eZero, // dstColorBlendFactor
vk::BlendFactor::eZero, // dstColorBlendFactor vk::BlendOp::eAdd, // colorBlendOp
vk::BlendOp::eAdd, // colorBlendOp vk::BlendFactor::eZero, // srcAlphaBlendFactor
vk::BlendFactor::eZero, // srcAlphaBlendFactor vk::BlendFactor::eZero, // dstAlphaBlendFactor
vk::BlendFactor::eZero, // dstAlphaBlendFactor vk::BlendOp::eAdd, // alphaBlendOp
vk::BlendOp::eAdd, // alphaBlendOp colorComponentFlags // colorWriteMask
colorComponentFlags // colorWriteMask
); );
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(), // flags
vk::PipelineColorBlendStateCreateFlags(), // flags false, // logicOpEnable
false, // logicOpEnable vk::LogicOp::eNoOp, // logicOp
vk::LogicOp::eNoOp, // logicOp pipelineColorBlendAttachmentState, // attachments
pipelineColorBlendAttachmentState, // attachments { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(), vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(), dynamicStates );
dynamicStates );
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlags(), // flags
vk::PipelineCreateFlags(), // flags pipelineShaderStageCreateInfos, // stages
pipelineShaderStageCreateInfos, // stages &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState nullptr, // pTessellationState
nullptr, // pTessellationState &pipelineViewportStateCreateInfo, // pViewportState
&pipelineViewportStateCreateInfo, // pViewportState &pipelineRasterizationStateCreateInfo, // pRasterizationState
&pipelineRasterizationStateCreateInfo, // pRasterizationState &pipelineMultisampleStateCreateInfo, // pMultisampleState
&pipelineMultisampleStateCreateInfo, // pMultisampleState &pipelineDepthStencilStateCreateInfo, // pDepthStencilState
&pipelineDepthStencilStateCreateInfo, // pDepthStencilState &pipelineColorBlendStateCreateInfo, // pColorBlendState
&pipelineColorBlendStateCreateInfo, // pColorBlendState &pipelineDynamicStateCreateInfo, // pDynamicState
&pipelineDynamicStateCreateInfo, // pDynamicState pipelineLayout, // layout
pipelineLayout, // layout renderPass // renderPass
renderPass // renderPass
); );
vk::Result result; vk::Result result;

View File

@ -34,23 +34,19 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -59,73 +55,58 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass = vk::su::createRenderPass(
device, device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData( vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::su::copyToDevice( device, vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
coloredCubeData,
sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::DescriptorPool descriptorPool = vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front(); vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() ); vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
device, pipelineCache,
pipelineCache, std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( vertexShaderModule, nullptr ), std::make_pair( fragmentShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ), sizeof( coloredCubeData[0] ),
sizeof( coloredCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
vk::ResultValue<uint32_t> currentBuffer = vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
@ -134,22 +115,15 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass, vk::RenderPassBeginInfo renderPassBeginInfo(
framebuffers[currentBuffer.value], renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -165,14 +139,11 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
vk::Result result = vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -44,8 +44,7 @@ int main( int /*argc*/, char ** /*argv*/ )
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 ) #if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
// initialize the DipatchLoaderDynamic to use // initialize the DipatchLoaderDynamic to use
static vk::DynamicLoader dl; static vk::DynamicLoader dl;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr ); VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
#endif #endif
@ -55,19 +54,15 @@ int main( int /*argc*/, char ** /*argv*/ )
// Translate the version into major/minor for easier comparison // Translate the version into major/minor for easier comparison
uint32_t loader_major_version = VK_VERSION_MAJOR( apiVersion ); uint32_t loader_major_version = VK_VERSION_MAJOR( apiVersion );
uint32_t loader_minor_version = VK_VERSION_MINOR( apiVersion ); uint32_t loader_minor_version = VK_VERSION_MINOR( apiVersion );
std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version << "\n";
<< "\n";
// Check current version against what we want to run // Check current version against what we want to run
if ( loader_major_version > desiredMajorVersion || if ( loader_major_version > desiredMajorVersion || ( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
{ {
// Create the instance // Create the instance
vk::Instance instance = vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions(), desiredVersion );
vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions(), desiredVersion );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
// Get the list of physical devices // Get the list of physical devices
@ -76,11 +71,10 @@ int main( int /*argc*/, char ** /*argv*/ )
// Go through the list of physical devices and select only those that are capable of running the API version we // Go through the list of physical devices and select only those that are capable of running the API version we
// want. // want.
std::vector<vk::PhysicalDevice> desiredPhysicalDevices; std::vector<vk::PhysicalDevice> desiredPhysicalDevices;
std::copy_if( std::copy_if( physicalDevices.begin(),
physicalDevices.begin(), physicalDevices.end(),
physicalDevices.end(), std::back_inserter( desiredPhysicalDevices ),
std::back_inserter( desiredPhysicalDevices ), [desiredVersion]( vk::PhysicalDevice const & pd ) { return pd.getProperties().apiVersion >= desiredVersion; } );
[desiredVersion]( vk::PhysicalDevice const & pd ) { return pd.getProperties().apiVersion >= desiredVersion; } );
// If we have something in the desired version physical device list, we're good // If we have something in the desired version physical device list, we're good
if ( desiredPhysicalDevices.size() > 0 ) if ( desiredPhysicalDevices.size() > 0 )
@ -101,13 +95,12 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( usingMinorVersion < desiredMinorVersion ) if ( usingMinorVersion < desiredMinorVersion )
{ {
std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString << " instead of desired version "
<< " instead of desired version " << desiredVersionString << std::endl; << desiredVersionString << std::endl;
} }
else else
{ {
std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString << std::endl;
<< std::endl;
} }
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */

View File

@ -29,8 +29,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
@ -44,15 +43,12 @@ int main( int /*argc*/, char ** /*argv*/ )
exit( -1 ); exit( -1 );
} }
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -61,8 +57,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferDst,
vk::ImageUsageFlagBits::eTransferDst,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -70,25 +65,20 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( swapChainData.colorFormat ); vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( swapChainData.colorFormat );
assert( ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc ) && assert( ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc ) && "Format cannot be used as transfer source" );
"Format cannot be used as transfer source" );
#endif #endif
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::ResultValue<uint32_t> nextImage = vk::ResultValue<uint32_t> nextImage = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( nextImage.result == vk::Result::eSuccess ); assert( nextImage.result == vk::Result::eSuccess );
assert( nextImage.value < swapChainData.images.size() ); assert( nextImage.value < swapChainData.images.size() );
uint32_t imageIndex = nextImage.value; uint32_t imageIndex = nextImage.value;
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
vk::su::setImageLayout( commandBuffer, vk::su::setImageLayout(
swapChainData.images[imageIndex], commandBuffer, swapChainData.images[imageIndex], swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eTransferDstOptimal );
// Create an image, map it, and write some values to the image // Create an image, map it, and write some values to the image
vk::ImageCreateInfo imageCreateInfo( vk::ImageCreateFlags(), vk::ImageCreateInfo imageCreateInfo( vk::ImageCreateFlags(),
@ -104,18 +94,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties(); vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties();
vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements( blitSourceImage ); vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements( blitSourceImage );
uint32_t memoryTypeIndex = vk::su::findMemoryType( uint32_t memoryTypeIndex = vk::su::findMemoryType( memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible );
memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible );
vk::DeviceMemory deviceMemory = vk::DeviceMemory deviceMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
device.bindImageMemory( blitSourceImage, deviceMemory, 0 ); device.bindImageMemory( blitSourceImage, deviceMemory, 0 );
vk::su::setImageLayout( commandBuffer, vk::su::setImageLayout( commandBuffer, blitSourceImage, swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eGeneral );
blitSourceImage,
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eGeneral );
commandBuffer.end(); commandBuffer.end();
@ -128,8 +112,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( device.waitForFences( commandFence, true, vk::su::FenceTimeout ) == vk::Result::eTimeout ) while ( device.waitForFences( commandFence, true, vk::su::FenceTimeout ) == vk::Result::eTimeout )
; ;
unsigned char * pImageMemory = unsigned char * pImageMemory = static_cast<unsigned char *>( device.mapMemory( deviceMemory, 0, memoryRequirements.size ) );
static_cast<unsigned char *>( device.mapMemory( deviceMemory, 0, memoryRequirements.size ) );
// Checkerboard of 8x8 pixel squares // Checkerboard of 8x8 pixel squares
for ( uint32_t row = 0; row < surfaceData.extent.height; row++ ) for ( uint32_t row = 0; row < surfaceData.extent.height; row++ )
@ -153,27 +136,18 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
// Intend to blit from this image, set the layout accordingly // Intend to blit from this image, set the layout accordingly
vk::su::setImageLayout( commandBuffer, vk::su::setImageLayout( commandBuffer, blitSourceImage, swapChainData.colorFormat, vk::ImageLayout::eGeneral, vk::ImageLayout::eTransferSrcOptimal );
blitSourceImage,
swapChainData.colorFormat,
vk::ImageLayout::eGeneral,
vk::ImageLayout::eTransferSrcOptimal );
vk::Image blitDestinationImage = swapChainData.images[imageIndex]; vk::Image blitDestinationImage = swapChainData.images[imageIndex];
// Do a 32x32 blit to all of the dst image - should get big squares // Do a 32x32 blit to all of the dst image - should get big squares
vk::ImageSubresourceLayers imageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 ); vk::ImageSubresourceLayers imageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 );
vk::ImageBlit imageBlit( vk::ImageBlit imageBlit( imageSubresourceLayers,
imageSubresourceLayers, { { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 32, 32, 1 ) } },
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 32, 32, 1 ) } }, imageSubresourceLayers,
imageSubresourceLayers, { { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( surfaceData.extent.width, surfaceData.extent.height, 1 ) } } );
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( surfaceData.extent.width, surfaceData.extent.height, 1 ) } } ); commandBuffer.blitImage(
commandBuffer.blitImage( blitSourceImage, blitSourceImage, vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageBlit, vk::Filter::eLinear );
vk::ImageLayout::eTransferSrcOptimal,
blitDestinationImage,
vk::ImageLayout::eTransferDstOptimal,
imageBlit,
vk::Filter::eLinear );
// Use a barrier to make sure the blit is finished before the copy starts // Use a barrier to make sure the blit is finished before the copy starts
vk::ImageMemoryBarrier memoryBarrier( vk::AccessFlagBits::eTransferWrite, vk::ImageMemoryBarrier memoryBarrier( vk::AccessFlagBits::eTransferWrite,
@ -184,40 +158,23 @@ int main( int /*argc*/, char ** /*argv*/ )
VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED,
blitDestinationImage, blitDestinationImage,
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) ); vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer, commandBuffer.pipelineBarrier(
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, vk::DependencyFlags(), nullptr, nullptr, memoryBarrier );
vk::DependencyFlags(),
nullptr,
nullptr,
memoryBarrier );
// Do a image copy to part of the dst image - checks should stay small // Do a image copy to part of the dst image - checks should stay small
vk::ImageCopy imageCopy( imageSubresourceLayers, vk::ImageCopy imageCopy( imageSubresourceLayers, vk::Offset3D(), imageSubresourceLayers, vk::Offset3D( 256, 256, 0 ), vk::Extent3D( 128, 128, 1 ) );
vk::Offset3D(), commandBuffer.copyImage( blitSourceImage, vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageCopy );
imageSubresourceLayers,
vk::Offset3D( 256, 256, 0 ),
vk::Extent3D( 128, 128, 1 ) );
commandBuffer.copyImage( blitSourceImage,
vk::ImageLayout::eTransferSrcOptimal,
blitDestinationImage,
vk::ImageLayout::eTransferDstOptimal,
imageCopy );
vk::ImageMemoryBarrier prePresentBarrier( vk::ImageMemoryBarrier prePresentBarrier( vk::AccessFlagBits::eTransferWrite,
vk::AccessFlagBits::eTransferWrite, vk::AccessFlagBits::eMemoryRead,
vk::AccessFlagBits::eMemoryRead, vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::ePresentSrcKHR,
vk::ImageLayout::ePresentSrcKHR, VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED, swapChainData.images[imageIndex],
swapChainData.images[imageIndex], vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) ); commandBuffer.pipelineBarrier(
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTopOfPipe, vk::DependencyFlags(), nullptr, nullptr, prePresentBarrier );
vk::PipelineStageFlagBits::eTopOfPipe,
vk::DependencyFlags(),
nullptr,
nullptr,
prePresentBarrier );
commandBuffer.end(); commandBuffer.end();
vk::Fence drawFence = device.createFence( {} ); vk::Fence drawFence = device.createFence( {} );
@ -233,9 +190,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -34,9 +34,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT( VkInstance
return pfnVkCreateDebugUtilsMessengerEXT( instance, pCreateInfo, pAllocator, pMessenger ); return pfnVkCreateDebugUtilsMessengerEXT( instance, pCreateInfo, pAllocator, pMessenger );
} }
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance, VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator )
VkDebugUtilsMessengerEXT messenger,
VkAllocationCallbacks const * pAllocator )
{ {
return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator ); return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator );
} }
@ -85,8 +83,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc( VkDebugUtilsMessageSeverityFlag
message << "\t\t" message << "\t\t"
<< "Object " << i << "\n"; << "Object " << i << "\n";
message << "\t\t\t" message << "\t\t\t"
<< "objectType = " << "objectType = " << vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) << "\n";
<< vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) << "\n";
message << "\t\t\t" message << "\t\t\t"
<< "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n"; << "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n";
if ( pCallbackData->pObjects[i].pObjectName ) if ( pCallbackData->pObjects[i].pObjectName )
@ -114,31 +111,26 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::ExtensionProperties> props = vk::enumerateInstanceExtensionProperties(); std::vector<vk::ExtensionProperties> props = vk::enumerateInstanceExtensionProperties();
auto propertyIterator = std::find_if( props.begin(), props.end(), []( vk::ExtensionProperties const & ep ) { auto propertyIterator = std::find_if(
return strcmp( ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) == 0; props.begin(), props.end(), []( vk::ExtensionProperties const & ep ) { return strcmp( ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) == 0; } );
} );
if ( propertyIterator == props.end() ) if ( propertyIterator == props.end() )
{ {
std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension" std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension" << std::endl;
<< std::endl;
exit( 1 ); exit( 1 );
} }
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 ); vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
const char * extensionName = VK_EXT_DEBUG_UTILS_EXTENSION_NAME; const char * extensionName = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
vk::Instance instance = vk::Instance instance = vk::createInstance( vk::InstanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, {}, extensionName ) );
vk::createInstance( vk::InstanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, {}, extensionName ) );
pfnVkCreateDebugUtilsMessengerEXT = pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
if ( !pfnVkCreateDebugUtilsMessengerEXT ) if ( !pfnVkCreateDebugUtilsMessengerEXT )
{ {
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl; std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
exit( 1 ); exit( 1 );
} }
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>( pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>( instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
if ( !pfnVkDestroyDebugUtilsMessengerEXT ) if ( !pfnVkDestroyDebugUtilsMessengerEXT )
{ {
std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl; std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl;
@ -147,11 +139,10 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
vk::DebugUtilsMessageSeverityFlagBitsEXT::eError ); vk::DebugUtilsMessageSeverityFlagBitsEXT::eError );
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation ); vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::DebugUtilsMessengerEXT debugUtilsMessenger =
vk::DebugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc ) ); instance.createDebugUtilsMessengerEXT( vk::DebugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc ) );
instance.destroyDebugUtilsMessengerEXT( debugUtilsMessenger ); instance.destroyDebugUtilsMessengerEXT( debugUtilsMessenger );
instance.destroy(); instance.destroy();

View File

@ -33,16 +33,14 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName ); vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
std::vector<vk::PhysicalDevice> physicalDevices = instance.enumeratePhysicalDevices(); std::vector<vk::PhysicalDevice> physicalDevices = instance.enumeratePhysicalDevices();
assert( !physicalDevices.empty() ); assert( !physicalDevices.empty() );
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevices[0].getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevices[0].getQueueFamilyProperties() ); vk::Device device = vk::su::createDevice( physicalDevices[0], graphicsQueueFamilyIndex );
vk::Device device = vk::su::createDevice( physicalDevices[0], graphicsQueueFamilyIndex );
// create an image // create an image
vk::ImageCreateInfo imageCreateInfo( {}, vk::ImageCreateInfo imageCreateInfo( {},
@ -54,12 +52,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::SampleCountFlagBits::e1, vk::SampleCountFlagBits::e1,
vk::ImageTiling::eLinear, vk::ImageTiling::eLinear,
vk::ImageUsageFlagBits::eTransferSrc ); vk::ImageUsageFlagBits::eTransferSrc );
vk::Image image = device.createImage( imageCreateInfo ); vk::Image image = device.createImage( imageCreateInfo );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
vk::DebugUtilsObjectNameInfoEXT debugUtilsObjectNameInfo( vk::DebugUtilsObjectNameInfoEXT debugUtilsObjectNameInfo( vk::ObjectType::eImage, NON_DISPATCHABLE_HANDLE_TO_UINT64_CAST( VkImage, image ), "Image name" );
vk::ObjectType::eImage, NON_DISPATCHABLE_HANDLE_TO_UINT64_CAST( VkImage, image ), "Image name" );
device.setDebugUtilsObjectNameEXT( debugUtilsObjectNameInfo ); device.setDebugUtilsObjectNameEXT( debugUtilsObjectNameInfo );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */

View File

@ -34,23 +34,19 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -59,8 +55,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -72,66 +67,53 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() ); textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
device, vk::su::createDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass = vk::su::createRenderPass(
device, device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData( vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool( vk::DescriptorPool descriptorPool =
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front(); vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() ); vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
vk::su::createGraphicsPipeline( device, pipelineCache,
pipelineCache, std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( vertexShaderModule, nullptr ), std::make_pair( fragmentShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ), sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
vk::ResultValue<uint32_t> currentBuffer = vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
@ -140,22 +122,15 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass, vk::RenderPassBeginInfo renderPassBeginInfo(
framebuffers[currentBuffer.value], renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -171,14 +146,11 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
vk::Result result = vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -45,23 +45,19 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -70,8 +66,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -79,26 +74,18 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass = vk::su::createRenderPass(
device, device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData( vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::su::copyToDevice( device, vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
coloredCubeData,
sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -111,9 +98,8 @@ int main( int /*argc*/, char ** /*argv*/ )
/* Set up uniform buffer with 2 transform matrices in it */ /* Set up uniform buffer with 2 transform matrices in it */
glm::mat4x4 mvpcs[2]; glm::mat4x4 mvpcs[2];
glm::mat4x4 model = glm::mat4x4( 1.0f ); glm::mat4x4 model = glm::mat4x4( 1.0f );
glm::mat4x4 view = glm::mat4x4 view = glm::lookAt( glm::vec3( 0.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
glm::lookAt( glm::vec3( 0.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
glm::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f ); glm::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f );
// clang-format off // clang-format off
glm::mat4x4 clip = glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f, glm::mat4x4 clip = glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f,
@ -129,45 +115,38 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DeviceSize bufferSize = sizeof( glm::mat4x4 ); vk::DeviceSize bufferSize = sizeof( glm::mat4x4 );
if ( limits.minUniformBufferOffsetAlignment ) if ( limits.minUniformBufferOffsetAlignment )
{ {
bufferSize = bufferSize = ( bufferSize + limits.minUniformBufferOffsetAlignment - 1 ) & ~( limits.minUniformBufferOffsetAlignment - 1 );
( bufferSize + limits.minUniformBufferOffsetAlignment - 1 ) & ~( limits.minUniformBufferOffsetAlignment - 1 );
} }
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcs, 2, bufferSize ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcs, 2, bufferSize );
// create a DescriptorSetLayout with vk::DescriptorType::eUniformBufferDynamic // create a DescriptorSetLayout with vk::DescriptorType::eUniformBufferDynamic
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
// create a DescriptorPool with vk::DescriptorType::eUniformBufferDynamic // create a DescriptorPool with vk::DescriptorType::eUniformBufferDynamic
vk::DescriptorPool descriptorPool = vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front(); vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, {} } }, {} );
device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, {} } }, {} );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() ); vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
device, pipelineCache,
pipelineCache, std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( vertexShaderModule, nullptr ), std::make_pair( fragmentShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ), sizeof( coloredCubeData[0] ),
sizeof( coloredCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
vk::ResultValue<uint32_t> currentBuffer = vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
@ -176,34 +155,25 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass, vk::RenderPassBeginInfo renderPassBeginInfo(
framebuffers[currentBuffer.value], renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
/* The first draw should use the first matrix in the buffer */ /* The first draw should use the first matrix in the buffer */
uint32_t dynamicOffset = 0; uint32_t dynamicOffset = 0;
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, dynamicOffset );
vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, dynamicOffset );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
// the second draw should use the second matrix in the buffer; // the second draw should use the second matrix in the buffer;
dynamicOffset = (uint32_t)bufferSize; dynamicOffset = (uint32_t)bufferSize;
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, dynamicOffset );
vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, dynamicOffset );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass(); commandBuffer.endRenderPass();
@ -218,14 +188,11 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
vk::Result result = vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -46,9 +46,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT( VkInstance
return pfnVkCreateDebugUtilsMessengerEXT( instance, pCreateInfo, pAllocator, pMessenger ); return pfnVkCreateDebugUtilsMessengerEXT( instance, pCreateInfo, pAllocator, pMessenger );
} }
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance, VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator )
VkDebugUtilsMessengerEXT messenger,
VkAllocationCallbacks const * pAllocator )
{ {
return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator ); return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator );
} }
@ -86,10 +84,8 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc( VkDebugUtilsMessageSeverityFlag
for ( uint32_t i = 0; i < pCallbackData->objectCount; i++ ) for ( uint32_t i = 0; i < pCallbackData->objectCount; i++ )
{ {
message += std::string( "\t" ) + "Object " + std::to_string( i ) + "\n"; message += std::string( "\t" ) + "Object " + std::to_string( i ) + "\n";
message += std::string( "\t\t" ) + "objectType = " + message += std::string( "\t\t" ) + "objectType = " + vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) + "\n";
vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) + "\n"; message += std::string( "\t\t" ) + "objectHandle = " + std::to_string( pCallbackData->pObjects[i].objectHandle ) + "\n";
message +=
std::string( "\t\t" ) + "objectHandle = " + std::to_string( pCallbackData->pObjects[i].objectHandle ) + "\n";
if ( pCallbackData->pObjects[i].pObjectName ) if ( pCallbackData->pObjects[i].pObjectName )
{ {
message += std::string( "\t\t" ) + "objectName = <" + pCallbackData->pObjects[i].pObjectName + ">\n"; message += std::string( "\t\t" ) + "objectName = <" + pCallbackData->pObjects[i].pObjectName + ">\n";
@ -109,11 +105,15 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc( VkDebugUtilsMessageSeverityFlag
bool checkLayers( std::vector<char const *> const & layers, std::vector<vk::LayerProperties> const & properties ) bool checkLayers( std::vector<char const *> const & layers, std::vector<vk::LayerProperties> const & properties )
{ {
// return true if all layers are listed in the properties // return true if all layers are listed in the properties
return std::all_of( layers.begin(), layers.end(), [&properties]( char const * name ) { return std::all_of( layers.begin(),
return std::find_if( properties.begin(), properties.end(), [&name]( vk::LayerProperties const & property ) { layers.end(),
return strcmp( property.layerName, name ) == 0; [&properties]( char const * name )
} ) != properties.end(); {
} ); return std::find_if( properties.begin(),
properties.end(),
[&name]( vk::LayerProperties const & property )
{ return strcmp( property.layerName, name ) == 0; } ) != properties.end();
} );
} }
int main( int /*argc*/, char ** /*argv*/ ) int main( int /*argc*/, char ** /*argv*/ )
@ -123,8 +123,7 @@ int main( int /*argc*/, char ** /*argv*/ )
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 ) #if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
// initialize the DipatchLoaderDynamic to use // initialize the DipatchLoaderDynamic to use
static vk::DynamicLoader dl; static vk::DynamicLoader dl;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr ); VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
#endif #endif
@ -146,25 +145,22 @@ int main( int /*argc*/, char ** /*argv*/ )
instanceExtensionNames.push_back( VK_EXT_DEBUG_UTILS_EXTENSION_NAME ); instanceExtensionNames.push_back( VK_EXT_DEBUG_UTILS_EXTENSION_NAME );
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 ); vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
vk::InstanceCreateInfo instanceCreateInfo( vk::InstanceCreateInfo instanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, instanceLayerNames, instanceExtensionNames );
vk::InstanceCreateFlags(), &applicationInfo, instanceLayerNames, instanceExtensionNames ); vk::Instance instance = vk::createInstance( instanceCreateInfo );
vk::Instance instance = vk::createInstance( instanceCreateInfo );
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 ) #if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
// initialize function pointers for instance // initialize function pointers for instance
VULKAN_HPP_DEFAULT_DISPATCHER.init( instance ); VULKAN_HPP_DEFAULT_DISPATCHER.init( instance );
#endif #endif
pfnVkCreateDebugUtilsMessengerEXT = pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
if ( !pfnVkCreateDebugUtilsMessengerEXT ) if ( !pfnVkCreateDebugUtilsMessengerEXT )
{ {
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl; std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
exit( 1 ); exit( 1 );
} }
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>( pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>( instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
if ( !pfnVkDestroyDebugUtilsMessengerEXT ) if ( !pfnVkDestroyDebugUtilsMessengerEXT )
{ {
std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl; std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl;
@ -173,27 +169,22 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
vk::DebugUtilsMessageSeverityFlagBitsEXT::eError ); vk::DebugUtilsMessageSeverityFlagBitsEXT::eError );
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation ); vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::DebugUtilsMessengerEXT debugUtilsMessenger =
vk::DebugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc ) ); instance.createDebugUtilsMessengerEXT( vk::DebugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc ) );
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
// get the index of the first queue family that supports graphics // get the index of the first queue family that supports graphics
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), graphicsQueueFamilyIndex, 1, &queuePriority );
vk::DeviceQueueCreateFlags(), graphicsQueueFamilyIndex, 1, &queuePriority ); vk::Device device = physicalDevice.createDevice( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) );
vk::Device device =
physicalDevice.createDevice( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) );
// Create a CommandPool and don't destroy it, for testing purposes! // Create a CommandPool and don't destroy it, for testing purposes!
vk::CommandPool commandPool = vk::CommandPool commandPool = device.createCommandPool( vk::CommandPoolCreateInfo( vk::CommandPoolCreateFlags(), graphicsQueueFamilyIndex ) );
device.createCommandPool( vk::CommandPoolCreateInfo( vk::CommandPoolCreateFlags(), graphicsQueueFamilyIndex ) );
#if true #if true
// The commandPool is not destroyed automatically // The commandPool is not destroyed automatically

View File

@ -30,8 +30,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName ); vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */

View File

@ -29,20 +29,17 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex = uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsQueueFamilyIndex ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsQueueFamilyIndex );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsQueueFamilyIndex, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsQueueFamilyIndex, 0 );
@ -78,8 +75,7 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.reset( vk::CommandBufferResetFlags() ); commandBuffer.reset( vk::CommandBufferResetFlags() );
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
commandBuffer.waitEvents( commandBuffer.waitEvents( event, vk::PipelineStageFlagBits::eHost, vk::PipelineStageFlagBits::eBottomOfPipe, nullptr, nullptr, nullptr );
event, vk::PipelineStageFlagBits::eHost, vk::PipelineStageFlagBits::eBottomOfPipe, nullptr, nullptr, nullptr );
commandBuffer.end(); commandBuffer.end();
device.resetFences( fence ); device.resetFences( fence );

View File

@ -43,23 +43,19 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -68,40 +64,30 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass = vk::su::createRenderPass(
device, device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData( vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -112,30 +98,26 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::DescriptorSetLayoutBinding, 2> bindings = { std::array<vk::DescriptorSetLayoutBinding, 2> bindings = {
vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ), vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ),
vk::DescriptorSetLayoutBinding( vk::DescriptorSetLayoutBinding( 1, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, textureData.sampler )
1, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, textureData.sampler )
}; };
vk::DescriptorSetLayout descriptorSetLayout = device.createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), bindings ) ); device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), bindings ) );
// Create pipeline layout // Create pipeline layout
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
// Create a single pool to contain data for our descriptor set // Create a single pool to contain data for our descriptor set
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorType::eCombinedImageSampler, 1 ) }; vk::DescriptorPool descriptorPool =
vk::DescriptorPool descriptorPool = device.createDescriptorPool( device.createDescriptorPool( vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
// Populate descriptor sets // Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front(); vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo( vk::DescriptorImageInfo imageInfo( textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = { std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
vk::WriteDescriptorSet( descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ), vk::WriteDescriptorSet( descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( descriptorSet, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo ) vk::WriteDescriptorSet( descriptorSet, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
@ -144,44 +126,35 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() ); vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
vk::su::createGraphicsPipeline( device, pipelineCache,
pipelineCache, std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( vertexShaderModule, nullptr ), std::make_pair( fragmentShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ), sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
vk::ResultValue<uint32_t> currentBuffer = vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass, vk::RenderPassBeginInfo renderPassBeginInfo(
framebuffers[currentBuffer.value], renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -190,14 +163,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::submitAndWait( device, graphicsQueue, commandBuffer ); vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
vk::Result result = vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -43,23 +43,19 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 50, 50 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 50, 50 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -72,32 +68,28 @@ int main( int /*argc*/, char ** /*argv*/ )
// See if we can use a linear tiled image for a texture, if not, we will need a staging buffer for the texture data // See if we can use a linear tiled image for a texture, if not, we will need a staging buffer for the texture data
bool needsStaging = !( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eSampledImage ); bool needsStaging = !( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eSampledImage );
vk::ImageCreateInfo imageCreateInfo( vk::ImageCreateInfo imageCreateInfo( vk::ImageCreateFlags(),
vk::ImageCreateFlags(), vk::ImageType::e2D,
vk::ImageType::e2D, format,
format, vk::Extent3D( surfaceData.extent, 1 ),
vk::Extent3D( surfaceData.extent, 1 ), 1,
1, 1,
1, vk::SampleCountFlagBits::e1,
vk::SampleCountFlagBits::e1, needsStaging ? vk::ImageTiling::eOptimal : vk::ImageTiling::eLinear,
needsStaging ? vk::ImageTiling::eOptimal : vk::ImageTiling::eLinear, vk::ImageUsageFlagBits::eSampled | ( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ),
vk::ImageUsageFlagBits::eSampled | vk::SharingMode::eExclusive,
( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ), {},
vk::SharingMode::eExclusive, needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized );
{}, vk::Image image = device.createImage( imageCreateInfo );
needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized );
vk::Image image = device.createImage( imageCreateInfo );
vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements( image ); vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements( image );
uint32_t memoryTypeIndex = vk::su::findMemoryType( uint32_t memoryTypeIndex = vk::su::findMemoryType(
physicalDevice.getMemoryProperties(), physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits, memoryRequirements.memoryTypeBits,
needsStaging ? vk::MemoryPropertyFlags() needsStaging ? vk::MemoryPropertyFlags() : ( vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ) );
: ( vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ) );
// allocate memory // allocate memory
vk::DeviceMemory imageMemory = vk::DeviceMemory imageMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
// bind memory // bind memory
device.bindImageMemory( image, imageMemory, 0 ); device.bindImageMemory( image, imageMemory, 0 );
@ -107,16 +99,13 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( needsStaging ) if ( needsStaging )
{ {
// Need a staging buffer to map and copy texture into // Need a staging buffer to map and copy texture into
textureBuffer = textureBuffer = device.createBuffer(
device.createBuffer( vk::BufferCreateInfo( vk::BufferCreateFlags(), vk::BufferCreateInfo( vk::BufferCreateFlags(), surfaceData.extent.width * surfaceData.extent.height * 4, vk::BufferUsageFlagBits::eTransferSrc ) );
surfaceData.extent.width * surfaceData.extent.height * 4,
vk::BufferUsageFlagBits::eTransferSrc ) );
memoryRequirements = device.getBufferMemoryRequirements( textureBuffer ); memoryRequirements = device.getBufferMemoryRequirements( textureBuffer );
memoryTypeIndex = memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits,
memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
// allocate memory // allocate memory
textureBufferMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) ); textureBufferMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
@ -126,12 +115,10 @@ int main( int /*argc*/, char ** /*argv*/ )
} }
else else
{ {
vk::SubresourceLayout subresourceLayout = vk::SubresourceLayout subresourceLayout = device.getImageSubresourceLayout( image, vk::ImageSubresource( vk::ImageAspectFlagBits::eColor ) );
device.getImageSubresourceLayout( image, vk::ImageSubresource( vk::ImageAspectFlagBits::eColor ) );
} }
void * data = device.mapMemory( void * data = device.mapMemory( needsStaging ? textureBufferMemory : imageMemory, 0, memoryRequirements.size, vk::MemoryMapFlags() );
needsStaging ? textureBufferMemory : imageMemory, 0, memoryRequirements.size, vk::MemoryMapFlags() );
// Checkerboard of 16x16 pixel squares // Checkerboard of 16x16 pixel squares
unsigned char * pImageMemory = static_cast<unsigned char *>( data ); unsigned char * pImageMemory = static_cast<unsigned char *>( data );
@ -154,8 +141,7 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( needsStaging ) if ( needsStaging )
{ {
// Since we're going to blit to the texture image, set its layout to eTransferDstOptimal // Since we're going to blit to the texture image, set its layout to eTransferDstOptimal
vk::su::setImageLayout( vk::su::setImageLayout( commandBuffer, image, format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
commandBuffer, image, format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
vk::BufferImageCopy copyRegion( 0, vk::BufferImageCopy copyRegion( 0,
surfaceData.extent.width, surfaceData.extent.width,
surfaceData.extent.height, surfaceData.extent.height,
@ -164,14 +150,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Extent3D( surfaceData.extent, 1 ) ); vk::Extent3D( surfaceData.extent, 1 ) );
commandBuffer.copyBufferToImage( textureBuffer, image, vk::ImageLayout::eTransferDstOptimal, copyRegion ); commandBuffer.copyBufferToImage( textureBuffer, image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
// Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY // Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY
vk::su::setImageLayout( vk::su::setImageLayout( commandBuffer, image, format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
commandBuffer, image, format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
} }
else else
{ {
// If we can use the linear tiled image as a texture, just do it // If we can use the linear tiled image as a texture, just do it
vk::su::setImageLayout( vk::su::setImageLayout( commandBuffer, image, format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal );
commandBuffer, image, format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal );
} }
commandBuffer.end(); commandBuffer.end();
@ -194,9 +178,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::BorderColor::eFloatOpaqueWhite ); vk::BorderColor::eFloatOpaqueWhite );
vk::Sampler sampler = device.createSampler( samplerCreateInfo ); vk::Sampler sampler = device.createSampler( samplerCreateInfo );
vk::ImageViewCreateInfo imageViewCreateInfo( vk::ImageViewCreateInfo imageViewCreateInfo( {}, image, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
{}, image, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } ); vk::ImageView imageView = device.createImageView( imageViewCreateInfo );
vk::ImageView imageView = device.createImageView( imageViewCreateInfo );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */

View File

@ -72,8 +72,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
@ -87,15 +86,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -104,8 +100,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -126,54 +121,36 @@ int main( int /*argc*/, char ** /*argv*/ )
1, 1,
vk::SampleCountFlagBits::e1, vk::SampleCountFlagBits::e1,
vk::ImageTiling::eOptimal, vk::ImageTiling::eOptimal,
vk::ImageUsageFlagBits::eInputAttachment | vk::ImageUsageFlagBits::eInputAttachment | vk::ImageUsageFlagBits::eTransferDst );
vk::ImageUsageFlagBits::eTransferDst );
vk::Image inputImage = device.createImage( imageCreateInfo ); vk::Image inputImage = device.createImage( imageCreateInfo );
vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements( inputImage ); vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements( inputImage );
uint32_t memoryTypeIndex = vk::su::findMemoryType( uint32_t memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlags() );
physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlags() ); vk::DeviceMemory inputMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
vk::DeviceMemory inputMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
device.bindImageMemory( inputImage, inputMemory, 0 ); device.bindImageMemory( inputImage, inputMemory, 0 );
// Set the image layout to TRANSFER_DST_OPTIMAL to be ready for clear // Set the image layout to TRANSFER_DST_OPTIMAL to be ready for clear
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
vk::su::setImageLayout( commandBuffer, vk::su::setImageLayout( commandBuffer, inputImage, swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
inputImage,
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eTransferDstOptimal );
commandBuffer.clearColorImage( commandBuffer.clearColorImage( inputImage,
inputImage, vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eTransferDstOptimal, vk::ClearColorValue( std::array<float, 4>( { { 1.0f, 1.0f, 0.0f, 0.0f } } ) ),
vk::ClearColorValue( std::array<float, 4>( { { 1.0f, 1.0f, 0.0f, 0.0f } } ) ), vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS ) );
vk::ImageSubresourceRange(
vk::ImageAspectFlagBits::eColor, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS ) );
// Set the image layout to SHADER_READONLY_OPTIMAL for use by the shaders // Set the image layout to SHADER_READONLY_OPTIMAL for use by the shaders
vk::su::setImageLayout( commandBuffer, vk::su::setImageLayout(
inputImage, commandBuffer, inputImage, swapChainData.colorFormat, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
swapChainData.colorFormat,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eShaderReadOnlyOptimal );
vk::ImageViewCreateInfo imageViewCreateInfo( {}, vk::ImageViewCreateInfo imageViewCreateInfo(
inputImage, {}, inputImage, vk::ImageViewType::e2D, swapChainData.colorFormat, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::ImageViewType::e2D, vk::ImageView inputAttachmentView = device.createImageView( imageViewCreateInfo );
swapChainData.colorFormat,
{},
{ vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::ImageView inputAttachmentView = device.createImageView( imageViewCreateInfo );
vk::DescriptorSetLayoutBinding layoutBinding( vk::DescriptorSetLayoutBinding layoutBinding( 0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment );
0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment ); vk::DescriptorSetLayout descriptorSetLayout =
vk::DescriptorSetLayout descriptorSetLayout = device.createDescriptorSetLayout( device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), layoutBinding ) );
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), layoutBinding ) );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
std::array<vk::AttachmentDescription, 2> attachments = { std::array<vk::AttachmentDescription, 2> attachments = {
// First attachment is the color attachment - clear at the beginning of the renderpass and transition layout to // First attachment is the color attachment - clear at the beginning of the renderpass and transition layout to
@ -202,31 +179,26 @@ int main( int /*argc*/, char ** /*argv*/ )
}; };
vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal ); vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal );
vk::AttachmentReference inputReference( 1, vk::ImageLayout::eShaderReadOnlyOptimal ); vk::AttachmentReference inputReference( 1, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::SubpassDescription subPass( vk::SubpassDescription subPass( vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, inputReference, colorReference );
vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, inputReference, colorReference ); vk::RenderPass renderPass = device.createRenderPass( vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachments, subPass ) );
vk::RenderPass renderPass =
device.createRenderPass( vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachments, subPass ) );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, inputAttachmentView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, inputAttachmentView, surfaceData.extent );
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eInputAttachment, 1 ); vk::DescriptorPoolSize poolSize( vk::DescriptorType::eInputAttachment, 1 );
vk::DescriptorPool descriptorPool = device.createDescriptorPool( vk::DescriptorPool descriptorPool =
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) ); device.createDescriptorPool( vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front(); vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::DescriptorImageInfo inputImageInfo( nullptr, inputAttachmentView, vk::ImageLayout::eShaderReadOnlyOptimal ); vk::DescriptorImageInfo inputImageInfo( nullptr, inputAttachmentView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::WriteDescriptorSet writeDescriptorSet( vk::WriteDescriptorSet writeDescriptorSet( descriptorSet, 0, 0, vk::DescriptorType::eInputAttachment, inputImageInfo );
descriptorSet, 0, 0, vk::DescriptorType::eInputAttachment, inputImageInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr ); device.updateDescriptorSets( writeDescriptorSet, nullptr );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() ); vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
@ -243,27 +215,21 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
vk::ResultValue<uint32_t> nexImage = device.acquireNextImage2KHR( vk::ResultValue<uint32_t> nexImage =
vk::AcquireNextImageInfoKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, {}, 1 ) ); device.acquireNextImage2KHR( vk::AcquireNextImageInfoKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, {}, 1 ) );
assert( nexImage.result == vk::Result::eSuccess ); assert( nexImage.result == vk::Result::eSuccess );
uint32_t currentBuffer = nexImage.value; uint32_t currentBuffer = nexImage.value;
vk::ClearValue clearValue; vk::ClearValue clearValue;
clearValue.color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValue.color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
commandBuffer.beginRenderPass( commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo( vk::RenderPassBeginInfo( renderPass, framebuffers[currentBuffer], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValue ),
renderPass, framebuffers[currentBuffer], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValue ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 3, 1, 0, 0 ); commandBuffer.draw( 3, 1, 0, 0 );
@ -278,9 +244,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -33,9 +33,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::sort( extensionProperties.begin(), std::sort( extensionProperties.begin(),
extensionProperties.end(), extensionProperties.end(),
[]( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) { []( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) { return strcmp( a.extensionName, b.extensionName ) < 0; } );
return strcmp( a.extensionName, b.extensionName ) < 0;
} );
std::cout << "Instance Extensions:" << std::endl; std::cout << "Instance Extensions:" << std::endl;
for ( auto const & ep : extensionProperties ) for ( auto const & ep : extensionProperties )

View File

@ -23,8 +23,7 @@
struct PropertyData struct PropertyData
{ {
PropertyData( vk::LayerProperties const & layerProperties_, PropertyData( vk::LayerProperties const & layerProperties_, std::vector<vk::ExtensionProperties> const & extensionProperties_ )
std::vector<vk::ExtensionProperties> const & extensionProperties_ )
: layerProperties( layerProperties_ ), extensionProperties( extensionProperties_ ) : layerProperties( layerProperties_ ), extensionProperties( extensionProperties_ )
{} {}

View File

@ -38,8 +38,8 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
std::cout << lp.layerName << ":" << std::endl; std::cout << lp.layerName << ":" << std::endl;
std::cout << "\tVersion: " << lp.implementationVersion << std::endl; std::cout << "\tVersion: " << lp.implementationVersion << std::endl;
std::cout << "\tAPI Version: (" << ( lp.specVersion >> 22 ) << "." << ( ( lp.specVersion >> 12 ) & 0x03FF ) << "." std::cout << "\tAPI Version: (" << ( lp.specVersion >> 22 ) << "." << ( ( lp.specVersion >> 12 ) & 0x03FF ) << "." << ( lp.specVersion & 0xFFF ) << ")"
<< ( lp.specVersion & 0xFFF ) << ")" << std::endl; << std::endl;
std::cout << "\tDescription: " << lp.description << std::endl; std::cout << "\tDescription: " << lp.description << std::endl;
std::cout << std::endl; std::cout << std::endl;
} }

View File

@ -22,8 +22,8 @@
std::string decodeAPIVersion( uint32_t apiVersion ) std::string decodeAPIVersion( uint32_t apiVersion )
{ {
return std::to_string( VK_VERSION_MAJOR( apiVersion ) ) + "." + std::to_string( VK_VERSION_MINOR( apiVersion ) ) + return std::to_string( VK_VERSION_MAJOR( apiVersion ) ) + "." + std::to_string( VK_VERSION_MINOR( apiVersion ) ) + "." +
"." + std::to_string( VK_VERSION_PATCH( apiVersion ) ); std::to_string( VK_VERSION_PATCH( apiVersion ) );
} }
int main( int /*argc*/, char ** /*argv*/ ) int main( int /*argc*/, char ** /*argv*/ )

View File

@ -93,23 +93,19 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -118,8 +114,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -131,67 +126,53 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) ); textureData.setImage( device, commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass = vk::su::createRenderPass(
device, device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData( vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
// Create first layout to contain uniform buffer data // Create first layout to contain uniform buffer data
vk::DescriptorSetLayoutBinding uniformBinding( vk::DescriptorSetLayoutBinding uniformBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ); vk::DescriptorSetLayout uniformLayout =
vk::DescriptorSetLayout uniformLayout = device.createDescriptorSetLayout( device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), uniformBinding ) );
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), uniformBinding ) );
// Create second layout containing combined sampler/image data // Create second layout containing combined sampler/image data
vk::DescriptorSetLayoutBinding sampler2DBinding( vk::DescriptorSetLayoutBinding sampler2DBinding( 0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex );
0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex ); vk::DescriptorSetLayout samplerLayout =
vk::DescriptorSetLayout samplerLayout = device.createDescriptorSetLayout( device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), sampler2DBinding ) );
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), sampler2DBinding ) );
// Create pipeline layout with multiple descriptor sets // Create pipeline layout with multiple descriptor sets
std::array<vk::DescriptorSetLayout, 2> descriptorSetLayouts = { { uniformLayout, samplerLayout } }; std::array<vk::DescriptorSetLayout, 2> descriptorSetLayouts = { { uniformLayout, samplerLayout } };
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayouts ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayouts ) );
// Create a single pool to contain data for our two descriptor sets // Create a single pool to contain data for our two descriptor sets
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorType::eCombinedImageSampler, 1 ) }; vk::DescriptorPool descriptorPool =
vk::DescriptorPool descriptorPool = device.createDescriptorPool( device.createDescriptorPool( vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, poolSizes ) );
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, poolSizes ) );
// Populate descriptor sets // Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayouts ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayouts );
std::vector<vk::DescriptorSet> descriptorSets = device.allocateDescriptorSets( descriptorSetAllocateInfo ); std::vector<vk::DescriptorSet> descriptorSets = device.allocateDescriptorSets( descriptorSetAllocateInfo );
// Populate with info about our uniform buffer // Populate with info about our uniform buffer
vk::DescriptorBufferInfo uniformBufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo uniformBufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo textureImageInfo( vk::DescriptorImageInfo textureImageInfo( textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = { std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
{ vk::WriteDescriptorSet( descriptorSets[0], 0, 0, vk::DescriptorType::eUniformBuffer, {}, uniformBufferInfo ), { vk::WriteDescriptorSet( descriptorSets[0], 0, 0, vk::DescriptorType::eUniformBuffer, {}, uniformBufferInfo ),
vk::WriteDescriptorSet( descriptorSets[1], 0, 0, vk::DescriptorType::eCombinedImageSampler, textureImageInfo ) } vk::WriteDescriptorSet( descriptorSets[1], 0, 0, vk::DescriptorType::eCombinedImageSampler, textureImageInfo ) }
@ -200,46 +181,36 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() ); vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
vk::su::createGraphicsPipeline( device, pipelineCache,
pipelineCache, std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( vertexShaderModule, nullptr ), std::make_pair( fragmentShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ), sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
vk::ResultValue<uint32_t> currentBuffer = vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass, vk::RenderPassBeginInfo renderPassBeginInfo(
framebuffers[currentBuffer.value], renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, { descriptorSets[0], descriptorSets[1] }, nullptr );
vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, { descriptorSets[0], descriptorSets[1] }, nullptr );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -255,14 +226,11 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
vk::Result result = vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -34,23 +34,19 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -59,96 +55,76 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass = vk::su::createRenderPass(
device, device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData( vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::su::copyToDevice( device, vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
coloredCubeData,
sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::DescriptorPool descriptorPool = vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front(); vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() ); vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
device, pipelineCache,
pipelineCache, std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( vertexShaderModule, nullptr ), std::make_pair( fragmentShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ), sizeof( coloredCubeData[0] ),
sizeof( coloredCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
vk::Semaphore imageAcquiredSemaphore = vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::ResultValue<uint32_t> currentBuffer = vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
/* Allocate a uniform buffer that will take query results. */ /* Allocate a uniform buffer that will take query results. */
vk::Buffer queryResultBuffer = device.createBuffer( vk::Buffer queryResultBuffer = device.createBuffer( vk::BufferCreateInfo(
vk::BufferCreateInfo( vk::BufferCreateFlags(), vk::BufferCreateFlags(), 4 * sizeof( uint64_t ), vk::BufferUsageFlagBits::eUniformBuffer | vk::BufferUsageFlagBits::eTransferDst ) );
4 * sizeof( uint64_t ),
vk::BufferUsageFlagBits::eUniformBuffer | vk::BufferUsageFlagBits::eTransferDst ) );
vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements( queryResultBuffer ); vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements( queryResultBuffer );
uint32_t memoryTypeIndex = uint32_t memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits,
memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ); vk::DeviceMemory queryResultMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
vk::DeviceMemory queryResultMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
device.bindBufferMemory( queryResultBuffer, queryResultMemory, 0 ); device.bindBufferMemory( queryResultBuffer, queryResultMemory, 0 );
vk::QueryPool queryPool = device.createQueryPool( vk::QueryPoolCreateInfo( vk::QueryPool queryPool =
vk::QueryPoolCreateFlags(), vk::QueryType::eOcclusion, 2, vk::QueryPipelineStatisticFlags() ) ); device.createQueryPool( vk::QueryPoolCreateInfo( vk::QueryPoolCreateFlags(), vk::QueryType::eOcclusion, 2, vk::QueryPipelineStatisticFlags() ) );
commandBuffer.begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) ); commandBuffer.begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) );
commandBuffer.resetQueryPool( queryPool, 0, 2 ); commandBuffer.resetQueryPool( queryPool, 0, 2 );
@ -157,21 +133,15 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer.beginRenderPass( commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo( vk::RenderPassBeginInfo( renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, {} ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, {} );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.beginQuery( queryPool, 0, vk::QueryControlFlags() ); commandBuffer.beginQuery( queryPool, 0, vk::QueryControlFlags() );
@ -182,13 +152,8 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.endRenderPass(); commandBuffer.endRenderPass();
commandBuffer.endQuery( queryPool, 1 ); commandBuffer.endQuery( queryPool, 1 );
commandBuffer.copyQueryPoolResults( queryPool, commandBuffer.copyQueryPoolResults(
0, queryPool, 0, 2, queryResultBuffer, 0, sizeof( uint64_t ), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
2,
queryResultBuffer,
0,
sizeof( uint64_t ),
vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
commandBuffer.end(); commandBuffer.end();
vk::Fence drawFence = device.createFence( vk::FenceCreateInfo() ); vk::Fence drawFence = device.createFence( vk::FenceCreateInfo() );
@ -199,19 +164,12 @@ int main( int /*argc*/, char ** /*argv*/ )
graphicsQueue.waitIdle(); graphicsQueue.waitIdle();
vk::ResultValue<std::vector<uint64_t>> rv = vk::ResultValue<std::vector<uint64_t>> rv = device.getQueryPoolResults<uint64_t>(
device.getQueryPoolResults<uint64_t>( queryPool, queryPool, 0, 2, 2 * sizeof( uint64_t ), sizeof( uint64_t ), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
0,
2,
2 * sizeof( uint64_t ),
sizeof( uint64_t ),
vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
switch ( rv.result ) switch ( rv.result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eNotReady: case vk::Result::eNotReady: std::cout << "vk::Device::getQueryPoolResults returned vk::Result::eNotReady !\n"; break;
std::cout << "vk::Device::getQueryPoolResults returned vk::Result::eNotReady !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
@ -220,8 +178,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "samples_passed[1] = " << rv.value[1] << "\n"; std::cout << "samples_passed[1] = " << rv.value[1] << "\n";
/* Read back query result from buffer */ /* Read back query result from buffer */
uint64_t * samplesPassedPtr = static_cast<uint64_t *>( uint64_t * samplesPassedPtr = static_cast<uint64_t *>( device.mapMemory( queryResultMemory, 0, memoryRequirements.size, vk::MemoryMapFlags() ) );
device.mapMemory( queryResultMemory, 0, memoryRequirements.size, vk::MemoryMapFlags() ) );
std::cout << "vkCmdCopyQueryPoolResults data\n"; std::cout << "vkCmdCopyQueryPoolResults data\n";
std::cout << "samples_passed[0] = " << samplesPassedPtr[0] << "\n"; std::cout << "samples_passed[0] = " << samplesPassedPtr[0] << "\n";
@ -232,14 +189,11 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
vk::Result result = vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -29,8 +29,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName ); vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
// enumerate the physicalDevices // enumerate the physicalDevices
@ -40,16 +39,13 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ ) for ( size_t i = 0; i < physicalDevices.size(); i++ )
{ {
std::vector<vk::ExtensionProperties> extensionProperties = std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << " : " << extensionProperties.size() << " extensions:\n"; std::cout << "PhysicalDevice " << i << " : " << extensionProperties.size() << " extensions:\n";
// sort the extensions alphabetically // sort the extensions alphabetically
std::sort( extensionProperties.begin(), std::sort( extensionProperties.begin(),
extensionProperties.end(), extensionProperties.end(),
[]( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) { []( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) { return strcmp( a.extensionName, b.extensionName ) < 0; } );
return strcmp( a.extensionName, b.extensionName ) < 0;
} );
for ( auto const & ep : extensionProperties ) for ( auto const & ep : extensionProperties )
{ {
std::cout << "\t" << ep.extensionName << ":" << std::endl; std::cout << "\t" << ep.extensionName << ":" << std::endl;

View File

@ -38,8 +38,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, {}, VK_API_VERSION_1_1 ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
// enumerate the physicalDevices // enumerate the physicalDevices
@ -51,8 +50,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ ) for ( size_t i = 0; i < physicalDevices.size(); i++ )
{ {
// some features are only valid, if a corresponding extension is available! // some features are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties = std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << " :\n"; std::cout << "PhysicalDevice " << i << " :\n";
auto features2 = physicalDevices[i] auto features2 = physicalDevices[i]
@ -110,147 +108,85 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceFeatures const & features = features2.get<vk::PhysicalDeviceFeatures2>().features; vk::PhysicalDeviceFeatures const & features = features2.get<vk::PhysicalDeviceFeatures2>().features;
std::cout << "\tFeatures:\n"; std::cout << "\tFeatures:\n";
std::cout << "\t\talphaToOne : " << !!features.alphaToOne << "\n"; std::cout << "\t\talphaToOne : " << !!features.alphaToOne << "\n";
std::cout << "\t\tdepthBiasClamp : " << !!features.depthBiasClamp std::cout << "\t\tdepthBiasClamp : " << !!features.depthBiasClamp << "\n";
<< "\n"; std::cout << "\t\tdepthBounds : " << !!features.depthBounds << "\n";
std::cout << "\t\tdepthBounds : " << !!features.depthBounds
<< "\n";
std::cout << "\t\tdepthClamp : " << !!features.depthClamp << "\n"; std::cout << "\t\tdepthClamp : " << !!features.depthClamp << "\n";
std::cout << "\t\tdrawIndirectFirstInstance : " std::cout << "\t\tdrawIndirectFirstInstance : " << !!features.drawIndirectFirstInstance << "\n";
<< !!features.drawIndirectFirstInstance << "\n"; std::cout << "\t\tdualSrcBlend : " << !!features.dualSrcBlend << "\n";
std::cout << "\t\tdualSrcBlend : " << !!features.dualSrcBlend std::cout << "\t\tfillModeNonSolid : " << !!features.fillModeNonSolid << "\n";
<< "\n"; std::cout << "\t\tfragmentStoresAndAtomics : " << !!features.fragmentStoresAndAtomics << "\n";
std::cout << "\t\tfillModeNonSolid : " << !!features.fillModeNonSolid std::cout << "\t\tfullDrawIndexUint32 : " << !!features.fullDrawIndexUint32 << "\n";
<< "\n"; std::cout << "\t\tgeometryShader : " << !!features.geometryShader << "\n";
std::cout << "\t\tfragmentStoresAndAtomics : " std::cout << "\t\timageCubeArray : " << !!features.imageCubeArray << "\n";
<< !!features.fragmentStoresAndAtomics << "\n"; std::cout << "\t\tindependentBlend : " << !!features.independentBlend << "\n";
std::cout << "\t\tfullDrawIndexUint32 : " << !!features.fullDrawIndexUint32 std::cout << "\t\tinheritedQueries : " << !!features.inheritedQueries << "\n";
<< "\n"; std::cout << "\t\tlargePoints : " << !!features.largePoints << "\n";
std::cout << "\t\tgeometryShader : " << !!features.geometryShader
<< "\n";
std::cout << "\t\timageCubeArray : " << !!features.imageCubeArray
<< "\n";
std::cout << "\t\tindependentBlend : " << !!features.independentBlend
<< "\n";
std::cout << "\t\tinheritedQueries : " << !!features.inheritedQueries
<< "\n";
std::cout << "\t\tlargePoints : " << !!features.largePoints
<< "\n";
std::cout << "\t\tlogicOp : " << !!features.logicOp << "\n"; std::cout << "\t\tlogicOp : " << !!features.logicOp << "\n";
std::cout << "\t\tmultiDrawIndirect : " << !!features.multiDrawIndirect std::cout << "\t\tmultiDrawIndirect : " << !!features.multiDrawIndirect << "\n";
<< "\n"; std::cout << "\t\tmultiViewport : " << !!features.multiViewport << "\n";
std::cout << "\t\tmultiViewport : " << !!features.multiViewport std::cout << "\t\tocclusionQueryPrecise : " << !!features.occlusionQueryPrecise << "\n";
<< "\n"; std::cout << "\t\tpipelineStatisticsQuery : " << !!features.pipelineStatisticsQuery << "\n";
std::cout << "\t\tocclusionQueryPrecise : " std::cout << "\t\trobustBufferAccess : " << !!features.robustBufferAccess << "\n";
<< !!features.occlusionQueryPrecise << "\n"; std::cout << "\t\tsamplerAnisotropy : " << !!features.samplerAnisotropy << "\n";
std::cout << "\t\tpipelineStatisticsQuery : " std::cout << "\t\tsampleRateShading : " << !!features.sampleRateShading << "\n";
<< !!features.pipelineStatisticsQuery << "\n"; std::cout << "\t\tshaderClipDistance : " << !!features.shaderClipDistance << "\n";
std::cout << "\t\trobustBufferAccess : " << !!features.robustBufferAccess std::cout << "\t\tshaderCullDistance : " << !!features.shaderCullDistance << "\n";
<< "\n"; std::cout << "\t\tshaderFloat64 : " << !!features.shaderFloat64 << "\n";
std::cout << "\t\tsamplerAnisotropy : " << !!features.samplerAnisotropy std::cout << "\t\tshaderImageGatherExtended : " << !!features.shaderImageGatherExtended << "\n";
<< "\n"; std::cout << "\t\tshaderInt16 : " << !!features.shaderInt16 << "\n";
std::cout << "\t\tsampleRateShading : " << !!features.sampleRateShading std::cout << "\t\tshaderInt64 : " << !!features.shaderInt64 << "\n";
<< "\n"; std::cout << "\t\tshaderResourceMinLod : " << !!features.shaderResourceMinLod << "\n";
std::cout << "\t\tshaderClipDistance : " << !!features.shaderClipDistance std::cout << "\t\tshaderResourceResidency : " << !!features.shaderResourceResidency << "\n";
<< "\n"; std::cout << "\t\tshaderSampledImageArrayDynamicIndexing : " << !!features.shaderSampledImageArrayDynamicIndexing << "\n";
std::cout << "\t\tshaderCullDistance : " << !!features.shaderCullDistance std::cout << "\t\tshaderStorageBufferArrayDynamicIndexing : " << !!features.shaderStorageBufferArrayDynamicIndexing << "\n";
<< "\n"; std::cout << "\t\tshaderStorageImageArrayDynamicIndexing : " << !!features.shaderStorageImageArrayDynamicIndexing << "\n";
std::cout << "\t\tshaderFloat64 : " << !!features.shaderFloat64 std::cout << "\t\tshaderStorageImageExtendedFormats : " << !!features.shaderStorageImageExtendedFormats << "\n";
<< "\n"; std::cout << "\t\tshaderStorageImageMultisample : " << !!features.shaderStorageImageMultisample << "\n";
std::cout << "\t\tshaderImageGatherExtended : " std::cout << "\t\tshaderStorageImageReadWithoutFormat : " << !!features.shaderStorageImageReadWithoutFormat << "\n";
<< !!features.shaderImageGatherExtended << "\n"; std::cout << "\t\tshaderStorageImageWriteWithoutFormat : " << !!features.shaderStorageImageWriteWithoutFormat << "\n";
std::cout << "\t\tshaderInt16 : " << !!features.shaderInt16 std::cout << "\t\tshaderTessellationAndGeometryPointSize : " << !!features.shaderTessellationAndGeometryPointSize << "\n";
<< "\n"; std::cout << "\t\tshaderUniformBufferArrayDynamicIndexing : " << !!features.shaderUniformBufferArrayDynamicIndexing << "\n";
std::cout << "\t\tshaderInt64 : " << !!features.shaderInt64 std::cout << "\t\tsparseBinding : " << !!features.sparseBinding << "\n";
<< "\n"; std::cout << "\t\tsparseResidency16Samples : " << !!features.sparseResidency16Samples << "\n";
std::cout << "\t\tshaderResourceMinLod : " std::cout << "\t\tsparseResidency2Samples : " << !!features.sparseResidency2Samples << "\n";
<< !!features.shaderResourceMinLod << "\n"; std::cout << "\t\tsparseResidency4Samples : " << !!features.sparseResidency4Samples << "\n";
std::cout << "\t\tshaderResourceResidency : " std::cout << "\t\tsparseResidency8Samples : " << !!features.sparseResidency8Samples << "\n";
<< !!features.shaderResourceResidency << "\n"; std::cout << "\t\tsparseResidencyAliased : " << !!features.sparseResidencyAliased << "\n";
std::cout << "\t\tshaderSampledImageArrayDynamicIndexing : " std::cout << "\t\tsparseResidencyBuffer : " << !!features.sparseResidencyBuffer << "\n";
<< !!features.shaderSampledImageArrayDynamicIndexing << "\n"; std::cout << "\t\tsparseResidencyImage2D : " << !!features.sparseResidencyImage2D << "\n";
std::cout << "\t\tshaderStorageBufferArrayDynamicIndexing : " std::cout << "\t\tsparseResidencyImage3D : " << !!features.sparseResidencyImage3D << "\n";
<< !!features.shaderStorageBufferArrayDynamicIndexing << "\n"; std::cout << "\t\ttessellationShader : " << !!features.tessellationShader << "\n";
std::cout << "\t\tshaderStorageImageArrayDynamicIndexing : " std::cout << "\t\ttextureCompressionASTC_LDR : " << !!features.textureCompressionASTC_LDR << "\n";
<< !!features.shaderStorageImageArrayDynamicIndexing << "\n"; std::cout << "\t\ttextureCompressionBC : " << !!features.textureCompressionBC << "\n";
std::cout << "\t\tshaderStorageImageExtendedFormats : " std::cout << "\t\ttextureCompressionETC2 : " << !!features.textureCompressionETC2 << "\n";
<< !!features.shaderStorageImageExtendedFormats << "\n"; std::cout << "\t\tvariableMultisampleRate : " << !!features.variableMultisampleRate << "\n";
std::cout << "\t\tshaderStorageImageMultisample : " std::cout << "\t\tvertexPipelineStoresAndAtomics : " << !!features.vertexPipelineStoresAndAtomics << "\n";
<< !!features.shaderStorageImageMultisample << "\n";
std::cout << "\t\tshaderStorageImageReadWithoutFormat : "
<< !!features.shaderStorageImageReadWithoutFormat << "\n";
std::cout << "\t\tshaderStorageImageWriteWithoutFormat : "
<< !!features.shaderStorageImageWriteWithoutFormat << "\n";
std::cout << "\t\tshaderTessellationAndGeometryPointSize : "
<< !!features.shaderTessellationAndGeometryPointSize << "\n";
std::cout << "\t\tshaderUniformBufferArrayDynamicIndexing : "
<< !!features.shaderUniformBufferArrayDynamicIndexing << "\n";
std::cout << "\t\tsparseBinding : " << !!features.sparseBinding
<< "\n";
std::cout << "\t\tsparseResidency16Samples : "
<< !!features.sparseResidency16Samples << "\n";
std::cout << "\t\tsparseResidency2Samples : "
<< !!features.sparseResidency2Samples << "\n";
std::cout << "\t\tsparseResidency4Samples : "
<< !!features.sparseResidency4Samples << "\n";
std::cout << "\t\tsparseResidency8Samples : "
<< !!features.sparseResidency8Samples << "\n";
std::cout << "\t\tsparseResidencyAliased : "
<< !!features.sparseResidencyAliased << "\n";
std::cout << "\t\tsparseResidencyBuffer : "
<< !!features.sparseResidencyBuffer << "\n";
std::cout << "\t\tsparseResidencyImage2D : "
<< !!features.sparseResidencyImage2D << "\n";
std::cout << "\t\tsparseResidencyImage3D : "
<< !!features.sparseResidencyImage3D << "\n";
std::cout << "\t\ttessellationShader : " << !!features.tessellationShader
<< "\n";
std::cout << "\t\ttextureCompressionASTC_LDR : "
<< !!features.textureCompressionASTC_LDR << "\n";
std::cout << "\t\ttextureCompressionBC : "
<< !!features.textureCompressionBC << "\n";
std::cout << "\t\ttextureCompressionETC2 : "
<< !!features.textureCompressionETC2 << "\n";
std::cout << "\t\tvariableMultisampleRate : "
<< !!features.variableMultisampleRate << "\n";
std::cout << "\t\tvertexPipelineStoresAndAtomics : "
<< !!features.vertexPipelineStoresAndAtomics << "\n";
std::cout << "\t\twideLines : " << !!features.wideLines << "\n"; std::cout << "\t\twideLines : " << !!features.wideLines << "\n";
std::cout << "\n"; std::cout << "\n";
vk::PhysicalDevice16BitStorageFeatures const & sixteenBitStorageFeatures = vk::PhysicalDevice16BitStorageFeatures const & sixteenBitStorageFeatures = features2.get<vk::PhysicalDevice16BitStorageFeatures>();
features2.get<vk::PhysicalDevice16BitStorageFeatures>();
std::cout << "\t16BitStorageFeatures:\n"; std::cout << "\t16BitStorageFeatures:\n";
std::cout << "\t\tstorageBuffer16BitAccess : " std::cout << "\t\tstorageBuffer16BitAccess : " << !!sixteenBitStorageFeatures.storageBuffer16BitAccess << "\n";
<< !!sixteenBitStorageFeatures.storageBuffer16BitAccess << "\n"; std::cout << "\t\tstorageInputOutput16 : " << !!sixteenBitStorageFeatures.storageInputOutput16 << "\n";
std::cout << "\t\tstorageInputOutput16 : " std::cout << "\t\tstoragePushConstant16 : " << !!sixteenBitStorageFeatures.storagePushConstant16 << "\n";
<< !!sixteenBitStorageFeatures.storageInputOutput16 << "\n"; std::cout << "\t\tuniformAndStorageBuffer16BitAccess : " << !!sixteenBitStorageFeatures.uniformAndStorageBuffer16BitAccess << "\n";
std::cout << "\t\tstoragePushConstant16 : "
<< !!sixteenBitStorageFeatures.storagePushConstant16 << "\n";
std::cout << "\t\tuniformAndStorageBuffer16BitAccess : "
<< !!sixteenBitStorageFeatures.uniformAndStorageBuffer16BitAccess << "\n";
std::cout << "\n"; std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_KHR_8bit_storage" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_8bit_storage" ) )
{ {
vk::PhysicalDevice8BitStorageFeaturesKHR const & eightBitStorageFeatures = vk::PhysicalDevice8BitStorageFeaturesKHR const & eightBitStorageFeatures = features2.get<vk::PhysicalDevice8BitStorageFeaturesKHR>();
features2.get<vk::PhysicalDevice8BitStorageFeaturesKHR>();
std::cout << "\t8BitStorageFeatures:\n"; std::cout << "\t8BitStorageFeatures:\n";
std::cout << "\t\tstorageBuffer8BitAccess : " std::cout << "\t\tstorageBuffer8BitAccess : " << !!eightBitStorageFeatures.storageBuffer8BitAccess << "\n";
<< !!eightBitStorageFeatures.storageBuffer8BitAccess << "\n"; std::cout << "\t\tstoragePushConstant8 : " << !!eightBitStorageFeatures.storagePushConstant8 << "\n";
std::cout << "\t\tstoragePushConstant8 : " std::cout << "\t\tuniformAndStorageBuffer8BitAccess : " << !!eightBitStorageFeatures.uniformAndStorageBuffer8BitAccess << "\n";
<< !!eightBitStorageFeatures.storagePushConstant8 << "\n";
std::cout << "\t\tuniformAndStorageBuffer8BitAccess : "
<< !!eightBitStorageFeatures.uniformAndStorageBuffer8BitAccess << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_astc_decode_mode" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_astc_decode_mode" ) )
{ {
vk::PhysicalDeviceASTCDecodeFeaturesEXT const & astcDecodeFeatures = vk::PhysicalDeviceASTCDecodeFeaturesEXT const & astcDecodeFeatures = features2.get<vk::PhysicalDeviceASTCDecodeFeaturesEXT>();
features2.get<vk::PhysicalDeviceASTCDecodeFeaturesEXT>();
std::cout << "\tASTCDecodeFeature:\n"; std::cout << "\tASTCDecodeFeature:\n";
std::cout << "\t\tdecodeModeSharedExponent : " std::cout << "\t\tdecodeModeSharedExponent : " << !!astcDecodeFeatures.decodeModeSharedExponent << "\n";
<< !!astcDecodeFeatures.decodeModeSharedExponent << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -259,8 +195,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT const & blendOperationAdvancedFeatures = vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT const & blendOperationAdvancedFeatures =
features2.get<vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT>(); features2.get<vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT>();
std::cout << "\tBlendOperationAdvancedFeatures:\n"; std::cout << "\tBlendOperationAdvancedFeatures:\n";
std::cout << "\t\tadvancedBlendCoherentOperations : " std::cout << "\t\tadvancedBlendCoherentOperations : " << !!blendOperationAdvancedFeatures.advancedBlendCoherentOperations << "\n";
<< !!blendOperationAdvancedFeatures.advancedBlendCoherentOperations << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -269,22 +204,17 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT const & bufferDeviceAddressFeatures = vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT const & bufferDeviceAddressFeatures =
features2.get<vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT>(); features2.get<vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT>();
std::cout << "\tBufferDeviceAddressFeatures:\n"; std::cout << "\tBufferDeviceAddressFeatures:\n";
std::cout << "\t\tbufferDeviceAddress : " std::cout << "\t\tbufferDeviceAddress : " << !!bufferDeviceAddressFeatures.bufferDeviceAddress << "\n";
<< !!bufferDeviceAddressFeatures.bufferDeviceAddress << "\n"; std::cout << "\t\tbufferDeviceAddressCaptureReplay : " << !!bufferDeviceAddressFeatures.bufferDeviceAddressCaptureReplay << "\n";
std::cout << "\t\tbufferDeviceAddressCaptureReplay : " std::cout << "\t\tbufferDeviceAddressMultiDevice : " << !!bufferDeviceAddressFeatures.bufferDeviceAddressMultiDevice << "\n";
<< !!bufferDeviceAddressFeatures.bufferDeviceAddressCaptureReplay << "\n";
std::cout << "\t\tbufferDeviceAddressMultiDevice : "
<< !!bufferDeviceAddressFeatures.bufferDeviceAddressMultiDevice << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_AMD_device_coherent_memory" ) ) if ( vk::su::contains( extensionProperties, "VK_AMD_device_coherent_memory" ) )
{ {
vk::PhysicalDeviceCoherentMemoryFeaturesAMD const & coherentMemoryFeatures = vk::PhysicalDeviceCoherentMemoryFeaturesAMD const & coherentMemoryFeatures = features2.get<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>();
features2.get<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>();
std::cout << "\tCoherentMemoryFeatures:\n"; std::cout << "\tCoherentMemoryFeatures:\n";
std::cout << "\t\tdeviceCoherentMemory : " << !!coherentMemoryFeatures.deviceCoherentMemory std::cout << "\t\tdeviceCoherentMemory : " << !!coherentMemoryFeatures.deviceCoherentMemory << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -293,10 +223,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV const & computeShaderDerivativesFeatures = vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV const & computeShaderDerivativesFeatures =
features2.get<vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV>(); features2.get<vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV>();
std::cout << "\tComputeShaderDerivativeFeatures:\n"; std::cout << "\tComputeShaderDerivativeFeatures:\n";
std::cout << "\t\tcomputeDerivativeGroupLinear : " std::cout << "\t\tcomputeDerivativeGroupLinear : " << !!computeShaderDerivativesFeatures.computeDerivativeGroupLinear << "\n";
<< !!computeShaderDerivativesFeatures.computeDerivativeGroupLinear << "\n"; std::cout << "\t\tcomputeDerivativeGroupQuads : " << !!computeShaderDerivativesFeatures.computeDerivativeGroupQuads << "\n";
std::cout << "\t\tcomputeDerivativeGroupQuads : "
<< !!computeShaderDerivativesFeatures.computeDerivativeGroupQuads << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -305,32 +233,25 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceConditionalRenderingFeaturesEXT const & conditionalRenderingFeatures = vk::PhysicalDeviceConditionalRenderingFeaturesEXT const & conditionalRenderingFeatures =
features2.get<vk::PhysicalDeviceConditionalRenderingFeaturesEXT>(); features2.get<vk::PhysicalDeviceConditionalRenderingFeaturesEXT>();
std::cout << "\tConditionalRenderingFeatures:\n"; std::cout << "\tConditionalRenderingFeatures:\n";
std::cout << "\t\tconditionalRendering : " std::cout << "\t\tconditionalRendering : " << !!conditionalRenderingFeatures.conditionalRendering << "\n";
<< !!conditionalRenderingFeatures.conditionalRendering << "\n"; std::cout << "\t\tinheritedConditionalRendering : " << !!conditionalRenderingFeatures.inheritedConditionalRendering << "\n";
std::cout << "\t\tinheritedConditionalRendering : "
<< !!conditionalRenderingFeatures.inheritedConditionalRendering << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_NV_cooperative_matrix" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_cooperative_matrix" ) )
{ {
vk::PhysicalDeviceCooperativeMatrixFeaturesNV const & cooperativeMatrixFeatures = vk::PhysicalDeviceCooperativeMatrixFeaturesNV const & cooperativeMatrixFeatures = features2.get<vk::PhysicalDeviceCooperativeMatrixFeaturesNV>();
features2.get<vk::PhysicalDeviceCooperativeMatrixFeaturesNV>();
std::cout << "\tCooperativeMatrixFeatures:\n"; std::cout << "\tCooperativeMatrixFeatures:\n";
std::cout << "\t\tcooperativeMatrix : " std::cout << "\t\tcooperativeMatrix : " << !!cooperativeMatrixFeatures.cooperativeMatrix << "\n";
<< !!cooperativeMatrixFeatures.cooperativeMatrix << "\n"; std::cout << "\t\tcooperativeMatrixRobustBufferAccess : " << !!cooperativeMatrixFeatures.cooperativeMatrixRobustBufferAccess << "\n";
std::cout << "\t\tcooperativeMatrixRobustBufferAccess : "
<< !!cooperativeMatrixFeatures.cooperativeMatrixRobustBufferAccess << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_NV_corner_sampled_image" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_corner_sampled_image" ) )
{ {
vk::PhysicalDeviceCornerSampledImageFeaturesNV const & cornerSampledImageFeatures = vk::PhysicalDeviceCornerSampledImageFeaturesNV const & cornerSampledImageFeatures = features2.get<vk::PhysicalDeviceCornerSampledImageFeaturesNV>();
features2.get<vk::PhysicalDeviceCornerSampledImageFeaturesNV>();
std::cout << "\tCornerSampledImageFeatures:\n"; std::cout << "\tCornerSampledImageFeatures:\n";
std::cout << "\t\tcornerSampledImage : " << !!cornerSampledImageFeatures.cornerSampledImage std::cout << "\t\tcornerSampledImage : " << !!cornerSampledImageFeatures.cornerSampledImage << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -339,8 +260,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceCoverageReductionModeFeaturesNV const & coverageReductionModeFeatures = vk::PhysicalDeviceCoverageReductionModeFeaturesNV const & coverageReductionModeFeatures =
features2.get<vk::PhysicalDeviceCoverageReductionModeFeaturesNV>(); features2.get<vk::PhysicalDeviceCoverageReductionModeFeaturesNV>();
std::cout << "\tCoverageReductionModeFeatures:\n"; std::cout << "\tCoverageReductionModeFeatures:\n";
std::cout << "\t\tcoverageReductionMode : " std::cout << "\t\tcoverageReductionMode : " << !!coverageReductionModeFeatures.coverageReductionMode << "\n";
<< !!coverageReductionModeFeatures.coverageReductionMode << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -349,16 +269,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV const & dedicatedAllocationImageAliasingFeatures = vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV const & dedicatedAllocationImageAliasingFeatures =
features2.get<vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(); features2.get<vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>();
std::cout << "\tDedicatedAllocationAliasingFeatures:\n"; std::cout << "\tDedicatedAllocationAliasingFeatures:\n";
std::cout << "\t\tdedicatedAllocationImageAliasing : " std::cout << "\t\tdedicatedAllocationImageAliasing : " << !!dedicatedAllocationImageAliasingFeatures.dedicatedAllocationImageAliasing << "\n";
<< !!dedicatedAllocationImageAliasingFeatures.dedicatedAllocationImageAliasing
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_depth_clip_enable" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_depth_clip_enable" ) )
{ {
vk::PhysicalDeviceDepthClipEnableFeaturesEXT const & depthClipEnabledFeatures = vk::PhysicalDeviceDepthClipEnableFeaturesEXT const & depthClipEnabledFeatures = features2.get<vk::PhysicalDeviceDepthClipEnableFeaturesEXT>();
features2.get<vk::PhysicalDeviceDepthClipEnableFeaturesEXT>();
std::cout << "\tDepthClipEnabledFeatures:\n"; std::cout << "\tDepthClipEnabledFeatures:\n";
std::cout << "\t\tdepthClipEnable : " << !!depthClipEnabledFeatures.depthClipEnable << "\n"; std::cout << "\t\tdepthClipEnable : " << !!depthClipEnabledFeatures.depthClipEnable << "\n";
std::cout << "\n"; std::cout << "\n";
@ -366,84 +283,64 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_descriptor_indexing" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_descriptor_indexing" ) )
{ {
vk::PhysicalDeviceDescriptorIndexingFeaturesEXT const & descriptorIndexingFeatures = vk::PhysicalDeviceDescriptorIndexingFeaturesEXT const & descriptorIndexingFeatures = features2.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
features2.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
std::cout << "\tDescriptorIndexingFeatures:\n"; std::cout << "\tDescriptorIndexingFeatures:\n";
std::cout << "\t\tdescriptorBindingPartiallyBound : " std::cout << "\t\tdescriptorBindingPartiallyBound : " << !!descriptorIndexingFeatures.descriptorBindingPartiallyBound << "\n";
<< !!descriptorIndexingFeatures.descriptorBindingPartiallyBound << "\n"; std::cout << "\t\tdescriptorBindingSampledImageUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingSampledImageUpdateAfterBind
std::cout << "\t\tdescriptorBindingSampledImageUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingSampledImageUpdateAfterBind
<< "\n"; << "\n";
std::cout << "\t\tdescriptorBindingStorageBufferUpdateAfterBind : " std::cout << "\t\tdescriptorBindingStorageBufferUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingStorageBufferUpdateAfterBind
<< !!descriptorIndexingFeatures.descriptorBindingStorageBufferUpdateAfterBind
<< "\n"; << "\n";
std::cout << "\t\tdescriptorBindingStorageImageUpdateAfterBind : " std::cout << "\t\tdescriptorBindingStorageImageUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingStorageImageUpdateAfterBind
<< !!descriptorIndexingFeatures.descriptorBindingStorageImageUpdateAfterBind
<< "\n"; << "\n";
std::cout << "\t\tdescriptorBindingStorageTexelBufferUpdateAfterBind : " std::cout << "\t\tdescriptorBindingStorageTexelBufferUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingStorageTexelBufferUpdateAfterBind << !!descriptorIndexingFeatures.descriptorBindingStorageTexelBufferUpdateAfterBind << "\n";
<< "\n"; std::cout << "\t\tdescriptorBindingUniformBufferUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingUniformBufferUpdateAfterBind
std::cout << "\t\tdescriptorBindingUniformBufferUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingUniformBufferUpdateAfterBind
<< "\n"; << "\n";
std::cout << "\t\tdescriptorBindingUniformTexelBufferUpdateAfterBind : " std::cout << "\t\tdescriptorBindingUniformTexelBufferUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingUniformTexelBufferUpdateAfterBind << !!descriptorIndexingFeatures.descriptorBindingUniformTexelBufferUpdateAfterBind << "\n";
std::cout << "\t\tdescriptorBindingUpdateUnusedWhilePending : " << !!descriptorIndexingFeatures.descriptorBindingUpdateUnusedWhilePending
<< "\n"; << "\n";
std::cout << "\t\tdescriptorBindingUpdateUnusedWhilePending : " std::cout << "\t\tdescriptorBindingVariableDescriptorCount : " << !!descriptorIndexingFeatures.descriptorBindingVariableDescriptorCount
<< !!descriptorIndexingFeatures.descriptorBindingUpdateUnusedWhilePending << "\n";
std::cout << "\t\tdescriptorBindingVariableDescriptorCount : "
<< !!descriptorIndexingFeatures.descriptorBindingVariableDescriptorCount << "\n";
std::cout << "\t\truntimeDescriptorArray : "
<< !!descriptorIndexingFeatures.runtimeDescriptorArray << "\n";
std::cout << "\t\tshaderInputAttachmentArrayDynamicIndexing : "
<< !!descriptorIndexingFeatures.shaderInputAttachmentArrayDynamicIndexing << "\n";
std::cout << "\t\tshaderInputAttachmentArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderInputAttachmentArrayNonUniformIndexing
<< "\n"; << "\n";
std::cout << "\t\tshaderSampledImageArrayNonUniformIndexing : " std::cout << "\t\truntimeDescriptorArray : " << !!descriptorIndexingFeatures.runtimeDescriptorArray << "\n";
<< !!descriptorIndexingFeatures.shaderSampledImageArrayNonUniformIndexing << "\n"; std::cout << "\t\tshaderInputAttachmentArrayDynamicIndexing : " << !!descriptorIndexingFeatures.shaderInputAttachmentArrayDynamicIndexing
std::cout << "\t\tshaderStorageBufferArrayNonUniformIndexing : " << "\n";
<< !!descriptorIndexingFeatures.shaderStorageBufferArrayNonUniformIndexing << "\n"; std::cout << "\t\tshaderInputAttachmentArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderInputAttachmentArrayNonUniformIndexing
std::cout << "\t\tshaderStorageImageArrayNonUniformIndexing : " << "\n";
<< !!descriptorIndexingFeatures.shaderStorageImageArrayNonUniformIndexing << "\n"; std::cout << "\t\tshaderSampledImageArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderSampledImageArrayNonUniformIndexing
std::cout << "\t\tshaderStorageTexelBufferArrayDynamicIndexing : " << "\n";
<< !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayDynamicIndexing std::cout << "\t\tshaderStorageBufferArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderStorageBufferArrayNonUniformIndexing
<< "\n";
std::cout << "\t\tshaderStorageImageArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderStorageImageArrayNonUniformIndexing
<< "\n";
std::cout << "\t\tshaderStorageTexelBufferArrayDynamicIndexing : " << !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayDynamicIndexing
<< "\n"; << "\n";
std::cout << "\t\tshaderStorageTexelBufferArrayNonUniformIndexing : " std::cout << "\t\tshaderStorageTexelBufferArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayNonUniformIndexing << !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayNonUniformIndexing << "\n";
std::cout << "\t\tshaderUniformBufferArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderUniformBufferArrayNonUniformIndexing
<< "\n"; << "\n";
std::cout << "\t\tshaderUniformBufferArrayNonUniformIndexing : " std::cout << "\t\tshaderUniformTexelBufferArrayDynamicIndexing : " << !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayDynamicIndexing
<< !!descriptorIndexingFeatures.shaderUniformBufferArrayNonUniformIndexing << "\n";
std::cout << "\t\tshaderUniformTexelBufferArrayDynamicIndexing : "
<< !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayDynamicIndexing
<< "\n"; << "\n";
std::cout << "\t\tshaderUniformTexelBufferArrayNonUniformIndexing : " std::cout << "\t\tshaderUniformTexelBufferArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayNonUniformIndexing << !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayNonUniformIndexing << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_NV_scissor_exclusive" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_scissor_exclusive" ) )
{ {
vk::PhysicalDeviceExclusiveScissorFeaturesNV const & exclusiveScissorFeatures = vk::PhysicalDeviceExclusiveScissorFeaturesNV const & exclusiveScissorFeatures = features2.get<vk::PhysicalDeviceExclusiveScissorFeaturesNV>();
features2.get<vk::PhysicalDeviceExclusiveScissorFeaturesNV>();
std::cout << "\tExclusiveScissorFeatures:\n"; std::cout << "\tExclusiveScissorFeatures:\n";
std::cout << "\t\texclusiveScissor : " << !!exclusiveScissorFeatures.exclusiveScissor std::cout << "\t\texclusiveScissor : " << !!exclusiveScissorFeatures.exclusiveScissor << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_fragment_density_map" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_fragment_density_map" ) )
{ {
vk::PhysicalDeviceFragmentDensityMapFeaturesEXT const & fragmentDensityMapFeatures = vk::PhysicalDeviceFragmentDensityMapFeaturesEXT const & fragmentDensityMapFeatures = features2.get<vk::PhysicalDeviceFragmentDensityMapFeaturesEXT>();
features2.get<vk::PhysicalDeviceFragmentDensityMapFeaturesEXT>();
std::cout << "\tFragmentDensityMapFeatures:\n"; std::cout << "\tFragmentDensityMapFeatures:\n";
std::cout << "\t\tfragmentDensityMap : " std::cout << "\t\tfragmentDensityMap : " << !!fragmentDensityMapFeatures.fragmentDensityMap << "\n";
<< !!fragmentDensityMapFeatures.fragmentDensityMap << "\n"; std::cout << "\t\tfragmentDensityMapDynamic : " << !!fragmentDensityMapFeatures.fragmentDensityMapDynamic << "\n";
std::cout << "\t\tfragmentDensityMapDynamic : " std::cout << "\t\tfragmentDensityMapNonSubsampledImages : " << !!fragmentDensityMapFeatures.fragmentDensityMapNonSubsampledImages << "\n";
<< !!fragmentDensityMapFeatures.fragmentDensityMapDynamic << "\n";
std::cout << "\t\tfragmentDensityMapNonSubsampledImages : "
<< !!fragmentDensityMapFeatures.fragmentDensityMapNonSubsampledImages << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -452,8 +349,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV const & fragmentShaderBarycentricFeatures = vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV const & fragmentShaderBarycentricFeatures =
features2.get<vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV>(); features2.get<vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV>();
std::cout << "\tFragmentShaderBarycentricFeatures:\n"; std::cout << "\tFragmentShaderBarycentricFeatures:\n";
std::cout << "\t\tfragmentShaderBarycentric : " std::cout << "\t\tfragmentShaderBarycentric : " << !!fragmentShaderBarycentricFeatures.fragmentShaderBarycentric << "\n";
<< !!fragmentShaderBarycentricFeatures.fragmentShaderBarycentric << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -462,19 +358,15 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT const & fragmentShaderInterlockFeatures = vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT const & fragmentShaderInterlockFeatures =
features2.get<vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT>(); features2.get<vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT>();
std::cout << "\tFragmentShaderInterlockFeatures:\n"; std::cout << "\tFragmentShaderInterlockFeatures:\n";
std::cout << "\t\tfragmentShaderPixelInterlock : " std::cout << "\t\tfragmentShaderPixelInterlock : " << !!fragmentShaderInterlockFeatures.fragmentShaderPixelInterlock << "\n";
<< !!fragmentShaderInterlockFeatures.fragmentShaderPixelInterlock << "\n"; std::cout << "\t\tfragmentShaderSampleInterlock : " << !!fragmentShaderInterlockFeatures.fragmentShaderSampleInterlock << "\n";
std::cout << "\t\tfragmentShaderSampleInterlock : " std::cout << "\t\tfragmentShaderShadingRateInterlock : " << !!fragmentShaderInterlockFeatures.fragmentShaderShadingRateInterlock << "\n";
<< !!fragmentShaderInterlockFeatures.fragmentShaderSampleInterlock << "\n";
std::cout << "\t\tfragmentShaderShadingRateInterlock : "
<< !!fragmentShaderInterlockFeatures.fragmentShaderShadingRateInterlock << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_host_query_reset" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_host_query_reset" ) )
{ {
vk::PhysicalDeviceHostQueryResetFeaturesEXT const & hostQueryResetFeatures = vk::PhysicalDeviceHostQueryResetFeaturesEXT const & hostQueryResetFeatures = features2.get<vk::PhysicalDeviceHostQueryResetFeaturesEXT>();
features2.get<vk::PhysicalDeviceHostQueryResetFeaturesEXT>();
std::cout << "\tHostQueryResetFeatures:\n"; std::cout << "\tHostQueryResetFeatures:\n";
std::cout << "\t\thostQueryReset : " << !!hostQueryResetFeatures.hostQueryReset << "\n"; std::cout << "\t\thostQueryReset : " << !!hostQueryResetFeatures.hostQueryReset << "\n";
std::cout << "\n"; std::cout << "\n";
@ -485,15 +377,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceImagelessFramebufferFeaturesKHR const & imagelessFramebufferFeatures = vk::PhysicalDeviceImagelessFramebufferFeaturesKHR const & imagelessFramebufferFeatures =
features2.get<vk::PhysicalDeviceImagelessFramebufferFeaturesKHR>(); features2.get<vk::PhysicalDeviceImagelessFramebufferFeaturesKHR>();
std::cout << "\tImagelessFramebufferFeatures:\n"; std::cout << "\tImagelessFramebufferFeatures:\n";
std::cout << "\t\timagelessFramebuffer : " std::cout << "\t\timagelessFramebuffer : " << !!imagelessFramebufferFeatures.imagelessFramebuffer << "\n";
<< !!imagelessFramebufferFeatures.imagelessFramebuffer << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_index_type_uint8" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_index_type_uint8" ) )
{ {
vk::PhysicalDeviceIndexTypeUint8FeaturesEXT const & indexTypeUint8Features = vk::PhysicalDeviceIndexTypeUint8FeaturesEXT const & indexTypeUint8Features = features2.get<vk::PhysicalDeviceIndexTypeUint8FeaturesEXT>();
features2.get<vk::PhysicalDeviceIndexTypeUint8FeaturesEXT>();
std::cout << "\tIndexTypeUint8Features:\n"; std::cout << "\tIndexTypeUint8Features:\n";
std::cout << "\t\tindexTypeUint8 : " << !!indexTypeUint8Features.indexTypeUint8 << "\n"; std::cout << "\t\tindexTypeUint8 : " << !!indexTypeUint8Features.indexTypeUint8 << "\n";
std::cout << "\n"; std::cout << "\n";
@ -501,41 +391,30 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_inline_uniform_block" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_inline_uniform_block" ) )
{ {
vk::PhysicalDeviceInlineUniformBlockFeaturesEXT const & inlineUniformBlockFeatures = vk::PhysicalDeviceInlineUniformBlockFeaturesEXT const & inlineUniformBlockFeatures = features2.get<vk::PhysicalDeviceInlineUniformBlockFeaturesEXT>();
features2.get<vk::PhysicalDeviceInlineUniformBlockFeaturesEXT>();
std::cout << "\tInlineUniformBlockFeatures:\n"; std::cout << "\tInlineUniformBlockFeatures:\n";
std::cout << "\t\tdescriptorBindingInlineUniformBlockUpdateAfterBind : " std::cout << "\t\tdescriptorBindingInlineUniformBlockUpdateAfterBind : "
<< !!inlineUniformBlockFeatures.descriptorBindingInlineUniformBlockUpdateAfterBind << !!inlineUniformBlockFeatures.descriptorBindingInlineUniformBlockUpdateAfterBind << "\n";
<< "\n"; std::cout << "\t\tinlineUniformBlock : " << !!inlineUniformBlockFeatures.inlineUniformBlock << "\n";
std::cout << "\t\tinlineUniformBlock : "
<< !!inlineUniformBlockFeatures.inlineUniformBlock << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_line_rasterization" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_line_rasterization" ) )
{ {
vk::PhysicalDeviceLineRasterizationFeaturesEXT const & lineRasterizationFeatures = vk::PhysicalDeviceLineRasterizationFeaturesEXT const & lineRasterizationFeatures = features2.get<vk::PhysicalDeviceLineRasterizationFeaturesEXT>();
features2.get<vk::PhysicalDeviceLineRasterizationFeaturesEXT>();
std::cout << "\tLineRasterizationFeatures:\n"; std::cout << "\tLineRasterizationFeatures:\n";
std::cout << "\t\tbresenhamLines : " << !!lineRasterizationFeatures.bresenhamLines std::cout << "\t\tbresenhamLines : " << !!lineRasterizationFeatures.bresenhamLines << "\n";
<< "\n"; std::cout << "\t\trectangularLines : " << !!lineRasterizationFeatures.rectangularLines << "\n";
std::cout << "\t\trectangularLines : " std::cout << "\t\tsmoothLines : " << !!lineRasterizationFeatures.smoothLines << "\n";
<< !!lineRasterizationFeatures.rectangularLines << "\n"; std::cout << "\t\tstippledBresenhamLines : " << !!lineRasterizationFeatures.stippledBresenhamLines << "\n";
std::cout << "\t\tsmoothLines : " << !!lineRasterizationFeatures.smoothLines std::cout << "\t\tstippledRectangularLines : " << !!lineRasterizationFeatures.stippledRectangularLines << "\n";
<< "\n"; std::cout << "\t\tstippledSmoothLines : " << !!lineRasterizationFeatures.stippledSmoothLines << "\n";
std::cout << "\t\tstippledBresenhamLines : "
<< !!lineRasterizationFeatures.stippledBresenhamLines << "\n";
std::cout << "\t\tstippledRectangularLines : "
<< !!lineRasterizationFeatures.stippledRectangularLines << "\n";
std::cout << "\t\tstippledSmoothLines : "
<< !!lineRasterizationFeatures.stippledSmoothLines << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_memory_priority" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_memory_priority" ) )
{ {
vk::PhysicalDeviceMemoryPriorityFeaturesEXT const & memoryPriorityFeatures = vk::PhysicalDeviceMemoryPriorityFeaturesEXT const & memoryPriorityFeatures = features2.get<vk::PhysicalDeviceMemoryPriorityFeaturesEXT>();
features2.get<vk::PhysicalDeviceMemoryPriorityFeaturesEXT>();
std::cout << "\tMemoryPriorityFeatures:\n"; std::cout << "\tMemoryPriorityFeatures:\n";
std::cout << "\t\tmemoryPriority : " << !!memoryPriorityFeatures.memoryPriority << "\n"; std::cout << "\t\tmemoryPriority : " << !!memoryPriorityFeatures.memoryPriority << "\n";
std::cout << "\n"; std::cout << "\n";
@ -543,22 +422,18 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_NV_mesh_shader" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_mesh_shader" ) )
{ {
vk::PhysicalDeviceMeshShaderFeaturesNV const & meshShaderFeatures = vk::PhysicalDeviceMeshShaderFeaturesNV const & meshShaderFeatures = features2.get<vk::PhysicalDeviceMeshShaderFeaturesNV>();
features2.get<vk::PhysicalDeviceMeshShaderFeaturesNV>();
std::cout << "\tMeshShaderFeatures:\n"; std::cout << "\tMeshShaderFeatures:\n";
std::cout << "\t\tmeshShader : " << !!meshShaderFeatures.meshShader << "\n"; std::cout << "\t\tmeshShader : " << !!meshShaderFeatures.meshShader << "\n";
std::cout << "\t\ttaskShader : " << !!meshShaderFeatures.taskShader << "\n"; std::cout << "\t\ttaskShader : " << !!meshShaderFeatures.taskShader << "\n";
std::cout << "\n"; std::cout << "\n";
} }
vk::PhysicalDeviceMultiviewFeatures const & multiviewFeatures = vk::PhysicalDeviceMultiviewFeatures const & multiviewFeatures = features2.get<vk::PhysicalDeviceMultiviewFeatures>();
features2.get<vk::PhysicalDeviceMultiviewFeatures>();
std::cout << "\tMultiviewFeatures:\n"; std::cout << "\tMultiviewFeatures:\n";
std::cout << "\t\tmultiview : " << !!multiviewFeatures.multiview << "\n"; std::cout << "\t\tmultiview : " << !!multiviewFeatures.multiview << "\n";
std::cout << "\t\tmultiviewGeometryShader : " std::cout << "\t\tmultiviewGeometryShader : " << !!multiviewFeatures.multiviewGeometryShader << "\n";
<< !!multiviewFeatures.multiviewGeometryShader << "\n"; std::cout << "\t\tmultiviewTessellationShader : " << !!multiviewFeatures.multiviewTessellationShader << "\n";
std::cout << "\t\tmultiviewTessellationShader : "
<< !!multiviewFeatures.multiviewTessellationShader << "\n";
std::cout << "\n"; std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_KHR_pipeline_executable_properties" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_pipeline_executable_properties" ) )
@ -566,13 +441,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR const & pipelineExecutablePropertiesFeatures = vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR const & pipelineExecutablePropertiesFeatures =
features2.get<vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(); features2.get<vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR>();
std::cout << "\tPipelineExectuablePropertiesFeatures:\n"; std::cout << "\tPipelineExectuablePropertiesFeatures:\n";
std::cout << "\t\tpipelineExecutableInfo : " std::cout << "\t\tpipelineExecutableInfo : " << !!pipelineExecutablePropertiesFeatures.pipelineExecutableInfo << "\n";
<< !!pipelineExecutablePropertiesFeatures.pipelineExecutableInfo << "\n";
std::cout << "\n"; std::cout << "\n";
} }
vk::PhysicalDeviceProtectedMemoryFeatures const & protectedMemoryFeatures = vk::PhysicalDeviceProtectedMemoryFeatures const & protectedMemoryFeatures = features2.get<vk::PhysicalDeviceProtectedMemoryFeatures>();
features2.get<vk::PhysicalDeviceProtectedMemoryFeatures>();
std::cout << "\tProtectedMemoryFeatures:\n"; std::cout << "\tProtectedMemoryFeatures:\n";
std::cout << "\t\tprotectedMemory : " << !!protectedMemoryFeatures.protectedMemory << "\n"; std::cout << "\t\tprotectedMemory : " << !!protectedMemoryFeatures.protectedMemory << "\n";
std::cout << "\n"; std::cout << "\n";
@ -582,37 +455,30 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV const & representativeFragmentTestFeatures = vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV const & representativeFragmentTestFeatures =
features2.get<vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV>(); features2.get<vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV>();
std::cout << "\tRepresentativeFragmentTestFeatures:\n"; std::cout << "\tRepresentativeFragmentTestFeatures:\n";
std::cout << "\t\trepresentativeFragmentTest : " std::cout << "\t\trepresentativeFragmentTest : " << !!representativeFragmentTestFeatures.representativeFragmentTest << "\n";
<< !!representativeFragmentTestFeatures.representativeFragmentTest << "\n";
std::cout << "\n"; std::cout << "\n";
} }
vk::PhysicalDeviceSamplerYcbcrConversionFeatures const & samplerYcbcrConversionFeatures = vk::PhysicalDeviceSamplerYcbcrConversionFeatures const & samplerYcbcrConversionFeatures =
features2.get<vk::PhysicalDeviceSamplerYcbcrConversionFeatures>(); features2.get<vk::PhysicalDeviceSamplerYcbcrConversionFeatures>();
std::cout << "\tSamplerYcbcrConversionFeatures:\n"; std::cout << "\tSamplerYcbcrConversionFeatures:\n";
std::cout << "\t\tsamplerYcbcrConversion : " std::cout << "\t\tsamplerYcbcrConversion : " << !!samplerYcbcrConversionFeatures.samplerYcbcrConversion << "\n";
<< !!samplerYcbcrConversionFeatures.samplerYcbcrConversion << "\n";
std::cout << "\n"; std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_EXT_scalar_block_layout" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_scalar_block_layout" ) )
{ {
vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT const & scalarBlockLayoutFeatures = vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT const & scalarBlockLayoutFeatures = features2.get<vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT>();
features2.get<vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT>();
std::cout << "\tScalarBlockLayoutFeatures:\n"; std::cout << "\tScalarBlockLayoutFeatures:\n";
std::cout << "\t\tscalarBlockLayout : " << !!scalarBlockLayoutFeatures.scalarBlockLayout std::cout << "\t\tscalarBlockLayout : " << !!scalarBlockLayoutFeatures.scalarBlockLayout << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_KHR_shader_atomic_int64" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_shader_atomic_int64" ) )
{ {
vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR const & shaderAtomicInt64Features = vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR const & shaderAtomicInt64Features = features2.get<vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR>();
features2.get<vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR>();
std::cout << "\tShaderAtomicInt64Features:\n"; std::cout << "\tShaderAtomicInt64Features:\n";
std::cout << "\t\tshaderBufferInt64Atomics : " std::cout << "\t\tshaderBufferInt64Atomics : " << !!shaderAtomicInt64Features.shaderBufferInt64Atomics << "\n";
<< !!shaderAtomicInt64Features.shaderBufferInt64Atomics << "\n"; std::cout << "\t\tshaderSharedInt64Atomics : " << !!shaderAtomicInt64Features.shaderSharedInt64Atomics << "\n";
std::cout << "\t\tshaderSharedInt64Atomics : "
<< !!shaderAtomicInt64Features.shaderSharedInt64Atomics << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -621,22 +487,18 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT const & shaderDemoteToHelperInvocationFeatures = vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT const & shaderDemoteToHelperInvocationFeatures =
features2.get<vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(); features2.get<vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>();
std::cout << "\tShaderDemoteToHelperInvocationFeatures:\n"; std::cout << "\tShaderDemoteToHelperInvocationFeatures:\n";
std::cout << "\t\tshaderDemoteToHelperInvocation : " std::cout << "\t\tshaderDemoteToHelperInvocation : " << !!shaderDemoteToHelperInvocationFeatures.shaderDemoteToHelperInvocation << "\n";
<< !!shaderDemoteToHelperInvocationFeatures.shaderDemoteToHelperInvocation << "\n";
std::cout << "\n"; std::cout << "\n";
} }
vk::PhysicalDeviceShaderDrawParametersFeatures const & shaderDrawParametersFeature = vk::PhysicalDeviceShaderDrawParametersFeatures const & shaderDrawParametersFeature = features2.get<vk::PhysicalDeviceShaderDrawParametersFeatures>();
features2.get<vk::PhysicalDeviceShaderDrawParametersFeatures>();
std::cout << "\tShaderDrawParametersFeature:\n"; std::cout << "\tShaderDrawParametersFeature:\n";
std::cout << "\t\tshaderDrawParameters : " std::cout << "\t\tshaderDrawParameters : " << !!shaderDrawParametersFeature.shaderDrawParameters << "\n";
<< !!shaderDrawParametersFeature.shaderDrawParameters << "\n";
std::cout << "\n"; std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_KHR_shader_float16_int8" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_shader_float16_int8" ) )
{ {
vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR const & shaderFloat16Int8Features = vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR const & shaderFloat16Int8Features = features2.get<vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR>();
features2.get<vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR>();
std::cout << "\tShaderFloat16Int8Features:\n"; std::cout << "\tShaderFloat16Int8Features:\n";
std::cout << "\t\tshaderFloat16 : " << !!shaderFloat16Int8Features.shaderFloat16 << "\n"; std::cout << "\t\tshaderFloat16 : " << !!shaderFloat16Int8Features.shaderFloat16 << "\n";
std::cout << "\t\tshaderInt8 : " << !!shaderFloat16Int8Features.shaderInt8 << "\n"; std::cout << "\t\tshaderInt8 : " << !!shaderFloat16Int8Features.shaderInt8 << "\n";
@ -648,8 +510,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderImageFootprintFeaturesNV const & shaderImageFootprintFeatures = vk::PhysicalDeviceShaderImageFootprintFeaturesNV const & shaderImageFootprintFeatures =
features2.get<vk::PhysicalDeviceShaderImageFootprintFeaturesNV>(); features2.get<vk::PhysicalDeviceShaderImageFootprintFeaturesNV>();
std::cout << "\tShaderImageFootprintFeatures:\n"; std::cout << "\tShaderImageFootprintFeatures:\n";
std::cout << "\t\timageFootprint : " << !!shaderImageFootprintFeatures.imageFootprint std::cout << "\t\timageFootprint : " << !!shaderImageFootprintFeatures.imageFootprint << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -658,18 +519,15 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL const & shaderIntegerFunctions2Features = vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL const & shaderIntegerFunctions2Features =
features2.get<vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(); features2.get<vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>();
std::cout << "\tShaderIntegerFunctions2Features:\n"; std::cout << "\tShaderIntegerFunctions2Features:\n";
std::cout << "\t\tshaderIntegerFunctions2 : " std::cout << "\t\tshaderIntegerFunctions2 : " << !!shaderIntegerFunctions2Features.shaderIntegerFunctions2 << "\n";
<< !!shaderIntegerFunctions2Features.shaderIntegerFunctions2 << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_NV_shader_sm_builtins" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_shader_sm_builtins" ) )
{ {
vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV const & shaderSMBuiltinsFeatures = vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV const & shaderSMBuiltinsFeatures = features2.get<vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV>();
features2.get<vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV>();
std::cout << "\tShaderSMBuiltinsFeatures:\n"; std::cout << "\tShaderSMBuiltinsFeatures:\n";
std::cout << "\t\tshaderSMBuiltins : " << !!shaderSMBuiltinsFeatures.shaderSMBuiltins std::cout << "\t\tshaderSMBuiltins : " << !!shaderSMBuiltinsFeatures.shaderSMBuiltins << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -678,20 +536,16 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR const & shaderSubgroupExtendedTypesFeatures = vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR const & shaderSubgroupExtendedTypesFeatures =
features2.get<vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR>(); features2.get<vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR>();
std::cout << "\tShaderSubgroupExtendedTypeFeatures:\n"; std::cout << "\tShaderSubgroupExtendedTypeFeatures:\n";
std::cout << "\t\tshaderSubgroupExtendedTypes : " std::cout << "\t\tshaderSubgroupExtendedTypes : " << !!shaderSubgroupExtendedTypesFeatures.shaderSubgroupExtendedTypes << "\n";
<< !!shaderSubgroupExtendedTypesFeatures.shaderSubgroupExtendedTypes << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_NV_shading_rate_image" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_shading_rate_image" ) )
{ {
vk::PhysicalDeviceShadingRateImageFeaturesNV const & shadingRateImageFeatures = vk::PhysicalDeviceShadingRateImageFeaturesNV const & shadingRateImageFeatures = features2.get<vk::PhysicalDeviceShadingRateImageFeaturesNV>();
features2.get<vk::PhysicalDeviceShadingRateImageFeaturesNV>();
std::cout << "\tShadingRateImageFeatures:\n"; std::cout << "\tShadingRateImageFeatures:\n";
std::cout << "\t\tshadingRateCoarseSampleOrder : " std::cout << "\t\tshadingRateCoarseSampleOrder : " << !!shadingRateImageFeatures.shadingRateCoarseSampleOrder << "\n";
<< !!shadingRateImageFeatures.shadingRateCoarseSampleOrder << "\n"; std::cout << "\t\tshadingRateImage : " << !!shadingRateImageFeatures.shadingRateImage << "\n";
std::cout << "\t\tshadingRateImage : "
<< !!shadingRateImageFeatures.shadingRateImage << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -700,10 +554,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT const & subgroupSizeControlFeatures = vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT const & subgroupSizeControlFeatures =
features2.get<vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT>(); features2.get<vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT>();
std::cout << "\tSubgroupSizeControlFeatures:\n"; std::cout << "\tSubgroupSizeControlFeatures:\n";
std::cout << "\t\tcomputeFullSubgroups : " std::cout << "\t\tcomputeFullSubgroups : " << !!subgroupSizeControlFeatures.computeFullSubgroups << "\n";
<< !!subgroupSizeControlFeatures.computeFullSubgroups << "\n"; std::cout << "\t\tsubgroupSizeControl : " << !!subgroupSizeControlFeatures.subgroupSizeControl << "\n";
std::cout << "\t\tsubgroupSizeControl : "
<< !!subgroupSizeControlFeatures.subgroupSizeControl << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -712,8 +564,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT const & texelBufferAlignmentFeatures = vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT const & texelBufferAlignmentFeatures =
features2.get<vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT>(); features2.get<vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT>();
std::cout << "\tTexelBufferAlignmentFeatures:\n"; std::cout << "\tTexelBufferAlignmentFeatures:\n";
std::cout << "\t\ttexelBufferAlignment : " std::cout << "\t\ttexelBufferAlignment : " << !!texelBufferAlignmentFeatures.texelBufferAlignment << "\n";
<< !!texelBufferAlignmentFeatures.texelBufferAlignment << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -722,29 +573,24 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT const & textureCompressionASTCHDRFeatures = vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT const & textureCompressionASTCHDRFeatures =
features2.get<vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT>(); features2.get<vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT>();
std::cout << "\tTextureCompressionASTCHHRFeatures:\n"; std::cout << "\tTextureCompressionASTCHHRFeatures:\n";
std::cout << "\t\ttextureCompressionASTC_HDR : " std::cout << "\t\ttextureCompressionASTC_HDR : " << !!textureCompressionASTCHDRFeatures.textureCompressionASTC_HDR << "\n";
<< !!textureCompressionASTCHDRFeatures.textureCompressionASTC_HDR << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_KHR_timeline_semaphore" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_timeline_semaphore" ) )
{ {
vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR const & timelineSemaphoreFeatures = vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR const & timelineSemaphoreFeatures = features2.get<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
features2.get<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
std::cout << "\tTimelineSemaphoreFeatures:\n"; std::cout << "\tTimelineSemaphoreFeatures:\n";
std::cout << "\t\ttimelineSemaphore :" << !!timelineSemaphoreFeatures.timelineSemaphore std::cout << "\t\ttimelineSemaphore :" << !!timelineSemaphoreFeatures.timelineSemaphore << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_EXT_transform_feedback" ) ) if ( vk::su::contains( extensionProperties, "VK_EXT_transform_feedback" ) )
{ {
vk::PhysicalDeviceTransformFeedbackFeaturesEXT const & transformFeedbackFeatures = vk::PhysicalDeviceTransformFeedbackFeaturesEXT const & transformFeedbackFeatures = features2.get<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>();
features2.get<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>();
std::cout << "\tTransformFeedbackFeatures:\n"; std::cout << "\tTransformFeedbackFeatures:\n";
std::cout << "\t\tgeometryStreams : " << !!transformFeedbackFeatures.geometryStreams << "\n"; std::cout << "\t\tgeometryStreams : " << !!transformFeedbackFeatures.geometryStreams << "\n";
std::cout << "\t\ttransformFeedback : " << !!transformFeedbackFeatures.transformFeedback std::cout << "\t\ttransformFeedback : " << !!transformFeedbackFeatures.transformFeedback << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -753,20 +599,16 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR const & uniformBufferStandardLayoutFeatures = vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR const & uniformBufferStandardLayoutFeatures =
features2.get<vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR>(); features2.get<vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR>();
std::cout << "\tUniformBufferStandardLayoutFeatures:\n"; std::cout << "\tUniformBufferStandardLayoutFeatures:\n";
std::cout << "\t\tuniformBufferStandardLayout : " std::cout << "\t\tuniformBufferStandardLayout : " << !!uniformBufferStandardLayoutFeatures.uniformBufferStandardLayout << "\n";
<< !!uniformBufferStandardLayoutFeatures.uniformBufferStandardLayout << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_KHR_variable_pointers" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_variable_pointers" ) )
{ {
vk::PhysicalDeviceVariablePointersFeatures const & variablePointersFeatures = vk::PhysicalDeviceVariablePointersFeatures const & variablePointersFeatures = features2.get<vk::PhysicalDeviceVariablePointersFeatures>();
features2.get<vk::PhysicalDeviceVariablePointersFeatures>();
std::cout << "\tVariablePointersFeatures:\n"; std::cout << "\tVariablePointersFeatures:\n";
std::cout << "\t\tvariablePointers : " std::cout << "\t\tvariablePointers : " << !!variablePointersFeatures.variablePointers << "\n";
<< !!variablePointersFeatures.variablePointers << "\n"; std::cout << "\t\tvariablePointersStorageBuffer : " << !!variablePointersFeatures.variablePointersStorageBuffer << "\n";
std::cout << "\t\tvariablePointersStorageBuffer : "
<< !!variablePointersFeatures.variablePointersStorageBuffer << "\n";
std::cout << "\n"; std::cout << "\n";
} }
@ -775,35 +617,27 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT const & vertexAttributeDivisorFeatures = vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT const & vertexAttributeDivisorFeatures =
features2.get<vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT>(); features2.get<vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT>();
std::cout << "\tVertexAttributeDivisorFeature:\n"; std::cout << "\tVertexAttributeDivisorFeature:\n";
std::cout << "\t\tvertexAttributeInstanceRateDivisor : " std::cout << "\t\tvertexAttributeInstanceRateDivisor : " << !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateDivisor << "\n";
<< !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateDivisor << "\n"; std::cout << "\t\tvertexAttributeInstanceRateZeroDivisor : " << !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateZeroDivisor << "\n";
std::cout << "\t\tvertexAttributeInstanceRateZeroDivisor : "
<< !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateZeroDivisor << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_KHR_vulkan_memory_model" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_vulkan_memory_model" ) )
{ {
vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR const & vulkanMemoryModelFeatures = vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR const & vulkanMemoryModelFeatures = features2.get<vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR>();
features2.get<vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR>();
std::cout << "\tVulkanMemoryModelFeatures:\n"; std::cout << "\tVulkanMemoryModelFeatures:\n";
std::cout << "\t\tvulkanMemoryModel : " std::cout << "\t\tvulkanMemoryModel : " << !!vulkanMemoryModelFeatures.vulkanMemoryModel << "\n";
<< !!vulkanMemoryModelFeatures.vulkanMemoryModel << "\n"; std::cout << "\t\tvulkanMemoryModelAvailabilityVisibilityChains : " << !!vulkanMemoryModelFeatures.vulkanMemoryModelAvailabilityVisibilityChains
std::cout << "\t\tvulkanMemoryModelAvailabilityVisibilityChains : "
<< !!vulkanMemoryModelFeatures.vulkanMemoryModelAvailabilityVisibilityChains
<< "\n"; << "\n";
std::cout << "\t\tvulkanMemoryModelDeviceScope : " std::cout << "\t\tvulkanMemoryModelDeviceScope : " << !!vulkanMemoryModelFeatures.vulkanMemoryModelDeviceScope << "\n";
<< !!vulkanMemoryModelFeatures.vulkanMemoryModelDeviceScope << "\n";
std::cout << "\n"; std::cout << "\n";
} }
if ( vk::su::contains( extensionProperties, "VK_KHR_sampler_ycbcr_conversion" ) ) if ( vk::su::contains( extensionProperties, "VK_KHR_sampler_ycbcr_conversion" ) )
{ {
vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT const & ycbcrImageArraysFeatures = vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT const & ycbcrImageArraysFeatures = features2.get<vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT>();
features2.get<vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT>();
std::cout << "\tYcbcrImageArraysFeatures:\n"; std::cout << "\tYcbcrImageArraysFeatures:\n";
std::cout << "\t\tycbcrImageArrays : " << !!ycbcrImageArraysFeatures.ycbcrImageArrays std::cout << "\t\tycbcrImageArrays : " << !!ycbcrImageArraysFeatures.ycbcrImageArrays << "\n";
<< "\n";
std::cout << "\n"; std::cout << "\n";
} }
} }

View File

@ -29,8 +29,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, {}, VK_API_VERSION_1_1 ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -61,21 +60,18 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties(); std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
// get the first index into queueFamiliyProperties which supports graphics // get the first index into queueFamiliyProperties which supports graphics
auto propertyIterator = std::find_if( auto propertyIterator = std::find_if( queueFamilyProperties.begin(),
queueFamilyProperties.begin(), queueFamilyProperties.end(), []( vk::QueueFamilyProperties const & qfp ) { queueFamilyProperties.end(),
return qfp.queueFlags & vk::QueueFlagBits::eGraphics; []( vk::QueueFamilyProperties const & qfp ) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; } );
} );
size_t graphicsQueueFamilyIndex = std::distance( queueFamilyProperties.begin(), propertyIterator ); size_t graphicsQueueFamilyIndex = std::distance( queueFamilyProperties.begin(), propertyIterator );
assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() ); assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() );
// create a Device // create a Device
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority ); vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo );
vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo );
vk::DeviceGroupDeviceCreateInfo deviceGroupDeviceCreateInfo( groupProperties[i].physicalDeviceCount, vk::DeviceGroupDeviceCreateInfo deviceGroupDeviceCreateInfo( groupProperties[i].physicalDeviceCount, groupProperties[i].physicalDevices );
groupProperties[i].physicalDevices );
deviceCreateInfo.pNext = &deviceGroupDeviceCreateInfo; deviceCreateInfo.pNext = &deviceGroupDeviceCreateInfo;
vk::Device device = physicalDevice.createDevice( deviceCreateInfo ); vk::Device device = physicalDevice.createDevice( deviceCreateInfo );

View File

@ -52,8 +52,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, {}, VK_API_VERSION_1_1 ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
// enumerate the physicalDevices // enumerate the physicalDevices
@ -64,18 +63,13 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ ) for ( size_t i = 0; i < physicalDevices.size(); i++ )
{ {
// some properties are only valid, if a corresponding extension is available! // some properties are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties = std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
physicalDevices[i].enumerateDeviceExtensionProperties(); bool containsMemoryBudget = vk::su::contains( extensionProperties, "VK_EXT_memory_budget" );
bool containsMemoryBudget = vk::su::contains( extensionProperties, "VK_EXT_memory_budget" );
std::cout << "PhysicalDevice " << i << "\n"; std::cout << "PhysicalDevice " << i << "\n";
auto memoryProperties2 = auto memoryProperties2 = physicalDevices[i].getMemoryProperties2<vk::PhysicalDeviceMemoryProperties2, vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
physicalDevices[i] vk::PhysicalDeviceMemoryProperties const & memoryProperties = memoryProperties2.get<vk::PhysicalDeviceMemoryProperties2>().memoryProperties;
.getMemoryProperties2<vk::PhysicalDeviceMemoryProperties2, vk::PhysicalDeviceMemoryBudgetPropertiesEXT>(); vk::PhysicalDeviceMemoryBudgetPropertiesEXT const & memoryBudgetProperties = memoryProperties2.get<vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
vk::PhysicalDeviceMemoryProperties const & memoryProperties =
memoryProperties2.get<vk::PhysicalDeviceMemoryProperties2>().memoryProperties;
vk::PhysicalDeviceMemoryBudgetPropertiesEXT const & memoryBudgetProperties =
memoryProperties2.get<vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
std::cout << "memoryHeapCount: " << memoryProperties.memoryHeapCount << "\n"; std::cout << "memoryHeapCount: " << memoryProperties.memoryHeapCount << "\n";
for ( uint32_t j = 0; j < memoryProperties.memoryHeapCount; j++ ) for ( uint32_t j = 0; j < memoryProperties.memoryHeapCount; j++ )
{ {

File diff suppressed because it is too large Load Diff

View File

@ -31,8 +31,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, {}, VK_API_VERSION_1_1 ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
// enumerate the physicalDevices // enumerate the physicalDevices
@ -44,21 +43,18 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ ) for ( size_t i = 0; i < physicalDevices.size(); i++ )
{ {
// some features are only valid, if a corresponding extension is available! // some features are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties = std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << "\n"; std::cout << "PhysicalDevice " << i << "\n";
// need to explicitly specify all the template arguments for getQueueFamilyProperties2 to make the compiler happy // need to explicitly specify all the template arguments for getQueueFamilyProperties2 to make the compiler happy
using Chain = vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyCheckpointPropertiesNV>; using Chain = vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyCheckpointPropertiesNV>;
auto queueFamilyProperties2 = auto queueFamilyProperties2 = physicalDevices[i].getQueueFamilyProperties2<Chain, std::allocator<Chain>, vk::DispatchLoaderDynamic>();
physicalDevices[i].getQueueFamilyProperties2<Chain, std::allocator<Chain>, vk::DispatchLoaderDynamic>();
for ( size_t j = 0; j < queueFamilyProperties2.size(); j++ ) for ( size_t j = 0; j < queueFamilyProperties2.size(); j++ )
{ {
std::cout << "\t" std::cout << "\t"
<< "QueueFamily " << j << "\n"; << "QueueFamily " << j << "\n";
vk::QueueFamilyProperties const & properties = vk::QueueFamilyProperties const & properties = queueFamilyProperties2[j].get<vk::QueueFamilyProperties2>().queueFamilyProperties;
queueFamilyProperties2[j].get<vk::QueueFamilyProperties2>().queueFamilyProperties;
std::cout << "\t\t" std::cout << "\t\t"
<< "QueueFamilyProperties:\n"; << "QueueFamilyProperties:\n";
std::cout << "\t\t\t" std::cout << "\t\t\t"
@ -68,20 +64,17 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "\t\t\t" std::cout << "\t\t\t"
<< "timestampValidBits = " << properties.timestampValidBits << "\n"; << "timestampValidBits = " << properties.timestampValidBits << "\n";
std::cout << "\t\t\t" std::cout << "\t\t\t"
<< "minImageTransferGranularity = " << properties.minImageTransferGranularity.width << " x " << "minImageTransferGranularity = " << properties.minImageTransferGranularity.width << " x " << properties.minImageTransferGranularity.height
<< properties.minImageTransferGranularity.height << " x " << " x " << properties.minImageTransferGranularity.depth << "\n";
<< properties.minImageTransferGranularity.depth << "\n";
std::cout << "\n"; std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_NV_device_diagnostic_checkpoints" ) ) if ( vk::su::contains( extensionProperties, "VK_NV_device_diagnostic_checkpoints" ) )
{ {
vk::QueueFamilyCheckpointPropertiesNV const & checkpointProperties = vk::QueueFamilyCheckpointPropertiesNV const & checkpointProperties = queueFamilyProperties2[j].get<vk::QueueFamilyCheckpointPropertiesNV>();
queueFamilyProperties2[j].get<vk::QueueFamilyCheckpointPropertiesNV>();
std::cout << "\t\t" std::cout << "\t\t"
<< "CheckPointPropertiesNV:\n"; << "CheckPointPropertiesNV:\n";
std::cout << "\t\t\t" std::cout << "\t\t\t"
<< "checkpointExecutionStageMask = " << "checkpointExecutionStageMask = " << vk::to_string( checkpointProperties.checkpointExecutionStageMask ) << "\n";
<< vk::to_string( checkpointProperties.checkpointExecutionStageMask ) << "\n";
std::cout << "\n"; std::cout << "\n";
} }
} }

View File

@ -73,8 +73,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
@ -82,15 +81,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -99,8 +95,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -111,47 +106,36 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) ); textureData.setImage( device, commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
device, vk::su::createDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass = vk::su::createRenderPass(
device, device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData( vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool( vk::DescriptorPool descriptorPool =
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front(); vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -286,35 +270,32 @@ int main( int /*argc*/, char ** /*argv*/ )
} }
// Feed the initial cache data into cache creation // Feed the initial cache data into cache creation
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCache pipelineCache =
vk::PipelineCacheCreateInfo( vk::PipelineCacheCreateFlags(), startCacheSize, startCacheData ) ); device.createPipelineCache( vk::PipelineCacheCreateInfo( vk::PipelineCacheCreateFlags(), startCacheSize, startCacheData ) );
// Free our initialData now that pipeline cache has been created // Free our initialData now that pipeline cache has been created
free( startCacheData ); free( startCacheData );
startCacheData = NULL; startCacheData = NULL;
// Time (roughly) taken to create the graphics pipeline // Time (roughly) taken to create the graphics pipeline
timestamp_t start = getMilliseconds(); timestamp_t start = getMilliseconds();
vk::Pipeline graphicsPipeline = vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
vk::su::createGraphicsPipeline( device, pipelineCache,
pipelineCache, std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( vertexShaderModule, nullptr ), std::make_pair( fragmentShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ), sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass ); timestamp_t elapsed = getMilliseconds() - start;
timestamp_t elapsed = getMilliseconds() - start;
std::cout << " vkCreateGraphicsPipeline time: " << (double)elapsed << " ms\n"; std::cout << " vkCreateGraphicsPipeline time: " << (double)elapsed << " ms\n";
vk::Semaphore imageAcquiredSemaphore = vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::ResultValue<uint32_t> currentBuffer = vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
@ -323,20 +304,14 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer.beginRenderPass( commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo( vk::RenderPassBeginInfo( renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, {} ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, {} );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -352,14 +327,11 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
vk::Result result = vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -42,23 +42,19 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -67,8 +63,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -79,47 +74,36 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() ); textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
device, vk::su::createDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass = vk::su::createRenderPass(
device, device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData( vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool( vk::DescriptorPool descriptorPool =
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front(); vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() ); vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
@ -131,13 +115,11 @@ int main( int /*argc*/, char ** /*argv*/ )
// Second pipeline has a modified fragment shader and sets the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag. // Second pipeline has a modified fragment shader and sets the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag.
std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = { std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "main" ), vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule, "main" )
vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule, "main" )
}; };
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( texturedCubeData[0] ) ); vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( texturedCubeData[0] ) );
std::array<vk::VertexInputAttributeDescription, 2> vertexInputAttributeDescriptions = { std::array<vk::VertexInputAttributeDescription, 2> vertexInputAttributeDescriptions = {
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ), vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 ) vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
@ -145,41 +127,31 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
vk::PipelineVertexInputStateCreateFlags(), vertexInputBindingDescription, vertexInputAttributeDescriptions ); vk::PipelineVertexInputStateCreateFlags(), vertexInputBindingDescription, vertexInputAttributeDescriptions );
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateFlags(),
vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList ); vk::PrimitiveTopology::eTriangleList );
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( vk::PipelineRasterizationStateCreateFlags(),
vk::PipelineRasterizationStateCreateFlags(), false,
false, false,
false, vk::PolygonMode::eFill,
vk::PolygonMode::eFill, vk::CullModeFlagBits::eBack,
vk::CullModeFlagBits::eBack, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, false,
false, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f );
1.0f );
vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( {}, vk::SampleCountFlagBits::e1 ); vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( {}, vk::SampleCountFlagBits::e1 );
vk::StencilOpState stencilOpState( vk::StencilOpState stencilOpState( vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo( vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(
vk::PipelineDepthStencilStateCreateFlags(), vk::PipelineDepthStencilStateCreateFlags(), true, true, vk::CompareOp::eLessOrEqual, false, false, stencilOpState, stencilOpState );
true,
true,
vk::CompareOp::eLessOrEqual,
false,
false,
stencilOpState,
stencilOpState );
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB |
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA ); vk::ColorComponentFlagBits::eA );
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false, vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false,
vk::BlendFactor::eZero, vk::BlendFactor::eZero,
vk::BlendFactor::eZero, vk::BlendFactor::eZero,
@ -188,15 +160,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::BlendFactor::eZero, vk::BlendFactor::eZero,
vk::BlendOp::eAdd, vk::BlendOp::eAdd,
colorComponentFlags ); colorComponentFlags );
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(), vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(
false, vk::PipelineColorBlendStateCreateFlags(), false, vk::LogicOp::eNoOp, pipelineColorBlendAttachmentState, { { 1.0f, 1.0f, 1.0f, 1.0f } } );
vk::LogicOp::eNoOp,
pipelineColorBlendAttachmentState,
{ { 1.0f, 1.0f, 1.0f, 1.0f } } );
std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(), vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(), dynamicStates );
dynamicStates );
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlagBits::eAllowDerivatives, vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlagBits::eAllowDerivatives,
pipelineShaderStageCreateInfos, pipelineShaderStageCreateInfos,
@ -213,8 +181,7 @@ int main( int /*argc*/, char ** /*argv*/ )
renderPass ); renderPass );
vk::Pipeline basePipeline; vk::Pipeline basePipeline;
vk::ResultValue<vk::Pipeline> rvPipeline = vk::ResultValue<vk::Pipeline> rvPipeline = device.createGraphicsPipeline( pipelineCache, graphicsPipelineCreateInfo );
device.createGraphicsPipeline( pipelineCache, graphicsPipelineCreateInfo );
switch ( rvPipeline.result ) switch ( rvPipeline.result )
{ {
case vk::Result::eSuccess: basePipeline = std::move( rvPipeline.value ); break; case vk::Result::eSuccess: basePipeline = std::move( rvPipeline.value ); break;
@ -241,13 +208,12 @@ void main()
// Convert GLSL to SPIR-V // Convert GLSL to SPIR-V
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule fragmentShaderModule2 = vk::ShaderModule fragmentShaderModule2 = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C_2 );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C_2 );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
// Modify pipeline info to reflect derivation // Modify pipeline info to reflect derivation
pipelineShaderStageCreateInfos[1] = vk::PipelineShaderStageCreateInfo( pipelineShaderStageCreateInfos[1] =
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule2, "main" ); vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule2, "main" );
graphicsPipelineCreateInfo.flags = vk::PipelineCreateFlagBits::eDerivative; graphicsPipelineCreateInfo.flags = vk::PipelineCreateFlagBits::eDerivative;
graphicsPipelineCreateInfo.basePipelineHandle = basePipeline; graphicsPipelineCreateInfo.basePipelineHandle = basePipeline;
graphicsPipelineCreateInfo.basePipelineIndex = -1; graphicsPipelineCreateInfo.basePipelineIndex = -1;
@ -266,12 +232,10 @@ void main()
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
vk::Semaphore imageAcquiredSemaphore = vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
// Get the index of the next available swapchain image // Get the index of the next available swapchain image
vk::ResultValue<uint32_t> currentBuffer = vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
@ -280,20 +244,14 @@ void main()
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer.beginRenderPass( commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo( vk::RenderPassBeginInfo( renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, derivedPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, derivedPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, {} ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, {} );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -309,14 +267,11 @@ void main()
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
vk::Result result = vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -83,23 +83,19 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -108,59 +104,48 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent ); vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass = vk::su::createRenderPass(
device, device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData( vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
// Create binding and layout for the following, matching contents of shader // Create binding and layout for the following, matching contents of shader
// binding 0 = uniform buffer (MVP) // binding 0 = uniform buffer (MVP)
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
// Set up our push constant range, which mirrors the declaration of // Set up our push constant range, which mirrors the declaration of
vk::PushConstantRange pushConstantRanges( vk::ShaderStageFlagBits::eFragment, 0, 8 ); vk::PushConstantRange pushConstantRanges( vk::ShaderStageFlagBits::eFragment, 0, 8 );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout =
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout, pushConstantRanges ) ); device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout, pushConstantRanges ) );
// Create a single pool to contain data for our descriptor set // Create a single pool to contain data for our descriptor set
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorType::eCombinedImageSampler, 1 ) }; vk::DescriptorPool descriptorPool =
vk::DescriptorPool descriptorPool = device.createDescriptorPool( device.createDescriptorPool( vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
// Populate descriptor sets // Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
@ -168,37 +153,33 @@ int main( int /*argc*/, char ** /*argv*/ )
// Populate with info about our uniform buffer for MVP // Populate with info about our uniform buffer for MVP
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::WriteDescriptorSet writeDescriptorSet( vk::WriteDescriptorSet writeDescriptorSet( descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo );
descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr ); device.updateDescriptorSets( writeDescriptorSet, nullptr );
// Create our push constant data, which matches shader expectations // Create our push constant data, which matches shader expectations
std::array<unsigned, 2> pushConstants = { { (unsigned)2, (unsigned)0x3F800000 } }; std::array<unsigned, 2> pushConstants = { { (unsigned)2, (unsigned)0x3F800000 } };
// Ensure we have enough room for push constant data // Ensure we have enough room for push constant data
assert( ( sizeof( pushConstants ) <= physicalDevice.getProperties().limits.maxPushConstantsSize ) && assert( ( sizeof( pushConstants ) <= physicalDevice.getProperties().limits.maxPushConstantsSize ) && "Too many push constants" );
"Too many push constants" );
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
commandBuffer.pushConstants<unsigned>( pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, pushConstants ); commandBuffer.pushConstants<unsigned>( pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, pushConstants );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() ); vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
device, pipelineCache,
pipelineCache, std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( vertexShaderModule, nullptr ), std::make_pair( fragmentShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ), sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
vk::ResultValue<uint32_t> currentBuffer = vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
@ -206,22 +187,15 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass, vk::RenderPassBeginInfo renderPassBeginInfo(
framebuffers[currentBuffer.value], renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -237,14 +211,11 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
vk::Result result = vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -35,8 +35,7 @@ int main( int /*argc*/, char ** /*argv*/ )
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 ) #if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
// initialize the DipatchLoaderDynamic to use // initialize the DipatchLoaderDynamic to use
static vk::DynamicLoader dl; static vk::DynamicLoader dl;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr ); VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
#endif #endif
@ -45,9 +44,9 @@ int main( int /*argc*/, char ** /*argv*/ )
// To use PUSH_DESCRIPTOR, you must also specify GET_PHYSICAL_DEVICE_PROPERTIES_2 // To use PUSH_DESCRIPTOR, you must also specify GET_PHYSICAL_DEVICE_PROPERTIES_2
std::vector<vk::ExtensionProperties> extensionProperties = vk::enumerateInstanceExtensionProperties(); std::vector<vk::ExtensionProperties> extensionProperties = vk::enumerateInstanceExtensionProperties();
auto propertyIterator = auto propertyIterator =
std::find_if( extensionProperties.begin(), extensionProperties.end(), []( vk::ExtensionProperties ep ) { std::find_if( extensionProperties.begin(),
return ( strcmp( ep.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ) == 0 ); extensionProperties.end(),
} ); []( vk::ExtensionProperties ep ) { return ( strcmp( ep.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ) == 0 ); } );
if ( propertyIterator == extensionProperties.end() ) if ( propertyIterator == extensionProperties.end() )
{ {
std::cout << "No GET_PHYSICAL_DEVICE_PROPERTIES_2 extension" << std::endl; std::cout << "No GET_PHYSICAL_DEVICE_PROPERTIES_2 extension" << std::endl;
@ -59,18 +58,16 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, instanceExtensions ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, instanceExtensions );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
// Once instance is created, need to make sure the extension is available // Once instance is created, need to make sure the extension is available
extensionProperties = physicalDevice.enumerateDeviceExtensionProperties(); extensionProperties = physicalDevice.enumerateDeviceExtensionProperties();
propertyIterator = propertyIterator = std::find_if( extensionProperties.begin(),
std::find_if( extensionProperties.begin(), extensionProperties.end(), []( vk::ExtensionProperties ep ) { extensionProperties.end(),
return ( strcmp( ep.extensionName, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME ) == 0 ); []( vk::ExtensionProperties ep ) { return ( strcmp( ep.extensionName, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME ) == 0 ); } );
} );
if ( propertyIterator == extensionProperties.end() ) if ( propertyIterator == extensionProperties.end() )
{ {
std::cout << "No extension for push descriptors" << std::endl; std::cout << "No extension for push descriptors" << std::endl;
@ -82,15 +79,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) ); vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first ); vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer = vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
.front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 ); vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 ); vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -99,8 +93,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device, device,
surfaceData.surface, surfaceData.surface,
surfaceData.extent, surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eTransferSrc,
{}, {},
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
@ -111,92 +104,69 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() ); textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer ); glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix ); vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
// Need to specify that descriptor set layout will be for push descriptors // Need to specify that descriptor set layout will be for push descriptors
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::DescriptorSetLayout descriptorSetLayout =
device, vk::su::createDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } }, { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } },
vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR ); vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass( vk::RenderPass renderPass = vk::su::createRenderPass(
device, device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData( vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ); vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() ); vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
vk::su::createGraphicsPipeline( device, pipelineCache,
pipelineCache, std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( vertexShaderModule, nullptr ), std::make_pair( fragmentShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ), sizeof( texturedCubeData[0] ),
sizeof( texturedCubeData[0] ), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } }, vk::FrontFace::eClockwise,
vk::FrontFace::eClockwise, true,
true, pipelineLayout,
pipelineLayout, renderPass );
renderPass );
// Get the index of the next available swapchain image: // Get the index of the next available swapchain image:
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
vk::ResultValue<uint32_t> currentBuffer = vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass, vk::RenderPassBeginInfo renderPassBeginInfo(
framebuffers[currentBuffer.value], renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo( vk::DescriptorImageInfo imageInfo( textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal ); vk::WriteDescriptorSet writeDescriptorSets[2] = { vk::WriteDescriptorSet( {}, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet writeDescriptorSets[2] = { vk::WriteDescriptorSet( {}, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo ) };
vk::WriteDescriptorSet( {}, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( {}, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
};
// this call is from an extension and needs the dynamic dispatcher !! // this call is from an extension and needs the dynamic dispatcher !!
commandBuffer.pushDescriptorSetKHR( commandBuffer.pushDescriptorSetKHR( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, { 2, writeDescriptorSets } );
vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, { 2, writeDescriptorSets } );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.draw( 12 * 3, 1, 0, 0 ); commandBuffer.draw( 12 * 3, 1, 0, 0 );
@ -212,14 +182,11 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
vk::Result result = vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

@ -105,15 +105,13 @@ namespace vk
return m_windowSize; return m_windowSize;
} }
CameraManipulator::Action CameraManipulator::Action CameraManipulator::mouseMove( glm::ivec2 const & position, MouseButton mouseButton, ModifierFlags & modifiers )
CameraManipulator::mouseMove( glm::ivec2 const & position, MouseButton mouseButton, ModifierFlags & modifiers )
{ {
Action curAction = Action::None; Action curAction = Action::None;
switch ( mouseButton ) switch ( mouseButton )
{ {
case MouseButton::Left: case MouseButton::Left:
if ( ( ( modifiers & ModifierFlagBits::Ctrl ) && ( modifiers & ModifierFlagBits::Shift ) ) || if ( ( ( modifiers & ModifierFlagBits::Ctrl ) && ( modifiers & ModifierFlagBits::Shift ) ) || ( modifiers & ModifierFlagBits::Alt ) )
( modifiers & ModifierFlagBits::Alt ) )
{ {
curAction = m_mode == Mode::Examine ? Action::LookAround : Action::Orbit; curAction = m_mode == Mode::Examine ? Action::LookAround : Action::Orbit;
} }
@ -140,9 +138,7 @@ namespace vk
return curAction; return curAction;
} }
void CameraManipulator::setLookat( const glm::vec3 & cameraPosition, void CameraManipulator::setLookat( const glm::vec3 & cameraPosition, const glm::vec3 & centerPosition, const glm::vec3 & upVector )
const glm::vec3 & centerPosition,
const glm::vec3 & upVector )
{ {
m_cameraPosition = cameraPosition; m_cameraPosition = cameraPosition;
m_centerPosition = centerPosition; m_centerPosition = centerPosition;

View File

@ -91,13 +91,13 @@ namespace vk
glm::vec3 const & getUpVector() const; glm::vec3 const & getUpVector() const;
glm::u32vec2 const & getWindowSize() const; glm::u32vec2 const & getWindowSize() const;
Action mouseMove( glm::ivec2 const & position, MouseButton mouseButton, ModifierFlags & modifiers ); Action mouseMove( glm::ivec2 const & position, MouseButton mouseButton, ModifierFlags & modifiers );
void setLookat( const glm::vec3 & cameraPosition, const glm::vec3 & centerPosition, const glm::vec3 & upVector ); void setLookat( const glm::vec3 & cameraPosition, const glm::vec3 & centerPosition, const glm::vec3 & upVector );
void setMode( Mode mode ); void setMode( Mode mode );
void setMousePosition( glm::ivec2 const & position ); void setMousePosition( glm::ivec2 const & position );
void setRoll( float roll ); // roll in radians void setRoll( float roll ); // roll in radians
void setSpeed( float speed ); void setSpeed( float speed );
void setWindowSize( glm::ivec2 const & size ); void setWindowSize( glm::ivec2 const & size );
void wheel( int value ); void wheel( int value );
private: private:
void dolly( glm::vec2 const & delta ); void dolly( glm::vec2 const & delta );

View File

@ -54,17 +54,9 @@ static char const * EngineName = "Vulkan.hpp";
struct GeometryInstanceData struct GeometryInstanceData
{ {
GeometryInstanceData( glm::mat4x4 const & transform_, GeometryInstanceData(
uint32_t instanceID_, glm::mat4x4 const & transform_, uint32_t instanceID_, uint8_t mask_, uint32_t instanceOffset_, uint8_t flags_, uint64_t accelerationStructureHandle_ )
uint8_t mask_, : instanceId( instanceID_ ), mask( mask_ ), instanceOffset( instanceOffset_ ), flags( flags_ ), accelerationStructureHandle( accelerationStructureHandle_ )
uint32_t instanceOffset_,
uint8_t flags_,
uint64_t accelerationStructureHandle_ )
: instanceId( instanceID_ )
, mask( mask_ )
, instanceOffset( instanceOffset_ )
, flags( flags_ )
, accelerationStructureHandle( accelerationStructureHandle_ )
{ {
assert( !( instanceID_ & 0xFF000000 ) && !( instanceOffset_ & 0xFF000000 ) ); assert( !( instanceID_ & 0xFF000000 ) && !( instanceOffset_ & 0xFF000000 ) );
memcpy( transform, &transform_, 12 * sizeof( float ) ); memcpy( transform, &transform_, 12 * sizeof( float ) );
@ -104,12 +96,11 @@ struct AccelerationStructureData
std::unique_ptr<vk::su::BufferData> instanceBufferData; std::unique_ptr<vk::su::BufferData> instanceBufferData;
}; };
AccelerationStructureData AccelerationStructureData createAccelerationStructureData( vk::PhysicalDevice const & physicalDevice,
createAccelerationStructureData( vk::PhysicalDevice const & physicalDevice, vk::Device const & device,
vk::Device const & device, vk::CommandBuffer const & commandBuffer,
vk::CommandBuffer const & commandBuffer, std::vector<std::pair<vk::AccelerationStructureNV, glm::mat4x4>> const & instances,
std::vector<std::pair<vk::AccelerationStructureNV, glm::mat4x4>> const & instances, std::vector<vk::GeometryNV> const & geometries )
std::vector<vk::GeometryNV> const & geometries )
{ {
assert( instances.empty() ^ geometries.empty() ); assert( instances.empty() ^ geometries.empty() );
@ -117,47 +108,32 @@ AccelerationStructureData
vk::AccelerationStructureTypeNV accelerationStructureType = vk::AccelerationStructureTypeNV accelerationStructureType =
instances.empty() ? vk::AccelerationStructureTypeNV::eBottomLevel : vk::AccelerationStructureTypeNV::eTopLevel; instances.empty() ? vk::AccelerationStructureTypeNV::eBottomLevel : vk::AccelerationStructureTypeNV::eTopLevel;
vk::AccelerationStructureInfoNV accelerationStructureInfo( vk::AccelerationStructureInfoNV accelerationStructureInfo( accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
accelerationStructureData.accelerationStructure = accelerationStructureData.accelerationStructure =
device.createAccelerationStructureNV( vk::AccelerationStructureCreateInfoNV( 0, accelerationStructureInfo ) ); device.createAccelerationStructureNV( vk::AccelerationStructureCreateInfoNV( 0, accelerationStructureInfo ) );
vk::AccelerationStructureMemoryRequirementsInfoNV objectRequirements( vk::AccelerationStructureMemoryRequirementsInfoNV objectRequirements( vk::AccelerationStructureMemoryRequirementsTypeNV::eObject,
vk::AccelerationStructureMemoryRequirementsTypeNV::eObject, accelerationStructureData.accelerationStructure ); accelerationStructureData.accelerationStructure );
vk::DeviceSize resultSizeInBytes = vk::DeviceSize resultSizeInBytes = device.getAccelerationStructureMemoryRequirementsNV( objectRequirements ).memoryRequirements.size;
device.getAccelerationStructureMemoryRequirementsNV( objectRequirements ).memoryRequirements.size;
assert( 0 < resultSizeInBytes ); assert( 0 < resultSizeInBytes );
accelerationStructureData.resultBufferData = accelerationStructureData.resultBufferData = std::unique_ptr<vk::su::BufferData>(
std::unique_ptr<vk::su::BufferData>( new vk::su::BufferData( physicalDevice, new vk::su::BufferData( physicalDevice, device, resultSizeInBytes, vk::BufferUsageFlagBits::eRayTracingNV, vk::MemoryPropertyFlagBits::eDeviceLocal ) );
device,
resultSizeInBytes,
vk::BufferUsageFlagBits::eRayTracingNV,
vk::MemoryPropertyFlagBits::eDeviceLocal ) );
vk::AccelerationStructureMemoryRequirementsInfoNV buildScratchRequirements( vk::AccelerationStructureMemoryRequirementsInfoNV buildScratchRequirements( vk::AccelerationStructureMemoryRequirementsTypeNV::eBuildScratch,
vk::AccelerationStructureMemoryRequirementsTypeNV::eBuildScratch, accelerationStructureData.accelerationStructure ); accelerationStructureData.accelerationStructure );
vk::AccelerationStructureMemoryRequirementsInfoNV updateScratchRequirements( vk::AccelerationStructureMemoryRequirementsInfoNV updateScratchRequirements( vk::AccelerationStructureMemoryRequirementsTypeNV::eUpdateScratch,
vk::AccelerationStructureMemoryRequirementsTypeNV::eUpdateScratch, accelerationStructureData.accelerationStructure );
accelerationStructureData.accelerationStructure ); vk::DeviceSize scratchSizeInBytes = std::max( device.getAccelerationStructureMemoryRequirementsNV( buildScratchRequirements ).memoryRequirements.size,
vk::DeviceSize scratchSizeInBytes = std::max( device.getAccelerationStructureMemoryRequirementsNV( updateScratchRequirements ).memoryRequirements.size );
device.getAccelerationStructureMemoryRequirementsNV( buildScratchRequirements ).memoryRequirements.size,
device.getAccelerationStructureMemoryRequirementsNV( updateScratchRequirements ).memoryRequirements.size );
assert( 0 < scratchSizeInBytes ); assert( 0 < scratchSizeInBytes );
accelerationStructureData.scratchBufferData = accelerationStructureData.scratchBufferData = std::unique_ptr<vk::su::BufferData>(
std::unique_ptr<vk::su::BufferData>( new vk::su::BufferData( physicalDevice, new vk::su::BufferData( physicalDevice, device, scratchSizeInBytes, vk::BufferUsageFlagBits::eRayTracingNV, vk::MemoryPropertyFlagBits::eDeviceLocal ) );
device,
scratchSizeInBytes,
vk::BufferUsageFlagBits::eRayTracingNV,
vk::MemoryPropertyFlagBits::eDeviceLocal ) );
if ( !instances.empty() ) if ( !instances.empty() )
{ {
accelerationStructureData.instanceBufferData = accelerationStructureData.instanceBufferData = std::unique_ptr<vk::su::BufferData>(
std::unique_ptr<vk::su::BufferData>( new vk::su::BufferData( physicalDevice, new vk::su::BufferData( physicalDevice, device, instances.size() * sizeof( GeometryInstanceData ), vk::BufferUsageFlagBits::eRayTracingNV ) );
device,
instances.size() * sizeof( GeometryInstanceData ),
vk::BufferUsageFlagBits::eRayTracingNV ) );
std::vector<GeometryInstanceData> geometryInstanceData; std::vector<GeometryInstanceData> geometryInstanceData;
for ( size_t i = 0; i < instances.size(); i++ ) for ( size_t i = 0; i < instances.size(); i++ )
@ -169,23 +145,21 @@ AccelerationStructureData
// table will contain the hit group to be executed when hitting this instance. We set this // table will contain the hit group to be executed when hitting this instance. We set this
// index to 2*i due to the use of 2 types of rays in the scene: the camera rays and the shadow // index to 2*i due to the use of 2 types of rays in the scene: the camera rays and the shadow
// rays. For each instance, the SBT will then have 2 hit groups // rays. For each instance, the SBT will then have 2 hit groups
geometryInstanceData.emplace_back( geometryInstanceData.emplace_back( GeometryInstanceData( glm::transpose( instances[i].second ),
GeometryInstanceData( glm::transpose( instances[i].second ), static_cast<uint32_t>( i ),
static_cast<uint32_t>( i ), 0xFF,
0xFF, static_cast<uint32_t>( 2 * i ),
static_cast<uint32_t>( 2 * i ), static_cast<uint8_t>( vk::GeometryInstanceFlagBitsNV::eTriangleCullDisable ),
static_cast<uint8_t>( vk::GeometryInstanceFlagBitsNV::eTriangleCullDisable ), accelerationStructureHandle ) );
accelerationStructureHandle ) );
} }
accelerationStructureData.instanceBufferData->upload( device, geometryInstanceData ); accelerationStructureData.instanceBufferData->upload( device, geometryInstanceData );
} }
device.bindAccelerationStructureMemoryNV( vk::BindAccelerationStructureMemoryInfoNV( device.bindAccelerationStructureMemoryNV(
accelerationStructureData.accelerationStructure, accelerationStructureData.resultBufferData->deviceMemory ) ); vk::BindAccelerationStructureMemoryInfoNV( accelerationStructureData.accelerationStructure, accelerationStructureData.resultBufferData->deviceMemory ) );
commandBuffer.buildAccelerationStructureNV( commandBuffer.buildAccelerationStructureNV(
vk::AccelerationStructureInfoNV( vk::AccelerationStructureInfoNV( accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries ),
accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries ),
accelerationStructureData.instanceBufferData ? accelerationStructureData.instanceBufferData->buffer : nullptr, accelerationStructureData.instanceBufferData ? accelerationStructureData.instanceBufferData->buffer : nullptr,
0, 0,
false, false,
@ -197,10 +171,8 @@ AccelerationStructureData
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eAccelerationStructureBuildNV, commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eAccelerationStructureBuildNV,
vk::PipelineStageFlagBits::eAccelerationStructureBuildNV, vk::PipelineStageFlagBits::eAccelerationStructureBuildNV,
{}, {},
vk::MemoryBarrier( vk::AccessFlagBits::eAccelerationStructureWriteNV | vk::MemoryBarrier( vk::AccessFlagBits::eAccelerationStructureWriteNV | vk::AccessFlagBits::eAccelerationStructureReadNV,
vk::AccessFlagBits::eAccelerationStructureReadNV, vk::AccessFlagBits::eAccelerationStructureWriteNV | vk::AccessFlagBits::eAccelerationStructureReadNV ),
vk::AccessFlagBits::eAccelerationStructureWriteNV |
vk::AccessFlagBits::eAccelerationStructureReadNV ),
{}, {},
{} ); {} );
@ -244,9 +216,7 @@ const size_t MaterialStride = ( ( sizeof( Material ) + 15 ) / 16 ) * 16;
struct Vertex struct Vertex
{ {
Vertex( glm::vec3 const & p, glm::vec3 const & n, glm::vec2 const & tc, int m = 0 ) Vertex( glm::vec3 const & p, glm::vec3 const & n, glm::vec2 const & tc, int m = 0 ) : pos( p ), nrm( n ), texCoord( tc ), matID( m ) {}
: pos( p ), nrm( n ), texCoord( tc ), matID( m )
{}
glm::vec3 pos; glm::vec3 pos;
glm::vec3 nrm; glm::vec3 nrm;
@ -577,13 +547,10 @@ static void check_vk_result( VkResult err )
static void cursorPosCallback( GLFWwindow * window, double mouseX, double mouseY ) static void cursorPosCallback( GLFWwindow * window, double mouseX, double mouseY )
{ {
vk::su::CameraManipulator::MouseButton mouseButton = vk::su::CameraManipulator::MouseButton mouseButton =
( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_LEFT ) == GLFW_PRESS ) ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_LEFT ) == GLFW_PRESS ) ? vk::su::CameraManipulator::MouseButton::Left
? vk::su::CameraManipulator::MouseButton::Left : ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_MIDDLE ) == GLFW_PRESS ) ? vk::su::CameraManipulator::MouseButton::Middle
: ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_MIDDLE ) == GLFW_PRESS ) : ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_RIGHT ) == GLFW_PRESS ) ? vk::su::CameraManipulator::MouseButton::Right
? vk::su::CameraManipulator::MouseButton::Middle : vk::su::CameraManipulator::MouseButton::None;
: ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_RIGHT ) == GLFW_PRESS )
? vk::su::CameraManipulator::MouseButton::Right
: vk::su::CameraManipulator::MouseButton::None;
if ( mouseButton != vk::su::CameraManipulator::MouseButton::None ) if ( mouseButton != vk::su::CameraManipulator::MouseButton::None )
{ {
vk::su::CameraManipulator::ModifierFlags modifiers; vk::su::CameraManipulator::ModifierFlags modifiers;
@ -600,10 +567,8 @@ static void cursorPosCallback( GLFWwindow * window, double mouseX, double mouseY
modifiers |= vk::su::CameraManipulator::ModifierFlagBits::Shift; modifiers |= vk::su::CameraManipulator::ModifierFlagBits::Shift;
} }
vk::su::CameraManipulator & cameraManipulator = vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator; cameraManipulator.mouseMove( glm::ivec2( static_cast<int>( mouseX ), static_cast<int>( mouseY ) ), mouseButton, modifiers );
cameraManipulator.mouseMove(
glm::ivec2( static_cast<int>( mouseX ), static_cast<int>( mouseY ) ), mouseButton, modifiers );
} }
} }
@ -614,8 +579,7 @@ static void errorCallback( int error, const char * description )
static void framebufferSizeCallback( GLFWwindow * window, int w, int h ) static void framebufferSizeCallback( GLFWwindow * window, int w, int h )
{ {
vk::su::CameraManipulator & cameraManipulator = vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
cameraManipulator.setWindowSize( glm::ivec2( w, h ) ); cameraManipulator.setWindowSize( glm::ivec2( w, h ) );
} }
@ -628,11 +592,11 @@ static void keyCallback( GLFWwindow * window, int key, int /*scancode*/, int act
case GLFW_KEY_ESCAPE: case GLFW_KEY_ESCAPE:
case 'Q': glfwSetWindowShouldClose( window, 1 ); break; case 'Q': glfwSetWindowShouldClose( window, 1 ); break;
case 'R': case 'R':
{ {
AppInfo * appInfo = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) ); AppInfo * appInfo = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) );
appInfo->useRasterRender = !appInfo->useRasterRender; appInfo->useRasterRender = !appInfo->useRasterRender;
} }
break; break;
} }
} }
} }
@ -642,15 +606,13 @@ static void mouseButtonCallback( GLFWwindow * window, int /*button*/, int /*acti
double xpos, ypos; double xpos, ypos;
glfwGetCursorPos( window, &xpos, &ypos ); glfwGetCursorPos( window, &xpos, &ypos );
vk::su::CameraManipulator & cameraManipulator = vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
cameraManipulator.setMousePosition( glm::ivec2( static_cast<int>( xpos ), static_cast<int>( ypos ) ) ); cameraManipulator.setMousePosition( glm::ivec2( static_cast<int>( xpos ), static_cast<int>( ypos ) ) );
} }
static void scrollCallback( GLFWwindow * window, double /*xoffset*/, double yoffset ) static void scrollCallback( GLFWwindow * window, double /*xoffset*/, double yoffset )
{ {
vk::su::CameraManipulator & cameraManipulator = vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
cameraManipulator.wheel( static_cast<int>( yoffset ) ); cameraManipulator.wheel( static_cast<int>( yoffset ) );
} }
@ -671,9 +633,7 @@ glm::vec3 randomVec3( float minValue, float maxValue )
{ {
std::uniform_real_distribution<float> randomDistribution( minValue, maxValue ); std::uniform_real_distribution<float> randomDistribution( minValue, maxValue );
return glm::vec3( randomDistribution( randomGenerator ), return glm::vec3( randomDistribution( randomGenerator ), randomDistribution( randomGenerator ), randomDistribution( randomGenerator ) );
randomDistribution( randomGenerator ),
randomDistribution( randomGenerator ) );
} }
uint32_t roundUp( uint32_t value, uint32_t alignment ) uint32_t roundUp( uint32_t value, uint32_t alignment )
@ -719,8 +679,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// Setup camera and make it available as the userPointer in the glfw window // Setup camera and make it available as the userPointer in the glfw window
appInfo.cameraManipulator.setWindowSize( glm::u32vec2( windowExtent.width, windowExtent.height ) ); appInfo.cameraManipulator.setWindowSize( glm::u32vec2( windowExtent.width, windowExtent.height ) );
glm::vec3 diagonal = glm::vec3 diagonal = 3.0f * glm::vec3( static_cast<float>( xMax ), static_cast<float>( yMax ), static_cast<float>( zMax ) );
3.0f * glm::vec3( static_cast<float>( xMax ), static_cast<float>( yMax ), static_cast<float>( zMax ) );
appInfo.cameraManipulator.setLookat( 1.5f * diagonal, 0.5f * diagonal, glm::vec3( 0, 1, 0 ) ); appInfo.cameraManipulator.setLookat( 1.5f * diagonal, 0.5f * diagonal, glm::vec3( 0, 1, 0 ) );
glfwSetWindowUserPointer( window, &appInfo ); glfwSetWindowUserPointer( window, &appInfo );
@ -737,30 +696,24 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, instanceExtensions ); vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, instanceExtensions );
#if !defined( NDEBUG ) #if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger = vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif #endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
// Create Window Surface (using glfw) // Create Window Surface (using glfw)
vk::SurfaceKHR surface; vk::SurfaceKHR surface;
VkResult err = glfwCreateWindowSurface( VkResult err = glfwCreateWindowSurface( static_cast<VkInstance>( instance ), window, nullptr, reinterpret_cast<VkSurfaceKHR *>( &surface ) );
static_cast<VkInstance>( instance ), window, nullptr, reinterpret_cast<VkSurfaceKHR *>( &surface ) );
check_vk_result( err ); check_vk_result( err );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surface );
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surface );
// Create a Device with ray tracing support (besides some other extensions needed) and needed features // Create a Device with ray tracing support (besides some other extensions needed) and needed features
auto supportedFeatures = auto supportedFeatures = physicalDevice.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
physicalDevice.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
vk::Device device = vk::Device device =
vk::su::createDevice( physicalDevice, vk::su::createDevice( physicalDevice,
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
{ VK_KHR_SWAPCHAIN_EXTENSION_NAME, { VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_NV_RAY_TRACING_EXTENSION_NAME, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME },
VK_NV_RAY_TRACING_EXTENSION_NAME,
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME },
&supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features, &supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features,
&supportedFeatures.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>() ); &supportedFeatures.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>() );
@ -768,13 +721,11 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<PerFrameData, IMGUI_VK_QUEUED_FRAMES> perFrameData; std::array<PerFrameData, IMGUI_VK_QUEUED_FRAMES> perFrameData;
for ( int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++ ) for ( int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++ )
{ {
perFrameData[i].commandPool = device.createCommandPool( vk::CommandPoolCreateInfo( perFrameData[i].commandPool =
vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first ) ); device.createCommandPool( vk::CommandPoolCreateInfo( vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first ) );
perFrameData[i].commandBuffer = device perFrameData[i].commandBuffer =
.allocateCommandBuffers( vk::CommandBufferAllocateInfo( device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( perFrameData[i].commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
perFrameData[i].commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ) perFrameData[i].fence = device.createFence( vk::FenceCreateInfo( vk::FenceCreateFlagBits::eSignaled ) );
.front();
perFrameData[i].fence = device.createFence( vk::FenceCreateInfo( vk::FenceCreateFlagBits::eSignaled ) );
perFrameData[i].presentCompleteSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); perFrameData[i].presentCompleteSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
perFrameData[i].renderCompleteSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() ); perFrameData[i].renderCompleteSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
} }
@ -806,8 +757,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::RenderPass renderPass = vk::su::createRenderPass( device, surfaceFormat.format, depthFormat ); vk::RenderPass renderPass = vk::su::createRenderPass( device, surfaceFormat.format, depthFormat );
vk::su::DepthBufferData depthBufferData( physicalDevice, device, depthFormat, windowExtent ); vk::su::DepthBufferData depthBufferData( physicalDevice, device, depthFormat, windowExtent );
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers( std::vector<vk::Framebuffer> framebuffers =
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, windowExtent ); vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, windowExtent );
bool samplerAnisotropy = !!supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features.samplerAnisotropy; bool samplerAnisotropy = !!supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features.samplerAnisotropy;
@ -825,17 +776,19 @@ int main( int /*argc*/, char ** /*argv*/ )
samplerAnisotropy, samplerAnisotropy,
true ); true );
} }
vk::su::oneTimeSubmit( vk::su::oneTimeSubmit( device,
device, perFrameData[0].commandPool, graphicsQueue, [&]( vk::CommandBuffer const & commandBuffer ) { perFrameData[0].commandPool,
for ( auto & t : textures ) graphicsQueue,
{ [&]( vk::CommandBuffer const & commandBuffer )
t.setImage( {
device, for ( auto & t : textures )
commandBuffer, {
vk::su::CheckerboardImageGenerator( { random<uint8_t>(), random<uint8_t>(), random<uint8_t>() }, t.setImage( device,
{ random<uint8_t>(), random<uint8_t>(), random<uint8_t>() } ) ); commandBuffer,
} vk::su::CheckerboardImageGenerator( { random<uint8_t>(), random<uint8_t>(), random<uint8_t>() },
} ); { random<uint8_t>(), random<uint8_t>(), random<uint8_t>() } ) );
}
} );
// create some materials with a random diffuse color, referencing one of the above textures // create some materials with a random diffuse color, referencing one of the above textures
const size_t materialCount = 10; const size_t materialCount = 10;
@ -846,8 +799,7 @@ int main( int /*argc*/, char ** /*argv*/ )
materials[i].diffuse = randomVec3( 0.0f, 1.0f ); materials[i].diffuse = randomVec3( 0.0f, 1.0f );
materials[i].textureID = vk::su::checked_cast<uint32_t>( i ); materials[i].textureID = vk::su::checked_cast<uint32_t>( i );
} }
vk::su::BufferData materialBufferData( vk::su::BufferData materialBufferData( physicalDevice, device, materialCount * MaterialStride, vk::BufferUsageFlagBits::eStorageBuffer );
physicalDevice, device, materialCount * MaterialStride, vk::BufferUsageFlagBits::eStorageBuffer );
materialBufferData.upload( device, materials, MaterialStride ); materialBufferData.upload( device, materials, MaterialStride );
// create a a 3D-array of cubes, randomly jittered, using a random material // create a a 3D-array of cubes, randomly jittered, using a random material
@ -864,8 +816,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( auto const & v : cubeData ) for ( auto const & v : cubeData )
{ {
vertices.push_back( v ); vertices.push_back( v );
vertices.back().pos += vertices.back().pos += 3.0f * glm::vec3( static_cast<float>( x ), static_cast<float>( y ), static_cast<float>( z ) ) + jitter;
3.0f * glm::vec3( static_cast<float>( x ), static_cast<float>( y ), static_cast<float>( z ) ) + jitter;
vertices.back().matID = static_cast<int>( m ); vertices.back().matID = static_cast<int>( m );
} }
} }
@ -880,76 +831,67 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::BufferData vertexBufferData( physicalDevice, vk::su::BufferData vertexBufferData( physicalDevice,
device, device,
vertices.size() * VertexStride, vertices.size() * VertexStride,
vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eVertexBuffer |
vk::BufferUsageFlagBits::eVertexBuffer |
vk::BufferUsageFlagBits::eStorageBuffer, vk::BufferUsageFlagBits::eStorageBuffer,
vk::MemoryPropertyFlagBits::eDeviceLocal ); vk::MemoryPropertyFlagBits::eDeviceLocal );
vertexBufferData.upload( vertexBufferData.upload( physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, vertices, VertexStride );
physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, vertices, VertexStride );
vk::su::BufferData indexBufferData( physicalDevice, vk::su::BufferData indexBufferData( physicalDevice,
device, device,
indices.size() * sizeof( uint32_t ), indices.size() * sizeof( uint32_t ),
vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eStorageBuffer,
vk::BufferUsageFlagBits::eStorageBuffer,
vk::MemoryPropertyFlagBits::eDeviceLocal ); vk::MemoryPropertyFlagBits::eDeviceLocal );
indexBufferData.upload( indexBufferData.upload( physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, indices, sizeof( uint32_t ) );
physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, indices, sizeof( uint32_t ) );
glm::mat4x4 transform( glm::mat4x4 transform( glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ) );
glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ) );
vk::DescriptorSetLayout descriptorSetLayout = vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
vk::su::createDescriptorSetLayout( device, device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eStorageBuffer, { vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment },
1, { vk::DescriptorType::eCombinedImageSampler, static_cast<uint32_t>( textures.size() ), vk::ShaderStageFlagBits::eFragment } } );
vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment }, vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( {}, descriptorSetLayout ) );
{ vk::DescriptorType::eCombinedImageSampler,
static_cast<uint32_t>( textures.size() ),
vk::ShaderStageFlagBits::eFragment } } );
vk::PipelineLayout pipelineLayout =
device.createPipelineLayout( vk::PipelineLayoutCreateInfo( {}, descriptorSetLayout ) );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule = vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText ); vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( vk::Pipeline graphicsPipeline =
device, vk::su::createGraphicsPipeline( device,
{}, {},
std::make_pair( vertexShaderModule, nullptr ), std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ), std::make_pair( fragmentShaderModule, nullptr ),
VertexStride, VertexStride,
{ { vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, pos ) ) }, { { vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, pos ) ) },
{ vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, nrm ) ) }, { vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, nrm ) ) },
{ vk::Format::eR32G32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, texCoord ) ) }, { vk::Format::eR32G32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, texCoord ) ) },
{ vk::Format::eR32Sint, vk::su::checked_cast<uint32_t>( offsetof( Vertex, matID ) ) } }, { vk::Format::eR32Sint, vk::su::checked_cast<uint32_t>( offsetof( Vertex, matID ) ) } },
vk::FrontFace::eCounterClockwise, vk::FrontFace::eCounterClockwise,
true, true,
pipelineLayout, pipelineLayout,
renderPass ); renderPass );
vk::su::BufferData uniformBufferData( vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( UniformBufferObject ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( UniformBufferObject ), vk::BufferUsageFlagBits::eUniformBuffer );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout ); vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front(); vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets( device, vk::su::updateDescriptorSets(
descriptorSet, device,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} }, descriptorSet,
{ vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, {} } }, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} }, { vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, {} } },
textures ); textures );
// RayTracing specific stuff // RayTracing specific stuff
// create acceleration structures: one top-level, and just one bottom-level // create acceleration structures: one top-level, and just one bottom-level
AccelerationStructureData topLevelAS, bottomLevelAS; AccelerationStructureData topLevelAS, bottomLevelAS;
vk::su::oneTimeSubmit( vk::su::oneTimeSubmit(
device, perFrameData[0].commandPool, graphicsQueue, [&]( vk::CommandBuffer const & commandBuffer ) { device,
perFrameData[0].commandPool,
graphicsQueue,
[&]( vk::CommandBuffer const & commandBuffer )
{
vk::GeometryDataNV geometryDataNV( vk::GeometryTrianglesNV( vertexBufferData.buffer, vk::GeometryDataNV geometryDataNV( vk::GeometryTrianglesNV( vertexBufferData.buffer,
0, 0,
vk::su::checked_cast<uint32_t>( vertices.size() ), vk::su::checked_cast<uint32_t>( vertices.size() ),
@ -961,61 +903,36 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::IndexType::eUint32 ), vk::IndexType::eUint32 ),
{} ); {} );
bottomLevelAS = bottomLevelAS =
createAccelerationStructureData( physicalDevice, createAccelerationStructureData( physicalDevice, device, commandBuffer, {}, { vk::GeometryNV( vk::GeometryTypeNV::eTriangles, geometryDataNV ) } );
device,
commandBuffer,
{},
{ vk::GeometryNV( vk::GeometryTypeNV::eTriangles, geometryDataNV ) } );
topLevelAS = topLevelAS = createAccelerationStructureData(
createAccelerationStructureData( physicalDevice, physicalDevice, device, commandBuffer, { std::make_pair( bottomLevelAS.accelerationStructure, transform ) }, std::vector<vk::GeometryNV>() );
device,
commandBuffer,
{ std::make_pair( bottomLevelAS.accelerationStructure, transform ) },
std::vector<vk::GeometryNV>() );
} ); } );
// create raytracing descriptor set // create raytracing descriptor set
vk::su::oneTimeSubmit( vk::su::oneTimeSubmit(
device, perFrameData[0].commandPool, graphicsQueue, [&]( vk::CommandBuffer const & commandBuffer ) { device,
vk::BufferMemoryBarrier bufferMemoryBarrier( {}, perFrameData[0].commandPool,
vk::AccessFlagBits::eShaderRead, graphicsQueue,
VK_QUEUE_FAMILY_IGNORED, [&]( vk::CommandBuffer const & commandBuffer )
VK_QUEUE_FAMILY_IGNORED, {
vertexBufferData.buffer, vk::BufferMemoryBarrier bufferMemoryBarrier(
0, {}, vk::AccessFlagBits::eShaderRead, VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, vertexBufferData.buffer, 0, VK_WHOLE_SIZE );
VK_WHOLE_SIZE ); commandBuffer.pipelineBarrier(
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, nullptr, bufferMemoryBarrier, nullptr );
vk::PipelineStageFlagBits::eAllCommands,
{},
nullptr,
bufferMemoryBarrier,
nullptr );
bufferMemoryBarrier.buffer = indexBufferData.buffer; bufferMemoryBarrier.buffer = indexBufferData.buffer;
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eAllCommands, commandBuffer.pipelineBarrier(
vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, nullptr, bufferMemoryBarrier, nullptr );
{},
nullptr,
bufferMemoryBarrier,
nullptr );
} ); } );
std::vector<vk::DescriptorSetLayoutBinding> bindings; std::vector<vk::DescriptorSetLayoutBinding> bindings;
bindings.emplace_back( 0, bindings.emplace_back( 0, vk::DescriptorType::eAccelerationStructureNV, 1, vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV );
vk::DescriptorType::eAccelerationStructureNV, bindings.emplace_back( 1, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eRaygenNV ); // raytracing output
1, bindings.emplace_back( 2, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eRaygenNV ); // camera information
vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV ); bindings.emplace_back( 3, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // vertex buffer
bindings.emplace_back( bindings.emplace_back( 4, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // index buffer
1, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eRaygenNV ); // raytracing output bindings.emplace_back( 5, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // material buffer
bindings.emplace_back(
2, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eRaygenNV ); // camera information
bindings.emplace_back(
3, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // vertex buffer
bindings.emplace_back(
4, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // index buffer
bindings.emplace_back(
5, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ); // material buffer
bindings.emplace_back( 6, bindings.emplace_back( 6,
vk::DescriptorType::eCombinedImageSampler, vk::DescriptorType::eCombinedImageSampler,
vk::su::checked_cast<uint32_t>( textures.size() ), vk::su::checked_cast<uint32_t>( textures.size() ),
@ -1025,28 +942,22 @@ int main( int /*argc*/, char ** /*argv*/ )
descriptorPoolSizes.reserve( bindings.size() ); descriptorPoolSizes.reserve( bindings.size() );
for ( const auto & b : bindings ) for ( const auto & b : bindings )
{ {
descriptorPoolSizes.emplace_back( descriptorPoolSizes.emplace_back( b.descriptorType, vk::su::checked_cast<uint32_t>( swapChainData.images.size() ) * b.descriptorCount );
b.descriptorType, vk::su::checked_cast<uint32_t>( swapChainData.images.size() ) * b.descriptorCount );
} }
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, vk::su::checked_cast<uint32_t>( swapChainData.images.size() ), descriptorPoolSizes );
vk::su::checked_cast<uint32_t>( swapChainData.images.size() ), vk::DescriptorPool rayTracingDescriptorPool = device.createDescriptorPool( descriptorPoolCreateInfo );
descriptorPoolSizes ); vk::DescriptorSetLayout rayTracingDescriptorSetLayout = device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( {}, bindings ) );
vk::DescriptorPool rayTracingDescriptorPool = device.createDescriptorPool( descriptorPoolCreateInfo );
vk::DescriptorSetLayout rayTracingDescriptorSetLayout =
device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( {}, bindings ) );
std::vector<vk::DescriptorSetLayout> layouts; std::vector<vk::DescriptorSetLayout> layouts;
for ( size_t i = 0; i < swapChainData.images.size(); i++ ) for ( size_t i = 0; i < swapChainData.images.size(); i++ )
{ {
layouts.push_back( rayTracingDescriptorSetLayout ); layouts.push_back( rayTracingDescriptorSetLayout );
} }
descriptorSetAllocateInfo = vk::DescriptorSetAllocateInfo( rayTracingDescriptorPool, layouts ); descriptorSetAllocateInfo = vk::DescriptorSetAllocateInfo( rayTracingDescriptorPool, layouts );
std::vector<vk::DescriptorSet> rayTracingDescriptorSets = std::vector<vk::DescriptorSet> rayTracingDescriptorSets = device.allocateDescriptorSets( descriptorSetAllocateInfo );
device.allocateDescriptorSets( descriptorSetAllocateInfo );
// Bind ray tracing specific descriptor sets into pNext of a vk::WriteDescriptorSet // Bind ray tracing specific descriptor sets into pNext of a vk::WriteDescriptorSet
vk::WriteDescriptorSetAccelerationStructureNV writeDescriptorSetAcceleration( 1, vk::WriteDescriptorSetAccelerationStructureNV writeDescriptorSetAcceleration( 1, &topLevelAS.accelerationStructure );
&topLevelAS.accelerationStructure );
std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets; std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets;
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ ) for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
{ {
@ -1071,14 +982,10 @@ int main( int /*argc*/, char ** /*argv*/ )
// create the ray-tracing shader modules // create the ray-tracing shader modules
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::ShaderModule raygenShaderModule = vk::ShaderModule raygenShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eRaygenNV, raygenShaderText );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eRaygenNV, raygenShaderText ); vk::ShaderModule missShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eMissNV, missShaderText );
vk::ShaderModule missShaderModule = vk::ShaderModule shadowMissShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eMissNV, shadowMissShaderText );
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eMissNV, missShaderText ); vk::ShaderModule closestHitShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eClosestHitNV, closestHitShaderText );
vk::ShaderModule shadowMissShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eMissNV, shadowMissShaderText );
vk::ShaderModule closestHitShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eClosestHitNV, closestHitShaderText );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
// create the ray tracing pipeline // create the ray tracing pipeline
@ -1086,46 +993,31 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::RayTracingShaderGroupCreateInfoNV> shaderGroups; std::vector<vk::RayTracingShaderGroupCreateInfoNV> shaderGroups;
// We use only one ray generation, that will implement the camera model // We use only one ray generation, that will implement the camera model
shaderStages.emplace_back( shaderStages.emplace_back( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eRaygenNV, raygenShaderModule, "main" );
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eRaygenNV, raygenShaderModule, "main" ); shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eGeneral, 0, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
shaderGroups.emplace_back(
vk::RayTracingShaderGroupTypeNV::eGeneral, 0, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
// The first miss shader is used to look-up the environment in case the rays from the camera miss the geometry // The first miss shader is used to look-up the environment in case the rays from the camera miss the geometry
shaderStages.emplace_back( shaderStages.emplace_back( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eMissNV, missShaderModule, "main" );
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eMissNV, missShaderModule, "main" ); shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eGeneral, 1, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
shaderGroups.emplace_back(
vk::RayTracingShaderGroupTypeNV::eGeneral, 1, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
// The second miss shader is invoked when a shadow ray misses the geometry. It simply indicates that no occlusion // The second miss shader is invoked when a shadow ray misses the geometry. It simply indicates that no occlusion
// has been found // has been found
shaderStages.emplace_back( shaderStages.emplace_back( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eMissNV, shadowMissShaderModule, "main" );
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eMissNV, shadowMissShaderModule, "main" ); shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eGeneral, 2, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
shaderGroups.emplace_back(
vk::RayTracingShaderGroupTypeNV::eGeneral, 2, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
// The first hit group defines the shaders invoked when a ray shot from the camera hit the geometry. In this case we // The first hit group defines the shaders invoked when a ray shot from the camera hit the geometry. In this case we
// only specify the closest hit shader, and rely on the build-in triangle intersection and pass-through any-hit // only specify the closest hit shader, and rely on the build-in triangle intersection and pass-through any-hit
// shader. However, explicit intersection and any hit shaders could be added as well. // shader. However, explicit intersection and any hit shaders could be added as well.
shaderStages.emplace_back( shaderStages.emplace_back( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eClosestHitNV, closestHitShaderModule, "main" );
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eClosestHitNV, closestHitShaderModule, "main" ); shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup, VK_SHADER_UNUSED_NV, 3, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup,
VK_SHADER_UNUSED_NV,
3,
VK_SHADER_UNUSED_NV,
VK_SHADER_UNUSED_NV );
// The second hit group defines the shaders invoked when a shadow ray hits the geometry. For simple shadows we do // The second hit group defines the shaders invoked when a shadow ray hits the geometry. For simple shadows we do
// not need any shader in that group: we will rely on initializing the payload and update it only in the miss shader // not need any shader in that group: we will rely on initializing the payload and update it only in the miss shader
shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup, shaderGroups.emplace_back(
VK_SHADER_UNUSED_NV, vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
VK_SHADER_UNUSED_NV,
VK_SHADER_UNUSED_NV,
VK_SHADER_UNUSED_NV );
// Create the layout of the pipeline following the provided descriptor set layout // Create the layout of the pipeline following the provided descriptor set layout
vk::PipelineLayout rayTracingPipelineLayout = vk::PipelineLayout rayTracingPipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( {}, rayTracingDescriptorSetLayout ) );
device.createPipelineLayout( vk::PipelineLayoutCreateInfo( {}, rayTracingDescriptorSetLayout ) );
// Assemble the shader stages and recursion depth info into the raytracing pipeline // Assemble the shader stages and recursion depth info into the raytracing pipeline
// The ray tracing process can shoot rays from the camera, and a shadow ray can be shot from the // The ray tracing process can shoot rays from the camera, and a shadow ray can be shot from the
@ -1133,11 +1025,9 @@ int main( int /*argc*/, char ** /*argv*/ )
// as possible for performance reasons. Even recursive ray tracing should be flattened into a loop // as possible for performance reasons. Even recursive ray tracing should be flattened into a loop
// in the ray generation to avoid deep recursion. // in the ray generation to avoid deep recursion.
uint32_t maxRecursionDepth = 2; uint32_t maxRecursionDepth = 2;
vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo( vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo( {}, shaderStages, shaderGroups, maxRecursionDepth, rayTracingPipelineLayout );
{}, shaderStages, shaderGroups, maxRecursionDepth, rayTracingPipelineLayout ); vk::Pipeline rayTracingPipeline;
vk::Pipeline rayTracingPipeline; vk::ResultValue<vk::Pipeline> rvPipeline = device.createRayTracingPipelineNV( nullptr, rayTracingPipelineCreateInfo );
vk::ResultValue<vk::Pipeline> rvPipeline =
device.createRayTracingPipelineNV( nullptr, rayTracingPipelineCreateInfo );
switch ( rvPipeline.result ) switch ( rvPipeline.result )
{ {
case vk::Result::eSuccess: rayTracingPipeline = rvPipeline.value; break; case vk::Result::eSuccess: rayTracingPipeline = rvPipeline.value; break;
@ -1149,36 +1039,26 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV> propertiesChain = vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV> propertiesChain =
physicalDevice.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV>(); physicalDevice.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV>();
uint32_t shaderGroupBaseAlignment = uint32_t shaderGroupBaseAlignment = propertiesChain.get<vk::PhysicalDeviceRayTracingPropertiesNV>().shaderGroupBaseAlignment;
propertiesChain.get<vk::PhysicalDeviceRayTracingPropertiesNV>().shaderGroupBaseAlignment; uint32_t shaderGroupHandleSize = propertiesChain.get<vk::PhysicalDeviceRayTracingPropertiesNV>().shaderGroupHandleSize;
uint32_t shaderGroupHandleSize =
propertiesChain.get<vk::PhysicalDeviceRayTracingPropertiesNV>().shaderGroupHandleSize;
uint32_t raygenShaderBindingOffset = 0; // starting with raygen uint32_t raygenShaderBindingOffset = 0; // starting with raygen
uint32_t raygenShaderTableSize = shaderGroupHandleSize; // one raygen shader uint32_t raygenShaderTableSize = shaderGroupHandleSize; // one raygen shader
uint32_t missShaderBindingOffset = uint32_t missShaderBindingOffset = raygenShaderBindingOffset + roundUp( raygenShaderTableSize, shaderGroupBaseAlignment );
raygenShaderBindingOffset + roundUp( raygenShaderTableSize, shaderGroupBaseAlignment ); uint32_t missShaderBindingStride = shaderGroupHandleSize;
uint32_t missShaderBindingStride = shaderGroupHandleSize; uint32_t missShaderTableSize = 2 * missShaderBindingStride; // two raygen shaders
uint32_t missShaderTableSize = 2 * missShaderBindingStride; // two raygen shaders uint32_t hitShaderBindingOffset = missShaderBindingOffset + roundUp( missShaderTableSize, shaderGroupBaseAlignment );
uint32_t hitShaderBindingOffset = uint32_t hitShaderBindingStride = shaderGroupHandleSize;
missShaderBindingOffset + roundUp( missShaderTableSize, shaderGroupBaseAlignment ); uint32_t hitShaderTableSize = 2 * hitShaderBindingStride; // two hit shaders
uint32_t hitShaderBindingStride = shaderGroupHandleSize;
uint32_t hitShaderTableSize = 2 * hitShaderBindingStride; // two hit shaders
uint32_t shaderBindingTableSize = hitShaderBindingOffset + hitShaderTableSize; uint32_t shaderBindingTableSize = hitShaderBindingOffset + hitShaderTableSize;
std::vector<uint8_t> shaderHandleStorage( shaderBindingTableSize ); std::vector<uint8_t> shaderHandleStorage( shaderBindingTableSize );
(void)device.getRayTracingShaderGroupHandlesNV( (void)device.getRayTracingShaderGroupHandlesNV( rayTracingPipeline, 0, 1, raygenShaderTableSize, &shaderHandleStorage[raygenShaderBindingOffset] );
rayTracingPipeline, 0, 1, raygenShaderTableSize, &shaderHandleStorage[raygenShaderBindingOffset] ); (void)device.getRayTracingShaderGroupHandlesNV( rayTracingPipeline, 1, 2, missShaderTableSize, &shaderHandleStorage[missShaderBindingOffset] );
(void)device.getRayTracingShaderGroupHandlesNV( (void)device.getRayTracingShaderGroupHandlesNV( rayTracingPipeline, 3, 2, hitShaderTableSize, &shaderHandleStorage[hitShaderBindingOffset] );
rayTracingPipeline, 1, 2, missShaderTableSize, &shaderHandleStorage[missShaderBindingOffset] );
(void)device.getRayTracingShaderGroupHandlesNV(
rayTracingPipeline, 3, 2, hitShaderTableSize, &shaderHandleStorage[hitShaderBindingOffset] );
vk::su::BufferData shaderBindingTableBufferData( physicalDevice, vk::su::BufferData shaderBindingTableBufferData(
device, physicalDevice, device, shaderBindingTableSize, vk::BufferUsageFlagBits::eTransferDst, vk::MemoryPropertyFlagBits::eHostVisible );
shaderBindingTableSize,
vk::BufferUsageFlagBits::eTransferDst,
vk::MemoryPropertyFlagBits::eHostVisible );
shaderBindingTableBufferData.upload( device, shaderHandleStorage ); shaderBindingTableBufferData.upload( device, shaderHandleStorage );
std::array<vk::ClearValue, 2> clearValues; std::array<vk::ClearValue, 2> clearValues;
@ -1207,48 +1087,44 @@ int main( int /*argc*/, char ** /*argv*/ )
windowExtent.width = w; windowExtent.width = w;
windowExtent.height = h; windowExtent.height = h;
device.waitIdle(); device.waitIdle();
swapChainData = swapChainData = vk::su::SwapChainData( physicalDevice,
vk::su::SwapChainData( physicalDevice, device,
device, surface,
surface, windowExtent,
windowExtent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage, swapChainData.swapChain,
swapChainData.swapChain, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second );
graphicsAndPresentQueueFamilyIndex.second ); depthBufferData = vk::su::DepthBufferData( physicalDevice, device, vk::su::pickDepthFormat( physicalDevice ), windowExtent );
depthBufferData =
vk::su::DepthBufferData( physicalDevice, device, vk::su::pickDepthFormat( physicalDevice ), windowExtent );
vk::su::oneTimeSubmit( commandBuffer, graphicsQueue, [&]( vk::CommandBuffer const & commandBuffer ) { vk::su::oneTimeSubmit(
vk::su::setImageLayout( commandBuffer, commandBuffer,
depthBufferData.image, graphicsQueue,
depthFormat, [&]( vk::CommandBuffer const & commandBuffer )
vk::ImageLayout::eUndefined, {
vk::ImageLayout::eDepthStencilAttachmentOptimal ); vk::su::setImageLayout(
} ); commandBuffer, depthBufferData.image, depthFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilAttachmentOptimal );
} );
framebuffers = vk::su::createFramebuffers( framebuffers = vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, windowExtent );
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, windowExtent );
} }
// update the uniformBufferObject // update the uniformBufferObject
assert( 0 < windowExtent.height ); assert( 0 < windowExtent.height );
uniformBufferObject.view = appInfo.cameraManipulator.getMatrix(); uniformBufferObject.view = appInfo.cameraManipulator.getMatrix();
uniformBufferObject.proj = glm::perspective( uniformBufferObject.proj = glm::perspective( glm::radians( 65.0f ), windowExtent.width / static_cast<float>( windowExtent.height ), 0.1f, 1000.0f );
glm::radians( 65.0f ), windowExtent.width / static_cast<float>( windowExtent.height ), 0.1f, 1000.0f );
uniformBufferObject.proj[1][1] *= -1; // Inverting Y for Vulkan uniformBufferObject.proj[1][1] *= -1; // Inverting Y for Vulkan
uniformBufferObject.viewInverse = glm::inverse( uniformBufferObject.view ); uniformBufferObject.viewInverse = glm::inverse( uniformBufferObject.view );
uniformBufferObject.projInverse = glm::inverse( uniformBufferObject.proj ); uniformBufferObject.projInverse = glm::inverse( uniformBufferObject.proj );
uniformBufferData.upload( device, uniformBufferObject ); uniformBufferData.upload( device, uniformBufferObject );
// frame begin // frame begin
vk::ResultValue<uint32_t> rv = device.acquireNextImageKHR( vk::ResultValue<uint32_t> rv =
swapChainData.swapChain, UINT64_MAX, perFrameData[frameIndex].presentCompleteSemaphore, nullptr ); device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, perFrameData[frameIndex].presentCompleteSemaphore, nullptr );
assert( rv.result == vk::Result::eSuccess ); assert( rv.result == vk::Result::eSuccess );
uint32_t backBufferIndex = rv.value; uint32_t backBufferIndex = rv.value;
while ( vk::Result::eTimeout == while ( vk::Result::eTimeout == device.waitForFences( perFrameData[frameIndex].fence, VK_TRUE, vk::su::FenceTimeout ) )
device.waitForFences( perFrameData[frameIndex].fence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
device.resetFences( perFrameData[frameIndex].fence ); device.resetFences( perFrameData[frameIndex].fence );
@ -1257,20 +1133,14 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( appInfo.useRasterRender ) if ( appInfo.useRasterRender )
{ {
commandBuffer.beginRenderPass( commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo( vk::RenderPassBeginInfo( renderPass, framebuffers[backBufferIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ), clearValues ),
renderPass, framebuffers[backBufferIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ), clearValues ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr ); commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.setViewport( 0, commandBuffer.setViewport(
vk::Viewport( 0.0f, 0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( windowExtent.width ), static_cast<float>( windowExtent.height ), 0.0f, 1.0f ) );
0.0f,
static_cast<float>( windowExtent.width ),
static_cast<float>( windowExtent.height ),
0.0f,
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ) ); commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ) );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } ); commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
@ -1281,25 +1151,17 @@ int main( int /*argc*/, char ** /*argv*/ )
} }
else else
{ {
vk::DescriptorImageInfo imageInfo( vk::DescriptorImageInfo imageInfo( nullptr, swapChainData.imageViews[backBufferIndex], vk::ImageLayout::eGeneral );
nullptr, swapChainData.imageViews[backBufferIndex], vk::ImageLayout::eGeneral ); vk::WriteDescriptorSet writeDescriptorSet( rayTracingDescriptorSets[backBufferIndex], 1, 0, bindings[1].descriptorType, imageInfo );
vk::WriteDescriptorSet writeDescriptorSet(
rayTracingDescriptorSets[backBufferIndex], 1, 0, bindings[1].descriptorType, imageInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr ); device.updateDescriptorSets( writeDescriptorSet, nullptr );
vk::su::setImageLayout( commandBuffer, vk::su::setImageLayout(
swapChainData.images[backBufferIndex], commandBuffer, swapChainData.images[backBufferIndex], surfaceFormat.format, vk::ImageLayout::eUndefined, vk::ImageLayout::eGeneral );
surfaceFormat.format,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eGeneral );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eRayTracingNV, rayTracingPipeline ); commandBuffer.bindPipeline( vk::PipelineBindPoint::eRayTracingNV, rayTracingPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eRayTracingNV, commandBuffer.bindDescriptorSets(
rayTracingPipelineLayout, vk::PipelineBindPoint::eRayTracingNV, rayTracingPipelineLayout, 0, rayTracingDescriptorSets[backBufferIndex], nullptr );
0,
rayTracingDescriptorSets[backBufferIndex],
nullptr );
commandBuffer.traceRaysNV( shaderBindingTableBufferData.buffer, commandBuffer.traceRaysNV( shaderBindingTableBufferData.buffer,
raygenShaderBindingOffset, raygenShaderBindingOffset,
@ -1316,11 +1178,8 @@ int main( int /*argc*/, char ** /*argv*/ )
windowExtent.height, windowExtent.height,
1 ); 1 );
vk::su::setImageLayout( commandBuffer, vk::su::setImageLayout(
swapChainData.images[backBufferIndex], commandBuffer, swapChainData.images[backBufferIndex], surfaceFormat.format, vk::ImageLayout::eGeneral, vk::ImageLayout::ePresentSrcKHR );
surfaceFormat.format,
vk::ImageLayout::eGeneral,
vk::ImageLayout::ePresentSrcKHR );
} }
// frame end // frame end
@ -1334,14 +1193,12 @@ int main( int /*argc*/, char ** /*argv*/ )
1, 1,
&( perFrameData[frameIndex].renderCompleteSemaphore ) ), &( perFrameData[frameIndex].renderCompleteSemaphore ) ),
perFrameData[frameIndex].fence ); perFrameData[frameIndex].fence );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( vk::Result result =
perFrameData[frameIndex].renderCompleteSemaphore, swapChainData.swapChain, backBufferIndex ) ); presentQueue.presentKHR( vk::PresentInfoKHR( perFrameData[frameIndex].renderCompleteSemaphore, swapChainData.swapChain, backBufferIndex ) );
switch ( result ) switch ( result )
{ {
case vk::Result::eSuccess: break; case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR: case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
default: assert( false ); // an unexpected result is returned ! default: assert( false ); // an unexpected result is returned !
} }
frameIndex = ( frameIndex + 1 ) % IMGUI_VK_QUEUED_FRAMES; frameIndex = ( frameIndex + 1 ) % IMGUI_VK_QUEUED_FRAMES;
@ -1354,9 +1211,8 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( 0 < frameCount ); assert( 0 < frameCount );
std::ostringstream oss; std::ostringstream oss;
oss << AppName << ": " << vertices.size() << " Vertices " oss << AppName << ": " << vertices.size() << " Vertices " << ( appInfo.useRasterRender ? "Rastering" : "RayTracing" ) << " ( "
<< ( appInfo.useRasterRender ? "Rastering" : "RayTracing" ) << " ( " << frameCount / accumulatedTime << frameCount / accumulatedTime << " fps)";
<< " fps)";
glfwSetWindowTitle( window, oss.str().c_str() ); glfwSetWindowTitle( window, oss.str().c_str() );
accumulatedTime = 0.0; accumulatedTime = 0.0;

Some files were not shown because too many files have changed in this diff Show More