public RenderPass()
        {
            var anAttachmentDescription = new Interop.AttachmentDescription
            {
                Format         = VulkanRenderer.Surface.SelectedSurfaceFormat.Format,
                Samples        = Interop.SampleCountFlags.Count1,
                LoadOp         = Interop.AttachmentLoadOp.Clear,
                StoreOp        = Interop.AttachmentStoreOp.Store,
                StencilLoadOp  = Interop.AttachmentLoadOp.DontCare,
                StencilStoreOp = Interop.AttachmentStoreOp.DontCare,
                InitialLayout  = Interop.ImageLayout.Undefined,
                FinalLayout    = Interop.ImageLayout.PresentSrcKHR
            };
            var anAttachmentReference = new Interop.AttachmentReference {
                Layout = Interop.ImageLayout.ColorAttachmentOptimal
            };
            var aSubpassDescription = new Interop.SubpassDescription
            {
                PipelineBindPoint = Interop.PipelineBindPoint.Graphics,
                ColorAttachments  = new Interop.AttachmentReference[] { anAttachmentReference }
            };

            var aRenderPassCreateInfo = new Interop.RenderPassCreateInfo
            {
                Attachments = new Interop.AttachmentDescription[] { anAttachmentDescription },
                Subpasses   = new Interop.SubpassDescription[] { aSubpassDescription }
            };

            CreateRenderPass(aRenderPassCreateInfo);
        }
Example #2
0
        private void createRenderPass(VkContext context)
        {
            var colourAttachment = new Vk.AttachmentDescription();

            colourAttachment.Format         = this.wrapper.Format;
            colourAttachment.Samples        = Vk.SampleCountFlags.Count1;
            colourAttachment.LoadOp         = Vk.AttachmentLoadOp.Clear;
            colourAttachment.StoreOp        = Vk.AttachmentStoreOp.Store;
            colourAttachment.StencilLoadOp  = Vk.AttachmentLoadOp.DontCare;
            colourAttachment.StencilStoreOp = Vk.AttachmentStoreOp.DontCare;
            colourAttachment.InitialLayout  = Vk.ImageLayout.Undefined;
            colourAttachment.FinalLayout    = Vk.ImageLayout.PresentSrcKhr;

            var colourAttachmentRef = new Vk.AttachmentReference();

            colourAttachmentRef.Attachment = 0;
            colourAttachmentRef.Layout     = Vk.ImageLayout.ColorAttachmentOptimal;

            var depthAttachment = new Vk.AttachmentDescription();

            depthAttachment.Format         = VkHelper.FindDepthFormat(context);
            depthAttachment.Samples        = Vk.SampleCountFlags.Count1;
            depthAttachment.LoadOp         = Vk.AttachmentLoadOp.Clear;
            depthAttachment.StoreOp        = Vk.AttachmentStoreOp.DontCare;
            depthAttachment.StencilLoadOp  = Vk.AttachmentLoadOp.DontCare;
            depthAttachment.StencilStoreOp = Vk.AttachmentStoreOp.DontCare;
            depthAttachment.InitialLayout  = Vk.ImageLayout.Undefined;
            depthAttachment.FinalLayout    = Vk.ImageLayout.DepthStencilAttachmentOptimal;

            var depthAttachmentRef = new Vk.AttachmentReference();

            depthAttachmentRef.Attachment = 1;
            depthAttachmentRef.Layout     = Vk.ImageLayout.DepthStencilAttachmentOptimal;

            var subpass = new Vk.SubpassDescription();

            subpass.PipelineBindPoint    = Vk.PipelineBindPoint.Graphics;
            subpass.ColorAttachmentCount = 1;
            subpass.ColorAttachments     = new Vk.AttachmentReference[] {
                colourAttachmentRef
            };
            subpass.DepthStencilAttachment = depthAttachmentRef;

            var subpassDep = new Vk.SubpassDependency();

            subpassDep.SrcSubpass    = VkConstants.VK_SUBPASS_EXTERNAL;
            subpassDep.DstSubpass    = 0;
            subpassDep.SrcStageMask  = Vk.PipelineStageFlags.ColorAttachmentOutput;
            subpassDep.DstStageMask  = Vk.PipelineStageFlags.ColorAttachmentOutput;
            subpassDep.SrcAccessMask = 0;
            subpassDep.DstAccessMask = Vk.AccessFlags.ColorAttachmentRead | Vk.AccessFlags.ColorAttachmentWrite;

            var renderPassInfo = new Vk.RenderPassCreateInfo();

            renderPassInfo.AttachmentCount = 2;
            renderPassInfo.Attachments     = new Vk.AttachmentDescription[] {
                colourAttachment,
                depthAttachment
            };
            renderPassInfo.SubpassCount = 1;
            renderPassInfo.Subpasses    = new Vk.SubpassDescription[] {
                subpass
            };
            renderPassInfo.DependencyCount = 1;
            renderPassInfo.Dependencies    = new Vk.SubpassDependency[] {
                subpassDep
            };

            try {
                this.wrapper.RenderPass = context.Device.CreateRenderPass(renderPassInfo);
            } catch (Vk.ResultException result) {
                throw new VkException("An error occurred while creating a render pass.", result);
            }
        }