VPP  0.7
A high-level modern C++ API for Vulkan
Public Member Functions | Public Attributes | List of all members
vpp::arrayOf< SingleT > Class Template Reference

Template allowing to construct arrays of binding points. More...

#include <vppLangIntBase.hpp>

Public Member Functions

 arrayOf (unsigned int count, unsigned int set=0, int binding=-1)
 Constructs array of binding points. More...
 
 arrayOf (const std::vector< NormalizedSampler > &samplers, unsigned int count, unsigned int set=0, int binding=-1)
 Constructs array of binding points. More...
 
 arrayOf (const std::vector< UnnormalizedSampler > &samplers, unsigned int count, unsigned int set=0, int binding=-1)
 Constructs array of binding points. More...
 
auto operator= (const multi_value_type &value)
 
return_type operator[] (const Int &index) const
 Indexing operator for accessing individual binding points in the array. More...
 
return_type operator[] (const UInt &index) const
 
return_type operator[] (int index) const
 
return_type operator[] (unsigned int index) const
 

Public Attributes

typedef< implementation_defined > return_type
 Type of accessed image resource. More...
 

Detailed Description

template<class SingleT>
class vpp::arrayOf< SingleT >

Template allowing to construct arrays of binding points.

This template is used as a wrapper over binding point classes to create arrays of binding points. The purpose of such arrays is to allow dynamic selection of binding points in shader, based on GPU-level index. Arrays of binding points are static, so their size must be known in advance.

The arrayOf template is applicable for the following binding point classes: inUniformBuffer, inUniformBufferDyn, ioBuffer, ioBufferDyn, ioImageBuffer, inTextureBuffer, ioImage, inSampler, inConstSampler, inTexture, inSampledTexture, inConstSampledTexture.

Arrays of data buffers (inUniformBuffer, inUniformBufferDyn, ioBuffer, ioBufferDyn) are being accessed slightly differently than arrays of images and texel buffers (ioImageBuffer, inTextureBuffer, ioImage, inSampler, inConstSampler, inTexture, inSampledTexture, inConstSampledTexture). These differences will be explained further below.

An array of binding points in VPP corresponds to array of descriptors in Vulkan. That is, it defines proper count values in descriptor defining structures and generates array types on SPIR-V level.

In order to declare an array of binding points, just wrap the base type inside arrayOf. Examples:

// defines array of uniform buffers
// defines array of storage buffers.
// defines arrays of texel buffers
// defines arrays of various image resources
// defines arrays of samplers

In order to construct arrayOf object, you must provide array size to the constructor. See the docs for individual constructors for more detail.

In order to access an arrayed binding point in your shader code, use one of two methods depending on what kind of binding point is is.

For buffer binding points, i.e. inUniformBuffer, inUniformBufferDyn, ioBuffer, ioBufferDyn, use UniformVar accessor. It is specialized for arrays an provides an operator[] for additional level of indirection.

Examples:

template< ETag TAG >
struct TFramePar : public UniformStruct< TAG, TFramePar >
{
UniformFld< TAG, glm::mat4 > m_world2projected;
UniformFld< TAG, glm::mat4 > m_world2view;
// ...
};
typedef TFramePar< vpp::CPU > CFramePar;
typedef TFramePar< vpp::GPU > GFramePar;
class MyPipelineConfig : public vpp::PipelineConfig
{
// ...
void fVertexShader ( vpp::VertexShader* pShader )
{
using namespace vpp;
varUniformBufferArr ( m_inUniformBufferArr );
Int arrayIndex = ...; // compute array index
Mat4 w2p = varUniformBufferArr [ arrayIndex ][ & GFramePar::m_world2projected ];
// ...
}
};

For image binding points, i.e. ioImageBuffer, inTextureBuffer, ioImage, inSampler, inConstSampler, inTexture, inSampledTexture, inConstSampledTexture, use the indexing operator directly on arrayOf object when supplying an argument to the image manipulation function.

Examples:

class MyPipelineConfig : public vpp::PipelineConfig
{
void fFragmentShader ( vpp::FragmentShader* pShader )
{
using namespace vpp;
Int arrIdx = ...; // compute array index
// dummy coordinates only to demonstrate function call syntax
Int n = 0;
Vec2 c = { 0.5f, 0.5f };
IVec3 ci = { 7, 8, 0 };
Float b = 0.0f;
Vec3 d = { 0.5f, 0.5f, 0.0f };
IVec2 i = { 7, 8 };
IVec3 s1 = ImageSize ( m_ioImageArr [ arrIdx ] );
IVec3 s2 = TextureSize ( m_inTextureArr [ arrIdx ], n );
Int s3 = ImageQuerySamples ( m_inSampledTextureArr [ arrIdx ] );
Int s4 = ImageQueryLevels ( m_inConstSampledTextureArr [ arrIdx ] );
Vec2 s5 = TextureQueryLod ( m_inSampledTextureArr [ arrIdx ], c );
UVec4 s6 = ImageLoad ( m_ioImageArr [ arrIdx ], ci );
ImageStore ( m_ioImageArr [ arrIdx ], ci, s6 [ X ] );
UVec4 s7 = TexelFetch ( m_inTextureBufferArr [ arrIdx ], n );
UVec4 s8 = TexelFetchLod ( m_inTextureArr [ arrIdx ], ci, n );
Vec4 s9 = TexelFetchOffset ( m_inConstSampledTextureArr [ arrIdx ], i, n, i );
Vec4 s10 = Texture ( m_inSampledTextureArr [ arrIdx ], c );
Vec4 s11 = TextureLod ( m_inConstSampledTextureArr [ arrIdx ], c, b );
Vec4 s12 = TextureProj ( m_inSampledTextureArr [ arrIdx ], d, b );
Vec4 s13 = TextureLodProj ( m_inConstSampledTextureArr [ arrIdx ], d, b );
Vec4 s14 = TextureGather ( m_inSampledTextureArr [ arrIdx ], c, n );
const auto st1 = MakeSampledTexture (
m_inTextureArr [ arrIdx ], m_inSamplerArr [ arrIdx ] );
const auto st2 = MakeSampledTexture (
m_inTextureArr [ arrIdx ], m_inSampler );
}
};

Constructor & Destructor Documentation

◆ arrayOf() [1/3]

template<class SingleT>
vpp::arrayOf< SingleT >::arrayOf ( unsigned int  count,
unsigned int  set = 0,
int  binding = -1 
)

Constructs array of binding points.

This constructor is meant to be used with all binding point types except inConstSampler and inConstSampledTexture.

Size of the array is mandatory argument.

Optionally you can force the set and binding index. This feature may be useful if you need to interface VPP binding point with externally supplied shader (written in GLSL and compiled externally to SPIR-V blob).

◆ arrayOf() [2/3]

template<class SingleT>
vpp::arrayOf< SingleT >::arrayOf ( const std::vector< NormalizedSampler > &  samplers,
unsigned int  count,
unsigned int  set = 0,
int  binding = -1 
)

Constructs array of binding points.

This constructor is meant to be used with inConstSampler and inConstSampledTexture binding points and normalized samplers.

You must specify a list of samplers to be statically bound to the image.

Size of the array is also mandatory argument. If the size is larger than provided vector of samplers, the last sampler on the list will be duplicated to fill remaining positions.

Optionally you can force the set and binding index. This feature may be useful if you need to interface VPP binding point with externally supplied shader (written in GLSL and compiled externally to SPIR-V blob).

◆ arrayOf() [3/3]

template<class SingleT>
vpp::arrayOf< SingleT >::arrayOf ( const std::vector< UnnormalizedSampler > &  samplers,
unsigned int  count,
unsigned int  set = 0,
int  binding = -1 
)

Constructs array of binding points.

This constructor is meant to be used with inConstSampler and inConstSampledTexture binding points and unnormalized samplers.

You must specify a list of samplers to be statically bound to the image.

Size of the array is also mandatory argument. If the size is larger than provided vector of samplers, the last sampler on the list will be duplicated to fill remaining positions.

Optionally you can force the set and binding index. This feature may be useful if you need to interface VPP binding point with externally supplied shader (written in GLSL and compiled externally to SPIR-V blob).

Member Function Documentation

◆ operator[]() [1/4]

template<class SingleT>
return_type vpp::arrayOf< SingleT >::operator[] ( const Int index) const

Indexing operator for accessing individual binding points in the array.

This operator is used only for the following binding point types: ioImage, inSampler, inConstSampler, inTexture, inSampledTexture, inConstSampledTexture, inTextureBuffer, ioImageBuffer.

Use it inside shaders to extract the binding point used as an argument for image or texture manipulation functions.

◆ operator[]() [2/4]

template<class SingleT>
return_type vpp::arrayOf< SingleT >::operator[] ( const UInt index) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator[]() [3/4]

template<class SingleT>
return_type vpp::arrayOf< SingleT >::operator[] ( int  index) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator[]() [4/4]

template<class SingleT>
return_type vpp::arrayOf< SingleT >::operator[] ( unsigned int  index) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Member Data Documentation

◆ return_type

template<class SingleT>
typedef<implementation_defined> vpp::arrayOf< SingleT >::return_type

Type of accessed image resource.

This type is used only for the following binding point types: ioImage, inSampler, inConstSampler, inTexture, inSampledTexture, inConstSampledTexture, inTextureBuffer, ioImageBuffer.

This is the type of object that goes to image manipulation function inside the shader. The object is obtained by indexing the arrayOf object (by means of operator[]).


The documentation for this class was generated from the following file: