PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
PipelineGraphics.hpp
1#pragma once
2
3#include "PixelBullet/Filesystem/VirtualPath.hpp"
4#include "PixelBullet/Graphics/Pipelines/Pipeline.hpp"
5#include "PixelBullet/Graphics/RenderStage.hpp"
6
7#include <array>
8#include <optional>
9#include <stdexcept>
10#include <vector>
11
12namespace PixelBullet
13{
14 class ImageDepth;
15 class Image2D;
16
21 {
22 public:
23 enum class Mode
24 {
25 Polygon,
26 MRT
27 };
28
29 enum class Depth
30 {
31 None = 0,
32 Read = 1,
33 Write = 2,
34 ReadWrite = Read | Write
35 };
36
51 PipelineGraphics(Stage stage, std::vector<VirtualPath> shaderStages,
52 std::vector<Shader::VertexInput> vertexInputs, std::vector<Shader::Define> defines = {},
53 Mode mode = Mode::Polygon, Depth depth = Depth::ReadWrite,
54 VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
55 VkPolygonMode polygonMode = VK_POLYGON_MODE_FILL,
56 VkCullModeFlags cullMode = VK_CULL_MODE_BACK_BIT,
57 VkFrontFace frontFace = VK_FRONT_FACE_CLOCKWISE, bool pushDescriptors = false);
59
65 const ImageDepth* GetDepthStencil(const std::optional<uint32_t>& stage = std::nullopt) const;
66
73 const Image2D* GetImage(uint32_t index, const std::optional<uint32_t>& stage = std::nullopt) const;
74
80 RenderArea GetRenderArea(const std::optional<uint32_t>& stage = std::nullopt) const;
81
82 const Stage& GetStage() const
83 {
84 return m_Stage;
85 }
86 const std::vector<VirtualPath>& GetShaderStages() const
87 {
88 return m_ShaderStages;
89 }
90 const std::vector<Shader::VertexInput>& GetVertexInputs() const
91 {
92 return m_VertexInputs;
93 }
94 const std::vector<Shader::Define>& GetDefines() const
95 {
96 return m_Defines;
97 }
98 Mode GetMode() const
99 {
100 return m_Mode;
101 }
102 Depth GetDepth() const
103 {
104 return m_Depth;
105 }
106 VkPrimitiveTopology GetTopology() const
107 {
108 return m_Topology;
109 }
110 VkPolygonMode GetPolygonMode() const
111 {
112 return m_PolygonMode;
113 }
114 VkCullModeFlags GetCullMode() const
115 {
116 return m_CullMode;
117 }
118 VkFrontFace GetFrontFace() const
119 {
120 return m_FrontFace;
121 }
122 bool IsPushDescriptors() const override
123 {
124 return m_PushDescriptors;
125 }
126 const Shader* GetShader() const override
127 {
128 return m_Shader.get();
129 }
130 const VkDescriptorSetLayout& GetDescriptorSetLayout() const override
131 {
132 return m_DescriptorSetLayout;
133 }
134 const VkDescriptorPool& GetDescriptorPool() const override
135 {
136 return m_DescriptorPool;
137 }
138 const VkPipeline& GetPipeline() const override
139 {
140 return m_Pipeline;
141 }
142 const VkPipelineLayout& GetPipelineLayout() const override
143 {
144 return m_PipelineLayout;
145 }
146 const VkPipelineBindPoint& GetPipelineBindPoint() const override
147 {
148 return m_PipelineBindPoint;
149 }
150
151 private:
152 void CreateShaderProgram();
153 void CreateDescriptorLayout();
154 void CreateDescriptorPool();
155 void CreatePipelineLayout();
156 void CreateAttributes();
157 void CreatePipeline();
158 void CreatePipelinePolygon();
159 void CreatePipelineMrt();
160
161 private:
162 Stage m_Stage;
163 std::vector<VirtualPath> m_ShaderStages;
164 std::vector<Shader::VertexInput> m_VertexInputs;
165 std::vector<Shader::Define> m_Defines;
166 Mode m_Mode;
167 Depth m_Depth;
168 VkPrimitiveTopology m_Topology;
169 VkPolygonMode m_PolygonMode;
170 VkCullModeFlags m_CullMode;
171 VkFrontFace m_FrontFace;
172 bool m_PushDescriptors;
173
174 std::unique_ptr<Shader> m_Shader;
175
176 std::vector<VkDynamicState> m_DynamicStates;
177
178 std::vector<VkShaderModule> m_Modules;
179 std::vector<VkPipelineShaderStageCreateInfo> m_Stages;
180
181 VkDescriptorSetLayout m_DescriptorSetLayout = VK_NULL_HANDLE;
182 VkDescriptorPool m_DescriptorPool = VK_NULL_HANDLE;
183
184 VkPipeline m_Pipeline = VK_NULL_HANDLE;
185 VkPipelineLayout m_PipelineLayout = VK_NULL_HANDLE;
186 VkPipelineBindPoint m_PipelineBindPoint;
187
188 VkPipelineVertexInputStateCreateInfo m_VertexInputStateCreateInfo = {};
189 VkPipelineInputAssemblyStateCreateInfo m_InputAssemblyState = {};
190 VkPipelineRasterizationStateCreateInfo m_RasterizationState = {};
191 std::array<VkPipelineColorBlendAttachmentState, 1> m_BlendAttachmentStates;
192 VkPipelineColorBlendStateCreateInfo m_ColorBlendState = {};
193 VkPipelineDepthStencilStateCreateInfo m_DepthStencilState = {};
194 VkPipelineViewportStateCreateInfo m_ViewportState = {};
195 VkPipelineMultisampleStateCreateInfo m_MultisampleState = {};
196 VkPipelineDynamicStateCreateInfo m_DynamicState = {};
197 VkPipelineTessellationStateCreateInfo m_TessellationState = {};
198 };
199
201 {
202 public:
203 PipelineGraphicsCreate(std::vector<VirtualPath> shaderStages = {},
204 std::vector<Shader::VertexInput> vertexInputs = {},
205 std::vector<Shader::Define> defines = {},
206 PipelineGraphics::Mode mode = PipelineGraphics::Mode::Polygon,
207 PipelineGraphics::Depth depth = PipelineGraphics::Depth::ReadWrite,
208 VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
209 VkPolygonMode polygonMode = VK_POLYGON_MODE_FILL,
210 VkCullModeFlags cullMode = VK_CULL_MODE_BACK_BIT,
211 VkFrontFace frontFace = VK_FRONT_FACE_CLOCKWISE, bool pushDescriptors = false)
212 : m_ShaderStages(std::move(shaderStages))
213 , m_VertexInputs(std::move(vertexInputs))
214 , m_Defines(std::move(defines))
215 , m_Mode(mode)
216 , m_Depth(depth)
217 , m_Topology(topology)
218 , m_PolygonMode(polygonMode)
219 , m_CullMode(cullMode)
220 , m_FrontFace(frontFace)
221 , m_PushDescriptors(pushDescriptors)
222 {
223 }
224
230 PipelineGraphics* Create(const Pipeline::Stage& pipelineStage) const
231 {
232 return new PipelineGraphics(pipelineStage, m_ShaderStages, m_VertexInputs, m_Defines, m_Mode, m_Depth,
233 m_Topology, m_PolygonMode, m_CullMode, m_FrontFace, m_PushDescriptors);
234 }
235
236 friend const Node& operator>>(const Node& node, PipelineGraphicsCreate& pipelineCreate)
237 {
238 node["shaderStages"] >> pipelineCreate.m_ShaderStages;
239 node["vertexInputs"] >> pipelineCreate.m_VertexInputs;
240 node["defines"] >> pipelineCreate.m_Defines;
241 node["mode"] >> pipelineCreate.m_Mode;
242 node["depth"] >> pipelineCreate.m_Depth;
243 node["polygonMode"] >> pipelineCreate.m_PolygonMode;
244 node["cullMode"] >> pipelineCreate.m_CullMode;
245 node["frontFace"] >> pipelineCreate.m_FrontFace;
246 node["pushDescriptors"] >> pipelineCreate.m_PushDescriptors;
247 return node;
248 }
249
250 friend Node& operator<<(Node& node, const PipelineGraphicsCreate& pipelineCreate)
251 {
252 node["shaderStages"] << pipelineCreate.m_ShaderStages;
253 node["vertexInputs"] << pipelineCreate.m_VertexInputs;
254 node["defines"] << pipelineCreate.m_Defines;
255 node["mode"] << pipelineCreate.m_Mode;
256 node["depth"] << pipelineCreate.m_Depth;
257 node["polygonMode"] << pipelineCreate.m_PolygonMode;
258 node["cullMode"] << pipelineCreate.m_CullMode;
259 node["frontFace"] << pipelineCreate.m_FrontFace;
260 node["pushDescriptors"] << pipelineCreate.m_PushDescriptors;
261 return node;
262 }
263
264 const std::vector<VirtualPath>& GetShaderStages() const
265 {
266 return m_ShaderStages;
267 }
268
269 const std::vector<Shader::VertexInput>& GetVertexInputs() const
270 {
271 return m_VertexInputs;
272 }
273 const std::vector<Shader::Define>& GetDefines() const
274 {
275 return m_Defines;
276 }
277 PipelineGraphics::Mode GetMode() const
278 {
279 return m_Mode;
280 }
281 PipelineGraphics::Depth GetDepth() const
282 {
283 return m_Depth;
284 }
285 VkPrimitiveTopology GetTopology() const
286 {
287 return m_Topology;
288 }
289 VkPolygonMode GetPolygonMode() const
290 {
291 return m_PolygonMode;
292 }
293 VkCullModeFlags GetCullMode() const
294 {
295 return m_CullMode;
296 }
297 VkFrontFace GetFrontFace() const
298 {
299 return m_FrontFace;
300 }
301 bool GetPushDescriptors() const
302 {
303 return m_PushDescriptors;
304 }
305
306 private:
307 std::vector<VirtualPath> m_ShaderStages;
308 std::vector<Shader::VertexInput> m_VertexInputs;
309 std::vector<Shader::Define> m_Defines;
310
311 PipelineGraphics::Mode m_Mode;
312 PipelineGraphics::Depth m_Depth;
313 VkPrimitiveTopology m_Topology;
314 VkPolygonMode m_PolygonMode;
315 VkCullModeFlags m_CullMode;
316 VkFrontFace m_FrontFace;
317 bool m_PushDescriptors;
318 };
319} // namespace PixelBullet
Resource that represents a 2D image.
Definition Image2D.hpp:18
Resource that represents a depth‑stencil image.
Definition ImageDepth.hpp:13
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition Node.hpp:51
Definition PipelineGraphics.hpp:201
PipelineGraphics * Create(const Pipeline::Stage &pipelineStage) const
Definition PipelineGraphics.hpp:230
Class that represents a graphics pipeline.
Definition PipelineGraphics.hpp:21
const ImageDepth * GetDepthStencil(const std::optional< uint32_t > &stage=std::nullopt) const
Definition PipelineGraphics.cpp:78
const Image2D * GetImage(uint32_t index, const std::optional< uint32_t > &stage=std::nullopt) const
Definition PipelineGraphics.cpp:83
RenderArea GetRenderArea(const std::optional< uint32_t > &stage=std::nullopt) const
Definition PipelineGraphics.cpp:92
PipelineGraphics(Stage stage, std::vector< VirtualPath > shaderStages, std::vector< Shader::VertexInput > vertexInputs, std::vector< Shader::Define > defines={}, Mode mode=Mode::Polygon, Depth depth=Depth::ReadWrite, VkPrimitiveTopology topology=VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, VkPolygonMode polygonMode=VK_POLYGON_MODE_FILL, VkCullModeFlags cullMode=VK_CULL_MODE_BACK_BIT, VkFrontFace frontFace=VK_FRONT_FACE_CLOCKWISE, bool pushDescriptors=false)
Definition PipelineGraphics.cpp:14
Class that is used to represent a pipeline.
Definition Pipeline.hpp:12
std::pair< uint32_t, uint32_t > Stage
Definition Pipeline.hpp:17
Definition RenderStage.hpp:106
Class that loads and processes a shader, and provides reflection.
Definition Shader.hpp:22