-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathsubpass.hpp
More file actions
357 lines (302 loc) · 9.31 KB
/
Copy pathsubpass.hpp
File metadata and controls
357 lines (302 loc) · 9.31 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
/**
* @file liblava/block/subpass.hpp
* @brief Subpass
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/block/render_pipeline.hpp"
namespace lava {
/**
* @brief Subpass
*/
struct subpass : entity {
/// Shared pointer to subpass
using s_ptr = std::shared_ptr<subpass>;
/// List of subpasses
using s_list = std::vector<s_ptr>;
/**
* @brief Make a new subpass
* @param pipeline_bind_point Pipeline bind point
* @return s_ptr Shared pointer to subpass
*/
static s_ptr make(VkPipelineBindPoint pipeline_bind_point =
VK_PIPELINE_BIND_POINT_GRAPHICS) {
auto result = std::make_shared<subpass>();
result->set(pipeline_bind_point);
return result;
}
/**
* @brief Construct a new subpass
*/
explicit subpass();
/**
* @brief Destroy the subpass
*/
void destroy();
/**
* @brief Add a render pipeline to the back of the subpass
* @param pipeline Render pipeline
*/
void add(render_pipeline::s_ptr const& pipeline) {
m_pipelines.push_back(pipeline);
}
/**
* @brief Add a render pipeline to the fronst of the subpass
* @param pipeline Render pipeline
*/
void add_front(render_pipeline::s_ptr const& pipeline) {
m_pipelines.insert(m_pipelines.begin(), pipeline);
}
/**
* @brief Remove the render pipeline
* @param pipeline Render pipeline
*/
void remove(render_pipeline::s_ptr pipeline);
/**
* @brief Clear all pipelines
*/
void clear_pipelines();
/**
* @brief Process the subpass
* @param cmd_buf Command buffer
* @param size Size of render pass
*/
void process(VkCommandBuffer cmd_buf,
uv2 size);
/**
* @brief Get the description
* @return VkSubpassDescription const& Subpass description
*/
VkSubpassDescription const& get_description() const {
return m_description;
}
/**
* @brief Set pipeline bind point
* @param pipeline_bind_point Pipeline bind point
*/
void set(VkPipelineBindPoint pipeline_bind_point) {
m_description.pipelineBindPoint = pipeline_bind_point;
}
/**
* @brief Set the color attachment
* @param attachment Index of attachment
* @param layout Image layout
*/
void set_color_attachment(index attachment,
VkImageLayout layout);
/**
* @brief Set the color attachment
* @param attachment Attachment reference
*/
void set_color_attachment(VkAttachmentReference attachment);
/**
* @brief Set the color attachments
* @param attachments List of attachment references
*/
void set_color_attachments(VkAttachmentReferences const& attachments);
/**
* @brief Set the depth stencil attachment
* @param attachment Index of attachment
* @param layout Image layout
*/
void set_depth_stencil_attachment(index attachment,
VkImageLayout layout);
/**
* @brief Set the depth stencil attachment
* @param attachment Attachment reference
*/
void set_depth_stencil_attachment(VkAttachmentReference attachment);
/**
* @brief Set the input attachment
* @param attachment Index of attachment
* @param layout Image layout
*/
void set_input_attachment(index attachment,
VkImageLayout layout);
/**
* @brief Set the input attachment
* @param attachment Attachment reference
*/
void set_input_attachment(VkAttachmentReference attachment);
/**
* @brief Set the input attachments
* @param attachments List of attachment references
*/
void set_input_attachments(VkAttachmentReferences const& attachments);
/**
* @brief Set the resolve attachment
* @param attachment Index of attachment
* @param layout Image layout
*/
void set_resolve_attachment(index attachment, VkImageLayout layout);
/**
* @brief Set the resolve attachment
* @param attachment Attachment reference
*/
void set_resolve_attachment(VkAttachmentReference attachment);
/**
* @brief Set the resolve attachments
* @param attachments List of attachment references
*/
void set_resolve_attachments(VkAttachmentReferences const& attachments);
/**
* @brief Add preserve attachment
* @param attachment Index of attachment
*/
void add_preserve_attachment(index attachment);
/**
* @brief Set the preserve attachments
* @param attachments List of indices
*/
void set_preserve_attachments(index_list const& attachments);
/**
* @brief Activate or deactivate the subpass
* @param value Enable state
*/
void set_active(bool value = true) {
m_active = value;
}
/**
* @brief Check if subpass is active
* @return Subpass is active or not
*/
bool activated() const {
return m_active;
}
private:
/// Vulkan subpass description
VkSubpassDescription m_description;
//// Active state
bool m_active = true;
/// List of color attachment references
VkAttachmentReferences m_color_attachments;
/// Depth stencil attachment reference
VkAttachmentReference m_depth_stencil_attachment{};
/// List of input attachment references
VkAttachmentReferences m_input_attachments;
/// List of resolve attachment references
VkAttachmentReferences m_resolve_attachments;
/// List of preserve attachment indicies
index_list m_preserve_attachments;
/// List of render pipelines
render_pipeline::s_list m_pipelines;
};
/**
* @brief Subpass dependency
*/
struct subpass_dependency {
/// Shared pointer to subpass dependency
using s_ptr = std::shared_ptr<subpass_dependency>;
/// List of subpass dependencies
using s_list = std::vector<s_ptr>;
/**
* @brief Make a new subpass dependency
* @param src_subpass Source subpass
* @param dst_subpass Destination subpass
* @param dependency_flags Dependency flags
* @return s_ptr Shared pointer to subpass dependency
*/
static s_ptr make(ui32 src_subpass,
ui32 dst_subpass,
VkDependencyFlags dependency_flags =
VK_DEPENDENCY_BY_REGION_BIT) {
auto result = std::make_shared<subpass_dependency>();
result->set_subpass(src_subpass, dst_subpass);
result->set_dependency_flags(dependency_flags);
return result;
}
/**
* @brief Construct a new subpass dependency
*/
explicit subpass_dependency();
/**
* @brief Get the dependency
* @return VkSubpassDependency const& Vulkan subpass dependency
*/
VkSubpassDependency const& get_dependency() const {
return m_dependency;
}
/**
* @brief Set the subpass
* @param src Source Subpass
* @param dst Destination Subpass
*/
void set_subpass(ui32 src, ui32 dst) {
set_src_subpass(src);
set_dst_subpass(dst);
}
/**
* @brief Set the source subpass
* @param src Source Subpass
*/
void set_src_subpass(ui32 src) {
m_dependency.srcSubpass = src;
}
/**
* @brief Set the dst subpass
* @param dst Destination subpass
*/
void set_dst_subpass(ui32 dst) {
m_dependency.dstSubpass = dst;
}
/**
* @brief Set the stage mask
* @param src Source pipeline stage flags
* @param dst Destination pipeline stage flags
*/
void set_stage_mask(VkPipelineStageFlags src,
VkPipelineStageFlags dst) {
set_src_stage_mask(src);
set_dst_stage_mask(dst);
}
/**
* @brief Set the source stage mask
* @param mask Pipeline stage flags
*/
void set_src_stage_mask(VkPipelineStageFlags mask) {
m_dependency.srcStageMask = mask;
}
/**
* @brief Set the destination stage mask
* @param mask Pipeline stage flags
*/
void set_dst_stage_mask(VkPipelineStageFlags mask) {
m_dependency.dstStageMask = mask;
}
/**
* @brief Set the access mask
* @param src Source access flags
* @param dst Destination access flags
*/
void set_access_mask(VkAccessFlags src,
VkAccessFlags dst) {
set_src_access_mask(src);
set_dst_access_mask(dst);
}
/**
* @brief Set the src access mask
* @param mask Access flags
*/
void set_src_access_mask(VkAccessFlags mask) {
m_dependency.srcAccessMask = mask;
}
/**
* @brief Set the dst access mask
* @param mask Access flags
*/
void set_dst_access_mask(VkAccessFlags mask) {
m_dependency.dstAccessMask = mask;
}
/**
* @brief Set the dependency flags
* @param flags Dependency flags
*/
void set_dependency_flags(VkDependencyFlags flags) {
m_dependency.dependencyFlags = flags;
}
private:
/// Vulkan subpass dependency
VkSubpassDependency m_dependency;
};
} // namespace lava