Beispiel #1
0
        public void Set(params VkAttachmentDescription[] value)
        {
            IntPtr ptr = (IntPtr)this.pointer;

            value.Set(ref ptr, ref this.count);
            this.pointer = (VkAttachmentDescription *)ptr;
        }
Beispiel #2
0
 public VkAttachmentDescriptionGroup(params VkAttachmentDescription[] value)
 {
     this.count   = 0;
     this.pointer = null;
     if (value != null)
     {
         IntPtr ptr = IntPtr.Zero;
         value.Set(ref ptr, ref this.count);
         this.pointer = (VkAttachmentDescription *)ptr;
     }
 }
Beispiel #3
0
        internal void CreateRenderPass()
        {
            VkFormat color_format = SwapChain.color_format;
            VkFormat depth_format = SwapChain.DepthStencil.Format;


            // Descriptors for the attachments used by this renderpass
            VkAttachmentDescription *attachments = stackalloc VkAttachmentDescription[2]
            {
                // Color attachment
                new VkAttachmentDescription
                {
                    format         = color_format,                                   // Use the color format selected by the swapchain
                    samples        = VkSampleCountFlags.Count1,                      // We don't use multi sampling in this example
                    loadOp         = VkAttachmentLoadOp.Clear,                       // Clear this attachment at the start of the render pass
                    storeOp        = VkAttachmentStoreOp.Store,                      // Keep it's contents after the render pass is finished (for displaying it)
                    stencilLoadOp  = VkAttachmentLoadOp.DontCare,                    // We don't use stencil, so don't care for load
                    stencilStoreOp = VkAttachmentStoreOp.DontCare,                   // Same for store
                    initialLayout  = VkImageLayout.Undefined,                        // Layout at render pass start. Initial doesn't matter, so we use undefined
                    finalLayout    = VkImageLayout.PresentSrcKHR                     // Layout to which the attachment is transitioned when the render pass is finished
                },



                // Use the color format selected by the swapchain
                // As we want to present the color buffer to the swapchain, we transition to PRESENT_KHR
                // Depth attachment
                // A proper depth format is selected in the example base

                new VkAttachmentDescription
                {
                    format         = depth_format,                                   // A proper depth format is selected in the example base
                    samples        = VkSampleCountFlags.Count1,
                    loadOp         = VkAttachmentLoadOp.Clear,                       // Clear depth at start of first subpass
                    storeOp        = VkAttachmentStoreOp.DontCare,                   // We don't need depth after render pass has finished (DONT_CARE may result in better performance)
                    stencilLoadOp  = VkAttachmentLoadOp.DontCare,                    // No stencil
                    stencilStoreOp = VkAttachmentStoreOp.DontCare,                   // No Stencil
                    initialLayout  = VkImageLayout.Undefined,                        // Layout at render pass start. Initial doesn't matter, so we use undefined
                    finalLayout    = VkImageLayout.ColorAttachmentOptimal            // Transition to depth/stencil attachment
                },
            };


            // Setup attachment references
            VkAttachmentReference *colorReferences = stackalloc VkAttachmentReference[1]
            {
                new VkAttachmentReference                                               // Attachment layout used as color during the subpass
                {
                    attachment = 0,                                                     // Attachment 0 is color
                    layout     = VkImageLayout.ColorAttachmentOptimal
                }
            };


            VkAttachmentReference depthReference = new VkAttachmentReference
            {
                attachment = 1,                                                             // Attachment 1 is color
                layout     = VkImageLayout.DepthStencilAttachmentOptimal                    // Attachment used as depth/stemcil used during the subpass
            };


            // Setup a single subpass reference
            VkSubpassDescription *subpass_description = stackalloc VkSubpassDescription[1]
            {
                new VkSubpassDescription
                {
                    pipelineBindPoint       = VkPipelineBindPoint.Graphics,
                    colorAttachmentCount    = 1,                                                // Subpass uses one color attachment
                    pColorAttachments       = colorReferences,                                  // Reference to the color attachment in slot 0
                    pDepthStencilAttachment = &depthReference,                                  // Reference to the depth attachment in slot 1
                    inputAttachmentCount    = 0,                                                // Input attachments can be used to sample from contents of a previous subpass
                    pInputAttachments       = null,                                             // (Input attachments not used by this example)
                    preserveAttachmentCount = 0,                                                // Preserved attachments can be used to loop (and preserve) attachments through subpasses
                    pPreserveAttachments    = null,                                             // (Preserve attachments not used by this example)
                    pResolveAttachments     = null                                              // Resolve attachments are resolved at the end of a sub pass and can be used for e.g. multi sampling
                },
            };



            // Setup subpass dependencies
            // These will add the implicit ttachment layout transitionss specified by the attachment descriptions
            // The actual usage layout is preserved through the layout specified in the attachment reference
            // Each subpass dependency will introduce a memory and execution dependency between the source and dest subpass described by
            // srcStageMask, dstStageMask, srcAccessMask, dstAccessMask (and dependencyFlags is set)
            // Note: VK_SUBPASS_EXTERNAL is a special constant that refers to all commands executed outside of the actual renderpass)
            VkSubpassDependency *dependencies = stackalloc VkSubpassDependency[2]
            {
                // First dependency at the start of the renderpass
                // Does the transition from final to initial layout
                new VkSubpassDependency
                {
                    srcSubpass      = SubpassExternal,                              // Producer of the dependency
                    dstSubpass      = 0,                                            // Consumer is our single subpass that will wait for the execution depdendency
                    srcStageMask    = VkPipelineStageFlags.BottomOfPipe,
                    dstStageMask    = VkPipelineStageFlags.ColorAttachmentOutput,
                    srcAccessMask   = VkAccessFlags.MemoryRead,
                    dstAccessMask   = VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite,
                    dependencyFlags = VkDependencyFlags.ByRegion
                },

                // Second dependency at the end the renderpass
                // Does the transition from the initial to the final layout
                new VkSubpassDependency
                {
                    srcSubpass      = 0,                                            // Producer of the dependency is our single subpass
                    dstSubpass      = SubpassExternal,                              // Consumer are all commands outside of the renderpass
                    srcStageMask    = VkPipelineStageFlags.ColorAttachmentOutput,
                    dstStageMask    = VkPipelineStageFlags.BottomOfPipe,
                    srcAccessMask   = VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite,
                    dstAccessMask   = VkAccessFlags.MemoryRead,
                    dependencyFlags = VkDependencyFlags.ByRegion
                }
            };



            // Create the actual renderpass
            VkRenderPassCreateInfo render_pass_info = new VkRenderPassCreateInfo()
            {
                sType           = VkStructureType.RenderPassCreateInfo,
                attachmentCount = 2,                                             // Number of attachments used by this render pass
                pAttachments    = attachments,                                   // Descriptions of the attachments used by the render pass
                subpassCount    = 1,                                             // We only use one subpass in this example
                pSubpasses      = subpass_description,                           // Description of that subpass
                dependencyCount = 2,                                             // Number of subpass dependencies
                pDependencies   = dependencies,
            };

            vkCreateRenderPass(NativeDevice.handle, &render_pass_info, null, out renderPass).CheckResult();
        }
        private VkRenderPass CreateRenderPass()
        {
            VkAttachmentDescription *attachments = stackalloc VkAttachmentDescription[2]
            {
                // Color attachment.
                new VkAttachmentDescription
                {
                    format         = SwapchainFormat,
                    samples        = VkSampleCountFlags.Count1,
                    loadOp         = VkAttachmentLoadOp.Clear,
                    storeOp        = VkAttachmentStoreOp.Store,
                    stencilLoadOp  = VkAttachmentLoadOp.DontCare,
                    stencilStoreOp = VkAttachmentStoreOp.DontCare,
                    initialLayout  = VkImageLayout.Undefined,
                    finalLayout    = VkImageLayout.PresentSrcKHR
                },
                // Depth attachment.
                new VkAttachmentDescription
                {
                    format         = _depthStencilBuffer.Format,
                    samples        = VkSampleCountFlags.Count1,
                    loadOp         = VkAttachmentLoadOp.Clear,
                    storeOp        = VkAttachmentStoreOp.DontCare,
                    stencilLoadOp  = VkAttachmentLoadOp.DontCare,
                    stencilStoreOp = VkAttachmentStoreOp.DontCare,
                    initialLayout  = VkImageLayout.Undefined,
                    finalLayout    = VkImageLayout.DepthStencilAttachmentOptimal
                }
            };


            VkAttachmentReference colorAttachment = new VkAttachmentReference
            {
                attachment = 0,
                layout     = VkImageLayout.ColorAttachmentOptimal
            };
            VkAttachmentReference depthStencilAttachment = new VkAttachmentReference
            {
                attachment = 1,
                layout     = VkImageLayout.DepthStencilAttachmentOptimal
            };

            var subpass = new VkSubpassDescription
            {
                colorAttachmentCount    = 1,
                pColorAttachments       = &colorAttachment,
                pDepthStencilAttachment = &depthStencilAttachment
            };

            VkSubpassDependency *dependencies = stackalloc VkSubpassDependency[2]
            {
                new VkSubpassDependency
                {
                    srcSubpass      = uint.MaxValue, // 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      = uint.MaxValue, // SubpassExternal ?
                    srcStageMask    = VkPipelineStageFlags.ColorAttachmentOutput,
                    dstStageMask    = VkPipelineStageFlags.BottomOfPipe,
                    srcAccessMask   = VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite,
                    dstAccessMask   = VkAccessFlags.MemoryRead,
                    dependencyFlags = VkDependencyFlags.ByRegion
                }
            };

            var createInfo = new VkRenderPassCreateInfo
            {
                sType           = VkStructureType.RenderPassCreateInfo,
                pNext           = null,
                subpassCount    = 1,
                pSubpasses      = &subpass,
                attachmentCount = 2,
                pAttachments    = attachments,
                dependencyCount = 2,
                pDependencies   = dependencies
            };


            VkRenderPass renderPass;

            vkCreateRenderPass(Context.Device, &createInfo, null, out renderPass).CheckResult();
            return(renderPass);
        }