Repository navigation
Expand file tree
/
Copy pathrender_pipeline.hpp
More file actions
479 lines (396 loc) · 11.7 KB
/
Copy pathrender_pipeline.hpp
File metadata and controls
479 lines (396 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
/**
* @file liblava/block/render_pipeline.hpp
* @brief Render pipeline (Graphics)
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/block/pipeline.hpp"
namespace lava {
/**
* @brief Render pipeline (Graphics)
*/
struct render_pipeline : pipeline {
/// Shared pointer to render pipeline
using s_ptr = std::shared_ptr<render_pipeline>;
/// Map of render pipelines
using s_map = std::map<id, s_ptr>;
/// List of render pipelines
using s_list = std::vector<s_ptr>;
/**
* @brief Sizing modes
*/
enum class sizing_mode : index {
input = 0,
absolute,
relative
};
/**
* @brief Render pipeline create information
*/
struct create_info {
/// Vertex input stage
VkPipelineVertexInputStateCreateInfo vertex_input_state;
/// Input assembly state
VkPipelineInputAssemblyStateCreateInfo input_assembly_state;
/// Viewport state
VkPipelineViewportStateCreateInfo viewport_state;
/// Multisample state
VkPipelineMultisampleStateCreateInfo multisample_state;
/// Depth stencil state
VkPipelineDepthStencilStateCreateInfo depth_stencil_state;
/// Rasterization state
VkPipelineRasterizationStateCreateInfo rasterization_state;
};
/**
* @brief Make a new render pipeline
* @param device Vulkan device
* @param pipeline_cache Pipeline cache
* @return s_ptr Shared pointer to render pipeline
*/
static s_ptr make(device::ptr device,
VkPipelineCache pipeline_cache = 0) {
return std::make_shared<render_pipeline>(device, pipeline_cache);
}
/**
* @brief Construct a new render pipeline
* @param device Vulkan device
* @param pipeline_cache Pipeline cache
*/
explicit render_pipeline(device::ptr device,
VkPipelineCache pipeline_cache);
/**
* @brief Bind the pipeline
* @param cmd_buf Command buffer
*/
void bind(VkCommandBuffer cmd_buf) override;
/**
* @brief Set the viewport and scissor
* @param cmd_buf Command buffer
* @param size Viewport and scissor size
*/
void set_viewport_and_scissor(VkCommandBuffer cmd_buf,
uv2 size);
/**
* @brief Set the render pass
* @param pass Render pass
*/
void set_render_pass(VkRenderPass pass) {
m_render_pass = pass;
}
/**
* @see set_render_pass
*/
void set(VkRenderPass pass) {
set_render_pass(pass);
}
/**
* @brief Get the render pass
* @return VkRenderPass Render pass
*/
VkRenderPass get_render_pass() const {
return m_render_pass;
}
/**
* @brief Get the subpass
* @return index Index of subpass
*/
index get_subpass() const {
return m_subpass;
}
/**
* @brief Set the subpass
* @param value Index of subpass
*/
void set_subpass(index value) {
m_subpass = value;
}
/**
* @brief Create a new render pipeline
* @param pass Vulkan render pass
* @return Create was successful or failed
*/
bool create(VkRenderPass pass) {
set(pass);
return pipeline::create();
}
/**
* @brief Set the vertex input binding
* @param description Vertex input binding description
*/
void set_vertex_input_binding(VkVertexInputBindingDescription const& description);
/**
* @brief Set the vertex input bindings
* @param descriptions List of vertex input binding descriptions
*/
void set_vertex_input_bindings(VkVertexInputBindingDescriptions const& descriptions);
/**
* @brief Set the vertex input attribute
* @param attribute Vertex input attribute description
*/
void set_vertex_input_attribute(VkVertexInputAttributeDescription const& attribute);
/**
* @brief Set the vertex input attributes
* @param attributes List of vertex input attributes descriptions
*/
void set_vertex_input_attributes(VkVertexInputAttributeDescriptions const& attributes);
/**
* @brief Set the input assembler's topology
* @param topology Enum describing polygon primitives
*/
void set_input_topology(VkPrimitiveTopology const& topology);
/**
* @brief Set the depth test and write
* @param test_enable Enable depth test
* @param write_enable Enable depth write
*/
void set_depth_test_and_write(bool test_enable = true,
bool write_enable = true);
/**
* @brief Set the depth compare operation
* @param compare_op Depth compare operation
*/
void set_depth_compare_op(VkCompareOp compare_op);
/**
* @brief Set the rasterization cull mode
* @param cull_mode Cull mode flags
*/
void set_rasterization_cull_mode(VkCullModeFlags cull_mode);
/**
* @brief Set the rasterization front face
* @param front_face Front face
*/
void set_rasterization_front_face(VkFrontFace front_face);
/**
* @brief Set the rasterization polygon mode
* @param polygon_mode Polygon mode
*/
void set_rasterization_polygon_mode(VkPolygonMode polygon_mode);
/**
* @brief Add color blend attachment
* @param attachment Pipeline color blend attachment state
*/
void add_color_blend_attachment(VkPipelineColorBlendAttachmentState const& attachment);
/**
* @brief Add color blend attachment (default)
*/
void add_color_blend_attachment();
/**
* @brief Clear color blend attachment
*/
void clear_color_blend_attachment();
/**
* @brief Set the dynamic states
* @param states List of dynamic states
*/
void set_dynamic_states(VkDynamicStates const& states);
/**
* @brief Add a dynamic state
* @param state Dynamic state
*/
void add_dynamic_state(VkDynamicState state);
/**
* @brief Clear dynamic states
*/
void clear_dynamic_states();
/**
* @brief Add shader stage
* @param data Shader data
* @param stage Shader stage flag bits
* @return Add was successful or failed
*/
bool add_shader_stage(c_data::ref data,
VkShaderStageFlagBits stage);
/**
* @brief Add shader
* @param data Shader data
* @param stage Shader stage flag bits
* @return Add was successful or failed
*/
bool add_shader(c_data::ref data,
VkShaderStageFlagBits stage) {
return add_shader_stage(data, stage);
}
/**
* @brief Add shader stage
* @param shader_stage Shader stage
*/
void add(shader_stage::s_ptr const& shader_stage) {
m_shader_stages.push_back(shader_stage);
}
/**
* @brief Get the shader stages
* @return shader_stage::s_list const& List of shader stages
*/
shader_stage::s_list const& get_shader_stages() const {
return m_shader_stages;
}
/**
* @brief Clear the shader stages
*/
void clear_shader_stages() {
m_shader_stages.clear();
}
/**
* @brief Clear the render pipeline
*/
void clear() {
clear_color_blend_attachment();
clear_shader_stages();
}
/**
* @brief Set the auto size
* @param value Enable state
*/
void set_auto_size(bool value = true) {
m_auto_size = value;
}
/**
* @brief Get the auto sizing state
* @return Auto sizing is enabled or not
*/
bool auto_sizing() const {
return m_auto_size;
}
/**
* @brief Get the viewport
* @return VkViewport Vulkan viewport
*/
VkViewport get_viewport() const {
return m_viewport;
}
/**
* @brief Set the viewport
* @param value Vulkan viewport
*/
void set_viewport(VkViewport value) {
m_viewport = value;
}
/**
* @brief Get the scissor
* @return VkRect2D Scissor rectangle
*/
VkRect2D get_scissor() const {
return m_scissor;
}
/**
* @brief Set the scissor
* @param value Scissor rectangle
*/
void set_scissor(VkRect2D value) {
m_scissor = value;
}
/**
* @brief Get the sizing
* @return sizing_mode Sizing mode
*/
sizing_mode get_sizing() const {
return m_sizing;
}
/**
* @brief Set the sizing
* @param value Sizing mode
*/
void set_sizing(sizing_mode value) {
m_sizing = value;
}
/**
* @brief Copy pipeline configuration to target
* @param target Render pipeline
*/
void copy_to(render_pipeline* target) const;
/**
* @brief Copy pipeline configuration from source
* @param source Render pipeline
*/
void copy_from(s_ptr const& source) {
source->copy_to(this);
}
/**
* @brief Set the line width
* @param value Line width
*/
void set_line_width(r32 value) {
m_line_width = value;
}
/**
* @brief Get the line width
* @return r32 Line width
*/
r32 get_line_width() const {
return m_line_width;
}
/**
* @brief Check if auto line width is active
* @return Auto line width is enabled or not
*/
bool auto_line_width() const {
return m_auto_line_width_state;
}
/**
* @brief Set the auto line width
* @param value Enable state
*/
void set_auto_line_width(bool value = true) {
m_auto_line_width_state = value;
}
/**
* @brief Set the line width
* @param cmd_buf Command buffer
*/
void set_line_width(VkCommandBuffer cmd_buf) {
vkCmdSetLineWidth(cmd_buf, m_line_width);
}
/// Create function
using create_func = std::function<bool(create_info&)>;
/// Called on render pipeline create
create_func on_create;
private:
/**
* @brief Set up the render pipeline
* @return Setup was successful or failed
*/
bool setup() override;
/**
* @brief Tear down the render pipeline
*/
void teardown() override;
/// Vulkan render pass
VkRenderPass m_render_pass = VK_NULL_HANDLE;
/// Subpass index
index m_subpass = 0;
/// Create information
create_info m_info;
/// List of vertex input binding descriptions
VkVertexInputBindingDescriptions m_vertex_input_bindings;
/// List of vertex input attribute descriptions
VkVertexInputAttributeDescriptions m_vertex_input_attributes;
/// List of pipeline color blend attachment states
VkPipelineColorBlendAttachmentStates m_color_blend_attachment_states;
/// Pipeline color blend state create information
VkPipelineColorBlendStateCreateInfo m_color_blend_state;
/// Pipeline dynamic state create information
VkPipelineDynamicStateCreateInfo m_dynamic_state;
/// List of dynamic states
VkDynamicStates m_dynamic_states;
/// List of shader stages
shader_stage::s_list m_shader_stages;
/// Sizing mode
sizing_mode m_sizing = sizing_mode::input;
/// Vulkan viewport
VkViewport m_viewport;
/// Scissor rectangle
VkRect2D m_scissor;
/// Auto size
bool m_auto_size = true;
/// Auto line width state
bool m_auto_line_width_state = false;
/// Line width
r32 m_line_width = 1.f;
};
/**
* @brief Create a color blend attachment
* @return VkPipelineColorBlendAttachmentState Pipeline color blend attachment state
*/
VkPipelineColorBlendAttachmentState create_pipeline_color_blend_attachment();
} // namespace lava