Magnum::Vk::Pipeline class new in Git master

Pipeline.

Wraps a VkPipeline. A pipeline contains all state for execution of either rasterization commands or a compute dispatch and among other things contains shaders, pipeline layout specifying how uniform buffers, samplers and other resources are bound, or a render pass describing how framebuffer attachments get used.

Rasterization pipeline creation

A RasterizationPipelineCreateInfo is constructed from a ShaderSet, MeshLayout, PipelineLayout and a RenderPass together with subpass index and the count of color attachments. Apart from that you need to set a viewport using RasterizationPipelineCreateInfo::setViewport() and you end up with a minimal setup needed for color-only rendering:

#include <Magnum/Vk/RasterizationPipelineCreateInfo.h>



Vk::ShaderSet shaderSet{};
Vk::MeshLayout meshLayout{};
Vk::PipelineLayout pipelineLayout{};
Vk::RenderPass renderPass{};

Vk::Pipeline pipeline{device, Vk::RasterizationPipelineCreateInfo{
        shaderSet, meshLayout, pipelineLayout, renderPass, 0, 1}
    .setViewport({{}, {800.0f, 600.0f}})
};

Certain aspects of the pipeline can be set as dynamic using setDynamicStates() — in that case a subset of the values passed to the constructor will be ignored. See the particular DynamicRasterizationState values for more information.

Compute pipeline creation

Compared to a rasterization pipeline, ComputePipelineCreateInfo only takes a ShaderSet containing a single ShaderStage::Compute shader and a PipelineLayout:

#include <Magnum/Vk/ComputePipelineCreateInfo.h>



Vk::ShaderSet shaderSet{};
Vk::PipelineLayout pipelineLayout{};

Vk::Pipeline pipeline{device, Vk::ComputePipelineCreateInfo{
    shaderSet, pipelineLayout
}};

Pipeline usage

A pipeline is bound to a compatible command buffer using CommandBuffer::bindPipeline(), which replaces any pipeline bound previously to the same bindPoint():

Vk::Pipeline pipeline{};



cmd.bindPipeline(pipeline);

Public static functions

static auto wrap(Device& device, PipelineBindPoint bindPoint, VkPipeline handle, const DynamicRasterizationStates& dynamicStates, HandleFlags flags = {}) -> Pipeline
Wrap existing Vulkan handle.
static auto wrap(Device& device, PipelineBindPoint bindPoint, VkPipeline handle, HandleFlags flags = {}) -> Pipeline

Constructors, destructors, conversion operators

Pipeline(Device& device, const RasterizationPipelineCreateInfo& info) explicit
Construct a rasterization pipeline.
Pipeline(Device& device, const ComputePipelineCreateInfo& info) explicit
Construct a compute pipeline.
Pipeline(NoCreateT) explicit
Construct without creating the pipeline layout.
Pipeline(const Pipeline&) deleted
Copying is not allowed.
Pipeline(Pipeline&& other) noexcept
Move constructor.
~Pipeline()
Destructor.
operator VkPipeline()

Public functions

auto operator=(const Pipeline&) -> Pipeline& deleted
Copying is not allowed.
auto operator=(Pipeline&& other) -> Pipeline& noexcept
Move assignment.
auto handle() -> VkPipeline
Underlying VkPipeline handle.
auto handleFlags() const -> HandleFlags
Handle flags.
auto bindPoint() const -> PipelineBindPoint
Pipeline bind point.
auto dynamicRasterizationStates() const -> DynamicRasterizationStates
Dynamic rasterization states enabled in this pipeline.
auto release() -> VkPipeline
Release the underlying Vulkan pipeline.

Function documentation

static Pipeline Magnum::Vk::Pipeline::wrap(Device& device, PipelineBindPoint bindPoint, VkPipeline handle, const DynamicRasterizationStates& dynamicStates, HandleFlags flags = {})

Wrap existing Vulkan handle.

Parameters
device Vulkan device the pipeline is created on
bindPoint Pipeline bind point. Available through bindPoint() afterwards.
handle The VkPipeline handle
dynamicStates Dynamic states enabled on the rasterization pipeline. Available through dynamicRasterizationStates() afterwards.
flags Handle flags

The handle is expected to be originating from device. Unlike a pipeline layout created using a constructor, the Vulkan pipeline layout is by default not deleted on destruction, use flags for different behavior.

static Pipeline Magnum::Vk::Pipeline::wrap(Device& device, PipelineBindPoint bindPoint, VkPipeline handle, HandleFlags flags = {})

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

Magnum::Vk::Pipeline::Pipeline(Device& device, const RasterizationPipelineCreateInfo& info) explicit

Construct a rasterization pipeline.

Parameters
device Vulkan device to create the pipeline on
info Rasterization pipeline creation info

THe bindPoint() is set to PipelineBindPoint::Rasterization.

Magnum::Vk::Pipeline::Pipeline(Device& device, const ComputePipelineCreateInfo& info) explicit

Construct a compute pipeline.

Parameters
device Vulkan device to create the pipeline on
info Compite pipeline creation info

THe bindPoint() is set to PipelineBindPoint::Compute.

Magnum::Vk::Pipeline::Pipeline(NoCreateT) explicit

Construct without creating the pipeline layout.

The constructed instance is equivalent to moved-from state. Useful in cases where you will overwrite the instance later anyway. Move another object over it to make it useful.

Magnum::Vk::Pipeline::~Pipeline()

Destructor.

Destroys associated VkPipeline handle, unless the instance was created using wrap() without HandleFlag::DestroyOnDestruction specified.

Magnum::Vk::Pipeline::operator VkPipeline()

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

PipelineBindPoint Magnum::Vk::Pipeline::bindPoint() const

Pipeline bind point.

Either set implicitly based on what constructor was used, or coming from the wrap() call.

DynamicRasterizationStates Magnum::Vk::Pipeline::dynamicRasterizationStates() const

Dynamic rasterization states enabled in this pipeline.

Contains the states passed to RasterizationPipelineCreateInfo::setDynamicStates() or to the wrap() call. Expects that bindPoint() is PipelineBindPoint::Rasterization.

VkPipeline Magnum::Vk::Pipeline::release()

Release the underlying Vulkan pipeline.

Releases ownership of the Vulkan pipeline and returns its handle so vkDestroyPipeline() is not called on destruction. The internal state is then equivalent to moved-from state.