Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/RenderGraph/RunnablePasses/ImageCopy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ namespace crg
, ru::Config ruConfig = {}
, GetPassIndexCallback passIndex = GetPassIndexCallback( [](){ return 0u; } )
, IsEnabledCallback isEnabled = IsEnabledCallback( [](){ return true; } ) );
CRG_API ImageCopy( FramePass const & pass
, GraphContext & context
, RunnableGraph & graph
, VkExtent3D copySize
, VkImageLayout finalOutputLayout
, ru::Config ruConfig = {}
, GetPassIndexCallback passIndex = GetPassIndexCallback( [](){ return 0u; } )
, IsEnabledCallback isEnabled = IsEnabledCallback( [](){ return true; } ) );

private:
void doInitialise();
Expand All @@ -27,5 +35,6 @@ namespace crg

private:
VkExtent3D m_copySize;
VkImageLayout m_finalOutputLayout;
};
}
77 changes: 59 additions & 18 deletions source/RenderGraph/RunnablePasses/ImageCopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace crg
, GraphContext & context
, RunnableGraph & graph
, VkExtent3D copySize
, VkImageLayout finalOutputLayout
, ru::Config ruConfig
, GetPassIndexCallback passIndex
, IsEnabledCallback isEnabled )
Expand All @@ -40,8 +41,28 @@ namespace crg
, isEnabled }
, std::move( ruConfig ) }
, m_copySize{std::move( copySize ) }
, m_finalOutputLayout{ finalOutputLayout }
{
assert( pass.images.size() == 2u );
assert( ( pass.images.size() % 2u ) == 0u );
}

ImageCopy::ImageCopy( FramePass const & pass
, GraphContext & context
, RunnableGraph & graph
, VkExtent3D copySize
, ru::Config ruConfig
, GetPassIndexCallback passIndex
, IsEnabledCallback isEnabled )
: ImageCopy{ pass
, context
, graph
, copySize
, VK_IMAGE_LAYOUT_UNDEFINED
, std::move( ruConfig )
, passIndex
, isEnabled }
{
assert( ( pass.images.size() % 2u ) == 0u );
}

void ImageCopy::doInitialise()
Expand All @@ -52,22 +73,42 @@ namespace crg
, VkCommandBuffer commandBuffer
, uint32_t index )
{
auto srcAttach{ m_pass.images.front().view( index ) };
auto dstAttach{ m_pass.images.back().view( index ) };
auto srcImage{ m_graph.createImage( srcAttach.data->image ) };
auto dstImage{ m_graph.createImage( dstAttach.data->image ) };
// Copy source to target.
VkImageCopy copyRegion{ imgCopy::convert( srcAttach.data->info.subresourceRange )
, {}
, imgCopy::convert( dstAttach.data->info.subresourceRange )
, {}
, m_copySize };
m_context.vkCmdCopyImage( commandBuffer
, srcImage
, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
, dstImage
, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
, 1u
, &copyRegion );
auto srcIt = m_pass.images.begin();
auto dstIt = std::next( srcIt );

while ( srcIt != m_pass.images.end() )
{
auto srcAttach{ srcIt->view( index ) };
auto dstAttach{ dstIt->view( index ) };
auto srcImage{ m_graph.createImage( srcAttach.data->image ) };
auto dstImage{ m_graph.createImage( dstAttach.data->image ) };
// Copy source to target.
VkImageCopy copyRegion{ imgCopy::convert( srcAttach.data->info.subresourceRange )
, {}
, imgCopy::convert( dstAttach.data->info.subresourceRange )
, {}
, m_copySize };
m_context.vkCmdCopyImage( commandBuffer
, srcImage
, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
, dstImage
, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
, 1u
, &copyRegion );

if ( m_finalOutputLayout != VK_IMAGE_LAYOUT_UNDEFINED )
{
context.memoryBarrier( commandBuffer
, dstAttach
, crg::makeLayoutState( m_finalOutputLayout ) );
}

srcIt = std::next( dstIt );

if ( srcIt != m_pass.images.end() )
{
dstIt = std::next( srcIt );
}
}
}
}