MayaFlux 1.0.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 580 of file RenderFlow.cpp.

586{
588 if (!cmd) {
590 "Invalid command buffer ID: {}", cmd_id);
591 return;
592 }
593
594 if (!window) {
596 "Cannot begin rendering for null window");
597 return;
598 }
599
600 if (!swapchain_image) {
602 "Cannot begin rendering with null swapchain image");
603 return;
604 }
605
606 auto it = m_window_associations.find(window);
607 if (it == m_window_associations.end()) {
609 "Window '{}' not registered for rendering. "
610 "Call register_window_for_rendering() first.",
611 window->get_create_info().title);
612 m_window_associations.emplace(window, WindowRenderAssociation { .window = window, .swapchain_image = swapchain_image });
613 } else {
614 it->second.swapchain_image = swapchain_image;
615 }
616
617 uint32_t width = 0, height = 0;
619
620 if (width == 0 || height == 0) {
622 "Invalid swapchain extent for window '{}': {}x{}",
623 window->get_create_info().title, width, height);
624 return;
625 }
626
627 vk::ImageView image_view = get_current_image_view(window);
628 if (!image_view) {
630 "Failed to get image view for window '{}'",
631 window->get_create_info().title);
632 return;
633 }
634
635 vk::ImageMemoryBarrier pre_barrier {};
636 pre_barrier.oldLayout = vk::ImageLayout::eUndefined;
637 pre_barrier.newLayout = vk::ImageLayout::eColorAttachmentOptimal;
638 pre_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
639 pre_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
640 pre_barrier.image = swapchain_image;
641 pre_barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;
642 pre_barrier.subresourceRange.baseMipLevel = 0;
643 pre_barrier.subresourceRange.levelCount = 1;
644 pre_barrier.subresourceRange.baseArrayLayer = 0;
645 pre_barrier.subresourceRange.layerCount = 1;
646 pre_barrier.srcAccessMask = vk::AccessFlagBits::eNone;
647 pre_barrier.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
648
649 cmd.pipelineBarrier(
650 vk::PipelineStageFlagBits::eTopOfPipe,
651 vk::PipelineStageFlagBits::eColorAttachmentOutput,
652 vk::DependencyFlags {},
653 0, nullptr,
654 0, nullptr,
655 1, &pre_barrier);
656
657 vk::RenderingAttachmentInfo color_attachment {};
658 color_attachment.sType = vk::StructureType::eRenderingAttachmentInfo;
659 color_attachment.pNext = nullptr;
660 color_attachment.imageView = image_view;
661 color_attachment.imageLayout = vk::ImageLayout::eColorAttachmentOptimal;
662 color_attachment.resolveMode = vk::ResolveModeFlagBits::eNone;
663 color_attachment.resolveImageView = nullptr;
664 color_attachment.resolveImageLayout = vk::ImageLayout::eUndefined;
665 color_attachment.loadOp = vk::AttachmentLoadOp::eClear;
666 color_attachment.storeOp = vk::AttachmentStoreOp::eStore;
667
668 if (clear_color != default_color) {
669 color_attachment.clearValue.color = vk::ClearColorValue(clear_color);
670 } else {
671 color_attachment.clearValue.color = vk::ClearColorValue(window->get_create_info().clear_color);
672 }
673
674 vk::RenderingAttachmentInfo depth_attachment {};
675 if (depth_image_view) {
676 depth_attachment.sType = vk::StructureType::eRenderingAttachmentInfo;
677 depth_attachment.pNext = nullptr;
678 depth_attachment.imageView = depth_image_view;
679 depth_attachment.imageLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
680 depth_attachment.resolveMode = vk::ResolveModeFlagBits::eNone;
681 depth_attachment.resolveImageView = nullptr;
682 depth_attachment.resolveImageLayout = vk::ImageLayout::eUndefined;
683 depth_attachment.loadOp = vk::AttachmentLoadOp::eClear;
684 depth_attachment.storeOp = vk::AttachmentStoreOp::eDontCare;
685 depth_attachment.clearValue.depthStencil = vk::ClearDepthStencilValue { 1.0F, 0 };
686 }
687
688 vk::RenderingInfo rendering_info {};
689 rendering_info.sType = vk::StructureType::eRenderingInfo;
690 rendering_info.pNext = nullptr;
691 rendering_info.flags = vk::RenderingFlagBits::eContentsSecondaryCommandBuffers;
692 rendering_info.renderArea.offset = vk::Offset2D { 0, 0 };
693 rendering_info.renderArea.extent = vk::Extent2D { width, height };
694 rendering_info.layerCount = 1;
695 rendering_info.colorAttachmentCount = 1;
696 rendering_info.pColorAttachments = &color_attachment;
697 rendering_info.pDepthAttachment = depth_image_view ? &depth_attachment : nullptr;
698 rendering_info.pStencilAttachment = nullptr;
699
700 cmd.beginRendering(rendering_info);
701
703 "Began dynamic rendering for window '{}' ({}x{}, depth: {})",
704 window->get_create_info().title, width, height,
705 depth_image_view ? "yes" : "no");
706}
#define MF_RT_ERROR(comp, ctx,...)
#define MF_TRACE(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
vk::CommandBuffer cmd
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
uint32_t width
uint32_t height
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, height, m_display_service, m_shader_foundry, m_window_associations, MF_RT_ERROR, MF_TRACE, MF_WARN, MayaFlux::Journal::Portal, MayaFlux::Journal::Rendering, width, window, and MayaFlux::Portal::Graphics::RenderFlow::WindowRenderAssociation::window.

+ Here is the call graph for this function: