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
13 changes: 13 additions & 0 deletions include/RenderGraph/Attachment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ namespace crg
Uniform = 0x01 << 0,
Storage = 0x01 << 1,
View = 0x01 << 2,
Clearable = 0x01 << 4,
UniformView = Uniform | View,
StorageView = Storage | View,
};
Expand Down Expand Up @@ -274,6 +275,11 @@ namespace crg
return hasFlag( Flag::View );
}

bool isClearable()const
{
return hasFlag( Flag::Clearable );
}

bool isUniformView()const
{
return isUniform() && isView();
Expand Down Expand Up @@ -402,6 +408,13 @@ namespace crg
return isBuffer() && buffer.isStorage();
}

bool isClearableBuffer()const
{
return isBuffer()
&& isOutput()
&& buffer.isClearable();
}

bool isStorageBufferView()const
{
return isBuffer() && buffer.isStorageView();
Expand Down
8 changes: 8 additions & 0 deletions include/RenderGraph/FramePass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ namespace crg
, VkDeviceSize range );
/**
*\brief
* Creates a storage buffer attachment that will be cleared a the beginning of the pass.
*/
CRG_API void addClearableOutputStorageBuffer( Buffer buffer
, uint32_t binding
, VkDeviceSize offset
, VkDeviceSize range );
/**
*\brief
* Creates a storage buffer attachment.
*/
CRG_API void addInOutStorageBuffer( Buffer buffer
Expand Down
17 changes: 17 additions & 0 deletions source/RenderGraph/FramePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,23 @@ namespace crg
, range } );
}

void FramePass::addClearableOutputStorageBuffer( Buffer buffer
, uint32_t binding
, VkDeviceSize offset
, VkDeviceSize range )
{
auto attachName = fpass::adjustName( *this, buffer.name ) + "OSB";
buffers.push_back( Attachment{ Attachment::FlagKind( Attachment::Flag::Output )
, *this
, binding
, std::move( attachName )
, ( BufferAttachment::FlagKind( BufferAttachment::Flag::Storage )
| BufferAttachment::FlagKind( BufferAttachment::Flag::Clearable ) )
, buffer
, offset
, range } );
}

void FramePass::addInOutStorageBuffer( Buffer buffer
, uint32_t binding
, VkDeviceSize offset
Expand Down
29 changes: 29 additions & 0 deletions source/RenderGraph/RunnablePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ See LICENSE file in root folder.

namespace crg
{
namespace details
{
static constexpr VkDeviceSize getAlignedSize( VkDeviceSize size, VkDeviceSize align )
{
auto rem = size % align;
return ( rem
? size + ( align - rem )
: size );
}
}

//*********************************************************************************************

void convert( SemaphoreWaitArray const & toWait
Expand Down Expand Up @@ -429,6 +440,24 @@ namespace crg
auto buffer = attach.buffer;
auto currentState = context.getAccessState( buffer.buffer.buffer
, buffer.range );

if ( attach.isClearableBuffer() )
{
context.memoryBarrier( commandBuffer
, buffer.buffer.buffer
, buffer.range
, currentState.access
, currentState.pipelineStage
, { VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT } );
m_context.vkCmdFillBuffer( commandBuffer
, buffer.buffer.buffer
, buffer.range.offset == 0u ? 0u : details::getAlignedSize( buffer.range.offset, 4u )
, buffer.range.size == VK_WHOLE_SIZE ? VK_WHOLE_SIZE : details::getAlignedSize( buffer.range.size, 4u )
, 0u );
currentState.access = VK_ACCESS_TRANSFER_WRITE_BIT;
currentState.pipelineStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
}

context.memoryBarrier( commandBuffer
, buffer.buffer.buffer
, buffer.range
Expand Down