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

◆ execute_shader()

void MayaFlux::Buffers::RenderProcessor::execute_shader ( const std::shared_ptr< VKBuffer > &  buffer)
overrideprotectedvirtual

Implements MayaFlux::Buffers::ShaderProcessor.

Definition at line 277 of file RenderProcessor.cpp.

278{
279 if (m_buffer_info.find(buffer) == m_buffer_info.end()) {
280 if (buffer->has_vertex_layout()) {
281 auto vertex_layout = buffer->get_vertex_layout();
282 if (vertex_layout.has_value()) {
283 m_buffer_info[buffer] = {
284 .semantic_layout = vertex_layout.value(),
285 .use_reflection = false
286 };
287 }
288 }
289 }
290
291 if (!m_target_window->is_graphics_registered()) {
292 return;
293 }
294
296 return;
297 }
298
299 auto vertex_layout = buffer->get_vertex_layout();
300 if (!vertex_layout.has_value()) {
302 "VKBuffer has no vertex layout set. Use buffer->set_vertex_layout()");
303 return;
304 }
305
306 if (vertex_layout->vertex_count == 0) {
308 "Vertex layout has zero vertices, skipping draw");
309 return;
310 }
311
312 if (vertex_layout->attributes.empty()) {
314 "Vertex layout has no attributes");
315 return;
316 }
317
318 buffer->set_pipeline_window(m_pipeline_id, m_target_window);
319
320 auto& foundry = Portal::Graphics::get_shader_foundry();
322
323 vk::Format color_format = static_cast<vk::Format>(
325
326 auto cmd_id = foundry.begin_secondary_commands(color_format);
327 auto cmd = foundry.get_command_buffer(cmd_id);
328
329 uint32_t width = 0, height = 0;
331
332 if (width > 0 && height > 0) {
333 auto cmd = foundry.get_command_buffer(cmd_id);
334
335 vk::Viewport viewport { 0.0F, 0.0F, static_cast<float>(width), static_cast<float>(height), 0.0F, 1.0F };
336 cmd.setViewport(0, 1, &viewport);
337
338 vk::Rect2D scissor { { 0, 0 }, { width, height } };
339 cmd.setScissor(0, 1, &scissor);
340 }
341
342 flow.bind_pipeline(cmd_id, m_pipeline_id);
343
344 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
345 if (!descriptor_bindings.empty()) {
346 for (const auto& binding : descriptor_bindings) {
347 if (binding.set >= m_descriptor_set_ids.size()) {
349 "Descriptor set index {} out of range", binding.set);
350 continue;
351 }
352
353 foundry.update_descriptor_buffer(
354 m_descriptor_set_ids[binding.set],
355 binding.binding,
356 binding.type,
357 binding.buffer_info.buffer,
358 binding.buffer_info.offset,
359 binding.buffer_info.range);
360 }
361 }
362
363 if (!m_descriptor_set_ids.empty()) {
364 flow.bind_descriptor_sets(cmd_id, m_pipeline_id, m_descriptor_set_ids);
365 }
366
367 const auto& staging = buffer->get_pipeline_context();
368 if (!staging.push_constant_staging.empty()) {
369 flow.push_constants(
370 cmd_id,
372 staging.push_constant_staging.data(),
373 staging.push_constant_staging.size());
374 } else if (!m_push_constant_data.empty()) {
375 flow.push_constants(
376 cmd_id,
379 m_push_constant_data.size());
380 }
381
382 on_before_execute(cmd_id, buffer);
383
384 flow.bind_vertex_buffers(cmd_id, { buffer });
385
386 flow.draw(cmd_id, vertex_layout->vertex_count);
387
388 foundry.end_commands(cmd_id);
389
390 buffer->set_pipeline_command(m_pipeline_id, cmd_id);
391 m_target_window->track_frame_command(cmd_id);
392
394 "Recorded secondary command buffer {} for window '{}'",
395 cmd_id, m_target_window->get_create_info().title);
396}
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
#define MF_RT_TRACE(comp, ctx,...)
std::unordered_map< std::shared_ptr< VKBuffer >, VertexInfo > m_buffer_info
Registry::Service::DisplayService * m_display_service
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Called before each process callback.
Portal::Graphics::RenderPipelineID m_pipeline_id
std::shared_ptr< Core::Window > m_target_window
std::vector< uint8_t > m_push_constant_data
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
constexpr RenderPipelineID INVALID_RENDER_PIPELINE
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::function< int(const std::shared_ptr< void > &)> get_swapchain_format
Get actual swapchain format for a window.
std::function< void(const std::shared_ptr< void > &, uint32_t &, uint32_t &)> get_swapchain_extent
Get swapchain extent for a window.

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, MayaFlux::Portal::Graphics::get_render_flow(), MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Registry::Service::DisplayService::get_swapchain_extent, MayaFlux::Registry::Service::DisplayService::get_swapchain_format, MayaFlux::Portal::Graphics::INVALID_RENDER_PIPELINE, m_buffer_info, MayaFlux::Buffers::ShaderProcessor::m_descriptor_set_ids, m_display_service, m_pipeline_id, MayaFlux::Buffers::ShaderProcessor::m_push_constant_data, m_target_window, MF_RT_ERROR, MF_RT_TRACE, MF_RT_WARN, and on_before_execute().

+ Here is the call graph for this function: