Minor cleanup on fence and event handling in two RAII-samples. (#1859)

This commit is contained in:
Andreas Süßenbach 2024-05-02 09:37:29 +02:00 committed by GitHub
parent 48b5595082
commit 2d42465f64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 36 deletions

View File

@ -58,7 +58,7 @@ int main( int /*argc*/, char ** /*argv*/ )
int timeouts = -1; int timeouts = -1;
do do
{ {
result = device.waitForFences( { fence }, true, vk::su::FenceTimeout ); result = device.waitForFences( *fence, true, vk::su::FenceTimeout );
timeouts++; timeouts++;
} while ( result == vk::Result::eTimeout ); } while ( result == vk::Result::eTimeout );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
@ -75,16 +75,16 @@ int main( int /*argc*/, char ** /*argv*/ )
commandPool.reset(); commandPool.reset();
commandBuffer.begin( vk::CommandBufferBeginInfo() ); commandBuffer.begin( vk::CommandBufferBeginInfo() );
commandBuffer.waitEvents( { event }, vk::PipelineStageFlagBits::eHost, vk::PipelineStageFlagBits::eBottomOfPipe, nullptr, nullptr, nullptr ); commandBuffer.waitEvents( *event, vk::PipelineStageFlagBits::eHost, vk::PipelineStageFlagBits::eBottomOfPipe, nullptr, nullptr, nullptr );
commandBuffer.end(); commandBuffer.end();
device.resetFences( { fence } ); 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. // 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 // 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 // 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 ) if ( result != vk::Result::eTimeout )
{ {
std::cout << "Didn't get expected timeout in vk::Device::waitForFences, exiting\n"; std::cout << "Didn't get expected timeout in vk::Device::waitForFences, exiting\n";
@ -96,11 +96,11 @@ int main( int /*argc*/, char ** /*argv*/ )
event.set(); event.set();
do do
{ {
result = device.waitForFences( { fence }, true, vk::su::FenceTimeout ); result = device.waitForFences( *fence, true, vk::su::FenceTimeout );
} while ( result == vk::Result::eTimeout ); } while ( result == vk::Result::eTimeout );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
device.resetFences( { fence } ); device.resetFences( *fence );
event.reset(); event.reset();
// reset the command buffer by resetting the complete command pool // reset the command buffer by resetting the complete command pool
@ -116,7 +116,7 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( result == vk::Result::eEventReset ); assert( result == vk::Result::eEventReset );
// Send the command buffer and loop waiting for the event // Send the command buffer and loop waiting for the event
graphicsQueue.submit( submitInfo, fence ); graphicsQueue.submit( submitInfo, *fence );
int polls = 0; int polls = 0;
do do
@ -128,7 +128,7 @@ int main( int /*argc*/, char ** /*argv*/ )
do do
{ {
result = device.waitForFences( { fence }, true, vk::su::FenceTimeout ); result = device.waitForFences( *fence, true, vk::su::FenceTimeout );
} while ( result == vk::Result::eTimeout ); } while ( result == vk::Result::eTimeout );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );

View File

@ -1152,9 +1152,9 @@ int main( int /*argc*/, char ** /*argv*/ )
swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *perFrameData[frameIndex].presentCompleteSemaphore ); swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *perFrameData[frameIndex].presentCompleteSemaphore );
assert( result == vk::Result::eSuccess ); assert( result == vk::Result::eSuccess );
while ( vk::Result::eTimeout == device.waitForFences( { *perFrameData[frameIndex].fence }, VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device.waitForFences( *perFrameData[frameIndex].fence, VK_TRUE, vk::su::FenceTimeout ) )
; ;
device.resetFences( { *perFrameData[frameIndex].fence } ); device.resetFences( *perFrameData[frameIndex].fence );
// reset the command buffer by resetting the complete command pool of this frame // reset the command buffer by resetting the complete command pool of this frame
perFrameData[frameIndex].commandPool.reset(); perFrameData[frameIndex].commandPool.reset();

View File

@ -354,16 +354,18 @@ namespace vk
void * /*pUserData*/ ) void * /*pUserData*/ )
{ {
#if !defined( NDEBUG ) #if !defined( NDEBUG )
if ( static_cast<uint32_t>( pCallbackData->messageIdNumber ) == 0x822806fa ) switch ( static_cast<uint32_t>( pCallbackData->messageIdNumber ) )
{ {
// Validation Warning: vkCreateInstance(): to enable extension VK_EXT_debug_utils, but this extension is intended to support use by applications when case 0:
// debugging and it is strongly recommended that it be otherwise avoided. // Validation Warning: Override layer has override paths set to C:/VulkanSDK/<version>/Bin
return vk::False; return vk::False;
} case 0x822806fa:
else if ( static_cast<uint32_t>( pCallbackData->messageIdNumber ) == 0xe8d1a9fe ) // Validation Warning: vkCreateInstance(): to enable extension VK_EXT_debug_utils, but this extension is intended to support use by applications when
{ // debugging and it is strongly recommended that it be otherwise avoided.
// Validation Performance Warning: Using debug builds of the validation layers *will* adversely affect performance. return vk::False;
return vk::False; case 0xe8d1a9fe:
// Validation Performance Warning: Using debug builds of the validation layers *will* adversely affect performance.
return vk::False;
} }
#endif #endif
@ -824,21 +826,22 @@ namespace vk
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit ) ? vk::CompositeAlphaFlagBitsKHR::eInherit : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit ) ? vk::CompositeAlphaFlagBitsKHR::eInherit
: vk::CompositeAlphaFlagBitsKHR::eOpaque; : vk::CompositeAlphaFlagBitsKHR::eOpaque;
vk::PresentModeKHR presentMode = vk::su::pickPresentMode( physicalDevice.getSurfacePresentModesKHR( surface ) ); vk::PresentModeKHR presentMode = vk::su::pickPresentMode( physicalDevice.getSurfacePresentModesKHR( surface ) );
vk::SwapchainCreateInfoKHR swapChainCreateInfo( {}, vk::SwapchainCreateInfoKHR swapChainCreateInfo(
surface, {},
vk::su::clampSurfaceImageCount( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ), surface,
colorFormat, vk::su::clampSurfaceImageCount( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ),
surfaceFormat.colorSpace, colorFormat,
swapchainExtent, surfaceFormat.colorSpace,
1, swapchainExtent,
usage, 1,
vk::SharingMode::eExclusive, usage,
{}, vk::SharingMode::eExclusive,
preTransform, {},
compositeAlpha, preTransform,
presentMode, compositeAlpha,
true, presentMode,
oldSwapChain ); true,
oldSwapChain );
if ( graphicsQueueFamilyIndex != presentQueueFamilyIndex ) if ( graphicsQueueFamilyIndex != presentQueueFamilyIndex )
{ {
uint32_t queueFamilyIndices[2] = { graphicsQueueFamilyIndex, presentQueueFamilyIndex }; uint32_t queueFamilyIndices[2] = { graphicsQueueFamilyIndex, presentQueueFamilyIndex };

View File

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

View File

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