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

◆ create()

bool MayaFlux::Core::VKComputePipeline::create ( vk::Device  device,
const ComputePipelineConfig config 
)

Create compute pipeline from configuration.

Parameters
deviceLogical device
configPipeline configuration (shader, layouts, push constants)
Returns
true if creation succeeded

Creates:

  1. Pipeline layout (from descriptor set layouts + push constants)
  2. Compute pipeline (from shader + layout)

If config.cache is provided, pipeline creation will be faster on subsequent runs (cache can be saved/loaded between sessions).

Example: ComputePipelineConfig config; config.shader = &my_shader; config.add_descriptor_set_layout(layout); config.add_push_constant(vk::ShaderStageFlagBits::eCompute, 16);

VKComputePipeline pipeline; pipeline.create(device, config);

Definition at line 69 of file VKComputePipeline.cpp.

70{
71 if (!config.shader) {
73 "Cannot create compute pipeline without shader");
74 return false;
75 }
76
77 if (!config.shader->is_valid()) {
79 "Cannot create compute pipeline with invalid shader module");
80 return false;
81 }
82
83 if (config.shader->get_stage() != vk::ShaderStageFlagBits::eCompute) {
85 "Shader is not a compute shader (stage: {})",
86 vk::to_string(config.shader->get_stage()));
87 return false;
88 }
89
90 m_layout = create_pipeline_layout(device, config);
91 if (!m_layout) {
93 "Failed to create pipeline layout");
94 return false;
95 }
96
97 auto shader_stage = config.shader->get_stage_create_info();
98
99 vk::ComputePipelineCreateInfo pipeline_info;
100 pipeline_info.stage = shader_stage;
101 pipeline_info.layout = m_layout;
102 pipeline_info.basePipelineHandle = nullptr;
103 pipeline_info.basePipelineIndex = -1;
104
105 try {
106 auto result = device.createComputePipeline(config.cache, pipeline_info);
107 if (result.result != vk::Result::eSuccess) {
109 "Failed to create compute pipeline: {}",
110 vk::to_string(result.result));
111 device.destroyPipelineLayout(m_layout);
112 m_layout = nullptr;
113 return false;
114 }
115 m_pipeline = result.value;
116 } catch (const vk::SystemError& e) {
118 "Failed to create compute pipeline: {}", e.what());
119 device.destroyPipelineLayout(m_layout);
120 m_layout = nullptr;
121 return false;
122 }
123
124 const auto& reflection = config.shader->get_reflection();
125 m_workgroup_size = reflection.workgroup_size;
126
127 if (m_workgroup_size) {
129 "Compute pipeline created (workgroup: {}x{}x{}, {} descriptor sets, {} push constants)",
131 config.set_layouts.size(), config.push_constants.size());
132 } else {
134 "Compute pipeline created ({} descriptor sets, {} push constants)",
135 config.set_layouts.size(), config.push_constants.size());
136 }
137
138 return true;
139}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
std::optional< std::array< uint32_t, 3 > > m_workgroup_size
vk::PipelineLayout create_pipeline_layout(vk::Device device, const ComputePipelineConfig &config)
Create pipeline layout from configuration.
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Core::ComputePipelineConfig::cache, MayaFlux::Journal::Core, create_pipeline_layout(), MayaFlux::Journal::GraphicsBackend, m_layout, m_pipeline, m_workgroup_size, MF_ERROR, MF_INFO, MayaFlux::Core::ComputePipelineConfig::push_constants, MayaFlux::Core::ComputePipelineConfig::set_layouts, and MayaFlux::Core::ComputePipelineConfig::shader.

Referenced by create_specialized().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: