Refactor RAII-samples to use std::unique_ptr only if needed.

This commit is contained in:
asuessenbach 2021-06-21 11:32:43 +02:00
parent da2ecae452
commit 69e8e5bf84
52 changed files with 2171 additions and 2437 deletions

View File

@ -15,8 +15,9 @@
// VulkanHpp Samples : 01_InitInstanceRAII
// Create and destroy a vk::UniqueInstance
#include "vulkan/vulkan_raii.hpp"
#include "../utils/utils.hpp"
#include "vulkan/vulkan_raii.hpp"
#include <iostream>
static std::string AppName = "01_InitInstanceRAII";
@ -29,7 +30,7 @@ int main( int /*argc*/, char ** /*argv*/ )
try
{
// the very beginning: instantiate a context
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
vk::raii::Context context;
// initialize the vk::ApplicationInfo structure
vk::ApplicationInfo applicationInfo( AppName.c_str(), 1, EngineName.c_str(), 1, VK_API_VERSION_1_1 );
@ -38,7 +39,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::InstanceCreateInfo instanceCreateInfo( {}, &applicationInfo );
// create an Instance
std::unique_ptr<vk::raii::Instance> instance = vk::raii::su::make_unique<vk::raii::Instance>( *context, instanceCreateInfo );
vk::raii::Instance instance( context, instanceCreateInfo );
}
catch ( vk::SystemError & err )
{

View File

@ -36,17 +36,16 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance = vk::raii::su::makeUniqueInstance( *context, AppName, EngineName );
vk::raii::Context context;
vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
/* VULKAN_HPP_KEY_START */
// enumerate the physicalDevices
vk::raii::PhysicalDevices physicalDevices( *instance );
vk::raii::PhysicalDevices physicalDevices( instance );
/* VULKAN_HPP_KEY_END */
}

View File

@ -26,26 +26,25 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance = vk::raii::su::makeUniqueInstance( *context, AppName, EngineName );
vk::raii::Context context;
vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
/* VULKAN_HPP_KEY_START */
// find the index of the first queue family that supports graphics
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice->getQueueFamilyProperties() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
// create a Device
float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( {}, graphicsQueueFamilyIndex, 1, &queuePriority );
vk::DeviceCreateInfo deviceCreateInfo( {}, deviceQueueCreateInfo );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::make_unique<vk::raii::Device>( *physicalDevice, deviceCreateInfo );
vk::raii::Device device( physicalDevice, deviceCreateInfo );
/* VULKAN_HPP_KEY_END */
}

View File

@ -26,29 +26,27 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance = vk::raii::su::makeUniqueInstance( *context, AppName, EngineName );
vk::raii::Context context;
vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice->getQueueFamilyProperties() );
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::makeUniqueDevice( *physicalDevice, graphicsQueueFamilyIndex );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */
// create a CommandPool to allocate a CommandBuffer from
vk::CommandPoolCreateInfo commandPoolCreateInfo( {}, graphicsQueueFamilyIndex );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::make_unique<vk::raii::CommandPool>( *device, commandPoolCreateInfo );
vk::raii::CommandPool commandPool( device, commandPoolCreateInfo );
// allocate a CommandBuffer from the CommandPool
vk::CommandBufferAllocateInfo commandBufferAllocateInfo( **commandPool, vk::CommandBufferLevel::ePrimary, 1 );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer = vk::raii::su::make_unique<vk::raii::CommandBuffer>(
std::move( vk::raii::CommandBuffers( *device, commandBufferAllocateInfo ).front() ) );
vk::CommandBufferAllocateInfo commandBufferAllocateInfo( *commandPool, vk::CommandBufferLevel::ePrimary, 1 );
vk::raii::CommandBuffer commandBuffer =
std::move( vk::raii::CommandBuffers( device, commandBufferAllocateInfo ).front() );
/* VULKAN_HPP_KEY_END */
}

View File

@ -26,15 +26,15 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice->getQueueFamilyProperties();
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 );
/* VULKAN_HPP_KEY_START */
@ -43,12 +43,12 @@ int main( int /*argc*/, char ** /*argv*/ )
uint32_t height = 64;
vk::su::WindowData window = vk::su::createWindow( AppName, { width, height } );
VkSurfaceKHR _surface;
glfwCreateWindowSurface( static_cast<VkInstance>( **instance ), window.handle, nullptr, &_surface );
std::unique_ptr<vk::raii::SurfaceKHR> surface = vk::raii::su::make_unique<vk::raii::SurfaceKHR>( *instance, _surface );
glfwCreateWindowSurface( static_cast<VkInstance>( *instance ), window.handle, nullptr, &_surface );
vk::raii::SurfaceKHR surface( instance, _surface );
// determine a queueFamilyIndex that suports present
// first check if the graphicsQueueFamiliyIndex is good enough
uint32_t presentQueueFamilyIndex = physicalDevice->getSurfaceSupportKHR( graphicsQueueFamilyIndex, **surface )
uint32_t presentQueueFamilyIndex = physicalDevice.getSurfaceSupportKHR( graphicsQueueFamilyIndex, *surface )
? graphicsQueueFamilyIndex
: vk::su::checked_cast<uint32_t>( queueFamilyProperties.size() );
if ( presentQueueFamilyIndex == queueFamilyProperties.size() )
@ -58,7 +58,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
{
if ( ( queueFamilyProperties[i].queueFlags & vk::QueueFlagBits::eGraphics ) &&
physicalDevice->getSurfaceSupportKHR( vk::su::checked_cast<uint32_t>( i ), **surface ) )
physicalDevice.getSurfaceSupportKHR( vk::su::checked_cast<uint32_t>( i ), *surface ) )
{
graphicsQueueFamilyIndex = vk::su::checked_cast<uint32_t>( i );
presentQueueFamilyIndex = graphicsQueueFamilyIndex;
@ -71,7 +71,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// family index that supports present
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
{
if ( physicalDevice->getSurfaceSupportKHR( vk::su::checked_cast<uint32_t>( i ), **surface ) )
if ( physicalDevice.getSurfaceSupportKHR( vk::su::checked_cast<uint32_t>( i ), *surface ) )
{
presentQueueFamilyIndex = vk::su::checked_cast<uint32_t>( i );
break;
@ -86,16 +86,16 @@ int main( int /*argc*/, char ** /*argv*/ )
}
// create a device
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::makeUniqueDevice( *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 );
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::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice->getSurfaceCapabilitiesKHR( **surface );
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( *surface );
VkExtent2D swapchainExtent;
if ( surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max() )
{
@ -129,7 +129,7 @@ int main( int /*argc*/, char ** /*argv*/ )
: vk::CompositeAlphaFlagBitsKHR::eOpaque;
vk::SwapchainCreateInfoKHR swapChainCreateInfo( vk::SwapchainCreateFlagsKHR(),
**surface,
*surface,
surfaceCapabilities.minImageCount,
format,
vk::ColorSpaceKHR::eSrgbNonlinear,
@ -155,11 +155,10 @@ int main( int /*argc*/, char ** /*argv*/ )
swapChainCreateInfo.pQueueFamilyIndices = queueFamilyIndices.data();
}
std::unique_ptr<vk::raii::SwapchainKHR> swapChain =
vk::raii::su::make_unique<vk::raii::SwapchainKHR>( *device, swapChainCreateInfo );
std::vector<VkImage> swapChainImages = swapChain->getImages();
vk::raii::SwapchainKHR swapChain( device, swapChainCreateInfo );
std::vector<VkImage> swapChainImages = swapChain.getImages();
std::vector<std::unique_ptr<vk::raii::ImageView>> imageViews;
std::vector<vk::raii::ImageView> imageViews;
imageViews.reserve( swapChainImages.size() );
vk::ComponentMapping componentMapping(
vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA );
@ -168,7 +167,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{
vk::ImageViewCreateInfo imageViewCreateInfo(
{}, static_cast<vk::Image>( image ), vk::ImageViewType::e2D, format, componentMapping, subResourceRange );
imageViews.push_back( vk::raii::su::make_unique<vk::raii::ImageView>( *device, imageViewCreateInfo ) );
imageViews.push_back( { device, imageViewCreateInfo } );
}
/* VULKAN_HPP_KEY_END */

View File

@ -26,26 +26,25 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
/* VULKAN_HPP_KEY_START */
const vk::Format depthFormat = vk::Format::eD16Unorm;
vk::FormatProperties formatProperties = physicalDevice->getFormatProperties( depthFormat );
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( depthFormat );
vk::ImageTiling tiling;
if ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eDepthStencilAttachment )
@ -69,10 +68,10 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::SampleCountFlagBits::e1,
tiling,
vk::ImageUsageFlagBits::eDepthStencilAttachment );
std::unique_ptr<vk::raii::Image> depthImage = vk::raii::su::make_unique<vk::raii::Image>( *device, imageCreateInfo );
vk::raii::Image depthImage( device, imageCreateInfo );
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice->getMemoryProperties();
vk::MemoryRequirements memoryRequirements = depthImage->getMemoryRequirements();
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties();
vk::MemoryRequirements memoryRequirements = depthImage.getMemoryRequirements();
uint32_t typeBits = memoryRequirements.memoryTypeBits;
uint32_t typeIndex = uint32_t( ~0 );
@ -90,17 +89,15 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( typeIndex != uint32_t( ~0 ) );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, typeIndex );
std::unique_ptr<vk::raii::DeviceMemory> depthMemory =
vk::raii::su::make_unique<vk::raii::DeviceMemory>( *device, memoryAllocateInfo );
depthImage->bindMemory( **depthMemory, 0 );
vk::raii::DeviceMemory depthMemory( device, memoryAllocateInfo );
depthImage.bindMemory( *depthMemory, 0 );
vk::ComponentMapping componentMapping(
vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA );
vk::ImageSubresourceRange subResourceRange( vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1 );
vk::ImageViewCreateInfo imageViewCreateInfo(
{}, **depthImage, vk::ImageViewType::e2D, depthFormat, componentMapping, subResourceRange );
std::unique_ptr<vk::raii::ImageView> depthView =
vk::raii::su::make_unique<vk::raii::ImageView>( *device, imageViewCreateInfo );
{}, *depthImage, vk::ImageViewType::e2D, depthFormat, componentMapping, subResourceRange );
vk::raii::ImageView depthView( device, imageViewCreateInfo );
/* VULKAN_HPP_KEY_END */
}

View File

@ -39,18 +39,17 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice->getQueueFamilyProperties() );
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::makeUniqueDevice( *physicalDevice, graphicsQueueFamilyIndex );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */
@ -67,23 +66,21 @@ int main( int /*argc*/, char ** /*argv*/ )
glm::mat4x4 mvpc = clip * projection * view * model;
vk::BufferCreateInfo bufferCreateInfo( {}, sizeof( mvpc ), vk::BufferUsageFlagBits::eUniformBuffer );
std::unique_ptr<vk::raii::Buffer> uniformDataBuffer =
vk::raii::su::make_unique<vk::raii::Buffer>( *device, bufferCreateInfo );
vk::MemoryRequirements memoryRequirements = uniformDataBuffer->getMemoryRequirements();
vk::raii::Buffer uniformDataBuffer( device, bufferCreateInfo );
vk::MemoryRequirements memoryRequirements = uniformDataBuffer.getMemoryRequirements();
uint32_t typeIndex =
vk::su::findMemoryType( physicalDevice->getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, typeIndex );
std::unique_ptr<vk::raii::DeviceMemory> uniformDataMemory =
vk::raii::su::make_unique<vk::raii::DeviceMemory>( *device, memoryAllocateInfo );
vk::raii::DeviceMemory uniformDataMemory( device, memoryAllocateInfo );
uint8_t * pData = static_cast<uint8_t *>( uniformDataMemory->mapMemory( 0, memoryRequirements.size ) );
uint8_t * pData = static_cast<uint8_t *>( uniformDataMemory.mapMemory( 0, memoryRequirements.size ) );
memcpy( pData, &mvpc, sizeof( mvpc ) );
uniformDataMemory->unmapMemory();
uniformDataMemory.unmapMemory();
uniformDataBuffer->bindMemory( **uniformDataMemory, 0 );
uniformDataBuffer.bindMemory( *uniformDataMemory, 0 );
/* VULKAN_HPP_KEY_END */
}

View File

@ -26,18 +26,17 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice->getQueueFamilyProperties() );
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::makeUniqueDevice( *physicalDevice, graphicsQueueFamilyIndex );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */
@ -45,13 +44,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding(
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, descriptorSetLayoutBinding );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout =
vk::raii::su::make_unique<vk::raii::DescriptorSetLayout>( *device, descriptorSetLayoutCreateInfo );
vk::raii::DescriptorSetLayout descriptorSetLayout( device, descriptorSetLayoutCreateInfo );
// create a PipelineLayout using that DescriptorSetLayout
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, **descriptorSetLayout );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::make_unique<vk::raii::PipelineLayout>( *device, pipelineLayoutCreateInfo );
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, pipelineLayoutCreateInfo );
/* VULKAN_HPP_KEY_END */
}

View File

@ -39,26 +39,25 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice->getQueueFamilyProperties() );
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::makeUniqueDevice( *physicalDevice, 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 );
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::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*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 */
@ -66,18 +65,17 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 );
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::make_unique<vk::raii::DescriptorPool>( *device, descriptorPoolCreateInfo );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// allocate a descriptor set
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( **descriptorPool, **descriptorSetLayout );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet = vk::raii::su::make_unique<vk::raii::DescriptorSet>(
std::move( vk::raii::DescriptorSets( *device, descriptorSetAllocateInfo ).front() ) );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
vk::DescriptorBufferInfo descriptorBufferInfo( **uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorBufferInfo descriptorBufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::WriteDescriptorSet writeDescriptorSet(
**descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo );
device->updateDescriptorSets( writeDescriptorSet, nullptr );
*descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr );
/* VULKAN_HPP_KEY_END */
}

View File

@ -38,24 +38,23 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
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::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::Format depthFormat = vk::Format::eD16Unorm;
/* VULKAN_HPP_KEY_START */
@ -85,8 +84,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::SubpassDescription subpass( {}, vk::PipelineBindPoint::eGraphics, {}, colorReference, {}, &depthReference );
vk::RenderPassCreateInfo renderPassCreateInfo( {}, attachmentDescriptions, subpass );
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::make_unique<vk::raii::RenderPass>( *device, renderPassCreateInfo );
vk::raii::RenderPass renderPass( device, renderPassCreateInfo );
/* VULKAN_HPP_KEY_END */
}

View File

@ -28,18 +28,17 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice->getQueueFamilyProperties() );
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::makeUniqueDevice( *physicalDevice, graphicsQueueFamilyIndex );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex );
/* VULKAN_HPP_KEY_START */
@ -50,16 +49,14 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( ok );
vk::ShaderModuleCreateInfo vertexShaderModuleCreateInfo( {}, vertexShaderSPV );
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::make_unique<vk::raii::ShaderModule>( *device, vertexShaderModuleCreateInfo );
vk::raii::ShaderModule vertexShaderModule( device, vertexShaderModuleCreateInfo );
std::vector<unsigned int> fragmentShaderSPV;
ok = vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C, fragmentShaderSPV );
assert( ok );
vk::ShaderModuleCreateInfo fragmentShaderModuleCreateInfo( {}, fragmentShaderSPV );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::make_unique<vk::raii::ShaderModule>( *device, fragmentShaderModuleCreateInfo );
vk::raii::ShaderModule fragmentShaderModule( device, fragmentShaderModuleCreateInfo );
glslang::FinalizeProcess();

View File

@ -26,25 +26,24 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 64, 64 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -52,25 +51,24 @@ int main( int /*argc*/, char ** /*argv*/ )
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 );
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, swapChainData.colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass =
vk::raii::su::makeRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
/* VULKAN_KEY_START */
std::array<vk::ImageView, 2> attachments;
attachments[1] = **depthBufferData.imageView;
attachments[1] = **depthBufferData.pImageView;
std::vector<std::unique_ptr<vk::raii::Framebuffer>> framebuffers;
std::vector<vk::raii::Framebuffer> framebuffers;
framebuffers.reserve( swapChainData.imageViews.size() );
for ( auto const & view : swapChainData.imageViews )
{
attachments[0] = *view;
vk::FramebufferCreateInfo framebufferCreateInfo(
{}, **renderPass, attachments, surfaceData.extent.width, surfaceData.extent.height, 1 );
framebuffers.push_back( vk::raii::su::make_unique<vk::raii::Framebuffer>( *device, framebufferCreateInfo ) );
{}, *renderPass, attachments, surfaceData.extent.width, surfaceData.extent.height, 1 );
framebuffers.push_back( vk::raii::Framebuffer( device, framebufferCreateInfo ) );
}
/* VULKAN_KEY_END */

View File

@ -37,33 +37,30 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 64, 64 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -71,46 +68,43 @@ int main( int /*argc*/, char ** /*argv*/ )
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 );
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, swapChainData.colorFormat, depthBufferData.format );
vk::raii::RenderPass renderPass =
vk::raii::su::makeRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
std::vector<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
/* VULKAN_KEY_START */
// create a vertex buffer for some vertex and color data
vk::BufferCreateInfo bufferCreateInfo( {}, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
std::unique_ptr<vk::raii::Buffer> vertexBuffer = vk::raii::su::make_unique<vk::raii::Buffer>( *device, bufferCreateInfo );
vk::raii::Buffer vertexBuffer( device, bufferCreateInfo );
// allocate device memory for that buffer
vk::MemoryRequirements memoryRequirements = vertexBuffer->getMemoryRequirements();
vk::MemoryRequirements memoryRequirements = vertexBuffer.getMemoryRequirements();
uint32_t memoryTypeIndex =
vk::su::findMemoryType( physicalDevice->getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
std::unique_ptr<vk::raii::DeviceMemory> deviceMemory =
vk::raii::su::make_unique<vk::raii::DeviceMemory>( *device, memoryAllocateInfo );
vk::raii::DeviceMemory deviceMemory( device, memoryAllocateInfo );
// copy the vertex and color data into that device memory
uint8_t * pData = static_cast<uint8_t *>( deviceMemory->mapMemory( 0, memoryRequirements.size ) );
uint8_t * pData = static_cast<uint8_t *>( deviceMemory.mapMemory( 0, memoryRequirements.size ) );
memcpy( pData, coloredCubeData, sizeof( coloredCubeData ) );
deviceMemory->unmapMemory();
deviceMemory.unmapMemory();
// and bind the device memory to the vertex buffer
vertexBuffer->bindMemory( **deviceMemory, 0 );
vertexBuffer.bindMemory( *deviceMemory, 0 );
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -118,17 +112,17 @@ 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->begin( {} );
commandBuffer.begin( {} );
vk::RenderPassBeginInfo renderPassBeginInfo(
**renderPass, **framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindVertexBuffers( 0, { **vertexBuffer }, { 0 } );
commandBuffer.bindVertexBuffers( 0, { *vertexBuffer }, { 0 } );
commandBuffer->endRenderPass();
commandBuffer->end();
vk::raii::su::submitAndWait( *device, *graphicsQueue, *commandBuffer );
commandBuffer.endRenderPass();
commandBuffer.end();
vk::raii::su::submitAndWait( device, graphicsQueue, commandBuffer );
/* VULKAN_KEY_END */
}

View File

@ -40,44 +40,41 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
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;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, vk::Format::eD16Unorm );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, vk::Format::eD16Unorm );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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 */
std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eVertex, **vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, **fragmentShaderModule, "main" )
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eVertex, *vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, *fragmentShaderModule, "main" )
};
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( coloredCubeData[0] ) );
@ -164,13 +161,12 @@ int main( int /*argc*/, char ** /*argv*/ )
&pipelineDepthStencilStateCreateInfo, // pDepthStencilState
&pipelineColorBlendStateCreateInfo, // pColorBlendState
&pipelineDynamicStateCreateInfo, // pDynamicState
**pipelineLayout, // layout
**renderPass // renderPass
*pipelineLayout, // layout
*renderPass // renderPass
);
std::shared_ptr<vk::raii::Pipeline> pipeline =
vk::raii::su::make_unique<vk::raii::Pipeline>( *device, nullptr, graphicsPipelineCreateInfo );
switch ( pipeline->getConstructorSuccessCode() )
vk::raii::Pipeline pipeline( device, nullptr, graphicsPipelineCreateInfo );
switch ( pipeline.getConstructorSuccessCode() )
{
case vk::Result::eSuccess: break;
case vk::Result::ePipelineCompileRequiredEXT:

View File

@ -41,35 +41,31 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -77,112 +73,107 @@ int main( int /*argc*/, char ** /*argv*/ )
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::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
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;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::makeUniqueDescriptorPool( *device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet =
vk::raii::su::makeUniqueDescriptorSet( *device, *descriptorPool, *descriptorSetLayout );
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 } }, {} );
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, {} );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline(
device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
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 );
pipelineLayout,
renderPass );
/* VULKAN_KEY_START */
// Get the index of the next available swapchain image:
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
commandBuffer->begin( {} );
commandBuffer.begin( {} );
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 );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
commandBuffer->bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, **pipelineLayout, 0, { **descriptorSet }, nullptr );
*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->bindVertexBuffers( 0, { **vertexBufferData.buffer }, { 0 } );
commandBuffer->setViewport( 0,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;
@ -195,7 +186,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_END */
device->waitIdle();
device.waitIdle();
}
catch ( vk::SystemError & err )
{

View File

@ -41,10 +41,10 @@ int main( int /*argc*/, char ** /*argv*/ )
desiredVersionString += std::to_string( desiredMinorVersion );
// initialize the vulkan context
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
vk::raii::Context context;
// Determine what API version is available
uint32_t apiVersion = context->enumerateInstanceVersion();
uint32_t apiVersion = context.enumerateInstanceVersion();
// Translate the version into major/minor for easier comparison
uint32_t loader_major_version = VK_VERSION_MAJOR( apiVersion );
@ -57,24 +57,23 @@ int main( int /*argc*/, char ** /*argv*/ )
( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
{
// Create the instance
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::make_unique<vk::raii::DebugUtilsMessengerEXT>( *instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// Get the list of physical devices
vk::raii::PhysicalDevices physicalDevices( *instance );
vk::raii::PhysicalDevices physicalDevices( instance );
// Go through the list of physical devices and select only those that are capable of running the API version we
// want.
std::vector<std::unique_ptr<vk::raii::PhysicalDevice>> desiredPhysicalDevices;
std::vector<vk::raii::PhysicalDevice> desiredPhysicalDevices;
for ( auto & pdh : physicalDevices )
{
if ( desiredVersion <= pdh.getProperties().apiVersion )
{
desiredPhysicalDevices.push_back( vk::raii::su::make_unique<vk::raii::PhysicalDevice>( std::move( pdh ) ) );
desiredPhysicalDevices.push_back( std::move( pdh ) );
}
}

View File

@ -26,18 +26,17 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 640, 640 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 640, 640 ) );
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice->getSurfaceCapabilitiesKHR( **surfaceData.surface );
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( **surfaceData.pSurface );
if ( !( surfaceCapabilities.supportedUsageFlags & vk::ImageUsageFlagBits::eTransferDst ) )
{
std::cout << "Surface cannot be destination of blit - abort \n";
@ -45,23 +44,20 @@ int main( int /*argc*/, char ** /*argv*/ )
}
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc |
@ -72,23 +68,22 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_START */
vk::FormatProperties formatProperties = physicalDevice->getFormatProperties( swapChainData.colorFormat );
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( swapChainData.colorFormat );
assert( ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc ) &&
"Format cannot be used as transfer source" );
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
// 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 );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
vk::raii::su::setImageLayout( *commandBuffer,
commandBuffer.begin( vk::CommandBufferBeginInfo() );
vk::raii::su::setImageLayout( commandBuffer,
static_cast<vk::Image>( swapChainData.images[imageIndex] ),
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
@ -104,38 +99,36 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::SampleCountFlagBits::e1,
vk::ImageTiling::eLinear,
vk::ImageUsageFlagBits::eTransferSrc );
std::unique_ptr<vk::raii::Image> blitSourceImage = vk::raii::su::make_unique<vk::raii::Image>( *device, imageCreateInfo );
vk::raii::Image blitSourceImage( device, imageCreateInfo );
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice->getMemoryProperties();
vk::MemoryRequirements memoryRequirements = blitSourceImage->getMemoryRequirements();
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties();
vk::MemoryRequirements memoryRequirements = blitSourceImage.getMemoryRequirements();
uint32_t memoryTypeIndex = vk::su::findMemoryType(
memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
std::unique_ptr<vk::raii::DeviceMemory> deviceMemory =
vk::raii::su::make_unique<vk::raii::DeviceMemory>( *device, memoryAllocateInfo );
blitSourceImage->bindMemory( **deviceMemory, 0 );
vk::raii::DeviceMemory deviceMemory( device, memoryAllocateInfo );
blitSourceImage.bindMemory( *deviceMemory, 0 );
vk::raii::su::setImageLayout( *commandBuffer,
**blitSourceImage,
vk::raii::su::setImageLayout( commandBuffer,
*blitSourceImage,
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eGeneral );
commandBuffer->end();
commandBuffer.end();
/* Queue the command buffer for execution */
std::unique_ptr<vk::raii::Fence> commandFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence commandFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **commandFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *commandFence );
/* Make sure command buffer is finished before mapping */
while ( device->waitForFences( { **commandFence }, true, vk::su::FenceTimeout ) == vk::Result::eTimeout )
while ( device.waitForFences( { *commandFence }, true, vk::su::FenceTimeout ) == vk::Result::eTimeout )
;
unsigned char * pImageMemory =
static_cast<unsigned char *>( deviceMemory->mapMemory( 0, memoryRequirements.size ) );
unsigned char * pImageMemory = static_cast<unsigned char *>( deviceMemory.mapMemory( 0, memoryRequirements.size ) );
// Checkerboard of 8x8 pixel squares
for ( uint32_t row = 0; row < surfaceData.extent.height; row++ )
@ -152,16 +145,16 @@ int main( int /*argc*/, char ** /*argv*/ )
}
// Flush the mapped memory and then unmap it. Assume it isn't coherent since we didn't really confirm
vk::MappedMemoryRange mappedMemoryRange( **deviceMemory, 0, memoryRequirements.size );
device->flushMappedMemoryRanges( mappedMemoryRange );
deviceMemory->unmapMemory();
vk::MappedMemoryRange mappedMemoryRange( *deviceMemory, 0, memoryRequirements.size );
device.flushMappedMemoryRanges( mappedMemoryRange );
deviceMemory.unmapMemory();
commandBuffer->reset( {} );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
commandBuffer.reset( {} );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
// Intend to blit from this image, set the layout accordingly
vk::raii::su::setImageLayout( *commandBuffer,
**blitSourceImage,
vk::raii::su::setImageLayout( commandBuffer,
*blitSourceImage,
swapChainData.colorFormat,
vk::ImageLayout::eGeneral,
vk::ImageLayout::eTransferSrcOptimal );
@ -175,7 +168,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ { 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,
commandBuffer.blitImage( *blitSourceImage,
vk::ImageLayout::eTransferSrcOptimal,
blitDestinationImage,
vk::ImageLayout::eTransferDstOptimal,
@ -191,7 +184,7 @@ int main( int /*argc*/, char ** /*argv*/ )
VK_QUEUE_FAMILY_IGNORED,
blitDestinationImage,
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
commandBuffer->pipelineBarrier(
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
@ -200,7 +193,7 @@ int main( int /*argc*/, char ** /*argv*/ )
imageSubresourceLayers,
vk::Offset3D( 256, 256, 0 ),
vk::Extent3D( 128, 128, 1 ) );
commandBuffer->copyImage( **blitSourceImage,
commandBuffer.copyImage( *blitSourceImage,
vk::ImageLayout::eTransferSrcOptimal,
blitDestinationImage,
vk::ImageLayout::eTransferDstOptimal,
@ -215,26 +208,26 @@ 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,
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eTransfer,
vk::PipelineStageFlagBits::eTopOfPipe,
{},
nullptr,
nullptr,
prePresentBarrier );
commandBuffer->end();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
submitInfo = vk::SubmitInfo( {}, {}, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
graphicsQueue->waitIdle();
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
submitInfo = vk::SubmitInfo( {}, {}, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
graphicsQueue.waitIdle();
/* Make sure command buffer is finished before presenting */
while ( device->waitForFences( { **drawFence }, true, vk::su::FenceTimeout ) == vk::Result::eTimeout )
while ( device.waitForFences( { *drawFence }, true, vk::su::FenceTimeout ) == vk::Result::eTimeout )
;
/* Now present the image in the window */
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;

View File

@ -92,15 +92,16 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
vk::raii::Context context;
/* VULKAN_KEY_START */
std::vector<vk::ExtensionProperties> props = context->enumerateInstanceExtensionProperties();
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"
@ -111,7 +112,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
const char * extensionName = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
vk::InstanceCreateInfo instanceCreateInfo( {}, &applicationInfo, {}, extensionName );
std::unique_ptr<vk::raii::Instance> instance = vk::raii::su::make_unique<vk::raii::Instance>( *context, instanceCreateInfo );
vk::raii::Instance instance( context, instanceCreateInfo );
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
vk::DebugUtilsMessageSeverityFlagBitsEXT::eError );
@ -120,8 +121,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfoEXT(
{}, severityFlags, messageTypeFlags, &debugMessageFunc );
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::make_unique<vk::raii::DebugUtilsMessengerEXT>( *instance, debugUtilsMessengerCreateInfoEXT );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, debugUtilsMessengerCreateInfoEXT );
/* VULKAN_KEY_END */
}

View File

@ -30,29 +30,28 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::raii::PhysicalDevices physicalDevices( *instance );
vk::raii::PhysicalDevices physicalDevices( instance );
assert( !physicalDevices.empty() );
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevices[0].getQueueFamilyProperties() );
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::makeUniqueDevice( physicalDevices[0], graphicsQueueFamilyIndex );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevices[0], graphicsQueueFamilyIndex );
// create an image
std::unique_ptr<vk::raii::Image> image = vk::raii::su::makeUniqueImage( *device );
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" );
device->setDebugUtilsObjectNameEXT( debugUtilsObjectNameInfo );
vk::ObjectType::eImage, NON_DISPATCHABLE_HANDLE_TO_UINT64_CAST( VkImage, *image ), "Image name" );
device.setDebugUtilsObjectNameEXT( debugUtilsObjectNameInfo );
/* VULKAN_KEY_END */
}

View File

@ -32,35 +32,31 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -68,121 +64,117 @@ int main( int /*argc*/, char ** /*argv*/ )
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 );
vk::raii::su::TextureData textureData( physicalDevice, device );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
textureData.setImage( *commandBuffer, vk::su::CheckerboardImageGenerator() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::raii::su::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device,
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(
device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool = vk::raii::su::makeUniqueDescriptorPool(
*device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet =
vk::raii::su::makeUniqueDescriptorSet( *device, *descriptorPool, *descriptorSetLayout );
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 } },
vk::raii::su::updateDescriptorSets( device,
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } },
{ textureData } );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
/* VULKAN_KEY_START */
// Get the index of the next available swapchain image:
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
// commandBuffer->begin() has already been called above!
// commandBuffer.begin() has already been called above!
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 );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
commandBuffer->bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, **pipelineLayout, 0, { **descriptorSet }, nullptr );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer->bindVertexBuffers( 0, { **vertexBufferData.buffer }, { 0 } );
commandBuffer->setViewport( 0,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;

View File

@ -36,35 +36,31 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -72,32 +68,30 @@ int main( int /*argc*/, char ** /*argv*/ )
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::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
/* VULKAN_KEY_START */
vk::PhysicalDeviceLimits limits = physicalDevice->getProperties().limits;
vk::PhysicalDeviceLimits limits = physicalDevice.getProperties().limits;
if ( limits.maxDescriptorSetUniformBuffersDynamic < 1 )
{
std::cout << "No dynamic uniform buffers supported\n";
@ -129,100 +123,94 @@ int main( int /*argc*/, char ** /*argv*/ )
}
vk::raii::su::BufferData uniformBufferData(
*physicalDevice, *device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcs, 2, bufferSize );
physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcs, 2, bufferSize );
// create a DescriptorSetLayout with vk::DescriptorType::eUniformBufferDynamic
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
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
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::makeUniqueDescriptorPool( *device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet =
vk::raii::su::makeUniqueDescriptorSet( *device, *descriptorPool, *descriptorSetLayout );
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 } },
{} );
device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, nullptr } }, {} );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( coloredCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
// Get the index of the next available swapchain image:
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
commandBuffer->begin( {} );
commandBuffer.begin( {} );
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 );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
*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,
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.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 );
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->draw( 12 * 3, 1, 0, 0 );
commandBuffer.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, dynamicOffset );
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;

View File

@ -109,10 +109,14 @@ 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();
} );
}
@ -120,9 +124,9 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
vk::raii::Context context;
std::vector<vk::LayerProperties> instanceLayerProperties = context->enumerateInstanceLayerProperties();
std::vector<vk::LayerProperties> instanceLayerProperties = context.enumerateInstanceLayerProperties();
/* VULKAN_KEY_START */
@ -141,10 +145,10 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
vk::InstanceCreateInfo instanceCreateInfo( {}, &applicationInfo, instanceLayerNames, instanceExtensionNames );
std::unique_ptr<vk::raii::Instance> instance = vk::raii::su::make_unique<vk::raii::Instance>( *context, instanceCreateInfo );
vk::raii::Instance instance( context, instanceCreateInfo );
pfnVkCreateDebugUtilsMessengerEXT =
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance->getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance.getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
if ( !pfnVkCreateDebugUtilsMessengerEXT )
{
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
@ -152,7 +156,7 @@ int main( int /*argc*/, char ** /*argv*/ )
}
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(
instance->getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
instance.getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
if ( !pfnVkDestroyDebugUtilsMessengerEXT )
{
std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl;
@ -166,24 +170,23 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::DebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfoEXT(
{}, severityFlags, messageTypeFlags, &debugMessageFunc );
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::make_unique<vk::raii::DebugUtilsMessengerEXT>( *instance, debugUtilsMessengerCreateInfoEXT );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, debugUtilsMessengerCreateInfoEXT );
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
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() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( {}, graphicsQueueFamilyIndex, 1, &queuePriority );
vk::DeviceCreateInfo deviceCreateInfo( {}, deviceQueueCreateInfo );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::make_unique<vk::raii::Device>( *physicalDevice, deviceCreateInfo );
vk::raii::Device device( physicalDevice, deviceCreateInfo );
// 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() );
( *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

@ -28,18 +28,17 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
/* VULKAN_HPP_KEY_START */
// enumerate the physicalDevices
vk::raii::PhysicalDevices physicalDevices( *instance );
vk::raii::PhysicalDevices physicalDevices( instance );
for ( auto const & pdh : physicalDevices )
{

View File

@ -27,46 +27,43 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
uint32_t graphicsQueueFamilyIndex =
vk::su::findGraphicsQueueFamilyIndex( physicalDevice->getQueueFamilyProperties() );
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::makeUniqueDevice( *physicalDevice, graphicsQueueFamilyIndex, vk::su::getDeviceExtensions() );
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
vk::raii::Device device =
vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsQueueFamilyIndex );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *device, *commandPool );
vk::raii::CommandPool commandPool =
vk::raii::CommandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsQueueFamilyIndex } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsQueueFamilyIndex, 0 );
vk::raii::Queue graphicsQueue( device, graphicsQueueFamilyIndex, 0 );
/* VULKAN_KEY_START */
// Start with a trivial command buffer and make sure fence wait doesn't time out
commandBuffer->begin( {} );
commandBuffer->setViewport( 0, vk::Viewport( 0.0f, 0.0f, 10.0f, 10.0f, 0.0f, 1.0f ) );
commandBuffer->end();
commandBuffer.begin( {} );
commandBuffer.setViewport( 0, vk::Viewport( 0.0f, 0.0f, 10.0f, 10.0f, 0.0f, 1.0f ) );
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> fence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence fence( device, vk::FenceCreateInfo() );
vk::SubmitInfo submitInfo( {}, {}, **commandBuffer );
graphicsQueue->submit( submitInfo, **fence );
vk::SubmitInfo submitInfo( {}, {}, *commandBuffer );
graphicsQueue.submit( submitInfo, *fence );
// Make sure timeout is long enough for a simple command buffer without waiting for an event
vk::Result result;
int timeouts = -1;
do
{
result = device->waitForFences( { **fence }, true, vk::su::FenceTimeout );
result = device.waitForFences( { *fence }, true, vk::su::FenceTimeout );
timeouts++;
} while ( result == vk::Result::eTimeout );
assert( result == vk::Result::eSuccess );
@ -77,25 +74,25 @@ int main( int /*argc*/, char ** /*argv*/ )
}
// Now create an event and wait for it on the GPU
std::unique_ptr<vk::raii::Event> event = vk::raii::su::make_unique<vk::raii::Event>( *device, vk::EventCreateInfo() );
vk::raii::Event event( device, vk::EventCreateInfo() );
commandBuffer->reset( vk::CommandBufferResetFlags() );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
commandBuffer->waitEvents( { **event },
commandBuffer.reset( vk::CommandBufferResetFlags() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
commandBuffer.waitEvents( { *event },
vk::PipelineStageFlagBits::eHost,
vk::PipelineStageFlagBits::eBottomOfPipe,
nullptr,
nullptr,
nullptr );
commandBuffer->end();
device->resetFences( { **fence } );
commandBuffer.end();
device.resetFences( { *fence } );
// Note that stepping through this code in the debugger is a bad idea because the GPU can TDR waiting for the event.
// Execute the code from vk::Queue::submit() through vk::Device::setEvent() without breakpoints
graphicsQueue->submit( submitInfo, **fence );
graphicsQueue.submit( submitInfo, *fence );
// We should timeout waiting for the fence because the GPU should be waiting on the event
result = device->waitForFences( { **fence }, true, vk::su::FenceTimeout );
result = device.waitForFences( { *fence }, true, vk::su::FenceTimeout );
if ( result != vk::Result::eTimeout )
{
std::cout << "Didn't get expected timeout in vk::Device::waitForFences, exiting\n";
@ -104,40 +101,40 @@ int main( int /*argc*/, char ** /*argv*/ )
// Set the event from the CPU and wait for the fence.
// This should succeed since we set the event
event->set();
event.set();
do
{
result = device->waitForFences( { **fence }, true, vk::su::FenceTimeout );
result = device.waitForFences( { *fence }, true, vk::su::FenceTimeout );
} while ( result == vk::Result::eTimeout );
assert( result == vk::Result::eSuccess );
commandBuffer->reset( {} );
device->resetFences( { **fence } );
event->reset();
commandBuffer.reset( {} );
device.resetFences( { *fence } );
event.reset();
// Now set the event from the GPU and wait on the CPU
commandBuffer->begin( vk::CommandBufferBeginInfo() );
commandBuffer->setEvent( **event, vk::PipelineStageFlagBits::eBottomOfPipe );
commandBuffer->end();
commandBuffer.begin( vk::CommandBufferBeginInfo() );
commandBuffer.setEvent( *event, vk::PipelineStageFlagBits::eBottomOfPipe );
commandBuffer.end();
// Look for the event on the CPU. It should be vk::Result::eEventReset since we haven't sent the command buffer yet.
result = event->getStatus();
result = event.getStatus();
assert( result == vk::Result::eEventReset );
// Send the command buffer and loop waiting for the event
graphicsQueue->submit( submitInfo, **fence );
graphicsQueue.submit( submitInfo, *fence );
int polls = 0;
do
{
result = event->getStatus();
result = event.getStatus();
polls++;
} while ( result != vk::Result::eEventSet );
printf( "%d polls to find the event set\n", polls );
do
{
result = device->waitForFences( { **fence }, true, vk::su::FenceTimeout );
result = device.waitForFences( { *fence }, true, vk::su::FenceTimeout );
} while ( result == vk::Result::eTimeout );
assert( result == vk::Result::eSuccess );

View File

@ -44,35 +44,31 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -80,54 +76,50 @@ int main( int /*argc*/, char ** /*argv*/ )
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::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */
vk::raii::su::TextureData textureData( *physicalDevice, *device );
vk::raii::su::TextureData textureData( physicalDevice, device );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
textureData.setImage( *commandBuffer, vk::su::CheckerboardImageGenerator() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
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 )
1, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, *textureData.sampler )
};
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, bindings );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout =
vk::raii::su::make_unique<vk::raii::DescriptorSetLayout>( *device, descriptorSetLayoutCreateInfo );
vk::raii::DescriptorSetLayout descriptorSetLayout( device, descriptorSetLayoutCreateInfo );
// Create pipeline layout
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, **descriptorSetLayout );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::make_unique<vk::raii::PipelineLayout>( *device, pipelineLayoutCreateInfo );
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, pipelineLayoutCreateInfo );
// Create a single pool to contain data for our descriptor set
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
@ -135,47 +127,44 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::make_unique<vk::raii::DescriptorPool>( *device, descriptorPoolCreateInfo );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( **descriptorPool, **descriptorSetLayout );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet = vk::raii::su::make_unique<vk::raii::DescriptorSet>(
std::move( vk::raii::DescriptorSets( *device, descriptorSetAllocateInfo ).front() ) );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
vk::DescriptorBufferInfo bufferInfo( **uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo(
**textureData.sampler, **textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, **textureData.pImageData->pImageView, 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 )
vk::WriteDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( *descriptorSet, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
};
device->updateDescriptorSets( writeDescriptorSets, nullptr );
device.updateDescriptorSets( writeDescriptorSets, nullptr );
/* VULKAN_KEY_END */
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -183,30 +172,30 @@ 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 );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
commandBuffer->bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, **pipelineLayout, 0, { **descriptorSet }, nullptr );
*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->bindVertexBuffers( 0, { **vertexBufferData.buffer }, { 0 } );
commandBuffer->setViewport( 0,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
vk::raii::su::submitAndWait( *device, *graphicsQueue, *commandBuffer );
vk::raii::su::submitAndWait( device, graphicsQueue, commandBuffer );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;
@ -217,7 +206,7 @@ int main( int /*argc*/, char ** /*argv*/ )
}
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
device->waitIdle();
device.waitIdle();
}
catch ( vk::SystemError & err )
{

View File

@ -41,36 +41,32 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 50, 50 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 50, 50 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
/* VULKAN_KEY_START */
vk::Format format = vk::Format::eR8G8B8A8Unorm;
vk::FormatProperties formatProperties = physicalDevice->getFormatProperties( format );
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( format );
// 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 );
@ -89,53 +85,52 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::SharingMode::eExclusive,
{},
needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized );
std::unique_ptr<vk::raii::Image> image = vk::raii::su::make_unique<vk::raii::Image>( *device, imageCreateInfo );
vk::raii::Image image( device, imageCreateInfo );
vk::MemoryRequirements memoryRequirements = image->getMemoryRequirements();
vk::MemoryRequirements memoryRequirements = image.getMemoryRequirements();
uint32_t memoryTypeIndex = vk::su::findMemoryType(
physicalDevice->getMemoryProperties(),
physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
needsStaging ? vk::MemoryPropertyFlags()
: ( vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ) );
// allocate memory
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
std::unique_ptr<vk::raii::DeviceMemory> imageMemory =
vk::raii::su::make_unique<vk::raii::DeviceMemory>( *device, memoryAllocateInfo );
vk::raii::DeviceMemory imageMemory( device, memoryAllocateInfo );
// bind memory
image->bindMemory( **imageMemory, 0 );
image.bindMemory( *imageMemory, 0 );
std::unique_ptr<vk::raii::Buffer> textureBuffer;
std::unique_ptr<vk::raii::DeviceMemory> textureBufferMemory;
std::unique_ptr<vk::raii::Buffer> pTextureBuffer;
std::unique_ptr<vk::raii::DeviceMemory> pTextureBufferMemory;
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 );
textureBuffer = vk::raii::su::make_unique<vk::raii::Buffer>( *device, bufferCreateInfo );
pTextureBuffer = vk::raii::su::make_unique<vk::raii::Buffer>( device, bufferCreateInfo );
memoryRequirements = textureBuffer->getMemoryRequirements();
memoryRequirements = pTextureBuffer->getMemoryRequirements();
memoryTypeIndex =
vk::su::findMemoryType( physicalDevice->getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
// allocate memory
memoryAllocateInfo = vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
textureBufferMemory = vk::raii::su::make_unique<vk::raii::DeviceMemory>( *device, memoryAllocateInfo );
pTextureBufferMemory = vk::raii::su::make_unique<vk::raii::DeviceMemory>( device, memoryAllocateInfo );
// bind memory
textureBuffer->bindMemory( **textureBufferMemory, 0 );
pTextureBuffer->bindMemory( **pTextureBufferMemory, 0 );
}
else
{
vk::SubresourceLayout subresourceLayout =
image->getSubresourceLayout( vk::ImageSubresource( vk::ImageAspectFlagBits::eColor ) );
image.getSubresourceLayout( vk::ImageSubresource( vk::ImageAspectFlagBits::eColor ) );
}
void * data = needsStaging ? textureBufferMemory->mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() )
: imageMemory->mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() );
void * data = needsStaging ? pTextureBufferMemory->mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() )
: imageMemory.mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() );
// Checkerboard of 16x16 pixel squares
unsigned char * pImageMemory = static_cast<unsigned char *>( data );
@ -152,37 +147,34 @@ int main( int /*argc*/, char ** /*argv*/ )
}
}
needsStaging ? textureBufferMemory->unmapMemory() : imageMemory->unmapMemory();
needsStaging ? pTextureBufferMemory->unmapMemory() : imageMemory.unmapMemory();
commandBuffer->begin( vk::CommandBufferBeginInfo() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
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 );
commandBuffer, *image, format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
vk::BufferImageCopy copyRegion( 0,
surfaceData.extent.width,
surfaceData.extent.height,
vk::ImageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 ),
vk::Offset3D( 0, 0, 0 ),
vk::Extent3D( surfaceData.extent, 1 ) );
commandBuffer->copyBufferToImage( **textureBuffer, **image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
commandBuffer.copyBufferToImage( **pTextureBuffer, *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 );
commandBuffer, *image, format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal );
}
commandBuffer->end();
vk::raii::su::submitAndWait( *device, *graphicsQueue, *commandBuffer );
commandBuffer.end();
vk::raii::su::submitAndWait( device, graphicsQueue, commandBuffer );
vk::SamplerCreateInfo samplerCreateInfo( {},
vk::Filter::eNearest,
@ -199,15 +191,14 @@ int main( int /*argc*/, char ** /*argv*/ )
0.0f,
0.0f,
vk::BorderColor::eFloatOpaqueWhite );
std::unique_ptr<vk::raii::Sampler> sampler = vk::raii::su::make_unique<vk::raii::Sampler>( *device, samplerCreateInfo );
vk::raii::Sampler sampler( device, samplerCreateInfo );
vk::ComponentMapping componentMapping(
vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA );
vk::ImageSubresourceRange imageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 );
vk::ImageViewCreateInfo imageViewCreateInfo(
{}, **image, vk::ImageViewType::e2D, format, componentMapping, imageSubresourceRange );
std::unique_ptr<vk::raii::ImageView> imageView =
vk::raii::su::make_unique<vk::raii::ImageView>( *device, imageViewCreateInfo );
{}, *image, vk::ImageViewType::e2D, format, componentMapping, imageSubresourceRange );
vk::raii::ImageView imageView( device, imageViewCreateInfo );
/* VULKAN_KEY_END */
}

View File

@ -70,42 +70,38 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::FormatProperties formatProperties = physicalDevice->getFormatProperties( vk::Format::eR8G8B8A8Unorm );
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( vk::Format::eR8G8B8A8Unorm );
if ( !( formatProperties.optimalTilingFeatures & vk::FormatFeatureFlagBits::eColorAttachment ) )
{
std::cout << "vk::Format::eR8G8B8A8Unorm format unsupported for input attachment\n";
exit( -1 );
}
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -131,20 +127,19 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ImageTiling::eOptimal,
vk::ImageUsageFlagBits::eInputAttachment |
vk::ImageUsageFlagBits::eTransferDst );
std::unique_ptr<vk::raii::Image> inputImage = vk::raii::su::make_unique<vk::raii::Image>( *device, imageCreateInfo );
vk::raii::Image inputImage( device, imageCreateInfo );
vk::MemoryRequirements memoryRequirements = inputImage->getMemoryRequirements();
vk::MemoryRequirements memoryRequirements = inputImage.getMemoryRequirements();
uint32_t memoryTypeIndex =
vk::su::findMemoryType( physicalDevice->getMemoryProperties(), memoryRequirements.memoryTypeBits, {} );
vk::su::findMemoryType( physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, {} );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
std::unique_ptr<vk::raii::DeviceMemory> inputMemory =
vk::raii::su::make_unique<vk::raii::DeviceMemory>( *device, memoryAllocateInfo );
inputImage->bindMemory( **inputMemory, 0 );
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,
commandBuffer.begin( vk::CommandBufferBeginInfo() );
vk::raii::su::setImageLayout( commandBuffer,
*inputImage,
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eTransferDstOptimal );
@ -152,12 +147,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ClearColorValue clearColorValue( std::array<float, 4>( { { 1.0f, 1.0f, 0.0f, 0.0f } } ) );
vk::ImageSubresourceRange imageSubresourceRange(
vk::ImageAspectFlagBits::eColor, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS );
commandBuffer->clearColorImage(
**inputImage, vk::ImageLayout::eTransferDstOptimal, clearColorValue, imageSubresourceRange );
commandBuffer.clearColorImage(
*inputImage, vk::ImageLayout::eTransferDstOptimal, clearColorValue, imageSubresourceRange );
// Set the image layout to SHADER_READONLY_OPTIMAL for use by the shaders
vk::raii::su::setImageLayout( *commandBuffer,
**inputImage,
vk::raii::su::setImageLayout( commandBuffer,
*inputImage,
swapChainData.colorFormat,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eShaderReadOnlyOptimal );
@ -166,19 +161,16 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA );
imageSubresourceRange = vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 );
vk::ImageViewCreateInfo imageViewCreateInfo(
{}, **inputImage, vk::ImageViewType::e2D, swapChainData.colorFormat, componentMapping, imageSubresourceRange );
std::unique_ptr<vk::raii::ImageView> inputAttachmentView =
vk::raii::su::make_unique<vk::raii::ImageView>( *device, imageViewCreateInfo );
{}, *inputImage, vk::ImageViewType::e2D, swapChainData.colorFormat, componentMapping, imageSubresourceRange );
vk::raii::ImageView inputAttachmentView( device, imageViewCreateInfo );
vk::DescriptorSetLayoutBinding layoutBinding(
0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment );
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, layoutBinding );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout =
vk::raii::su::make_unique<vk::raii::DescriptorSetLayout>( *device, descriptorSetLayoutCreateInfo );
vk::raii::DescriptorSetLayout descriptorSetLayout( device, descriptorSetLayoutCreateInfo );
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, **descriptorSetLayout );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::make_unique<vk::raii::PipelineLayout>( *device, pipelineLayoutCreateInfo );
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, pipelineLayoutCreateInfo );
std::array<vk::AttachmentDescription, 2> attachments = {
// First attachment is the color attachment - clear at the beginning of the renderpass and transition layout to
@ -209,87 +201,82 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::AttachmentReference inputReference( 1, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::SubpassDescription subPass( {}, vk::PipelineBindPoint::eGraphics, inputReference, colorReference );
vk::RenderPassCreateInfo renderPassCreateInfo( {}, attachments, subPass );
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::make_unique<vk::raii::RenderPass>( *device, renderPassCreateInfo );
vk::raii::RenderPass renderPass( device, renderPassCreateInfo );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*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 );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::make_unique<vk::raii::DescriptorPool>( *device, descriptorPoolCreateInfo );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( **descriptorPool, **descriptorSetLayout );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet = vk::raii::su::make_unique<vk::raii::DescriptorSet>(
std::move( vk::raii::DescriptorSets( *device, descriptorSetAllocateInfo ).front() ) );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
vk::DescriptorImageInfo inputImageInfo( nullptr, **inputAttachmentView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::DescriptorImageInfo inputImageInfo( nullptr, *inputAttachmentView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::WriteDescriptorSet writeDescriptorSet(
**descriptorSet, 0, 0, vk::DescriptorType::eInputAttachment, inputImageInfo );
device->updateDescriptorSets( writeDescriptorSet, nullptr );
*descriptorSet, 0, 0, vk::DescriptorType::eInputAttachment, inputImageInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline =
vk::raii::su::makeUniqueGraphicsPipeline( *device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
0,
{},
vk::FrontFace::eClockwise,
false,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->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 );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
commandBuffer->bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, **pipelineLayout, 0, { **descriptorSet }, nullptr );
*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->setViewport( 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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
/* VULKAN_KEY_END */
vk::raii::su::submitAndWait( *device, *graphicsQueue, *commandBuffer );
vk::raii::su::submitAndWait( device, graphicsQueue, commandBuffer );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;

View File

@ -25,19 +25,18 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
vk::raii::Context context;
/* VULKAN_KEY_START */
std::vector<vk::ExtensionProperties> extensionProperties = context->enumerateInstanceExtensionProperties();
std::vector<vk::ExtensionProperties> extensionProperties = context.enumerateInstanceExtensionProperties();
// 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; } );
std::cout << "Instance Extensions:" << std::endl;
for ( auto const & ep : extensionProperties )

View File

@ -36,8 +36,8 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::vector<vk::LayerProperties> layerProperties = context->enumerateInstanceLayerProperties();
vk::raii::Context context;
std::vector<vk::LayerProperties> layerProperties = context.enumerateInstanceLayerProperties();
/* VULKAN_KEY_START */
@ -47,7 +47,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( auto const & layerProperty : layerProperties )
{
std::vector<vk::ExtensionProperties> extensionProperties =
context->enumerateInstanceExtensionProperties( vk::Optional<const std::string>( layerProperty.layerName ) );
context.enumerateInstanceExtensionProperties( vk::Optional<const std::string>( layerProperty.layerName ) );
propertyData.emplace_back( layerProperty, extensionProperties );
}

View File

@ -25,11 +25,11 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
vk::raii::Context context;
/* VULKAN_KEY_START */
std::vector<vk::LayerProperties> layerProperties = context->enumerateInstanceLayerProperties();
std::vector<vk::LayerProperties> layerProperties = context.enumerateInstanceLayerProperties();
std::cout << "Instance Layers:" << std::endl;
if ( layerProperties.empty() )

View File

@ -30,11 +30,11 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
vk::raii::Context context;
/* VULKAN_KEY_START */
uint32_t apiVersion = context->enumerateInstanceVersion();
uint32_t apiVersion = context.enumerateInstanceVersion();
std::cout << "APIVersion = " << decodeAPIVersion( apiVersion ) << std::endl;
/* VULKAN_KEY_END */

View File

@ -94,35 +94,38 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( vk::Format::eR8G8B8A8Unorm );
if ( !( formatProperties.optimalTilingFeatures & vk::FormatFeatureFlagBits::eColorAttachment ) )
{
std::cout << "vk::Format::eR8G8B8A8Unorm format unsupported for input attachment\n";
exit( -1 );
}
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 );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -130,38 +133,36 @@ int main( int /*argc*/, char ** /*argv*/ )
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 );
vk::raii::su::TextureData textureData( physicalDevice, device );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
textureData.setImage( *commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
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 );
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::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */
@ -169,21 +170,18 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorSetLayoutBinding uniformBinding(
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, uniformBinding );
std::unique_ptr<vk::raii::DescriptorSetLayout> uniformLayout =
vk::raii::su::make_unique<vk::raii::DescriptorSetLayout>( *device, descriptorSetLayoutCreateInfo );
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 );
descriptorSetLayoutCreateInfo.pBindings = &sampler2DBinding;
std::unique_ptr<vk::raii::DescriptorSetLayout> samplerLayout =
vk::raii::su::make_unique<vk::raii::DescriptorSetLayout>( *device, descriptorSetLayoutCreateInfo );
vk::raii::DescriptorSetLayout samplerLayout( device, descriptorSetLayoutCreateInfo );
// Create pipeline layout with multiple descriptor sets
std::array<vk::DescriptorSetLayout, 2> descriptorSetLayouts = { **uniformLayout, **samplerLayout };
std::array<vk::DescriptorSetLayout, 2> descriptorSetLayouts = { *uniformLayout, *samplerLayout };
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, descriptorSetLayouts );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::make_unique<vk::raii::PipelineLayout>( *device, pipelineLayoutCreateInfo );
vk::raii::PipelineLayout pipelineLayout( device, pipelineLayoutCreateInfo );
// Create a single pool to contain data for our two descriptor sets
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
@ -191,49 +189,46 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, poolSizes );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::make_unique<vk::raii::DescriptorPool>( *device, descriptorPoolCreateInfo );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( **descriptorPool, descriptorSetLayouts );
vk::raii::DescriptorSets descriptorSets( *device, descriptorSetAllocateInfo );
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::DescriptorBufferInfo uniformBufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo textureImageInfo(
**textureData.sampler, **textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, **textureData.pImageData->pImageView, 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 ) }
};
device->updateDescriptorSets( writeDescriptorSets, nullptr );
device.updateDescriptorSets( writeDescriptorSets, nullptr );
/* VULKAN_KEY_END */
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
// Get the index of the next available swapchain image:
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -241,38 +236,38 @@ 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 );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
commandBuffer->bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, **pipelineLayout, 0, { *descriptorSets[0], *descriptorSets[1] }, nullptr );
*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 );
vk::Buffer buffer = **vertexBufferData.buffer;
commandBuffer->bindVertexBuffers( 0, buffer, { 0 } );
commandBuffer->setViewport( 0,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;
@ -283,7 +278,7 @@ int main( int /*argc*/, char ** /*argv*/ )
}
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
device->waitIdle();
device.waitIdle();
}
catch ( vk::SystemError & err )
{

View File

@ -32,35 +32,38 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( vk::Format::eR8G8B8A8Unorm );
if ( !( formatProperties.optimalTilingFeatures & vk::FormatFeatureFlagBits::eColorAttachment ) )
{
std::cout << "vk::Format::eR8G8B8A8Unorm format unsupported for input attachment\n";
exit( -1 );
}
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 );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -68,148 +71,140 @@ int main( int /*argc*/, char ** /*argv*/ )
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::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
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;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::makeUniqueDescriptorPool( *device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet =
vk::raii::su::makeUniqueDescriptorSet( *device, *descriptorPool, *descriptorSetLayout );
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 } }, {} );
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } }, {} );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( coloredCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
/* VULKAN_KEY_START */
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
// 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 );
swapChainData.pSwapChain->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 );
std::unique_ptr<vk::raii::Buffer> queryResultBuffer =
vk::raii::su::make_unique<vk::raii::Buffer>( *device, bufferCreateInfo );
vk::raii::Buffer queryResultBuffer( device, bufferCreateInfo );
vk::MemoryRequirements memoryRequirements = queryResultBuffer->getMemoryRequirements();
vk::MemoryRequirements memoryRequirements = queryResultBuffer.getMemoryRequirements();
uint32_t memoryTypeIndex =
vk::su::findMemoryType( physicalDevice->getMemoryProperties(),
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
std::unique_ptr<vk::raii::DeviceMemory> queryResultMemory =
vk::raii::su::make_unique<vk::raii::DeviceMemory>( *device, memoryAllocateInfo );
vk::raii::DeviceMemory queryResultMemory( device, memoryAllocateInfo );
queryResultBuffer->bindMemory( **queryResultMemory, 0 );
queryResultBuffer.bindMemory( *queryResultMemory, 0 );
vk::QueryPoolCreateInfo queryPoolCreateInfo( {}, vk::QueryType::eOcclusion, 2, {} );
std::unique_ptr<vk::raii::QueryPool> queryPool =
vk::raii::su::make_unique<vk::raii::QueryPool>( *device, queryPoolCreateInfo );
vk::raii::QueryPool queryPool( device, queryPoolCreateInfo );
commandBuffer->begin( {} );
commandBuffer->resetQueryPool( **queryPool, 0, 2 );
commandBuffer.begin( {} );
commandBuffer.resetQueryPool( *queryPool, 0, 2 );
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 );
commandBuffer->beginRenderPass(
commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo(
**renderPass, **framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
commandBuffer->bindDescriptorSets( vk::PipelineBindPoint::eGraphics, **pipelineLayout, 0, { **descriptorSet }, {} );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, {} );
commandBuffer->bindVertexBuffers( 0, { **vertexBufferData.buffer }, { 0 } );
commandBuffer->setViewport( 0,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->beginQuery( **queryPool, 0, vk::QueryControlFlags() );
commandBuffer->endQuery( **queryPool, 0 );
commandBuffer.beginQuery( *queryPool, 0, vk::QueryControlFlags() );
commandBuffer.endQuery( *queryPool, 0 );
commandBuffer->beginQuery( **queryPool, 1, vk::QueryControlFlags() );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->endQuery( **queryPool, 1 );
commandBuffer.beginQuery( *queryPool, 1, vk::QueryControlFlags() );
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.endQuery( *queryPool, 1 );
commandBuffer->copyQueryPoolResults( **queryPool,
commandBuffer.copyQueryPoolResults( *queryPool,
0,
2,
**queryResultBuffer,
*queryResultBuffer,
0,
sizeof( uint64_t ),
vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
commandBuffer->end();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
graphicsQueue->waitIdle();
graphicsQueue.waitIdle();
std::vector<uint64_t> poolResults;
std::tie( result, poolResults ) = queryPool->getResults<uint64_t>(
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 )
{
@ -226,19 +221,19 @@ int main( int /*argc*/, char ** /*argv*/ )
/* Read back query result from buffer */
uint64_t * samplesPassedPtr =
static_cast<uint64_t *>( queryResultMemory->mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() ) );
static_cast<uint64_t *>( queryResultMemory.mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() ) );
std::cout << "vkCmdCopyQueryPoolResults data\n";
std::cout << "samples_passed[0] = " << samplesPassedPtr[0] << "\n";
std::cout << "samples_passed[1] = " << samplesPassedPtr[1] << "\n";
queryResultMemory->unmapMemory();
queryResultMemory.unmapMemory();
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;

View File

@ -27,15 +27,14 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance = vk::raii::su::makeUniqueInstance( *context, AppName, EngineName );
vk::raii::Context context;
vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// enumerate the physicalDevices
vk::raii::PhysicalDevices physicalDevices( *instance );
vk::raii::PhysicalDevices physicalDevices( instance );
/* VULKAN_KEY_START */
@ -48,9 +47,8 @@ int main( int /*argc*/, char ** /*argv*/ )
// 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

@ -36,16 +36,15 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
vk::raii::Context context;
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// enumerate the physicalDevices
vk::raii::PhysicalDevices physicalDevices( *instance );
vk::raii::PhysicalDevices physicalDevices( instance );
/* VULKAN_KEY_START */

View File

@ -27,17 +27,16 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
vk::raii::Context context;
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
/* VULKAN_KEY_START */
std::vector<vk::PhysicalDeviceGroupProperties> groupProperties = instance->enumeratePhysicalDeviceGroups();
std::vector<vk::PhysicalDeviceGroupProperties> groupProperties = instance.enumeratePhysicalDeviceGroups();
std::cout << std::boolalpha;
for ( size_t i = 0; i < groupProperties.size(); i++ )
@ -49,9 +48,9 @@ int main( int /*argc*/, char ** /*argv*/ )
<< "physicalDevices:\n";
for ( size_t j = 0; j < groupProperties[i].physicalDeviceCount; j++ )
{
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::make_unique<vk::raii::PhysicalDevice>(
static_cast<VkPhysicalDevice>( groupProperties[i].physicalDevices[j] ), instance->getDispatcher() );
std::cout << "\t\t" << j << " : " << physicalDevice->getProperties().deviceName << "\n";
vk::raii::PhysicalDevice physicalDevice( static_cast<VkPhysicalDevice>( groupProperties[i].physicalDevices[j] ),
instance.getDispatcher() );
std::cout << "\t\t" << j << " : " << physicalDevice.getProperties().deviceName << "\n";
}
std::cout << "\t"
<< "subsetAllocation = " << !!groupProperties[i].subsetAllocation << "\n";
@ -59,17 +58,17 @@ int main( int /*argc*/, char ** /*argv*/ )
if ( 1 < groupProperties[i].physicalDeviceCount )
{
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::make_unique<vk::raii::PhysicalDevice>(
static_cast<VkPhysicalDevice>( groupProperties[i].physicalDevices[0] ), instance->getDispatcher() );
vk::raii::PhysicalDevice physicalDevice( static_cast<VkPhysicalDevice>( groupProperties[i].physicalDevices[0] ),
instance.getDispatcher() );
// get the QueueFamilyProperties of the first PhysicalDevice
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice->getQueueFamilyProperties();
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() );
@ -81,8 +80,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ {}, deviceQueueCreateInfo },
{ groupProperties[i].physicalDeviceCount, groupProperties[i].physicalDevices } );
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::make_unique<vk::raii::Device>( *physicalDevice, deviceCreateInfoChain.get<vk::DeviceCreateInfo>() );
vk::raii::Device device( physicalDevice, deviceCreateInfoChain.get<vk::DeviceCreateInfo>() );
}
}

View File

@ -101,16 +101,15 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
vk::raii::Context context;
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// enumerate the physicalDevices
vk::raii::PhysicalDevices physicalDevices( *instance );
vk::raii::PhysicalDevices physicalDevices( instance );
/* VULKAN_KEY_START */

View File

@ -29,16 +29,15 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
vk::raii::Context context;
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// enumerate the physicalDevices
vk::raii::PhysicalDevices physicalDevices( *instance );
vk::raii::PhysicalDevices physicalDevices( instance );
/* VULKAN_KEY_START */

View File

@ -72,37 +72,32 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::PhysicalDeviceProperties properties = physicalDevice.getProperties();
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::PhysicalDeviceProperties properties = physicalDevice->getProperties();
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -110,54 +105,51 @@ int main( int /*argc*/, char ** /*argv*/ )
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 );
vk::raii::su::TextureData textureData( physicalDevice, device );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
textureData.setImage( *commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
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 );
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::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device,
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(
device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool = vk::raii::su::makeUniqueDescriptorPool(
*device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet =
vk::raii::su::makeUniqueDescriptorSet( *device, *descriptorPool, *descriptorSetLayout );
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 } },
vk::raii::su::updateDescriptorSets( device,
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } },
{ textureData } );
/* VULKAN_KEY_START */
@ -294,8 +286,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// Feed the initial cache data into cache creation
vk::PipelineCacheCreateInfo pipelineCacheCreateInfo( {}, startCacheSize, startCacheData );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, pipelineCacheCreateInfo );
vk::raii::PipelineCache pipelineCache( device, pipelineCacheCreateInfo );
// Free our initialData now that pipeline cache has been created
free( startCacheData );
@ -303,30 +294,29 @@ int main( int /*argc*/, char ** /*argv*/ )
// Time (roughly) taken to create the graphics pipeline
timestamp_t start = getMilliseconds();
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
timestamp_t elapsed = getMilliseconds() - start;
std::cout << " vkCreateGraphicsPipeline time: " << (double)elapsed << " ms\n";
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
// 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 );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -334,38 +324,38 @@ 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(
commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo(
**renderPass, **framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
commandBuffer->bindDescriptorSets( vk::PipelineBindPoint::eGraphics, **pipelineLayout, 0, { **descriptorSet }, {} );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, {} );
commandBuffer->bindVertexBuffers( 0, { **vertexBufferData.buffer }, { 0 } );
commandBuffer->setViewport( 0,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;
@ -379,7 +369,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// Store away the cache that we've populated. This could conceivably happen
// earlier, depends on when the pipeline cache stops being populated
// internally.
std::vector<uint8_t> endCacheData = pipelineCache->getData();
std::vector<uint8_t> endCacheData = pipelineCache.getData();
// Write the file to disk, overwriting whatever was there
std::ofstream writeCacheStream( cacheFileName, std::ios_base::out | std::ios_base::binary );

View File

@ -40,35 +40,31 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -76,58 +72,54 @@ int main( int /*argc*/, char ** /*argv*/ )
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 );
vk::raii::su::TextureData textureData( physicalDevice, device );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
textureData.setImage( *commandBuffer, vk::su::CheckerboardImageGenerator() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::raii::su::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device,
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(
device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool = vk::raii::su::makeUniqueDescriptorPool(
*device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet =
vk::raii::su::makeUniqueDescriptorSet( *device, *descriptorPool, *descriptorSetLayout );
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 } },
vk::raii::su::updateDescriptorSets( device,
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } },
{ textureData } );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
/* VULKAN_KEY_START */
@ -137,8 +129,8 @@ 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::ShaderStageFlagBits::eVertex, **vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, **fragmentShaderModule, "main" )
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eVertex, *vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, *fragmentShaderModule, "main" )
};
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( texturedCubeData[0] ) );
@ -200,12 +192,11 @@ int main( int /*argc*/, char ** /*argv*/ )
&pipelineDepthStencilStateCreateInfo,
&pipelineColorBlendStateCreateInfo,
&pipelineDynamicStateCreateInfo,
**pipelineLayout,
**renderPass );
*pipelineLayout,
*renderPass );
std::unique_ptr<vk::raii::Pipeline> basePipeline =
vk::raii::su::make_unique<vk::raii::Pipeline>( *device, *pipelineCache, graphicsPipelineCreateInfo );
switch ( basePipeline->getConstructorSuccessCode() )
vk::raii::Pipeline basePipeline( device, pipelineCache, graphicsPipelineCreateInfo );
switch ( basePipeline.getConstructorSuccessCode() )
{
case vk::Result::eSuccess: break;
case vk::Result::ePipelineCompileRequiredEXT:
@ -231,21 +222,20 @@ void main()
// Convert GLSL to SPIR-V
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule2 =
vk::raii::su::makeUniqueShaderModule( *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" );
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, *fragmentShaderModule2, "main" );
graphicsPipelineCreateInfo.flags = vk::PipelineCreateFlagBits::eDerivative;
graphicsPipelineCreateInfo.basePipelineHandle = **basePipeline;
graphicsPipelineCreateInfo.basePipelineHandle = *basePipeline;
graphicsPipelineCreateInfo.basePipelineIndex = -1;
// And create the derived pipeline
std::unique_ptr<vk::raii::Pipeline> derivedPipeline =
vk::raii::su::make_unique<vk::raii::Pipeline>( *device, *pipelineCache, graphicsPipelineCreateInfo );
switch ( derivedPipeline->getConstructorSuccessCode() )
vk::raii::Pipeline derivedPipeline( device, pipelineCache, graphicsPipelineCreateInfo );
switch ( derivedPipeline.getConstructorSuccessCode() )
{
case vk::Result::eSuccess: break;
case vk::Result::ePipelineCompileRequiredEXT:
@ -256,14 +246,13 @@ void main()
/* VULKAN_KEY_END */
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
// 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 );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -271,38 +260,38 @@ void main()
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(
commandBuffer.beginRenderPass(
vk::RenderPassBeginInfo(
**renderPass, **framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D(), surfaceData.extent ), clearValues ),
vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, **derivedPipeline );
commandBuffer->bindDescriptorSets( vk::PipelineBindPoint::eGraphics, **pipelineLayout, 0, { **descriptorSet }, {} );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *derivedPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, {} );
commandBuffer->bindVertexBuffers( 0, { **vertexBufferData.buffer }, { 0 } );
commandBuffer->setViewport( 0,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;

View File

@ -82,35 +82,31 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -118,46 +114,43 @@ int main( int /*argc*/, char ** /*argv*/ )
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::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
// Create binding and layout for the following, matching contents of shader
// binding 0 = uniform buffer (MVP)
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*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 */
// Set up our push constant range, which mirrors the declaration of
vk::PushConstantRange pushConstantRanges( vk::ShaderStageFlagBits::eFragment, 0, 8 );
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, **descriptorSetLayout, pushConstantRanges );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::make_unique<vk::raii::PipelineLayout>( *device, pipelineLayoutCreateInfo );
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, *descriptorSetLayout, pushConstantRanges );
vk::raii::PipelineLayout pipelineLayout( device, pipelineLayoutCreateInfo );
// Create a single pool to contain data for our descriptor set
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
@ -165,53 +158,50 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::make_unique<vk::raii::DescriptorPool>( *device, descriptorPoolCreateInfo );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( **descriptorPool, **descriptorSetLayout );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet = vk::raii::su::make_unique<vk::raii::DescriptorSet>(
std::move( vk::raii::DescriptorSets( *device, descriptorSetAllocateInfo ).front() ) );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
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::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::WriteDescriptorSet writeDescriptorSet(
**descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo );
device->updateDescriptorSets( writeDescriptorSet, nullptr );
*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 ) &&
assert( ( sizeof( pushConstants ) <= physicalDevice.getProperties().limits.maxPushConstantsSize ) &&
"Too many push constants" );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
commandBuffer->pushConstants<unsigned>( **pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, pushConstants );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
commandBuffer.pushConstants<unsigned>( *pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, pushConstants );
/* VULKAN_KEY_END */
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -220,37 +210,37 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
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 );
*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->bindVertexBuffers( 0, { **vertexBufferData.buffer }, { 0 } );
commandBuffer->setViewport( 0,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;

View File

@ -1,4 +1,5 @@
// Copyright(c) 2019, NVIDIA CORPORATION. All rights reserved.
// Copyright(c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -32,12 +33,12 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
vk::raii::Context context;
/* VULKAN_KEY_START */
// To use PUSH_DESCRIPTOR, you must also specify GET_PHYSICAL_DEVICE_PROPERTIES_2
std::vector<vk::ExtensionProperties> extensionProperties = context->enumerateInstanceExtensionProperties();
std::vector<vk::ExtensionProperties> extensionProperties = context.enumerateInstanceExtensionProperties();
auto propertyIterator =
std::find_if( extensionProperties.begin(), extensionProperties.end(), []( vk::ExtensionProperties ep ) {
return ( strcmp( ep.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ) == 0 );
@ -51,16 +52,15 @@ 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 );
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *context, AppName, EngineName, {}, instanceExtensions );
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, instanceExtensions );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
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();
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 );
@ -74,26 +74,24 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<std::string> deviceExtensions = vk::su::getDeviceExtensions();
deviceExtensions.push_back( VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::makeUniqueDevice( *physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device =
vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -102,70 +100,67 @@ int main( int /*argc*/, char ** /*argv*/ )
graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::DepthBufferData depthBufferData(
*physicalDevice, *device, vk::Format::eD16Unorm, surfaceData.extent );
physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::raii::su::TextureData textureData( *physicalDevice, *device );
vk::raii::su::TextureData textureData( physicalDevice, device );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
textureData.setImage( *commandBuffer, vk::su::CheckerboardImageGenerator() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::raii::su::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
// Need to specify that descriptor set layout will be for push descriptors
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device,
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 );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass =
vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline(
device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
// Get the index of the next available swapchain image:
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -173,47 +168,47 @@ 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 );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
*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::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo(
**textureData.sampler, **textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, **textureData.pImageData->pImageView, 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,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;
@ -226,7 +221,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_END */
device->waitIdle();
device.waitIdle();
}
catch ( vk::SystemError & err )
{

View File

@ -81,10 +81,10 @@ static_assert( sizeof( GeometryInstanceData ) == 64, "GeometryInstanceData struc
struct AccelerationStructureData
{
std::shared_ptr<vk::raii::AccelerationStructureNV> acclerationStructure;
std::unique_ptr<vk::raii::su::BufferData> scratchBufferData;
std::unique_ptr<vk::raii::su::BufferData> resultBufferData;
std::unique_ptr<vk::raii::su::BufferData> instanceBufferData;
std::shared_ptr<vk::raii::AccelerationStructureNV> pAcclerationStructure;
std::unique_ptr<vk::raii::su::BufferData> pScratchBufferData;
std::unique_ptr<vk::raii::su::BufferData> pResultBufferData;
std::unique_ptr<vk::raii::su::BufferData> pInstanceBufferData;
};
AccelerationStructureData createAccelerationStructureData(
@ -103,15 +103,15 @@ AccelerationStructureData createAccelerationStructureData(
vk::AccelerationStructureInfoNV accelerationStructureInfo(
accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
vk::AccelerationStructureCreateInfoNV accelerationStructureCreateInfoNV( 0, accelerationStructureInfo );
accelerationStructureData.acclerationStructure =
accelerationStructureData.pAcclerationStructure =
std::make_shared<vk::raii::AccelerationStructureNV>( device, accelerationStructureCreateInfoNV );
vk::AccelerationStructureMemoryRequirementsInfoNV objectRequirements(
vk::AccelerationStructureMemoryRequirementsTypeNV::eObject, **accelerationStructureData.acclerationStructure );
vk::AccelerationStructureMemoryRequirementsTypeNV::eObject, **accelerationStructureData.pAcclerationStructure );
vk::DeviceSize resultSizeInBytes =
device.getAccelerationStructureMemoryRequirementsNV( objectRequirements ).memoryRequirements.size;
assert( 0 < resultSizeInBytes );
accelerationStructureData.resultBufferData =
accelerationStructureData.pResultBufferData =
vk::raii::su::make_unique<vk::raii::su::BufferData>( physicalDevice,
device,
resultSizeInBytes,
@ -120,16 +120,16 @@ AccelerationStructureData createAccelerationStructureData(
vk::AccelerationStructureMemoryRequirementsInfoNV buildScratchRequirements(
vk::AccelerationStructureMemoryRequirementsTypeNV::eBuildScratch,
**accelerationStructureData.acclerationStructure );
**accelerationStructureData.pAcclerationStructure );
vk::AccelerationStructureMemoryRequirementsInfoNV updateScratchRequirements(
vk::AccelerationStructureMemoryRequirementsTypeNV::eUpdateScratch,
**accelerationStructureData.acclerationStructure );
**accelerationStructureData.pAcclerationStructure );
vk::DeviceSize scratchSizeInBytes = std::max(
device.getAccelerationStructureMemoryRequirementsNV( buildScratchRequirements ).memoryRequirements.size,
device.getAccelerationStructureMemoryRequirementsNV( updateScratchRequirements ).memoryRequirements.size );
assert( 0 < scratchSizeInBytes );
accelerationStructureData.scratchBufferData =
accelerationStructureData.pScratchBufferData =
vk::raii::su::make_unique<vk::raii::su::BufferData>( physicalDevice,
device,
scratchSizeInBytes,
@ -138,7 +138,7 @@ AccelerationStructureData createAccelerationStructureData(
if ( !instances.empty() )
{
accelerationStructureData.instanceBufferData =
accelerationStructureData.pInstanceBufferData =
vk::raii::su::make_unique<vk::raii::su::BufferData>( physicalDevice,
device,
instances.size() * sizeof( GeometryInstanceData ),
@ -161,16 +161,16 @@ AccelerationStructureData createAccelerationStructureData(
static_cast<uint8_t>( vk::GeometryInstanceFlagBitsNV::eTriangleCullDisable ),
accelerationStructureHandle );
}
accelerationStructureData.instanceBufferData->upload( geometryInstanceData );
accelerationStructureData.pInstanceBufferData->upload( geometryInstanceData );
}
device.bindAccelerationStructureMemoryNV( vk::BindAccelerationStructureMemoryInfoNV(
**accelerationStructureData.acclerationStructure, **accelerationStructureData.resultBufferData->deviceMemory ) );
**accelerationStructureData.pAcclerationStructure, *accelerationStructureData.pResultBufferData->deviceMemory ) );
vk::Buffer instanceData;
if ( accelerationStructureData.instanceBufferData )
if ( accelerationStructureData.pInstanceBufferData )
{
instanceData = **accelerationStructureData.instanceBufferData->buffer;
instanceData = *accelerationStructureData.pInstanceBufferData->buffer;
}
vk::AccelerationStructureInfoNV accelerationStructureInfoNV(
accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
@ -178,9 +178,9 @@ AccelerationStructureData createAccelerationStructureData(
instanceData,
0,
false,
**accelerationStructureData.acclerationStructure,
**accelerationStructureData.pAcclerationStructure,
nullptr,
**accelerationStructureData.scratchBufferData->buffer,
*accelerationStructureData.pScratchBufferData->buffer,
0 );
vk::MemoryBarrier memoryBarrier(
@ -198,11 +198,19 @@ AccelerationStructureData createAccelerationStructureData(
struct PerFrameData
{
std::unique_ptr<vk::raii::CommandPool> commandPool;
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer;
std::unique_ptr<vk::raii::Fence> fence;
std::unique_ptr<vk::raii::Semaphore> presentCompleteSemaphore;
std::unique_ptr<vk::raii::Semaphore> renderCompleteSemaphore;
PerFrameData( vk::raii::Device const & device, uint32_t queueFamilyIndex )
: commandPool( device, { vk::CommandPoolCreateFlagBits::eResetCommandBuffer, queueFamilyIndex } )
, commandBuffer( vk::raii::su::makeCommandBuffer( device, commandPool ) )
, fence( device, vk::FenceCreateInfo( vk::FenceCreateFlagBits::eSignaled ) )
, presentCompleteSemaphore( device, vk::SemaphoreCreateInfo() )
, renderCompleteSemaphore( device, vk::SemaphoreCreateInfo() )
{}
vk::raii::CommandPool commandPool;
vk::raii::CommandBuffer commandBuffer;
vk::raii::Fence fence;
vk::raii::Semaphore presentCompleteSemaphore;
vk::raii::Semaphore renderCompleteSemaphore;
};
struct UniformBufferObject
@ -715,29 +723,28 @@ int main( int /*argc*/, char ** /*argv*/ )
}
instanceExtensions.push_back( VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME );
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *context, AppName, EngineName, {}, instanceExtensions );
vk::raii::Context context;
vk::raii::Instance instance =
vk::raii::su::makeInstance( context, AppName, EngineName, {}, instanceExtensions, VK_API_VERSION_1_2 );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
// Create Window Surface (using glfw)
VkSurfaceKHR glfwSurface;
VkResult err = glfwCreateWindowSurface( static_cast<VkInstance>( **instance ), window, nullptr, &glfwSurface );
VkResult err = glfwCreateWindowSurface( static_cast<VkInstance>( *instance ), window, nullptr, &glfwSurface );
check_vk_result( err );
std::unique_ptr<vk::raii::SurfaceKHR> surface = vk::raii::su::make_unique<vk::raii::SurfaceKHR>( *instance, glfwSurface );
vk::raii::SurfaceKHR surface( instance, glfwSurface );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surface );
// Create a Device with ray tracing support (besides some other extensions needed) and needed features
auto supportedFeatures =
physicalDevice->getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
std::unique_ptr<vk::raii::Device> device =
vk::raii::su::makeUniqueDevice( *physicalDevice,
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,
@ -746,24 +753,14 @@ int main( int /*argc*/, char ** /*argv*/ )
&supportedFeatures.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>() );
// setup stuff per frame
std::array<PerFrameData, IMGUI_VK_QUEUED_FRAMES> perFrameData;
std::vector<PerFrameData> perFrameData;
for ( int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++ )
{
perFrameData[i].commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
perFrameData[i].commandBuffer = vk::raii::su::makeUniqueCommandBuffer( *device, *perFrameData[i].commandPool );
perFrameData[i].fence =
vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo( vk::FenceCreateFlagBits::eSignaled ) );
perFrameData[i].presentCompleteSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
perFrameData[i].renderCompleteSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
perFrameData.push_back( PerFrameData( device, graphicsAndPresentQueueFamilyIndex.first ) );
}
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
// create a descriptor pool with a number of available descriptors
std::vector<vk::DescriptorPoolSize> poolSizes = {
@ -771,29 +768,27 @@ int main( int /*argc*/, char ** /*argv*/ )
{ vk::DescriptorType::eUniformBuffer, 1000 },
{ vk::DescriptorType::eStorageBuffer, 1000 },
};
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::makeUniqueDescriptorPool( *device, poolSizes );
vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( device, poolSizes );
// setup swap chain, render pass, depth buffer and the frame buffers
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
surface,
windowExtent,
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
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, surfaceFormat.format, depthFormat );
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, surfaceFormat.format, depthFormat );
vk::raii::su::DepthBufferData depthBufferData( *physicalDevice, *device, depthFormat, windowExtent );
std::vector<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, windowExtent );
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, depthFormat, windowExtent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, windowExtent );
bool samplerAnisotropy = !!supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features.samplerAnisotropy;
@ -803,21 +798,24 @@ int main( int /*argc*/, char ** /*argv*/ )
textures.reserve( textureCount );
for ( size_t i = 0; i < textureCount; i++ )
{
textures.emplace_back( *physicalDevice,
*device,
textures.emplace_back( physicalDevice,
device,
vk::Extent2D( random<uint32_t>( 2, 8 ) * 16, random<uint32_t>( 2, 8 ) * 16 ),
vk::ImageUsageFlagBits::eTransferDst | vk::ImageUsageFlagBits::eSampled,
vk::FormatFeatureFlags(),
samplerAnisotropy,
true );
}
vk::raii::su::oneTimeSubmit(
*device, *perFrameData[0].commandPool, *graphicsQueue, [&]( vk::raii::CommandBuffer const & commandBuffer ) {
vk::raii::su::oneTimeSubmit( device,
perFrameData[0].commandPool,
graphicsQueue,
[&]( vk::raii::CommandBuffer const & commandBuffer )
{
for ( auto & t : textures )
{
t.setImage(
commandBuffer,
vk::su::CheckerboardImageGenerator( { random<uint8_t>(), random<uint8_t>(), random<uint8_t>() },
t.setImage( commandBuffer,
vk::su::CheckerboardImageGenerator(
{ random<uint8_t>(), random<uint8_t>(), random<uint8_t>() },
{ random<uint8_t>(), random<uint8_t>(), random<uint8_t>() } ) );
}
} );
@ -832,7 +830,7 @@ int main( int /*argc*/, char ** /*argv*/ )
materials[i].textureID = vk::su::checked_cast<uint32_t>( i );
}
vk::raii::su::BufferData materialBufferData(
*physicalDevice, *device, materialCount * MaterialStride, vk::BufferUsageFlagBits::eStorageBuffer );
physicalDevice, device, materialCount * MaterialStride, vk::BufferUsageFlagBits::eStorageBuffer );
materialBufferData.upload( materials, MaterialStride );
// create a a 3D-array of cubes, randomly jittered, using a random material
@ -865,23 +863,23 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::BufferUsageFlags bufferUsageFlags = vk::BufferUsageFlagBits::eTransferDst |
vk::BufferUsageFlagBits::eVertexBuffer |
vk::BufferUsageFlagBits::eStorageBuffer;
vk::raii::su::BufferData vertexBufferData( *physicalDevice,
*device,
vk::raii::su::BufferData vertexBufferData( physicalDevice,
device,
vertices.size() * VertexStride,
bufferUsageFlags,
vk::MemoryPropertyFlagBits::eDeviceLocal );
vertexBufferData.upload(
*physicalDevice, *device, *perFrameData[0].commandPool, *graphicsQueue, vertices, VertexStride );
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,
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 ) );
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,
@ -890,8 +888,8 @@ int main( int /*argc*/, char ** /*argv*/ )
0.0f, 0.0f, 0.0f, 1.0f ) );
// clang-format on
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device,
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(
device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eStorageBuffer,
1,
@ -899,24 +897,22 @@ int main( int /*argc*/, char ** /*argv*/ )
{ vk::DescriptorType::eCombinedImageSampler,
static_cast<uint32_t>( textures.size() ),
vk::ShaderStageFlagBits::eFragment } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline(
device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
VertexStride,
{ { vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, pos ) ) },
@ -925,18 +921,18 @@ int main( int /*argc*/, char ** /*argv*/ )
{ vk::Format::eR32Sint, vk::su::checked_cast<uint32_t>( offsetof( Vertex, matID ) ) } },
vk::FrontFace::eCounterClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
vk::raii::su::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( UniformBufferObject ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( UniformBufferObject ), vk::BufferUsageFlagBits::eUniformBuffer );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet =
vk::raii::su::makeUniqueDescriptorSet( *device, *descriptorPool, *descriptorSetLayout );
vk::raii::su::updateDescriptorSets( *device,
*descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, *uniformBufferData.buffer, {} },
{ vk::DescriptorType::eStorageBuffer, *materialBufferData.buffer, {} } },
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets( device,
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} },
{ vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, {} } },
textures );
// RayTracing specific stuff
@ -944,40 +940,47 @@ int main( int /*argc*/, char ** /*argv*/ )
// create acceleration structures: one top-level, and just one bottom-level
AccelerationStructureData topLevelAS, bottomLevelAS;
vk::raii::su::oneTimeSubmit(
*device, *perFrameData[0].commandPool, *graphicsQueue, [&]( vk::raii::CommandBuffer const & commandBuffer ) {
vk::GeometryDataNV geometryDataNV( vk::GeometryTrianglesNV( **vertexBufferData.buffer,
device,
perFrameData[0].commandPool,
graphicsQueue,
[&]( vk::raii::CommandBuffer const & commandBuffer )
{
vk::GeometryDataNV geometryDataNV( vk::GeometryTrianglesNV( *vertexBufferData.buffer,
0,
vk::su::checked_cast<uint32_t>( vertices.size() ),
VertexStride,
vk::Format::eR32G32B32Sfloat,
**indexBufferData.buffer,
*indexBufferData.buffer,
0,
vk::su::checked_cast<uint32_t>( indices.size() ),
vk::IndexType::eUint32 ),
{} );
bottomLevelAS =
createAccelerationStructureData( *physicalDevice,
*device,
createAccelerationStructureData( physicalDevice,
device,
commandBuffer,
{},
{ vk::GeometryNV( vk::GeometryTypeNV::eTriangles, geometryDataNV ) } );
topLevelAS =
createAccelerationStructureData( *physicalDevice,
*device,
createAccelerationStructureData( physicalDevice,
device,
commandBuffer,
{ std::make_pair( bottomLevelAS.acclerationStructure, transform ) },
{ std::make_pair( bottomLevelAS.pAcclerationStructure, transform ) },
std::vector<vk::GeometryNV>() );
} );
// create raytracing descriptor set
vk::raii::su::oneTimeSubmit(
*device, *perFrameData[0].commandPool, *graphicsQueue, [&]( vk::raii::CommandBuffer const & commandBuffer ) {
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,
*vertexBufferData.buffer,
0,
VK_WHOLE_SIZE );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eAllCommands,
@ -987,7 +990,7 @@ int main( int /*argc*/, char ** /*argv*/ )
bufferMemoryBarrier,
nullptr );
bufferMemoryBarrier.buffer = **indexBufferData.buffer;
bufferMemoryBarrier.buffer = *indexBufferData.buffer;
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eAllCommands,
vk::PipelineStageFlagBits::eAllCommands,
{},
@ -1027,54 +1030,52 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
vk::su::checked_cast<uint32_t>( swapChainData.images.size() ),
descriptorPoolSizes );
std::unique_ptr<vk::raii::DescriptorPool> rayTracingDescriptorPool =
vk::raii::su::make_unique<vk::raii::DescriptorPool>( *device, descriptorPoolCreateInfo );
vk::raii::DescriptorPool rayTracingDescriptorPool( device, descriptorPoolCreateInfo );
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, bindings );
std::unique_ptr<vk::raii::DescriptorSetLayout> rayTracingDescriptorSetLayout =
vk::raii::su::make_unique<vk::raii::DescriptorSetLayout>( *device, descriptorSetLayoutCreateInfo );
vk::raii::DescriptorSetLayout rayTracingDescriptorSetLayout( device, descriptorSetLayoutCreateInfo );
std::vector<vk::DescriptorSetLayout> layouts;
for ( size_t i = 0; i < swapChainData.images.size(); i++ )
{
layouts.push_back( **rayTracingDescriptorSetLayout );
layouts.push_back( *rayTracingDescriptorSetLayout );
}
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( **rayTracingDescriptorPool, layouts );
vk::raii::DescriptorSets rayTracingDescriptorSets( *device, descriptorSetAllocateInfo );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *rayTracingDescriptorPool, layouts );
vk::raii::DescriptorSets rayTracingDescriptorSets( device, descriptorSetAllocateInfo );
// Bind ray tracing specific descriptor sets into pNext of a vk::WriteDescriptorSet
vk::WriteDescriptorSetAccelerationStructureNV writeDescriptorSetAcceleration( 1,
&**topLevelAS.acclerationStructure );
&**topLevelAS.pAcclerationStructure );
std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets;
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
{
accelerationDescriptionSets.emplace_back( *rayTracingDescriptorSets[i], 0, 0, 1, bindings[0].descriptorType );
accelerationDescriptionSets.back().pNext = &writeDescriptorSetAcceleration;
}
device->updateDescriptorSets( accelerationDescriptionSets, nullptr );
device.updateDescriptorSets( accelerationDescriptionSets, nullptr );
// Bind all the other buffers and images, starting with dstBinding == 2 (dstBinding == 1 is used by the backBuffer
// view)
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
{
vk::raii::su::updateDescriptorSets( *device,
vk::raii::su::updateDescriptorSets( device,
rayTracingDescriptorSets[i],
{ { bindings[2].descriptorType, *uniformBufferData.buffer, {} },
{ bindings[3].descriptorType, *vertexBufferData.buffer, {} },
{ bindings[4].descriptorType, *indexBufferData.buffer, {} },
{ bindings[5].descriptorType, *materialBufferData.buffer, {} } },
{ { bindings[2].descriptorType, uniformBufferData.buffer, {} },
{ bindings[3].descriptorType, vertexBufferData.buffer, {} },
{ bindings[4].descriptorType, indexBufferData.buffer, {} },
{ bindings[5].descriptorType, materialBufferData.buffer, {} } },
textures,
2 );
}
// create the ray-tracing shader modules
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> raygenShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eRaygenNV, raygenShaderText );
std::unique_ptr<vk::raii::ShaderModule> missShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eMissNV, missShaderText );
std::unique_ptr<vk::raii::ShaderModule> shadowMissShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eMissNV, shadowMissShaderText );
std::unique_ptr<vk::raii::ShaderModule> closestHitShaderModule =
vk::raii::su::makeUniqueShaderModule( *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
@ -1083,20 +1084,20 @@ int main( int /*argc*/, char ** /*argv*/ )
// We use only one ray generation, that will implement the camera model
shaderStages.emplace_back(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eRaygenNV, **raygenShaderModule, "main" );
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eRaygenNV, *raygenShaderModule, "main" );
shaderGroups.emplace_back(
vk::RayTracingShaderGroupTypeNV::eGeneral, 0, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV );
// 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" );
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" );
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 );
@ -1104,7 +1105,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// 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" );
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eClosestHitNV, *closestHitShaderModule, "main" );
shaderGroups.emplace_back( vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup,
VK_SHADER_UNUSED_NV,
3,
@ -1120,8 +1121,7 @@ int main( int /*argc*/, char ** /*argv*/ )
VK_SHADER_UNUSED_NV );
// Create the layout of the pipeline following the provided descriptor set layout
std::unique_ptr<vk::raii::PipelineLayout> rayTracingPipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *rayTracingDescriptorSetLayout );
vk::raii::PipelineLayout rayTracingPipelineLayout( device, { {}, *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
@ -1130,10 +1130,9 @@ int main( int /*argc*/, char ** /*argv*/ )
// in the ray generation to avoid deep recursion.
uint32_t maxRecursionDepth = 2;
vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo(
{}, shaderStages, shaderGroups, maxRecursionDepth, **rayTracingPipelineLayout );
std::unique_ptr<vk::raii::Pipeline> rayTracingPipeline =
vk::raii::su::make_unique<vk::raii::Pipeline>( *device, nullptr, rayTracingPipelineCreateInfo );
switch ( rayTracingPipeline->getConstructorSuccessCode() )
{}, shaderStages, shaderGroups, maxRecursionDepth, *rayTracingPipelineLayout );
vk::raii::Pipeline rayTracingPipeline( device, nullptr, rayTracingPipelineCreateInfo );
switch ( rayTracingPipeline.getConstructorSuccessCode() )
{
case vk::Result::eSuccess: break;
case vk::Result::ePipelineCompileRequiredEXT:
@ -1143,7 +1142,7 @@ int main( int /*argc*/, char ** /*argv*/ )
}
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV> propertiesChain =
physicalDevice->getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV>();
physicalDevice.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV>();
uint32_t shaderGroupBaseAlignment =
propertiesChain.get<vk::PhysicalDeviceRayTracingPropertiesNV>().shaderGroupBaseAlignment;
uint32_t shaderGroupHandleSize =
@ -1163,18 +1162,18 @@ int main( int /*argc*/, char ** /*argv*/ )
uint32_t shaderBindingTableSize = hitShaderBindingOffset + hitShaderTableSize;
std::vector<uint8_t> shaderHandleStorage( shaderBindingTableSize );
memcpy( &shaderHandleStorage[raygenShaderBindingOffset],
rayTracingPipeline->getRayTracingShaderGroupHandlesKHR<uint8_t>( 0, 1, raygenShaderTableSize ).data(),
rayTracingPipeline.getRayTracingShaderGroupHandlesKHR<uint8_t>( 0, 1, raygenShaderTableSize ).data(),
raygenShaderTableSize );
memcpy( &shaderHandleStorage[missShaderBindingOffset],
rayTracingPipeline->getRayTracingShaderGroupHandlesKHR<uint8_t>( 1, 2, missShaderTableSize ).data(),
rayTracingPipeline.getRayTracingShaderGroupHandlesKHR<uint8_t>( 1, 2, missShaderTableSize ).data(),
missShaderTableSize );
memcpy( &shaderHandleStorage[hitShaderBindingOffset],
rayTracingPipeline->getRayTracingShaderGroupHandlesKHR<uint8_t>( 3, 2, hitShaderTableSize ).data(),
rayTracingPipeline.getRayTracingShaderGroupHandlesKHR<uint8_t>( 3, 2, hitShaderTableSize ).data(),
hitShaderTableSize );
assert( shaderHandleStorage.size() == shaderBindingTableSize );
vk::raii::su::BufferData shaderBindingTableBufferData( *physicalDevice,
*device,
vk::raii::su::BufferData shaderBindingTableBufferData( physicalDevice,
device,
shaderBindingTableSize,
vk::BufferUsageFlagBits::eTransferDst,
vk::MemoryPropertyFlagBits::eHostVisible );
@ -1197,7 +1196,7 @@ int main( int /*argc*/, char ** /*argv*/ )
double startTime = glfwGetTime();
glfwPollEvents();
vk::raii::CommandBuffer const & commandBuffer = *perFrameData[frameIndex].commandBuffer;
vk::raii::CommandBuffer const & commandBuffer = perFrameData[frameIndex].commandBuffer;
int w, h;
glfwGetWindowSize( window, &w, &h );
@ -1205,30 +1204,32 @@ int main( int /*argc*/, char ** /*argv*/ )
{
windowExtent.width = w;
windowExtent.height = h;
device->waitIdle();
device.waitIdle();
swapChainData =
vk::raii::su::SwapChainData( *physicalDevice,
*device,
*surface,
vk::raii::su::SwapChainData( physicalDevice,
device,
surface,
windowExtent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage,
swapChainData.swapChain,
&*swapChainData.pSwapChain,
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
depthBufferData = vk::raii::su::DepthBufferData(
*physicalDevice, *device, vk::su::pickDepthFormat( **physicalDevice ), windowExtent );
physicalDevice, device, vk::su::pickDepthFormat( *physicalDevice ), windowExtent );
vk::raii::su::oneTimeSubmit(
commandBuffer, *graphicsQueue, [&]( vk::raii::CommandBuffer const & commandBuffer ) {
vk::raii::su::oneTimeSubmit( commandBuffer,
graphicsQueue,
[&]( vk::raii::CommandBuffer const & commandBuffer )
{
vk::raii::su::setImageLayout( commandBuffer,
**depthBufferData.image,
*depthBufferData.image,
depthFormat,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eDepthStencilAttachmentOptimal );
} );
framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, windowExtent );
framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, windowExtent );
}
// update the uniformBufferObject
@ -1244,28 +1245,26 @@ 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.pSwapChain->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 ) )
device.waitForFences( { *perFrameData[frameIndex].fence }, VK_TRUE, vk::su::FenceTimeout ) )
;
device->resetFences( { **perFrameData[frameIndex].fence } );
device.resetFences( { *perFrameData[frameIndex].fence } );
commandBuffer.begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlagBits::eOneTimeSubmit ) );
if ( appInfo.useRasterRender )
{
vk::RenderPassBeginInfo renderPassBeginInfo( **renderPass,
**framebuffers[backBufferIndex],
vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ),
clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo(
*renderPass, *framebuffers[backBufferIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, **pipelineLayout, 0, { **descriptorSet }, nullptr );
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.setViewport( 0,
vk::Viewport( 0.0f,
@ -1276,8 +1275,8 @@ int main( int /*argc*/, char ** /*argv*/ )
1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ) );
commandBuffer.bindVertexBuffers( 0, { **vertexBufferData.buffer }, { 0 } );
commandBuffer.bindIndexBuffer( **indexBufferData.buffer, 0, vk::IndexType::eUint32 );
commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.bindIndexBuffer( *indexBufferData.buffer, 0, vk::IndexType::eUint32 );
commandBuffer.drawIndexed( vk::su::checked_cast<uint32_t>( indices.size() ), 1, 0, 0, 0 );
commandBuffer.endRenderPass();
@ -1288,7 +1287,7 @@ int main( int /*argc*/, char ** /*argv*/ )
nullptr, *swapChainData.imageViews[backBufferIndex], vk::ImageLayout::eGeneral );
vk::WriteDescriptorSet writeDescriptorSet(
*rayTracingDescriptorSets[backBufferIndex], 1, 0, bindings[1].descriptorType, imageInfo );
device->updateDescriptorSets( writeDescriptorSet, nullptr );
device.updateDescriptorSets( writeDescriptorSet, nullptr );
vk::raii::su::setImageLayout( commandBuffer,
static_cast<vk::Image>( swapChainData.images[backBufferIndex] ),
@ -1296,20 +1295,20 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ImageLayout::eUndefined,
vk::ImageLayout::eGeneral );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eRayTracingNV, **rayTracingPipeline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eRayTracingNV, *rayTracingPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eRayTracingNV,
**rayTracingPipelineLayout,
*rayTracingPipelineLayout,
0,
{ *rayTracingDescriptorSets[backBufferIndex] },
nullptr );
commandBuffer.traceRaysNV( **shaderBindingTableBufferData.buffer,
commandBuffer.traceRaysNV( *shaderBindingTableBufferData.buffer,
raygenShaderBindingOffset,
**shaderBindingTableBufferData.buffer,
*shaderBindingTableBufferData.buffer,
missShaderBindingOffset,
missShaderBindingStride,
**shaderBindingTableBufferData.buffer,
*shaderBindingTableBufferData.buffer,
hitShaderBindingOffset,
hitShaderBindingStride,
nullptr,
@ -1329,14 +1328,17 @@ int main( int /*argc*/, char ** /*argv*/ )
// frame end
commandBuffer.end();
const vk::PipelineStageFlags waitDestinationStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
vk::SubmitInfo submitInfo( **perFrameData[frameIndex].presentCompleteSemaphore,
waitDestinationStageMask,
*commandBuffer,
**perFrameData[frameIndex].renderCompleteSemaphore );
graphicsQueue->submit( submitInfo, **perFrameData[frameIndex].fence );
vk::SubmitInfo submitInfo( 1,
&*perFrameData[frameIndex].presentCompleteSemaphore,
&waitDestinationStageMask,
1,
&*commandBuffer,
1,
&*perFrameData[frameIndex].renderCompleteSemaphore );
graphicsQueue.submit( submitInfo, *perFrameData[frameIndex].fence );
vk::PresentInfoKHR presentInfoKHR(
**perFrameData[frameIndex].renderCompleteSemaphore, **swapChainData.swapChain, backBufferIndex );
result = presentQueue->presentKHR( presentInfoKHR );
*perFrameData[frameIndex].renderCompleteSemaphore, **swapChainData.pSwapChain, backBufferIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;
@ -1366,7 +1368,7 @@ int main( int /*argc*/, char ** /*argv*/ )
}
// Cleanup
device->waitIdle();
device.waitIdle();
glfwDestroyWindow( window );
glfwTerminate();

View File

@ -42,35 +42,31 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -78,104 +74,99 @@ int main( int /*argc*/, char ** /*argv*/ )
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::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device,
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(
device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device,
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device,
colorFormat,
depthBufferData.format,
vk::AttachmentLoadOp::eClear,
vk::ImageLayout::eColorAttachmentOptimal );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
vk::raii::su::TextureData greenTextureData( *physicalDevice, *device );
greenTextureData.setImage( *commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
vk::raii::su::TextureData greenTextureData( physicalDevice, device );
greenTextureData.setImage( commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
vk::raii::su::TextureData checkeredTextureData( *physicalDevice, *device );
checkeredTextureData.setImage( *commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::raii::su::TextureData checkeredTextureData( physicalDevice, device );
checkeredTextureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
// create two identical descriptor sets, each with a different texture but identical UBOs
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool = vk::raii::su::makeUniqueDescriptorPool(
*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 );
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,
vk::raii::su::updateDescriptorSets( device,
descriptorSets[0],
{ { vk::DescriptorType::eUniformBuffer, *uniformBufferData.buffer, {} } },
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
greenTextureData );
vk::raii::su::updateDescriptorSets( *device,
vk::raii::su::updateDescriptorSets( device,
descriptorSets[1],
{ { vk::DescriptorType::eUniformBuffer, *uniformBufferData.buffer, {} } },
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
checkeredTextureData );
/* VULKAN_KEY_START */
// create four secondary command buffers, for each quadrant of the screen
vk::CommandBufferAllocateInfo commandBufferAllocateInfo( **commandPool, vk::CommandBufferLevel::eSecondary, 4 );
vk::raii::CommandBuffers secondaryCommandBuffers( *device, commandBufferAllocateInfo );
vk::CommandBufferAllocateInfo commandBufferAllocateInfo( *commandPool, vk::CommandBufferLevel::eSecondary, 4 );
vk::raii::CommandBuffers secondaryCommandBuffers( device, commandBufferAllocateInfo );
// Get the index of the next available swapchain image:
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
vk::raii::su::setImageLayout( *commandBuffer,
vk::raii::su::setImageLayout( commandBuffer,
static_cast<vk::Image>( swapChainData.images[imageIndex] ),
swapChainData.colorFormat,
vk::ImageLayout::eUndefined,
@ -186,7 +177,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Rect2D scissor( vk::Offset2D( 0, 0 ), vk::Extent2D( surfaceData.extent ) );
// now we record four separate command buffers, one for each quadrant of the screen
vk::CommandBufferInheritanceInfo commandBufferInheritanceInfo( **renderPass, 0, **framebuffers[imageIndex] );
vk::CommandBufferInheritanceInfo commandBufferInheritanceInfo( *renderPass, 0, *framebuffers[imageIndex] );
vk::CommandBufferBeginInfo secondaryBeginInfo( vk::CommandBufferUsageFlagBits::eOneTimeSubmit |
vk::CommandBufferUsageFlagBits::eRenderPassContinue,
&commandBufferInheritanceInfo );
@ -198,10 +189,10 @@ int main( int /*argc*/, char ** /*argv*/ )
viewport.y = 25.0f + 250.0f * ( i / 2 );
secondaryCommandBuffers[i].begin( secondaryBeginInfo );
secondaryCommandBuffers[i].bindPipeline( vk::PipelineBindPoint::eGraphics, **graphicsPipeline );
secondaryCommandBuffers[i].bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
secondaryCommandBuffers[i].bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, **pipelineLayout, 0, { *descriptorSets[i == 0 || i == 3] }, nullptr );
secondaryCommandBuffers[i].bindVertexBuffers( 0, { **vertexBufferData.buffer }, offset );
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 );
secondaryCommandBuffers[i].draw( 12 * 3, 1, 0, 0 );
@ -214,13 +205,13 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo(
**renderPass, **framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
*renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
// specifying VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS means this render pass may ONLY call
// vkCmdExecuteCommands
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eSecondaryCommandBuffers );
commandBuffer->executeCommands( executeCommandBuffers );
commandBuffer->endRenderPass();
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eSecondaryCommandBuffers );
commandBuffer.executeCommands( executeCommandBuffers );
commandBuffer.endRenderPass();
vk::ImageSubresourceRange imageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 );
vk::ImageMemoryBarrier prePresentBarrier( vk::AccessFlagBits::eColorAttachmentWrite,
@ -231,24 +222,24 @@ int main( int /*argc*/, char ** /*argv*/ )
VK_QUEUE_FAMILY_IGNORED,
static_cast<vk::Image>( swapChainData.images[imageIndex] ),
imageSubresourceRange );
commandBuffer->pipelineBarrier( vk::PipelineStageFlagBits::eColorAttachmentOutput,
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eColorAttachmentOutput,
vk::PipelineStageFlagBits::eBottomOfPipe,
vk::DependencyFlags(),
nullptr,
nullptr,
prePresentBarrier );
commandBuffer->end();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
result = presentQueue->presentKHR( vk::PresentInfoKHR( {}, **swapChainData.swapChain, imageIndex, {} ) );
result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, **swapChainData.pSwapChain, imageIndex, {} ) );
switch ( result )
{
case vk::Result::eSuccess: break;
@ -261,7 +252,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_END */
device->waitIdle();
device.waitIdle();
}
catch ( vk::SystemError & err )
{

View File

@ -70,35 +70,31 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -106,41 +102,39 @@ int main( int /*argc*/, char ** /*argv*/ )
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::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
/* VULKAN_KEY_START */
commandBuffer->begin( vk::CommandBufferBeginInfo() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
// Create the separate image
vk::raii::su::TextureData textureData( *physicalDevice, *device );
textureData.setImage( *commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
vk::raii::su::TextureData textureData( physicalDevice, device );
textureData.setImage( commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
// Create the separate sampler
vk::SamplerCreateInfo samplerCreateInfo( {},
@ -158,7 +152,7 @@ int main( int /*argc*/, char ** /*argv*/ )
0.0f,
0.0f,
vk::BorderColor::eFloatOpaqueWhite );
std::unique_ptr<vk::raii::Sampler> sampler = vk::raii::su::make_unique<vk::raii::Sampler>( *device, samplerCreateInfo );
vk::raii::Sampler sampler( device, samplerCreateInfo );
// Create binding and layout for the following, matching contents of shader
// binding 0 = uniform buffer (MVP)
@ -170,13 +164,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorSetLayoutBinding( 2, vk::DescriptorType::eSampler, 1, vk::ShaderStageFlagBits::eFragment ) }
};
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( {}, resourceBindings );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout =
vk::raii::su::make_unique<vk::raii::DescriptorSetLayout>( *device, descriptorSetLayoutCreateInfo );
vk::raii::DescriptorSetLayout descriptorSetLayout( device, descriptorSetLayoutCreateInfo );
// Create pipeline layout
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, **descriptorSetLayout );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::make_unique<vk::raii::PipelineLayout>( *device, pipelineLayoutCreateInfo );
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( {}, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, pipelineLayoutCreateInfo );
// Create a single pool to contain data for the descriptor set
std::array<vk::DescriptorPoolSize, 3> poolSizes = {
@ -186,51 +178,47 @@ int main( int /*argc*/, char ** /*argv*/ )
};
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::make_unique<vk::raii::DescriptorPool>( *device, descriptorPoolCreateInfo );
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );
// Populate descriptor sets
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( **descriptorPool, **descriptorSetLayout );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet = vk::raii::su::make_unique<vk::raii::DescriptorSet>(
std::move( vk::raii::DescriptorSets( *device, descriptorSetAllocateInfo ).front() ) );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet =
std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );
vk::DescriptorBufferInfo bufferInfo( **uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo(
**textureData.sampler, **textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::DescriptorImageInfo samplerInfo( **sampler, {}, {} );
*textureData.sampler, **textureData.pImageData->pImageView, 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 ) }
{ 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 );
device.updateDescriptorSets( descriptorWrites, nullptr );
/* VULKAN_KEY_END */
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
// Get the index of the next available swapchain image:
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -239,38 +227,38 @@ int main( int /*argc*/, char ** /*argv*/ )
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo(
**renderPass, **framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
*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.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer->bindVertexBuffers( 0, { **vertexBufferData.buffer }, { 0 } );
commandBuffer->setViewport( 0,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;
@ -281,7 +269,7 @@ int main( int /*argc*/, char ** /*argv*/ )
}
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
device->waitIdle();
device.waitIdle();
}
catch ( vk::SystemError & err )
{

View File

@ -58,9 +58,9 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
vk::raii::Context context;
std::vector<vk::ExtensionProperties> instanceExtensionProperties = context->enumerateInstanceExtensionProperties();
std::vector<vk::ExtensionProperties> instanceExtensionProperties = context.enumerateInstanceExtensionProperties();
bool supportsGetSurfaceCapabilities2 =
( std::find_if( instanceExtensionProperties.begin(),
instanceExtensionProperties.end(),
@ -74,17 +74,15 @@ int main( int /*argc*/, char ** /*argv*/ )
extensions.push_back( VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME );
}
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *context, AppName, EngineName, {}, extensions );
vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, extensions );
#if !defined( NDEBUG )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// enumerate the physicalDevices
vk::raii::PhysicalDevices physicalDevices( *instance );
vk::raii::PhysicalDevices physicalDevices( instance );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
/* VULKAN_KEY_START */
@ -104,7 +102,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DisplayNativeHdrSurfaceCapabilitiesAMD,
vk::SharedPresentSurfaceCapabilitiesKHR,
vk::SurfaceCapabilitiesFullScreenExclusiveEXT,
vk::SurfaceProtectedCapabilitiesKHR>( { **surfaceData.surface } );
vk::SurfaceProtectedCapabilitiesKHR>( { **surfaceData.pSurface } );
vk::SurfaceCapabilitiesKHR const & surfaceCapabilities =
surfaceCapabilities2.get<vk::SurfaceCapabilities2KHR>().surfaceCapabilities;
@ -155,7 +153,7 @@ int main( int /*argc*/, char ** /*argv*/ )
else
{
vk::SurfaceCapabilitiesKHR surfaceCapabilities =
physicalDevices[i].getSurfaceCapabilitiesKHR( **surfaceData.surface );
physicalDevices[i].getSurfaceCapabilitiesKHR( **surfaceData.pSurface );
cout( surfaceCapabilities );
}
}

