Begin dynamic rendering to a window.
Uses vkCmdBeginRendering - no render pass objects needed. When depth_image_view is provided, depth clear value is 1.0.
586{
590 "Invalid command buffer ID: {}", cmd_id);
591 return;
592 }
593
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
609 "Window '{}' not registered for rendering. "
610 "Call register_window_for_rendering() first.",
611 window->get_create_info().title);
613 } else {
614 it->second.swapchain_image = swapchain_image;
615 }
616
619
622 "Invalid swapchain extent for window '{}': {}x{}",
624 return;
625 }
626
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
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
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: {})",
705 depth_image_view ? "yes" : "no");
706}
#define MF_RT_ERROR(comp, ctx,...)
#define MF_TRACE(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::weak_ptr< Core::Window > window
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.
ShaderFoundry * m_shader_foundry
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.