MayaFlux 0.5.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 222 of file RenderProcessor.cpp.

223{
226 "Vertex shader not loaded");
227 return;
228 }
229
232 "Fragment shader not loaded");
233 return;
234 }
235
236 if (!m_target_window) {
238 "Target window not set");
239 return;
240 }
241
243
245
246 Portal::Graphics::RenderPipelineConfig pipeline_config;
247 pipeline_config.vertex_shader = m_shader_id;
248 pipeline_config.fragment_shader = m_fragment_shader_id;
249 pipeline_config.geometry_shader = m_geometry_shader_id;
250 pipeline_config.tess_control_shader = m_tess_control_shader_id;
251 pipeline_config.tess_eval_shader = m_tess_eval_shader_id;
252
253 pipeline_config.topology = m_primitive_topology;
254 pipeline_config.rasterization.polygon_mode = m_polygon_mode;
255 pipeline_config.rasterization.cull_mode = m_cull_mode;
256
257 if (m_blend_attachment.has_value()) {
258 pipeline_config.blend_attachments.push_back(m_blend_attachment.value());
259 } else {
260 pipeline_config.blend_attachments.emplace_back();
261 }
262
263 pipeline_config.depth_stencil = m_depth_stencil;
264
265 if (m_buffer_info.find(buffer) == m_buffer_info.end()) {
266 if (buffer->has_vertex_layout()) {
267 auto vertex_layout = buffer->get_vertex_layout();
268 if (vertex_layout.has_value()) {
269 m_buffer_info[buffer] = {
270 .semantic_layout = vertex_layout.value(),
271 .use_reflection = false
272 };
273 }
274 }
275 }
276
277 const Kakshya::VertexLayout* local_layout = get_or_cache_vertex_layout(m_buffer_info, buffer);
278 if (!local_layout) {
280 "initialize_pipeline: layout not yet available, deferring");
281 return;
282 }
283
284 pipeline_config.semantic_vertex_layout = *local_layout;
285 pipeline_config.use_vertex_shader_reflection = m_buffer_info[buffer].use_reflection;
286
287 pipeline_config.push_constant_size = resolve_push_constant_size(buffer);
288
289 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
290 std::map<std::pair<uint32_t, uint32_t>, Portal::Graphics::DescriptorBindingInfo> unified_bindings;
291
292 for (const auto& binding : descriptor_bindings) {
293 unified_bindings[{ binding.set, binding.binding }] = binding;
294 }
295
296 for (const auto& [name, binding] : m_config.bindings) {
297 auto key = std::make_pair(binding.set, binding.binding);
298 if (unified_bindings.find(key) == unified_bindings.end()) {
299 unified_bindings[key] = Portal::Graphics::DescriptorBindingInfo {
300 .set = binding.set,
301 .binding = binding.binding,
302 .type = binding.type,
303 .buffer_info = {},
304 .name = name,
305 .count = binding.count
306 };
307 }
308 }
309
310 std::map<uint32_t, std::vector<Portal::Graphics::DescriptorBindingInfo>> bindings_by_set;
311 for (const auto& [key, binding] : unified_bindings) {
312 bindings_by_set[binding.set].push_back(binding);
313 }
314
315 for (const auto& [set_index, set_bindings] : bindings_by_set) {
316 pipeline_config.descriptor_sets.push_back(set_bindings);
317 }
318
319 vk::Format swapchain_format = static_cast<vk::Format>(
321
322 vk::Format depth_format = m_depth_enabled
323 ? vk::Format::eD32Sfloat
324 : vk::Format::eUndefined;
325
326 m_pipeline_id = flow.create_pipeline(pipeline_config, { swapchain_format }, depth_format);
327
330 "Failed to create render pipeline");
331 return;
332 }
333
334 if (m_depth_enabled) {
335 buffer->set_needs_depth_attachment(true);
336 }
337
340
342}
#define MF_ERROR(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::string name
Definition VKDevice.cpp:143
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
size_t resolve_push_constant_size(const std::shared_ptr< VKBuffer > &buffer) const
Byte width of this processor's push constant block, extended to cover any fragment staged on the buff...
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_shader_id, m_target_window, m_tess_control_shader_id, m_tess_eval_shader_id, MF_DEBUG, MF_ERROR, MF_RT_ERROR, name, MayaFlux::Buffers::ShaderProcessor::on_pipeline_created(), MayaFlux::Portal::Graphics::RasterizationConfig::polygon_mode, MayaFlux::Portal::Graphics::RenderPipelineConfig::push_constant_size, MayaFlux::Portal::Graphics::RenderPipelineConfig::rasterization, MayaFlux::Portal::Graphics::RenderFlow::register_window_for_rendering(), MayaFlux::Buffers::ShaderProcessor::resolve_push_constant_size(), 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: