MayaFlux 0.3.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 178 of file RenderProcessor.cpp.

179{
182 "Vertex shader not loaded");
183 return;
184 }
185
188 "Fragment shader not loaded");
189 return;
190 }
191
192 if (!m_target_window) {
194 "Target window not set");
195 return;
196 }
197
199
201
202 Portal::Graphics::RenderPipelineConfig pipeline_config;
203 pipeline_config.vertex_shader = m_shader_id;
204 pipeline_config.fragment_shader = m_fragment_shader_id;
205 pipeline_config.geometry_shader = m_geometry_shader_id;
206 pipeline_config.tess_control_shader = m_tess_control_shader_id;
207 pipeline_config.tess_eval_shader = m_tess_eval_shader_id;
208
209 pipeline_config.topology = m_primitive_topology;
210 pipeline_config.rasterization.polygon_mode = m_polygon_mode;
211 pipeline_config.rasterization.cull_mode = m_cull_mode;
212
213 if (m_blend_attachment.has_value()) {
214 pipeline_config.blend_attachments.push_back(m_blend_attachment.value());
215 } else {
216 pipeline_config.blend_attachments.emplace_back();
217 }
218
219 pipeline_config.depth_stencil = m_depth_stencil;
220
221 if (m_buffer_info.find(buffer) == m_buffer_info.end()) {
222 if (buffer->has_vertex_layout()) {
223 auto vertex_layout = buffer->get_vertex_layout();
224 if (vertex_layout.has_value()) {
225 m_buffer_info[buffer] = {
226 .semantic_layout = vertex_layout.value(),
227 .use_reflection = false
228 };
229 }
230 }
231 }
232
233 const Kakshya::VertexLayout* local_layout = get_or_cache_vertex_layout(m_buffer_info, buffer);
234 if (!local_layout) {
236 "initialize_pipeline: layout not yet available, deferring");
237 return;
238 }
239
240 pipeline_config.semantic_vertex_layout = *local_layout;
241 pipeline_config.use_vertex_shader_reflection = m_buffer_info[buffer].use_reflection;
242
243 const auto& staging = buffer->get_pipeline_context().push_constant_staging;
244 if (!staging.empty()) {
245 pipeline_config.push_constant_size = staging.size();
246 } else {
247 pipeline_config.push_constant_size = std::max(m_config.push_constant_size, m_push_constant_data.size());
248 }
249
250 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
251 std::map<std::pair<uint32_t, uint32_t>, Portal::Graphics::DescriptorBindingInfo> unified_bindings;
252
253 for (const auto& binding : descriptor_bindings) {
254 unified_bindings[{ binding.set, binding.binding }] = binding;
255 }
256
257 for (const auto& [name, binding] : m_config.bindings) {
258 auto key = std::make_pair(binding.set, binding.binding);
259 if (unified_bindings.find(key) == unified_bindings.end()) {
260 unified_bindings[key] = Portal::Graphics::DescriptorBindingInfo {
261 .set = binding.set,
262 .binding = binding.binding,
263 .type = binding.type,
264 .buffer_info = {},
265 .name = name
266 };
267 }
268 }
269
270 std::map<uint32_t, std::vector<Portal::Graphics::DescriptorBindingInfo>> bindings_by_set;
271 for (const auto& [key, binding] : unified_bindings) {
272 bindings_by_set[binding.set].push_back(binding);
273 }
274
275 for (const auto& [set_index, set_bindings] : bindings_by_set) {
276 pipeline_config.descriptor_sets.push_back(set_bindings);
277 }
278
279 vk::Format swapchain_format = static_cast<vk::Format>(
281
282 vk::Format depth_format = m_depth_enabled
283 ? vk::Format::eD32Sfloat
284 : vk::Format::eUndefined;
285
286 m_pipeline_id = flow.create_pipeline(pipeline_config, { swapchain_format }, depth_format);
287
290 "Failed to create render pipeline");
291 return;
292 }
293
294 if (m_depth_enabled) {
295 buffer->set_needs_depth_attachment(true);
296 }
297
298 m_needs_descriptor_rebuild = !pipeline_config.descriptor_sets.empty() && m_descriptor_set_ids.empty();
300
302}
#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: