Пример #1
0
        private void createDepthResources(VkContext context)
        {
            var depthFormat = VkHelper.FindDepthFormat(context);
            var depthImage  = VkHelper.CreateImage(context,
                                                   this.wrapper.Extent.Width, this.wrapper.Extent.Height,
                                                   depthFormat, Vk.ImageTiling.Optimal, Vk.ImageUsageFlags.DepthStencilAttachment,
                                                   Vk.MemoryPropertyFlags.DeviceLocal);

            var depthImageView = VkHelper.CreateImageView(context, depthImage.Image, depthFormat,
                                                          Vk.ImageAspectFlags.Depth);

            context.TransitionImageLayout(depthImage.Image, depthFormat, Vk.ImageLayout.Undefined,
                                          Vk.ImageLayout.DepthStencilAttachmentOptimal);

            this.wrapper.DepthImage       = depthImage.Image;
            this.wrapper.DepthImageMemory = depthImage.Memory;
            this.wrapper.DepthImageView   = depthImageView;
        }
Пример #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);
            }
        }