MayaFlux 0.2.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 104 of file RenderProcessor.cpp.

105{
108 "Vertex shader not loaded");
109 return;
110 }
111
114 "Fragment shader not loaded");
115 return;
116 }
117
118 if (!m_target_window) {
120 "Target window not set");
121 return;
122 }
123
125
127
128 Portal::Graphics::RenderPipelineConfig pipeline_config;
129 pipeline_config.vertex_shader = m_shader_id;
130 pipeline_config.fragment_shader = m_fragment_shader_id;
131 pipeline_config.geometry_shader = m_geometry_shader_id;
132 pipeline_config.tess_control_shader = m_tess_control_shader_id;
133 pipeline_config.tess_eval_shader = m_tess_eval_shader_id;
134
135 pipeline_config.topology = m_primitive_topology;
136 pipeline_config.rasterization.polygon_mode = m_polygon_mode;
137 pipeline_config.rasterization.cull_mode = m_cull_mode;
138
139 pipeline_config.blend_attachments.emplace_back();
140
141 if (m_buffer_info.find(buffer) == m_buffer_info.end()) {
142 if (buffer->has_vertex_layout()) {
143 auto vertex_layout = buffer->get_vertex_layout();
144 if (vertex_layout.has_value()) {
145 m_buffer_info[buffer] = {
146 .semantic_layout = vertex_layout.value(),
147 .use_reflection = false
148 };
149 }
150 }
151 }
152 if (m_buffer_info.find(buffer) != m_buffer_info.end()) {
153 const auto& vertex_info = m_buffer_info.find(buffer)->second;
154 pipeline_config.semantic_vertex_layout = vertex_info.semantic_layout;
155 pipeline_config.use_vertex_shader_reflection = vertex_info.use_reflection;
156 }
157
158 const auto& staging = buffer->get_pipeline_context().push_constant_staging;
159 if (!staging.empty()) {
160 pipeline_config.push_constant_size = staging.size();
161 } else {
162 pipeline_config.push_constant_size = std::max(m_config.push_constant_size, m_push_constant_data.size());
163 }
164
165 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
166 std::map<std::pair<uint32_t, uint32_t>, Portal::Graphics::DescriptorBindingInfo> unified_bindings;
167
168 for (const auto& binding : descriptor_bindings) {
169 unified_bindings[{ binding.set, binding.binding }] = binding;
170 }
171
172 for (const auto& [name, binding] : m_config.bindings) {
173 auto key = std::make_pair(binding.set, binding.binding);
174 if (unified_bindings.find(key) == unified_bindings.end()) {
175 unified_bindings[key] = Portal::Graphics::DescriptorBindingInfo {
176 .set = binding.set,
177 .binding = binding.binding,
178 .type = binding.type,
179 .buffer_info = {},
180 .name = name
181 };
182 }
183 }
184
185 std::map<uint32_t, std::vector<Portal::Graphics::DescriptorBindingInfo>> bindings_by_set;
186 for (const auto& [key, binding] : unified_bindings) {
187 bindings_by_set[binding.set].push_back(binding);
188 }
189
190 for (const auto& [set_index, set_bindings] : bindings_by_set) {
191 pipeline_config.descriptor_sets.push_back(set_bindings);
192 }
193
194 vk::Format swapchain_format = static_cast<vk::Format>(
196
197 m_pipeline_id = flow.create_pipeline(pipeline_config, { swapchain_format });
198
201 "Failed to create render pipeline");
202 return;
203 }
204
205 m_needs_descriptor_rebuild = !pipeline_config.descriptor_sets.empty() && m_descriptor_set_ids.empty();
207
209}
#define MF_ERROR(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
Portal::Graphics::ShaderID m_fragment_shader_id
std::unordered_map< std::shared_ptr< VKBuffer >, VertexInfo > m_buffer_info
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::PrimitiveTopology m_primitive_topology
Portal::Graphics::PolygonMode m_polygon_mode
Portal::Graphics::CullMode m_cull_mode
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::descriptor_sets, MayaFlux::Portal::Graphics::RenderPipelineConfig::fragment_shader, MayaFlux::Portal::Graphics::RenderPipelineConfig::geometry_shader, 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_buffer_info, MayaFlux::Buffers::ShaderProcessor::m_config, m_cull_mode, 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_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: