Change ColumnLimit with clang-format from 120 to 160.

This commit is contained in:
asuessenbach 2022-02-28 10:11:04 +01:00
parent 89e4213296
commit 5fe410279a
127 changed files with 37432 additions and 57496 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -42,8 +42,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try
{
vk::raii::Context context;
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
@ -53,11 +52,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool(
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandPool commandPool =
vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -67,63 +65,53 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::DescriptorSetLayout descriptorSetLayout =
vk::raii::su::makeDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule =
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 vertexShaderModule = 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 );
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers =
vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::raii::DescriptorPool descriptorPool =
vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets(
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, {} );
vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::raii::DescriptorSet descriptorSet = 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::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline(
device,
pipelineCache,
vertexShaderModule,
nullptr,
fragmentShaderModule,
nullptr,
vk::su::checked_cast<uint32_t>( sizeof( coloredCubeData[0] ) ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
fragmentShaderModule,
nullptr,
vk::su::checked_cast<uint32_t>( sizeof( coloredCubeData[0] ) ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
/* VULKAN_KEY_START */
@ -132,8 +120,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -142,21 +129,14 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues;
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 );
vk::RenderPassBeginInfo renderPassBeginInfo(
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
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.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.draw( 12 * 3, 1, 0, 0 );
@ -177,9 +157,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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
uint32_t loader_major_version = VK_VERSION_MAJOR( apiVersion );
uint32_t loader_minor_version = VK_VERSION_MINOR( apiVersion );
std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version
<< "\n";
std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version << "\n";
// Check current version against what we want to run
if ( loader_major_version > desiredMajorVersion ||
( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
if ( loader_major_version > desiredMajorVersion || ( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
{
// Create the instance
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
@ -91,13 +88,12 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( usingMinorVersion < desiredMinorVersion )
{
std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString
<< " instead of desired version " << desiredVersionString << std::endl;
std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString << " instead of desired version "
<< desiredVersionString << std::endl;
}
else
{
std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString
<< std::endl;
std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString << std::endl;
}
/* VULKAN_KEY_END */

View File

@ -27,8 +27,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try
{
vk::raii::Context context;
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
@ -45,11 +44,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool(
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandPool commandPool =
vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -59,8 +57,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc |
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc |
vk::ImageUsageFlagBits::eTransferDst,
{},
graphicsAndPresentQueueFamilyIndex.first,
@ -69,8 +66,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_START */
#if !defined( NDEBUG )
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( swapChainData.colorFormat );
assert( ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc ) &&
"Format cannot be used as transfer source" );
assert( ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc ) && "Format cannot be used as transfer source" );
#endif
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:
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -104,18 +99,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties();
vk::MemoryRequirements memoryRequirements = blitSourceImage.getMemoryRequirements();
uint32_t memoryTypeIndex = vk::su::findMemoryType(
memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible );
uint32_t memoryTypeIndex = vk::su::findMemoryType( memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
vk::raii::DeviceMemory deviceMemory( device, memoryAllocateInfo );
blitSourceImage.bindMemory( *deviceMemory, 0 );
vk::raii::su::setImageLayout( commandBuffer,
*blitSourceImage,
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eGeneral );
vk::raii::su::setImageLayout( commandBuffer, *blitSourceImage, swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eGeneral );
commandBuffer.end();
@ -154,27 +144,18 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() );
// Intend to blit from this image, set the layout accordingly
vk::raii::su::setImageLayout( commandBuffer,
*blitSourceImage,
swapChainData.colorFormat,
vk::ImageLayout::eGeneral,
vk::ImageLayout::eTransferSrcOptimal );
vk::raii::su::setImageLayout( commandBuffer, *blitSourceImage, swapChainData.colorFormat, vk::ImageLayout::eGeneral, vk::ImageLayout::eTransferSrcOptimal );
vk::Image blitDestinationImage = static_cast<vk::Image>( swapChainData.images[imageIndex] );
// Do a 32x32 blit to all of the dst image - should get big squares
vk::ImageSubresourceLayers imageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 );
vk::ImageBlit imageBlit(
imageSubresourceLayers,
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 32, 32, 1 ) } },
imageSubresourceLayers,
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( surfaceData.extent.width, surfaceData.extent.height, 1 ) } } );
commandBuffer.blitImage( *blitSourceImage,
vk::ImageLayout::eTransferSrcOptimal,
blitDestinationImage,
vk::ImageLayout::eTransferDstOptimal,
imageBlit,
vk::Filter::eLinear );
vk::ImageBlit imageBlit( imageSubresourceLayers,
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 32, 32, 1 ) } },
imageSubresourceLayers,
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( surfaceData.extent.width, surfaceData.extent.height, 1 ) } } );
commandBuffer.blitImage(
*blitSourceImage, 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
vk::ImageMemoryBarrier memoryBarrier( vk::AccessFlagBits::eTransferWrite,
@ -185,36 +166,21 @@ int main( int /*argc*/, char ** /*argv*/ )
VK_QUEUE_FAMILY_IGNORED,
blitDestinationImage,
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
commandBuffer.pipelineBarrier(
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, {}, nullptr, nullptr, memoryBarrier );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, {}, nullptr, nullptr, memoryBarrier );
// Do a image copy to part of the dst image - checks should stay small
vk::ImageCopy imageCopy( imageSubresourceLayers,
vk::Offset3D(),
imageSubresourceLayers,
vk::Offset3D( 256, 256, 0 ),
vk::Extent3D( 128, 128, 1 ) );
commandBuffer.copyImage( *blitSourceImage,
vk::ImageLayout::eTransferSrcOptimal,
blitDestinationImage,
vk::ImageLayout::eTransferDstOptimal,
imageCopy );
vk::ImageCopy imageCopy( imageSubresourceLayers, vk::Offset3D(), 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::AccessFlagBits::eTransferWrite,
vk::AccessFlagBits::eMemoryRead,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::ePresentSrcKHR,
VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED,
blitDestinationImage,
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer,
vk::PipelineStageFlagBits::eTopOfPipe,
{},
nullptr,
nullptr,
prePresentBarrier );
vk::ImageMemoryBarrier prePresentBarrier( vk::AccessFlagBits::eTransferWrite,
vk::AccessFlagBits::eMemoryRead,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::ePresentSrcKHR,
VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED,
blitDestinationImage,
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTopOfPipe, {}, nullptr, nullptr, prePresentBarrier );
commandBuffer.end();
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
@ -232,9 +198,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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"
<< "Object " << i << "\n";
message << "\t\t\t"
<< "objectType = "
<< vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) << "\n";
<< "objectType = " << vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) << "\n";
message << "\t\t\t"
<< "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n";
if ( pCallbackData->pObjects[i].pObjectName )
@ -98,14 +97,11 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::ExtensionProperties> props = context.enumerateInstanceExtensionProperties();
auto propsIterator = std::find_if( props.begin(),
props.end(),
[]( vk::ExtensionProperties const & ep )
{ return strcmp( ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) == 0; } );
auto propsIterator = std::find_if(
props.begin(), props.end(), []( vk::ExtensionProperties const & ep ) { return strcmp( ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) == 0; } );
if ( propsIterator == props.end() )
{
std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension"
<< std::endl;
std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension" << std::endl;
exit( 1 );
}
@ -116,12 +112,10 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
vk::DebugUtilsMessageSeverityFlagBitsEXT::eError );
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral |
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfoEXT(
{}, severityFlags, messageTypeFlags, &debugMessageFunc );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, debugUtilsMessengerCreateInfoEXT );
vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, debugUtilsMessengerCreateInfoEXT );
/* VULKAN_KEY_END */
}

View File

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

View File

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

View File

@ -37,8 +37,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try
{
vk::raii::Context context;
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
@ -48,11 +47,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool(
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandPool commandPool =
vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -62,32 +60,26 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule =
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 vertexShaderModule = 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 );
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers =
vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
/* VULKAN_KEY_START */
@ -100,9 +92,8 @@ int main( int /*argc*/, char ** /*argv*/ )
/* Set up uniform buffer with 2 transform matrices in it */
glm::mat4x4 mvpcs[2];
glm::mat4x4 model = glm::mat4x4( 1.0f );
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::mat4x4 model = glm::mat4x4( 1.0f );
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::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f );
// clang-format off
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 );
if ( limits.minUniformBufferOffsetAlignment )
{
bufferSize =
( bufferSize + limits.minUniformBufferOffsetAlignment - 1 ) & ~( limits.minUniformBufferOffsetAlignment - 1 );
bufferSize = ( bufferSize + limits.minUniformBufferOffsetAlignment - 1 ) & ~( limits.minUniformBufferOffsetAlignment - 1 );
}
vk::raii::su::BufferData uniformBufferData(
physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
vk::raii::su::BufferData uniformBufferData( physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcs, 2, bufferSize );
// create a DescriptorSetLayout with vk::DescriptorType::eUniformBufferDynamic
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::DescriptorSetLayout descriptorSetLayout =
vk::raii::su::makeDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
// create a DescriptorPool with vk::DescriptorType::eUniformBufferDynamic
vk::raii::DescriptorPool descriptorPool =
vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets(
device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, nullptr } }, {} );
vk::raii::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, nullptr } }, {} );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
fragmentShaderModule,
nullptr,
sizeof( coloredCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
fragmentShaderModule,
nullptr,
sizeof( coloredCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
// Get the index of the next available swapchain image:
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -169,32 +153,24 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues;
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 );
vk::RenderPassBeginInfo renderPassBeginInfo(
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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 ) );
/* The first draw should use the first matrix in the buffer */
uint32_t dynamicOffset = 0;
commandBuffer.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, dynamicOffset );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, dynamicOffset );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.draw( 12 * 3, 1, 0, 0 );
// the second draw should use the second matrix in the buffer;
dynamicOffset = (uint32_t)bufferSize;
commandBuffer.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, dynamicOffset );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, dynamicOffset );
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
@ -214,9 +190,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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 );
}
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance,
VkDebugUtilsMessengerEXT messenger,
VkAllocationCallbacks const * pAllocator )
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * 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++ )
{
message += std::string( "\t" ) + "Object " + std::to_string( i ) + "\n";
message += std::string( "\t\t" ) + "objectType = " +
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" ) + "objectType = " + 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";
if ( pCallbackData->pObjects[i].pObjectName )
{
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::raii::Instance instance( context, instanceCreateInfo );
pfnVkCreateDebugUtilsMessengerEXT =
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
if ( !pfnVkCreateDebugUtilsMessengerEXT )
{
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
exit( 1 );
}
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(
instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>( instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
if ( !pfnVkDestroyDebugUtilsMessengerEXT )
{
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::DebugUtilsMessageSeverityFlagBitsEXT::eError );
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral |
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfoEXT(
{}, severityFlags, messageTypeFlags, &debugMessageFunc );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, debugUtilsMessengerCreateInfoEXT );
vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, debugUtilsMessengerCreateInfoEXT );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
// get the index of the first queue family that supports graphics
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
float queuePriority = 0.0f;
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!)
vk::CommandPoolCreateInfo commandPoolCreateInfo( {}, graphicsQueueFamilyIndex );
vk::CommandPool commandPool =
( *device ).createCommandPool( commandPoolCreateInfo, nullptr, *device.getDispatcher() );
vk::CommandPool commandPool = ( *device ).createCommandPool( commandPoolCreateInfo, nullptr, *device.getDispatcher() );
// 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.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,8 +23,7 @@
struct PropertyData
{
PropertyData( vk::LayerProperties const & layerProperties_,
std::vector<vk::ExtensionProperties> const & extensionProperties_ )
PropertyData( vk::LayerProperties const & layerProperties_, std::vector<vk::ExtensionProperties> const & 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 << "\tVersion: " << lp.implementationVersion << std::endl;
std::cout << "\tAPI Version: (" << ( lp.specVersion >> 22 ) << "." << ( ( lp.specVersion >> 12 ) & 0x03FF ) << "."
<< ( lp.specVersion & 0xFFF ) << ")" << std::endl;
std::cout << "\tAPI Version: (" << ( lp.specVersion >> 22 ) << "." << ( ( lp.specVersion >> 12 ) & 0x03FF ) << "." << ( lp.specVersion & 0xFFF ) << ")"
<< std::endl;
std::cout << "\tDescription: " << lp.description << std::endl;
std::cout << std::endl;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -47,56 +47,80 @@ namespace vk
{
class CameraManipulator
{
public:
enum class Action { None, Orbit, 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:
enum class Action
{
None,
Orbit,
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:
CameraManipulator();
public:
CameraManipulator();
glm::vec3 const& getCameraPosition() const;
glm::vec3 const& getCenterPosition() const;
glm::mat4 const& getMatrix() const;
Mode getMode() const;
glm::ivec2 const& getMousePosition() const;
float getRoll() const;
float getSpeed() const;
glm::vec3 const& getUpVector() const;
glm::u32vec2 const& getWindowSize() const;
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 setMode(Mode mode);
void setMousePosition(glm::ivec2 const& position);
void setRoll(float roll); // roll in radians
void setSpeed(float speed);
void setWindowSize(glm::ivec2 const& size);
void wheel(int value);
glm::vec3 const & getCameraPosition() const;
glm::vec3 const & getCenterPosition() const;
glm::mat4 const & getMatrix() const;
Mode getMode() const;
glm::ivec2 const & getMousePosition() const;
float getRoll() const;
float getSpeed() const;
glm::vec3 const & getUpVector() const;
glm::u32vec2 const & getWindowSize() const;
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 setMode( Mode mode );
void setMousePosition( glm::ivec2 const & position );
void setRoll( float roll ); // roll in radians
void setSpeed( float speed );
void setWindowSize( glm::ivec2 const & size );
void wheel( int value );
private:
void dolly(glm::vec2 const& delta);
void motion(glm::ivec2 const& position, Action action = Action::None);
void orbit(glm::vec2 const& delta, bool invert = false);
void pan(glm::vec2 const& delta);
double projectOntoTBSphere(const glm::vec2& p);
void trackball(glm::ivec2 const& position);
void update();
private:
void dolly( glm::vec2 const & delta );
void motion( glm::ivec2 const & position, Action action = Action::None );
void orbit( glm::vec2 const & delta, bool invert = false );
void pan( glm::vec2 const & delta );
double projectOntoTBSphere( const glm::vec2 & p );
void trackball( glm::ivec2 const & position );
void update();
private:
glm::vec3 m_cameraPosition = glm::vec3(10, 10, 10);
glm::vec3 m_centerPosition = glm::vec3(0, 0, 0);
glm::vec3 m_upVector = glm::vec3(0, 1, 0);
float m_roll = 0; // Rotation around the Z axis in RAD
glm::mat4 m_matrix = glm::mat4(1);
private:
glm::vec3 m_cameraPosition = glm::vec3( 10, 10, 10 );
glm::vec3 m_centerPosition = glm::vec3( 0, 0, 0 );
glm::vec3 m_upVector = glm::vec3( 0, 1, 0 );
float m_roll = 0; // Rotation around the Z axis in RAD
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;
glm::ivec2 m_mousePosition = glm::ivec2(0, 0);
float m_speed = 30.0f;
glm::ivec2 m_mousePosition = glm::ivec2( 0, 0 );
Mode m_mode = Mode::Examine;
Mode m_mode = Mode::Examine;
};
} // namespace su
} // namespace su
} // namespace vk

View File

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

View File

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

View File

@ -71,8 +71,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try
{
vk::raii::Context context;
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG )
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
@ -82,11 +81,10 @@ int main( int /*argc*/, char ** /*argv*/ )
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool(
device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandPool commandPool =
vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -96,37 +94,30 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
vk::raii::ShaderModule vertexShaderModule =
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 vertexShaderModule = 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 );
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers =
vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::raii::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */
@ -171,54 +162,46 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, pipelineLayoutCreateInfo );
// Create a single pool to contain data for the descriptor set
std::array<vk::DescriptorPoolSize, 3> poolSizes = {
{ vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorType::eSampledImage, 1 ),
vk::DescriptorPoolSize( vk::DescriptorType::eSampler, 1 ) }
};
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
std::array<vk::DescriptorPoolSize, 3> poolSizes = { { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorType::eSampledImage, 1 ),
vk::DescriptorPoolSize( vk::DescriptorType::eSampler, 1 ) } };
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo(
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo( *textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::DescriptorImageInfo samplerInfo( *sampler, {}, {} );
std::array<vk::WriteDescriptorSet, 3> descriptorWrites = {
{ vk::WriteDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( *descriptorSet, 1, 0, vk::DescriptorType::eSampledImage, imageInfo ),
vk::WriteDescriptorSet( *descriptorSet, 2, 0, vk::DescriptorType::eSampler, samplerInfo ) }
};
std::array<vk::WriteDescriptorSet, 3> descriptorWrites = { { vk::WriteDescriptorSet(
*descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( *descriptorSet, 1, 0, vk::DescriptorType::eSampledImage, imageInfo ),
vk::WriteDescriptorSet( *descriptorSet, 2, 0, vk::DescriptorType::eSampler, samplerInfo ) } };
device.updateDescriptorSets( descriptorWrites, nullptr );
/* VULKAN_KEY_END */
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
// Get the index of the next available swapchain image:
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo(
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
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.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.draw( 12 * 3, 1, 0, 0 );
@ -262,9 +238,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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 << "\t\t"
<< "currentExtent = " << surfaceCapabilities.currentExtent.width << " x "
<< surfaceCapabilities.currentExtent.height << "\n";
<< "currentExtent = " << surfaceCapabilities.currentExtent.width << " x " << surfaceCapabilities.currentExtent.height << "\n";
std::cout << "\t\t"
<< "currentTransform = " << vk::to_string( surfaceCapabilities.currentTransform ) << "\n";
std::cout << "\t\t"
@ -38,13 +37,11 @@ void cout( vk::SurfaceCapabilitiesKHR const & surfaceCapabilities )
std::cout << "\t\t"
<< "maxImageCount = " << surfaceCapabilities.maxImageCount << "\n";
std::cout << "\t\t"
<< "maxImageExtent = " << surfaceCapabilities.maxImageExtent.width << " x "
<< surfaceCapabilities.maxImageExtent.height << "\n";
<< "maxImageExtent = " << surfaceCapabilities.maxImageExtent.width << " x " << surfaceCapabilities.maxImageExtent.height << "\n";
std::cout << "\t\t"
<< "minImageCount = " << surfaceCapabilities.minImageCount << "\n";
std::cout << "\t\t"
<< "minImageExtent = " << surfaceCapabilities.minImageExtent.width << " x "
<< surfaceCapabilities.minImageExtent.height << "\n";
<< "minImageExtent = " << surfaceCapabilities.minImageExtent.width << " x " << surfaceCapabilities.minImageExtent.height << "\n";
std::cout << "\t\t"
<< "supportedCompositeAlpha = " << vk::to_string( surfaceCapabilities.supportedCompositeAlpha ) << "\n";
std::cout << "\t\t"
@ -60,13 +57,12 @@ int main( int /*argc*/, char ** /*argv*/ )
{
vk::raii::Context context;
std::vector<vk::ExtensionProperties> instanceExtensionProperties = context.enumerateInstanceExtensionProperties();
bool supportsGetSurfaceCapabilities2 =
( std::find_if( instanceExtensionProperties.begin(),
instanceExtensionProperties.end(),
[]( vk::ExtensionProperties const & ep ) {
return strcmp( ep.extensionName, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME ) == 0;
} ) != instanceExtensionProperties.end() );
std::vector<vk::ExtensionProperties> instanceExtensionProperties = context.enumerateInstanceExtensionProperties();
bool supportsGetSurfaceCapabilities2 = ( std::find_if( instanceExtensionProperties.begin(),
instanceExtensionProperties.end(),
[]( vk::ExtensionProperties const & ep ) {
return strcmp( ep.extensionName, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME ) == 0;
} ) != instanceExtensionProperties.end() );
std::vector<std::string> extensions = vk::su::getInstanceExtensions();
if ( supportsGetSurfaceCapabilities2 )
@ -90,22 +86,19 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ )
{
// some properties are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties =
physicalDevices[i].enumerateDeviceExtensionProperties();
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << "\n";
if ( supportsGetSurfaceCapabilities2 )
{
auto surfaceCapabilities2 =
physicalDevices[i]
.getSurfaceCapabilities2KHR<vk::SurfaceCapabilities2KHR,
vk::DisplayNativeHdrSurfaceCapabilitiesAMD,
vk::SharedPresentSurfaceCapabilitiesKHR,
vk::SurfaceCapabilitiesFullScreenExclusiveEXT,
vk::SurfaceProtectedCapabilitiesKHR>( { *surfaceData.surface } );
auto surfaceCapabilities2 = physicalDevices[i]
.getSurfaceCapabilities2KHR<vk::SurfaceCapabilities2KHR,
vk::DisplayNativeHdrSurfaceCapabilitiesAMD,
vk::SharedPresentSurfaceCapabilitiesKHR,
vk::SurfaceCapabilitiesFullScreenExclusiveEXT,
vk::SurfaceProtectedCapabilitiesKHR>( { *surfaceData.surface } );
vk::SurfaceCapabilitiesKHR const & surfaceCapabilities =
surfaceCapabilities2.get<vk::SurfaceCapabilities2KHR>().surfaceCapabilities;
vk::SurfaceCapabilitiesKHR const & surfaceCapabilities = surfaceCapabilities2.get<vk::SurfaceCapabilities2KHR>().surfaceCapabilities;
cout( surfaceCapabilities );
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" ) )
{
vk::SharedPresentSurfaceCapabilitiesKHR sharedPresentSurfaceCapabilities =
surfaceCapabilities2.get<vk::SharedPresentSurfaceCapabilitiesKHR>();
vk::SharedPresentSurfaceCapabilitiesKHR sharedPresentSurfaceCapabilities = surfaceCapabilities2.get<vk::SharedPresentSurfaceCapabilitiesKHR>();
std::cout << "\tSharedPresentSurfaceCapabilitiesKHR:\n";
std::cout << "\t\t"
<< "sharedPresentSupportedUsageFlags = "
<< vk::to_string( sharedPresentSurfaceCapabilities.sharedPresentSupportedUsageFlags ) << "\n";
<< "sharedPresentSupportedUsageFlags = " << vk::to_string( sharedPresentSurfaceCapabilities.sharedPresentSupportedUsageFlags ) << "\n";
std::cout << "\n";
}
@ -135,15 +126,13 @@ int main( int /*argc*/, char ** /*argv*/ )
surfaceCapabilities2.get<vk::SurfaceCapabilitiesFullScreenExclusiveEXT>();
std::cout << "\tSurfaceCapabilitiesFullScreenExclusiveEXT:\n";
std::cout << "\t\t"
<< "fullScreenExclusiveSupported = "
<< !!surfaceCapabilitiesFullScreenExclusive.fullScreenExclusiveSupported << "\n";
<< "fullScreenExclusiveSupported = " << !!surfaceCapabilitiesFullScreenExclusive.fullScreenExclusiveSupported << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_KHR_surface_protected_capabilities" ) )
{
vk::SurfaceProtectedCapabilitiesKHR surfaceProtectedCapabilities =
surfaceCapabilities2.get<vk::SurfaceProtectedCapabilitiesKHR>();
vk::SurfaceProtectedCapabilitiesKHR surfaceProtectedCapabilities = surfaceCapabilities2.get<vk::SurfaceProtectedCapabilitiesKHR>();
std::cout << "\tSurfaceProtectedCapabilitiesKHR:\n";
std::cout << "\t\t"
<< "supportsProtected = " << !!surfaceProtectedCapabilities.supportsProtected << "\n";
@ -152,8 +141,7 @@ int main( int /*argc*/, char ** /*argv*/ )
}
else
{
vk::SurfaceCapabilitiesKHR surfaceCapabilities =
physicalDevices[i].getSurfaceCapabilitiesKHR( *surfaceData.surface );
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevices[i].getSurfaceCapabilitiesKHR( *surfaceData.surface );
cout( surfaceCapabilities );
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,14 +29,13 @@ int main( int /*argc*/, char ** /*argv*/ )
{
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( queueFamilyProperties );
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( queueFamilyProperties );
/* VULKAN_HPP_KEY_START */
@ -52,10 +51,9 @@ int main( int /*argc*/, char ** /*argv*/ )
// determine a queueFamilyIndex that suports present
// first check if the graphicsQueueFamiliyIndex is good enough
size_t presentQueueFamilyIndex =
physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( graphicsQueueFamilyIndex ), surface )
? graphicsQueueFamilyIndex
: queueFamilyProperties.size();
size_t presentQueueFamilyIndex = physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( graphicsQueueFamilyIndex ), surface )
? graphicsQueueFamilyIndex
: queueFamilyProperties.size();
if ( presentQueueFamilyIndex == queueFamilyProperties.size() )
{
// 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() ) ||
( presentQueueFamilyIndex == queueFamilyProperties.size() ) )
if ( ( graphicsQueueFamilyIndex == queueFamilyProperties.size() ) || ( presentQueueFamilyIndex == queueFamilyProperties.size() ) )
{
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
std::vector<vk::SurfaceFormatKHR> formats = physicalDevice.getSurfaceFormatsKHR( surface );
assert( !formats.empty() );
vk::Format format =
( formats[0].format == vk::Format::eUndefined ) ? vk::Format::eB8G8R8A8Unorm : formats[0].format;
vk::Format format = ( formats[0].format == vk::Format::eUndefined ) ? vk::Format::eB8G8R8A8Unorm : formats[0].format;
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface );
vk::Extent2D swapchainExtent;
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.
swapchainExtent.width =
vk::su::clamp( width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width );
swapchainExtent.height =
vk::su::clamp( height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height );
swapchainExtent.width = vk::su::clamp( width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width );
swapchainExtent.height = vk::su::clamp( height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height );
}
else
{
@ -118,19 +112,15 @@ int main( int /*argc*/, char ** /*argv*/ )
// The FIFO present mode is guaranteed by the spec to be supported
vk::PresentModeKHR swapchainPresentMode = vk::PresentModeKHR::eFifo;
vk::SurfaceTransformFlagBitsKHR preTransform =
( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity )
? vk::SurfaceTransformFlagBitsKHR::eIdentity
: surfaceCapabilities.currentTransform;
vk::SurfaceTransformFlagBitsKHR preTransform = ( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity )
? vk::SurfaceTransformFlagBitsKHR::eIdentity
: surfaceCapabilities.currentTransform;
vk::CompositeAlphaFlagBitsKHR compositeAlpha =
( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied )
? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied )
? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit )
? vk::CompositeAlphaFlagBitsKHR::eInherit
: vk::CompositeAlphaFlagBitsKHR::eOpaque;
( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit ) ? vk::CompositeAlphaFlagBitsKHR::eInherit
: vk::CompositeAlphaFlagBitsKHR::eOpaque;
vk::SwapchainCreateInfoKHR swapChainCreateInfo( vk::SwapchainCreateFlagsKHR(),
surface,
@ -148,8 +138,7 @@ int main( int /*argc*/, char ** /*argv*/ )
true,
nullptr );
uint32_t queueFamilyIndices[2] = { static_cast<uint32_t>( graphicsQueueFamilyIndex ),
static_cast<uint32_t>( presentQueueFamilyIndex ) };
uint32_t queueFamilyIndices[2] = { static_cast<uint32_t>( graphicsQueueFamilyIndex ), static_cast<uint32_t>( presentQueueFamilyIndex ) };
if ( graphicsQueueFamilyIndex != presentQueueFamilyIndex )
{
// 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;
imageViews.reserve( swapChainImages.size() );
vk::ImageViewCreateInfo imageViewCreateInfo(
{}, {}, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::ImageViewCreateInfo imageViewCreateInfo( {}, {}, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
for ( auto image : swapChainImages )
{
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
/* VULKAN_HPP_KEY_START */
@ -78,8 +75,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++ )
{
if ( ( typeBits & 1 ) &&
( ( memoryProperties.memoryTypes[i].propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal ) ==
vk::MemoryPropertyFlagBits::eDeviceLocal ) )
( ( memoryProperties.memoryTypes[i].propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal ) == vk::MemoryPropertyFlagBits::eDeviceLocal ) )
{
typeIndex = i;
break;
@ -87,18 +83,12 @@ int main( int /*argc*/, char ** /*argv*/ )
typeBits >>= 1;
}
assert( typeIndex != uint32_t( ~0 ) );
vk::DeviceMemory depthMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, typeIndex ) );
vk::DeviceMemory depthMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, typeIndex ) );
device.bindImageMemory( depthImage, depthMemory, 0 );
vk::ImageView depthView =
device.createImageView( vk::ImageViewCreateInfo( vk::ImageViewCreateFlags(),
depthImage,
vk::ImageViewType::e2D,
depthFormat,
{},
{ vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1 } ) );
vk::ImageView depthView = device.createImageView( vk::ImageViewCreateInfo(
vk::ImageViewCreateFlags(), depthImage, vk::ImageViewType::e2D, depthFormat, {}, { vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1 } ) );
// destroy depthView, depthMemory, and depthImage
device.destroyImageView( depthView );

View File

@ -42,21 +42,18 @@ int main( int /*argc*/, char ** /*argv*/ )
{
vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */
glm::mat4x4 model = glm::mat4x4( 1.0f );
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::mat4x4 model = glm::mat4x4( 1.0f );
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::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f );
// clang-format off
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
glm::mat4x4 mvpc = clip * projection * view * model;
vk::Buffer uniformDataBuffer = device.createBuffer(
vk::BufferCreateInfo( vk::BufferCreateFlags(), sizeof( mvpc ), vk::BufferUsageFlagBits::eUniformBuffer ) );
vk::Buffer uniformDataBuffer =
device.createBuffer( vk::BufferCreateInfo( vk::BufferCreateFlags(), sizeof( mvpc ), vk::BufferUsageFlagBits::eUniformBuffer ) );
vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements( uniformDataBuffer );
uint32_t typeIndex =
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::DeviceMemory uniformDataMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, typeIndex ) );
uint32_t typeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::DeviceMemory uniformDataMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, typeIndex ) );
uint8_t * pData = static_cast<uint8_t *>( device.mapMemory( uniformDataMemory, 0, memoryRequirements.size ) );
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 );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */
// create a DescriptorSetLayout
vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding(
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
vk::DescriptorSetLayout descriptorSetLayout = device.createDescriptorSetLayout(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), descriptorSetLayoutBinding ) );
vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
vk::DescriptorSetLayout descriptorSetLayout =
device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), descriptorSetLayoutBinding ) );
// create a PipelineLayout using that DescriptorSetLayout
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
// destroy the pipelineLayout and the descriptorSetLayout
device.destroyPipelineLayout( pipelineLayout );

View File

