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 473 of file RenderProcessor.cpp.

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