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

◆ initialize_pipeline()

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

Reimplemented from MayaFlux::Buffers::ShaderProcessor.

Definition at line 109 of file RenderProcessor.cpp.

110{
113 "Vertex shader not loaded");
114 return;
115 }
116
119 "Fragment shader not loaded");
120 return;
121 }
122
124
125 if (!m_target_window) {
127 "Target window not set");
128 return;
129 }
130
131 // vk::Format swapchain_format = vk::Format { m_display_service->get_swapchain_format(m_target_window) };
132 // m_render_pass_id = flow.create_simple_render_pass(swapchain_format);
133
135 vk::Format swapchain_format = vk::Format { m_display_service->get_swapchain_format(m_target_window) };
136 m_render_pass_id = flow.create_simple_render_pass(swapchain_format);
137
140 "Render pass not set");
141 return;
142 }
143 }
144
146
147 if (!buffer) {
149 "Cannot initialize pipeline: buffer is null");
150 return;
151 }
152 auto vk_buffer = std::dynamic_pointer_cast<VKBuffer>(buffer);
153
154 Portal::Graphics::RenderPipelineConfig pipeline_config;
155 pipeline_config.vertex_shader = m_shader_id;
156 pipeline_config.fragment_shader = m_fragment_shader_id;
157 pipeline_config.geometry_shader = m_geometry_shader_id;
158 pipeline_config.tess_control_shader = m_tess_control_shader_id;
159 pipeline_config.tess_eval_shader = m_tess_eval_shader_id;
160 pipeline_config.render_pass = m_render_pass_id;
161
162 pipeline_config.topology = m_primitive_topology;
163 pipeline_config.rasterization.polygon_mode = m_polygon_mode;
164 pipeline_config.rasterization.cull_mode = m_cull_mode;
165
166 pipeline_config.blend_attachments.emplace_back();
167
168 auto it = m_buffer_info.find(vk_buffer);
169 if (it != m_buffer_info.end()) {
170 const auto& vertex_info = it->second;
171 pipeline_config.semantic_vertex_layout = vertex_info.semantic_layout;
172 pipeline_config.use_vertex_shader_reflection = vertex_info.use_reflection;
173 }
174
175 if (!m_config.bindings.empty()) {
176 std::map<uint32_t, std::vector<std::pair<std::string, ShaderBinding>>> bindings_by_set;
177 for (const auto& [name, binding] : m_config.bindings) {
178 bindings_by_set[binding.set].emplace_back(name, binding);
179 }
180
181 for (const auto& [set_index, set_bindings] : bindings_by_set) {
182 std::vector<Portal::Graphics::DescriptorBindingConfig> set_config;
183 for (const auto& [name, binding] : set_bindings) {
184 set_config.emplace_back(binding.set, binding.binding, binding.type);
185 }
186 pipeline_config.descriptor_sets.push_back(set_config);
187 }
188 }
189
190 m_render_pipeline_id = flow.create_pipeline(pipeline_config);
191
194 "Failed to create render pipeline");
195 return;
196 }
197
198 if (!pipeline_config.descriptor_sets.empty() && m_descriptor_set_ids.empty()) {
199 m_descriptor_set_ids = flow.allocate_pipeline_descriptors(m_render_pipeline_id);
200
201 if (m_descriptor_set_ids.empty()) {
203 "Failed to allocate descriptor sets for pipeline");
204 return;
205 }
206
207 for (const auto& [binding, tex_binding] : m_texture_bindings) {
208 auto& foundry = Portal::Graphics::get_shader_foundry();
209 foundry.update_descriptor_image(
211 binding,
212 tex_binding.texture->get_image_view(),
213 tex_binding.sampler,
214 vk::ImageLayout::eShaderReadOnlyOptimal);
215 }
216
218 "Allocated {} descriptor sets and updated {} texture bindings",
220 }
221
223}
#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
Registry::Service::DisplayService * m_display_service
Portal::Graphics::ShaderID m_geometry_shader_id
Portal::Graphics::RenderPassID m_render_pass_id
Portal::Graphics::ShaderID m_tess_control_shader_id
std::unordered_map< uint32_t, TextureBinding > m_texture_bindings
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::RenderPipelineID m_render_pipeline_id
Portal::Graphics::ShaderID m_shader_id
void set_config(const ShaderProcessorConfig &config)
Update entire configuration.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
void register_window_for_rendering(const std::shared_ptr< Core::Window > &window, RenderPassID render_pass_id)
Associate a window with a render pass for rendering.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
constexpr RenderPipelineID INVALID_RENDER_PIPELINE
constexpr RenderPassID INVALID_RENDER_PASS
constexpr ShaderID INVALID_SHADER
MAYAFLUX_API RenderFlow & get_render_flow()
Get the global render flow instance.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
std::unordered_map< std::string, ShaderBinding > bindings
std::function< int(const std::shared_ptr< void > &)> get_swapchain_format
Get actual swapchain format for a window.

References MayaFlux::Buffers::ShaderProcessorConfig::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::Portal::Graphics::get_shader_foundry(), MayaFlux::Registry::Service::DisplayService::get_swapchain_format, MayaFlux::Portal::Graphics::INVALID_RENDER_PASS, 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_pipeline_rebuild, m_polygon_mode, m_primitive_topology, m_render_pass_id, m_render_pipeline_id, MayaFlux::Buffers::ShaderProcessor::m_shader_id, m_target_window, m_tess_control_shader_id, m_tess_eval_shader_id, m_texture_bindings, MF_DEBUG, MF_ERROR, MF_RT_ERROR, MayaFlux::Portal::Graphics::RasterizationConfig::polygon_mode, MayaFlux::Portal::Graphics::RenderPipelineConfig::rasterization, MayaFlux::Portal::Graphics::RenderFlow::register_window_for_rendering(), MayaFlux::Portal::Graphics::RenderPipelineConfig::render_pass, MayaFlux::Portal::Graphics::RenderPipelineConfig::semantic_vertex_layout, MayaFlux::Buffers::ShaderProcessor::set_config(), 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.

Referenced by processing_function().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: