Introduce constructors on nullptr_t for the RAII handle classes.

This commit is contained in:
asuessenbach
2021-10-11 17:49:13 +02:00
parent 9f86befbaa
commit c3f32b8538
30 changed files with 479 additions and 1154 deletions

View File

@@ -37,7 +37,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );

View File

@@ -49,12 +49,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::Format depthFormat = vk::Format::eD16Unorm;
/* VULKAN_HPP_KEY_START */

View File

@@ -37,13 +37,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -59,7 +59,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_START */
std::array<vk::ImageView, 2> attachments;
attachments[1] = **depthBufferData.pImageView;
attachments[1] = *depthBufferData.imageView;
std::vector<vk::raii::Framebuffer> framebuffers;
framebuffers.reserve( swapChainData.imageViews.size() );

View File

@@ -48,7 +48,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -60,7 +60,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -74,7 +74,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::makeRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
/* VULKAN_KEY_START */
@@ -104,7 +104,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );

View File

@@ -51,12 +51,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, vk::Format::eD16Unorm );
vk::raii::DescriptorSetLayout descriptorSetLayout = vk::raii::su::makeDescriptorSetLayout(

View File

@@ -52,7 +52,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -65,7 +65,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -85,7 +85,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -96,7 +96,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -133,7 +133,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -172,7 +172,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -36,7 +36,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 640, 640 ) );
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( **surfaceData.pSurface );
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( *surfaceData.surface );
if ( !( surfaceCapabilities.supportedUsageFlags & vk::ImageUsageFlagBits::eTransferDst ) )
{
std::cout << "Surface cannot be destination of blit - abort \n";
@@ -44,7 +44,7 @@ int main( int /*argc*/, char ** /*argv*/ )
}
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -57,7 +57,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc |
@@ -79,7 +79,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -227,7 +227,7 @@ int main( int /*argc*/, char ** /*argv*/ )
;
/* Now present the image in the window */
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -43,7 +43,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -56,7 +56,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -83,7 +83,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -94,7 +94,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -133,7 +133,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -173,7 +173,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -47,7 +47,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -60,7 +60,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -71,7 +71,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -82,7 +82,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -160,7 +160,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -209,7 +209,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -55,7 +55,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -68,7 +68,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -84,7 +84,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -95,7 +95,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -136,7 +136,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo(
*textureData.sampler, **textureData.pImageData->pImageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
vk::WriteDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( *descriptorSet, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
@@ -164,7 +164,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -194,7 +194,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::submitAndWait( device, graphicsQueue, commandBuffer );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -52,7 +52,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 50, 50 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -101,27 +101,27 @@ int main( int /*argc*/, char ** /*argv*/ )
// bind memory
image.bindMemory( *imageMemory, 0 );
std::unique_ptr<vk::raii::Buffer> pTextureBuffer;
std::unique_ptr<vk::raii::DeviceMemory> pTextureBufferMemory;
vk::raii::Buffer textureBuffer = nullptr;
vk::raii::DeviceMemory textureBufferMemory = nullptr;
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 );
pTextureBuffer = vk::raii::su::make_unique<vk::raii::Buffer>( device, bufferCreateInfo );
textureBuffer = vk::raii::Buffer( device, bufferCreateInfo );
memoryRequirements = pTextureBuffer->getMemoryRequirements();
memoryRequirements = textureBuffer.getMemoryRequirements();
memoryTypeIndex =
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
memoryRequirements.memoryTypeBits,
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
// allocate memory
memoryAllocateInfo = vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
pTextureBufferMemory = vk::raii::su::make_unique<vk::raii::DeviceMemory>( device, memoryAllocateInfo );
memoryAllocateInfo = vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
textureBufferMemory = vk::raii::DeviceMemory( device, memoryAllocateInfo );
// bind memory
pTextureBuffer->bindMemory( **pTextureBufferMemory, 0 );
textureBuffer.bindMemory( *textureBufferMemory, 0 );
}
else
{
@@ -129,7 +129,7 @@ int main( int /*argc*/, char ** /*argv*/ )
image.getSubresourceLayout( vk::ImageSubresource( vk::ImageAspectFlagBits::eColor ) );
}
void * data = needsStaging ? pTextureBufferMemory->mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() )
void * data = needsStaging ? textureBufferMemory.mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() )
: imageMemory.mapMemory( 0, memoryRequirements.size, vk::MemoryMapFlags() );
// Checkerboard of 16x16 pixel squares
@@ -147,7 +147,7 @@ int main( int /*argc*/, char ** /*argv*/ )
}
}
needsStaging ? pTextureBufferMemory->unmapMemory() : imageMemory.unmapMemory();
needsStaging ? textureBufferMemory.unmapMemory() : imageMemory.unmapMemory();
commandBuffer.begin( vk::CommandBufferBeginInfo() );
if ( needsStaging )
@@ -161,7 +161,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ImageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 ),
vk::Offset3D( 0, 0, 0 ),
vk::Extent3D( surfaceData.extent, 1 ) );
commandBuffer.copyBufferToImage( **pTextureBuffer, *image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
commandBuffer.copyBufferToImage( *textureBuffer, *image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
// Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY
vk::raii::su::setImageLayout(
commandBuffer, *image, format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal );

View File

@@ -88,7 +88,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -101,7 +101,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -245,7 +245,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -275,7 +275,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::submitAndWait( device, graphicsQueue, commandBuffer );
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -112,7 +112,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -125,7 +125,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -146,7 +146,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -157,7 +157,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -198,7 +198,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// Populate with info about our uniform buffer
vk::DescriptorBufferInfo uniformBufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo textureImageInfo(
*textureData.sampler, **textureData.pImageData->pImageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
{ vk::WriteDescriptorSet( *descriptorSets[0], 0, 0, vk::DescriptorType::eUniformBuffer, {}, uniformBufferInfo ),
vk::WriteDescriptorSet(
@@ -228,7 +228,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -266,7 +266,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -50,7 +50,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -63,7 +63,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -83,7 +83,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -94,7 +94,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -132,7 +132,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -232,7 +232,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -84,7 +84,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -97,7 +97,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -124,7 +124,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -135,7 +135,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -316,7 +316,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -354,7 +354,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -51,7 +51,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -64,7 +64,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -91,7 +91,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -102,7 +102,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -252,7 +252,7 @@ void main()
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -290,7 +290,7 @@ void main()
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -93,7 +93,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -106,7 +106,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -122,7 +122,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -133,7 +133,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -201,7 +201,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -239,7 +239,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -77,7 +77,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device =
vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions );
@@ -91,7 +91,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -121,7 +121,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass =
vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
@@ -133,7 +133,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -160,7 +160,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -174,7 +174,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo(
*textureData.sampler, **textureData.pImageData->pImageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::WriteDescriptorSet writeDescriptorSets[2] = {
vk::WriteDescriptorSet( {}, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( {}, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
@@ -207,7 +207,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -81,18 +81,18 @@ static_assert( sizeof( GeometryInstanceData ) == 64, "GeometryInstanceData struc
struct AccelerationStructureData
{
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;
vk::raii::AccelerationStructureNV acclerationStructure = nullptr;
vk::raii::su::BufferData scratchBufferData = nullptr;
vk::raii::su::BufferData resultBufferData = nullptr;
vk::raii::su::BufferData instanceBufferData = nullptr;
};
AccelerationStructureData createAccelerationStructureData(
vk::raii::PhysicalDevice const & physicalDevice,
vk::raii::Device const & device,
vk::raii::CommandBuffer const & commandBuffer,
std::vector<std::pair<std::shared_ptr<vk::raii::AccelerationStructureNV>, glm::mat4x4>> const & instances,
std::vector<vk::GeometryNV> const & geometries )
vk::raii::PhysicalDevice const & physicalDevice,
vk::raii::Device const & device,
vk::raii::CommandBuffer const & commandBuffer,
std::vector<std::pair<vk::raii::AccelerationStructureNV &, glm::mat4x4 &>> const & instances,
std::vector<vk::GeometryNV> const & geometries )
{
assert( instances.empty() ^ geometries.empty() );
@@ -103,51 +103,48 @@ AccelerationStructureData createAccelerationStructureData(
vk::AccelerationStructureInfoNV accelerationStructureInfo(
accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
vk::AccelerationStructureCreateInfoNV accelerationStructureCreateInfoNV( 0, accelerationStructureInfo );
accelerationStructureData.pAcclerationStructure =
std::make_shared<vk::raii::AccelerationStructureNV>( device, accelerationStructureCreateInfoNV );
accelerationStructureData.acclerationStructure =
vk::raii::AccelerationStructureNV( device, accelerationStructureCreateInfoNV );
vk::AccelerationStructureMemoryRequirementsInfoNV objectRequirements(
vk::AccelerationStructureMemoryRequirementsTypeNV::eObject, **accelerationStructureData.pAcclerationStructure );
vk::AccelerationStructureMemoryRequirementsTypeNV::eObject, *accelerationStructureData.acclerationStructure );
vk::DeviceSize resultSizeInBytes =
device.getAccelerationStructureMemoryRequirementsNV( objectRequirements ).memoryRequirements.size;
assert( 0 < resultSizeInBytes );
accelerationStructureData.pResultBufferData =
vk::raii::su::make_unique<vk::raii::su::BufferData>( physicalDevice,
device,
resultSizeInBytes,
vk::BufferUsageFlagBits::eRayTracingNV,
vk::MemoryPropertyFlagBits::eDeviceLocal );
accelerationStructureData.resultBufferData = vk::raii::su::BufferData( physicalDevice,
device,
resultSizeInBytes,
vk::BufferUsageFlagBits::eRayTracingNV,
vk::MemoryPropertyFlagBits::eDeviceLocal );
vk::AccelerationStructureMemoryRequirementsInfoNV buildScratchRequirements(
vk::AccelerationStructureMemoryRequirementsTypeNV::eBuildScratch,
**accelerationStructureData.pAcclerationStructure );
vk::AccelerationStructureMemoryRequirementsTypeNV::eBuildScratch, *accelerationStructureData.acclerationStructure );
vk::AccelerationStructureMemoryRequirementsInfoNV updateScratchRequirements(
vk::AccelerationStructureMemoryRequirementsTypeNV::eUpdateScratch,
**accelerationStructureData.pAcclerationStructure );
*accelerationStructureData.acclerationStructure );
vk::DeviceSize scratchSizeInBytes = std::max(
device.getAccelerationStructureMemoryRequirementsNV( buildScratchRequirements ).memoryRequirements.size,
device.getAccelerationStructureMemoryRequirementsNV( updateScratchRequirements ).memoryRequirements.size );
assert( 0 < scratchSizeInBytes );
accelerationStructureData.pScratchBufferData =
vk::raii::su::make_unique<vk::raii::su::BufferData>( physicalDevice,
device,
scratchSizeInBytes,
vk::BufferUsageFlagBits::eRayTracingNV,
vk::MemoryPropertyFlagBits::eDeviceLocal );
accelerationStructureData.scratchBufferData = vk::raii::su::BufferData( physicalDevice,
device,
scratchSizeInBytes,
vk::BufferUsageFlagBits::eRayTracingNV,
vk::MemoryPropertyFlagBits::eDeviceLocal );
if ( !instances.empty() )
{
accelerationStructureData.pInstanceBufferData =
vk::raii::su::make_unique<vk::raii::su::BufferData>( physicalDevice,
device,
instances.size() * sizeof( GeometryInstanceData ),
vk::BufferUsageFlagBits::eRayTracingNV );
accelerationStructureData.instanceBufferData =
vk::raii::su::BufferData( physicalDevice,
device,
instances.size() * sizeof( GeometryInstanceData ),
vk::BufferUsageFlagBits::eRayTracingNV );
std::vector<GeometryInstanceData> geometryInstanceData;
for ( size_t i = 0; i < instances.size(); i++ )
{
uint64_t accelerationStructureHandle = instances[i].first->getHandle<uint64_t>();
uint64_t accelerationStructureHandle = instances[i].first.getHandle<uint64_t>();
// For each instance we set its instance index to its index i in the instance vector, and set
// its hit group index to 2*i. The hit group index defines which entry of the shader binding
@@ -161,16 +158,16 @@ AccelerationStructureData createAccelerationStructureData(
static_cast<uint8_t>( vk::GeometryInstanceFlagBitsNV::eTriangleCullDisable ),
accelerationStructureHandle );
}
accelerationStructureData.pInstanceBufferData->upload( geometryInstanceData );
accelerationStructureData.instanceBufferData.upload( geometryInstanceData );
}
device.bindAccelerationStructureMemoryNV( vk::BindAccelerationStructureMemoryInfoNV(
**accelerationStructureData.pAcclerationStructure, *accelerationStructureData.pResultBufferData->deviceMemory ) );
*accelerationStructureData.acclerationStructure, *accelerationStructureData.resultBufferData.deviceMemory ) );
vk::Buffer instanceData;
if ( accelerationStructureData.pInstanceBufferData )
if ( *accelerationStructureData.instanceBufferData.buffer )
{
instanceData = *accelerationStructureData.pInstanceBufferData->buffer;
instanceData = *accelerationStructureData.instanceBufferData.buffer;
}
vk::AccelerationStructureInfoNV accelerationStructureInfoNV(
accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
@@ -178,9 +175,9 @@ AccelerationStructureData createAccelerationStructureData(
instanceData,
0,
false,
**accelerationStructureData.pAcclerationStructure,
*accelerationStructureData.acclerationStructure,
nullptr,
*accelerationStructureData.pScratchBufferData->buffer,
*accelerationStructureData.scratchBufferData.buffer,
0 );
vk::MemoryBarrier memoryBarrier(
@@ -788,7 +785,7 @@ int main( int /*argc*/, char ** /*argv*/ )
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 );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, windowExtent );
bool samplerAnisotropy = !!supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features.samplerAnisotropy;
@@ -962,12 +959,12 @@ int main( int /*argc*/, char ** /*argv*/ )
{},
{ vk::GeometryNV( vk::GeometryTypeNV::eTriangles, geometryDataNV ) } );
topLevelAS =
createAccelerationStructureData( physicalDevice,
device,
commandBuffer,
{ std::make_pair( bottomLevelAS.pAcclerationStructure, transform ) },
std::vector<vk::GeometryNV>() );
topLevelAS = createAccelerationStructureData(
physicalDevice,
device,
commandBuffer,
{ std::make_pair( std::ref( bottomLevelAS.acclerationStructure ), std::ref( transform ) ) },
std::vector<vk::GeometryNV>() );
} );
// create raytracing descriptor set
@@ -1043,7 +1040,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// Bind ray tracing specific descriptor sets into pNext of a vk::WriteDescriptorSet
vk::WriteDescriptorSetAccelerationStructureNV writeDescriptorSetAcceleration( 1,
&**topLevelAS.pAcclerationStructure );
&*topLevelAS.acclerationStructure );
std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets;
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
{
@@ -1211,7 +1208,7 @@ int main( int /*argc*/, char ** /*argv*/ )
surface,
windowExtent,
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage,
&*swapChainData.pSwapChain,
&swapChainData.swapChain,
graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second );
depthBufferData = vk::raii::su::DepthBufferData(
@@ -1229,7 +1226,7 @@ int main( int /*argc*/, char ** /*argv*/ )
} );
framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, windowExtent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, windowExtent );
}
// update the uniformBufferObject
@@ -1245,7 +1242,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// frame begin
vk::Result result;
uint32_t backBufferIndex;
std::tie( result, backBufferIndex ) = swapChainData.pSwapChain->acquireNextImage(
std::tie( result, backBufferIndex ) = swapChainData.swapChain.acquireNextImage(
vk::su::FenceTimeout, *perFrameData[frameIndex].presentCompleteSemaphore );
assert( result == vk::Result::eSuccess );
@@ -1337,7 +1334,7 @@ int main( int /*argc*/, char ** /*argv*/ )
&*perFrameData[frameIndex].renderCompleteSemaphore );
graphicsQueue.submit( submitInfo, *perFrameData[frameIndex].fence );
vk::PresentInfoKHR presentInfoKHR(
*perFrameData[frameIndex].renderCompleteSemaphore, **swapChainData.pSwapChain, backBufferIndex );
*perFrameData[frameIndex].renderCompleteSemaphore, *swapChainData.swapChain, backBufferIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -53,7 +53,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -66,7 +66,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -88,7 +88,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device,
colorFormat,
depthBufferData.format,
@@ -103,7 +103,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -162,7 +162,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -239,7 +239,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, **swapChainData.pSwapChain, imageIndex, {} ) );
result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, imageIndex, {} ) );
switch ( result )
{
case vk::Result::eSuccess: break;

View File

@@ -81,7 +81,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -94,7 +94,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -110,7 +110,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::copyToDevice( uniformBufferData.deviceMemory, mvpcMatrix );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -121,7 +121,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -187,7 +187,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorBufferInfo bufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo imageInfo(
*textureData.sampler, **textureData.pImageData->pImageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::DescriptorImageInfo samplerInfo( *sampler, {}, {} );
std::array<vk::WriteDescriptorSet, 3> descriptorWrites = {
{ vk::WriteDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
@@ -218,7 +218,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -257,7 +257,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -102,7 +102,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DisplayNativeHdrSurfaceCapabilitiesAMD,
vk::SharedPresentSurfaceCapabilitiesKHR,
vk::SurfaceCapabilitiesFullScreenExclusiveEXT,
vk::SurfaceProtectedCapabilitiesKHR>( { **surfaceData.pSurface } );
vk::SurfaceProtectedCapabilitiesKHR>( { *surfaceData.surface } );
vk::SurfaceCapabilitiesKHR const & surfaceCapabilities =
surfaceCapabilities2.get<vk::SurfaceCapabilities2KHR>().surfaceCapabilities;
@@ -153,7 +153,7 @@ int main( int /*argc*/, char ** /*argv*/ )
else
{
vk::SurfaceCapabilitiesKHR surfaceCapabilities =
physicalDevices[i].getSurfaceCapabilitiesKHR( **surfaceData.pSurface );
physicalDevices[i].getSurfaceCapabilitiesKHR( *surfaceData.surface );
cout( surfaceCapabilities );
}
}

View File

@@ -48,7 +48,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{
std::cout << "PhysicalDevice " << i << "\n";
std::vector<vk::SurfaceFormatKHR> surfaceFormats =
physicalDevices[i].getSurfaceFormatsKHR( **surfaceData.pSurface );
physicalDevices[i].getSurfaceFormatsKHR( *surfaceData.surface );
for ( size_t j = 0; j < surfaceFormats.size(); j++ )
{
std::cout << "\tFormat " << j << "\n";

View File

@@ -43,7 +43,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -56,7 +56,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -83,7 +83,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );
glslang::InitializeProcess();
@@ -94,7 +94,7 @@ int main( int /*argc*/, char ** /*argv*/ )
glslang::FinalizeProcess();
std::vector<vk::raii::Framebuffer> framebuffers = vk::raii::su::makeFramebuffers(
device, renderPass, swapChainData.imageViews, &*depthBufferData.pImageView, surfaceData.extent );
device, renderPass, swapChainData.imageViews, &depthBufferData.imageView, surfaceData.extent );
vk::raii::su::BufferData vertexBufferData(
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
@@ -131,7 +131,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -169,7 +169,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -85,7 +85,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.pSurface );
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice(
physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
@@ -98,7 +98,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::SwapChainData swapChainData( physicalDevice,
device,
*surfaceData.pSurface,
surfaceData.surface,
surfaceData.extent,
vk::ImageUsageFlagBits::eColorAttachment |
vk::ImageUsageFlagBits::eTransferSrc,
@@ -118,7 +118,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );
vk::Format colorFormat =
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( **surfaceData.pSurface ) ).format;
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, vk::Format::eUndefined );
glslang::InitializeProcess();
@@ -163,7 +163,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) =
swapChainData.pSwapChain->acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );
@@ -201,7 +201,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;
vk::PresentInfoKHR presentInfoKHR( nullptr, **swapChainData.pSwapChain, imageIndex );
vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
result = presentQueue.presentKHR( presentInfoKHR );
switch ( result )
{

View File

@@ -217,6 +217,8 @@ namespace vk
buffer.bindMemory( *deviceMemory, 0 );
}
BufferData( std::nullptr_t ) {}
template <typename DataType>
void upload( DataType const & data ) const
{
@@ -270,8 +272,8 @@ namespace vk
}
// the order of buffer and deviceMemory here is important to get the constructor running !
vk::raii::Buffer buffer;
vk::raii::DeviceMemory deviceMemory;
vk::raii::Buffer buffer = nullptr;
vk::raii::DeviceMemory deviceMemory = nullptr;
#if !defined( NDEBUG )
private:
vk::DeviceSize m_size;
@@ -309,7 +311,7 @@ namespace vk
device, physicalDevice.getMemoryProperties(), image.getMemoryRequirements(), memoryProperties ) )
{
image.bindMemory( *deviceMemory, 0 );
pImageView = vk::raii::su::make_unique<vk::raii::ImageView>(
imageView = vk::raii::ImageView(
device,
vk::ImageViewCreateInfo(
{},
@@ -320,10 +322,12 @@ namespace vk
{ aspectMask, 0, 1, 0, 1 } ) );
}
vk::Format format;
vk::raii::Image image;
vk::raii::DeviceMemory deviceMemory;
std::unique_ptr<vk::raii::ImageView> pImageView;
ImageData( std::nullptr_t ) {}
vk::Format format;
vk::raii::Image image = nullptr;
vk::raii::DeviceMemory deviceMemory = nullptr;
vk::raii::ImageView imageView = nullptr;
};
struct DepthBufferData : public ImageData
@@ -354,12 +358,12 @@ namespace vk
glfwCreateWindowSurface( static_cast<VkInstance>( *instance ), window.handle, nullptr, &_surface );
if ( err != VK_SUCCESS )
throw std::runtime_error( "Failed to create window!" );
pSurface = vk::raii::su::make_unique<vk::raii::SurfaceKHR>( instance, _surface );
surface = vk::raii::SurfaceKHR( instance, _surface );
}
vk::Extent2D extent;
vk::su::WindowData window;
std::unique_ptr<vk::raii::SurfaceKHR> pSurface;
vk::Extent2D extent;
vk::su::WindowData window;
vk::raii::SurfaceKHR surface = nullptr;
};
struct SwapChainData
@@ -431,9 +435,9 @@ namespace vk
swapChainCreateInfo.queueFamilyIndexCount = 2;
swapChainCreateInfo.pQueueFamilyIndices = queueFamilyIndices;
}
pSwapChain = vk::raii::su::make_unique<vk::raii::SwapchainKHR>( device, swapChainCreateInfo );
swapChain = vk::raii::SwapchainKHR( device, swapChainCreateInfo );
images = pSwapChain->getImages();
images = swapChain.getImages();
imageViews.reserve( images.size() );
vk::ComponentMapping componentMapping(
@@ -451,10 +455,10 @@ namespace vk
}
}
vk::Format colorFormat;
std::unique_ptr<vk::raii::SwapchainKHR> pSwapChain;
std::vector<VkImage> images;
std::vector<vk::raii::ImageView> imageViews;
vk::Format colorFormat;
vk::raii::SwapchainKHR swapChain = nullptr;
std::vector<VkImage> images;
std::vector<vk::raii::ImageView> imageViews;
};
struct TextureData
@@ -484,7 +488,6 @@ namespace vk
0.0f,
0.0f,
vk::BorderColor::eFloatOpaqueBlack } )
{
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( format );
@@ -497,7 +500,7 @@ namespace vk
if ( needsStaging )
{
assert( ( formatProperties.optimalTilingFeatures & formatFeatureFlags ) == formatFeatureFlags );
pStagingBufferData = vk::raii::su::make_unique<BufferData>(
stagingBufferData = BufferData(
physicalDevice, device, extent.width * extent.height * 4, vk::BufferUsageFlagBits::eTransferSrc );
imageTiling = vk::ImageTiling::eOptimal;
usageFlags |= vk::ImageUsageFlagBits::eTransferDst;
@@ -509,15 +512,15 @@ namespace vk
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 );
imageData = ImageData( physicalDevice,
device,
format,
extent,
imageTiling,
usageFlags | vk::ImageUsageFlagBits::eSampled,
initialLayout,
requirements,
vk::ImageAspectFlagBits::eColor );
}
template <typename ImageGenerator>
@@ -525,17 +528,17 @@ namespace vk
{
void * data =
needsStaging
? pStagingBufferData->deviceMemory.mapMemory( 0, pStagingBufferData->buffer.getMemoryRequirements().size )
: pImageData->deviceMemory.mapMemory( 0, pImageData->image.getMemoryRequirements().size );
? stagingBufferData.deviceMemory.mapMemory( 0, stagingBufferData.buffer.getMemoryRequirements().size )
: imageData.deviceMemory.mapMemory( 0, imageData.image.getMemoryRequirements().size );
imageGenerator( data, extent );
needsStaging ? pStagingBufferData->deviceMemory.unmapMemory() : pImageData->deviceMemory.unmapMemory();
needsStaging ? stagingBufferData.deviceMemory.unmapMemory() : imageData.deviceMemory.unmapMemory();
if ( needsStaging )
{
// Since we're going to blit to the texture image, set its layout to eTransferDstOptimal
vk::raii::su::setImageLayout( commandBuffer,
*pImageData->image,
pImageData->format,
*imageData.image,
imageData.format,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eTransferDstOptimal );
vk::BufferImageCopy copyRegion( 0,
@@ -545,11 +548,11 @@ namespace vk
vk::Offset3D( 0, 0, 0 ),
vk::Extent3D( extent, 1 ) );
commandBuffer.copyBufferToImage(
*pStagingBufferData->buffer, *pImageData->image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
// Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY
*stagingBufferData.buffer, *imageData.image, vk::ImageLayout::eTransferDstOptimal, copyRegion );
// Set the layout for the texture image from eTransferDstOptimal to eShaderReadOnlyOptimal
vk::raii::su::setImageLayout( commandBuffer,
*pImageData->image,
pImageData->format,
*imageData.image,
imageData.format,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eShaderReadOnlyOptimal );
}
@@ -557,19 +560,19 @@ namespace vk
{
// If we can use the linear tiled image as a texture, just do it
vk::raii::su::setImageLayout( commandBuffer,
*pImageData->image,
pImageData->format,
*imageData.image,
imageData.format,
vk::ImageLayout::ePreinitialized,
vk::ImageLayout::eShaderReadOnlyOptimal );
}
}
vk::Format format;
vk::Extent2D extent;
bool needsStaging;
std::unique_ptr<BufferData> pStagingBufferData;
std::unique_ptr<ImageData> pImageData;
vk::raii::Sampler sampler;
vk::Format format;
vk::Extent2D extent;
bool needsStaging;
BufferData stagingBufferData = nullptr;
ImageData imageData = nullptr;
vk::raii::Sampler sampler;
};
std::pair<uint32_t, uint32_t>
@@ -957,7 +960,7 @@ namespace vk
}
vk::DescriptorImageInfo imageInfo(
*textureData.sampler, **textureData.pImageData->pImageView, vk::ImageLayout::eShaderReadOnlyOptimal );
*textureData.sampler, *textureData.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
writeDescriptorSets.emplace_back(
*descriptorSet, dstBinding, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo, nullptr, nullptr );
@@ -1002,8 +1005,7 @@ namespace vk
imageInfos.reserve( textureData.size() );
for ( auto const & thd : textureData )
{
imageInfos.emplace_back(
*thd.sampler, **thd.pImageData->pImageView, vk::ImageLayout::eShaderReadOnlyOptimal );
imageInfos.emplace_back( *thd.sampler, *thd.imageData.imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
}
writeDescriptorSets.emplace_back( *descriptorSet,
dstBinding,