@ -42,38 +42,34 @@ int main( int /*argc*/, char ** /*argv*/ )
{
vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( vk::Extent2D( 0, 0 ) );
vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( vk::Extent2D( 0, 0 ) );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::DescriptorSetLayout descriptorSetLayout =
vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
/* VULKAN_HPP_KEY_START */
// create a descriptor pool
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 );
vk::DescriptorPool descriptorPool = device.createDescriptorPool(
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) );
vk::DescriptorPool descriptorPool =
device.createDescriptorPool( vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) );
// allocate a descriptor set
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::DescriptorBufferInfo descriptorBufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::WriteDescriptorSet writeDescriptorSet(
descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo );
vk::WriteDescriptorSet writeDescriptorSet( descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr );
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format;
vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format;
vk::Format depthFormat = vk::Format::eD16Unorm;
/* VULKAN_HPP_KEY_START */
@ -82,11 +78,9 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal );
vk::AttachmentReference depthReference( 1, vk::ImageLayout::eDepthStencilAttachmentOptimal );
vk::SubpassDescription subpass(
vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, {}, colorReference, {}, &depthReference );
vk::SubpassDescription subpass( vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, {}, colorReference, {}, &depthReference );
vk::RenderPass renderPass = device.createRenderPass(
vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachmentDescriptions, subpass ) );
vk::RenderPass renderPass = device.createRenderPass( vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachmentDescriptions, subpass ) );
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */
@ -47,7 +45,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<unsigned int> vertexShaderSPV;
#if !defined( NDEBUG )
bool ok =
bool ok =
#endif
vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C, vertexShaderSPV );
assert( ok );
@ -57,7 +55,7 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<unsigned int> fragmentShaderSPV;
#if !defined( NDEBUG )
ok =
ok =
#endif
vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C, fragmentShaderSPV );
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::su::SwapChainData swapChainData( physicalDevice,
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
nullptr,
graphicsAndPresentQueueFamilyIndex.first,
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -54,8 +50,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
@ -64,23 +59,21 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::RenderPass renderPass = vk::su::createRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
/* VULKAN_KEY_START */
// create a vertex buffer for some vertex and color data
vk::Buffer vertexBuffer = device.createBuffer( vk::BufferCreateInfo(
vk::BufferCreateFlags(), sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ) );
vk::Buffer vertexBuffer =
device.createBuffer( vk::BufferCreateInfo( vk::BufferCreateFlags(), sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ) );
// allocate device memory for that buffer
vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements( vertexBuffer );
uint32_t memoryTypeIndex =
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::DeviceMemory deviceMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
uint32_t memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::DeviceMemory deviceMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
// copy the vertex and color data into that device memory
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
device.bindBufferMemory( vertexBuffer, deviceMemory, 0 );
vk::Semaphore imageAcquiredSemaphore =
device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR(
swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() );
@ -103,10 +94,8 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass,
framebuffers[currentBuffer.value],
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
vk::Format::eD16Unorm );
vk::RenderPass renderPass =
vk::su::createRenderPass( device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, vk::Format::eD16Unorm );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::DescriptorSetLayout descriptorSetLayout =
vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
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 vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess();
/* VULKAN_KEY_START */
std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule, "main" )
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule, "main" )
};
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( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
};
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
vk::PipelineVertexInputStateCreateFlags(), // flags
vertexInputBindingDescription, // vertexBindingDescriptions
vertexInputAttributeDescriptions // vertexAttributeDescriptions
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateFlags(), // flags
vertexInputBindingDescription, // vertexBindingDescriptions
vertexInputAttributeDescriptions // vertexAttributeDescriptions
);
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList );
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateFlags(),
vk::PrimitiveTopology::eTriangleList );
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo(
vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo(
vk::PipelineRasterizationStateCreateFlags(), // flags
false, // depthClampEnable
false, // rasterizerDiscardEnable
vk::PolygonMode::eFill, // polygonMode
vk::CullModeFlagBits::eBack, // cullMode
vk::FrontFace::eClockwise, // frontFace
false, // depthBiasEnable
0.0f, // depthBiasConstantFactor
0.0f, // depthBiasClamp
0.0f, // depthBiasSlopeFactor
1.0f // lineWidth
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( vk::PipelineRasterizationStateCreateFlags(), // flags
false, // depthClampEnable
false, // rasterizerDiscardEnable
vk::PolygonMode::eFill, // polygonMode
vk::CullModeFlagBits::eBack, // cullMode
vk::FrontFace::eClockwise, // frontFace
false, // depthBiasEnable
0.0f, // depthBiasConstantFactor
0.0f, // depthBiasClamp
0.0f, // depthBiasSlopeFactor
1.0f // lineWidth
);
vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo(
vk::PipelineMultisampleStateCreateFlags(), // flags
vk::SampleCountFlagBits::e1 // rasterizationSamples
// other values can be default
vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( vk::PipelineMultisampleStateCreateFlags(), // flags
vk::SampleCountFlagBits::e1 // rasterizationSamples
// other values can be default
);
vk::StencilOpState stencilOpState(
vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(
vk::PipelineDepthStencilStateCreateFlags(), // flags
true, // depthTestEnable
true, // depthWriteEnable
vk::CompareOp::eLessOrEqual, // depthCompareOp
false, // depthBoundTestEnable
false, // stencilTestEnable
stencilOpState, // front
stencilOpState // back
vk::StencilOpState stencilOpState( vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo( vk::PipelineDepthStencilStateCreateFlags(), // flags
true, // depthTestEnable
true, // depthWriteEnable
vk::CompareOp::eLessOrEqual, // depthCompareOp
false, // depthBoundTestEnable
false, // stencilTestEnable
stencilOpState, // front
stencilOpState // back
);
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG |
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA );
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState(
false, // blendEnable
vk::BlendFactor::eZero, // srcColorBlendFactor
vk::BlendFactor::eZero, // dstColorBlendFactor
vk::BlendOp::eAdd, // colorBlendOp
vk::BlendFactor::eZero, // srcAlphaBlendFactor
vk::BlendFactor::eZero, // dstAlphaBlendFactor
vk::BlendOp::eAdd, // alphaBlendOp
colorComponentFlags // colorWriteMask
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB |
vk::ColorComponentFlagBits::eA );
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false, // blendEnable
vk::BlendFactor::eZero, // srcColorBlendFactor
vk::BlendFactor::eZero, // dstColorBlendFactor
vk::BlendOp::eAdd, // colorBlendOp
vk::BlendFactor::eZero, // srcAlphaBlendFactor
vk::BlendFactor::eZero, // dstAlphaBlendFactor
vk::BlendOp::eAdd, // alphaBlendOp
colorComponentFlags // colorWriteMask
);
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(
vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp
pipelineColorBlendAttachmentState, // attachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp
pipelineColorBlendAttachmentState, // attachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
);
std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(),
dynamicStates );
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(), dynamicStates );
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo(
vk::PipelineCreateFlags(), // flags
pipelineShaderStageCreateInfos, // stages
&pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState
&pipelineViewportStateCreateInfo, // pViewportState
&pipelineRasterizationStateCreateInfo, // pRasterizationState
&pipelineMultisampleStateCreateInfo, // pMultisampleState
&pipelineDepthStencilStateCreateInfo, // pDepthStencilState
&pipelineColorBlendStateCreateInfo, // pColorBlendState
&pipelineDynamicStateCreateInfo, // pDynamicState
pipelineLayout, // layout
renderPass // renderPass
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlags(), // flags
pipelineShaderStageCreateInfos, // stages
&pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState
&pipelineViewportStateCreateInfo, // pViewportState
&pipelineRasterizationStateCreateInfo, // pRasterizationState
&pipelineMultisampleStateCreateInfo, // pMultisampleState
&pipelineDepthStencilStateCreateInfo, // pDepthStencilState
&pipelineColorBlendStateCreateInfo, // pColorBlendState
&pipelineDynamicStateCreateInfo, // pDynamicState
pipelineLayout, // layout
renderPass // renderPass
);
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -59,73 +55,58 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::DescriptorSetLayout descriptorSetLayout =
vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
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 vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
coloredCubeData,
sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device, vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::DescriptorPool descriptorPool =
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets(
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline(
device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( coloredCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( coloredCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
/* VULKAN_KEY_START */
// Get the index of the next available swapchain image:
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
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.value < framebuffers.size() );
@ -134,22 +115,15 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues;
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 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass,
framebuffers[currentBuffer.value],
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.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 ) )
;
vk::Result result =
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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 )
// initialize the DipatchLoaderDynamic to use
static vk::DynamicLoader dl;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
#endif
@ -55,19 +54,15 @@ int main( int /*argc*/, char ** /*argv*/ )
// Translate the version into major/minor for easier comparison
uint32_t loader_major_version = VK_VERSION_MAJOR( apiVersion );
uint32_t loader_minor_version = VK_VERSION_MINOR( apiVersion );
std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version
<< "\n";
std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version << "\n";
// Check current version against what we want to run
if ( loader_major_version > desiredMajorVersion ||
( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
if ( loader_major_version > desiredMajorVersion || ( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
{
// Create the instance
vk::Instance instance =
vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions(), desiredVersion );
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions(), desiredVersion );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// 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
// want.
std::vector<vk::PhysicalDevice> desiredPhysicalDevices;
std::copy_if(
physicalDevices.begin(),
physicalDevices.end(),
std::back_inserter( desiredPhysicalDevices ),
[desiredVersion]( vk::PhysicalDevice const & pd ) { return pd.getProperties().apiVersion >= desiredVersion; } );
std::copy_if( physicalDevices.begin(),
physicalDevices.end(),
std::back_inserter( desiredPhysicalDevices ),
[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 ( desiredPhysicalDevices.size() > 0 )
@ -101,13 +95,12 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( usingMinorVersion < desiredMinorVersion )
{
std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString
<< " instead of desired version " << desiredVersionString << std::endl;
std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString << " instead of desired version "
<< desiredVersionString << std::endl;
}
else
{
std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString
<< std::endl;
std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString << std::endl;
}
/* 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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
@ -44,15 +43,12 @@ int main( int /*argc*/, char ** /*argv*/ )
exit( -1 );
}
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -61,8 +57,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferDst,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferDst,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
@ -70,25 +65,20 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_START */
#if !defined( NDEBUG )
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( swapChainData.colorFormat );
assert( ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc ) &&
"Format cannot be used as transfer source" );
assert( ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc ) && "Format cannot be used as transfer source" );
#endif
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
// Get the index of the next available swapchain image:
vk::ResultValue<uint32_t> nextImage =
device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
vk::ResultValue<uint32_t> nextImage = device.acquireNextImageKHR( swapChainData.swapChain, vk::su::FenceTimeout, imageAcquiredSemaphore, nullptr );
assert( nextImage.result == vk::Result::eSuccess );
assert( nextImage.value < swapChainData.images.size() );
uint32_t imageIndex = nextImage.value;
commandBuffer.begin( vk::CommandBufferBeginInfo() );
vk::su::setImageLayout( commandBuffer,
swapChainData.images[imageIndex],
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eTransferDstOptimal );
vk::su::setImageLayout(
commandBuffer, swapChainData.images[imageIndex], swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
// Create an image, map it, and write some values to the image
vk::ImageCreateInfo imageCreateInfo( vk::ImageCreateFlags(),
@ -104,18 +94,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties();
vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements( blitSourceImage );
uint32_t memoryTypeIndex = vk::su::findMemoryType(
memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible );
uint32_t memoryTypeIndex = vk::su::findMemoryType( memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible );
vk::DeviceMemory deviceMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
vk::DeviceMemory deviceMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
device.bindImageMemory( blitSourceImage, deviceMemory, 0 );
vk::su::setImageLayout( commandBuffer,
blitSourceImage,
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eGeneral );
vk::su::setImageLayout( commandBuffer, blitSourceImage, swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eGeneral );
commandBuffer.end();
@ -128,8 +112,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( device.waitForFences( commandFence, true, vk::su::FenceTimeout ) == vk::Result::eTimeout )
;
unsigned char * pImageMemory =
static_cast<unsigned char *>( device.mapMemory( deviceMemory, 0, memoryRequirements.size ) );
unsigned char * pImageMemory = static_cast<unsigned char *>( device.mapMemory( deviceMemory, 0, memoryRequirements.size ) );
// Checkerboard of 8x8 pixel squares
for ( uint32_t row = 0; row < surfaceData.extent.height; row++ )
@ -153,27 +136,18 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() );
// Intend to blit from this image, set the layout accordingly
vk::su::setImageLayout( commandBuffer,
blitSourceImage,
swapChainData.colorFormat,
vk::ImageLayout::eGeneral,
vk::ImageLayout::eTransferSrcOptimal );
vk::su::setImageLayout( commandBuffer, blitSourceImage, swapChainData.colorFormat, vk::ImageLayout::eGeneral, vk::ImageLayout::eTransferSrcOptimal );
vk::Image blitDestinationImage = swapChainData.images[imageIndex];
// Do a 32x32 blit to all of the dst image - should get big squares
vk::ImageSubresourceLayers imageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 );
vk::ImageBlit imageBlit(
imageSubresourceLayers,
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 32, 32, 1 ) } },
imageSubresourceLayers,
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( surfaceData.extent.width, surfaceData.extent.height, 1 ) } } );
commandBuffer.blitImage( blitSourceImage,
vk::ImageLayout::eTransferSrcOptimal,
blitDestinationImage,
vk::ImageLayout::eTransferDstOptimal,
imageBlit,
vk::Filter::eLinear );
vk::ImageBlit imageBlit( imageSubresourceLayers,
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 32, 32, 1 ) } },
imageSubresourceLayers,
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( surfaceData.extent.width, surfaceData.extent.height, 1 ) } } );
commandBuffer.blitImage(
blitSourceImage, 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
vk::ImageMemoryBarrier memoryBarrier( vk::AccessFlagBits::eTransferWrite,
@ -184,40 +158,23 @@ int main( int /*argc*/, char ** /*argv*/ )
VK_QUEUE_FAMILY_IGNORED,
blitDestinationImage,
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer,
vk::PipelineStageFlagBits::eTransfer,
vk::DependencyFlags(),
nullptr,
nullptr,
memoryBarrier );
commandBuffer.pipelineBarrier(
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, vk::DependencyFlags(), nullptr, nullptr, memoryBarrier );
// Do a image copy to part of the dst image - checks should stay small
vk::ImageCopy imageCopy( imageSubresourceLayers,
vk::Offset3D(),
imageSubresourceLayers,
vk::Offset3D( 256, 256, 0 ),
vk::Extent3D( 128, 128, 1 ) );
commandBuffer.copyImage( blitSourceImage,
vk::ImageLayout::eTransferSrcOptimal,
blitDestinationImage,
vk::ImageLayout::eTransferDstOptimal,
imageCopy );
vk::ImageCopy imageCopy( imageSubresourceLayers, vk::Offset3D(), 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::AccessFlagBits::eTransferWrite,
vk::AccessFlagBits::eMemoryRead,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::ePresentSrcKHR,
VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED,
swapChainData.images[imageIndex],
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer,
vk::PipelineStageFlagBits::eTopOfPipe,
vk::DependencyFlags(),
nullptr,
nullptr,
prePresentBarrier );
vk::ImageMemoryBarrier prePresentBarrier( vk::AccessFlagBits::eTransferWrite,
vk::AccessFlagBits::eMemoryRead,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::ePresentSrcKHR,
VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED,
swapChainData.images[imageIndex],
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
commandBuffer.pipelineBarrier(
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTopOfPipe, vk::DependencyFlags(), nullptr, nullptr, prePresentBarrier );
commandBuffer.end();
vk::Fence drawFence = device.createFence( {} );
@ -233,9 +190,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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 );
}
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance,
VkDebugUtilsMessengerEXT messenger,
VkAllocationCallbacks const * pAllocator )
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator )
{
return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator );
}
@ -85,8 +83,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc( VkDebugUtilsMessageSeverityFlag
message << "\t\t"
<< "Object " << i << "\n";
message << "\t\t\t"
<< "objectType = "
<< vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) << "\n";
<< "objectType = " << vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) << "\n";
message << "\t\t\t"
<< "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n";
if ( pCallbackData->pObjects[i].pObjectName )
@ -114,31 +111,26 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::ExtensionProperties> props = vk::enumerateInstanceExtensionProperties();
auto propertyIterator = std::find_if( props.begin(), props.end(), []( vk::ExtensionProperties const & ep ) {
return strcmp( ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) == 0;
} );
auto propertyIterator = std::find_if(
props.begin(), props.end(), []( vk::ExtensionProperties const & ep ) { return strcmp( ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) == 0; } );
if ( propertyIterator == props.end() )
{
std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension"
<< std::endl;
std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension" << std::endl;
exit( 1 );
}
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
const char * extensionName = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
vk::Instance instance =
vk::createInstance( vk::InstanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, {}, extensionName ) );
vk::Instance instance = vk::createInstance( vk::InstanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, {}, extensionName ) );
pfnVkCreateDebugUtilsMessengerEXT =
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
if ( !pfnVkCreateDebugUtilsMessengerEXT )
{
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
exit( 1 );
}
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(
instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>( instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
if ( !pfnVkDestroyDebugUtilsMessengerEXT )
{
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::DebugUtilsMessageSeverityFlagBitsEXT::eError );
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral |
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT(
vk::DebugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc ) );
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::DebugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc ) );
instance.destroyDebugUtilsMessengerEXT( debugUtilsMessenger );
instance.destroy();

View File

@ -33,16 +33,14 @@ int main( int /*argc*/, char ** /*argv*/ )
{
vk::Instance instance = vk::su::createInstance( AppName, EngineName );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::vector<vk::PhysicalDevice> physicalDevices = instance.enumeratePhysicalDevices();
assert( !physicalDevices.empty() );
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevices[0].getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevices[0], graphicsQueueFamilyIndex );
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevices[0].getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevices[0], graphicsQueueFamilyIndex );
// create an image
vk::ImageCreateInfo imageCreateInfo( {},
@ -54,12 +52,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::SampleCountFlagBits::e1,
vk::ImageTiling::eLinear,
vk::ImageUsageFlagBits::eTransferSrc );
vk::Image image = device.createImage( imageCreateInfo );
vk::Image image = device.createImage( imageCreateInfo );
/* VULKAN_KEY_START */
vk::DebugUtilsObjectNameInfoEXT debugUtilsObjectNameInfo(
vk::ObjectType::eImage, NON_DISPATCHABLE_HANDLE_TO_UINT64_CAST( VkImage, image ), "Image name" );
vk::DebugUtilsObjectNameInfoEXT debugUtilsObjectNameInfo( vk::ObjectType::eImage, NON_DISPATCHABLE_HANDLE_TO_UINT64_CAST( VkImage, image ), "Image name" );
device.setDebugUtilsObjectNameEXT( debugUtilsObjectNameInfo );
/* 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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -59,8 +55,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
@ -72,66 +67,53 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::DescriptorSetLayout descriptorSetLayout =
vk::su::createDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
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 vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool(
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::DescriptorPool descriptorPool =
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets(
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline =
vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
/* VULKAN_KEY_START */
// Get the index of the next available swapchain image:
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
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.value < framebuffers.size() );
@ -140,22 +122,15 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues;
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 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass,
framebuffers[currentBuffer.value],
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.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 ) )
;
vk::Result result =
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -70,8 +66,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
@ -79,26 +74,18 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
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 vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
coloredCubeData,
sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device, vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
/* VULKAN_KEY_START */
@ -111,9 +98,8 @@ int main( int /*argc*/, char ** /*argv*/ )
/* Set up uniform buffer with 2 transform matrices in it */
glm::mat4x4 mvpcs[2];
glm::mat4x4 model = glm::mat4x4( 1.0f );
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::mat4x4 model = glm::mat4x4( 1.0f );
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::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f );
// clang-format off
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 );
if ( limits.minUniformBufferOffsetAlignment )
{
bufferSize =
( bufferSize + limits.minUniformBufferOffsetAlignment - 1 ) & ~( limits.minUniformBufferOffsetAlignment - 1 );
bufferSize = ( bufferSize + limits.minUniformBufferOffsetAlignment - 1 ) & ~( limits.minUniformBufferOffsetAlignment - 1 );
}
vk::su::BufferData uniformBufferData(
physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
vk::su::BufferData uniformBufferData( physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcs, 2, bufferSize );
// create a DescriptorSetLayout with vk::DescriptorType::eUniformBufferDynamic
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::DescriptorSetLayout descriptorSetLayout =
vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
// create a DescriptorPool with vk::DescriptorType::eUniformBufferDynamic
vk::DescriptorPool descriptorPool =
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets(
device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, {} } }, {} );
vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, {} } }, {} );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline(
device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( coloredCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( coloredCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
// Get the index of the next available swapchain image:
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
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.value < framebuffers.size() );
@ -176,34 +155,25 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues;
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 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass,
framebuffers[currentBuffer.value],
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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 ) );
/* The first draw should use the first matrix in the buffer */
uint32_t dynamicOffset = 0;
commandBuffer.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, dynamicOffset );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, dynamicOffset );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.draw( 12 * 3, 1, 0, 0 );
// the second draw should use the second matrix in the buffer;
dynamicOffset = (uint32_t)bufferSize;
commandBuffer.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, dynamicOffset );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, dynamicOffset );
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
@ -218,14 +188,11 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::Result result =
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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 );
}
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance,
VkDebugUtilsMessengerEXT messenger,
VkAllocationCallbacks const * pAllocator )
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * 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++ )
{
message += std::string( "\t" ) + "Object " + std::to_string( i ) + "\n";
message += std::string( "\t\t" ) + "objectType = " +
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" ) + "objectType = " + 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";
if ( pCallbackData->pObjects[i].pObjectName )
{
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 )
{
// return true if all layers are listed in the properties
return std::all_of( layers.begin(), layers.end(), [&properties]( char const * name ) {
return std::find_if( properties.begin(), properties.end(), [&name]( vk::LayerProperties const & property ) {
return strcmp( property.layerName, name ) == 0;
} ) != properties.end();
} );
return std::all_of( layers.begin(),
layers.end(),
[&properties]( char const * name )
{
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*/ )
@ -123,8 +123,7 @@ int main( int /*argc*/, char ** /*argv*/ )
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
// initialize the DipatchLoaderDynamic to use
static vk::DynamicLoader dl;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
#endif
@ -146,25 +145,22 @@ int main( int /*argc*/, char ** /*argv*/ )
instanceExtensionNames.push_back( VK_EXT_DEBUG_UTILS_EXTENSION_NAME );
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
vk::InstanceCreateInfo instanceCreateInfo(
vk::InstanceCreateFlags(), &applicationInfo, instanceLayerNames, instanceExtensionNames );
vk::Instance instance = vk::createInstance( instanceCreateInfo );
vk::InstanceCreateInfo instanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, instanceLayerNames, instanceExtensionNames );
vk::Instance instance = vk::createInstance( instanceCreateInfo );
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
// initialize function pointers for instance
VULKAN_HPP_DEFAULT_DISPATCHER.init( instance );
#endif
pfnVkCreateDebugUtilsMessengerEXT =
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
if ( !pfnVkCreateDebugUtilsMessengerEXT )
{
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
exit( 1 );
}
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(
instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>( instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
if ( !pfnVkDestroyDebugUtilsMessengerEXT )
{
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::DebugUtilsMessageSeverityFlagBitsEXT::eError );
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral |
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT(
vk::DebugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc ) );
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::DebugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc ) );
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
// get the index of the first queue family that supports graphics
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
vk::DeviceQueueCreateFlags(), graphicsQueueFamilyIndex, 1, &queuePriority );
vk::Device device =
physicalDevice.createDevice( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) );
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), graphicsQueueFamilyIndex, 1, &queuePriority );
vk::Device device = physicalDevice.createDevice( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) );
// Create a CommandPool and don't destroy it, for testing purposes!
vk::CommandPool commandPool =
device.createCommandPool( vk::CommandPoolCreateInfo( vk::CommandPoolCreateFlags(), graphicsQueueFamilyIndex ) );
vk::CommandPool commandPool = device.createCommandPool( vk::CommandPoolCreateInfo( vk::CommandPoolCreateFlags(), graphicsQueueFamilyIndex ) );
#if true
// 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 );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
/* 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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsQueueFamilyIndex );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsQueueFamilyIndex, 0 );
@ -78,8 +75,7 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.reset( vk::CommandBufferResetFlags() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
commandBuffer.waitEvents(
event, vk::PipelineStageFlagBits::eHost, vk::PipelineStageFlagBits::eBottomOfPipe, nullptr, nullptr, nullptr );
commandBuffer.waitEvents( event, vk::PipelineStageFlagBits::eHost, vk::PipelineStageFlagBits::eBottomOfPipe, nullptr, nullptr, nullptr );
commandBuffer.end();
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -68,40 +64,30 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
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 vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */
@ -112,30 +98,26 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::DescriptorSetLayoutBinding, 2> bindings = {
vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ),
vk::DescriptorSetLayoutBinding(
1, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, textureData.sampler )
vk::DescriptorSetLayoutBinding( 1, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, textureData.sampler )
};
vk::DescriptorSetLayout descriptorSetLayout = device.createDescriptorSetLayout(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), bindings ) );
vk::DescriptorSetLayout descriptorSetLayout =
device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), bindings ) );
// Create pipeline layout
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
// Create a single pool to contain data for our descriptor set
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize(
vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPool descriptorPool = device.createDescriptorPool(
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPool descriptorPool =
device.createDescriptorPool( vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
// Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo(
textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo( textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
vk::WriteDescriptorSet( descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( descriptorSet, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
@ -144,44 +126,35 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_END */
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline =
vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
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.value < framebuffers.size() );
std::array<vk::ClearValue, 2> clearValues;
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 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass,
framebuffers[currentBuffer.value],
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.draw( 12 * 3, 1, 0, 0 );
@ -190,14 +163,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
vk::Result result =
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 50, 50 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 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
bool needsStaging = !( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eSampledImage );
vk::ImageCreateInfo imageCreateInfo(
vk::ImageCreateFlags(),
vk::ImageType::e2D,
format,
vk::Extent3D( surfaceData.extent, 1 ),
1,
1,
vk::SampleCountFlagBits::e1,
needsStaging ? vk::ImageTiling::eOptimal : vk::ImageTiling::eLinear,
vk::ImageUsageFlagBits::eSampled |
( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ),
vk::SharingMode::eExclusive,
{},
needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized );
vk::Image image = device.createImage( imageCreateInfo );
vk::ImageCreateInfo imageCreateInfo( vk::ImageCreateFlags(),
vk::ImageType::e2D,
format,
vk::Extent3D( surfaceData.extent, 1 ),
1,
1,
vk::SampleCountFlagBits::e1,
needsStaging ? vk::ImageTiling::eOptimal : vk::ImageTiling::eLinear,
vk::ImageUsageFlagBits::eSampled | ( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ),
vk::SharingMode::eExclusive,
{},
needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized );
vk::Image image = device.createImage( imageCreateInfo );
vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements( image );
uint32_t memoryTypeIndex = vk::su::findMemoryType(
physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
needsStaging ? vk::MemoryPropertyFlags()
: ( vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ) );
needsStaging ? vk::MemoryPropertyFlags() : ( vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ) );
// allocate memory
vk::DeviceMemory imageMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
vk::DeviceMemory imageMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
// bind memory
device.bindImageMemory( image, imageMemory, 0 );
@ -107,16 +99,13 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( needsStaging )
{
// Need a staging buffer to map and copy texture into
textureBuffer =
device.createBuffer( vk::BufferCreateInfo( vk::BufferCreateFlags(),
surfaceData.extent.width * surfaceData.extent.height * 4,
vk::BufferUsageFlagBits::eTransferSrc ) );
textureBuffer = device.createBuffer(
vk::BufferCreateInfo( vk::BufferCreateFlags(), surfaceData.extent.width * surfaceData.extent.height * 4, vk::BufferUsageFlagBits::eTransferSrc ) );
memoryRequirements = device.getBufferMemoryRequirements( textureBuffer );
memoryTypeIndex =
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
// allocate memory
textureBufferMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
@ -126,12 +115,10 @@ int main( int /*argc*/, char ** /*argv*/ )
}
else
{
vk::SubresourceLayout subresourceLayout =
device.getImageSubresourceLayout( image, vk::ImageSubresource( vk::ImageAspectFlagBits::eColor ) );
vk::SubresourceLayout subresourceLayout = device.getImageSubresourceLayout( image, vk::ImageSubresource( vk::ImageAspectFlagBits::eColor ) );
}
void * data = device.mapMemory(
needsStaging ? textureBufferMemory : imageMemory, 0, memoryRequirements.size, vk::MemoryMapFlags() );
void * data = device.mapMemory( needsStaging ? textureBufferMemory : imageMemory, 0, memoryRequirements.size, vk::MemoryMapFlags() );
// Checkerboard of 16x16 pixel squares
unsigned char * pImageMemory = static_cast<unsigned char *>( data );
@ -154,8 +141,7 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( needsStaging )
{
// Since we're going to blit to the texture image, set its layout to eTransferDstOptimal
vk::su::setImageLayout(
commandBuffer, image, format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
vk::su::setImageLayout( commandBuffer, image, format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
vk::BufferImageCopy copyRegion( 0,
surfaceData.extent.width,
surfaceData.extent.height,
@ -164,14 +150,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Extent3D( surfaceData.extent, 1 ) );
commandBuffer.copyBufferToImage( textureBuffer, image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
// Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY
vk::su::setImageLayout(
commandBuffer, image, format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::su::setImageLayout( commandBuffer, image, format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
}
else
{
// If we can use the linear tiled image as a texture, just do it
vk::su::setImageLayout(
commandBuffer, image, format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::su::setImageLayout( commandBuffer, image, format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal );
}
commandBuffer.end();
@ -194,9 +178,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::BorderColor::eFloatOpaqueWhite );
vk::Sampler sampler = device.createSampler( samplerCreateInfo );
vk::ImageViewCreateInfo imageViewCreateInfo(
{}, image, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::ImageView imageView = device.createImageView( imageViewCreateInfo );
vk::ImageViewCreateInfo imageViewCreateInfo( {}, image, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::ImageView imageView = device.createImageView( imageViewCreateInfo );
/* 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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
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 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -104,8 +100,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
@ -126,54 +121,36 @@ int main( int /*argc*/, char ** /*argv*/ )
1,
vk::SampleCountFlagBits::e1,
vk::ImageTiling::eOptimal,
vk::ImageUsageFlagBits::eInputAttachment |
vk::ImageUsageFlagBits::eTransferDst );
vk::ImageUsageFlagBits::eInputAttachment | vk::ImageUsageFlagBits::eTransferDst );
vk::Image inputImage = device.createImage( imageCreateInfo );
vk::MemoryRequirements memoryRequirements = device.getImageMemoryRequirements( inputImage );
uint32_t memoryTypeIndex = vk::su::findMemoryType(
physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlags() );
vk::DeviceMemory inputMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
uint32_t memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlags() );
vk::DeviceMemory inputMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
device.bindImageMemory( inputImage, inputMemory, 0 );
// Set the image layout to TRANSFER_DST_OPTIMAL to be ready for clear
commandBuffer.begin( vk::CommandBufferBeginInfo() );
vk::su::setImageLayout( commandBuffer,
inputImage,
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eTransferDstOptimal );
vk::su::setImageLayout( commandBuffer, inputImage, swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
commandBuffer.clearColorImage(
inputImage,
vk::ImageLayout::eTransferDstOptimal,
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 ) );
commandBuffer.clearColorImage( inputImage,
vk::ImageLayout::eTransferDstOptimal,
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 ) );
// Set the image layout to SHADER_READONLY_OPTIMAL for use by the shaders
vk::su::setImageLayout( commandBuffer,
inputImage,
swapChainData.colorFormat,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eShaderReadOnlyOptimal );
vk::su::setImageLayout(
commandBuffer, inputImage, swapChainData.colorFormat, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::ImageViewCreateInfo imageViewCreateInfo( {},
inputImage,
vk::ImageViewType::e2D,
swapChainData.colorFormat,
{},
{ vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::ImageView inputAttachmentView = device.createImageView( imageViewCreateInfo );
vk::ImageViewCreateInfo imageViewCreateInfo(
{}, inputImage, vk::ImageViewType::e2D, swapChainData.colorFormat, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::ImageView inputAttachmentView = device.createImageView( imageViewCreateInfo );
vk::DescriptorSetLayoutBinding layoutBinding(
0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment );
vk::DescriptorSetLayout descriptorSetLayout = device.createDescriptorSetLayout(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), layoutBinding ) );
vk::DescriptorSetLayoutBinding layoutBinding( 0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment );
vk::DescriptorSetLayout descriptorSetLayout =
device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), layoutBinding ) );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
std::array<vk::AttachmentDescription, 2> attachments = {
// 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 inputReference( 1, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::SubpassDescription subPass(
vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, inputReference, colorReference );
vk::RenderPass renderPass =
device.createRenderPass( vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachments, subPass ) );
vk::SubpassDescription subPass( vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, inputReference, colorReference );
vk::RenderPass renderPass = device.createRenderPass( vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachments, subPass ) );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, inputAttachmentView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, inputAttachmentView, surfaceData.extent );
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eInputAttachment, 1 );
vk::DescriptorPool descriptorPool = device.createDescriptorPool(
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) );
vk::DescriptorPool descriptorPool =
device.createDescriptorPool( vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::DescriptorImageInfo inputImageInfo( nullptr, inputAttachmentView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::WriteDescriptorSet writeDescriptorSet(
descriptorSet, 0, 0, vk::DescriptorType::eInputAttachment, inputImageInfo );
vk::WriteDescriptorSet writeDescriptorSet( descriptorSet, 0, 0, vk::DescriptorType::eInputAttachment, inputImageInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr );
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::ResultValue<uint32_t> nexImage = device.acquireNextImage2KHR(
vk::AcquireNextImageInfoKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, {}, 1 ) );
vk::ResultValue<uint32_t> nexImage =
device.acquireNextImage2KHR( vk::AcquireNextImageInfoKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, {}, 1 ) );
assert( nexImage.result == vk::Result::eSuccess );
uint32_t currentBuffer = nexImage.value;
vk::ClearValue clearValue;
clearValue.color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo(
renderPass, framebuffers[currentBuffer], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValue ),
vk::RenderPassBeginInfo( renderPass, framebuffers[currentBuffer], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValue ),
vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.draw( 3, 1, 0, 0 );
@ -278,9 +244,7 @@ int main( int /*argc*/, char ** /*argv*/ )
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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(),
extensionProperties.end(),
[]( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) {
return strcmp( a.extensionName, b.extensionName ) < 0;
} );
[]( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) { return strcmp( a.extensionName, b.extensionName ) < 0; } );
std::cout << "Instance Extensions:" << std::endl;
for ( auto const & ep : extensionProperties )

View File

@ -23,8 +23,7 @@
struct PropertyData
{
PropertyData( vk::LayerProperties const & layerProperties_,
std::vector<vk::ExtensionProperties> const & extensionProperties_ )
PropertyData( vk::LayerProperties const & layerProperties_, std::vector<vk::ExtensionProperties> const & 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 << "\tVersion: " << lp.implementationVersion << std::endl;
std::cout << "\tAPI Version: (" << ( lp.specVersion >> 22 ) << "." << ( ( lp.specVersion >> 12 ) & 0x03FF ) << "."
<< ( lp.specVersion & 0xFFF ) << ")" << std::endl;
std::cout << "\tAPI Version: (" << ( lp.specVersion >> 22 ) << "." << ( ( lp.specVersion >> 12 ) & 0x03FF ) << "." << ( lp.specVersion & 0xFFF ) << ")"
<< std::endl;
std::cout << "\tDescription: " << lp.description << std::endl;
std::cout << std::endl;
}

View File

@ -22,8 +22,8 @@
std::string decodeAPIVersion( uint32_t apiVersion )
{
return std::to_string( VK_VERSION_MAJOR( apiVersion ) ) + "." + std::to_string( VK_VERSION_MINOR( apiVersion ) ) +
"." + std::to_string( VK_VERSION_PATCH( apiVersion ) );
return std::to_string( VK_VERSION_MAJOR( apiVersion ) ) + "." + std::to_string( VK_VERSION_MINOR( apiVersion ) ) + "." +
std::to_string( VK_VERSION_PATCH( apiVersion ) );
}
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -118,8 +114,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
@ -131,67 +126,53 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
vk::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */
// Create first layout to contain uniform buffer data
vk::DescriptorSetLayoutBinding uniformBinding(
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
vk::DescriptorSetLayout uniformLayout = device.createDescriptorSetLayout(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), uniformBinding ) );
vk::DescriptorSetLayoutBinding uniformBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
vk::DescriptorSetLayout uniformLayout =
device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), uniformBinding ) );
// Create second layout containing combined sampler/image data
vk::DescriptorSetLayoutBinding sampler2DBinding(
0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex );
vk::DescriptorSetLayout samplerLayout = device.createDescriptorSetLayout(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), sampler2DBinding ) );
vk::DescriptorSetLayoutBinding sampler2DBinding( 0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex );
vk::DescriptorSetLayout samplerLayout =
device.createDescriptorSetLayout( vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), sampler2DBinding ) );
// Create pipeline layout with multiple descriptor sets
std::array<vk::DescriptorSetLayout, 2> descriptorSetLayouts = { { uniformLayout, samplerLayout } };
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayouts ) );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayouts ) );
// Create a single pool to contain data for our two descriptor sets
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize(
vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPool descriptorPool = device.createDescriptorPool(
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, poolSizes ) );
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPool descriptorPool =
device.createDescriptorPool( vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, poolSizes ) );
// Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayouts );
std::vector<vk::DescriptorSet> descriptorSets = device.allocateDescriptorSets( descriptorSetAllocateInfo );
// Populate with info about our uniform buffer
vk::DescriptorBufferInfo uniformBufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo textureImageInfo(
textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::DescriptorBufferInfo uniformBufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo textureImageInfo( textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
{ vk::WriteDescriptorSet( descriptorSets[0], 0, 0, vk::DescriptorType::eUniformBuffer, {}, uniformBufferInfo ),
vk::WriteDescriptorSet( descriptorSets[1], 0, 0, vk::DescriptorType::eCombinedImageSampler, textureImageInfo ) }
@ -200,46 +181,36 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_END */
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline =
vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
// Get the index of the next available swapchain image:
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
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.value < framebuffers.size() );
std::array<vk::ClearValue, 2> clearValues;
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 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass,
framebuffers[currentBuffer.value],
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, { descriptorSets[0], descriptorSets[1] }, nullptr );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, { descriptorSets[0], descriptorSets[1] }, nullptr );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.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 ) )
;
vk::Result result =
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -59,96 +55,76 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::DescriptorSetLayout descriptorSetLayout =
vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
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 vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
coloredCubeData,
sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device, vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vk::DescriptorPool descriptorPool =
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets(
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline(
device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( coloredCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( coloredCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
/* VULKAN_KEY_START */
vk::Semaphore imageAcquiredSemaphore =
device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
// Get the index of the next available swapchain image:
vk::ResultValue<uint32_t> currentBuffer =
device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() );
/* Allocate a uniform buffer that will take query results. */
vk::Buffer queryResultBuffer = device.createBuffer(
vk::BufferCreateInfo( vk::BufferCreateFlags(),
4 * sizeof( uint64_t ),
vk::BufferUsageFlagBits::eUniformBuffer | vk::BufferUsageFlagBits::eTransferDst ) );
vk::Buffer queryResultBuffer = device.createBuffer( vk::BufferCreateInfo(
vk::BufferCreateFlags(), 4 * sizeof( uint64_t ), vk::BufferUsageFlagBits::eUniformBuffer | vk::BufferUsageFlagBits::eTransferDst ) );
vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements( queryResultBuffer );
uint32_t memoryTypeIndex =
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::DeviceMemory queryResultMemory =
device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
uint32_t memoryTypeIndex = vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::DeviceMemory queryResultMemory = device.allocateMemory( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
device.bindBufferMemory( queryResultBuffer, queryResultMemory, 0 );
vk::QueryPool queryPool = device.createQueryPool( vk::QueryPoolCreateInfo(
vk::QueryPoolCreateFlags(), vk::QueryType::eOcclusion, 2, vk::QueryPipelineStatisticFlags() ) );
vk::QueryPool queryPool =
device.createQueryPool( vk::QueryPoolCreateInfo( vk::QueryPoolCreateFlags(), vk::QueryType::eOcclusion, 2, vk::QueryPipelineStatisticFlags() ) );
commandBuffer.begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) );
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::RenderPassBeginInfo( renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, {} );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.beginQuery( queryPool, 0, vk::QueryControlFlags() );
@ -182,13 +152,8 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.endRenderPass();
commandBuffer.endQuery( queryPool, 1 );
commandBuffer.copyQueryPoolResults( queryPool,
0,
2,
queryResultBuffer,
0,
sizeof( uint64_t ),
vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
commandBuffer.copyQueryPoolResults(
queryPool, 0, 2, queryResultBuffer, 0, sizeof( uint64_t ), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
commandBuffer.end();
vk::Fence drawFence = device.createFence( vk::FenceCreateInfo() );
@ -199,19 +164,12 @@ int main( int /*argc*/, char ** /*argv*/ )
graphicsQueue.waitIdle();
vk::ResultValue<std::vector<uint64_t>> rv =
device.getQueryPoolResults<uint64_t>( queryPool,
0,
2,
2 * sizeof( uint64_t ),
sizeof( uint64_t ),
vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
vk::ResultValue<std::vector<uint64_t>> rv = device.getQueryPoolResults<uint64_t>(
queryPool, 0, 2, 2 * sizeof( uint64_t ), sizeof( uint64_t ), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
switch ( rv.result )
{
case vk::Result::eSuccess: break;
case vk::Result::eNotReady:
std::cout << "vk::Device::getQueryPoolResults returned vk::Result::eNotReady !\n";
break;
case vk::Result::eNotReady: std::cout << "vk::Device::getQueryPoolResults returned vk::Result::eNotReady !\n"; break;
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";
/* Read back query result from buffer */
uint64_t * samplesPassedPtr = static_cast<uint64_t *>(
device.mapMemory( queryResultMemory, 0, memoryRequirements.size, vk::MemoryMapFlags() ) );
uint64_t * samplesPassedPtr = static_cast<uint64_t *>( device.mapMemory( queryResultMemory, 0, memoryRequirements.size, vk::MemoryMapFlags() ) );
std::cout << "vkCmdCopyQueryPoolResults data\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 ) )
;
vk::Result result =
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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 );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// enumerate the physicalDevices
@ -40,16 +39,13 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ )
{
std::vector<vk::ExtensionProperties> extensionProperties =
physicalDevices[i].enumerateDeviceExtensionProperties();
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << " : " << extensionProperties.size() << " extensions:\n";
// sort the extensions alphabetically
std::sort( extensionProperties.begin(),
extensionProperties.end(),
[]( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) {
return strcmp( a.extensionName, b.extensionName ) < 0;
} );
[]( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) { return strcmp( a.extensionName, b.extensionName ) < 0; } );
for ( auto const & ep : extensionProperties )
{
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 );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// enumerate the physicalDevices
@ -51,8 +50,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ )
{
// some features are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties =
physicalDevices[i].enumerateDeviceExtensionProperties();
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << " :\n";
auto features2 = physicalDevices[i]
@ -110,147 +108,85 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceFeatures const & features = features2.get<vk::PhysicalDeviceFeatures2>().features;
std::cout << "\tFeatures:\n";
std::cout << "\t\talphaToOne : " << !!features.alphaToOne << "\n";
std::cout << "\t\tdepthBiasClamp : " << !!features.depthBiasClamp
<< "\n";
std::cout << "\t\tdepthBounds : " << !!features.depthBounds
<< "\n";
std::cout << "\t\tdepthBiasClamp : " << !!features.depthBiasClamp << "\n";
std::cout << "\t\tdepthBounds : " << !!features.depthBounds << "\n";
std::cout << "\t\tdepthClamp : " << !!features.depthClamp << "\n";
std::cout << "\t\tdrawIndirectFirstInstance : "
<< !!features.drawIndirectFirstInstance << "\n";
std::cout << "\t\tdualSrcBlend : " << !!features.dualSrcBlend
<< "\n";
std::cout << "\t\tfillModeNonSolid : " << !!features.fillModeNonSolid
<< "\n";
std::cout << "\t\tfragmentStoresAndAtomics : "
<< !!features.fragmentStoresAndAtomics << "\n";
std::cout << "\t\tfullDrawIndexUint32 : " << !!features.fullDrawIndexUint32
<< "\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\tdrawIndirectFirstInstance : " << !!features.drawIndirectFirstInstance << "\n";
std::cout << "\t\tdualSrcBlend : " << !!features.dualSrcBlend << "\n";
std::cout << "\t\tfillModeNonSolid : " << !!features.fillModeNonSolid << "\n";
std::cout << "\t\tfragmentStoresAndAtomics : " << !!features.fragmentStoresAndAtomics << "\n";
std::cout << "\t\tfullDrawIndexUint32 : " << !!features.fullDrawIndexUint32 << "\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\tmultiDrawIndirect : " << !!features.multiDrawIndirect
<< "\n";
std::cout << "\t\tmultiViewport : " << !!features.multiViewport
<< "\n";
std::cout << "\t\tocclusionQueryPrecise : "
<< !!features.occlusionQueryPrecise << "\n";
std::cout << "\t\tpipelineStatisticsQuery : "
<< !!features.pipelineStatisticsQuery << "\n";
std::cout << "\t\trobustBufferAccess : " << !!features.robustBufferAccess
<< "\n";
std::cout << "\t\tsamplerAnisotropy : " << !!features.samplerAnisotropy
<< "\n";
std::cout << "\t\tsampleRateShading : " << !!features.sampleRateShading
<< "\n";
std::cout << "\t\tshaderClipDistance : " << !!features.shaderClipDistance
<< "\n";
std::cout << "\t\tshaderCullDistance : " << !!features.shaderCullDistance
<< "\n";
std::cout << "\t\tshaderFloat64 : " << !!features.shaderFloat64
<< "\n";
std::cout << "\t\tshaderImageGatherExtended : "
<< !!features.shaderImageGatherExtended << "\n";
std::cout << "\t\tshaderInt16 : " << !!features.shaderInt16
<< "\n";
std::cout << "\t\tshaderInt64 : " << !!features.shaderInt64
<< "\n";
std::cout << "\t\tshaderResourceMinLod : "
<< !!features.shaderResourceMinLod << "\n";
std::cout << "\t\tshaderResourceResidency : "
<< !!features.shaderResourceResidency << "\n";
std::cout << "\t\tshaderSampledImageArrayDynamicIndexing : "
<< !!features.shaderSampledImageArrayDynamicIndexing << "\n";
std::cout << "\t\tshaderStorageBufferArrayDynamicIndexing : "
<< !!features.shaderStorageBufferArrayDynamicIndexing << "\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\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\tmultiDrawIndirect : " << !!features.multiDrawIndirect << "\n";
std::cout << "\t\tmultiViewport : " << !!features.multiViewport << "\n";
std::cout << "\t\tocclusionQueryPrecise : " << !!features.occlusionQueryPrecise << "\n";
std::cout << "\t\tpipelineStatisticsQuery : " << !!features.pipelineStatisticsQuery << "\n";
std::cout << "\t\trobustBufferAccess : " << !!features.robustBufferAccess << "\n";
std::cout << "\t\tsamplerAnisotropy : " << !!features.samplerAnisotropy << "\n";
std::cout << "\t\tsampleRateShading : " << !!features.sampleRateShading << "\n";
std::cout << "\t\tshaderClipDistance : " << !!features.shaderClipDistance << "\n";
std::cout << "\t\tshaderCullDistance : " << !!features.shaderCullDistance << "\n";
std::cout << "\t\tshaderFloat64 : " << !!features.shaderFloat64 << "\n";
std::cout << "\t\tshaderImageGatherExtended : " << !!features.shaderImageGatherExtended << "\n";
std::cout << "\t\tshaderInt16 : " << !!features.shaderInt16 << "\n";
std::cout << "\t\tshaderInt64 : " << !!features.shaderInt64 << "\n";
std::cout << "\t\tshaderResourceMinLod : " << !!features.shaderResourceMinLod << "\n";
std::cout << "\t\tshaderResourceResidency : " << !!features.shaderResourceResidency << "\n";
std::cout << "\t\tshaderSampledImageArrayDynamicIndexing : " << !!features.shaderSampledImageArrayDynamicIndexing << "\n";
std::cout << "\t\tshaderStorageBufferArrayDynamicIndexing : " << !!features.shaderStorageBufferArrayDynamicIndexing << "\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\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 << "\n";
vk::PhysicalDevice16BitStorageFeatures const & sixteenBitStorageFeatures =
features2.get<vk::PhysicalDevice16BitStorageFeatures>();
vk::PhysicalDevice16BitStorageFeatures const & sixteenBitStorageFeatures = features2.get<vk::PhysicalDevice16BitStorageFeatures>();
std::cout << "\t16BitStorageFeatures:\n";
std::cout << "\t\tstorageBuffer16BitAccess : "
<< !!sixteenBitStorageFeatures.storageBuffer16BitAccess << "\n";
std::cout << "\t\tstorageInputOutput16 : "
<< !!sixteenBitStorageFeatures.storageInputOutput16 << "\n";
std::cout << "\t\tstoragePushConstant16 : "
<< !!sixteenBitStorageFeatures.storagePushConstant16 << "\n";
std::cout << "\t\tuniformAndStorageBuffer16BitAccess : "
<< !!sixteenBitStorageFeatures.uniformAndStorageBuffer16BitAccess << "\n";
std::cout << "\t\tstorageBuffer16BitAccess : " << !!sixteenBitStorageFeatures.storageBuffer16BitAccess << "\n";
std::cout << "\t\tstorageInputOutput16 : " << !!sixteenBitStorageFeatures.storageInputOutput16 << "\n";
std::cout << "\t\tstoragePushConstant16 : " << !!sixteenBitStorageFeatures.storagePushConstant16 << "\n";
std::cout << "\t\tuniformAndStorageBuffer16BitAccess : " << !!sixteenBitStorageFeatures.uniformAndStorageBuffer16BitAccess << "\n";
std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_KHR_8bit_storage" ) )
{
vk::PhysicalDevice8BitStorageFeaturesKHR const & eightBitStorageFeatures =
features2.get<vk::PhysicalDevice8BitStorageFeaturesKHR>();
vk::PhysicalDevice8BitStorageFeaturesKHR const & eightBitStorageFeatures = features2.get<vk::PhysicalDevice8BitStorageFeaturesKHR>();
std::cout << "\t8BitStorageFeatures:\n";
std::cout << "\t\tstorageBuffer8BitAccess : "
<< !!eightBitStorageFeatures.storageBuffer8BitAccess << "\n";
std::cout << "\t\tstoragePushConstant8 : "
<< !!eightBitStorageFeatures.storagePushConstant8 << "\n";
std::cout << "\t\tuniformAndStorageBuffer8BitAccess : "
<< !!eightBitStorageFeatures.uniformAndStorageBuffer8BitAccess << "\n";
std::cout << "\t\tstorageBuffer8BitAccess : " << !!eightBitStorageFeatures.storageBuffer8BitAccess << "\n";
std::cout << "\t\tstoragePushConstant8 : " << !!eightBitStorageFeatures.storagePushConstant8 << "\n";
std::cout << "\t\tuniformAndStorageBuffer8BitAccess : " << !!eightBitStorageFeatures.uniformAndStorageBuffer8BitAccess << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_EXT_astc_decode_mode" ) )
{
vk::PhysicalDeviceASTCDecodeFeaturesEXT const & astcDecodeFeatures =
features2.get<vk::PhysicalDeviceASTCDecodeFeaturesEXT>();
vk::PhysicalDeviceASTCDecodeFeaturesEXT const & astcDecodeFeatures = features2.get<vk::PhysicalDeviceASTCDecodeFeaturesEXT>();
std::cout << "\tASTCDecodeFeature:\n";
std::cout << "\t\tdecodeModeSharedExponent : "
<< !!astcDecodeFeatures.decodeModeSharedExponent << "\n";
std::cout << "\t\tdecodeModeSharedExponent : " << !!astcDecodeFeatures.decodeModeSharedExponent << "\n";
std::cout << "\n";
}
@ -259,8 +195,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT const & blendOperationAdvancedFeatures =
features2.get<vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT>();
std::cout << "\tBlendOperationAdvancedFeatures:\n";
std::cout << "\t\tadvancedBlendCoherentOperations : "
<< !!blendOperationAdvancedFeatures.advancedBlendCoherentOperations << "\n";
std::cout << "\t\tadvancedBlendCoherentOperations : " << !!blendOperationAdvancedFeatures.advancedBlendCoherentOperations << "\n";
std::cout << "\n";
}
@ -269,22 +204,17 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT const & bufferDeviceAddressFeatures =
features2.get<vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT>();
std::cout << "\tBufferDeviceAddressFeatures:\n";
std::cout << "\t\tbufferDeviceAddress : "
<< !!bufferDeviceAddressFeatures.bufferDeviceAddress << "\n";
std::cout << "\t\tbufferDeviceAddressCaptureReplay : "
<< !!bufferDeviceAddressFeatures.bufferDeviceAddressCaptureReplay << "\n";
std::cout << "\t\tbufferDeviceAddressMultiDevice : "
<< !!bufferDeviceAddressFeatures.bufferDeviceAddressMultiDevice << "\n";
std::cout << "\t\tbufferDeviceAddress : " << !!bufferDeviceAddressFeatures.bufferDeviceAddress << "\n";
std::cout << "\t\tbufferDeviceAddressCaptureReplay : " << !!bufferDeviceAddressFeatures.bufferDeviceAddressCaptureReplay << "\n";
std::cout << "\t\tbufferDeviceAddressMultiDevice : " << !!bufferDeviceAddressFeatures.bufferDeviceAddressMultiDevice << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_AMD_device_coherent_memory" ) )
{
vk::PhysicalDeviceCoherentMemoryFeaturesAMD const & coherentMemoryFeatures =
features2.get<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>();
vk::PhysicalDeviceCoherentMemoryFeaturesAMD const & coherentMemoryFeatures = features2.get<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>();
std::cout << "\tCoherentMemoryFeatures:\n";
std::cout << "\t\tdeviceCoherentMemory : " << !!coherentMemoryFeatures.deviceCoherentMemory
<< "\n";
std::cout << "\t\tdeviceCoherentMemory : " << !!coherentMemoryFeatures.deviceCoherentMemory << "\n";
std::cout << "\n";
}
@ -293,10 +223,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV const & computeShaderDerivativesFeatures =
features2.get<vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV>();
std::cout << "\tComputeShaderDerivativeFeatures:\n";
std::cout << "\t\tcomputeDerivativeGroupLinear : "
<< !!computeShaderDerivativesFeatures.computeDerivativeGroupLinear << "\n";
std::cout << "\t\tcomputeDerivativeGroupQuads : "
<< !!computeShaderDerivativesFeatures.computeDerivativeGroupQuads << "\n";
std::cout << "\t\tcomputeDerivativeGroupLinear : " << !!computeShaderDerivativesFeatures.computeDerivativeGroupLinear << "\n";
std::cout << "\t\tcomputeDerivativeGroupQuads : " << !!computeShaderDerivativesFeatures.computeDerivativeGroupQuads << "\n";
std::cout << "\n";
}
@ -305,32 +233,25 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceConditionalRenderingFeaturesEXT const & conditionalRenderingFeatures =
features2.get<vk::PhysicalDeviceConditionalRenderingFeaturesEXT>();
std::cout << "\tConditionalRenderingFeatures:\n";
std::cout << "\t\tconditionalRendering : "
<< !!conditionalRenderingFeatures.conditionalRendering << "\n";
std::cout << "\t\tinheritedConditionalRendering : "
<< !!conditionalRenderingFeatures.inheritedConditionalRendering << "\n";
std::cout << "\t\tconditionalRendering : " << !!conditionalRenderingFeatures.conditionalRendering << "\n";
std::cout << "\t\tinheritedConditionalRendering : " << !!conditionalRenderingFeatures.inheritedConditionalRendering << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_NV_cooperative_matrix" ) )
{
vk::PhysicalDeviceCooperativeMatrixFeaturesNV const & cooperativeMatrixFeatures =
features2.get<vk::PhysicalDeviceCooperativeMatrixFeaturesNV>();
vk::PhysicalDeviceCooperativeMatrixFeaturesNV const & cooperativeMatrixFeatures = features2.get<vk::PhysicalDeviceCooperativeMatrixFeaturesNV>();
std::cout << "\tCooperativeMatrixFeatures:\n";
std::cout << "\t\tcooperativeMatrix : "
<< !!cooperativeMatrixFeatures.cooperativeMatrix << "\n";
std::cout << "\t\tcooperativeMatrixRobustBufferAccess : "
<< !!cooperativeMatrixFeatures.cooperativeMatrixRobustBufferAccess << "\n";
std::cout << "\t\tcooperativeMatrix : " << !!cooperativeMatrixFeatures.cooperativeMatrix << "\n";
std::cout << "\t\tcooperativeMatrixRobustBufferAccess : " << !!cooperativeMatrixFeatures.cooperativeMatrixRobustBufferAccess << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_NV_corner_sampled_image" ) )
{
vk::PhysicalDeviceCornerSampledImageFeaturesNV const & cornerSampledImageFeatures =
features2.get<vk::PhysicalDeviceCornerSampledImageFeaturesNV>();
vk::PhysicalDeviceCornerSampledImageFeaturesNV const & cornerSampledImageFeatures = features2.get<vk::PhysicalDeviceCornerSampledImageFeaturesNV>();
std::cout << "\tCornerSampledImageFeatures:\n";
std::cout << "\t\tcornerSampledImage : " << !!cornerSampledImageFeatures.cornerSampledImage
<< "\n";
std::cout << "\t\tcornerSampledImage : " << !!cornerSampledImageFeatures.cornerSampledImage << "\n";
std::cout << "\n";
}
@ -339,8 +260,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceCoverageReductionModeFeaturesNV const & coverageReductionModeFeatures =
features2.get<vk::PhysicalDeviceCoverageReductionModeFeaturesNV>();
std::cout << "\tCoverageReductionModeFeatures:\n";
std::cout << "\t\tcoverageReductionMode : "
<< !!coverageReductionModeFeatures.coverageReductionMode << "\n";
std::cout << "\t\tcoverageReductionMode : " << !!coverageReductionModeFeatures.coverageReductionMode << "\n";
std::cout << "\n";
}
@ -349,16 +269,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV const & dedicatedAllocationImageAliasingFeatures =
features2.get<vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>();
std::cout << "\tDedicatedAllocationAliasingFeatures:\n";
std::cout << "\t\tdedicatedAllocationImageAliasing : "
<< !!dedicatedAllocationImageAliasingFeatures.dedicatedAllocationImageAliasing
<< "\n";
std::cout << "\t\tdedicatedAllocationImageAliasing : " << !!dedicatedAllocationImageAliasingFeatures.dedicatedAllocationImageAliasing << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_EXT_depth_clip_enable" ) )
{
vk::PhysicalDeviceDepthClipEnableFeaturesEXT const & depthClipEnabledFeatures =
features2.get<vk::PhysicalDeviceDepthClipEnableFeaturesEXT>();
vk::PhysicalDeviceDepthClipEnableFeaturesEXT const & depthClipEnabledFeatures = features2.get<vk::PhysicalDeviceDepthClipEnableFeaturesEXT>();
std::cout << "\tDepthClipEnabledFeatures:\n";
std::cout << "\t\tdepthClipEnable : " << !!depthClipEnabledFeatures.depthClipEnable << "\n";
std::cout << "\n";
@ -366,84 +283,64 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_descriptor_indexing" ) )
{
vk::PhysicalDeviceDescriptorIndexingFeaturesEXT const & descriptorIndexingFeatures =
features2.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
vk::PhysicalDeviceDescriptorIndexingFeaturesEXT const & descriptorIndexingFeatures = features2.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
std::cout << "\tDescriptorIndexingFeatures:\n";
std::cout << "\t\tdescriptorBindingPartiallyBound : "
<< !!descriptorIndexingFeatures.descriptorBindingPartiallyBound << "\n";
std::cout << "\t\tdescriptorBindingSampledImageUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingSampledImageUpdateAfterBind
std::cout << "\t\tdescriptorBindingPartiallyBound : " << !!descriptorIndexingFeatures.descriptorBindingPartiallyBound << "\n";
std::cout << "\t\tdescriptorBindingSampledImageUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingSampledImageUpdateAfterBind
<< "\n";
std::cout << "\t\tdescriptorBindingStorageBufferUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingStorageBufferUpdateAfterBind
std::cout << "\t\tdescriptorBindingStorageBufferUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingStorageBufferUpdateAfterBind
<< "\n";
std::cout << "\t\tdescriptorBindingStorageImageUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingStorageImageUpdateAfterBind
std::cout << "\t\tdescriptorBindingStorageImageUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingStorageImageUpdateAfterBind
<< "\n";
std::cout << "\t\tdescriptorBindingStorageTexelBufferUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingStorageTexelBufferUpdateAfterBind
<< "\n";
std::cout << "\t\tdescriptorBindingUniformBufferUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingUniformBufferUpdateAfterBind
<< !!descriptorIndexingFeatures.descriptorBindingStorageTexelBufferUpdateAfterBind << "\n";
std::cout << "\t\tdescriptorBindingUniformBufferUpdateAfterBind : " << !!descriptorIndexingFeatures.descriptorBindingUniformBufferUpdateAfterBind
<< "\n";
std::cout << "\t\tdescriptorBindingUniformTexelBufferUpdateAfterBind : "
<< !!descriptorIndexingFeatures.descriptorBindingUniformTexelBufferUpdateAfterBind
<< !!descriptorIndexingFeatures.descriptorBindingUniformTexelBufferUpdateAfterBind << "\n";
std::cout << "\t\tdescriptorBindingUpdateUnusedWhilePending : " << !!descriptorIndexingFeatures.descriptorBindingUpdateUnusedWhilePending
<< "\n";
std::cout << "\t\tdescriptorBindingUpdateUnusedWhilePending : "
<< !!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
std::cout << "\t\tdescriptorBindingVariableDescriptorCount : " << !!descriptorIndexingFeatures.descriptorBindingVariableDescriptorCount
<< "\n";
std::cout << "\t\tshaderSampledImageArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderSampledImageArrayNonUniformIndexing << "\n";
std::cout << "\t\tshaderStorageBufferArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderStorageBufferArrayNonUniformIndexing << "\n";
std::cout << "\t\tshaderStorageImageArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderStorageImageArrayNonUniformIndexing << "\n";
std::cout << "\t\tshaderStorageTexelBufferArrayDynamicIndexing : "
<< !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayDynamicIndexing
std::cout << "\t\truntimeDescriptorArray : " << !!descriptorIndexingFeatures.runtimeDescriptorArray << "\n";
std::cout << "\t\tshaderInputAttachmentArrayDynamicIndexing : " << !!descriptorIndexingFeatures.shaderInputAttachmentArrayDynamicIndexing
<< "\n";
std::cout << "\t\tshaderInputAttachmentArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderInputAttachmentArrayNonUniformIndexing
<< "\n";
std::cout << "\t\tshaderSampledImageArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderSampledImageArrayNonUniformIndexing
<< "\n";
std::cout << "\t\tshaderStorageBufferArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderStorageBufferArrayNonUniformIndexing
<< "\n";
std::cout << "\t\tshaderStorageImageArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderStorageImageArrayNonUniformIndexing
<< "\n";
std::cout << "\t\tshaderStorageTexelBufferArrayDynamicIndexing : " << !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayDynamicIndexing
<< "\n";
std::cout << "\t\tshaderStorageTexelBufferArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayNonUniformIndexing
<< !!descriptorIndexingFeatures.shaderStorageTexelBufferArrayNonUniformIndexing << "\n";
std::cout << "\t\tshaderUniformBufferArrayNonUniformIndexing : " << !!descriptorIndexingFeatures.shaderUniformBufferArrayNonUniformIndexing
<< "\n";
std::cout << "\t\tshaderUniformBufferArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderUniformBufferArrayNonUniformIndexing << "\n";
std::cout << "\t\tshaderUniformTexelBufferArrayDynamicIndexing : "
<< !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayDynamicIndexing
std::cout << "\t\tshaderUniformTexelBufferArrayDynamicIndexing : " << !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayDynamicIndexing
<< "\n";
std::cout << "\t\tshaderUniformTexelBufferArrayNonUniformIndexing : "
<< !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayNonUniformIndexing
<< "\n";
<< !!descriptorIndexingFeatures.shaderUniformTexelBufferArrayNonUniformIndexing << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_NV_scissor_exclusive" ) )
{
vk::PhysicalDeviceExclusiveScissorFeaturesNV const & exclusiveScissorFeatures =
features2.get<vk::PhysicalDeviceExclusiveScissorFeaturesNV>();
vk::PhysicalDeviceExclusiveScissorFeaturesNV const & exclusiveScissorFeatures = features2.get<vk::PhysicalDeviceExclusiveScissorFeaturesNV>();
std::cout << "\tExclusiveScissorFeatures:\n";
std::cout << "\t\texclusiveScissor : " << !!exclusiveScissorFeatures.exclusiveScissor
<< "\n";
std::cout << "\t\texclusiveScissor : " << !!exclusiveScissorFeatures.exclusiveScissor << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_EXT_fragment_density_map" ) )
{
vk::PhysicalDeviceFragmentDensityMapFeaturesEXT const & fragmentDensityMapFeatures =
features2.get<vk::PhysicalDeviceFragmentDensityMapFeaturesEXT>();
vk::PhysicalDeviceFragmentDensityMapFeaturesEXT const & fragmentDensityMapFeatures = features2.get<vk::PhysicalDeviceFragmentDensityMapFeaturesEXT>();
std::cout << "\tFragmentDensityMapFeatures:\n";
std::cout << "\t\tfragmentDensityMap : "
<< !!fragmentDensityMapFeatures.fragmentDensityMap << "\n";
std::cout << "\t\tfragmentDensityMapDynamic : "
<< !!fragmentDensityMapFeatures.fragmentDensityMapDynamic << "\n";
std::cout << "\t\tfragmentDensityMapNonSubsampledImages : "
<< !!fragmentDensityMapFeatures.fragmentDensityMapNonSubsampledImages << "\n";
std::cout << "\t\tfragmentDensityMap : " << !!fragmentDensityMapFeatures.fragmentDensityMap << "\n";
std::cout << "\t\tfragmentDensityMapDynamic : " << !!fragmentDensityMapFeatures.fragmentDensityMapDynamic << "\n";
std::cout << "\t\tfragmentDensityMapNonSubsampledImages : " << !!fragmentDensityMapFeatures.fragmentDensityMapNonSubsampledImages << "\n";
std::cout << "\n";
}
@ -452,8 +349,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV const & fragmentShaderBarycentricFeatures =
features2.get<vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV>();
std::cout << "\tFragmentShaderBarycentricFeatures:\n";
std::cout << "\t\tfragmentShaderBarycentric : "
<< !!fragmentShaderBarycentricFeatures.fragmentShaderBarycentric << "\n";
std::cout << "\t\tfragmentShaderBarycentric : " << !!fragmentShaderBarycentricFeatures.fragmentShaderBarycentric << "\n";
std::cout << "\n";
}
@ -462,19 +358,15 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT const & fragmentShaderInterlockFeatures =
features2.get<vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT>();
std::cout << "\tFragmentShaderInterlockFeatures:\n";
std::cout << "\t\tfragmentShaderPixelInterlock : "
<< !!fragmentShaderInterlockFeatures.fragmentShaderPixelInterlock << "\n";
std::cout << "\t\tfragmentShaderSampleInterlock : "
<< !!fragmentShaderInterlockFeatures.fragmentShaderSampleInterlock << "\n";
std::cout << "\t\tfragmentShaderShadingRateInterlock : "
<< !!fragmentShaderInterlockFeatures.fragmentShaderShadingRateInterlock << "\n";
std::cout << "\t\tfragmentShaderPixelInterlock : " << !!fragmentShaderInterlockFeatures.fragmentShaderPixelInterlock << "\n";
std::cout << "\t\tfragmentShaderSampleInterlock : " << !!fragmentShaderInterlockFeatures.fragmentShaderSampleInterlock << "\n";
std::cout << "\t\tfragmentShaderShadingRateInterlock : " << !!fragmentShaderInterlockFeatures.fragmentShaderShadingRateInterlock << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_EXT_host_query_reset" ) )
{
vk::PhysicalDeviceHostQueryResetFeaturesEXT const & hostQueryResetFeatures =
features2.get<vk::PhysicalDeviceHostQueryResetFeaturesEXT>();
vk::PhysicalDeviceHostQueryResetFeaturesEXT const & hostQueryResetFeatures = features2.get<vk::PhysicalDeviceHostQueryResetFeaturesEXT>();
std::cout << "\tHostQueryResetFeatures:\n";
std::cout << "\t\thostQueryReset : " << !!hostQueryResetFeatures.hostQueryReset << "\n";
std::cout << "\n";
@ -485,15 +377,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceImagelessFramebufferFeaturesKHR const & imagelessFramebufferFeatures =
features2.get<vk::PhysicalDeviceImagelessFramebufferFeaturesKHR>();
std::cout << "\tImagelessFramebufferFeatures:\n";
std::cout << "\t\timagelessFramebuffer : "
<< !!imagelessFramebufferFeatures.imagelessFramebuffer << "\n";
std::cout << "\t\timagelessFramebuffer : " << !!imagelessFramebufferFeatures.imagelessFramebuffer << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_EXT_index_type_uint8" ) )
{
vk::PhysicalDeviceIndexTypeUint8FeaturesEXT const & indexTypeUint8Features =
features2.get<vk::PhysicalDeviceIndexTypeUint8FeaturesEXT>();
vk::PhysicalDeviceIndexTypeUint8FeaturesEXT const & indexTypeUint8Features = features2.get<vk::PhysicalDeviceIndexTypeUint8FeaturesEXT>();
std::cout << "\tIndexTypeUint8Features:\n";
std::cout << "\t\tindexTypeUint8 : " << !!indexTypeUint8Features.indexTypeUint8 << "\n";
std::cout << "\n";
@ -501,41 +391,30 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_EXT_inline_uniform_block" ) )
{
vk::PhysicalDeviceInlineUniformBlockFeaturesEXT const & inlineUniformBlockFeatures =
features2.get<vk::PhysicalDeviceInlineUniformBlockFeaturesEXT>();
vk::PhysicalDeviceInlineUniformBlockFeaturesEXT const & inlineUniformBlockFeatures = features2.get<vk::PhysicalDeviceInlineUniformBlockFeaturesEXT>();
std::cout << "\tInlineUniformBlockFeatures:\n";
std::cout << "\t\tdescriptorBindingInlineUniformBlockUpdateAfterBind : "
<< !!inlineUniformBlockFeatures.descriptorBindingInlineUniformBlockUpdateAfterBind
<< "\n";
std::cout << "\t\tinlineUniformBlock : "
<< !!inlineUniformBlockFeatures.inlineUniformBlock << "\n";
<< !!inlineUniformBlockFeatures.descriptorBindingInlineUniformBlockUpdateAfterBind << "\n";
std::cout << "\t\tinlineUniformBlock : " << !!inlineUniformBlockFeatures.inlineUniformBlock << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_EXT_line_rasterization" ) )
{
vk::PhysicalDeviceLineRasterizationFeaturesEXT const & lineRasterizationFeatures =
features2.get<vk::PhysicalDeviceLineRasterizationFeaturesEXT>();
vk::PhysicalDeviceLineRasterizationFeaturesEXT const & lineRasterizationFeatures = features2.get<vk::PhysicalDeviceLineRasterizationFeaturesEXT>();
std::cout << "\tLineRasterizationFeatures:\n";
std::cout << "\t\tbresenhamLines : " << !!lineRasterizationFeatures.bresenhamLines
<< "\n";
std::cout << "\t\trectangularLines : "
<< !!lineRasterizationFeatures.rectangularLines << "\n";
std::cout << "\t\tsmoothLines : " << !!lineRasterizationFeatures.smoothLines
<< "\n";
std::cout << "\t\tstippledBresenhamLines : "
<< !!lineRasterizationFeatures.stippledBresenhamLines << "\n";
std::cout << "\t\tstippledRectangularLines : "
<< !!lineRasterizationFeatures.stippledRectangularLines << "\n";
std::cout << "\t\tstippledSmoothLines : "
<< !!lineRasterizationFeatures.stippledSmoothLines << "\n";
std::cout << "\t\tbresenhamLines : " << !!lineRasterizationFeatures.bresenhamLines << "\n";
std::cout << "\t\trectangularLines : " << !!lineRasterizationFeatures.rectangularLines << "\n";
std::cout << "\t\tsmoothLines : " << !!lineRasterizationFeatures.smoothLines << "\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";
}
if ( vk::su::contains( extensionProperties, "VK_EXT_memory_priority" ) )
{
vk::PhysicalDeviceMemoryPriorityFeaturesEXT const & memoryPriorityFeatures =
features2.get<vk::PhysicalDeviceMemoryPriorityFeaturesEXT>();
vk::PhysicalDeviceMemoryPriorityFeaturesEXT const & memoryPriorityFeatures = features2.get<vk::PhysicalDeviceMemoryPriorityFeaturesEXT>();
std::cout << "\tMemoryPriorityFeatures:\n";
std::cout << "\t\tmemoryPriority : " << !!memoryPriorityFeatures.memoryPriority << "\n";
std::cout << "\n";
@ -543,22 +422,18 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( vk::su::contains( extensionProperties, "VK_NV_mesh_shader" ) )
{
vk::PhysicalDeviceMeshShaderFeaturesNV const & meshShaderFeatures =
features2.get<vk::PhysicalDeviceMeshShaderFeaturesNV>();
vk::PhysicalDeviceMeshShaderFeaturesNV const & meshShaderFeatures = features2.get<vk::PhysicalDeviceMeshShaderFeaturesNV>();
std::cout << "\tMeshShaderFeatures:\n";
std::cout << "\t\tmeshShader : " << !!meshShaderFeatures.meshShader << "\n";
std::cout << "\t\ttaskShader : " << !!meshShaderFeatures.taskShader << "\n";
std::cout << "\n";
}
vk::PhysicalDeviceMultiviewFeatures const & multiviewFeatures =
features2.get<vk::PhysicalDeviceMultiviewFeatures>();
vk::PhysicalDeviceMultiviewFeatures const & multiviewFeatures = features2.get<vk::PhysicalDeviceMultiviewFeatures>();
std::cout << "\tMultiviewFeatures:\n";
std::cout << "\t\tmultiview : " << !!multiviewFeatures.multiview << "\n";
std::cout << "\t\tmultiviewGeometryShader : "
<< !!multiviewFeatures.multiviewGeometryShader << "\n";
std::cout << "\t\tmultiviewTessellationShader : "
<< !!multiviewFeatures.multiviewTessellationShader << "\n";
std::cout << "\t\tmultiviewGeometryShader : " << !!multiviewFeatures.multiviewGeometryShader << "\n";
std::cout << "\t\tmultiviewTessellationShader : " << !!multiviewFeatures.multiviewTessellationShader << "\n";
std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_KHR_pipeline_executable_properties" ) )
@ -566,13 +441,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR const & pipelineExecutablePropertiesFeatures =
features2.get<vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR>();
std::cout << "\tPipelineExectuablePropertiesFeatures:\n";
std::cout << "\t\tpipelineExecutableInfo : "
<< !!pipelineExecutablePropertiesFeatures.pipelineExecutableInfo << "\n";
std::cout << "\t\tpipelineExecutableInfo : " << !!pipelineExecutablePropertiesFeatures.pipelineExecutableInfo << "\n";
std::cout << "\n";
}
vk::PhysicalDeviceProtectedMemoryFeatures const & protectedMemoryFeatures =
features2.get<vk::PhysicalDeviceProtectedMemoryFeatures>();
vk::PhysicalDeviceProtectedMemoryFeatures const & protectedMemoryFeatures = features2.get<vk::PhysicalDeviceProtectedMemoryFeatures>();
std::cout << "\tProtectedMemoryFeatures:\n";
std::cout << "\t\tprotectedMemory : " << !!protectedMemoryFeatures.protectedMemory << "\n";
std::cout << "\n";
@ -582,37 +455,30 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV const & representativeFragmentTestFeatures =
features2.get<vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV>();
std::cout << "\tRepresentativeFragmentTestFeatures:\n";
std::cout << "\t\trepresentativeFragmentTest : "
<< !!representativeFragmentTestFeatures.representativeFragmentTest << "\n";
std::cout << "\t\trepresentativeFragmentTest : " << !!representativeFragmentTestFeatures.representativeFragmentTest << "\n";
std::cout << "\n";
}
vk::PhysicalDeviceSamplerYcbcrConversionFeatures const & samplerYcbcrConversionFeatures =
features2.get<vk::PhysicalDeviceSamplerYcbcrConversionFeatures>();
std::cout << "\tSamplerYcbcrConversionFeatures:\n";
std::cout << "\t\tsamplerYcbcrConversion : "
<< !!samplerYcbcrConversionFeatures.samplerYcbcrConversion << "\n";
std::cout << "\t\tsamplerYcbcrConversion : " << !!samplerYcbcrConversionFeatures.samplerYcbcrConversion << "\n";
std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_EXT_scalar_block_layout" ) )
{
vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT const & scalarBlockLayoutFeatures =
features2.get<vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT>();
vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT const & scalarBlockLayoutFeatures = features2.get<vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT>();
std::cout << "\tScalarBlockLayoutFeatures:\n";
std::cout << "\t\tscalarBlockLayout : " << !!scalarBlockLayoutFeatures.scalarBlockLayout
<< "\n";
std::cout << "\t\tscalarBlockLayout : " << !!scalarBlockLayoutFeatures.scalarBlockLayout << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_KHR_shader_atomic_int64" ) )
{
vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR const & shaderAtomicInt64Features =
features2.get<vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR>();
vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR const & shaderAtomicInt64Features = features2.get<vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR>();
std::cout << "\tShaderAtomicInt64Features:\n";
std::cout << "\t\tshaderBufferInt64Atomics : "
<< !!shaderAtomicInt64Features.shaderBufferInt64Atomics << "\n";
std::cout << "\t\tshaderSharedInt64Atomics : "
<< !!shaderAtomicInt64Features.shaderSharedInt64Atomics << "\n";
std::cout << "\t\tshaderBufferInt64Atomics : " << !!shaderAtomicInt64Features.shaderBufferInt64Atomics << "\n";
std::cout << "\t\tshaderSharedInt64Atomics : " << !!shaderAtomicInt64Features.shaderSharedInt64Atomics << "\n";
std::cout << "\n";
}
@ -621,22 +487,18 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT const & shaderDemoteToHelperInvocationFeatures =
features2.get<vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>();
std::cout << "\tShaderDemoteToHelperInvocationFeatures:\n";
std::cout << "\t\tshaderDemoteToHelperInvocation : "
<< !!shaderDemoteToHelperInvocationFeatures.shaderDemoteToHelperInvocation << "\n";
std::cout << "\t\tshaderDemoteToHelperInvocation : " << !!shaderDemoteToHelperInvocationFeatures.shaderDemoteToHelperInvocation << "\n";
std::cout << "\n";
}
vk::PhysicalDeviceShaderDrawParametersFeatures const & shaderDrawParametersFeature =
features2.get<vk::PhysicalDeviceShaderDrawParametersFeatures>();
vk::PhysicalDeviceShaderDrawParametersFeatures const & shaderDrawParametersFeature = features2.get<vk::PhysicalDeviceShaderDrawParametersFeatures>();
std::cout << "\tShaderDrawParametersFeature:\n";
std::cout << "\t\tshaderDrawParameters : "
<< !!shaderDrawParametersFeature.shaderDrawParameters << "\n";
std::cout << "\t\tshaderDrawParameters : " << !!shaderDrawParametersFeature.shaderDrawParameters << "\n";
std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_KHR_shader_float16_int8" ) )
{
vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR const & shaderFloat16Int8Features =
features2.get<vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR>();
vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR const & shaderFloat16Int8Features = features2.get<vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR>();
std::cout << "\tShaderFloat16Int8Features:\n";
std::cout << "\t\tshaderFloat16 : " << !!shaderFloat16Int8Features.shaderFloat16 << "\n";
std::cout << "\t\tshaderInt8 : " << !!shaderFloat16Int8Features.shaderInt8 << "\n";
@ -648,8 +510,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderImageFootprintFeaturesNV const & shaderImageFootprintFeatures =
features2.get<vk::PhysicalDeviceShaderImageFootprintFeaturesNV>();
std::cout << "\tShaderImageFootprintFeatures:\n";
std::cout << "\t\timageFootprint : " << !!shaderImageFootprintFeatures.imageFootprint
<< "\n";
std::cout << "\t\timageFootprint : " << !!shaderImageFootprintFeatures.imageFootprint << "\n";
std::cout << "\n";
}
@ -658,18 +519,15 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL const & shaderIntegerFunctions2Features =
features2.get<vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>();
std::cout << "\tShaderIntegerFunctions2Features:\n";
std::cout << "\t\tshaderIntegerFunctions2 : "
<< !!shaderIntegerFunctions2Features.shaderIntegerFunctions2 << "\n";
std::cout << "\t\tshaderIntegerFunctions2 : " << !!shaderIntegerFunctions2Features.shaderIntegerFunctions2 << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_NV_shader_sm_builtins" ) )
{
vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV const & shaderSMBuiltinsFeatures =
features2.get<vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV>();
vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV const & shaderSMBuiltinsFeatures = features2.get<vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV>();
std::cout << "\tShaderSMBuiltinsFeatures:\n";
std::cout << "\t\tshaderSMBuiltins : " << !!shaderSMBuiltinsFeatures.shaderSMBuiltins
<< "\n";
std::cout << "\t\tshaderSMBuiltins : " << !!shaderSMBuiltinsFeatures.shaderSMBuiltins << "\n";
std::cout << "\n";
}
@ -678,20 +536,16 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR const & shaderSubgroupExtendedTypesFeatures =
features2.get<vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR>();
std::cout << "\tShaderSubgroupExtendedTypeFeatures:\n";
std::cout << "\t\tshaderSubgroupExtendedTypes : "
<< !!shaderSubgroupExtendedTypesFeatures.shaderSubgroupExtendedTypes << "\n";
std::cout << "\t\tshaderSubgroupExtendedTypes : " << !!shaderSubgroupExtendedTypesFeatures.shaderSubgroupExtendedTypes << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_NV_shading_rate_image" ) )
{
vk::PhysicalDeviceShadingRateImageFeaturesNV const & shadingRateImageFeatures =
features2.get<vk::PhysicalDeviceShadingRateImageFeaturesNV>();
vk::PhysicalDeviceShadingRateImageFeaturesNV const & shadingRateImageFeatures = features2.get<vk::PhysicalDeviceShadingRateImageFeaturesNV>();
std::cout << "\tShadingRateImageFeatures:\n";
std::cout << "\t\tshadingRateCoarseSampleOrder : "
<< !!shadingRateImageFeatures.shadingRateCoarseSampleOrder << "\n";
std::cout << "\t\tshadingRateImage : "
<< !!shadingRateImageFeatures.shadingRateImage << "\n";
std::cout << "\t\tshadingRateCoarseSampleOrder : " << !!shadingRateImageFeatures.shadingRateCoarseSampleOrder << "\n";
std::cout << "\t\tshadingRateImage : " << !!shadingRateImageFeatures.shadingRateImage << "\n";
std::cout << "\n";
}
@ -700,10 +554,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT const & subgroupSizeControlFeatures =
features2.get<vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT>();
std::cout << "\tSubgroupSizeControlFeatures:\n";
std::cout << "\t\tcomputeFullSubgroups : "
<< !!subgroupSizeControlFeatures.computeFullSubgroups << "\n";
std::cout << "\t\tsubgroupSizeControl : "
<< !!subgroupSizeControlFeatures.subgroupSizeControl << "\n";
std::cout << "\t\tcomputeFullSubgroups : " << !!subgroupSizeControlFeatures.computeFullSubgroups << "\n";
std::cout << "\t\tsubgroupSizeControl : " << !!subgroupSizeControlFeatures.subgroupSizeControl << "\n";
std::cout << "\n";
}
@ -712,8 +564,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT const & texelBufferAlignmentFeatures =
features2.get<vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT>();
std::cout << "\tTexelBufferAlignmentFeatures:\n";
std::cout << "\t\ttexelBufferAlignment : "
<< !!texelBufferAlignmentFeatures.texelBufferAlignment << "\n";
std::cout << "\t\ttexelBufferAlignment : " << !!texelBufferAlignmentFeatures.texelBufferAlignment << "\n";
std::cout << "\n";
}
@ -722,29 +573,24 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT const & textureCompressionASTCHDRFeatures =
features2.get<vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT>();
std::cout << "\tTextureCompressionASTCHHRFeatures:\n";
std::cout << "\t\ttextureCompressionASTC_HDR : "
<< !!textureCompressionASTCHDRFeatures.textureCompressionASTC_HDR << "\n";
std::cout << "\t\ttextureCompressionASTC_HDR : " << !!textureCompressionASTCHDRFeatures.textureCompressionASTC_HDR << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_KHR_timeline_semaphore" ) )
{
vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR const & timelineSemaphoreFeatures =
features2.get<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR const & timelineSemaphoreFeatures = features2.get<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
std::cout << "\tTimelineSemaphoreFeatures:\n";
std::cout << "\t\ttimelineSemaphore :" << !!timelineSemaphoreFeatures.timelineSemaphore
<< "\n";
std::cout << "\t\ttimelineSemaphore :" << !!timelineSemaphoreFeatures.timelineSemaphore << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_EXT_transform_feedback" ) )
{
vk::PhysicalDeviceTransformFeedbackFeaturesEXT const & transformFeedbackFeatures =
features2.get<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>();
vk::PhysicalDeviceTransformFeedbackFeaturesEXT const & transformFeedbackFeatures = features2.get<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>();
std::cout << "\tTransformFeedbackFeatures:\n";
std::cout << "\t\tgeometryStreams : " << !!transformFeedbackFeatures.geometryStreams << "\n";
std::cout << "\t\ttransformFeedback : " << !!transformFeedbackFeatures.transformFeedback
<< "\n";
std::cout << "\t\ttransformFeedback : " << !!transformFeedbackFeatures.transformFeedback << "\n";
std::cout << "\n";
}
@ -753,20 +599,16 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR const & uniformBufferStandardLayoutFeatures =
features2.get<vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR>();
std::cout << "\tUniformBufferStandardLayoutFeatures:\n";
std::cout << "\t\tuniformBufferStandardLayout : "
<< !!uniformBufferStandardLayoutFeatures.uniformBufferStandardLayout << "\n";
std::cout << "\t\tuniformBufferStandardLayout : " << !!uniformBufferStandardLayoutFeatures.uniformBufferStandardLayout << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_KHR_variable_pointers" ) )
{
vk::PhysicalDeviceVariablePointersFeatures const & variablePointersFeatures =
features2.get<vk::PhysicalDeviceVariablePointersFeatures>();
vk::PhysicalDeviceVariablePointersFeatures const & variablePointersFeatures = features2.get<vk::PhysicalDeviceVariablePointersFeatures>();
std::cout << "\tVariablePointersFeatures:\n";
std::cout << "\t\tvariablePointers : "
<< !!variablePointersFeatures.variablePointers << "\n";
std::cout << "\t\tvariablePointersStorageBuffer : "
<< !!variablePointersFeatures.variablePointersStorageBuffer << "\n";
std::cout << "\t\tvariablePointers : " << !!variablePointersFeatures.variablePointers << "\n";
std::cout << "\t\tvariablePointersStorageBuffer : " << !!variablePointersFeatures.variablePointersStorageBuffer << "\n";
std::cout << "\n";
}
@ -775,35 +617,27 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT const & vertexAttributeDivisorFeatures =
features2.get<vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT>();
std::cout << "\tVertexAttributeDivisorFeature:\n";
std::cout << "\t\tvertexAttributeInstanceRateDivisor : "
<< !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateDivisor << "\n";
std::cout << "\t\tvertexAttributeInstanceRateZeroDivisor : "
<< !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateZeroDivisor << "\n";
std::cout << "\t\tvertexAttributeInstanceRateDivisor : " << !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateDivisor << "\n";
std::cout << "\t\tvertexAttributeInstanceRateZeroDivisor : " << !!vertexAttributeDivisorFeatures.vertexAttributeInstanceRateZeroDivisor << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_KHR_vulkan_memory_model" ) )
{
vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR const & vulkanMemoryModelFeatures =
features2.get<vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR>();
vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR const & vulkanMemoryModelFeatures = features2.get<vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR>();
std::cout << "\tVulkanMemoryModelFeatures:\n";
std::cout << "\t\tvulkanMemoryModel : "
<< !!vulkanMemoryModelFeatures.vulkanMemoryModel << "\n";
std::cout << "\t\tvulkanMemoryModelAvailabilityVisibilityChains : "
<< !!vulkanMemoryModelFeatures.vulkanMemoryModelAvailabilityVisibilityChains
std::cout << "\t\tvulkanMemoryModel : " << !!vulkanMemoryModelFeatures.vulkanMemoryModel << "\n";
std::cout << "\t\tvulkanMemoryModelAvailabilityVisibilityChains : " << !!vulkanMemoryModelFeatures.vulkanMemoryModelAvailabilityVisibilityChains
<< "\n";
std::cout << "\t\tvulkanMemoryModelDeviceScope : "
<< !!vulkanMemoryModelFeatures.vulkanMemoryModelDeviceScope << "\n";
std::cout << "\t\tvulkanMemoryModelDeviceScope : " << !!vulkanMemoryModelFeatures.vulkanMemoryModelDeviceScope << "\n";
std::cout << "\n";
}
if ( vk::su::contains( extensionProperties, "VK_KHR_sampler_ycbcr_conversion" ) )
{
vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT const & ycbcrImageArraysFeatures =
features2.get<vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT>();
vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT const & ycbcrImageArraysFeatures = features2.get<vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT>();
std::cout << "\tYcbcrImageArraysFeatures:\n";
std::cout << "\t\tycbcrImageArrays : " << !!ycbcrImageArraysFeatures.ycbcrImageArrays
<< "\n";
std::cout << "\t\tycbcrImageArrays : " << !!ycbcrImageArraysFeatures.ycbcrImageArrays << "\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 );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
/* VULKAN_KEY_START */
@ -61,21 +60,18 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
// get the first index into queueFamiliyProperties which supports graphics
auto propertyIterator = std::find_if(
queueFamilyProperties.begin(), queueFamilyProperties.end(), []( vk::QueueFamilyProperties const & qfp ) {
return qfp.queueFlags & vk::QueueFlagBits::eGraphics;
} );
auto propertyIterator = std::find_if( queueFamilyProperties.begin(),
queueFamilyProperties.end(),
[]( vk::QueueFamilyProperties const & qfp ) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; } );
size_t graphicsQueueFamilyIndex = std::distance( queueFamilyProperties.begin(), propertyIterator );
assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() );
// create a Device
float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo );
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo );
vk::DeviceGroupDeviceCreateInfo deviceGroupDeviceCreateInfo( groupProperties[i].physicalDeviceCount,
groupProperties[i].physicalDevices );
vk::DeviceGroupDeviceCreateInfo deviceGroupDeviceCreateInfo( groupProperties[i].physicalDeviceCount, groupProperties[i].physicalDevices );
deviceCreateInfo.pNext = &deviceGroupDeviceCreateInfo;
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 );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// enumerate the physicalDevices
@ -64,18 +63,13 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ )
{
// some properties are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties =
physicalDevices[i].enumerateDeviceExtensionProperties();
bool containsMemoryBudget = vk::su::contains( extensionProperties, "VK_EXT_memory_budget" );
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
bool containsMemoryBudget = vk::su::contains( extensionProperties, "VK_EXT_memory_budget" );
std::cout << "PhysicalDevice " << i << "\n";
auto memoryProperties2 =
physicalDevices[i]
.getMemoryProperties2<vk::PhysicalDeviceMemoryProperties2, vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
vk::PhysicalDeviceMemoryProperties const & memoryProperties =
memoryProperties2.get<vk::PhysicalDeviceMemoryProperties2>().memoryProperties;
vk::PhysicalDeviceMemoryBudgetPropertiesEXT const & memoryBudgetProperties =
memoryProperties2.get<vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
auto memoryProperties2 = physicalDevices[i].getMemoryProperties2<vk::PhysicalDeviceMemoryProperties2, 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";
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 );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// enumerate the physicalDevices
@ -44,21 +43,18 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < physicalDevices.size(); i++ )
{
// some features are only valid, if a corresponding extension is available!
std::vector<vk::ExtensionProperties> extensionProperties =
physicalDevices[i].enumerateDeviceExtensionProperties();
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
std::cout << "PhysicalDevice " << i << "\n";
// need to explicitly specify all the template arguments for getQueueFamilyProperties2 to make the compiler happy
using Chain = vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyCheckpointPropertiesNV>;
auto queueFamilyProperties2 =
physicalDevices[i].getQueueFamilyProperties2<Chain, std::allocator<Chain>, vk::DispatchLoaderDynamic>();
using Chain = vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyCheckpointPropertiesNV>;
auto queueFamilyProperties2 = physicalDevices[i].getQueueFamilyProperties2<Chain, std::allocator<Chain>, vk::DispatchLoaderDynamic>();
for ( size_t j = 0; j < queueFamilyProperties2.size(); j++ )
{
std::cout << "\t"
<< "QueueFamily " << j << "\n";
vk::QueueFamilyProperties const & properties =
queueFamilyProperties2[j].get<vk::QueueFamilyProperties2>().queueFamilyProperties;
vk::QueueFamilyProperties const & properties = queueFamilyProperties2[j].get<vk::QueueFamilyProperties2>().queueFamilyProperties;
std::cout << "\t\t"
<< "QueueFamilyProperties:\n";
std::cout << "\t\t\t"
@ -68,20 +64,17 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "\t\t\t"
<< "timestampValidBits = " << properties.timestampValidBits << "\n";
std::cout << "\t\t\t"
<< "minImageTransferGranularity = " << properties.minImageTransferGranularity.width << " x "
<< properties.minImageTransferGranularity.height << " x "
<< properties.minImageTransferGranularity.depth << "\n";
<< "minImageTransferGranularity = " << properties.minImageTransferGranularity.width << " x " << properties.minImageTransferGranularity.height
<< " x " << properties.minImageTransferGranularity.depth << "\n";
std::cout << "\n";
if ( vk::su::contains( extensionProperties, "VK_NV_device_diagnostic_checkpoints" ) )
{
vk::QueueFamilyCheckpointPropertiesNV const & checkpointProperties =
queueFamilyProperties2[j].get<vk::QueueFamilyCheckpointPropertiesNV>();
vk::QueueFamilyCheckpointPropertiesNV const & checkpointProperties = queueFamilyProperties2[j].get<vk::QueueFamilyCheckpointPropertiesNV>();
std::cout << "\t\t"
<< "CheckPointPropertiesNV:\n";
std::cout << "\t\t\t"
<< "checkpointExecutionStageMask = "
<< vk::to_string( checkpointProperties.checkpointExecutionStageMask ) << "\n";
<< "checkpointExecutionStageMask = " << vk::to_string( checkpointProperties.checkpointExecutionStageMask ) << "\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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
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 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -99,8 +95,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
@ -111,47 +106,36 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
vk::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::DescriptorSetLayout descriptorSetLayout =
vk::su::createDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
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 vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool(
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::DescriptorPool descriptorPool =
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets(
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
/* VULKAN_KEY_START */
@ -286,35 +270,32 @@ int main( int /*argc*/, char ** /*argv*/ )
}
// Feed the initial cache data into cache creation
vk::PipelineCache pipelineCache = device.createPipelineCache(
vk::PipelineCacheCreateInfo( vk::PipelineCacheCreateFlags(), startCacheSize, startCacheData ) );
vk::PipelineCache pipelineCache =
device.createPipelineCache( vk::PipelineCacheCreateInfo( vk::PipelineCacheCreateFlags(), startCacheSize, startCacheData ) );
// Free our initialData now that pipeline cache has been created
free( startCacheData );
startCacheData = NULL;
// Time (roughly) taken to create the graphics pipeline
timestamp_t start = getMilliseconds();
vk::Pipeline graphicsPipeline =
vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
timestamp_t elapsed = getMilliseconds() - start;
timestamp_t start = getMilliseconds();
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
timestamp_t elapsed = getMilliseconds() - start;
std::cout << " vkCreateGraphicsPipeline time: " << (double)elapsed << " ms\n";
vk::Semaphore imageAcquiredSemaphore =
device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
// Get the index of the next available swapchain image:
vk::ResultValue<uint32_t> currentBuffer =
device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() );
@ -323,20 +304,14 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::RenderPassBeginInfo( renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, {} );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.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 ) )
;
vk::Result result =
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -67,8 +63,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
@ -79,47 +74,36 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::DescriptorSetLayout descriptorSetLayout =
vk::su::createDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
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 vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::DescriptorPool descriptorPool = vk::su::createDescriptorPool(
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::DescriptorPool descriptorPool =
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
vk::DescriptorSet descriptorSet = device.allocateDescriptorSets( descriptorSetAllocateInfo ).front();
vk::su::updateDescriptorSets(
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
vk::su::updateDescriptorSets( device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
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.
std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule, "main" )
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "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 = {
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
@ -145,41 +127,31 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
vk::PipelineVertexInputStateCreateFlags(), vertexInputBindingDescription, vertexInputAttributeDescriptions );
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList );
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateFlags(),
vk::PrimitiveTopology::eTriangleList );
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo(
vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo(
vk::PipelineRasterizationStateCreateFlags(),
false,
false,
vk::PolygonMode::eFill,
vk::CullModeFlagBits::eBack,
vk::FrontFace::eClockwise,
false,
0.0f,
0.0f,
0.0f,
1.0f );
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( vk::PipelineRasterizationStateCreateFlags(),
false,
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::StencilOpState stencilOpState(
vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::StencilOpState stencilOpState( vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(
vk::PipelineDepthStencilStateCreateFlags(),
true,
true,
vk::CompareOp::eLessOrEqual,
false,
false,
stencilOpState,
stencilOpState );
vk::PipelineDepthStencilStateCreateFlags(), true, true, vk::CompareOp::eLessOrEqual, false, false, stencilOpState, stencilOpState );
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG |
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA );
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB |
vk::ColorComponentFlagBits::eA );
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false,
vk::BlendFactor::eZero,
vk::BlendFactor::eZero,
@ -188,15 +160,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::BlendFactor::eZero,
vk::BlendOp::eAdd,
colorComponentFlags );
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(),
false,
vk::LogicOp::eNoOp,
pipelineColorBlendAttachmentState,
{ { 1.0f, 1.0f, 1.0f, 1.0f } } );
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(
vk::PipelineColorBlendStateCreateFlags(), 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 };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(),
dynamicStates );
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(), dynamicStates );
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlagBits::eAllowDerivatives,
pipelineShaderStageCreateInfos,
@ -213,8 +181,7 @@ int main( int /*argc*/, char ** /*argv*/ )
renderPass );
vk::Pipeline basePipeline;
vk::ResultValue<vk::Pipeline> rvPipeline =
device.createGraphicsPipeline( pipelineCache, graphicsPipelineCreateInfo );
vk::ResultValue<vk::Pipeline> rvPipeline = device.createGraphicsPipeline( pipelineCache, graphicsPipelineCreateInfo );
switch ( rvPipeline.result )
{
case vk::Result::eSuccess: basePipeline = std::move( rvPipeline.value ); break;
@ -241,13 +208,12 @@ void main()
// Convert GLSL to SPIR-V
glslang::InitializeProcess();
vk::ShaderModule fragmentShaderModule2 =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C_2 );
vk::ShaderModule fragmentShaderModule2 = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C_2 );
glslang::FinalizeProcess();
// Modify pipeline info to reflect derivation
pipelineShaderStageCreateInfos[1] = vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule2, "main" );
pipelineShaderStageCreateInfos[1] =
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule2, "main" );
graphicsPipelineCreateInfo.flags = vk::PipelineCreateFlagBits::eDerivative;
graphicsPipelineCreateInfo.basePipelineHandle = basePipeline;
graphicsPipelineCreateInfo.basePipelineIndex = -1;
@ -266,12 +232,10 @@ void main()
/* VULKAN_KEY_END */
vk::Semaphore imageAcquiredSemaphore =
device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
// Get the index of the next available swapchain image
vk::ResultValue<uint32_t> currentBuffer =
device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
vk::ResultValue<uint32_t> currentBuffer = device.acquireNextImageKHR( swapChainData.swapChain, UINT64_MAX, imageAcquiredSemaphore, nullptr );
assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() );
@ -280,20 +244,14 @@ void main()
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::RenderPassBeginInfo( renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, derivedPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, {} );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.draw( 12 * 3, 1, 0, 0 );
@ -309,14 +267,11 @@ void main()
while ( vk::Result::eTimeout == device.waitForFences( drawFence, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::Result result =
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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() );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -108,59 +104,48 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::ShaderModule fragmentShaderModule =
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
vk::ShaderModule vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
// Create binding and layout for the following, matching contents of shader
// binding 0 = uniform buffer (MVP)
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::DescriptorSetLayout descriptorSetLayout =
vk::su::createDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
/* VULKAN_KEY_START */
// Set up our push constant range, which mirrors the declaration of
vk::PushConstantRange pushConstantRanges( vk::ShaderStageFlagBits::eFragment, 0, 8 );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout, pushConstantRanges ) );
vk::PipelineLayout pipelineLayout =
device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout, pushConstantRanges ) );
// Create a single pool to contain data for our descriptor set
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize(
vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPool descriptorPool = device.createDescriptorPool(
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPool descriptorPool =
device.createDescriptorPool( vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
// Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, descriptorSetLayout );
@ -168,37 +153,33 @@ int main( int /*argc*/, char ** /*argv*/ )
// Populate with info about our uniform buffer for MVP
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::WriteDescriptorSet writeDescriptorSet(
descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo );
vk::WriteDescriptorSet writeDescriptorSet( descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr );
// Create our push constant data, which matches shader expectations
std::array<unsigned, 2> pushConstants = { { (unsigned)2, (unsigned)0x3F800000 } };
// Ensure we have enough room for push constant data
assert( ( sizeof( pushConstants ) <= physicalDevice.getProperties().limits.maxPushConstantsSize ) &&
"Too many push constants" );
assert( ( sizeof( pushConstants ) <= physicalDevice.getProperties().limits.maxPushConstantsSize ) && "Too many push constants" );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
commandBuffer.pushConstants<unsigned>( pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, pushConstants );
/* VULKAN_KEY_END */
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline(
device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
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.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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass,
framebuffers[currentBuffer.value],
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, descriptorSet, nullptr );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.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 ) )
;
vk::Result result =
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
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 )
// initialize the DipatchLoaderDynamic to use
static vk::DynamicLoader dl;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
#endif
@ -45,9 +44,9 @@ int main( int /*argc*/, char ** /*argv*/ )
// To use PUSH_DESCRIPTOR, you must also specify GET_PHYSICAL_DEVICE_PROPERTIES_2
std::vector<vk::ExtensionProperties> extensionProperties = vk::enumerateInstanceExtensionProperties();
auto propertyIterator =
std::find_if( extensionProperties.begin(), extensionProperties.end(), []( vk::ExtensionProperties ep ) {
return ( strcmp( ep.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ) == 0 );
} );
std::find_if( extensionProperties.begin(),
extensionProperties.end(),
[]( vk::ExtensionProperties ep ) { return ( strcmp( ep.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ) == 0 ); } );
if ( propertyIterator == extensionProperties.end() )
{
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 );
#if !defined( NDEBUG )
vk::DebugUtilsMessengerEXT debugUtilsMessenger =
instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
// Once instance is created, need to make sure the extension is available
extensionProperties = physicalDevice.enumerateDeviceExtensionProperties();
propertyIterator =
std::find_if( extensionProperties.begin(), extensionProperties.end(), []( vk::ExtensionProperties ep ) {
return ( strcmp( ep.extensionName, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME ) == 0 );
} );
propertyIterator = std::find_if( extensionProperties.begin(),
extensionProperties.end(),
[]( vk::ExtensionProperties ep ) { return ( strcmp( ep.extensionName, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME ) == 0 ); } );
if ( propertyIterator == extensionProperties.end() )
{
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 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device =
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions );
vk::CommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
vk::CommandBuffer commandBuffer =
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
.front();
device.allocateCommandBuffers( vk::CommandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 ) ).front();
vk::Queue graphicsQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::Queue presentQueue = device.getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
@ -99,8 +93,7 @@ int main( int /*argc*/, char ** /*argv*/ )
device,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
{},
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
@ -111,92 +104,69 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::su::BufferData uniformBufferData(
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::BufferData uniformBufferData( physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcMatrix );
// Need to specify that descriptor set layout will be for push descriptors
vk::DescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } },
vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::DescriptorSetLayout descriptorSetLayout =
vk::su::createDescriptorSetLayout( device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } },
vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR );
vk::PipelineLayout pipelineLayout = device.createPipelineLayout( vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayout ) );
vk::RenderPass renderPass = vk::su::createRenderPass(
device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format,
depthBufferData.format );
device, vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format, depthBufferData.format );
glslang::InitializeProcess();
vk::ShaderModule vertexShaderModule =
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 vertexShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
vk::ShaderModule fragmentShaderModule = vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
glslang::FinalizeProcess();
std::vector<vk::Framebuffer> framebuffers = vk::su::createFramebuffers(
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::Framebuffer> framebuffers =
vk::su::createFramebuffers( device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
vk::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device,
vertexBufferData.deviceMemory,
texturedCubeData,
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::su::BufferData vertexBufferData( physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::su::copyToDevice( device, vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline =
vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
vk::PipelineCache pipelineCache = device.createPipelineCache( vk::PipelineCacheCreateInfo() );
vk::Pipeline graphicsPipeline = vk::su::createGraphicsPipeline( device,
pipelineCache,
std::make_pair( vertexShaderModule, nullptr ),
std::make_pair( fragmentShaderModule, nullptr ),
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
pipelineLayout,
renderPass );
// Get the index of the next available swapchain image:
vk::Semaphore imageAcquiredSemaphore = device.createSemaphore( vk::SemaphoreCreateInfo() );
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.value < framebuffers.size() );
std::array<vk::ClearValue, 2> clearValues;
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 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass,
framebuffers[currentBuffer.value],
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo(
renderPass, framebuffers[currentBuffer.value], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo(
textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::WriteDescriptorSet writeDescriptorSets[2] = {
vk::WriteDescriptorSet( {}, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( {}, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
};
vk::DescriptorImageInfo imageInfo( textureData.sampler, textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::WriteDescriptorSet writeDescriptorSets[2] = { 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 !!
commandBuffer.pushDescriptorSetKHR(
vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, { 2, writeDescriptorSets } );
commandBuffer.pushDescriptorSetKHR( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, { 2, writeDescriptorSets } );
commandBuffer.bindVertexBuffers( 0, vertexBufferData.buffer, { 0 } );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
0.0f,
static_cast<float>( surfaceData.extent.width ),
static_cast<float>( surfaceData.extent.height ),
0.0f,
1.0f ) );
commandBuffer.setViewport(
0, vk::Viewport( 0.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.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 ) )
;
vk::Result result =
presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, swapChainData.swapChain, currentBuffer.value ) );
switch ( result )
{
case vk::Result::eSuccess: break;
case vk::Result::eSuboptimalKHR:
std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
break;
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n"; break;
default: assert( false ); // an unexpected result is returned !
}
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );

View File

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

View File

@ -91,13 +91,13 @@ namespace vk
glm::vec3 const & getUpVector() const;
glm::u32vec2 const & getWindowSize() const;
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 setMode( Mode mode );
void setMousePosition( glm::ivec2 const & position );
void setRoll( float roll ); // roll in radians
void setSpeed( float speed );
void setWindowSize( glm::ivec2 const & size );
void wheel( int value );
void setLookat( const glm::vec3 & cameraPosition, const glm::vec3 & centerPosition, const glm::vec3 & upVector );
void setMode( Mode mode );
void setMousePosition( glm::ivec2 const & position );
void setRoll( float roll ); // roll in radians
void setSpeed( float speed );
void setWindowSize( glm::ivec2 const & size );
void wheel( int value );
private:
void dolly( glm::vec2 const & delta );

View File

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

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