MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ create()

bool MayaFlux::Core::VKGraphicsPipeline::create ( vk::Device  device,
const GraphicsPipelineConfig config 
)

Create graphics pipeline from configuration.

Parameters
deviceLogical device
configPipeline configuration
Returns
true if creation succeeded

Validates shaders, creates pipeline layout, and creates pipeline.

Definition at line 195 of file VKGraphicsPipeline.cpp.

196{
197 if (!device) {
199 "Cannot create graphics pipeline with null device");
200 return false;
201 }
202
203 m_device = device;
204 m_config = config;
205
206 if (!validate_shaders(config)) {
208 "Shader validation failed");
209 return false;
210 }
211
212 m_layout = create_pipeline_layout(device, config);
213 if (!m_layout) {
215 "Failed to create pipeline layout");
216 return false;
217 }
218
219 std::vector<vk::PipelineShaderStageCreateInfo> shader_stages;
220 if (config.mesh_shader) {
221 shader_stages.push_back(config.mesh_shader->get_stage_create_info());
222 if (config.task_shader) {
223 shader_stages.push_back(config.task_shader->get_stage_create_info());
224 }
225 } else {
226 if (config.vertex_shader)
227 shader_stages.push_back(config.vertex_shader->get_stage_create_info());
228 if (config.fragment_shader)
229 shader_stages.push_back(config.fragment_shader->get_stage_create_info());
230 if (config.geometry_shader)
231 shader_stages.push_back(config.geometry_shader->get_stage_create_info());
232 if (config.tess_control_shader)
233 shader_stages.push_back(config.tess_control_shader->get_stage_create_info());
234 if (config.tess_evaluation_shader)
235 shader_stages.push_back(config.tess_evaluation_shader->get_stage_create_info());
236 }
237
238 std::vector<vk::VertexInputBindingDescription> vertex_bindings;
239 std::vector<vk::VertexInputAttributeDescription> vertex_attributes;
240 auto vertex_input_state = build_vertex_input_state(config, vertex_bindings, vertex_attributes);
241
242 auto input_assembly_state = build_input_assembly_state(config);
243 auto tessellation_state = build_tessellation_state(config);
244
245 std::vector<vk::Viewport> viewports;
246 std::vector<vk::Rect2D> scissors;
247 auto viewport_state = build_viewport_state(config, viewports, scissors);
248
249 auto rasterization_state = build_rasterization_state(config);
250 auto multisample_state = build_multisample_state(config);
251 auto depth_stencil_state = build_depth_stencil_state(config);
252
253 std::vector<vk::PipelineColorBlendAttachmentState> blend_attachments;
254 auto color_blend_state = build_color_blend_state(config, blend_attachments);
255
256 auto dynamic_state = build_dynamic_state(config);
257
258 vk::GraphicsPipelineCreateInfo pipeline_info;
259 pipeline_info.stageCount = static_cast<uint32_t>(shader_stages.size());
260 pipeline_info.pStages = shader_stages.data();
261 pipeline_info.pVertexInputState = &vertex_input_state;
262 pipeline_info.pInputAssemblyState = &input_assembly_state;
263 pipeline_info.pTessellationState = (config.tess_control_shader || config.tess_evaluation_shader)
264 ? &tessellation_state
265 : nullptr;
266
267 pipeline_info.pViewportState = &viewport_state;
268 pipeline_info.pRasterizationState = &rasterization_state;
269 pipeline_info.pMultisampleState = &multisample_state;
270 pipeline_info.pDepthStencilState = &depth_stencil_state;
271 pipeline_info.pColorBlendState = &color_blend_state;
272 pipeline_info.pDynamicState = config.dynamic_states.empty() ? nullptr : &dynamic_state;
273 pipeline_info.layout = m_layout;
274 pipeline_info.basePipelineHandle = nullptr;
275 pipeline_info.basePipelineIndex = -1;
276
277 vk::PipelineRenderingCreateInfo rendering_create_info;
278 rendering_create_info.colorAttachmentCount = static_cast<uint32_t>(config.color_attachment_formats.size());
279 rendering_create_info.pColorAttachmentFormats = config.color_attachment_formats.data();
280 rendering_create_info.depthAttachmentFormat = config.depth_attachment_format;
281 rendering_create_info.stencilAttachmentFormat = config.stencil_attachment_format;
282
283 pipeline_info.pNext = &rendering_create_info;
284 pipeline_info.renderPass = nullptr;
285 pipeline_info.subpass = 0;
286
288 "Creating pipeline for dynamic rendering ({} color attachments)",
289 config.color_attachment_formats.size());
290
291 try {
292 auto result = device.createGraphicsPipeline(config.cache, pipeline_info);
293 if (result.result != vk::Result::eSuccess) {
295 "Failed to create graphics pipeline: {}", vk::to_string(result.result));
296 device.destroyPipelineLayout(m_layout);
297 m_layout = nullptr;
298 return false;
299 }
300 m_pipeline = result.value;
301 } catch (const vk::SystemError& e) {
303 "Failed to create graphics pipeline: {}", e.what());
304 device.destroyPipelineLayout(m_layout);
305 m_layout = nullptr;
306 return false;
307 }
308
310 "Graphics pipeline created ({} shader stages)", shader_stages.size());
311
312 return true;
313}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
bool validate_shaders(const GraphicsPipelineConfig &config)
Validate shader stages.
vk::PipelineDepthStencilStateCreateInfo build_depth_stencil_state(const GraphicsPipelineConfig &config)
Build depth stencil state.
vk::PipelineInputAssemblyStateCreateInfo build_input_assembly_state(const GraphicsPipelineConfig &config)
Build input assembly state.
vk::PipelineMultisampleStateCreateInfo build_multisample_state(const GraphicsPipelineConfig &config)
Build multisample state.
vk::PipelineRasterizationStateCreateInfo build_rasterization_state(const GraphicsPipelineConfig &config)
Build rasterization state.
vk::PipelineVertexInputStateCreateInfo build_vertex_input_state(const GraphicsPipelineConfig &config, std::vector< vk::VertexInputBindingDescription > &bindings, std::vector< vk::VertexInputAttributeDescription > &attributes)
Build vertex input state from config.
vk::PipelineTessellationStateCreateInfo build_tessellation_state(const GraphicsPipelineConfig &config)
Build tessellation state.
vk::PipelineLayout create_pipeline_layout(vk::Device device, const GraphicsPipelineConfig &config)
Create pipeline layout from config.
vk::PipelineColorBlendStateCreateInfo build_color_blend_state(const GraphicsPipelineConfig &config, std::vector< vk::PipelineColorBlendAttachmentState > &attachments)
Build color blend state.
vk::PipelineDynamicStateCreateInfo build_dynamic_state(const GraphicsPipelineConfig &config)
Build dynamic state.
vk::PipelineViewportStateCreateInfo build_viewport_state(const GraphicsPipelineConfig &config, std::vector< vk::Viewport > &viewports, std::vector< vk::Rect2D > &scissors)
Build viewport state.
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.

References build_color_blend_state(), build_depth_stencil_state(), build_dynamic_state(), build_input_assembly_state(), build_multisample_state(), build_rasterization_state(), build_tessellation_state(), build_vertex_input_state(), build_viewport_state(), MayaFlux::Core::GraphicsPipelineConfig::cache, MayaFlux::Core::GraphicsPipelineConfig::color_attachment_formats, MayaFlux::Journal::Core, create_pipeline_layout(), MayaFlux::Core::GraphicsPipelineConfig::depth_attachment_format, MayaFlux::Core::GraphicsPipelineConfig::dynamic_states, MayaFlux::Core::GraphicsPipelineConfig::fragment_shader, MayaFlux::Core::GraphicsPipelineConfig::geometry_shader, MayaFlux::Journal::GraphicsBackend, m_config, m_device, m_layout, m_pipeline, MayaFlux::Core::GraphicsPipelineConfig::mesh_shader, MF_DEBUG, MF_ERROR, MF_INFO, MayaFlux::Core::GraphicsPipelineConfig::stencil_attachment_format, MayaFlux::Core::GraphicsPipelineConfig::task_shader, MayaFlux::Core::GraphicsPipelineConfig::tess_control_shader, MayaFlux::Core::GraphicsPipelineConfig::tess_evaluation_shader, validate_shaders(), and MayaFlux::Core::GraphicsPipelineConfig::vertex_shader.

+ Here is the call graph for this function: