Repository navigation
Expand file tree
/
Copy pathpipeline.hpp
More file actions
268 lines (221 loc) · 6.48 KB
/
Copy pathpipeline.hpp
File metadata and controls
268 lines (221 loc) · 6.48 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
/**
* @file liblava/block/pipeline.hpp
* @brief Pipeline
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/block/pipeline_layout.hpp"
namespace lava {
/**
* @brief Pipeline
*/
struct pipeline : entity {
/// Shared pointer to pipeline
using s_ptr = std::shared_ptr<pipeline>;
/// List of pipelines
using s_list = std::vector<s_ptr>;
/// Pipeline process function
using process_func = std::function<void(VkCommandBuffer)>;
/// Called on pipeline process
process_func on_process;
/**
* @brief Construct a new pipeline
* @param device Vulkan device
* @param pipeline_cache Pipeline cache
*/
explicit pipeline(device::ptr device,
VkPipelineCache pipeline_cache = 0);
/**
* @brief Destroy the pipeline
*/
~pipeline() override;
/**
* @brief Create a new pipeline
* @return Create was successful or failed
*/
bool create();
/**
* @brief Destroy the pipeline
*/
void destroy();
/**
* @brief Bind the pipeline
* @param cmd_buf Command buffer
*/
virtual void bind(VkCommandBuffer cmd_buf) = 0;
/**
* @brief Set pipeline active
* @param value Active state
*/
void set_active(bool value = true) {
m_active = value;
}
/**
* @brief Check if pipeline is active
* @return Pipeline is active or note
*/
bool activated() const {
return m_active;
}
/**
* @brief Toggle activation
*/
void toggle() {
m_active = !m_active;
}
/**
* @brief Set auto bind
* @param value Enable state
*/
void set_auto_bind(bool value = true) {
m_auto_bind_active = value;
}
/**
* @brief Check if auto bind is enabled
* @return Auto bind is enabled or not
*/
bool auto_bind() const {
return m_auto_bind_active;
}
/**
* @brief Check if pipeline is ready
* @return Pipeline is ready or not
*/
bool ready() const {
return m_vk_pipeline != VK_NULL_HANDLE;
}
/**
* @brief Get the pipeline
* @return VkPipeline Vulkan pipeline
*/
VkPipeline get() const {
return m_vk_pipeline;
}
/**
* @brief Get the device
* @return device::ptr Vulkan device
*/
device::ptr get_device() {
return m_device;
}
/**
* @brief Get the layout
* @return pipeline_layout::s_ptr Pipeline layout
*/
pipeline_layout::s_ptr get_layout() const {
return m_layout;
}
/**
* @brief Set the layout
* @param value Pipeline layout
*/
void set_layout(pipeline_layout::s_ptr const& value) {
m_layout = value;
}
/**
* @brief Shader stage
*/
struct shader_stage {
/// Shared pointer to shader stage
using s_ptr = std::shared_ptr<shader_stage>;
/// List of shader stages
using s_list = std::vector<s_ptr>;
/**
* @brief Make a new pipline shader stage
* @param stage Shader stage flag bits
* @return s_ptr Shared pointer to shader stage
*/
static s_ptr make(VkShaderStageFlagBits stage) {
auto result = std::make_shared<shader_stage>();
result->set_stage(stage);
return result;
}
/**
* @brief Construct a new shader stage
*/
explicit shader_stage();
/**
* @brief Destroy the shader stage
*/
~shader_stage();
/**
* @brief Set the stage
* @param stage Shader stage flag bits
*/
void set_stage(VkShaderStageFlagBits stage) {
m_create_info.stage = stage;
}
/**
* @brief Add specialization entry
* @param specialization Specialization map entry
*/
void add_specialization_entry(VkSpecializationMapEntry const& specialization);
/**
* @brief Create a new shader stage
* @param device Vulkan device
* @param shader_data Shader data
* @param specialization_data Specialization data
* @return Create was successful or failed
*/
bool create(device::ptr device,
c_data::ref shader_data,
c_data::ref specialization_data = data());
/**
* @brief Destroy the shader stage
*/
void destroy();
/**
* @brief Get the create info
* @return VkPipelineShaderStageCreateInfo const& Pipeline shader stage create information
*/
VkPipelineShaderStageCreateInfo const& get_create_info() const {
return m_create_info;
}
private:
/// Vulkan device
device::ptr m_device = nullptr;
/// Pipeline shader stage create information
VkPipelineShaderStageCreateInfo m_create_info;
/// Secialization information
VkSpecializationInfo m_specialization_info;
/// Map of specialization entries
VkSpecializationMapEntries m_specialization_entries;
/// Specialization data copy
data m_specialization_data_copy;
};
protected:
/**
* @brief Set up the pipeline
* @return Setup was successful or failed
*/
virtual bool setup() = 0;
/**
* @brief Tear down the pipeline
*/
virtual void teardown() = 0;
/// Vulkan device
device::ptr m_device = nullptr;
/// Vulkan pipeline
VkPipeline m_vk_pipeline = VK_NULL_HANDLE;
/// Vulkan pipeline cache
VkPipelineCache m_pipeline_cache = VK_NULL_HANDLE;
/// Pipeline layout
pipeline_layout::s_ptr m_layout;
private:
/// Active state
bool m_active = true;
/// Auto bind state
bool m_auto_bind_active = true;
};
/**
* @brief Create a new pipeline shader stage
* @param device Vulkan device
* @param data Shader data
* @param stage Shader stage flag bits
* @return pipeline::shader_stage::s_ptr Shared pointer to pipeline shader stage
*/
pipeline::shader_stage::s_ptr create_pipeline_shader_stage(device::ptr device,
c_data::ref data,
VkShaderStageFlagBits stage);
} // namespace lava