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

Pipeline layout template for a compute pipeline. Use to create actual pipeline layout (Vulkan objects) from abstract representation in the form of ComputePipelineConfig object. More...

#include <vppPipelineLayout.hpp>

Public Member Functions

template<typename... Args>
 ComputePipelineLayout (const Device &hDevice, Args... args)
 Constructs a pipeline layout attached to specified Device, with optional list of user-specific arguments. The constructor pass the extra arguments to the DefinitionT constructor.
 
VkPipelineLayout handle () const
 Retrieves Vulkan handle for the pipeline layout.
 
const Devicedevice () const
 Retrieves the device.
 
DefinitionT & definition ()
 Retrieves the definition object. Useful to call resource binding methods defined in your pipeline config from the ComputePass command sequence.
 
const DefinitionT & definition () const
 

Detailed Description

template<class DefinitionT>
class vpp::ComputePipelineLayout< DefinitionT >

Pipeline layout template for a compute pipeline. Use to create actual pipeline layout (Vulkan objects) from abstract representation in the form of ComputePipelineConfig object.

Place an instance of ComputePipelineLayout inside your computation engine class. As the DefinitionT type, supply your custom class derived from ComputePipelineConfig.

In the constructor, provide a reference to target Device and any number of your own arguments. Those optional arguments will be passed to the constructor of your ComputePipelineConfig subclass. You can parameterize your ComputePipelineConfig this way.

After construction, register the ComputePipelineLayout in your ComputePass object by calling addPipeline().

The ComputePipelineLayout template creates an instance of DefinitionT internally. Optionally you can pass your own arguments to the constructor. You can retrieve the definition object by calling the definition() method.

An example:

class MyPipelineConfig : public vpp::ComputePipelineConfig
{
public:
MyPipelineConfig ( const vpp::Device& hDevice )
m_computeShader ( this, { 32, 1, 1 }, & MyPipelineConfig::fComputeShader )
{}
void setDataBuffers (
vpp::ShaderDataBlock* pDataBlock,
const vpp::UniformBufferView& dataInput,
const vpp::UniformBufferView& dataOutput )
{
pDataBlock->update ( (
m_dataInput = dataInput,
m_dataOutput = dataOutput
) );
}
void fComputeShader ( vpp::ComputeShader* pShader )
{
using namespace vpp;
const IVec3 workgroupId = pShader->inWorkgroupId;
const IVec3 localId = pShader->inLocalInvocationId;
const Int g = workgroupId [ X ];
const Int l = localId [ X ];
const Int i = ( g << 5 ) + l;
const Float s = inData [ i ];
const Float d = s*s;
outData [ i ] = d;
}
private:
vpp::inUniformBuffer m_dataInput;
vpp::ioBuffer m_dataOutput;
vpp::computeShader m_computeShader;
};
class MyComputePass : public vpp::ComputePass
{
public:
MyComputePass ( const vpp::Device& dev ) :
m_myPipelineLt ( dev ),
m_dataBlock ( m_myPipelineLt ),
m_myDataSrc ( 2048, vpp::MemProfile::DEVICE_STATIC, dev )
m_myDataDest ( 2048, vpp::MemProfile::DEVICE_STATIC, dev )
{
// Register and compile the pipeline.
addPipeline ( m_myPipelineLt );
// Obtain MyPipelineConfig object and call the data binding method.
m_myPipelineLt.definition().setDataBuffers (
& m_dataBlock,
m_myDataSrc,
m_myDataDest
);
// Provide command sequence as lambda.
(*this) << [ this ]()
{
// Retrieve compiled pipeline object and select it for subsequent computation.
pipeline ( 0 ).cmdBind();
// Select the data block for subsequent computation.
m_dataBlock.cmdBind();
// Launch the computation in 64 workgroups.
cmdDispatch ( 64, 1, 1 );
};
}
private:
// Declare ComputePipelineLayout instance.
// Declare a data block.
vpp::ShaderDataBlock m_dataBlock;
// Declare a data source and target.
};

Member Function Documentation

◆ definition()

template<class DefinitionT>
const DefinitionT& vpp::ComputePipelineLayout< DefinitionT >::definition ( ) const

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


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