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

@ -53,7 +53,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( device, { {}, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandPool commandPool = vk::raii::CommandPool( device, { {}, graphicsAndPresentQueueFamilyIndex.first } );
vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool );
vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 );
@ -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

@ -144,15 +144,16 @@ int main( int /*argc*/, char ** /*argv*/ )
// Do a 32x32 blit to all of the dst image - should get big squares
vk::ImageSubresourceLayers imageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 );
vk::ImageBlit imageBlit( imageSubresourceLayers,
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 32, 32, 1 ) } },
{ { 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 ) } } );
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( surfaceData.extent.width, surfaceData.extent.height, 1 ) } } );
commandBuffer.blitImage(
blitSourceImage, vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageBlit, vk::Filter::eLinear );
// Use a barrier to make sure the blit is finished before the copy starts
// 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();

View File

@ -7048,7 +7048,7 @@ namespace VULKAN_HPP_NAMESPACE
# elif defined( __APPLE__ )
m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
# elif defined( _WIN32 )
m_library = ::LoadLibraryA( "vulkan-1.dll" );
m_library = ::LoadLibraryA( "vulkan-1.dll" );
# else
# error unsupported platform
# endif