SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
spark::render::PushConstantsLayout< PushConstantsRangeType > Class Template Referenceabstract

Describes the layout of the pipelines push constant ranges. More...

#include <PushConstantsLayout.h>

Inheritance diagram for spark::render::PushConstantsLayout< PushConstantsRangeType >:
spark::render::IPushConstantsLayout

Public Types

using PushConstantsRange = PushConstantsRangeType
 

Public Member Functions

const PushConstantsRangeType & range (ShaderStage stage) const override=0
 Get the push constants range associated with the shader stage provided.
 
virtual std::vector< const PushConstantsRangeType * > ranges () const noexcept=0
 Get all push constants ranges .
 
- Public Member Functions inherited from spark::render::IPushConstantsLayout
virtual unsigned int size () const noexcept=0
 Get the size (in bytes) of the push constants backing memory.
 
std::vector< const IPushConstantsRange * > ranges () const noexcept
 Get all push constants ranges .
 

Detailed Description

template<typename PushConstantsRangeType>
class spark::render::PushConstantsLayout< PushConstantsRangeType >

Describes the layout of the pipelines push constant ranges.

Template Parameters
PushConstantsRangeTypeThe type of the push constant ranges (inherits from IPushConstantsRange).

Push constants are very efficient, yet quite limited ways of passing per-draw data to shaders. They are mapped directly, so no buffer must be created or transitioned in order to use them. Conceptually a push constant is a single piece of memory that gets transferred to a command buffer directly. Each shader stage has a view into this piece of memory, described by an offset and a size. Since the memory is directly dumped in the command buffer, the backing memory can be incrementally updated and there is no need to store an array of buffers, as long as updates happen sequentially from the same thread.

However, there are certain restrictions when using push constants:

  • Only one push constant layout per pipeline layout is supported.
  • A push constant layout may not define a overall memory size larger than 128 bytes. This is a soft restriction that will issue a warning, however it might be supported on some hardware or for some back-ends.
  • The elements and offsets of a push constant memory block must be aligned to 4 bytes.
  • Accordingly, the size of a push constant layout must align to 4 bytes.
  • Only one IPushConstantsRange per shader stage is permitted. Shader stages can be combined together, however in this case, no other ranges must be defined for the stages.

Push constants can be updated by calling ICommandBuffer::pushConstants() and are visible to subsequent draw calls immediately, until another update is performed or the command buffer is ended.

Member Function Documentation

◆ range()

template<typename PushConstantsRangeType >
const PushConstantsRangeType & spark::render::PushConstantsLayout< PushConstantsRangeType >::range ( ShaderStage stage) const
nodiscardoverridepure virtual

Get the push constants range associated with the shader stage provided.

Returns
The push constants range associated with the shader stage provided.
Exceptions
spark::base::ArgumentOutOfRangeExceptionif no range is mapped to the provided shader stage.
spark::base::BadArgumentExceptionif stage contains multiple shader stages.

Implements spark::render::IPushConstantsLayout.

Implemented in spark::render::vk::VulkanPushConstantsLayout.

◆ ranges()

template<typename PushConstantsRangeType >
virtual std::vector< const PushConstantsRangeType * > spark::render::PushConstantsLayout< PushConstantsRangeType >::ranges ( ) const
nodiscardpure virtualnoexcept