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
26 changes: 25 additions & 1 deletion include/RenderGraph/FrameGraphPrerequisites.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,21 @@ namespace crg
VkDeviceMemory memory;
};

using IndexBufferPtr = std::unique_ptr< IndexBuffer >;
struct IndirectBuffer
{
explicit IndirectBuffer( Buffer pbuffer
, uint32_t pstride
, VkDeviceSize poffset = {} )
: buffer{ std::move( pbuffer ) }
, offset{ poffset }
, stride{ pstride }
{
}

Buffer buffer;
VkDeviceSize offset;
uint32_t stride;
};

static constexpr VkPipelineColorBlendAttachmentState DefaultBlendState{ VK_FALSE
, VK_BLEND_FACTOR_ONE
Expand Down Expand Up @@ -383,6 +397,16 @@ namespace crg
}
};

template<>
struct DefaultValueGetterT< IndirectBuffer >
{
static IndirectBuffer get()
{
IndirectBuffer const result{ Buffer{ VkBuffer{}, std::string{} }, 0u };
return result;
}
};

template< typename TypeT >
struct RawTyperT
{
Expand Down
3 changes: 3 additions & 0 deletions include/RenderGraph/GraphContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,11 @@ namespace crg
DECL_vkFunction( CmdClearColorImage );
DECL_vkFunction( CmdClearDepthStencilImage );
DECL_vkFunction( CmdDispatch );
DECL_vkFunction( CmdDispatchIndirect );
DECL_vkFunction( CmdDraw );
DECL_vkFunction( CmdDrawIndexed );
DECL_vkFunction( CmdDrawIndexedIndirect );
DECL_vkFunction( CmdDrawIndirect );
DECL_vkFunction( CmdBeginRenderPass );
DECL_vkFunction( CmdEndRenderPass );
DECL_vkFunction( CmdPushConstants );
Expand Down
11 changes: 11 additions & 0 deletions include/RenderGraph/RunnablePasses/ComputePass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ namespace crg
m_groupCountZ = config;
return *this;
}
/**
*\param[in] config
* The buffer used during indirect compute.
*/
auto & indirectBuffer( IndirectBuffer config )
{
m_indirectBuffer = config;
return *this;
}

pp::ConfigT< WrapperT > m_baseConfig{};
WrapperT< RunnablePass::InitialiseCallback > m_initialise{};
Expand All @@ -171,6 +180,7 @@ namespace crg
WrapperT< uint32_t > m_groupCountX{};
WrapperT< uint32_t > m_groupCountY{};
WrapperT< uint32_t > m_groupCountZ{};
WrapperT< IndirectBuffer > m_indirectBuffer{};
};

template<>
Expand All @@ -185,6 +195,7 @@ namespace crg
RawTypeT< uint32_t > groupCountX{ 1u };
RawTypeT< uint32_t > groupCountY{ 1u };
RawTypeT< uint32_t > groupCountZ{ 1u };
RawTypeT< IndirectBuffer > indirectBuffer{ defaultV< IndirectBuffer > };
};

using Config = ConfigT< std::optional >;
Expand Down
11 changes: 11 additions & 0 deletions include/RenderGraph/RunnablePasses/RenderMeshConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ namespace crg
}
/**
*\param[in] config
* The indirect buffer.
*/
auto & indirectBuffer( IndirectBuffer config )
{
m_indirectBuffer = config;
return *this;
}
/**
*\param[in] config
* The primitive count retrieval callback.
*/
auto & getPrimitiveCount( GetPrimitiveCountCallback config )
Expand Down Expand Up @@ -218,6 +227,7 @@ namespace crg
WrapperT< VkExtent2D > m_renderSize{};
WrapperT< VertexBuffer > m_vertexBuffer{};
WrapperT< IndexBuffer > m_indexBuffer{};
WrapperT< IndirectBuffer > m_indirectBuffer{};
};

template<>
Expand All @@ -235,6 +245,7 @@ namespace crg
RawTypeT< GetCullModeCallback > getCullMode{};
RawTypeT< VertexBuffer > vertexBuffer{};
RawTypeT< IndexBuffer > indexBuffer{};
RawTypeT< IndirectBuffer > indirectBuffer{ defaultV< IndirectBuffer > };
};

using Config = ConfigT< std::optional >;
Expand Down
11 changes: 11 additions & 0 deletions include/RenderGraph/RunnablePasses/RenderQuadConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ namespace crg
m_instances = config;
return *this;
}
/**
*\param[in] config
* The indirect buffer.
*/
auto & indirectBuffer( IndirectBuffer config )
{
m_indirectBuffer = config;
return *this;
}

pp::ConfigT< WrapperT > m_baseConfig{};
WrapperT< Texcoord > m_texcoordConfig{};
Expand All @@ -170,6 +179,7 @@ namespace crg
WrapperT< RunnablePass::RecordCallback > m_end{};
WrapperT< uint32_t > m_instances{};
WrapperT< VkExtent2D > m_renderSize{};
WrapperT< IndirectBuffer > m_indirectBuffer{};
};

template<>
Expand All @@ -184,6 +194,7 @@ namespace crg
RawTypeT< RunnablePass::RecordCallback > recordInto;
RawTypeT< RunnablePass::RecordCallback > end;
RawTypeT< uint32_t > m_instances;
RawTypeT< IndirectBuffer > indirectBuffer{ Buffer{ VkBuffer{}, std::string{} }, 0u };
};

using Config = ConfigT< std::optional >;
Expand Down
3 changes: 3 additions & 0 deletions source/RenderGraph/GraphContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ namespace crg
DECL_vkFunction( CmdClearColorImage );
DECL_vkFunction( CmdClearDepthStencilImage );
DECL_vkFunction( CmdDispatch );
DECL_vkFunction( CmdDispatchIndirect );
DECL_vkFunction( CmdDraw );
DECL_vkFunction( CmdDrawIndexed );
DECL_vkFunction( CmdDrawIndexedIndirect );
DECL_vkFunction( CmdDrawIndirect );
DECL_vkFunction( CmdBeginRenderPass );
DECL_vkFunction( CmdEndRenderPass );
DECL_vkFunction( CmdPushConstants );
Expand Down
14 changes: 12 additions & 2 deletions source/RenderGraph/RunnablePasses/ComputePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace crg
, cpConfig.m_end ? std::move( *cpConfig.m_end ) : getDefaultV< RunnablePass::RecordCallback >()
, cpConfig.m_groupCountX ? std::move( *cpConfig.m_groupCountX ) : 1u
, cpConfig.m_groupCountY ? std::move( *cpConfig.m_groupCountY ) : 1u
, cpConfig.m_groupCountZ ? std::move( *cpConfig.m_groupCountZ ) : 1u }
, cpConfig.m_groupCountZ ? std::move( *cpConfig.m_groupCountZ ) : 1u
, cpConfig.m_indirectBuffer ? *cpConfig.m_indirectBuffer : getDefaultV < IndirectBuffer >() }
, m_pipeline{ pass
, context
, graph
Expand Down Expand Up @@ -80,7 +81,16 @@ namespace crg
{
m_pipeline.recordInto( context, commandBuffer, index );
m_cpConfig.recordInto( context, commandBuffer, index );
m_context.vkCmdDispatch( commandBuffer, m_cpConfig.groupCountX, m_cpConfig.groupCountY, m_cpConfig.groupCountZ );

if ( auto indirectBuffer = m_cpConfig.indirectBuffer.buffer.buffer( index ) )
{
m_context.vkCmdDispatchIndirect( commandBuffer, indirectBuffer, m_cpConfig.indirectBuffer.offset );
}
else
{
m_context.vkCmdDispatch( commandBuffer, m_cpConfig.groupCountX, m_cpConfig.groupCountY, m_cpConfig.groupCountZ );
}

m_cpConfig.end( context, commandBuffer, index );
}

Expand Down
19 changes: 16 additions & 3 deletions source/RenderGraph/RunnablePasses/RenderMeshHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace crg
, config.m_getIndexType ? std::move( *config.m_getIndexType ) : getDefaultV< GetIndexTypeCallback >()
, config.m_getCullMode ? std::move( *config.m_getCullMode ) : getDefaultV< GetCullModeCallback >()
, config.m_vertexBuffer ? std::move( *config.m_vertexBuffer ) : getDefaultV< VertexBuffer >()
, config.m_indexBuffer ? std::move( *config.m_indexBuffer ) : getDefaultV< IndexBuffer >() }
, config.m_indexBuffer ? std::move( *config.m_indexBuffer ) : getDefaultV< IndexBuffer >()
, config.m_indirectBuffer ? *config.m_indirectBuffer : getDefaultV< IndirectBuffer >() }
, m_context{ context }
, m_pipeline{ pass
, context
Expand Down Expand Up @@ -114,9 +115,21 @@ namespace crg
m_context.vkCmdBindVertexBuffers( commandBuffer, 0u, 1u, &m_config.vertexBuffer.buffer.buffer( index ), &offset );
}

if ( m_config.indexBuffer.buffer.buffer( index ) )
if ( auto indirectBuffer = m_config.indirectBuffer.buffer.buffer( index ) )
{
m_context.vkCmdBindIndexBuffer( commandBuffer, m_config.indexBuffer.buffer.buffer( index ), offset, m_config.getIndexType() );
if ( auto indexBuffer = m_config.indexBuffer.buffer.buffer( index ) )
{
m_context.vkCmdBindIndexBuffer( commandBuffer, indexBuffer, offset, m_config.getIndexType() );
m_context.vkCmdDrawIndexedIndirect( commandBuffer, indirectBuffer, m_config.indirectBuffer.offset, 1u, m_config.indirectBuffer.stride );
}
else
{
m_context.vkCmdDrawIndirect( commandBuffer, indirectBuffer, m_config.indirectBuffer.offset, 1u, m_config.indirectBuffer.stride );
}
}
else if ( auto indexBuffer = m_config.indexBuffer.buffer.buffer( index ) )
{
m_context.vkCmdBindIndexBuffer( commandBuffer, indexBuffer, offset, m_config.getIndexType() );
m_context.vkCmdDrawIndexed( commandBuffer, m_config.getPrimitiveCount(), 1u, 0u, 0u, 0u );
}
else
Expand Down
13 changes: 11 additions & 2 deletions source/RenderGraph/RunnablePasses/RenderQuadHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace crg
, config.m_isEnabled
, config.m_recordInto ? std::move( *config.m_recordInto ) : getDefaultV< RunnablePass::RecordCallback >()
, config.m_end ? std::move( *config.m_end ) : getDefaultV< RunnablePass::RecordCallback >()
, config.m_instances ? std::move( *config.m_instances ) : 1u }
, config.m_instances ? std::move( *config.m_instances ) : 1u
, config.m_indirectBuffer ? *config.m_indirectBuffer : getDefaultV < IndirectBuffer >() }
, m_context{ context }
, m_graph{ graph }
, m_pipeline{ pass
Expand Down Expand Up @@ -110,7 +111,15 @@ namespace crg
m_config.recordInto( context, commandBuffer, index );
VkDeviceSize offset{};
m_context.vkCmdBindVertexBuffers( commandBuffer, 0u, 1u, &m_vertexBuffer->buffer.buffer( index ), &offset );
m_context.vkCmdDraw( commandBuffer, 3u, m_config.m_instances, 0u, 0u );

if ( auto indirectBuffer = m_config.indirectBuffer.buffer.buffer( index ) )
{
m_context.vkCmdDrawIndirect( commandBuffer, indirectBuffer, m_config.indirectBuffer.offset, 1u, m_config.indirectBuffer.stride );
}
else
{
m_context.vkCmdDraw( commandBuffer, 3u, m_config.m_instances, 0u, 0u );
}
}

void RenderQuadHolder::end( RecordContext & context
Expand Down