Class GraphicsPipelineBuilder¶
Defined in File graphics_pipeline_builder.hpp
Class Documentation¶
-
class GraphicsPipelineBuilder¶
Builder class for VkPipelineCreateInfo for graphics pipelines which use dynamic rendering
Note
This builder pattern does not perform any checks which are already covered by validation layers. This means if you forget to specify viewport for example, creation of the graphics pipeline will fail. It is the reponsibility of the programmer to use validation layers to check for problems.
Public Functions
-
GraphicsPipelineBuilder(const Device &device, const PipelineCache &pipeline_cache)¶
Default constructor
- Parameters:
device – The device wrapper
pipeline_cache – The Vulkan pipeline cache
-
GraphicsPipelineBuilder(const GraphicsPipelineBuilder&) = delete¶
-
GraphicsPipelineBuilder(GraphicsPipelineBuilder &&other) noexcept¶
-
~GraphicsPipelineBuilder() = default¶
-
GraphicsPipelineBuilder &operator=(const GraphicsPipelineBuilder&) = delete¶
-
GraphicsPipelineBuilder &operator=(GraphicsPipelineBuilder&&) = delete¶
-
GraphicsPipelineBuilder &add_color_attachment_format(VkFormat format)¶
Adds a color attachment
- Parameters:
format – The format of the color attachment
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &add_color_blend_attachment(const VkPipelineColorBlendAttachmentState &attachment)¶
Add a color blend attachment
- Parameters:
attachment – The color blend attachment
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &add_default_color_blend_attachment()¶
Add the default color blend attachment
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &add_push_constant_range(VkShaderStageFlags shader_stage, std::uint32_t size, std::uint32_t offset = 0)¶
Add a push constant range to the graphics pass
- Parameters:
shader_stage – The shader stage for the push constant range
size – The size of the push constant
offset – The offset in the push constant range
- Returns:
A const reference to the this pointer (allowing method calls to be chained)
-
std::shared_ptr<GraphicsPipeline> build(std::string name)¶
Build the graphics pipeline with specified pipeline create flags
- Parameters:
name – The debug name of the graphics pipeline
- Returns:
The unique pointer instance of
GraphicsPipelinethat was created
-
GraphicsPipelineBuilder &set_color_blend(const VkPipelineColorBlendStateCreateInfo &color_blend)¶
Set the color blend manually
- Parameters:
color_blend – The color blend
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_color_blend_attachments(const std::vector<VkPipelineColorBlendAttachmentState> &attachments)¶
Set all color blend attachments manually
Note
You should prefer to use
add_color_blend_attachmentinstead- Parameters:
attachments – The color blend attachments
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_culling_mode(VkBool32 culling_enabled)¶
Enable or disable culling
Warning
Disabling culling will have a significant performance impact
- Parameters:
culling_enabled –
trueif culling is enabled- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_depth_attachment_format(VkFormat format)¶
Set the deptch attachment format
- Parameters:
format – The format of the depth attachment
- Returns:
A const reference to the this pointer (allowing method calls to be chained)
-
GraphicsPipelineBuilder &set_descriptor_set_layouts(std::vector<VkDescriptorSetLayout> descriptor_set_layouts)¶
Set the descriptor set layout
- Parameters:
descriptor_set_layouts – The descriptor set layout
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_depth_stencil(const VkPipelineDepthStencilStateCreateInfo &depth_stencil)¶
Set the depth stencil
Warning
Disabling culling can have performance impacts!
- Parameters:
depth_stencil – The depth stencil
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_dynamic_states(const std::vector<VkDynamicState> &dynamic_states)¶
Set the dynamic states
- Parameters:
dynamic_states – The dynamic states
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_stencil_attachment_format(VkFormat format)¶
Set the stencil attachment format
- Parameters:
format – The format of the stencil attachment
- Returns:
A const reference to the this pointer (allowing method calls to be chained)
-
GraphicsPipelineBuilder &set_input_assembly(const VkPipelineInputAssemblyStateCreateInfo &input_assembly)¶
Set the input assembly state create info
Note
If you just want to set the triangle topology, call
set_triangle_topologyinstead, because this is the most powerful method of this method in case you really need to overwrite it- Parameters:
input_assembly – The pipeline input state create info
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_line_width(float width)¶
Set the line width of rasterization
- Parameters:
line_width – The line width used in rasterization
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_multisampling(VkSampleCountFlagBits sample_count, std::optional<float> min_sample_shading = std::nullopt)¶
Set the most important MSAA settings
- Parameters:
sample_count – The number of samples used in rasterization
min_sample_shading – A minimum fraction of sample shading
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_pipeline_layout(VkPipelineLayout layout)¶
Store the pipeline layout
- Parameters:
layout – The pipeline layout
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_primitive_topology(VkPrimitiveTopology topology)¶
Set the triangle topology
- Parameters:
topology – the primitive topology
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_render_pass(const VkRenderPass &render_pass)¶
Set the renderpass
- Parameters:
render_pass – The renderpass
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_push_constant_ranges(std::vector<VkPushConstantRange> push_constant_ranges)¶
Set the push constant ranges
- Parameters:
push_constant_ranges – The push constant ranges
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_rasterization(const VkPipelineRasterizationStateCreateInfo &rasterization)¶
Set the rasterization state of the graphics pipeline manually
- Parameters:
rasterization – The rasterization state
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_scissor(const VkRect2D &scissor)¶
Set the scissor data in VkPipelineViewportStateCreateInfo There is another method called set_scissors in case multiple scissors will be used
- Parameters:
scissors – The scissors in in VkPipelineViewportStateCreateInfo
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_scissor(const VkExtent2D &extent)¶
Set the scissor data in VkPipelineViewportStateCreateInfo (convert VkExtent2D to VkRect2D)
- Parameters:
extent – The extent of the scissor
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_shaders(std::vector<VkPipelineShaderStageCreateInfo> shaders)¶
Set the shader modules
- Parameters:
shaders – The shader stage create infos
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_tesselation_control_point_count(std::uint32_t control_point_count)¶
Set the tesselation control point count
Note
This is not used in the code so far, because we are not using tesselation
- Parameters:
control_point_count – The tesselation control point count
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_vertex_input_attributes(const std::vector<VkVertexInputAttributeDescription> &descriptions)¶
Set the vertex input attribute descriptions manually
Note
As of C++23, there is no mechanism to do so called reflection in C++, meaning we can’t get any information about the members of a struct, which would allow us to determine vertex input attributes automatically.
- Parameters:
descriptions – The vertex input attribute descriptions
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_vertex_input_bindings(const std::vector<VkVertexInputBindingDescription> &descriptions)¶
Set the vertex input binding descriptions manually
- Parameters:
descriptions – The vertex input binding descriptions
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_viewport(const VkViewport &viewport)¶
Set the viewport in VkPipelineViewportStateCreateInfo There is another method called set_viewports in case multiple viewports will be used
- Parameters:
viewport – The viewport in VkPipelineViewportStateCreateInfo
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_viewport(const VkExtent2D &extent)¶
Set the viewport in VkPipelineViewportStateCreateInfo (convert VkExtent2D to VkViewport)
- Parameters:
extent – The extent of the viewport
- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
-
GraphicsPipelineBuilder &set_wireframe(VkBool32 wireframe)¶
Set the wireframe mode
- Parameters:
wireframe –
trueif wireframe is enabled- Returns:
A reference to the dereferenced this pointer (allows method calls to be chained)
Private Functions
-
void reset()¶
Reset all data in this class so the builder can be re-used
Note
This is called by the constructor
Private Members
-
const PipelineCache &m_pipeline_cache¶
The Vulkan pipeline cache.
-
std::vector<VkPipelineShaderStageCreateInfo> m_shader_stages¶
-
std::vector<VkVertexInputBindingDescription> m_vertex_input_binding_descriptions¶
-
std::vector<VkVertexInputAttributeDescription> m_vertex_input_attribute_descriptions¶
-
VkPipelineVertexInputStateCreateInfo m_vertex_input_sci¶
-
VkPipelineInputAssemblyStateCreateInfo m_input_assembly_sci¶
-
VkPipelineTessellationStateCreateInfo m_tesselation_sci¶
-
std::vector<VkViewport> m_viewports¶
-
std::vector<VkRect2D> m_scissors¶
-
VkPipelineViewportStateCreateInfo m_viewport_sci¶
-
VkPipelineRasterizationStateCreateInfo m_rasterization_sci¶
-
VkPipelineDepthStencilStateCreateInfo m_depth_stencil_sci¶
-
VkRenderPass m_render_pass¶
-
VkFormat m_depth_attachment_format¶
This is used for dynamic rendering.
-
VkFormat m_stencil_attachment_format¶
-
std::vector<VkFormat> m_color_attachments¶
-
VkPipelineRenderingCreateInfo m_pipeline_rendering_ci¶
-
VkPipelineMultisampleStateCreateInfo m_multisample_sci¶
-
VkPipelineColorBlendStateCreateInfo m_color_blend_sci¶
-
std::vector<VkDynamicState> m_dynamic_states¶
-
VkPipelineDynamicStateCreateInfo m_dynamic_states_sci¶
-
VkPipelineLayout m_pipeline_layout¶
The layout of the graphics pipeline.
-
std::vector<VkPipelineColorBlendAttachmentState> m_color_blend_attachment_states¶
-
std::vector<VkPushConstantRange> m_push_constant_ranges¶
The push constant ranges of the graphics pass.
-
std::vector<VkDescriptorSetLayout> m_descriptor_set_layouts¶
-
GraphicsPipelineBuilder(const Device &device, const PipelineCache &pipeline_cache)¶