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

◆ begin_rendering()

void MayaFlux::Portal::Graphics::RenderFlow::begin_rendering ( CommandBufferID  cmd_id,
const std::shared_ptr< Core::Window > &  window,
vk::Image  swapchain_image,
const std::array< float, 4 > &  clear_color = default_color,
vk::ImageView  depth_image_view = nullptr 
)

Begin dynamic rendering to a window.

Parameters
cmd_idCommand buffer ID
windowTarget window
swapchain_imageSwapchain image to render to
clear_colorClear color (RGBA)
depth_image_viewOptional depth attachment view (nullptr = no depth)

Uses vkCmdBeginRendering - no render pass objects needed. When depth_image_view is provided, depth clear value is 1.0.

Definition at line 575 of file RenderFlow.cpp.

581{
583 if (!cmd) {
585 "Invalid command buffer ID: {}", cmd_id);
586 return;
587 }
588
589 if (!window) {
591 "Cannot begin rendering for null window");
592 return;
593 }
594
595 if (!swapchain_image) {
597 "Cannot begin rendering with null swapchain image");
598 return;
599 }
600
601 auto it = m_window_associations.find(window);
602 if (it == m_window_associations.end()) {
604 "Window '{}' not registered for rendering. "
605 "Call register_window_for_rendering() first.",
606 window->get_create_info().title);
607 m_window_associations.emplace(window, WindowRenderAssociation { .window = window, .swapchain_image = swapchain_image });
608 } else {
609 it->second.swapchain_image = swapchain_image;
610 }
611
612 uint32_t width = 0, height = 0;
614
615 if (width == 0 || height == 0) {
617 "Invalid swapchain extent for window '{}': {}x{}",
618 window->get_create_info().title, width, height);
619 return;
620 }
621
622 vk::ImageView image_view = get_current_image_view(window);
623 if (!image_view) {
625 "Failed to get image view for window '{}'",
626 window->get_create_info().title);
627 return;
628 }
629
630 vk::ImageMemoryBarrier pre_barrier {};
631 pre_barrier.oldLayout = vk::ImageLayout::eUndefined;
632 pre_barrier.newLayout = vk::ImageLayout::eColorAttachmentOptimal;
633 pre_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
634 pre_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
635 pre_barrier.image = swapchain_image;
636 pre_barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;
637 pre_barrier.subresourceRange.baseMipLevel = 0;
638 pre_barrier.subresourceRange.levelCount = 1;
639 pre_barrier.subresourceRange.baseArrayLayer = 0;
640 pre_barrier.subresourceRange.layerCount = 1;
641 pre_barrier.srcAccessMask = vk::AccessFlagBits::eNone;
642 pre_barrier.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
643
644 cmd.pipelineBarrier(
645 vk::PipelineStageFlagBits::eTopOfPipe,
646 vk::PipelineStageFlagBits::eColorAttachmentOutput,
647 vk::DependencyFlags {},
648 0, nullptr,
649 0, nullptr,
650 1, &pre_barrier);
651
652 vk::RenderingAttachmentInfo color_attachment {};
653 color_attachment.sType = vk::StructureType::eRenderingAttachmentInfo;
654 color_attachment.pNext = nullptr;
655 color_attachment.imageView = image_view;
656 color_attachment.imageLayout = vk::ImageLayout::eColorAttachmentOptimal;
657 color_attachment.resolveMode = vk::ResolveModeFlagBits::eNone;
658 color_attachment.resolveImageView = nullptr;
659 color_attachment.resolveImageLayout = vk::ImageLayout::eUndefined;
660 color_attachment.loadOp = vk::AttachmentLoadOp::eClear;
661 color_attachment.storeOp = vk::AttachmentStoreOp::eStore;
662
663 if (clear_color != default_color) {
664 color_attachment.clearValue.color = vk::ClearColorValue(clear_color);
665 } else {
666 color_attachment.clearValue.color = vk::ClearColorValue(window->get_create_info().clear_color);
667 }
668
669 vk::RenderingAttachmentInfo depth_attachment {};
670 if (depth_image_view) {
671 depth_attachment.sType = vk::StructureType::eRenderingAttachmentInfo;
672 depth_attachment.pNext = nullptr;
673 depth_attachment.imageView = depth_image_view;
674 depth_attachment.imageLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
675 depth_attachment.resolveMode = vk::ResolveModeFlagBits::eNone;
676 depth_attachment.resolveImageView = nullptr;
677 depth_attachment.resolveImageLayout = vk::ImageLayout::eUndefined;
678 depth_attachment.loadOp = vk::AttachmentLoadOp::eClear;
679 depth_attachment.storeOp = vk::AttachmentStoreOp::eDontCare;
680 depth_attachment.clearValue.depthStencil = vk::ClearDepthStencilValue { 1.0F, 0 };
681 }
682
683 vk::RenderingInfo rendering_info {};
684 rendering_info.sType = vk::StructureType::eRenderingInfo;
685 rendering_info.pNext = nullptr;
686 rendering_info.flags = vk::RenderingFlagBits::eContentsSecondaryCommandBuffers;
687 rendering_info.renderArea.offset = vk::Offset2D { 0, 0 };
688 rendering_info.renderArea.extent = vk::Extent2D { width, height };
689 rendering_info.layerCount = 1;
690 rendering_info.colorAttachmentCount = 1;
691 rendering_info.pColorAttachments = &color_attachment;
692 rendering_info.pDepthAttachment = depth_image_view ? &depth_attachment : nullptr;
693 rendering_info.pStencilAttachment = nullptr;
694
695 cmd.beginRendering(rendering_info);
696
698 "Began dynamic rendering for window '{}' ({}x{}, depth: {})",
699 window->get_create_info().title, width, height,
700 depth_image_view ? "yes" : "no");
701}
#define MF_RT_ERROR(comp, ctx,...)
#define MF_TRACE(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
vk::CommandBuffer cmd
uint32_t width
std::unordered_map< std::shared_ptr< Core::Window >, WindowRenderAssociation > m_window_associations
vk::ImageView get_current_image_view(const std::shared_ptr< Core::Window > &window)
Get current image view for window.
Registry::Service::DisplayService * m_display_service
vk::CommandBuffer get_command_buffer(CommandBufferID cmd_id)
Get Vulkan command buffer handle from CommandBufferID.
@ Rendering
GPU rendering operations (graphics pipeline, frame rendering)
@ Portal
High-level user-facing API layer.
const std::array< float, 4 > default_color
std::function< void(const std::shared_ptr< void > &, uint32_t &, uint32_t &)> get_swapchain_extent
Get swapchain extent for a window.

References cmd, MayaFlux::Portal::Graphics::default_color, MayaFlux::Portal::Graphics::ShaderFoundry::get_command_buffer(), get_current_image_view(), MayaFlux::Registry::Service::DisplayService::get_swapchain_extent, m_display_service, m_shader_foundry, m_window_associations, MF_RT_ERROR, MF_TRACE, MF_WARN, MayaFlux::Journal::Portal, MayaFlux::Journal::Rendering, width, and MayaFlux::Portal::Graphics::RenderFlow::WindowRenderAssociation::window.

+ Here is the call graph for this function: