Encapsulates a Vulkan compute pipeline and all necessary resources to use it.
More...
#include <ComputePipeline.h>
|
| ComputePipeline (const std::string &shaderPath, size_t numSSBOs, size_t pushConstantSize, size_t numStorageImages=0, size_t numSampledImages=0) |
| Construct a new compute pipeline. More...
|
|
void | Reinitialize (const std::string &shaderPath, size_t numSSBOs, size_t pushConstantSize, size_t numStorageImages=0, size_t numSampledImages=0) |
| Wipes the state of this object and recreates it with a new shader binary and configuration. More...
|
|
template<class T > |
void | BindBuffer (size_t i, AcceleratorBuffer< T > &buf, bool outputOnly=false) |
| Binds an input or output SSBO to a descriptor slot. More...
|
|
void | BindStorageImage (size_t i, vk::Sampler sampler, vk::ImageView view, vk::ImageLayout layout) |
| Binds a storage (output) image to a descriptor slot. More...
|
|
void | BindSampledImage (size_t i, vk::Sampler sampler, vk::ImageView view, vk::ImageLayout layout) |
| Binds a sampled (input) image to a descriptor slot. More...
|
|
template<class T > |
void | BindBufferNonblocking (size_t i, AcceleratorBuffer< T > &buf, vk::raii::CommandBuffer &cmdBuf, bool outputOnly=false) |
| Binds an input or output SSBO to a descriptor slot. More...
|
|
void | Bind (vk::raii::CommandBuffer &cmdBuf) |
| Binds the pipeline to a command buffer. More...
|
|
template<class T > |
void | Dispatch (vk::raii::CommandBuffer &cmdBuf, T pushConstants, uint32_t x, uint32_t y=1, uint32_t z=1) |
| Adds a vkCmdDispatch operation to a command buffer to execute the compute shader. More...
|
|
template<class T > |
void | DispatchNoRebind (vk::raii::CommandBuffer &cmdBuf, T pushConstants, uint32_t x, uint32_t y=1, uint32_t z=1) |
| Similar to Dispatch() but does not bind descriptor sets. More...
|
|
|
static void | AddComputeMemoryBarrier (vk::raii::CommandBuffer &cmdBuf) |
| Helper function to insert a shader write-to-read memory barrier in a command buffer. More...
|
|
|
void | DeferredInit () |
| Performs deferred initialization of the compute pipeline the first time the object is used. More...
|
|
|
std::string | m_shaderPath |
| Filesystem path to the compiled SPIR-V shader binary.
|
|
size_t | m_numSSBOs |
| Number of SSBO bindings in the shader.
|
|
size_t | m_numStorageImages |
| Number of output image bindings in the shader.
|
|
size_t | m_numSampledImages |
| Number of input image bindings in the shader.
|
|
size_t | m_pushConstantSize |
| Size of the push constants, in bytes.
|
|
std::unique_ptr< vk::raii::ShaderModule > | m_shaderModule |
| Handle to the shader module object.
|
|
std::unique_ptr< vk::raii::Pipeline > | m_computePipeline |
| Handle to the Vulkan compute pipeline.
|
|
std::unique_ptr< vk::raii::PipelineLayout > | m_pipelineLayout |
| Layout of the compute pipeline.
|
|
std::unique_ptr< vk::raii::DescriptorSetLayout > | m_descriptorSetLayout |
| Layout of our descriptor set.
|
|
std::unique_ptr< vk::raii::DescriptorPool > | m_descriptorPool |
| Pool for allocating m_descriptorSet from.
|
|
std::unique_ptr< vk::raii::DescriptorSet > | m_descriptorSet |
| The actual descriptor set storing our inputs and outputs.
|
|
std::vector< vk::WriteDescriptorSet > | m_writeDescriptors |
| Set of bindings to be written to m_descriptorSet.
|
|
std::vector< vk::DescriptorBufferInfo > | m_bufferInfo |
| Details about our SSBOs.
|
|
std::vector< vk::DescriptorImageInfo > | m_storageImageInfo |
| Details about our output images.
|
|
std::vector< vk::DescriptorImageInfo > | m_sampledImageInfo |
| Details about our input images.
|
|
Encapsulates a Vulkan compute pipeline and all necessary resources to use it.
Supported shaders must have all image bindings numerically after all SSBO bindings.
A ComputePipeline is typically owned by a filter instance.
Prefers KHR_push_descriptor (and some APIs are only available if it is present), but basic functionality is available without it.
◆ ComputePipeline()
ComputePipeline::ComputePipeline |
( |
const std::string & |
shaderPath, |
|
|
size_t |
numSSBOs, |
|
|
size_t |
pushConstantSize, |
|
|
size_t |
numStorageImages = 0 , |
|
|
size_t |
numSampledImages = 0 |
|
) |
| |
Construct a new compute pipeline.
Initialization is deferred until the first time the shader is bound. This allows creation of a ComputePipeline object to be relatively inexpensive (so many pipelines can be created which may not ever be used).
- Parameters
-
shaderPath | Path to the compiled shader binary |
numSSBOs | Number of SSBO bindings |
pushConstantSize | Size in bytes of our push constants |
numStorageImages | Number of output image bindings |
numSampledImages | Number of input image bindings |
◆ AddComputeMemoryBarrier()
static void ComputePipeline::AddComputeMemoryBarrier |
( |
vk::raii::CommandBuffer & |
cmdBuf | ) |
|
|
inlinestatic |
Helper function to insert a shader write-to-read memory barrier in a command buffer.
- Parameters
-
cmdBuf | Command buffer to append the pipeline barrier to |
◆ Bind()
void ComputePipeline::Bind |
( |
vk::raii::CommandBuffer & |
cmdBuf | ) |
|
|
inline |
Binds the pipeline to a command buffer.
- Parameters
-
cmdBuf | Command buffer to append the bind to |
◆ BindBuffer()
template<class T >
void ComputePipeline::BindBuffer |
( |
size_t |
i, |
|
|
AcceleratorBuffer< T > & |
buf, |
|
|
bool |
outputOnly = false |
|
) |
| |
|
inline |
Binds an input or output SSBO to a descriptor slot.
This method performs a blocking copy from the CPU to GPU views of the buffer if they are incoherent.
- Parameters
-
i | Descriptor index |
buf | The buffer to bind to the slot |
outputOnly | Hint that the shader never reads from the buffer, so there is no need to ensure coherence between CPU and GPU cache views of the buffer before executing the shader. |
◆ BindBufferNonblocking()
template<class T >
void ComputePipeline::BindBufferNonblocking |
( |
size_t |
i, |
|
|
AcceleratorBuffer< T > & |
buf, |
|
|
vk::raii::CommandBuffer & |
cmdBuf, |
|
|
bool |
outputOnly = false |
|
) |
| |
|
inline |
Binds an input or output SSBO to a descriptor slot.
This method performs a nonblocking copy from the CPU to GPU views of the buffer if they are incoherent.
- Parameters
-
i | Descriptor index |
buf | The buffer to bind to the slot |
cmdBuf | Command buffer to append the copy operation, if needed, to |
outputOnly | Hint that the shader never reads from the buffer, so there is no need to ensure coherence between CPU and GPU cache views of the buffer before executing the shader. |
◆ BindSampledImage()
void ComputePipeline::BindSampledImage |
( |
size_t |
i, |
|
|
vk::Sampler |
sampler, |
|
|
vk::ImageView |
view, |
|
|
vk::ImageLayout |
layout |
|
) |
| |
|
inline |
Binds a sampled (input) image to a descriptor slot.
- Parameters
-
i | Descriptor index |
sampler | Vulkan sampler |
view | Vulkan image view |
layout | Vulkan image layout |
◆ BindStorageImage()
void ComputePipeline::BindStorageImage |
( |
size_t |
i, |
|
|
vk::Sampler |
sampler, |
|
|
vk::ImageView |
view, |
|
|
vk::ImageLayout |
layout |
|
) |
| |
|
inline |
Binds a storage (output) image to a descriptor slot.
- Parameters
-
i | Descriptor index |
sampler | Vulkan sampler |
view | Vulkan image view |
layout | Vulkan image layout |
◆ DeferredInit()
void ComputePipeline::DeferredInit |
( |
| ) |
|
|
protected |
Performs deferred initialization of the compute pipeline the first time the object is used.
This function actually loads the shader binary and creates descriptor sets etc.
◆ Dispatch()
template<class T >
void ComputePipeline::Dispatch |
( |
vk::raii::CommandBuffer & |
cmdBuf, |
|
|
T |
pushConstants, |
|
|
uint32_t |
x, |
|
|
uint32_t |
y = 1 , |
|
|
uint32_t |
z = 1 |
|
) |
| |
|
inline |
Adds a vkCmdDispatch operation to a command buffer to execute the compute shader.
If KHR_push_descriptor is not available, performs an updateDescriptorSets. This means only one Dispatch() of a given ComputePipeline can be present in a command buffer at a time.
If KHR_push_descriptor is available, performs a pushDescriptorSetKHR. In this case, arbitrarily many Dispatch() calls on the same ComputePipeline may be submitted to the same command buffer in sequence.
- Parameters
-
cmdBuf | Command buffer to append the dispatch operation to |
pushConstants | Constants to pass to the shader |
x | X size of the dispatch, in thread blocks |
y | Y size of the dispatch, in thread blocks |
z | Z size of the dispatch, in thread blocks |
◆ DispatchNoRebind()
template<class T >
void ComputePipeline::DispatchNoRebind |
( |
vk::raii::CommandBuffer & |
cmdBuf, |
|
|
T |
pushConstants, |
|
|
uint32_t |
x, |
|
|
uint32_t |
y = 1 , |
|
|
uint32_t |
z = 1 |
|
) |
| |
|
inline |
Similar to Dispatch() but does not bind descriptor sets.
This allows multiple consecutive invocations of the same shader (potentially with different dispatch sizes or push constant values) in the same command buffer, even without KHR_push_descriptor, as long as the same set of input and output descriptors are used by each invocation.
If KHR_push_descriptor is available, performs a vkPushDescriptorSetKHR. If not, descriptors are untouched.
- Parameters
-
cmdBuf | Command buffer to append the dispatch operation to |
pushConstants | Constants to pass to the shader |
x | X size of the dispatch, in thread blocks |
y | Y size of the dispatch, in thread blocks |
z | Z size of the dispatch, in thread blocks |
◆ Reinitialize()
void ComputePipeline::Reinitialize |
( |
const std::string & |
shaderPath, |
|
|
size_t |
numSSBOs, |
|
|
size_t |
pushConstantSize, |
|
|
size_t |
numStorageImages = 0 , |
|
|
size_t |
numSampledImages = 0 |
|
) |
| |
Wipes the state of this object and recreates it with a new shader binary and configuration.
Initialization is deferred until the first time the shader is bound. This allows creation of a ComputePipeline object to be relatively inexpensive (so many pipelines can be created which may not ever be used).
- Parameters
-
shaderPath | Path to the compiled shader binary |
numSSBOs | Number of SSBO bindings |
pushConstantSize | Size in bytes of our push constants |
numStorageImages | Number of output image bindings |
numSampledImages | Number of input image bindings |
The documentation for this class was generated from the following files: