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

◆ initialize_pipeline()

void MayaFlux::Buffers::RenderProcessor::initialize_pipeline ( const std::shared_ptr< VKBuffer > &  buffer)
overrideprotectedvirtual

Implements MayaFlux::Buffers::ShaderProcessor.

Definition at line 198 of file RenderProcessor.cpp.

199{
202 "Vertex shader not loaded");
203 return;
204 }
205
208 "Fragment shader not loaded");
209 return;
210 }
211
212 if (!m_target_window) {
214 "Target window not set");
215 return;
216 }
217
219
221
222 Portal::Graphics::RenderPipelineConfig pipeline_config;
223 pipeline_config.vertex_shader = m_shader_id;
224 pipeline_config.fragment_shader = m_fragment_shader_id;
225 pipeline_config.geometry_shader = m_geometry_shader_id;
226 pipeline_config.tess_control_shader = m_tess_control_shader_id;
227 pipeline_config.tess_eval_shader = m_tess_eval_shader_id;
228
229 pipeline_config.topology = m_primitive_topology;
230 pipeline_config.rasterization.polygon_mode = m_polygon_mode;
231 pipeline_config.rasterization.cull_mode = m_cull_mode;
232
233 if (m_blend_attachment.has_value()) {
234 pipeline_config.blend_attachments.push_back(m_blend_attachment.value());
235 } else {
236 pipeline_config.blend_attachments.emplace_back();
237 }
238
239 pipeline_config.depth_stencil = m_depth_stencil;
240
241 if (m_buffer_info.find(buffer) == m_buffer_info.end()) {
242 if (buffer->has_vertex_layout()) {
243 auto vertex_layout = buffer->get_vertex_layout();
244 if (vertex_layout.has_value()) {
245 m_buffer_info[buffer] = {
246 .semantic_layout = vertex_layout.value(),
247 .use_reflection = false
248 };
249 }
250 }
251 }
252
253 const Kakshya::VertexLayout* local_layout = get_or_cache_vertex_layout(m_buffer_info, buffer);
254 if (!local_layout) {
256 "initialize_pipeline: layout not yet available, deferring");
257 return;
258 }
259
260 pipeline_config.semantic_vertex_layout = *local_layout;
261 pipeline_config.use_vertex_shader_reflection = m_buffer_info[buffer].use_reflection;
262
263 const auto& staging = buffer->get_pipeline_context().push_constant_staging;
264 if (!staging.empty()) {
265 pipeline_config.push_constant_size = staging.size();
266 } else {
267 pipeline_config.push_constant_size = std::max(m_config.push_constant_size, m_push_constant_data.size());
268 }
269
270 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
271 std::map<std::pair<uint32_t, uint32_t>, Portal::Graphics::DescriptorBindingInfo> unified_bindings;
272
273 for (const auto& binding : descriptor_bindings) {
274 unified_bindings[{ binding.set, binding.binding }] = binding;
275 }
276
277 for (const auto& [name, binding] : m_config.bindings) {
278 auto key = std::make_pair(binding.set, binding.binding);
279 if (unified_bindings.find(key) == unified_bindings.end()) {
280 unified_bindings[key] = Portal::Graphics::DescriptorBindingInfo {
281 .set = binding.set,
282 .binding = binding.binding,
283 .type = binding.type,
284 .buffer_info = {},
285 .name = name,
286 .count = binding.count
287 };
288 }
289 }
290
291 std::map<uint32_t, std::vector<Portal::Graphics::DescriptorBindingInfo>> bindings_by_set;
292 for (const auto& [key, binding] : unified_bindings) {
293 bindings_by_set[binding.set].push_back(binding);
294 }
295
296 for (const auto& [set_index, set_bindings] : bindings_by_set) {
297 pipeline_config.descriptor_sets.push_back(set_bindings);
298 }
299
300 vk::Format swapchain_format = static_cast<vk::Format>(
302
303 vk::Format depth_format = m_depth_enabled
304 ? vk::Format::eD32Sfloat
305 : vk::Format::eUndefined;
306
307 m_pipeline_id = flow.create_pipeline(pipeline_config, { swapchain_format }, depth_format);
308
311 "Failed to create render pipeline");
312 return;
313 }
314
315 if (m_depth_enabled) {
316 buffer->set_needs_depth_attachment(true);
317 }
318
321
323}
#define MF_ERROR(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
Portal::Graphics::ShaderID m_fragment_shader_id
std::unordered_map< std::shared_ptr< VKBuffer >, VertexInfo > m_buffer_info
std::optional< Portal::Graphics::BlendAttachmentConfig > m_blend_attachment
Registry::Service::DisplayService * m_display_service
Portal::Graphics::ShaderID m_geometry_shader_id
Portal::Graphics::RenderPipelineID m_pipeline_id
Portal::Graphics::ShaderID m_tess_control_shader_id
Portal::Graphics::DepthStencilConfig m_depth_stencil
Portal::Graphics::PrimitiveTopology m_primitive_topology
Portal::Graphics::PolygonMode m_polygon_mode
Portal::Graphics::CullMode m_cull_mode
const Kakshya::VertexLayout * get_or_cache_vertex_layout(std::unordered_map< std::shared_ptr< VKBuffer >, VertexInfo > &buffer_info, const std::shared_ptr< VKBuffer > &buffer)
std::shared_ptr< Core::Window > m_target_window
Portal::Graphics::ShaderID m_tess_eval_shader_id
Portal::Graphics::ShaderID m_shader_id
std::vector< uint8_t > m_push_constant_data
virtual void on_pipeline_created(Portal::Graphics::ComputePipelineID pipeline_id)
Called after pipeline is created.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
void register_window_for_rendering(const std::shared_ptr< Core::Window > &window)
Register a window for dynamic rendering.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
constexpr RenderPipelineID INVALID_RENDER_PIPELINE
constexpr ShaderID INVALID_SHADER
MAYAFLUX_API RenderFlow & get_render_flow()
Get the global render flow instance.
std::function< int(const std::shared_ptr< void > &)> get_swapchain_format
Get actual swapchain format for a window.

References MayaFlux::Buffers::ShaderConfig::bindings, MayaFlux::Portal::Graphics::RenderPipelineConfig::blend_attachments, MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, MayaFlux::Portal::Graphics::RasterizationConfig::cull_mode, MayaFlux::Portal::Graphics::RenderPipelineConfig::depth_stencil, MayaFlux::Portal::Graphics::RenderPipelineConfig::descriptor_sets, MayaFlux::Portal::Graphics::RenderPipelineConfig::fragment_shader, MayaFlux::Portal::Graphics::RenderPipelineConfig::geometry_shader, get_or_cache_vertex_layout(), MayaFlux::Portal::Graphics::get_render_flow(), MayaFlux::Registry::Service::DisplayService::get_swapchain_format, MayaFlux::Portal::Graphics::INVALID_RENDER_PIPELINE, MayaFlux::Portal::Graphics::INVALID_SHADER, m_blend_attachment, m_buffer_info, MayaFlux::Buffers::ShaderProcessor::m_config, m_cull_mode, m_depth_enabled, m_depth_stencil, MayaFlux::Buffers::ShaderProcessor::m_descriptor_set_ids, m_display_service, m_fragment_shader_id, m_geometry_shader_id, MayaFlux::Buffers::ShaderProcessor::m_needs_descriptor_rebuild, MayaFlux::Buffers::ShaderProcessor::m_needs_pipeline_rebuild, m_pipeline_id, m_polygon_mode, m_primitive_topology, MayaFlux::Buffers::ShaderProcessor::m_push_constant_data, MayaFlux::Buffers::ShaderProcessor::m_shader_id, m_target_window, m_tess_control_shader_id, m_tess_eval_shader_id, MF_DEBUG, MF_ERROR, MF_RT_ERROR, MayaFlux::Buffers::ShaderProcessor::on_pipeline_created(), MayaFlux::Portal::Graphics::RasterizationConfig::polygon_mode, MayaFlux::Buffers::ShaderConfig::push_constant_size, MayaFlux::Portal::Graphics::RenderPipelineConfig::push_constant_size, MayaFlux::Portal::Graphics::RenderPipelineConfig::rasterization, MayaFlux::Portal::Graphics::RenderFlow::register_window_for_rendering(), MayaFlux::Portal::Graphics::RenderPipelineConfig::semantic_vertex_layout, MayaFlux::Portal::Graphics::DescriptorBindingInfo::set, MayaFlux::Portal::Graphics::RenderPipelineConfig::tess_control_shader, MayaFlux::Portal::Graphics::RenderPipelineConfig::tess_eval_shader, MayaFlux::Portal::Graphics::RenderPipelineConfig::topology, MayaFlux::Portal::Graphics::RenderPipelineConfig::use_vertex_shader_reflection, and MayaFlux::Portal::Graphics::RenderPipelineConfig::vertex_shader.

+ Here is the call graph for this function: