Resolve some validation layer warnings in some samples. (#1640)

This commit is contained in:
Andreas Süßenbach 2023-08-17 14:28:39 +02:00 committed by GitHub
parent 57d54a0ba6
commit d07d082af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 11 deletions

View File

@ -116,6 +116,9 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer.end();
vk::raii::su::submitAndWait( device, graphicsQueue, commandBuffer );
// in order to prevent some validation layer warning, you need to explicitly free the buffer before the device memory
vertexBuffer.clear();
/* VULKAN_KEY_END */
}
catch ( vk::SystemError & err )

View File

@ -159,8 +159,9 @@ int main( int /*argc*/, char ** /*argv*/ )
*blitSourceImage, vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageBlit, vk::Filter::eLinear );
// Use a barrier to make sure the blit is finished before the copy starts
// Note: for a layout of vk::ImageLayout::eTransferDstOptimal, the access mask is supposed to be vk::AccessFlagBits::eTransferWrite
vk::ImageMemoryBarrier memoryBarrier( vk::AccessFlagBits::eTransferWrite,
vk::AccessFlagBits::eMemoryRead,
vk::AccessFlagBits::eTransferWrite,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eTransferDstOptimal,
VK_QUEUE_FAMILY_IGNORED,
@ -173,8 +174,9 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ImageCopy imageCopy( imageSubresourceLayers, vk::Offset3D(), imageSubresourceLayers, vk::Offset3D( 256, 256, 0 ), vk::Extent3D( 128, 128, 1 ) );
commandBuffer.copyImage( *blitSourceImage, vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageCopy );
// Note: for a layout of vk::ImageLayout::ePresentSrcKHR, the access mask is supposed to be empty
vk::ImageMemoryBarrier prePresentBarrier( vk::AccessFlagBits::eTransferWrite,
vk::AccessFlagBits::eMemoryRead,
{},
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::ePresentSrcKHR,
VK_QUEUE_FAMILY_IGNORED,
@ -204,6 +206,9 @@ int main( int /*argc*/, char ** /*argv*/ )
}
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
// in order to prevent some validation layer warning, you need to explicitly free the image before the device memory
blitSourceImage.clear();
/* VULKAN_KEY_END */
}
catch ( vk::SystemError & err )

View File

@ -183,6 +183,9 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ImageViewCreateInfo imageViewCreateInfo( {}, *image, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::raii::ImageView imageView( device, imageViewCreateInfo );
// in order to prevent some validation layer warning, you need to explicitly free the image before the device memory
image.clear();
/* VULKAN_KEY_END */
}
catch ( vk::SystemError & err )

View File

@ -549,6 +549,13 @@ namespace vk
return std::move( vk::raii::CommandBuffers( device, commandBufferAllocateInfo ).front() );
}
void fullPipelineBarrier( vk::raii::CommandBuffer const & commandBuffer )
{
vk::MemoryBarrier memoryBarrier( vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite,
vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite );
commandBuffer.pipelineBarrier( vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, memoryBarrier, nullptr, nullptr );
}
vk::raii::DescriptorPool makeDescriptorPool( vk::raii::Device const & device, std::vector<vk::DescriptorPoolSize> const & poolSizes )
{
assert( !poolSizes.empty() );

View File

@ -104,8 +104,8 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
device.destroySemaphore( imageAcquiredSemaphore );
device.destroyBuffer( vertexBuffer ); // destroy the buffer before the bound device memory to prevent some validation layer warning
device.freeMemory( deviceMemory );
device.destroyBuffer( vertexBuffer );
/* VULKAN_KEY_END */

View File

@ -151,8 +151,9 @@ int main( int /*argc*/, char ** /*argv*/ )
blitSourceImage, vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageBlit, vk::Filter::eLinear );
// Use a barrier to make sure the blit is finished before the copy starts
// Note: for a layout of vk::ImageLayout::eTransferDstOptimal, the access mask is supposed to be vk::AccessFlagBits::eTransferWrite
vk::ImageMemoryBarrier memoryBarrier( vk::AccessFlagBits::eTransferWrite,
vk::AccessFlagBits::eMemoryRead,
vk::AccessFlagBits::eTransferWrite,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eTransferDstOptimal,
VK_QUEUE_FAMILY_IGNORED,
@ -166,8 +167,9 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ImageCopy imageCopy( imageSubresourceLayers, vk::Offset3D(), imageSubresourceLayers, vk::Offset3D( 256, 256, 0 ), vk::Extent3D( 128, 128, 1 ) );
commandBuffer.copyImage( blitSourceImage, vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageCopy );
// Note: for a layout of vk::ImageLayout::ePresentSrcKHR, the access mask is supposed to be empty
vk::ImageMemoryBarrier prePresentBarrier( vk::AccessFlagBits::eTransferWrite,
vk::AccessFlagBits::eMemoryRead,
{},
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::ePresentSrcKHR,
VK_QUEUE_FAMILY_IGNORED,
@ -200,8 +202,8 @@ int main( int /*argc*/, char ** /*argv*/ )
device.destroyFence( drawFence );
device.destroyFence( commandFence );
device.destroyImage( blitSourceImage ); // destroy the image before the bound device memory to prevent some validation layer warning
device.freeMemory( deviceMemory );
device.destroyImage( blitSourceImage );
device.destroySemaphore( imageAcquiredSemaphore );
swapChainData.clear( device );
device.freeCommandBuffers( commandPool, commandBuffer );

View File

@ -186,8 +186,8 @@ int main( int /*argc*/, char ** /*argv*/ )
device.destroySampler( sampler );
device.freeMemory( textureBufferMemory );
device.destroyBuffer( textureBuffer );
device.destroyImage( image ); // destroy the image before the bound device memory to prevent some validation layer warning
device.freeMemory( imageMemory );
device.destroyImage( image );
device.freeCommandBuffers( commandPool, commandBuffer );
device.destroyCommandPool( commandPool );
device.destroy();