![]() |
VPP
0.8
A high-level modern C++ API for Vulkan
|
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... | |
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.
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. Caution: this is available only for storage binding points, i.e. ioBuffer and ioBufferDyn. For others, you must specify the size of the array explicitly.
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 (with storage buffers) unless the size is 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. This also enforces explicit array size.
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.
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.
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.
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.
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.
int vpp::UniformArray< TDef, BufferT >::size | ( | ) | const |
Returns CPU-side value equal to the size of the array.
For dynamically sized arrays, returns zero.