![]() |
VPP
0.8
A high-level modern C++ API for Vulkan
|
Provides shader code access to a binding point for buffer holding array of simple scalars, vectors or matrices. More...
#include <vppLangIntUniform.hpp>
Public Member Functions | |
UniformSimpleArray (BufferT &buf, int size=0, int stride=0) | |
Constructs accessor for given binding point, assuming the buffer is holding an array of simple items. 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 simple scalars, vectors or matrices.
Place UniformSimpleArray inside your shader code to access the data in uniform, storage or push constant buffer.
The first argument should be the CPU type. For scalars this is just numeric C++ type, e.g. int, unsigned int, float or double. For vectors and matrices, you need to define your own vector or matrix class and provide StructMemberTraits template specialization. That permits to use your custom types for vectors and matrices. By default, VPP supplies such integration for GLM library types.
Caution: a type allowed to be an element of UniformSimpleArray must not be a packed 3-element vector, due to Vulkan alignment constraints for uniform buffers. This restriction forbids e.g. glm::vec3
vectors in that context (use glm::vec4
instead). The vpp::vect3 type is permitted, because it is aligned to 16 bytes.
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 UniformSimpleArray. 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.
UniformSimpleArray gives access to multiple values (of scalar, vector or matrix) packed in single, non-arrayed buffer. For other variants, see arrayOf, UniformVar and UniformArray.
This should not be confused with arrayed buffers (arrayOf). Array of buffers consists of multiple buffers presented to the shader as an array. The UniformSimpleArray accessor operates on single buffer, but containing multiple data entries.
The GPU-side type (returned by indexing operators) is automatically inferred from the HostT
type with help of StructMemberTraits template specialization. Define your own specialization of StructMemberTraits to use a custom data type which is not supported by VPP already.
vpp::UniformSimpleArray< HostT, BufferT >::UniformSimpleArray | ( | BufferT & | buf, |
int | size = 0 , |
||
int | stride = 0 |
||
) |
Constructs accessor for given binding point, assuming the buffer is holding an array of simple items.
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 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 HostT
and StructMemberTraits. This also enforces explicit array size.
auto vpp::UniformSimpleArray< HostT, BufferT >::operator[] | ( | const Int & | index | ) | const |
Provides read and write access to specified item.
Returns a type inferred from the host data type, allowing to read or write the array.
Some buffers are read-only. It is an error to attempt to write them.
auto vpp::UniformSimpleArray< HostT, 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::UniformSimpleArray< HostT, 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::UniformSimpleArray< HostT, 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::UniformSimpleArray< HostT, 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::UniformSimpleArray< HostT, BufferT >::size | ( | ) | const |
Returns CPU-side value equal to the size of the array.
For dynamically sized arrays, returns zero.