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.
525{
527 if (!cmd) {
529 "Invalid command buffer ID: {}", cmd_id);
530 return;
531 }
532
533 if (!window) {
535 "Cannot begin rendering for null window");
536 return;
537 }
538
539 if (!swapchain_image) {
541 "Cannot begin rendering with null swapchain image");
542 return;
543 }
544
548 "Window '{}' not registered for rendering. "
549 "Call register_window_for_rendering() first.",
550 window->get_create_info().title);
551 m_window_associations.emplace(window, WindowRenderAssociation { .window = window, .swapchain_image = swapchain_image });
552 } else {
553 it->second.swapchain_image = swapchain_image;
554 }
555
556 uint32_t width = 0, height = 0;
558
559 if (width == 0 || height == 0) {
561 "Invalid swapchain extent for window '{}': {}x{}",
562 window->get_create_info().title, width, height);
563 return;
564 }
565
567 if (!image_view) {
569 "Failed to get image view for window '{}'",
570 window->get_create_info().title);
571 return;
572 }
573
574 vk::ImageMemoryBarrier pre_barrier {};
575 pre_barrier.oldLayout = vk::ImageLayout::eUndefined;
576 pre_barrier.newLayout = vk::ImageLayout::eColorAttachmentOptimal;
577 pre_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
578 pre_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
579 pre_barrier.image = swapchain_image;
580 pre_barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;
581 pre_barrier.subresourceRange.baseMipLevel = 0;
582 pre_barrier.subresourceRange.levelCount = 1;
583 pre_barrier.subresourceRange.baseArrayLayer = 0;
584 pre_barrier.subresourceRange.layerCount = 1;
585 pre_barrier.srcAccessMask = vk::AccessFlagBits::eNone;
586 pre_barrier.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
587
588 cmd.pipelineBarrier(
589 vk::PipelineStageFlagBits::eTopOfPipe,
590 vk::PipelineStageFlagBits::eColorAttachmentOutput,
591 vk::DependencyFlags {},
592 0, nullptr,
593 0, nullptr,
594 1, &pre_barrier);
595
596 vk::RenderingAttachmentInfo color_attachment {};
597 color_attachment.sType = vk::StructureType::eRenderingAttachmentInfo;
598 color_attachment.pNext = nullptr;
599 color_attachment.imageView = image_view;
600 color_attachment.imageLayout = vk::ImageLayout::eColorAttachmentOptimal;
601 color_attachment.resolveMode = vk::ResolveModeFlagBits::eNone;
602 color_attachment.resolveImageView = nullptr;
603 color_attachment.resolveImageLayout = vk::ImageLayout::eUndefined;
604 color_attachment.loadOp = vk::AttachmentLoadOp::eClear;
605 color_attachment.storeOp = vk::AttachmentStoreOp::eStore;
606
608 color_attachment.clearValue.color = vk::ClearColorValue(clear_color);
609 } else {
610 color_attachment.clearValue.color = vk::ClearColorValue(window->get_create_info().clear_color);
611 }
612
613 vk::RenderingAttachmentInfo depth_attachment {};
614 if (depth_image_view) {
615 depth_attachment.sType = vk::StructureType::eRenderingAttachmentInfo;
616 depth_attachment.pNext = nullptr;
617 depth_attachment.imageView = depth_image_view;
618 depth_attachment.imageLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
619 depth_attachment.resolveMode = vk::ResolveModeFlagBits::eNone;
620 depth_attachment.resolveImageView = nullptr;
621 depth_attachment.resolveImageLayout = vk::ImageLayout::eUndefined;
622 depth_attachment.loadOp = vk::AttachmentLoadOp::eClear;
623 depth_attachment.storeOp = vk::AttachmentStoreOp::eDontCare;
624 depth_attachment.clearValue.depthStencil = vk::ClearDepthStencilValue { 1.0F, 0 };
625 }
626
627 vk::RenderingInfo rendering_info {};
628 rendering_info.sType = vk::StructureType::eRenderingInfo;
629 rendering_info.pNext = nullptr;
630 rendering_info.flags = vk::RenderingFlagBits::eContentsSecondaryCommandBuffers;
631 rendering_info.renderArea.offset = vk::Offset2D { 0, 0 };
632 rendering_info.renderArea.extent = vk::Extent2D { width, height };
633 rendering_info.layerCount = 1;
634 rendering_info.colorAttachmentCount = 1;
635 rendering_info.pColorAttachments = &color_attachment;
636 rendering_info.pDepthAttachment = depth_image_view ? &depth_attachment : nullptr;
637 rendering_info.pStencilAttachment = nullptr;
638
639 cmd.beginRendering(rendering_info);
640
642 "Began dynamic rendering for window '{}' ({}x{}, depth: {})",
643 window->get_create_info().title, width, height,
644 depth_image_view ? "yes" : "no");
645}
#define MF_RT_ERROR(comp, ctx,...)
#define MF_TRACE(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
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.