Пример #1
0
        private void CreateRenderPass(VkFormat colorFormat)
        {
            VkAttachmentDescription attachment = new VkAttachmentDescription(
                colorFormat,
                VkSampleCountFlags.Count1,
                VkAttachmentLoadOp.Clear, VkAttachmentStoreOp.Store,
                VkAttachmentLoadOp.DontCare, VkAttachmentStoreOp.DontCare,
                VkImageLayout.Undefined, VkImageLayout.PresentSrcKHR
                );

            VkAttachmentReference colorAttachmentRef = new VkAttachmentReference(0, VkImageLayout.ColorAttachmentOptimal);

            VkSubpassDescription subpass = new VkSubpassDescription
            {
                pipelineBindPoint    = VkPipelineBindPoint.Graphics,
                colorAttachmentCount = 1,
                pColorAttachments    = &colorAttachmentRef
            };

            VkSubpassDependency[] dependencies = new VkSubpassDependency[2];

            dependencies[0] = new VkSubpassDependency
            {
                srcSubpass      = SubpassExternal,
                dstSubpass      = 0,
                srcStageMask    = VkPipelineStageFlags.BottomOfPipe,
                dstStageMask    = VkPipelineStageFlags.ColorAttachmentOutput,
                srcAccessMask   = VkAccessFlags.MemoryRead,
                dstAccessMask   = VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite,
                dependencyFlags = VkDependencyFlags.ByRegion
            };

            dependencies[1] = new VkSubpassDependency
            {
                srcSubpass      = 0,
                dstSubpass      = SubpassExternal,
                srcStageMask    = VkPipelineStageFlags.ColorAttachmentOutput,
                dstStageMask    = VkPipelineStageFlags.BottomOfPipe,
                srcAccessMask   = VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite,
                dstAccessMask   = VkAccessFlags.MemoryRead,
                dependencyFlags = VkDependencyFlags.ByRegion
            };

            fixed(VkSubpassDependency *dependenciesPtr = &dependencies[0])
            {
                VkRenderPassCreateInfo createInfo = new VkRenderPassCreateInfo
                {
                    sType           = VkStructureType.RenderPassCreateInfo,
                    attachmentCount = 1,
                    pAttachments    = &attachment,
                    subpassCount    = 1,
                    pSubpasses      = &subpass,
                    dependencyCount = 2,
                    pDependencies   = dependenciesPtr
                };

                vkCreateRenderPass(Device, &createInfo, null, out RenderPass).CheckResult();
            }
        }
Пример #2
0
        public AttachmentInfo(VkFormat format)
        {
            this.RTType           = format.IsDepthFormat() ? RTType.DepthOutput : RTType.ColorOutput;
            attachmentDescription = new VkAttachmentDescription(format, VkSampleCountFlags.Count1);

            if (Device.IsDepthFormat(format))
            {
                ClearValue = new VkClearDepthStencilValue(1, 0);
                id         = "depth";
            }
            else
            {
                ClearValue = new VkClearColorValue(0, 0, 0, 1);
                id         = "output_color";
            }
        }
Пример #3
0
        public AttachmentInfo(StringID id, SizeHint sizeHint, VkFormat format, VkImageUsageFlags usage, VkSampleCountFlags samples = VkSampleCountFlags.Count1)
        {
            this.id               = id;
            this.SizeHint         = sizeHint;
            this.Usage            = usage;
            attachmentDescription = new VkAttachmentDescription(format, samples);

            if (Device.IsDepthFormat(format))
            {
                ClearValue = new VkClearDepthStencilValue(1, 0);
            }
            else
            {
                ClearValue = new VkClearColorValue(0, 0, 0, 1);
            }
        }
Пример #4
0
        public AttachmentInfo(uint width, uint height, uint layers, VkFormat format, VkImageUsageFlags usage,
                              VkSampleCountFlags samples = VkSampleCountFlags.Count1)
        {
            this.Width            = width;
            this.Height           = height;
            this.Layers           = layers;
            this.Usage            = usage;
            attachmentDescription = new VkAttachmentDescription(format, samples);

            if (Device.IsDepthFormat(format))
            {
                ClearValue = new VkClearDepthStencilValue(1, 0);
            }
            else
            {
                ClearValue = new VkClearColorValue(0, 0, 0, 1);
            }
        }
Пример #5
0
        protected virtual void CreateRenderPass()
        {
            if (renderPassCreator != null)
            {
                RenderPass = renderPassCreator.Invoke();
            }
            else if (!renderTextureInfos.Empty())
            {
                var attachmentDescriptions = new VkAttachmentDescription[renderTextureInfos.Count];
                var subpassDescriptions    = new SubpassDescription[subpasses.Count];
                var dependencies           = new VkSubpassDependency[subpasses.Count + 1];

                for (int i = 0; i < renderTextureInfos.Count; i++)
                {
                    attachmentDescriptions[i] = renderTextureInfos[i].attachmentDescription;
                }

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

                for (int i = 0; i < subpasses.Count; i++)
                {
                    subpasses[i].GetDescription(attachmentDescriptions, ref subpassDescriptions[i]);

                    if (i > 0)
                    {
                        //dependencies[i] = subpasses[i].Dependency;
                        dependencies[i].srcSubpass      = (uint)(i - 1);
                        dependencies[i].dstSubpass      = (uint)i;
                        dependencies[i].srcStageMask    = VkPipelineStageFlags.ColorAttachmentOutput;
                        dependencies[i].dstStageMask    = VkPipelineStageFlags.FragmentShader;
                        dependencies[i].srcAccessMask   = VkAccessFlags.ColorAttachmentWrite;
                        dependencies[i].dstAccessMask   = VkAccessFlags.InputAttachmentRead;
                        dependencies[i].dependencyFlags = VkDependencyFlags.ByRegion;
                    }
                }

                dependencies[subpasses.Count] = new VkSubpassDependency
                {
                    srcSubpass      = (uint)(subpasses.Count - 1),
                    dstSubpass      = Vulkan.SubpassExternal,
                    srcStageMask    = VkPipelineStageFlags.ColorAttachmentOutput,
                    dstStageMask    = VkPipelineStageFlags.BottomOfPipe,
                    srcAccessMask   = VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite,
                    dstAccessMask   = VkAccessFlags.MemoryRead,
                    dependencyFlags = VkDependencyFlags.ByRegion
                };

                RenderPass = new RenderPass(attachmentDescriptions, subpassDescriptions, dependencies);
            }

            if (RenderPass == null)
            {
                RenderPass = Graphics.RenderPass;
            }
        }