vOOlkan
An object oriented approach to Vulkan
Pipeline.h
Go to the documentation of this file.
1#ifndef VULKAN_PIPELINE
2#define VULKAN_PIPELINE
3
4#include <vulkan/vulkan.h>
5#include <glm/glm.hpp>
6#include <vector>
7#include <concepts>
8
9#include "LogicalDevice.h"
10#include "Attachment.h"
12#include "DepthStencil.h"
13#include "DynamicState.h"
14#include "InputAssembly.h"
15#include "Multisampler.h"
17#include "PipelineLayout.h"
18#include "Rasterizer.h"
19#include "RenderPass.h"
20#include "Shader.h"
21#include "Subpass.h"
22#include "VertexInput.h"
23#include "Viewport.h"
24
25
26namespace Vulkan { class Pipeline; }
27
29
30public:
31
33 const LogicalDevice& virtualGpu,
34 const PipelineOptions::RenderPass& renderPass,
35 int subpassIndex,
36 const std::vector<PipelineOptions::Shader*>& shaders,
37 const PipelineOptions::PipelineVertexArrays& vertexArraysDescriptor,
38 const PipelineOptions::PipelineLayout& pipelineLayout,
39 const PipelineOptions::Rasterizer& rasterizer,
42 const PipelineOptions::DepthStencil& depthStencil = PipelineOptions::DepthStencil{},
43 const PipelineOptions::DynamicState& dynamicState = PipelineOptions::DynamicState{},
44 const PipelineOptions::Viewport& viewport = PipelineOptions::Viewport{}
45 ) : virtualGpu{ virtualGpu }, pipelineLayout{ pipelineLayout } {
46 //create the array of VkPipelineShaderStageCreateInfo starting from the shaders
47 std::vector<VkPipelineShaderStageCreateInfo> shadersDescriptors;
48 for (const auto& shader : shaders) {
49 shadersDescriptors.push_back(+*shader);
50 }
51
52 //create the PipelineColorBlendingModes object starting from the subpass
53 PipelineOptions::PipelineColorBlendingModes pipelineColorBlendingModes{ renderPass.getSubpass(subpassIndex) };
54
55
56 VkGraphicsPipelineCreateInfo pipelineInfo{};
57 pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
58 pipelineInfo.pNext = nullptr;
59 pipelineInfo.stageCount = shadersDescriptors.size();
60 pipelineInfo.pStages = shadersDescriptors.data();
61 pipelineInfo.pVertexInputState = &+vertexArraysDescriptor;
62 pipelineInfo.pInputAssemblyState = &+inputAssembly;
63 pipelineInfo.pViewportState = &+viewport;
64 pipelineInfo.pRasterizationState = &+rasterizer;
65 pipelineInfo.pMultisampleState = &+multisampler;
66 pipelineInfo.pDepthStencilState = &+depthStencil;
67 pipelineInfo.pColorBlendState = &+pipelineColorBlendingModes;
68 pipelineInfo.pDynamicState = &+dynamicState;
69 pipelineInfo.layout = +pipelineLayout;
70 pipelineInfo.renderPass = +renderPass;
71 pipelineInfo.subpass = subpassIndex;
72 pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
73 pipelineInfo.basePipelineIndex = -1;
74
75 if (VkResult result = vkCreateGraphicsPipelines(+virtualGpu, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline); result != VK_SUCCESS) {
76 throw VulkanException("Failed to create graphics pipeline!", result);
77 }
78 }
79
80 Pipeline(const Pipeline&&) = delete;
81 Pipeline(Pipeline&&) = delete;
82 Pipeline& operator=(const Pipeline&) = delete;
84
86 vkDestroyPipeline(+virtualGpu, pipeline, nullptr);
87 }
88
89 const VkPipeline& operator+() const {
90 return pipeline;
91 }
92
93
95 return pipelineLayout;
96 }
97
98private:
99 VkPipeline pipeline;
100 const LogicalDevice& virtualGpu;
101 const PipelineOptions::PipelineLayout& pipelineLayout;
102};
103
104
105#endif
A logical device is an abstraction of the physical GPU which we can mainly use to send commands.
Definition: LogicalDevice.h:15
Definition: Pipeline.h:28
Pipeline & operator=(const Pipeline &)=delete
~Pipeline()
Definition: Pipeline.h:85
Pipeline(const Pipeline &&)=delete
Pipeline(Pipeline &&)=delete
const VkPipeline & operator+() const
Definition: Pipeline.h:89
Pipeline(const LogicalDevice &virtualGpu, const PipelineOptions::RenderPass &renderPass, int subpassIndex, const std::vector< PipelineOptions::Shader * > &shaders, const PipelineOptions::PipelineVertexArrays &vertexArraysDescriptor, const PipelineOptions::PipelineLayout &pipelineLayout, const PipelineOptions::Rasterizer &rasterizer, const PipelineOptions::InputAssembly &inputAssembly=PipelineOptions::InputAssembly{}, const PipelineOptions::Multisampler &multisampler=PipelineOptions::Multisampler{}, const PipelineOptions::DepthStencil &depthStencil=PipelineOptions::DepthStencil{}, const PipelineOptions::DynamicState &dynamicState=PipelineOptions::DynamicState{}, const PipelineOptions::Viewport &viewport=PipelineOptions::Viewport{})
Definition: Pipeline.h:32
Pipeline & operator=(Pipeline &&)=delete
const PipelineOptions::PipelineLayout & getLayout() const
Definition: Pipeline.h:94
Describes how the vertices will be connected. e.g. triangle list, triangle fan, .....
Definition: InputAssembly.h:11
Definition: Multisampler.h:10
This objects is a reference to all of the resources (e.g. uniforms) that the pipeline can access.
Definition: PipelineLayout.h:19
Describes how the vertices will be transformed to fragments to be drawn on screen.
Definition: Rasterizer.h:13
A RenderPass is the set of attachments, the way they are used, and the rendering work that is perform...
Definition: RenderPass.h:20
RenderPassOptions::Subpass getSubpass(unsigned int i) const
Returns the subpasses of this render pass.
Definition: RenderPass.h:87
Types of queue families.
Definition: Animations.h:17