private RenderPass CreateRenderPass(SurfaceFormatKhr surfaceFormat) { var attDesc = new AttachmentDescription { Format = surfaceFormat.Format, Samples = SampleCountFlags.Count1, LoadOp = AttachmentLoadOp.Clear, StoreOp = AttachmentStoreOp.Store, StencilLoadOp = AttachmentLoadOp.DontCare, StencilStoreOp = AttachmentStoreOp.DontCare, InitialLayout = ImageLayout.ColorAttachmentOptimal, FinalLayout = ImageLayout.ColorAttachmentOptimal }; var attRef = new AttachmentReference { Layout = ImageLayout.ColorAttachmentOptimal }; var subpassDesc = new SubpassDescription { PipelineBindPoint = PipelineBindPoint.Graphics, ColorAttachments = new [] { attRef } }; var renderPassCreateInfo = new RenderPassCreateInfo { Attachments = new [] { attDesc }, Subpasses = new [] { subpassDesc } }; return(_device.CreateRenderPass(renderPassCreateInfo)); }
private void CreateSwapChain() { var swapChainSupport = new SwapChainSupportDetails(vkPhysicalDevice, vkSurface); SurfaceFormatKhr surfaceFormat = ChooseSwapSurfaceFormat(swapChainSupport.formats); PresentModeKhr presentMode = ChooseSwapPresentMode(swapChainSupport.presentModes); Extent2D extent = ChooseSwapExtent(swapChainSupport.capabilities); uint imageCount = swapChainSupport.capabilities.MinImageCount + 1; if (swapChainSupport.capabilities.MaxImageCount > 0) { imageCount = Math.Min(imageCount, swapChainSupport.capabilities.MaxImageCount); } var createInfo = new SwapchainCreateInfoKhr() { MinImageCount = imageCount, ImageFormat = surfaceFormat.Format, ImageColorSpace = surfaceFormat.ColorSpace, ImageExtent = extent, ImageArrayLayers = 1, ImageUsage = ImageUsageFlags.ColorAttachment, PreTransform = swapChainSupport.capabilities.CurrentTransform, CompositeAlpha = CompositeAlphaFlagsKhr.Opaque, PresentMode = presentMode, Surface = vkSurface, }; var indices = new QueueFamilyIndices(vkPhysicalDevice, vkSurface); if (indices.GraphicsFamily != indices.PresentFamily) { createInfo.ImageSharingMode = SharingMode.Concurrent; createInfo.QueueFamilyIndices = new[] { (uint)indices.GraphicsFamily, (uint)indices.PresentFamily, }; } else { createInfo.ImageSharingMode = SharingMode.Exclusive; } vkSwapChain = vkDevice.CreateSwapchainKHR(createInfo); vkSwapChainImages = vkDevice.GetSwapchainImagesKHR(vkSwapChain); vkSwapChainImageFormat = surfaceFormat.Format; vkSwapChainExtent = extent; }
protected void CreateSwapChain() { format = ChooseFormat(data.formats); var presentMode = ChoosePresentMode(data.presentModes); extent = ChooseSwapExtent(); var imageCount = data.surfaceCapabilities.MinImageCount + 1; if (data.surfaceCapabilities.MaxImageCount > 0 && imageCount > data.surfaceCapabilities.MaxImageCount) { imageCount = data.surfaceCapabilities.MaxImageCount; } var swapChainInfo = new SwapchainCreateInfoKhr { Surface = data.surface, MinImageCount = imageCount, ImageFormat = format.Format, ImageColorSpace = format.ColorSpace, ImageExtent = extent, ImageArrayLayers = 1, ImageUsage = ImageUsageFlags.ColorAttachment, PreTransform = data.surfaceCapabilities.CurrentTransform, CompositeAlpha = CompositeAlphaFlagsKhr.Opaque, PresentMode = presentMode, Clipped = true }; var indices = data.queueFamilyIndices; var queueFamilyIndices = new uint[] { (uint)indices.GraphicsFamily, (uint)indices.PresentFamily }; if (indices.PresentFamily != indices.GraphicsFamily) { swapChainInfo.ImageSharingMode = SharingMode.Concurrent; swapChainInfo.QueueFamilyIndexCount = (uint)queueFamilyIndices.Length; swapChainInfo.QueueFamilyIndices = queueFamilyIndices; } else { swapChainInfo.ImageSharingMode = SharingMode.Exclusive; } swapchain = device.CreateSwapchainKHR(swapChainInfo); images = device.GetSwapchainImagesKHR(swapchain); bufferSize = imageCount; }
private Framebuffer[] CreateFramebuffers(Image[] images, SurfaceFormatKhr surfaceFormat) { var displayViews = new ImageView[images.Length]; for (var i = 0; i < images.Length; i++) { var viewCreateInfo = new ImageViewCreateInfo { Image = images[i], ViewType = ImageViewType.View2D, Format = surfaceFormat.Format, Components = new ComponentMapping { R = ComponentSwizzle.R, G = ComponentSwizzle.G, B = ComponentSwizzle.B, A = ComponentSwizzle.A }, SubresourceRange = new ImageSubresourceRange { AspectMask = ImageAspectFlags.Color, LevelCount = 1, LayerCount = 1 } }; displayViews[i] = _device.CreateImageView(viewCreateInfo); } var framebuffers = new Framebuffer [images.Length]; for (var i = 0; i < images.Length; i++) { var frameBufferCreateInfo = new FramebufferCreateInfo { Layers = 1, RenderPass = _renderPass, Attachments = new[] { displayViews[i] }, Width = _surfaceCapabilities.CurrentExtent.Width, Height = _surfaceCapabilities.CurrentExtent.Height }; framebuffers[i] = _device.CreateFramebuffer(frameBufferCreateInfo); } return(framebuffers); }
SwapchainKhr CreateSwapchain(SurfaceKhr surface, SurfaceFormatKhr surfaceFormat) { var swapchainInfo = new SwapchainCreateInfoKhr { Surface = surface, MinImageCount = surfaceCapabilities.MinImageCount, ImageFormat = surfaceFormat.Format, ImageColorSpace = surfaceFormat.ColorSpace, ImageExtent = surfaceCapabilities.CurrentExtent, ImageUsage = ImageUsageFlags.ColorAttachment, PreTransform = SurfaceTransformFlagsKhr.Identity, ImageArrayLayers = 1, ImageSharingMode = SharingMode.Exclusive, QueueFamilyIndices = new uint [] { 0 }, PresentMode = PresentModeKhr.Fifo, CompositeAlpha = CompositeAlphaFlagsKhr.Inherit }; return(device.CreateSwapchainKHR(swapchainInfo)); }