MayaFlux 0.4.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 472 of file RenderProcessor.cpp.

473{
474 if (m_buffer_info.find(buffer) == m_buffer_info.end()) {
475 if (buffer->has_vertex_layout()) {
476 auto vertex_layout = buffer->get_vertex_layout();
477 if (vertex_layout.has_value()) {
478 m_buffer_info[buffer] = {
479 .semantic_layout = vertex_layout.value(),
480 .use_reflection = false
481 };
482 }
483 }
484 }
485
486 if (!m_target_window->is_graphics_registered()) {
487 return;
488 }
489
491 return;
492 }
493
494 const Kakshya::VertexLayout* local_layout = get_or_cache_vertex_layout(m_buffer_info, buffer);
495 if (!local_layout) {
497 "VKBuffer has no vertex layout set. Use buffer->set_vertex_layout()");
498 return;
499 }
500
501 buffer->set_pipeline_window(m_pipeline_id, m_target_window);
502
503 auto& foundry = Portal::Graphics::get_shader_foundry();
505
506 vk::Format color_format = static_cast<vk::Format>(
508
509 vk::Format depth_format = m_depth_enabled
510 ? vk::Format::eD32Sfloat
511 : vk::Format::eUndefined;
512
513 auto cmd_id = foundry.begin_secondary_commands(color_format, depth_format);
514 auto cmd = foundry.get_command_buffer(cmd_id);
515
516 uint32_t width = 0, height = 0;
518
519 if (width > 0 && height > 0) {
520 auto cmd = foundry.get_command_buffer(cmd_id);
521
522 vk::Viewport viewport {
523 0.0F,
524 static_cast<float>(height),
525 static_cast<float>(width),
526 -static_cast<float>(height),
527 0.0F,
528 1.0F
529 };
530 cmd.setViewport(0, 1, &viewport);
531
532 vk::Rect2D scissor { { 0, 0 }, { width, height } };
533 cmd.setScissor(0, 1, &scissor);
534 }
535
536 flow.bind_pipeline(cmd_id, m_pipeline_id);
537
538 auto& engine_bindings = buffer->get_engine_context().ssbo_bindings;
539 for (const auto& binding : engine_bindings) {
540 if (binding.set == 0 && binding.binding == 0) {
542 "Engine SSBO at binding=0 is reserved for ViewTransform UBO");
543 continue;
544 }
547 "Engine SSBO binding {} skipped: engine descriptor set not allocated", binding.binding);
548 continue;
549 }
550 foundry.update_descriptor_buffer(
552 binding.binding,
553 binding.type,
554 binding.buffer_info.buffer,
555 binding.buffer_info.offset,
556 binding.buffer_info.range);
557 }
558
559 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
560 if (!descriptor_bindings.empty()) {
561 for (const auto& binding : descriptor_bindings) {
562 auto ds_index = resolve_ds_index(binding.set);
563 if (!ds_index) {
565 "Descriptor set index {} out of range or reserved", binding.set);
566 continue;
567 }
568
569 foundry.update_descriptor_buffer(
570 m_descriptor_set_ids[*ds_index],
571 binding.binding,
572 binding.type,
573 binding.buffer_info.buffer,
574 binding.buffer_info.offset,
575 binding.buffer_info.range);
576 }
577 }
578
579 if (!m_descriptor_set_ids.empty()) {
580 flow.bind_descriptor_sets(cmd_id, m_pipeline_id, m_descriptor_set_ids);
581 }
582
583 {
584 Kinesis::ViewTransform vt;
588 : m_view_transform.value_or(Kinesis::ViewTransform {});
589 }
590
591 if (m_view_transform_ubo && m_view_transform_ubo->get_mapped_ptr()) {
592 std::memcpy(
593 m_view_transform_ubo->get_mapped_ptr(),
594 &vt,
595 sizeof(Kinesis::ViewTransform));
596 }
597 }
598
600 flow.bind_descriptor_sets(
601 cmd_id, m_pipeline_id,
603 0);
604 }
605
606 if (!m_descriptor_set_ids.empty()) {
607 flow.bind_descriptor_sets(
608 cmd_id, m_pipeline_id,
610 1);
611 }
612
613 const auto& staging = buffer->get_pipeline_context();
614 if (!staging.push_constant_staging.empty()) {
615 flow.push_constants(
616 cmd_id,
618 staging.push_constant_staging.data(),
619 staging.push_constant_staging.size());
620 } else if (!m_push_constant_data.empty()) {
621 flow.push_constants(
622 cmd_id,
625 m_push_constant_data.size());
626 }
627
628 on_before_execute(cmd_id, buffer);
629
630 flow.bind_vertex_buffers(cmd_id, { buffer });
631
632 uint32_t draw_count = 0;
633 if (m_vertex_count > 0) {
634 draw_count = m_vertex_count;
635 } else {
636 auto current_layout = buffer->get_vertex_layout();
637 if (!current_layout.has_value() || current_layout->vertex_count == 0) {
639 "Vertex layout has zero vertices, skipping draw");
640 return;
641 }
642 draw_count = current_layout->vertex_count;
643 }
644
645 if (buffer->has_index_buffer()) {
646 const auto index_count = static_cast<uint32_t>(
647 buffer->get_index_buffer_size() / sizeof(uint32_t));
648 flow.bind_index_buffer(cmd_id, buffer);
649 flow.draw_indexed(cmd_id, index_count, m_instance_count, 0, 0, 0);
650 } else {
651 flow.draw(cmd_id, draw_count, m_instance_count, m_first_vertex, 0);
652 }
653
654 foundry.end_commands(cmd_id);
655
656 buffer->set_pipeline_command(m_pipeline_id, cmd_id);
657 m_target_window->track_frame_command(cmd_id);
658
660 "Recorded secondary command buffer {} for window '{}'",
661 cmd_id, m_target_window->get_create_info().title);
662}
#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:59
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< 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.
@ 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, 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, MayaFlux::Buffers::ShaderProcessor::m_push_constant_data, 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(), and width.

+ Here is the call graph for this function: