Beispiel #1
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;
            }
        }
Beispiel #2
0
 public void BeginRenderPass(ref RenderPassBeginInfo renderPassBeginInfo, VkSubpassContents contents)
 {
     vkCmdBeginRenderPass(commandBuffer, Utilities.AsPtr(ref renderPassBeginInfo.native), contents);
     renderPass = renderPassBeginInfo.renderPass;
     ClearDescriptorSets();
 }
Beispiel #3
0
        public RenderPass CreateRenderPass(bool clearColor = false, bool clearDepth = false)
        {
            VkAttachmentDescription[] attachments =
            {
                // Color attachment
                new VkAttachmentDescription(ColorFormat)
                {
                    loadOp      = clearColor? VkAttachmentLoadOp.Clear : VkAttachmentLoadOp.DontCare, // AttachmentLoadOp.Load,
                    storeOp     = VkAttachmentStoreOp.Store,
                    finalLayout = VkImageLayout.PresentSrcKHR
                },

                // Depth attachment
                new VkAttachmentDescription(DepthFormat)
                {
                    loadOp      = clearDepth? VkAttachmentLoadOp.Clear: VkAttachmentLoadOp.DontCare,
                    storeOp     = VkAttachmentStoreOp.DontCare,
                    finalLayout = VkImageLayout.DepthStencilAttachmentOptimal
                }
            };

            SubpassDescription[] subpassDescription =
            {
                new SubpassDescription
                {
                    pipelineBindPoint = VkPipelineBindPoint.Graphics,

                    pColorAttachments = new []
                    {
                        new VkAttachmentReference(0, VkImageLayout.ColorAttachmentOptimal)
                    },

                    pDepthStencilAttachment = new []
                    {
                        new VkAttachmentReference(1, VkImageLayout.DepthStencilAttachmentOptimal)
                    },
                }
            };

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

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

            renderPass = new RenderPass(attachments, subpassDescription, dependencies);
            return(renderPass);
        }