From 2d42465f64cdf7ff6ac1d5d4a1d090be914ffacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Thu, 2 May 2024 09:37:29 +0200 Subject: [PATCH] Minor cleanup on fence and event handling in two RAII-samples. (#1859) --- RAII_Samples/Events/Events.cpp | 16 ++++---- RAII_Samples/RayTracing/RayTracing.cpp | 4 +- samples/utils/utils.cpp | 51 ++++++++++++++------------ vulkan/vulkan.hpp | 2 +- vulkan/vulkansc.hpp | 2 +- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/RAII_Samples/Events/Events.cpp b/RAII_Samples/Events/Events.cpp index fbb153a..1b7f42b 100644 --- a/RAII_Samples/Events/Events.cpp +++ b/RAII_Samples/Events/Events.cpp @@ -58,7 +58,7 @@ int main( int /*argc*/, char ** /*argv*/ ) int timeouts = -1; do { - result = device.waitForFences( { fence }, true, vk::su::FenceTimeout ); + result = device.waitForFences( *fence, true, vk::su::FenceTimeout ); timeouts++; } while ( result == vk::Result::eTimeout ); assert( result == vk::Result::eSuccess ); @@ -75,16 +75,16 @@ int main( int /*argc*/, char ** /*argv*/ ) commandPool.reset(); 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(); - 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. // Execute the code from vk::Queue::submit() through vk::Device::setEvent() without breakpoints graphicsQueue.submit( submitInfo, fence ); // We should timeout waiting for the fence because the GPU should be waiting on the event - result = device.waitForFences( { fence }, true, vk::su::FenceTimeout ); + result = device.waitForFences( *fence, true, vk::su::FenceTimeout ); if ( result != vk::Result::eTimeout ) { std::cout << "Didn't get expected timeout in vk::Device::waitForFences, exiting\n"; @@ -96,11 +96,11 @@ int main( int /*argc*/, char ** /*argv*/ ) event.set(); do { - result = device.waitForFences( { fence }, true, vk::su::FenceTimeout ); + result = device.waitForFences( *fence, true, vk::su::FenceTimeout ); } while ( result == vk::Result::eTimeout ); assert( result == vk::Result::eSuccess ); - device.resetFences( { fence } ); + device.resetFences( *fence ); event.reset(); // 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 ); // Send the command buffer and loop waiting for the event - graphicsQueue.submit( submitInfo, fence ); + graphicsQueue.submit( submitInfo, *fence ); int polls = 0; do @@ -128,7 +128,7 @@ int main( int /*argc*/, char ** /*argv*/ ) do { - result = device.waitForFences( { fence }, true, vk::su::FenceTimeout ); + result = device.waitForFences( *fence, true, vk::su::FenceTimeout ); } while ( result == vk::Result::eTimeout ); assert( result == vk::Result::eSuccess ); diff --git a/RAII_Samples/RayTracing/RayTracing.cpp b/RAII_Samples/RayTracing/RayTracing.cpp index 839be10..f488476 100644 --- a/RAII_Samples/RayTracing/RayTracing.cpp +++ b/RAII_Samples/RayTracing/RayTracing.cpp @@ -1152,9 +1152,9 @@ int main( int /*argc*/, char ** /*argv*/ ) swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *perFrameData[frameIndex].presentCompleteSemaphore ); assert( result == vk::Result::eSuccess ); - while ( vk::Result::eTimeout == device.waitForFences( { *perFrameData[frameIndex].fence }, VK_TRUE, vk::su::FenceTimeout ) ) + 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 perFrameData[frameIndex].commandPool.reset(); diff --git a/samples/utils/utils.cpp b/samples/utils/utils.cpp index ff56e86..7a56644 100644 --- a/samples/utils/utils.cpp +++ b/samples/utils/utils.cpp @@ -354,16 +354,18 @@ namespace vk void * /*pUserData*/ ) { #if !defined( NDEBUG ) - if ( static_cast( pCallbackData->messageIdNumber ) == 0x822806fa ) + switch ( static_cast( pCallbackData->messageIdNumber ) ) { - // 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. - return vk::False; - } - else if ( static_cast( pCallbackData->messageIdNumber ) == 0xe8d1a9fe ) - { - // Validation Performance Warning: Using debug builds of the validation layers *will* adversely affect performance. - return vk::False; + case 0: + // Validation Warning: Override layer has override paths set to C:/VulkanSDK//Bin + return vk::False; + case 0x822806fa: + // 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. + return vk::False; + case 0xe8d1a9fe: + // Validation Performance Warning: Using debug builds of the validation layers *will* adversely affect performance. + return vk::False; } #endif @@ -824,21 +826,22 @@ namespace vk : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit ) ? vk::CompositeAlphaFlagBitsKHR::eInherit : vk::CompositeAlphaFlagBitsKHR::eOpaque; vk::PresentModeKHR presentMode = vk::su::pickPresentMode( physicalDevice.getSurfacePresentModesKHR( surface ) ); - vk::SwapchainCreateInfoKHR swapChainCreateInfo( {}, - surface, - vk::su::clampSurfaceImageCount( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ), - colorFormat, - surfaceFormat.colorSpace, - swapchainExtent, - 1, - usage, - vk::SharingMode::eExclusive, - {}, - preTransform, - compositeAlpha, - presentMode, - true, - oldSwapChain ); + vk::SwapchainCreateInfoKHR swapChainCreateInfo( + {}, + surface, + vk::su::clampSurfaceImageCount( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ), + colorFormat, + surfaceFormat.colorSpace, + swapchainExtent, + 1, + usage, + vk::SharingMode::eExclusive, + {}, + preTransform, + compositeAlpha, + presentMode, + true, + oldSwapChain ); if ( graphicsQueueFamilyIndex != presentQueueFamilyIndex ) { uint32_t queueFamilyIndices[2] = { graphicsQueueFamilyIndex, presentQueueFamilyIndex }; diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index eae7cc3..3618860 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -16709,7 +16709,7 @@ namespace VULKAN_HPP_NAMESPACE m_library = dlopen( "libvulkan.1.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 diff --git a/vulkan/vulkansc.hpp b/vulkan/vulkansc.hpp index fd53834..657c58c 100644 --- a/vulkan/vulkansc.hpp +++ b/vulkan/vulkansc.hpp @@ -6960,7 +6960,7 @@ namespace VULKAN_HPP_NAMESPACE m_library = dlopen( "libvulkan.1.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