From 377e9a23a6de7c41c5446ee29627572e6d4ad7a9 Mon Sep 17 00:00:00 2001 From: Sylvain Doremus Date: Sat, 25 Feb 2023 13:41:24 +0100 Subject: [PATCH] Improved optional passes output image layouts handling. --- include/RenderGraph/FrameGraph.hpp | 3 +++ include/RenderGraph/RunnablePass.hpp | 5 +++++ source/RenderGraph/FrameGraph.cpp | 11 ++++++++++- source/RenderGraph/RunnableGraph.cpp | 16 ++++++++++++++++ source/RenderGraph/RunnablePass.cpp | 18 ++++++++++++------ .../RunnablePasses/RenderPassHolder.cpp | 6 +----- 6 files changed, 47 insertions(+), 12 deletions(-) diff --git a/include/RenderGraph/FrameGraph.hpp b/include/RenderGraph/FrameGraph.hpp index 32745fe..2fb5977 100644 --- a/include/RenderGraph/FrameGraph.hpp +++ b/include/RenderGraph/FrameGraph.hpp @@ -72,6 +72,9 @@ namespace crg * Getters. */ /**@{*/ + CRG_API LayoutState getFinalLayoutState( ImageId image + , VkImageViewType viewType + , VkImageSubresourceRange range )const; CRG_API LayoutState getFinalLayoutState( ImageViewId view )const; CRG_API AccessState getFinalAccessState( Buffer const & buffer )const; CRG_API void addInput( ImageId image diff --git a/include/RenderGraph/RunnablePass.hpp b/include/RenderGraph/RunnablePass.hpp index bc963ee..3517eb0 100644 --- a/include/RenderGraph/RunnablePass.hpp +++ b/include/RenderGraph/RunnablePass.hpp @@ -13,6 +13,11 @@ See LICENSE file in root folder. namespace crg { + CRG_API void checkUndefinedInput( std::string const & stepName + , Attachment const & attach + , ImageViewId const & view + , VkImageLayout currentLayout ); + template< typename StrongT, typename ValueT > struct GetValueCallbackT { diff --git a/source/RenderGraph/FrameGraph.cpp b/source/RenderGraph/FrameGraph.cpp index fcbdcec..68f2032 100644 --- a/source/RenderGraph/FrameGraph.cpp +++ b/source/RenderGraph/FrameGraph.cpp @@ -242,9 +242,18 @@ namespace crg , context ); } + LayoutState FrameGraph::getFinalLayoutState( ImageId image + , VkImageViewType viewType + , VkImageSubresourceRange range )const + { + return m_finalState.getLayoutState( image, viewType, range ); + } + LayoutState FrameGraph::getFinalLayoutState( ImageViewId view )const { - return m_finalState.getLayoutState( view ); + return getFinalLayoutState( view.data->image + , view.data->info.viewType + , view.data->info.subresourceRange ); } AccessState FrameGraph::getFinalAccessState( Buffer const & buffer )const diff --git a/source/RenderGraph/RunnableGraph.cpp b/source/RenderGraph/RunnableGraph.cpp index ed01bbb..4f777cf 100644 --- a/source/RenderGraph/RunnableGraph.cpp +++ b/source/RenderGraph/RunnableGraph.cpp @@ -358,6 +358,22 @@ namespace crg { // Lookup in graph's external inputs. result = m_graph.getInputLayoutState( image, viewType, range ); + + if ( result.layout != VK_IMAGE_LAYOUT_UNDEFINED ) + { + context.setLayoutState( image, viewType, range, result ); + } + } + + if ( result.layout == VK_IMAGE_LAYOUT_UNDEFINED ) + { + // Lookup in graph's previous final state. + result = m_graph.getFinalLayoutState( image, viewType, range ); + + if ( result.layout != VK_IMAGE_LAYOUT_UNDEFINED ) + { + context.setLayoutState( image, viewType, range, result ); + } } return result; diff --git a/source/RenderGraph/RunnablePass.cpp b/source/RenderGraph/RunnablePass.cpp index c0c113f..7bf584c 100644 --- a/source/RenderGraph/RunnablePass.cpp +++ b/source/RenderGraph/RunnablePass.cpp @@ -340,6 +340,17 @@ namespace crg } } + void checkUndefinedInput( std::string const & stepName + , Attachment const & attach + , ImageViewId const & view + , VkImageLayout currentLayout ) + { + if ( !attach.isTransitionView() && attach.isInput() && currentLayout == VK_IMAGE_LAYOUT_UNDEFINED ) + { + Logger::logWarning( stepName + " - [" + attach.pass->getFullName() + "]: Input view [" + view.data->name + "] is currently in undefined layout" ); + } + } + void RunnablePass::recordOne( CommandBuffer & enabled , uint32_t index , RecordContext & context ) @@ -400,12 +411,7 @@ namespace crg { auto needed = makeLayoutState( attach.getImageLayout( m_context.separateDepthStencilLayouts ) ); auto currentLayout = m_graph.getCurrentLayoutState( context, view ); - - if ( !( attach.isTransitionView() || !attach.isInput() || currentLayout.layout != VK_IMAGE_LAYOUT_UNDEFINED ) ) - { - Logger::logWarning( "Input view [" + view.data->name + "] is currently in undefined layout" ); - } - + checkUndefinedInput( "Record", attach, view, currentLayout.layout ); context.memoryBarrier( commandBuffer , view , currentLayout.layout diff --git a/source/RenderGraph/RunnablePasses/RenderPassHolder.cpp b/source/RenderGraph/RunnablePasses/RenderPassHolder.cpp index 5555bca..3ce1f14 100644 --- a/source/RenderGraph/RunnablePasses/RenderPassHolder.cpp +++ b/source/RenderGraph/RunnablePasses/RenderPassHolder.cpp @@ -222,11 +222,7 @@ namespace crg auto from = ( !attach.isInput() ? crg::makeLayoutState( VK_IMAGE_LAYOUT_UNDEFINED ) : currentLayout ); - - if ( !( !attach.isInput() || from.layout != VK_IMAGE_LAYOUT_UNDEFINED ) ) - { - Logger::logWarning( "Input image in undefined layout" ); - } + checkUndefinedInput( "RenderPass", attach, view, from.layout ); if ( attach.isDepthAttach() || attach.isStencilAttach() ) {