MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Tools / prepare_render_pass

Method prepare_render_pass

cube/cube.cpp:2688–2751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2686}
2687
2688void Demo::prepare_render_pass() {
2689 // The initial layout for the color and depth attachments will be LAYOUT_UNDEFINED
2690 // because at the start of the renderpass, we don't care about their contents.
2691 // At the start of the subpass, the color attachment's layout will be transitioned
2692 // to LAYOUT_COLOR_ATTACHMENT_OPTIMAL and the depth stencil attachment's layout
2693 // will be transitioned to LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL. At the end of
2694 // the renderpass, the color attachment's layout will be transitioned to
2695 // LAYOUT_PRESENT_SRC_KHR to be ready to present. This is all done as part of
2696 // the renderpass, no barriers are necessary.
2697 std::array<vk::AttachmentDescription, 2> const attachments = {
2698 vk::AttachmentDescription()
2699 .setFormat(format)
2700 .setSamples(vk::SampleCountFlagBits::e1)
2701 .setLoadOp(vk::AttachmentLoadOp::eClear)
2702 .setStoreOp(vk::AttachmentStoreOp::eStore)
2703 .setStencilLoadOp(vk::AttachmentLoadOp::eDontCare)
2704 .setStencilStoreOp(vk::AttachmentStoreOp::eDontCare)
2705 .setInitialLayout(vk::ImageLayout::eUndefined)
2706 .setFinalLayout(vk::ImageLayout::ePresentSrcKHR),
2707 vk::AttachmentDescription()
2708 .setFormat(depth.format)
2709 .setSamples(vk::SampleCountFlagBits::e1)
2710 .setLoadOp(vk::AttachmentLoadOp::eClear)
2711 .setStoreOp(vk::AttachmentStoreOp::eDontCare)
2712 .setStencilLoadOp(vk::AttachmentLoadOp::eDontCare)
2713 .setStencilStoreOp(vk::AttachmentStoreOp::eDontCare)
2714 .setInitialLayout(vk::ImageLayout::eUndefined)
2715 .setFinalLayout(vk::ImageLayout::eDepthStencilAttachmentOptimal)};
2716
2717 auto const color_reference = vk::AttachmentReference().setAttachment(0).setLayout(vk::ImageLayout::eColorAttachmentOptimal);
2718
2719 auto const depth_reference =
2720 vk::AttachmentReference().setAttachment(1).setLayout(vk::ImageLayout::eDepthStencilAttachmentOptimal);
2721
2722 auto const subpass = vk::SubpassDescription()
2723 .setPipelineBindPoint(vk::PipelineBindPoint::eGraphics)
2724 .setColorAttachments(color_reference)
2725 .setPDepthStencilAttachment(&depth_reference);
2726
2727 vk::PipelineStageFlags stages = vk::PipelineStageFlagBits::eEarlyFragmentTests | vk::PipelineStageFlagBits::eLateFragmentTests;
2728 std::array<vk::SubpassDependency, 2> const dependencies = {
2729 vk::SubpassDependency() // Depth buffer is shared between swapchain images
2730 .setSrcSubpass(VK_SUBPASS_EXTERNAL)
2731 .setDstSubpass(0)
2732 .setSrcStageMask(stages)
2733 .setDstStageMask(stages)
2734 .setSrcAccessMask(vk::AccessFlagBits::eDepthStencilAttachmentWrite)
2735 .setDstAccessMask(vk::AccessFlagBits::eDepthStencilAttachmentRead | vk::AccessFlagBits::eDepthStencilAttachmentWrite)
2736 .setDependencyFlags(vk::DependencyFlags()),
2737 vk::SubpassDependency() // Image layout transition
2738 .setSrcSubpass(VK_SUBPASS_EXTERNAL)
2739 .setDstSubpass(0)
2740 .setSrcStageMask(vk::PipelineStageFlagBits::eColorAttachmentOutput)
2741 .setDstStageMask(vk::PipelineStageFlagBits::eColorAttachmentOutput)
2742 .setSrcAccessMask(vk::AccessFlagBits())
2743 .setDstAccessMask(vk::AccessFlagBits::eColorAttachmentWrite | vk::AccessFlagBits::eColorAttachmentRead)
2744 .setDependencyFlags(vk::DependencyFlags()),
2745 };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected