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 216 of file RenderProcessor.cpp.

217{
220 "Vertex shader not loaded");
221 return;
222 }
223
226 "Fragment shader not loaded");
227 return;
228 }
229
230 if (!m_target_window) {
232 "Target window not set");
233 return;
234 }
235
237
239
240 Portal::Graphics::RenderPipelineConfig pipeline_config;
241 pipeline_config.vertex_shader = m_shader_id;
242 pipeline_config.fragment_shader = m_fragment_shader_id;
243 pipeline_config.geometry_shader = m_geometry_shader_id;
244 pipeline_config.tess_control_shader = m_tess_control_shader_id;
245 pipeline_config.tess_eval_shader = m_tess_eval_shader_id;
246
247 pipeline_config.topology = m_primitive_topology;
248 pipeline_config.rasterization.polygon_mode = m_polygon_mode;
249 pipeline_config.rasterization.cull_mode = m_cull_mode;
250
251 if (m_blend_attachment.has_value()) {
252 pipeline_config.blend_attachments.push_back(m_blend_attachment.value());
253 } else {
254 pipeline_config.blend_attachments.emplace_back();
255 }
256
257 pipeline_config.depth_stencil = m_depth_stencil;
258
259 if (m_buffer_info.find(buffer) == m_buffer_info.end()) {
260 if (buffer->has_vertex_layout()) {
261 auto vertex_layout = buffer->get_vertex_layout();
262 if (vertex_layout.has_value()) {
263 m_buffer_info[buffer] = {
264 .semantic_layout = vertex_layout.value(),
265 .use_reflection = false
266 };
267 }
268 }
269 }
270
271 const Kakshya::VertexLayout* local_layout = get_or_cache_vertex_layout(m_buffer_info, buffer);
272 if (!local_layout) {
274 "initialize_pipeline: layout not yet available, deferring");
275 return;
276 }
277
278 pipeline_config.semantic_vertex_layout = *local_layout;
279 pipeline_config.use_vertex_shader_reflection = m_buffer_info[buffer].use_reflection;
280
281 const auto& staging = buffer->get_pipeline_context().push_constant_staging;
282 if (!staging.empty()) {
283 pipeline_config.push_constant_size = staging.size();
284 } else {
285 pipeline_config.push_constant_size = std::max(m_config.push_constant_size, m_push_constant_data.size());
286 }
287
288 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
289 std::map<std::pair<uint32_t, uint32_t>, Portal::Graphics::DescriptorBindingInfo> unified_bindings;
290
291 for (const auto& binding : descriptor_bindings) {
292 unified_bindings[{ binding.set, binding.binding }] = binding;
293 }
294
295 for (const auto& [name, binding] : m_config.bindings) {
296 auto key = std::make_pair(binding.set, binding.binding);
297 if (unified_bindings.find(key) == unified_bindings.end()) {
298 unified_bindings[key] = Portal::Graphics::DescriptorBindingInfo {
299 .set = binding.set,
300 .binding = binding.binding,
301 .type = binding.type,
302 .buffer_info = {},
303 .name = name,
304 .count = binding.count
305 };
306 }
307 }
308
309 std::map<uint32_t, std::vector<Portal::Graphics::DescriptorBindingInfo>> bindings_by_set;
310 for (const auto& [key, binding] : unified_bindings) {
311 bindings_by_set[binding.set].push_back(binding);
312 }
313
314 for (const auto& [set_index, set_bindings] : bindings_by_set) {
315 pipeline_config.descriptor_sets.push_back(set_bindings);
316 }
317
318 vk::Format swapchain_format = static_cast<vk::Format>(
320
321 vk::Format depth_format = m_depth_enabled
322 ? vk::Format::eD32Sfloat
323 : vk::Format::eUndefined;
324
325 m_pipeline_id = flow.create_pipeline(pipeline_config, { swapchain_format }, depth_format);
326
329 "Failed to create render pipeline");
330 return;
331 }
332
333 if (m_depth_enabled) {
334 buffer->set_needs_depth_attachment(true);
335 }
336
339
341}
#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: