MayaFlux 1.0.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 72 of file VKComputePipeline.cpp.

73{
74 if (!config.shader) {
76 "Cannot create compute pipeline without shader");
77 return false;
78 }
79
80 if (!config.shader->is_valid()) {
82 "Cannot create compute pipeline with invalid shader module");
83 return false;
84 }
85
86 if (config.shader->get_stage() != vk::ShaderStageFlagBits::eCompute) {
88 "Shader is not a compute shader (stage: {})",
89 vk::to_string(config.shader->get_stage()));
90 return false;
91 }
92
94 if (!m_layout) {
96 "Failed to create pipeline layout");
97 return false;
98 }
99
100 auto shader_stage = config.shader->get_stage_create_info();
101
102 vk::ComputePipelineCreateInfo pipeline_info;
103 pipeline_info.stage = shader_stage;
104 pipeline_info.layout = m_layout;
105 pipeline_info.basePipelineHandle = nullptr;
106 pipeline_info.basePipelineIndex = -1;
107
108 try {
109 auto result = device.createComputePipeline(config.cache, pipeline_info);
110 if (result.result != vk::Result::eSuccess) {
112 "Failed to create compute pipeline: {}",
113 vk::to_string(result.result));
114 device.destroyPipelineLayout(m_layout);
115 m_layout = nullptr;
116 return false;
117 }
118 m_pipeline = result.value;
119 } catch (const vk::SystemError& e) {
121 "Failed to create compute pipeline: {}", e.what());
122 device.destroyPipelineLayout(m_layout);
123 m_layout = nullptr;
124 return false;
125 }
126
127 m_shader = config.shader;
128 const auto& reflection = config.shader->get_reflection();
129 m_workgroup_size = reflection.workgroup_size;
130
131 if (m_workgroup_size) {
133 "Compute pipeline created (workgroup: {}x{}x{}, {} descriptor sets, {} push constants)",
135 config.set_layouts.size(), config.push_constants.size());
136 } else {
138 "Compute pipeline created ({} descriptor sets, {} push constants)",
139 config.set_layouts.size(), config.push_constants.size());
140 }
141
142 return true;
143}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
vk::PhysicalDevice device
Definition VKDevice.cpp:121
std::optional< std::array< uint32_t, 3 > > m_workgroup_size
std::shared_ptr< VKShaderModule > m_shader
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(), device, MayaFlux::Journal::GraphicsBackend, m_layout, m_pipeline, m_shader, 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: