public void Dispose() { VK.DestroySemaphore(device, imageAvailableSemaphore, alloc); VK.DestroySemaphore(device, renderFinishedSemaphore, alloc); VK.DestroyCommandPool(device, commandPool, alloc); foreach (var fb in swapchainFramebuffers) { VK.DestroyFramebuffer(device, fb, alloc); } VK.DestroyPipeline(device, pipeline, alloc); VK.DestroyPipelineLayout(device, pipelineLayout, alloc); VK.DestroyRenderPass(device, renderPass, alloc); foreach (var iv in swapchainImageViews) { VK.DestroyImageView(device, iv, alloc); } destroySwapchain(device, swapchain, alloc); VK.DestroyDevice(device, alloc); destroySurface(instance, surface, alloc); VK.DestroyInstance(instance, alloc); GLFW.Terminate(); }
void CreateRenderPass() { var colorAttachment = new VkAttachmentDescription(); colorAttachment.format = swapchainImageFormat; colorAttachment.samples = CSGL.Vulkan.VkSampleCountFlags._1_Bit; colorAttachment.loadOp = CSGL.Vulkan.VkAttachmentLoadOp.Clear; colorAttachment.storeOp = CSGL.Vulkan.VkAttachmentStoreOp.Store; colorAttachment.stencilLoadOp = CSGL.Vulkan.VkAttachmentLoadOp.DontCare; colorAttachment.stencilStoreOp = CSGL.Vulkan.VkAttachmentStoreOp.DontCare; colorAttachment.initialLayout = CSGL.Vulkan.VkImageLayout.Undefined; colorAttachment.finalLayout = CSGL.Vulkan.VkImageLayout.PresentSrcKhr; var colorAttachmentNative = new Native <VkAttachmentDescription>(colorAttachment); var colorAttachmentRef = new VkAttachmentReference(); colorAttachmentRef.attachment = 0; colorAttachmentRef.layout = CSGL.Vulkan.VkImageLayout.ColorAttachmentOptimal; var colorAttachmentRefNative = new Native <VkAttachmentReference>(colorAttachmentRef); var subpass = new VkSubpassDescription(); subpass.pipelineBindPoint = CSGL.Vulkan.VkPipelineBindPoint.Graphics; subpass.colorAttachmentCount = 1; subpass.pColorAttachments = colorAttachmentRefNative.Address; var subpassNative = new Native <VkSubpassDescription>(subpass); var dependency = new VkSubpassDependency(); dependency.srcSubpass = uint.MaxValue; //VK_SUBPASS_EXTERNAL dependency.dstSubpass = 0; dependency.srcStageMask = CSGL.Vulkan.VkPipelineStageFlags.BottomOfPipeBit; dependency.srcAccessMask = CSGL.Vulkan.VkAccessFlags.MemoryReadBit; dependency.dstStageMask = CSGL.Vulkan.VkPipelineStageFlags.ColorAttachmentOutputBit; dependency.dstAccessMask = CSGL.Vulkan.VkAccessFlags.ColorAttachmentReadBit | CSGL.Vulkan.VkAccessFlags.ColorAttachmentWriteBit; var dependencyNative = new Native <VkSubpassDependency>(dependency); var info = new VkRenderPassCreateInfo(); info.sType = CSGL.Vulkan.VkStructureType.RenderPassCreateInfo; info.attachmentCount = 1; info.pAttachments = colorAttachmentNative.Address; info.subpassCount = 1; info.pSubpasses = subpassNative.Address; info.dependencyCount = 1; info.pDependencies = dependencyNative.Address; if (renderPass != VkRenderPass.Null) { VK.DestroyRenderPass(device, renderPass, alloc); } var result = VK.CreateRenderPass(device, ref info, alloc, out renderPass); colorAttachmentNative.Dispose(); colorAttachmentRefNative.Dispose(); subpassNative.Dispose(); dependencyNative.Dispose(); }