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

468{
469 if (m_buffer_info.find(buffer) == m_buffer_info.end()) {
470 if (buffer->has_vertex_layout()) {
471 auto vertex_layout = buffer->get_vertex_layout();
472 if (vertex_layout.has_value()) {
473 m_buffer_info[buffer] = {
474 .semantic_layout = vertex_layout.value(),
475 .use_reflection = false
476 };
477 }
478 }
479 }
480
481 if (!m_target_window->is_graphics_registered()) {
482 return;
483 }
484
486 return;
487 }
488
489 const Kakshya::VertexLayout* local_layout = get_or_cache_vertex_layout(m_buffer_info, buffer);
490 if (!local_layout) {
492 "VKBuffer has no vertex layout set. Use buffer->set_vertex_layout()");
493 return;
494 }
495
496 buffer->set_pipeline_window(m_pipeline_id, m_target_window);
497
498 auto& foundry = Portal::Graphics::get_shader_foundry();
500
501 vk::Format color_format = static_cast<vk::Format>(
503
504 vk::Format depth_format = m_depth_enabled
505 ? vk::Format::eD32Sfloat
506 : vk::Format::eUndefined;
507
508 auto cmd_id = foundry.begin_secondary_commands(color_format, depth_format);
509 auto cmd = foundry.get_command_buffer(cmd_id);
510
511 uint32_t width = 0, height = 0;
513
514 if (width > 0 && height > 0) {
515 auto cmd = foundry.get_command_buffer(cmd_id);
516
517 vk::Viewport viewport {
518 0.0F,
519 static_cast<float>(height),
520 static_cast<float>(width),
521 -static_cast<float>(height),
522 0.0F,
523 1.0F
524 };
525 cmd.setViewport(0, 1, &viewport);
526
527 vk::Rect2D scissor { { 0, 0 }, { width, height } };
528 cmd.setScissor(0, 1, &scissor);
529 }
530
531 flow.bind_pipeline(cmd_id, m_pipeline_id);
532
533 auto& engine_bindings = buffer->get_engine_context().ssbo_bindings;
534 for (const auto& binding : engine_bindings) {
535 if (binding.set == 0 && binding.binding == 0) {
537 "Engine SSBO at binding=0 is reserved for ViewTransform UBO");
538 continue;
539 }
542 "Engine SSBO binding {} skipped: engine descriptor set not allocated", binding.binding);
543 continue;
544 }
545 foundry.update_descriptor_buffer(
547 binding.binding,
548 binding.type,
549 binding.buffer_info.buffer,
550 binding.buffer_info.offset,
551 binding.buffer_info.range);
552 }
553
554 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
555 if (!descriptor_bindings.empty()) {
556 for (const auto& binding : descriptor_bindings) {
557 auto ds_index = resolve_ds_index(binding.set);
558 if (!ds_index) {
560 "Descriptor set index {} out of range or reserved", binding.set);
561 continue;
562 }
563
564 foundry.update_descriptor_buffer(
565 m_descriptor_set_ids[*ds_index],
566 binding.binding,
567 binding.type,
568 binding.buffer_info.buffer,
569 binding.buffer_info.offset,
570 binding.buffer_info.range);
571 }
572 }
573
574 if (!m_descriptor_set_ids.empty()) {
575 flow.bind_descriptor_sets(cmd_id, m_pipeline_id, m_descriptor_set_ids);
576 }
577
578 {
579 Kinesis::ViewTransform vt;
583 : m_view_transform.value_or(Kinesis::ViewTransform {});
584 }
585
586 if (m_view_transform_ubo && m_view_transform_ubo->get_mapped_ptr()) {
587 std::memcpy(
588 m_view_transform_ubo->get_mapped_ptr(),
589 &vt,
590 sizeof(Kinesis::ViewTransform));
591 }
592 }
593
595 flow.bind_descriptor_sets(
596 cmd_id, m_pipeline_id,
598 0);
599 }
600
601 if (!m_descriptor_set_ids.empty()) {
602 flow.bind_descriptor_sets(
603 cmd_id, m_pipeline_id,
605 1);
606 }
607
608 const auto push_data = resolve_push_constants(buffer);
609 if (!push_data.empty()) {
610 flow.push_constants(
611 cmd_id, m_pipeline_id, push_data.data(), push_data.size());
612 }
613
614 on_before_execute(cmd_id, buffer);
615
616 flow.bind_vertex_buffers(cmd_id, { buffer });
617
618 uint32_t draw_count = 0;
619 if (m_vertex_count > 0) {
620 draw_count = m_vertex_count;
621 } else {
622 auto current_layout = buffer->get_vertex_layout();
623 if (!current_layout.has_value() || current_layout->vertex_count == 0) {
625 "Vertex layout has zero vertices, skipping draw");
626 return;
627 }
628 draw_count = current_layout->vertex_count;
629 }
630
631 if (buffer->has_index_buffer()) {
632 const auto index_count = static_cast<uint32_t>(
633 buffer->get_index_buffer_size() / sizeof(uint32_t));
634 flow.bind_index_buffer(cmd_id, buffer);
635 flow.draw_indexed(cmd_id, index_count, m_instance_count, 0, 0, 0);
636 } else {
637 flow.draw(cmd_id, draw_count, m_instance_count, m_first_vertex, 0);
638 }
639
640 foundry.end_commands(cmd_id);
641
642 buffer->set_pipeline_command(m_pipeline_id, cmd_id);
643 m_target_window->track_frame_command(cmd_id);
644
646 "Recorded secondary command buffer {} for window '{}'",
647 cmd_id, m_target_window->get_create_info().title);
648}
#define MF_RT_ERROR(comp, ctx,...)
#define MF_RT_TRACE(comp, ctx,...)
#define MF_RT_DEBUG(comp, ctx,...)
vk::CommandBuffer cmd
uint32_t width
Definition Decoder.cpp:66
uint32_t height
Portal::Graphics::DescriptorSetID m_view_transform_descriptor_set_id
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.
std::function< Kinesis::ViewTransform()> m_view_transform_source
Portal::Graphics::RenderPipelineID m_pipeline_id
std::optional< Kinesis::ViewTransform > m_view_transform
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
std::shared_ptr< VKBuffer > m_view_transform_ubo
std::optional< uint32_t > resolve_ds_index(uint32_t set) const
Resolve logical descriptor set index to actual index.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
std::vector< uint8_t > resolve_push_constants(const std::shared_ptr< VKBuffer > &buffer) const
This processor's push constant data with buffer-staged fragments overlaid at their declared offsets.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
@ Kinesis
General mathematical and physics algorithns.
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.
constexpr DescriptorSetID INVALID_DESCRIPTOR_SET
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, cmd, get_or_cache_vertex_layout(), 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, height, MayaFlux::Portal::Graphics::INVALID_DESCRIPTOR_SET, MayaFlux::Portal::Graphics::INVALID_RENDER_PIPELINE, m_buffer_info, m_depth_enabled, MayaFlux::Buffers::ShaderProcessor::m_descriptor_set_ids, m_display_service, m_first_vertex, m_instance_count, m_pipeline_id, m_target_window, m_vertex_count, m_view_transform, m_view_transform_active, m_view_transform_descriptor_set_id, m_view_transform_source, m_view_transform_ubo, MF_RT_DEBUG, MF_RT_ERROR, MF_RT_TRACE, on_before_execute(), MayaFlux::Buffers::ShaderProcessor::resolve_ds_index(), MayaFlux::Buffers::ShaderProcessor::resolve_push_constants(), and width.

+ Here is the call graph for this function: