Example #1
0
        public void createRenderPass()
        {
            VkAttachmentDescription colorAttachment = new VkAttachmentDescription();

            colorAttachment.format         = swapChainImageFormat;
            colorAttachment.samples        = VkSampleCountFlagBits.VK_SAMPLE_COUNT_1_BIT;
            colorAttachment.loadOp         = VkAttachmentLoadOp.VK_ATTACHMENT_LOAD_OP_CLEAR;
            colorAttachment.storeOp        = VkAttachmentStoreOp.VK_ATTACHMENT_STORE_OP_STORE;
            colorAttachment.stencilLoadOp  = VkAttachmentLoadOp.VK_ATTACHMENT_LOAD_OP_DONT_CARE;
            colorAttachment.stencilStoreOp = VkAttachmentStoreOp.VK_ATTACHMENT_STORE_OP_DONT_CARE;
            colorAttachment.initialLayout  = VkImageLayout.VK_IMAGE_LAYOUT_UNDEFINED;
            colorAttachment.finalLayout    = VkImageLayout.VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;

            VkAttachmentReference colorAttachmentRef = new VkAttachmentReference();

            colorAttachmentRef.attachment = 0;
            colorAttachmentRef.layout     = VkImageLayout.VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

            VkSubpassDescription subpass = new VkSubpassDescription();

            subpass.pipelineBindPoint    = VkPipelineBindPoint.VK_PIPELINE_BIND_POINT_GRAPHICS;
            subpass.colorAttachmentCount = 1;
            subpass.pColorAttachments    = new VkAttachmentReference[] { colorAttachmentRef };

            VkSubpassDependency dependency = new VkSubpassDependency();

            dependency.srcSubpass    = Vulkan.VK_SUBPASS_EXTERNAL;
            dependency.dstSubpass    = 0;
            dependency.srcStageMask  = VkPipelineStageFlagBits.VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
            dependency.srcAccessMask = 0;
            dependency.dstStageMask  = VkPipelineStageFlagBits.VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
            dependency.dstAccessMask = VkAccessFlagBits.VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VkAccessFlagBits.VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;

            VkRenderPassCreateInfo renderPassInfo = new VkRenderPassCreateInfo();

            renderPassInfo.sType           = VkStructureType.VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
            renderPassInfo.attachmentCount = 1;
            renderPassInfo.pAttachments    = new VkAttachmentDescription[] { colorAttachment };
            renderPassInfo.subpassCount    = 1;
            renderPassInfo.pSubpasses      = new VkSubpassDescription[] { subpass };
            renderPassInfo.dependencyCount = 1;
            renderPassInfo.pDependencies   = new VkSubpassDependency[] { dependency };

            VkResult result = Vulkan.vkCreateRenderPass(device, renderPassInfo, null, out renderPass);

            if (result != VkResult.VK_SUCCESS)
            {
                throw Program.Throw("failed to create render pass!", result);
            }
        }