View File

@ -29,18 +29,17 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
// enumerate the physicalDevices
vk::raii::PhysicalDevices physicalDevices( *instance );
vk::raii::PhysicalDevices physicalDevices( instance );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
/* VULKAN_KEY_START */
@ -49,7 +48,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{
std::cout << "PhysicalDevice " << i << "\n";
std::vector<vk::SurfaceFormatKHR> surfaceFormats =
physicalDevices[i].getSurfaceFormatsKHR( **surfaceData.surface );
physicalDevices[i].getSurfaceFormatsKHR( **surfaceData.pSurface );
for ( size_t j = 0; j < surfaceFormats.size(); j++ )
{
std::cout << "\tFormat " << j << "\n";

View File

@ -32,35 +32,31 @@ int main( int /*argc*/, char ** /*argv*/ )
{
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -68,79 +64,74 @@ int main( int /*argc*/, char ** /*argv*/ )
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 );
vk::raii::su::TextureData textureData( physicalDevice, device );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
textureData.setImage( *commandBuffer, vk::su::CheckerboardImageGenerator() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
textureData.setImage( commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::raii::su::BufferData uniformBufferData(
*physicalDevice, *device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
glm::mat4x4 mvpcMatrix = vk::su::createModelViewProjectionClipMatrix( surfaceData.extent );
vk::raii::su::copyToDevice( *uniformBufferData.deviceMemory, mvpcMatrix );
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device,
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(
device,
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice->getSurfaceFormatsKHR( **surfaceData.surface ) ).format;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, depthBufferData.format );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
*physicalDevice, *device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
vk::raii::su::copyToDevice(
*vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
vertexBufferData.deviceMemory, texturedCubeData, sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool = vk::raii::su::makeUniqueDescriptorPool(
*device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet =
vk::raii::su::makeUniqueDescriptorSet( *device, *descriptorPool, *descriptorSetLayout );
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 } },
vk::raii::su::updateDescriptorSets( device,
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, nullptr } },
{ textureData } );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline = vk::raii::su::makeUniqueGraphicsPipeline(
*device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline =
vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
sizeof( texturedCubeData[0] ),
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
// Get the index of the next available swapchain image:
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@ -148,38 +139,38 @@ 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 );
*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.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,
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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 12 * 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 12 * 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;
@ -190,7 +181,7 @@ int main( int /*argc*/, char ** /*argv*/ )
}
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
device->waitIdle();
device.waitIdle();
}
catch ( vk::SystemError & err )
{

View File

@ -59,16 +59,15 @@ int main( int /*argc*/, char ** /*argv*/ )
try
{
std::unique_ptr<vk::raii::Context> context = vk::raii::su::make_unique<vk::raii::Context>();
std::unique_ptr<vk::raii::Instance> instance =
vk::raii::su::makeUniqueInstance( *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 )
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT> debugUtilsMessenger =
vk::raii::su::makeUniqueDebugUtilsMessengerEXT( *instance );
vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
#endif
std::unique_ptr<vk::raii::PhysicalDevice> physicalDevice = vk::raii::su::makeUniquePhysicalDevice( *instance );
vk::raii::PhysicalDevice physicalDevice = std::move( vk::raii::PhysicalDevices( instance ).front() );
vk::PhysicalDeviceProperties physicalDeviceProperties = physicalDevice->getProperties();
vk::PhysicalDeviceProperties physicalDeviceProperties = physicalDevice.getProperties();
if ( physicalDeviceProperties.limits.maxTexelBufferElements < 4 )
{
std::cout << "maxTexelBufferElements too small\n";
@ -76,33 +75,30 @@ int main( int /*argc*/, char ** /*argv*/ )
}
vk::Format texelFormat = vk::Format::eR32Sfloat;
vk::FormatProperties formatProperties = physicalDevice->getFormatProperties( texelFormat );
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( texelFormat );
if ( !( formatProperties.bufferFeatures & vk::FormatFeatureFlagBits::eUniformTexelBuffer ) )
{
std::cout << "R32_SFLOAT format unsupported for texel buffer\n";
exit( -1 );
}
vk::raii::su::SurfaceData surfaceData( *instance, AppName, vk::Extent2D( 500, 500 ) );
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( *physicalDevice, *surfaceData.surface );
std::unique_ptr<vk::raii::Device> device = vk::raii::su::makeUniqueDevice(
*physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
std::unique_ptr<vk::raii::CommandPool> commandPool =
vk::raii::su::makeUniqueCommandPool( *device, graphicsAndPresentQueueFamilyIndex.first );
std::unique_ptr<vk::raii::CommandBuffer> commandBuffer =
vk::raii::su::makeUniqueCommandBuffer( *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 );
std::unique_ptr<vk::raii::Queue> graphicsQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.first, 0 );
std::unique_ptr<vk::raii::Queue> presentQueue =
vk::raii::su::make_unique<vk::raii::Queue>( *device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 );
vk::raii::su::SwapChainData swapChainData( *physicalDevice,
*device,
*surfaceData.surface,
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@ -111,108 +107,102 @@ int main( int /*argc*/, char ** /*argv*/ )
graphicsAndPresentQueueFamilyIndex.second );
vk::raii::su::BufferData texelBufferData(
*physicalDevice, *device, sizeof( texels ), vk::BufferUsageFlagBits::eUniformTexelBuffer );
physicalDevice, device, sizeof( texels ), vk::BufferUsageFlagBits::eUniformTexelBuffer );
texelBufferData.upload( texels );
vk::BufferViewCreateInfo bufferViewCreateInfo( {}, **texelBufferData.buffer, texelFormat, 0, sizeof( texels ) );
std::unique_ptr<vk::raii::BufferView> texelBufferView =
vk::raii::su::make_unique<vk::raii::BufferView>( *device, bufferViewCreateInfo );
vk::BufferViewCreateInfo bufferViewCreateInfo( {}, *texelBufferData.buffer, texelFormat, 0, sizeof( texels ) );
vk::raii::BufferView texelBufferView( device, bufferViewCreateInfo );
std::unique_ptr<vk::raii::DescriptorSetLayout> descriptorSetLayout = vk::raii::su::makeUniqueDescriptorSetLayout(
*device, { { vk::DescriptorType::eUniformTexelBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
std::unique_ptr<vk::raii::PipelineLayout> pipelineLayout =
vk::raii::su::makeUniquePipelineLayout( *device, *descriptorSetLayout );
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;
std::unique_ptr<vk::raii::RenderPass> renderPass =
vk::raii::su::makeUniqueRenderPass( *device, colorFormat, vk::Format::eUndefined );
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, vk::Format::eUndefined );
glslang::InitializeProcess();
std::unique_ptr<vk::raii::ShaderModule> vertexShaderModule =
vk::raii::su::makeUniqueShaderModule( *device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
std::unique_ptr<vk::raii::ShaderModule> fragmentShaderModule =
vk::raii::su::makeUniqueShaderModule( *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<std::unique_ptr<vk::raii::Framebuffer>> framebuffers = vk::raii::su::makeUniqueFramebuffers(
*device, *renderPass, swapChainData.imageViews, std::unique_ptr<vk::raii::ImageView>(), surfaceData.extent );
std::vector<vk::raii::Framebuffer> framebuffers =
vk::raii::su::makeFramebuffers( device, renderPass, swapChainData.imageViews, nullptr, surfaceData.extent );
std::unique_ptr<vk::raii::DescriptorPool> descriptorPool =
vk::raii::su::makeUniqueDescriptorPool( *device, { { vk::DescriptorType::eUniformTexelBuffer, 1 } } );
std::unique_ptr<vk::raii::DescriptorSet> descriptorSet =
vk::raii::su::makeUniqueDescriptorSet( *device, *descriptorPool, *descriptorSetLayout );
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 } },
device,
descriptorSet,
{ { vk::DescriptorType::eUniformTexelBuffer, texelBufferData.buffer, &texelBufferView } },
{} );
std::unique_ptr<vk::raii::PipelineCache> pipelineCache =
vk::raii::su::make_unique<vk::raii::PipelineCache>( *device, vk::PipelineCacheCreateInfo() );
std::unique_ptr<vk::raii::Pipeline> graphicsPipeline =
vk::raii::su::makeUniqueGraphicsPipeline( *device,
*pipelineCache,
*vertexShaderModule,
vk::raii::PipelineCache pipelineCache( device, vk::PipelineCacheCreateInfo() );
vk::raii::Pipeline graphicsPipeline = vk::raii::su::makeGraphicsPipeline( device,
pipelineCache,
vertexShaderModule,
nullptr,
*fragmentShaderModule,
fragmentShaderModule,
nullptr,
0,
{},
vk::FrontFace::eClockwise,
true,
*pipelineLayout,
*renderPass );
pipelineLayout,
renderPass );
/* VULKAN_KEY_START */
// Get the index of the next available swapchain image:
std::unique_ptr<vk::raii::Semaphore> imageAcquiredSemaphore =
vk::raii::su::make_unique<vk::raii::Semaphore>( *device, vk::SemaphoreCreateInfo() );
vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.swapChain->acquireNextImage( vk::su::FenceTimeout, **imageAcquiredSemaphore );
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
commandBuffer->begin( vk::CommandBufferBeginInfo() );
commandBuffer.begin( vk::CommandBufferBeginInfo() );
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 );
*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.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer->setViewport( 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->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
commandBuffer->draw( 3, 1, 0, 0 );
commandBuffer->endRenderPass();
commandBuffer->end();
commandBuffer.draw( 3, 1, 0, 0 );
commandBuffer.endRenderPass();
commandBuffer.end();
std::unique_ptr<vk::raii::Fence> drawFence = vk::raii::su::make_unique<vk::raii::Fence>( *device, vk::FenceCreateInfo() );
vk::raii::Fence drawFence( device, vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( **imageAcquiredSemaphore, waitDestinationStageMask, **commandBuffer );
graphicsQueue->submit( submitInfo, **drawFence );
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );
while ( vk::Result::eTimeout == device->waitForFences( { **drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.swapChain, imageIndex );
result = presentQueue->presentKHR( presentInfoKHR );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{
case vk::Result::eSuccess: break;
@ -225,7 +215,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_END */
device->waitIdle();
device.waitIdle();
}
catch ( vk::SystemError & err )
{

View File

@ -13,8 +13,8 @@
// limitations under the License.
//
#include "utils.hpp"
#include "../../samples/utils/shaders.hpp"
#include "utils.hpp"
namespace vk
{
@ -23,7 +23,7 @@ namespace vk
namespace su
{
template <typename Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
std::unique_ptr<vk::raii::ShaderModule> makeUniqueShaderModule( vk::raii::Device const & device,
vk::raii::ShaderModule makeShaderModule( vk::raii::Device const & device,
vk::ShaderStageFlagBits shaderStage,
std::string const & shaderText )
{
@ -33,8 +33,7 @@ namespace vk
throw std::runtime_error( "Could not convert glsl shader to spir-v -> terminating" );
}
return vk::raii::su::make_unique<vk::raii::ShaderModule>(
device, vk::ShaderModuleCreateInfo( vk::ShaderModuleCreateFlags(), shaderSPV ) );
return vk::raii::ShaderModule( device, vk::ShaderModuleCreateInfo( vk::ShaderModuleCreateFlags(), shaderSPV ) );
}
} // namespace su
} // namespace raii

View File

@ -205,14 +205,16 @@ namespace vk
vk::BufferUsageFlags usage,
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 ) )
#if !defined( NDEBUG )
: m_size( size ), m_usage( usage ), m_propertyFlags( propertyFlags )
, m_size( size )
, m_usage( usage )
, m_propertyFlags( propertyFlags )
#endif
{
buffer = vk::raii::su::make_unique<vk::raii::Buffer>( device, vk::BufferCreateInfo( {}, size, usage ) );
deviceMemory = vk::raii::su::make_unique<vk::raii::DeviceMemory>( vk::raii::su::allocateDeviceMemory(
device, physicalDevice.getMemoryProperties(), buffer->getMemoryRequirements(), propertyFlags ) );
buffer->bindMemory( **deviceMemory, 0 );
buffer.bindMemory( *deviceMemory, 0 );
}
template <typename DataType>
@ -222,9 +224,9 @@ namespace vk
( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible ) );
assert( sizeof( DataType ) <= m_size );
void * dataPtr = deviceMemory->mapMemory( 0, sizeof( DataType ) );
void * dataPtr = deviceMemory.mapMemory( 0, sizeof( DataType ) );
memcpy( dataPtr, &data, sizeof( DataType ) );
deviceMemory->unmapMemory();
deviceMemory.unmapMemory();
}
template <typename DataType>
@ -235,7 +237,7 @@ namespace vk
size_t elementSize = stride ? stride : sizeof( DataType );
assert( sizeof( DataType ) <= elementSize );
copyToDevice( *deviceMemory, data.data(), data.size(), elementSize );
copyToDevice( deviceMemory, data.data(), data.size(), elementSize );
}
template <typename DataType>
@ -257,18 +259,19 @@ namespace vk
vk::raii::su::BufferData stagingBuffer(
physicalDevice, device, dataSize, vk::BufferUsageFlagBits::eTransferSrc );
copyToDevice( *stagingBuffer.deviceMemory, data.data(), data.size(), elementSize );
copyToDevice( stagingBuffer.deviceMemory, data.data(), data.size(), elementSize );
vk::raii::su::oneTimeSubmit(
device,
commandPool,
queue,
[&]( vk::raii::CommandBuffer const & commandBuffer )
{ commandBuffer.copyBuffer( **stagingBuffer.buffer, **this->buffer, vk::BufferCopy( 0, 0, dataSize ) ); } );
{ commandBuffer.copyBuffer( *stagingBuffer.buffer, *this->buffer, vk::BufferCopy( 0, 0, dataSize ) ); } );
}
std::unique_ptr<vk::raii::Buffer> buffer;
std::unique_ptr<vk::raii::DeviceMemory> deviceMemory;
// the order of buffer and deviceMemory here is important to get the constructor running !
vk::raii::Buffer buffer;
vk::raii::DeviceMemory deviceMemory;
#if !defined( NDEBUG )
private:
vk::DeviceSize m_size;
@ -289,8 +292,8 @@ namespace vk
vk::MemoryPropertyFlags memoryProperties,
vk::ImageAspectFlags aspectMask )
: format( format_ )
{
vk::ImageCreateInfo imageCreateInfo( vk::ImageCreateFlags(),
, image( device,
{ vk::ImageCreateFlags(),
vk::ImageType::e2D,
format,
vk::Extent3D( extent, 1 ),
@ -301,26 +304,26 @@ namespace vk
usage | vk::ImageUsageFlagBits::eSampled,
vk::SharingMode::eExclusive,
{},
initialLayout );
image = vk::raii::su::make_unique<vk::raii::Image>( device, imageCreateInfo );
deviceMemory = vk::raii::su::make_unique<vk::raii::DeviceMemory>( vk::raii::su::allocateDeviceMemory(
device, physicalDevice.getMemoryProperties(), image->getMemoryRequirements(), memoryProperties ) );
image->bindMemory( **deviceMemory, 0 );
vk::ComponentMapping componentMapping(
ComponentSwizzle::eR, ComponentSwizzle::eG, ComponentSwizzle::eB, ComponentSwizzle::eA );
vk::ImageSubresourceRange imageSubresourceRange( aspectMask, 0, 1, 0, 1 );
vk::ImageViewCreateInfo imageViewCreateInfo(
{}, **image, vk::ImageViewType::e2D, format, componentMapping, imageSubresourceRange );
imageView = vk::raii::su::make_unique<vk::raii::ImageView>( device, imageViewCreateInfo );
initialLayout } )
, deviceMemory( vk::raii::su::allocateDeviceMemory(
device, physicalDevice.getMemoryProperties(), image.getMemoryRequirements(), memoryProperties ) )
{
image.bindMemory( *deviceMemory, 0 );
pImageView = vk::raii::su::make_unique<vk::raii::ImageView>(
device,
vk::ImageViewCreateInfo(
{},
*image,
vk::ImageViewType::e2D,
format,
{ ComponentSwizzle::eR, ComponentSwizzle::eG, ComponentSwizzle::eB, ComponentSwizzle::eA },
{ aspectMask, 0, 1, 0, 1 } ) );
}
vk::Format format;
std::unique_ptr<vk::raii::Image> image;
std::unique_ptr<vk::raii::DeviceMemory> deviceMemory;
std::unique_ptr<vk::raii::ImageView> imageView;
vk::raii::Image image;
vk::raii::DeviceMemory deviceMemory;
std::unique_ptr<vk::raii::ImageView> pImageView;
};
struct DepthBufferData : public ImageData
@ -351,12 +354,12 @@ namespace vk
glfwCreateWindowSurface( static_cast<VkInstance>( *instance ), window.handle, nullptr, &_surface );
if ( err != VK_SUCCESS )
throw std::runtime_error( "Failed to create window!" );
surface = vk::raii::su::make_unique<vk::raii::SurfaceKHR>( instance, _surface );
pSurface = vk::raii::su::make_unique<vk::raii::SurfaceKHR>( instance, _surface );
}
vk::Extent2D extent;
vk::su::WindowData window;
std::unique_ptr<vk::raii::SurfaceKHR> surface;
std::unique_ptr<vk::raii::SurfaceKHR> pSurface;
};
struct SwapChainData
@ -366,7 +369,7 @@ namespace vk
vk::raii::SurfaceKHR const & surface,
vk::Extent2D const & extent,
vk::ImageUsageFlags usage,
std::unique_ptr<vk::raii::SwapchainKHR> const & oldSwapchain,
vk::raii::SwapchainKHR const * pOldSwapchain,
uint32_t graphicsQueueFamilyIndex,
uint32_t presentQueueFamilyIndex )
{
@ -417,7 +420,7 @@ namespace vk
compositeAlpha,
presentMode,
true,
oldSwapchain ? **oldSwapchain : nullptr );
pOldSwapchain ? **pOldSwapchain : nullptr );
if ( graphicsQueueFamilyIndex != presentQueueFamilyIndex )
{
uint32_t queueFamilyIndices[2] = { graphicsQueueFamilyIndex, presentQueueFamilyIndex };
@ -428,9 +431,9 @@ namespace vk
swapChainCreateInfo.queueFamilyIndexCount = 2;
swapChainCreateInfo.pQueueFamilyIndices = queueFamilyIndices;
}
swapChain = vk::raii::su::make_unique<vk::raii::SwapchainKHR>( device, swapChainCreateInfo );
pSwapChain = vk::raii::su::make_unique<vk::raii::SwapchainKHR>( device, swapChainCreateInfo );
images = swapChain->getImages();
images = pSwapChain->getImages();
imageViews.reserve( images.size() );
vk::ComponentMapping componentMapping(
@ -449,7 +452,7 @@ namespace vk
}
vk::Format colorFormat;
std::unique_ptr<vk::raii::SwapchainKHR> swapChain;
std::unique_ptr<vk::raii::SwapchainKHR> pSwapChain;
std::vector<VkImage> images;
std::vector<vk::raii::ImageView> imageViews;
};
@ -463,44 +466,10 @@ namespace vk
vk::FormatFeatureFlags formatFeatureFlags = {},
bool anisotropyEnable = false,
bool forceStaging = false )
: format( vk::Format::eR8G8B8A8Unorm ), extent( extent_ )
{
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( format );
formatFeatureFlags |= vk::FormatFeatureFlagBits::eSampledImage;
needsStaging =
forceStaging || ( ( formatProperties.linearTilingFeatures & formatFeatureFlags ) != formatFeatureFlags );
vk::ImageTiling imageTiling;
vk::ImageLayout initialLayout;
vk::MemoryPropertyFlags requirements;
if ( needsStaging )
{
assert( ( formatProperties.optimalTilingFeatures & formatFeatureFlags ) == formatFeatureFlags );
stagingBufferData = vk::raii::su::make_unique<BufferData>(
physicalDevice, device, extent.width * extent.height * 4, vk::BufferUsageFlagBits::eTransferSrc );
imageTiling = vk::ImageTiling::eOptimal;
usageFlags |= vk::ImageUsageFlagBits::eTransferDst;
initialLayout = vk::ImageLayout::eUndefined;
}
else
{
imageTiling = vk::ImageTiling::eLinear;
initialLayout = vk::ImageLayout::ePreinitialized;
requirements = vk::MemoryPropertyFlagBits::eHostCoherent | vk::MemoryPropertyFlagBits::eHostVisible;
}
imageData = vk::raii::su::make_unique<ImageData>( physicalDevice,
device,
format,
extent,
imageTiling,
usageFlags | vk::ImageUsageFlagBits::eSampled,
initialLayout,
requirements,
vk::ImageAspectFlagBits::eColor );
sampler =
vk::raii::su::make_unique<vk::raii::Sampler>( device,
vk::SamplerCreateInfo( vk::SamplerCreateFlags(),
: format( vk::Format::eR8G8B8A8Unorm )
, extent( extent_ )
, sampler( device,
{ {},
vk::Filter::eLinear,
vk::Filter::eLinear,
vk::SamplerMipmapMode::eLinear,
@ -514,7 +483,41 @@ namespace vk
vk::CompareOp::eNever,
0.0f,
0.0f,
vk::BorderColor::eFloatOpaqueBlack ) );
vk::BorderColor::eFloatOpaqueBlack } )
{
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( format );
formatFeatureFlags |= vk::FormatFeatureFlagBits::eSampledImage;
needsStaging =
forceStaging || ( ( formatProperties.linearTilingFeatures & formatFeatureFlags ) != formatFeatureFlags );
vk::ImageTiling imageTiling;
vk::ImageLayout initialLayout;
vk::MemoryPropertyFlags requirements;
if ( needsStaging )
{
assert( ( formatProperties.optimalTilingFeatures & formatFeatureFlags ) == formatFeatureFlags );
pStagingBufferData = vk::raii::su::make_unique<BufferData>(
physicalDevice, device, extent.width * extent.height * 4, vk::BufferUsageFlagBits::eTransferSrc );
imageTiling = vk::ImageTiling::eOptimal;
usageFlags |= vk::ImageUsageFlagBits::eTransferDst;
initialLayout = vk::ImageLayout::eUndefined;
}
else
{
imageTiling = vk::ImageTiling::eLinear;
initialLayout = vk::ImageLayout::ePreinitialized;
requirements = vk::MemoryPropertyFlagBits::eHostCoherent | vk::MemoryPropertyFlagBits::eHostVisible;
}
pImageData = vk::raii::su::make_unique<ImageData>( physicalDevice,
device,
format,
extent,
imageTiling,
usageFlags | vk::ImageUsageFlagBits::eSampled,
initialLayout,
requirements,
vk::ImageAspectFlagBits::eColor );
}
template <typename ImageGenerator>
@ -522,17 +525,17 @@ namespace vk
{
void * data =
needsStaging
? stagingBufferData->deviceMemory->mapMemory( 0, stagingBufferData->buffer->getMemoryRequirements().size )
: imageData->deviceMemory->mapMemory( 0, imageData->image->getMemoryRequirements().size );
? pStagingBufferData->deviceMemory.mapMemory( 0, pStagingBufferData->buffer.getMemoryRequirements().size )
: pImageData->deviceMemory.mapMemory( 0, pImageData->image.getMemoryRequirements().size );
imageGenerator( data, extent );
needsStaging ? stagingBufferData->deviceMemory->unmapMemory() : imageData->deviceMemory->unmapMemory();
needsStaging ? pStagingBufferData->deviceMemory.unmapMemory() : pImageData->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,
*pImageData->image,
pImageData->format,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eTransferDstOptimal );
vk::BufferImageCopy copyRegion( 0,
@ -542,11 +545,11 @@ namespace vk
vk::Offset3D( 0, 0, 0 ),
vk::Extent3D( extent, 1 ) );
commandBuffer.copyBufferToImage(
**stagingBufferData->buffer, **imageData->image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
*pStagingBufferData->buffer, *pImageData->image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
// Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY
vk::raii::su::setImageLayout( commandBuffer,
**imageData->image,
imageData->format,
*pImageData->image,
pImageData->format,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eShaderReadOnlyOptimal );
}
@ -554,8 +557,8 @@ namespace vk
{
// If we can use the linear tiled image as a texture, just do it
vk::raii::su::setImageLayout( commandBuffer,
**imageData->image,
imageData->format,
*pImageData->image,
pImageData->format,
vk::ImageLayout::ePreinitialized,
vk::ImageLayout::eShaderReadOnlyOptimal );
}
@ -564,9 +567,9 @@ namespace vk
vk::Format format;
vk::Extent2D extent;
bool needsStaging;
std::unique_ptr<BufferData> stagingBufferData;
std::unique_ptr<ImageData> imageData;
std::unique_ptr<vk::raii::Sampler> sampler;
std::unique_ptr<BufferData> pStagingBufferData;
std::unique_ptr<ImageData> pImageData;
vk::raii::Sampler sampler;
};
std::pair<uint32_t, uint32_t>
@ -608,31 +611,14 @@ namespace vk
throw std::runtime_error( "Could not find queues for both graphics or present -> terminating" );
}
std::unique_ptr<vk::raii::CommandBuffer> makeUniqueCommandBuffer( vk::raii::Device const & device,
vk::raii::CommandBuffer makeCommandBuffer( vk::raii::Device const & device,
vk::raii::CommandPool const & commandPool )
{
vk::CommandBufferAllocateInfo commandBufferAllocateInfo( *commandPool, vk::CommandBufferLevel::ePrimary, 1 );
return vk::raii::su::make_unique<vk::raii::CommandBuffer>(
std::move( vk::raii::CommandBuffers( device, commandBufferAllocateInfo ).front() ) );
return std::move( vk::raii::CommandBuffers( device, commandBufferAllocateInfo ).front() );
}
std::unique_ptr<vk::raii::CommandPool> makeUniqueCommandPool( vk::raii::Device const & device,
uint32_t queueFamilyIndex )
{
vk::CommandPoolCreateInfo commandPoolCreateInfo( vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
queueFamilyIndex );
return vk::raii::su::make_unique<vk::raii::CommandPool>( device, commandPoolCreateInfo );
}
std::unique_ptr<vk::raii::DebugUtilsMessengerEXT>
makeUniqueDebugUtilsMessengerEXT( vk::raii::Instance const & instance )
{
return vk::raii::su::make_unique<vk::raii::DebugUtilsMessengerEXT>(
instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
}
std::unique_ptr<vk::raii::DescriptorPool>
makeUniqueDescriptorPool( vk::raii::Device const & device,
vk::raii::DescriptorPool makeDescriptorPool( vk::raii::Device const & device,
std::vector<vk::DescriptorPoolSize> const & poolSizes )
{
assert( !poolSizes.empty() );
@ -645,20 +631,10 @@ namespace vk
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, maxSets, poolSizes );
return vk::raii::su::make_unique<vk::raii::DescriptorPool>( device, descriptorPoolCreateInfo );
return vk::raii::DescriptorPool( device, descriptorPoolCreateInfo );
}
std::unique_ptr<vk::raii::DescriptorSet>
makeUniqueDescriptorSet( vk::raii::Device const & device,
vk::raii::DescriptorPool const & descriptorPool,
vk::raii::DescriptorSetLayout const & descriptorSetLayout )
{
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
return vk::raii::su::make_unique<vk::raii::DescriptorSet>(
std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() ) );
}
std::unique_ptr<vk::raii::DescriptorSetLayout> makeUniqueDescriptorSetLayout(
vk::raii::DescriptorSetLayout makeDescriptorSetLayout(
vk::raii::Device const & device,
std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const & bindingData,
vk::DescriptorSetLayoutCreateFlags flags = {} )
@ -672,11 +648,10 @@ namespace vk
std::get<2>( bindingData[i] ) );
}
vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( flags, bindings );
return vk::raii::su::make_unique<vk::raii::DescriptorSetLayout>( device, descriptorSetLayoutCreateInfo );
return vk::raii::DescriptorSetLayout( device, descriptorSetLayoutCreateInfo );
}
std::unique_ptr<vk::raii::Device>
makeUniqueDevice( vk::raii::PhysicalDevice const & physicalDevice,
vk::raii::Device makeDevice( vk::raii::PhysicalDevice const & physicalDevice,
uint32_t queueFamilyIndex,
std::vector<std::string> const & extensions = {},
vk::PhysicalDeviceFeatures const * physicalDeviceFeatures = nullptr,
@ -695,39 +670,38 @@ namespace vk
vk::DeviceCreateInfo deviceCreateInfo(
vk::DeviceCreateFlags(), deviceQueueCreateInfo, {}, enabledExtensions, physicalDeviceFeatures );
deviceCreateInfo.pNext = pNext;
return vk::raii::su::make_unique<vk::raii::Device>( physicalDevice, deviceCreateInfo );
return vk::raii::Device( physicalDevice, deviceCreateInfo );
}
std::vector<std::unique_ptr<vk::raii::Framebuffer>>
makeUniqueFramebuffers( vk::raii::Device const & device,
std::vector<vk::raii::Framebuffer> makeFramebuffers( vk::raii::Device const & device,
vk::raii::RenderPass & renderPass,
std::vector<vk::raii::ImageView> const & imageViews,
std::unique_ptr<vk::raii::ImageView> const & depthImageView,
vk::raii::ImageView const * pDepthImageView,
vk::Extent2D const & extent )
{
vk::ImageView attachments[2];
attachments[1] = depthImageView ? **depthImageView : vk::ImageView();
attachments[1] = pDepthImageView ? **pDepthImageView : vk::ImageView();
vk::FramebufferCreateInfo framebufferCreateInfo( vk::FramebufferCreateFlags(),
*renderPass,
depthImageView ? 2 : 1,
pDepthImageView ? 2 : 1,
attachments,
extent.width,
extent.height,
1 );
std::vector<std::unique_ptr<vk::raii::Framebuffer>> framebuffers;
std::vector<vk::raii::Framebuffer> framebuffers;
framebuffers.reserve( imageViews.size() );
for ( auto const & imageView : imageViews )
{
attachments[0] = *imageView;
framebuffers.push_back( vk::raii::su::make_unique<vk::raii::Framebuffer>( device, framebufferCreateInfo ) );
framebuffers.push_back( vk::raii::Framebuffer( device, framebufferCreateInfo ) );
}
return framebuffers;
}
std::unique_ptr<vk::raii::Pipeline> makeUniqueGraphicsPipeline(
vk::raii::Device const & device,
vk::raii::Pipeline
makeGraphicsPipeline( vk::raii::Device const & device,
vk::raii::PipelineCache const & pipelineCache,
vk::raii::ShaderModule const & vertexShaderModule,
vk::SpecializationInfo const * vertexShaderSpecializationInfo,
@ -831,10 +805,10 @@ namespace vk
*pipelineLayout,
*renderPass );
return vk::raii::su::make_unique<vk::raii::Pipeline>( device, pipelineCache, graphicsPipelineCreateInfo );
return vk::raii::Pipeline( device, pipelineCache, graphicsPipelineCreateInfo );
}
std::unique_ptr<vk::raii::Image> makeUniqueImage( vk::raii::Device const & device )
vk::raii::Image makeImage( vk::raii::Device const & device )
{
vk::ImageCreateInfo imageCreateInfo( {},
vk::ImageType::e2D,
@ -845,10 +819,10 @@ namespace vk
vk::SampleCountFlagBits::e1,
vk::ImageTiling::eLinear,
vk::ImageUsageFlagBits::eTransferSrc );
return vk::raii::su::make_unique<vk::raii::Image>( device, imageCreateInfo );
return vk::raii::Image( device, imageCreateInfo );
}
std::unique_ptr<vk::raii::Instance> makeUniqueInstance( vk::raii::Context const & context,
vk::raii::Instance makeInstance( vk::raii::Context const & context,
std::string const & appName,
std::string const & engineName,
std::vector<std::string> const & layers = {},
@ -877,26 +851,10 @@ namespace vk
instanceCreateInfoChain =
vk::su::makeInstanceCreateInfoChain( applicationInfo, enabledLayers, enabledExtensions );
return vk::raii::su::make_unique<vk::raii::Instance>( context,
instanceCreateInfoChain.get<vk::InstanceCreateInfo>() );
return vk::raii::Instance( context, instanceCreateInfoChain.get<vk::InstanceCreateInfo>() );
}
std::unique_ptr<vk::raii::PhysicalDevice> makeUniquePhysicalDevice( vk::raii::Instance const & instance )
{
return vk::raii::su::make_unique<vk::raii::PhysicalDevice>(
std::move( vk::raii::PhysicalDevices( instance ).front() ) );
}
std::unique_ptr<vk::raii::PipelineLayout>
makeUniquePipelineLayout( vk::raii::Device const & device,
vk::raii::DescriptorSetLayout const & descriptorSetLayout )
{
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout );
return vk::raii::su::make_unique<vk::raii::PipelineLayout>( device, pipelineLayoutCreateInfo );
}
std::unique_ptr<vk::raii::RenderPass>
makeUniqueRenderPass( vk::raii::Device const & device,
vk::raii::RenderPass makeRenderPass( vk::raii::Device const & device,
vk::Format colorFormat,
vk::Format depthFormat,
vk::AttachmentLoadOp loadOp = vk::AttachmentLoadOp::eClear,
@ -936,7 +894,7 @@ namespace vk
: nullptr );
vk::RenderPassCreateInfo renderPassCreateInfo(
vk::RenderPassCreateFlags(), attachmentDescriptions, subpassDescription );
return vk::raii::su::make_unique<vk::raii::RenderPass>( device, renderPassCreateInfo );
return vk::raii::RenderPass( device, renderPassCreateInfo );
}
vk::Format pickDepthFormat( vk::raii::PhysicalDevice const & physicalDevice )
@ -999,7 +957,7 @@ namespace vk
}
vk::DescriptorImageInfo imageInfo(
**textureData.sampler, **textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, **textureData.pImageData->pImageView, vk::ImageLayout::eShaderReadOnlyOptimal );
writeDescriptorSets.emplace_back(
*descriptorSet, dstBinding, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo, nullptr, nullptr );
@ -1045,7 +1003,7 @@ namespace vk
for ( auto const & thd : textureData )
{
imageInfos.emplace_back(
**thd.sampler, **thd.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*thd.sampler, **thd.pImageData->pImageView, vk::ImageLayout::eShaderReadOnlyOptimal );
}
writeDescriptorSets.emplace_back( *descriptorSet,
dstBinding,

View File

@ -353,30 +353,6 @@ namespace vk
#endif
);
#if defined( NDEBUG )
// in non-debug mode just use the InstanceCreateInfo for instance creation
vk::StructureChain<vk::InstanceCreateInfo> instanceCreateInfo(
{ {}, &applicationInfo, enabledLayers, enabledExtensions } );
#else
// in debug mode, addionally use the debugUtilsMessengerCallback in instance creation!
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
vk::DebugUtilsMessageSeverityFlagBitsEXT::eError );
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral |
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
# if defined( VULKAN_HPP_UTILS_USE_BEST_PRACTICES )
vk::ValidationFeatureEnableEXT validationFeatureEnable = vk::ValidationFeatureEnableEXT::eBestPractices;
vk::StructureChain<vk::InstanceCreateInfo, vk::DebugUtilsMessengerCreateInfoEXT, vk::ValidationFeaturesEXT>
instanceCreateInfo( { {}, &applicationInfo, enabledLayers, enabledExtensions },
{ {}, severityFlags, messageTypeFlags, &vk::su::debugUtilsMessengerCallback },
{ validationFeatureEnable } );
# else
vk::StructureChain<vk::InstanceCreateInfo, vk::DebugUtilsMessengerCreateInfoEXT> instanceCreateInfo(
{ {}, &applicationInfo, enabledLayers, enabledExtensions },
{ {}, severityFlags, messageTypeFlags, &vk::su::debugUtilsMessengerCallback } );
# endif
#endif
vk::Instance instance =
vk::createInstance( makeInstanceCreateInfoChain( applicationInfo, enabledLayers, enabledExtensions )
.get<vk::InstanceCreateInfo>() );