VPP  0.8
A high-level modern C++ API for Vulkan
vpp::inPushConstant< DefinitionT > Class Template Reference

Binding point class for push constant data input to shaders. Place in your pipeline configuration class to declare a push constant. More...

#include <vppLangIntUniform.hpp>

Public Types

typedef DefinitionT< CPUDataBlock
 A typedef to CPU version of the data structure.
 

Public Member Functions

 inPushConstant ()
 Constructor. Does not take any arguments.
 
void cmdPush (CommandBuffer currentBuffer)
 Emits push command to specified command buffer. More...
 
template<typename ValueT >
void cmdPush (CommandBuffer currentBuffer, const ValueT &field)
 Emits push command to specified command buffer. More...
 
void cmdPush ()
 Emits push command to default command buffer. More...
 
template<typename ValueT >
void cmdPush (const ValueT &field)
 Emits push command to default command buffer. More...
 
DataBlockdata ()
 Allows to access the fields of the data structure. More...
 

Detailed Description

template<template< vpp::ETag TAG > class DefinitionT>
class vpp::inPushConstant< DefinitionT >

Binding point class for push constant data input to shaders. Place in your pipeline configuration class to declare a push constant.

Specify the name of your uniform data structure template as the argument. Accepts templates derived from UniformStruct.

This class should be used only to define a binding point inside your custom pipeline configuration (a PipelineConfig or ComputePipelineConfig subclass).

Push constants in VPP are used in pretty much the same way as uniform buffers, with some differences. There are the following steps to consider when using push constants within pipeline config:

  • Definition of data structure to be stored within the constant. Use UniformStruct template for that. Beware that push constant size is limited and it should be very small structure.
  • Declaration of binding point inside PipelineConfig (or ComputePipelineConfig) derived class. It can be private member.
  • Supplying actual data on CPU side. Here the important thing is that push constants bypass ShaderDataBlock completely and you do not need to bind any buffers. Instead, the binding point contains its own small data buffer. You can obtrain access to this buffer by calling data() method on the binding point. Write the fields directly.
  • Synchronizing CPU side buffer to GPU. This is done by means of a command generated to a command buffer. Easiest way is to use one of the overloads of cmdPush() method within your rendering sequence. It's exactly in the same place in which you would select ShaderDataBlock into the pipeline - now it sends the data instead.
  • Reading the data in a shader on the GPU side. All shader types can read push constants. This is being done by means of accessor object declared within the shader. Declare UniformVar object, just the same as for uniform buffers.

Example:

// define data structure for the buffer
template< ETag TAG >
struct TMyBufferStructure : public UniformStruct< TAG, TMyBufferStructure >
{
UniformFld< TAG, glm::mat4 > m_matrixField;
UniformFld< TAG, glm::vec4 > m_vectorField;
// ...
};
// it is convenient to make these typedefs
typedef TMyBufferStructure< vpp::CPU > CMyBufferStructure;
typedef TMyBufferStructure< vpp::GPU > GMyBufferStructure;
class MyPipelineConfig : public vpp::PipelineConfig
{
// defines the binding point - assume it contains TMyBufferStructure entry
void fVertexShader ( vpp::VertexShader* pShader )
{
using namespace vpp;
// Accessing a buffer containing single structure.
varBuffer ( m_inPushConstant );
Mat4 m1 = varBuffer [ & GMyBufferStructure::m_matrixField ];
}
};
// [jeszcze example na cmdPush]

Member Function Documentation

◆ cmdPush() [1/4]

template<template< vpp::ETag TAG > class DefinitionT>
void vpp::inPushConstant< DefinitionT >::cmdPush ( CommandBuffer  currentBuffer)

Emits push command to specified command buffer.

The command will be executed when the command buffer is executed by the queue. It will transfer entire push constant structure to the GPU.

◆ cmdPush() [2/4]

template<template< vpp::ETag TAG > class DefinitionT>
template<typename ValueT >
void vpp::inPushConstant< DefinitionT >::cmdPush ( CommandBuffer  currentBuffer,
const ValueT &  field 
)

Emits push command to specified command buffer.

The command will be executed when the command buffer is executed by the queue. It will transfer only specified field contents to the GPU. As the field reference, supply a reference to a field inside CPU version of the data structure.

◆ cmdPush() [3/4]

template<template< vpp::ETag TAG > class DefinitionT>
void vpp::inPushConstant< DefinitionT >::cmdPush ( )

Emits push command to default command buffer.

The command will be executed when the command buffer is executed by the queue. It will transfer entire push constant structure to the GPU. This overload is meant to be used inside rendering command sequence (Process, Preprocess or Postprocess).

◆ cmdPush() [4/4]

template<template< vpp::ETag TAG > class DefinitionT>
template<typename ValueT >
void vpp::inPushConstant< DefinitionT >::cmdPush ( const ValueT &  field)

Emits push command to default command buffer.

The command will be executed when the command buffer is executed by the queue. It will transfer only specified field contents to the GPU. As the field reference, supply a reference to a field inside CPU version of the data structure.

This overload is meant to be used inside rendering command sequence (Process, Preprocess or Postprocess).

◆ data()

template<template< vpp::ETag TAG > class DefinitionT>
DataBlock& vpp::inPushConstant< DefinitionT >::data ( )

Allows to access the fields of the data structure.

Fields are being written directly. However, they are synchronized (sent to GPU) at the moment when cmdPush() command is being executed by the queue.

It is a common practice to issue cmdPush() inside rendering command sequence (Process, Preprocess or Postprocess). However, do NOT write push constant fields there. Fields should be written before issuing the command buffer to the queue – not when constructing the buffer what the command sequence actually does.


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