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

455{
456 if (m_buffer_info.find(buffer) == m_buffer_info.end()) {
457 if (buffer->has_vertex_layout()) {
458 auto vertex_layout = buffer->get_vertex_layout();
459 if (vertex_layout.has_value()) {
460 m_buffer_info[buffer] = {
461 .semantic_layout = vertex_layout.value(),
462 .use_reflection = false
463 };
464 }
465 }
466 }
467
468 if (!m_target_window->is_graphics_registered()) {
469 return;
470 }
471
473 return;
474 }
475
476 const Kakshya::VertexLayout* local_layout = get_or_cache_vertex_layout(m_buffer_info, buffer);
477 if (!local_layout) {
479 "VKBuffer has no vertex layout set. Use buffer->set_vertex_layout()");
480 return;
481 }
482
483 buffer->set_pipeline_window(m_pipeline_id, m_target_window);
484
485 auto& foundry = Portal::Graphics::get_shader_foundry();
487
488 vk::Format color_format = static_cast<vk::Format>(
490
491 auto cmd_id = foundry.begin_secondary_commands(color_format);
492 auto cmd = foundry.get_command_buffer(cmd_id);
493
494 uint32_t width = 0, height = 0;
496
497 if (width > 0 && height > 0) {
498 auto cmd = foundry.get_command_buffer(cmd_id);
499
500 vk::Viewport viewport {
501 0.0F,
502 static_cast<float>(height),
503 static_cast<float>(width),
504 -static_cast<float>(height),
505 0.0F,
506 1.0F
507 };
508 cmd.setViewport(0, 1, &viewport);
509
510 vk::Rect2D scissor { { 0, 0 }, { width, height } };
511 cmd.setScissor(0, 1, &scissor);
512 }
513
514 flow.bind_pipeline(cmd_id, m_pipeline_id);
515
516 auto& engine_bindings = buffer->get_engine_context().ssbo_bindings;
517 for (const auto& binding : engine_bindings) {
518 if (binding.set == 0 && binding.binding == 0) {
520 "Engine SSBO at binding=0 is reserved for ViewTransform UBO");
521 continue;
522 }
525 "Engine SSBO binding {} skipped: engine descriptor set not allocated", binding.binding);
526 continue;
527 }
528 foundry.update_descriptor_buffer(
530 binding.binding,
531 binding.type,
532 binding.buffer_info.buffer,
533 binding.buffer_info.offset,
534 binding.buffer_info.range);
535 }
536
537 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
538 if (!descriptor_bindings.empty()) {
539 for (const auto& binding : descriptor_bindings) {
540 auto ds_index = resolve_ds_index(binding.set);
541 if (!ds_index) {
543 "Descriptor set index {} out of range or reserved", binding.set);
544 continue;
545 }
546
547 foundry.update_descriptor_buffer(
548 m_descriptor_set_ids[*ds_index],
549 binding.binding,
550 binding.type,
551 binding.buffer_info.buffer,
552 binding.buffer_info.offset,
553 binding.buffer_info.range);
554 }
555 }
556
557 if (!m_descriptor_set_ids.empty()) {
558 flow.bind_descriptor_sets(cmd_id, m_pipeline_id, m_descriptor_set_ids);
559 }
560
561 {
562 Kinesis::ViewTransform vt;
566 : m_view_transform.value_or(Kinesis::ViewTransform {});
567 }
568
569 if (m_view_transform_ubo && m_view_transform_ubo->get_mapped_ptr()) {
570 std::memcpy(
571 m_view_transform_ubo->get_mapped_ptr(),
572 &vt,
573 sizeof(Kinesis::ViewTransform));
574 }
575 }
576
578 flow.bind_descriptor_sets(
579 cmd_id, m_pipeline_id,
581 0);
582 }
583
584 if (!m_descriptor_set_ids.empty()) {
585 flow.bind_descriptor_sets(
586 cmd_id, m_pipeline_id,
588 1);
589 }
590
591 const auto& staging = buffer->get_pipeline_context();
592 if (!staging.push_constant_staging.empty()) {
593 flow.push_constants(
594 cmd_id,
596 staging.push_constant_staging.data(),
597 staging.push_constant_staging.size());
598 } else if (!m_push_constant_data.empty()) {
599 flow.push_constants(
600 cmd_id,
603 m_push_constant_data.size());
604 }
605
606 on_before_execute(cmd_id, buffer);
607
608 flow.bind_vertex_buffers(cmd_id, { buffer });
609
610 uint32_t draw_count = 0;
611 if (m_vertex_count > 0) {
612 draw_count = m_vertex_count;
613 } else {
614 auto current_layout = buffer->get_vertex_layout();
615 if (!current_layout.has_value() || current_layout->vertex_count == 0) {
617 "Vertex layout has zero vertices, skipping draw");
618 return;
619 }
620 draw_count = current_layout->vertex_count;
621 }
622
623 if (buffer->has_index_buffer()) {
624 const auto index_count = static_cast<uint32_t>(
625 buffer->get_index_buffer_size() / sizeof(uint32_t));
626 flow.bind_index_buffer(cmd_id, buffer);
627 flow.draw_indexed(cmd_id, index_count, 1, 0, 0, 0);
628 } else {
629 flow.draw(cmd_id, draw_count, 1, m_first_vertex, 0);
630 }
631
632 foundry.end_commands(cmd_id);
633
634 buffer->set_pipeline_command(m_pipeline_id, cmd_id);
635 m_target_window->track_frame_command(cmd_id);
636
638 "Recorded secondary command buffer {} for window '{}'",
639 cmd_id, m_target_window->get_create_info().title);
640}
#define MF_RT_ERROR(comp, ctx,...)
#define MF_RT_TRACE(comp, ctx,...)
#define MF_RT_DEBUG(comp, ctx,...)
vk::CommandBuffer cmd
uint32_t width
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, MayaFlux::Buffers::ShaderProcessor::m_descriptor_set_ids, m_display_service, m_first_vertex, 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: