VPP  0.7
A high-level modern C++ API for Vulkan
Public Member Functions | List of all members
vpp::UniformArray< TDef, BufferT > Class Template Reference

Provides shader code access to a binding point for buffer holding array of structures. More...

#include <vppLangIntUniform.hpp>

Public Member Functions

 UniformArray (BufferT &buf, int size=0, int stride=0)
 Constructs the accessor for given binding point, assuming the buffer is holding an array of structures. More...
 
auto operator[] (const Int &index) const
 Provides read and write access to specified item. More...
 
auto operator[] (const UInt &index) const
 
auto operator[] (int index) const
 
auto operator[] (unsigned int index) const
 
Int Size () const
 Returns GPU-side value equal to the size of the array. More...
 
int size () const
 Returns CPU-side value equal to the size of the array. More...
 

Detailed Description

template<template< vpp::ETag TAG > class TDef, class BufferT>
class vpp::UniformArray< TDef, BufferT >

Provides shader code access to a binding point for buffer holding array of structures.

Place UniformArray inside your shader code to access the data in uniform, storage or push constant buffer.

The first argument should be the structure template (derived from UniformStruct).

The second argument should be the decltype of accessed binding point. It accepts the following binding points: inUniformBuffer, ioBuffer, inUniformBufferDyn, ioBufferDyn, inPushConstant. Also specify the binding point in the constructor of UniformArray. The binding point should be an object inside PipelineConfig subclass and the shader should be a method in the same subclass - or some code called from it.

UniformArray gives access to multiple structures packed in single, non-arrayed buffer. For other variants, see arrayOf, UniformVar and UniformSimpleArray.

This should not be confused with arrayed buffers (arrayOf). Array of buffers consists of multiple buffers presented to the shader as an array. The UniformArray accessor operates on single buffer, but containing multiple data entries.

Constructor & Destructor Documentation

◆ UniformArray()

template<template< vpp::ETag TAG > class TDef, class BufferT>
vpp::UniformArray< TDef, BufferT >::UniformArray ( BufferT &  buf,
int  size = 0,
int  stride = 0 
)

Constructs the accessor for given binding point, assuming the buffer is holding an array of structures.

The constructor of the accessor creates actual variable (of array type) on the SPIR-V level.

As the first argument, provide reference to the binding point.

You can optionally provide fixed array size as the second argument.

If you omit array size, the accessor will generate a runtime array. Its size will be determined automatically from the size of bound buffer. You can read the dynamic size using the Size() method.

If you specify array size, the accessor will generate statically sized array. Its size will be fixed and can be read either by Size() method or size() method (they return GPU and CPU level types respectively).

Warning: it has been observed in practice that drivers for some GPUs (notably NVIDIA) have trouble with large size fixed arrays, which may lead to crashes or long hangs during shader code compilation. It is recommended to use runtime sized arrays unless the size is very small.

The third argument, also optional, allows to override array stride. It is provided just for completeness, as the accessor infers the stride automatically from the structure definition.

Member Function Documentation

◆ operator[]() [1/4]

template<template< vpp::ETag TAG > class TDef, class BufferT>
auto vpp::UniformArray< TDef, BufferT >::operator[] ( const Int index) const

Provides read and write access to specified item.

Returns an opaque type serving as temporary object, meant to be indexed again with operator[]. The second level operator[] accepts a pointer to member of GPU version of the data structure. This double indexing allows to read or write particular field in particular array item.

Some buffers are read-only. It is an error to attempt to write them.

◆ operator[]() [2/4]

template<template< vpp::ETag TAG > class TDef, class BufferT>
auto vpp::UniformArray< TDef, BufferT >::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<template< vpp::ETag TAG > class TDef, class BufferT>
auto vpp::UniformArray< TDef, BufferT >::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<template< vpp::ETag TAG > class TDef, class BufferT>
auto vpp::UniformArray< TDef, BufferT >::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.

◆ Size()

template<template< vpp::ETag TAG > class TDef, class BufferT>
Int vpp::UniformArray< TDef, BufferT >::Size ( ) const

Returns GPU-side value equal to the size of the array.

The size determined by this function may be dynamic. This happens if you did not specify explicit size in the constructor.

◆ size()

template<template< vpp::ETag TAG > class TDef, class BufferT>
int vpp::UniformArray< TDef, BufferT >::size ( ) const

Returns CPU-side value equal to the size of the array.

For dynamically sized arrays, returns zero.


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