Beispiel #1
0
        protected virtual void SetupRenderPass()
        {
            using (NativeList <VkAttachmentDescription> attachments = new NativeList <VkAttachmentDescription>())
            {
                attachments.Count = 2;
                // Color attachment
                attachments[0]                = new VkAttachmentDescription();
                attachments[0].format         = Swapchain.ColorFormat;
                attachments[0].samples        = VkSampleCountFlags._1;
                attachments[0].loadOp         = VkAttachmentLoadOp.Clear;
                attachments[0].storeOp        = VkAttachmentStoreOp.Store;
                attachments[0].stencilLoadOp  = VkAttachmentLoadOp.DontCare;
                attachments[0].stencilStoreOp = VkAttachmentStoreOp.DontCare;
                attachments[0].initialLayout  = VkImageLayout.Undefined;
                attachments[0].finalLayout    = VkImageLayout.PresentSrc;
                // Depth attachment
                attachments[1]                = new VkAttachmentDescription();
                attachments[1].format         = DepthFormat;
                attachments[1].samples        = VkSampleCountFlags._1;
                attachments[1].loadOp         = VkAttachmentLoadOp.Clear;
                attachments[1].storeOp        = VkAttachmentStoreOp.Store;
                attachments[1].stencilLoadOp  = VkAttachmentLoadOp.DontCare;
                attachments[1].stencilStoreOp = VkAttachmentStoreOp.DontCare;
                attachments[1].initialLayout  = VkImageLayout.Undefined;
                attachments[1].finalLayout    = VkImageLayout.DepthStencilAttachmentOptimal;

                VkAttachmentReference colorReference = new VkAttachmentReference();
                colorReference.attachment = 0;
                colorReference.layout     = VkImageLayout.ColorAttachmentOptimal;

                VkAttachmentReference depthReference = new VkAttachmentReference();
                depthReference.attachment = 1;
                depthReference.layout     = VkImageLayout.DepthStencilAttachmentOptimal;

                VkSubpassDescription subpassDescription = new VkSubpassDescription();
                subpassDescription.pipelineBindPoint       = VkPipelineBindPoint.Graphics;
                subpassDescription.colorAttachmentCount    = 1;
                subpassDescription.pColorAttachments       = &colorReference;
                subpassDescription.pDepthStencilAttachment = &depthReference;
                subpassDescription.inputAttachmentCount    = 0;
                subpassDescription.pInputAttachments       = null;
                subpassDescription.preserveAttachmentCount = 0;
                subpassDescription.pPreserveAttachments    = null;
                subpassDescription.pResolveAttachments     = null;

                // Subpass dependencies for layout transitions
                using (NativeList <VkSubpassDependency> dependencies = new NativeList <VkSubpassDependency>(2))
                {
                    dependencies.Count = 2;

                    dependencies[0].srcSubpass      = SubpassExternal;
                    dependencies[0].dstSubpass      = 0;
                    dependencies[0].srcStageMask    = VkPipelineStageFlags.BottomOfPipe;
                    dependencies[0].dstStageMask    = VkPipelineStageFlags.ColorAttachmentOutput;
                    dependencies[0].srcAccessMask   = VkAccessFlags.MemoryRead;
                    dependencies[0].dstAccessMask   = (VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite);
                    dependencies[0].dependencyFlags = VkDependencyFlags.ByRegion;

                    dependencies[1].srcSubpass      = 0;
                    dependencies[1].dstSubpass      = SubpassExternal;
                    dependencies[1].srcStageMask    = VkPipelineStageFlags.ColorAttachmentOutput;
                    dependencies[1].dstStageMask    = VkPipelineStageFlags.BottomOfPipe;
                    dependencies[1].srcAccessMask   = (VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite);
                    dependencies[1].dstAccessMask   = VkAccessFlags.MemoryRead;
                    dependencies[1].dependencyFlags = VkDependencyFlags.ByRegion;

                    VkRenderPassCreateInfo renderPassInfo = new VkRenderPassCreateInfo();
                    renderPassInfo.sType           = VkStructureType.RenderPassCreateInfo;
                    renderPassInfo.attachmentCount = attachments.Count;
                    renderPassInfo.pAttachments    = (VkAttachmentDescription *)attachments.Data.ToPointer();
                    renderPassInfo.subpassCount    = 1;
                    renderPassInfo.pSubpasses      = &subpassDescription;
                    renderPassInfo.dependencyCount = dependencies.Count;
                    renderPassInfo.pDependencies   = (VkSubpassDependency *)dependencies.Data;

                    Util.CheckResult(vkCreateRenderPass(Device, &renderPassInfo, null, out _renderPass));
                }
            }
        }