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

Describes the layout of a descriptor set. More...

#include <DescriptorSet.h>

Inheritance diagram for spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >:
spark::render::IDescriptorSetLayout

Public Types

using descriptor_layout_type = DescriptorLayoutType
 
using descriptor_set_type = DescriptorSetType
 

Public Member Functions

virtual std::vector< const descriptor_layout_type * > descriptors () const noexcept=0
 Gets the layouts of all descriptors in the IDescriptorSet.
 
const descriptor_layout_type * descriptor (unsigned binding) const override=0
 Gets the layout of a descriptor in the IDescriptorSet bound to a specific binding point.
 
virtual std::unique_ptr< descriptor_set_type > allocate (const std::vector< DescriptorBinding > &bindings={}) const =0
 Allocates a new IDescriptorSet or returns an unused descriptor set.
 
virtual std::unique_ptr< descriptor_set_type > allocate (unsigned descriptors, const std::vector< DescriptorBinding > &bindings={ }) const =0
 Allocates a new IDescriptorSet or returns an unused descriptor set.
 
virtual std::vector< std::unique_ptr< descriptor_set_type > > allocateMultiple (unsigned descriptor_sets, const std::vector< std::vector< DescriptorBinding > > &bindings={ }) const =0
 Allocates an array of IDescriptorSet.
 
virtual std::vector< std::unique_ptr< descriptor_set_type > > allocateMultiple (unsigned descriptor_sets, const std::function< std::vector< DescriptorBinding >(unsigned)> &binding_factory) const =0
 Allocates an array of IDescriptorSet.
 
virtual std::vector< std::unique_ptr< descriptor_set_type > > allocateMultiple (unsigned descriptor_sets, unsigned descriptors, const std::vector< std::vector< DescriptorBinding > > &bindings={ }) const =0
 Allocates an array of IDescriptorSet.
 
virtual std::vector< std::unique_ptr< descriptor_set_type > > allocateMultiple (unsigned descriptor_sets, unsigned descriptors, const std::function< std::vector< DescriptorBinding >(unsigned)> &binding_factory) const =0
 Allocates an array of IDescriptorSet.
 
virtual void free (const descriptor_set_type &descriptor_set) const noexcept=0
 Marks a IDescriptorSet as unused, so that it can be handed out again instead of allocating a new one.
 
- Public Member Functions inherited from spark::render::IDescriptorSetLayout
std::vector< const IDescriptorLayout * > descriptors () const noexcept
 Gets the layouts of all descriptors in the IDescriptorSet.
 
virtual const IDescriptorLayoutdescriptor (unsigned int binding) const =0
 Gets the layout of a descriptor in the IDescriptorSet bound to a specific binding point.
 
virtual unsigned int space () const noexcept=0
 Gets the space index of the IDescriptorSet.
 
virtual ShaderStage shaderStage () const noexcept=0
 Gets the shader stage the IDescriptorSet is used in.
 
virtual unsigned int uniforms () const noexcept=0
 Gets the number of uniform/constant buffers in the IDescriptorSet.
 
virtual unsigned int storages () const noexcept=0
 Gets the number of storage buffers in the IDescriptorSet.
 
virtual unsigned int images () const noexcept=0
 Gets the number of images (textures) in the IDescriptorSet.
 
virtual unsigned int buffers () const noexcept=0
 Get the number of texel buffer descriptors in the IDescriptorSet.
 
virtual unsigned int samplers () const noexcept=0
 Gets the number of texel buffer descriptors in the IDescriptorSet.
 
virtual unsigned int staticSamplers () const noexcept=0
 Gets the number of static/immutable samplers in the IDescriptorSet.
 
virtual unsigned int inputAttachments () const noexcept=0
 Gets the number of input attachments in the IDescriptorSet.
 
std::unique_ptr< IDescriptorSetallocate (const std::vector< DescriptorBinding > &bindings={}) const
 Allocates a new IDescriptorSet or returns an unused descriptor set.
 
std::unique_ptr< IDescriptorSetallocate (unsigned int descriptors, const std::vector< DescriptorBinding > &bindings={}) const
 Allocates a new IDescriptorSet or returns an unused descriptor set.
 
std::vector< std::unique_ptr< IDescriptorSet > > allocateMultiple (unsigned int descriptors_sets, const std::vector< std::vector< DescriptorBinding > > &bindings={}) const noexcept
 Allocates an array of IDescriptorSet.
 
std::vector< std::unique_ptr< IDescriptorSet > > allocateMultiple (unsigned int descriptors_sets, const std::function< std::vector< DescriptorBinding >(unsigned)> &binding_factory) const noexcept
 Allocates an array of IDescriptorSet.
 
std::vector< std::unique_ptr< IDescriptorSet > > allocateMultiple (unsigned int descriptors_sets, unsigned int descriptors, const std::vector< std::vector< DescriptorBinding > > &bindings={}) const noexcept
 Allocates an array of IDescriptorSet.
 
std::vector< std::unique_ptr< IDescriptorSet > > allocateMultiple (unsigned int descriptors_sets, unsigned int descriptors, const std::function< std::vector< DescriptorBinding >(unsigned)> &binding_factory={}) const noexcept
 Allocates an array of IDescriptorSet.
 
void free (const IDescriptorSet &descriptor_set) const noexcept
 Marks a IDescriptorSet as unused, so that it can be handed out again instead of allocating a new one.
 

Detailed Description

template<typename DescriptorLayoutType, typename DescriptorSetType>
class spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >

Describes the layout of a descriptor set.

Template Parameters
DescriptorLayoutTypeType of the descriptor layout. (inherits from IDescriptorLayout)
DescriptorSetTypeType of the descriptor set. (inherits from IDescriptorSet)

Member Function Documentation

◆ allocate() [1/2]

template<typename DescriptorLayoutType , typename DescriptorSetType >
virtual std::unique_ptr< descriptor_set_type > spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >::allocate ( const std::vector< DescriptorBinding > & bindings = {}) const
nodiscardpure virtual

Allocates a new IDescriptorSet or returns an unused descriptor set.

Parameters
bindingsOptional list of descriptor bindings to initialize the IDescriptorSet with.
Returns
A std::unique_ptr to the allocated IDescriptorSet.

Allocating a new descriptor set may be an expensive operation. To improve performance, and prevent fragmentation, the descriptor set layout keeps track of created descriptor sets. It does this by never releasing them. Instead, when a IDescriptorSet instance gets destroyed, it should call IDescriptorSetLayout::free() in order to mark itself (i.e. its handle) as not being used any longer.

Before allocating a new descriptor set from a pool (which may even result in the creation of a new pool, if the existing pools are full), the layout tries to hand out descriptor sets that marked as unused. Descriptor sets are only deleted, if the whole layout instance and therefore the descriptor pools are deleted. ( The above does not apply to unbounded descriptor arrays. A unbounded descriptor array is one, for which IDescriptorLayout::descriptors() returns -1 (or 0xFFFFFFFF). They must be allocated by specifying the descriptors parameter. This parameter defines the number of descriptors to allocate in the array.

Note that descriptor sets, that contain an unbounded descriptor array must only contain one single descriptor (the one that identifies this array). Such descriptor sets are never cached. Instead, they are released when calling IDescriptorSetLayout::free(). It is a good practice to cache such descriptor sets as global descriptor tables once and never release them. They provide more flexibility than regular descriptor arrays, since they may be updated, even after they have been bound to a command buffer or from different threads. However, you must ensure yourself not to overwrite any descriptors that are currently in use. Because unbounded arrays are not cached, freeing and re-allocating such descriptor sets may leave the descriptor heap fragmented, which might cause the allocation to fail, if the heap is full.

Implemented in spark::render::vk::VulkanDescriptorSetLayout.

◆ allocate() [2/2]

template<typename DescriptorLayoutType , typename DescriptorSetType >
virtual std::unique_ptr< descriptor_set_type > spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >::allocate ( unsigned descriptors,
const std::vector< DescriptorBinding > & bindings = { } ) const
nodiscardpure virtual

Allocates a new IDescriptorSet or returns an unused descriptor set.

Parameters
bindingsOptional list of descriptor bindings to initialize the IDescriptorSet with.
Returns
A std::unique_ptr to the allocated IDescriptorSet.

Allocating a new descriptor set may be an expensive operation. To improve performance, and prevent fragmentation, the descriptor set layout keeps track of created descriptor sets. It does this by never releasing them. Instead, when a IDescriptorSet instance gets destroyed, it should call IDescriptorSetLayout::free() in order to mark itself (i.e. its handle) as not being used any longer.

Before allocating a new descriptor set from a pool (which may even result in the creation of a new pool, if the existing pools are full), the layout tries to hand out descriptor sets that marked as unused. Descriptor sets are only deleted, if the whole layout instance and therefore the descriptor pools are deleted. ( The above does not apply to unbounded descriptor arrays. A unbounded descriptor array is one, for which IDescriptorLayout::descriptors() returns -1 (or 0xFFFFFFFF). They must be allocated by specifying the descriptors parameter. This parameter defines the number of descriptors to allocate in the array.

Note that descriptor sets, that contain an unbounded descriptor array must only contain one single descriptor (the one that identifies this array). Such descriptor sets are never cached. Instead, they are released when calling IDescriptorSetLayout::free(). It is a good practice to cache such descriptor sets as global descriptor tables once and never release them. They provide more flexibility than regular descriptor arrays, since they may be updated, even after they have been bound to a command buffer or from different threads. However, you must ensure yourself not to overwrite any descriptors that are currently in use. Because unbounded arrays are not cached, freeing and re-allocating such descriptor sets may leave the descriptor heap fragmented, which might cause the allocation to fail, if the heap is full.

Implemented in spark::render::vk::VulkanDescriptorSetLayout.

◆ allocateMultiple() [1/4]

template<typename DescriptorLayoutType , typename DescriptorSetType >
virtual std::vector< std::unique_ptr< descriptor_set_type > > spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >::allocateMultiple ( unsigned descriptor_sets,
const std::function< std::vector< DescriptorBinding >(unsigned)> & binding_factory ) const
nodiscardpure virtual

Allocates an array of IDescriptorSet.

Parameters
descriptors_setsThe number of IDescriptorSet to allocate.
bindingsOptional list of descriptor bindings to initialize the IDescriptorSet with.
Returns
A std::vector containing std::unique_ptr to the newly allocated descriptor sets .

Implemented in spark::render::vk::VulkanDescriptorSetLayout.

◆ allocateMultiple() [2/4]

template<typename DescriptorLayoutType , typename DescriptorSetType >
virtual std::vector< std::unique_ptr< descriptor_set_type > > spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >::allocateMultiple ( unsigned descriptor_sets,
const std::vector< std::vector< DescriptorBinding > > & bindings = { } ) const
nodiscardpure virtual

Allocates an array of IDescriptorSet.

Parameters
descriptors_setsThe number of IDescriptorSet to allocate.
bindingsOptional list of descriptor bindings to initialize the IDescriptorSet with.
Returns
A std::vector containing std::unique_ptr to the newly allocated descriptor sets .

Implemented in spark::render::vk::VulkanDescriptorSetLayout.

◆ allocateMultiple() [3/4]

template<typename DescriptorLayoutType , typename DescriptorSetType >
virtual std::vector< std::unique_ptr< descriptor_set_type > > spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >::allocateMultiple ( unsigned descriptor_sets,
unsigned descriptors,
const std::function< std::vector< DescriptorBinding >(unsigned)> & binding_factory ) const
nodiscardpure virtual

Allocates an array of IDescriptorSet.

Parameters
descriptors_setsThe number of IDescriptorSet to allocate.
bindingsOptional list of descriptor bindings to initialize the IDescriptorSet with.
Returns
A std::vector containing std::unique_ptr to the newly allocated descriptor sets .

Implemented in spark::render::vk::VulkanDescriptorSetLayout.

◆ allocateMultiple() [4/4]

template<typename DescriptorLayoutType , typename DescriptorSetType >
virtual std::vector< std::unique_ptr< descriptor_set_type > > spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >::allocateMultiple ( unsigned descriptor_sets,
unsigned descriptors,
const std::vector< std::vector< DescriptorBinding > > & bindings = { } ) const
nodiscardpure virtual

Allocates an array of IDescriptorSet.

Parameters
descriptors_setsThe number of IDescriptorSet to allocate.
bindingsOptional list of descriptor bindings to initialize the IDescriptorSet with.
Returns
A std::vector containing std::unique_ptr to the newly allocated descriptor sets .

Implemented in spark::render::vk::VulkanDescriptorSetLayout.

◆ descriptor()

template<typename DescriptorLayoutType , typename DescriptorSetType >
const descriptor_layout_type * spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >::descriptor ( unsigned binding) const
nodiscardoverridepure virtual

Gets the layout of a descriptor in the IDescriptorSet bound to a specific binding point.

Parameters
bindingThe binding point of the requested descriptor layout.
Returns
A pointer to the IDescriptorLayout describing the layout of the descriptor bound to binding.

Implemented in spark::render::vk::VulkanDescriptorSetLayout.

◆ descriptors()

template<typename DescriptorLayoutType , typename DescriptorSetType >
virtual std::vector< const descriptor_layout_type * > spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >::descriptors ( ) const
nodiscardpure virtualnoexcept

Gets the layouts of all descriptors in the IDescriptorSet.

Returns
A std::vector containing pointers to IDescriptorLayout of all descriptors in the IDescriptorSet.

Implemented in spark::render::vk::VulkanDescriptorSetLayout.

◆ free()

template<typename DescriptorLayoutType , typename DescriptorSetType >
virtual void spark::render::DescriptorSetLayout< DescriptorLayoutType, DescriptorSetType >::free ( const descriptor_set_type & descriptor_set) const
pure virtualnoexcept

Marks a IDescriptorSet as unused, so that it can be handed out again instead of allocating a new one.

Parameters
descriptor_setThe IDescriptorSet to mark as unused.