public unsafe UserInterface(Api api, Window window, SwapChain swapChain, DepthBuffer depthBuffer) { _swapChain = swapChain; // Initialise ImGui _imGuiController = new ImGuiController(api.Vk, window.IWindow, window.InputContext, new ImGuiFontConfig("./assets/fonts/Cousine-Regular.ttf", 13), api.Device.PhysicalDevice, api.Device.GraphicsFamilyIndex, swapChain.VkImages.Count, swapChain.Format, depthBuffer.Format); }
public unsafe Framebuffer(Api api, SwapChain swapChain, DepthBuffer depthBuffer, ImageView imageView, RenderPass renderPass) { (_api, _imageView, _renderPass) = (api, imageView, renderPass); var attachments = new Silk.NET.Vulkan.ImageView[] { imageView.VkImageView, depthBuffer.ImageView.VkImageView }; fixed(Silk.NET.Vulkan.ImageView *attachmentsPtr = &attachments[0]) { var framebufferInfo = new FramebufferCreateInfo(); framebufferInfo.SType = StructureType.FramebufferCreateInfo; framebufferInfo.RenderPass = renderPass.VkRenderPass; framebufferInfo.AttachmentCount = (uint)attachments.Length; framebufferInfo.PAttachments = attachmentsPtr; framebufferInfo.Width = swapChain.Extent.Width; framebufferInfo.Height = swapChain.Extent.Height; framebufferInfo.Layers = 1; Util.Verify(_api.Vk.CreateFramebuffer( _api.Vk.CurrentDevice.Value, framebufferInfo, default, out _vkFramebuffer), $"{nameof(Framebuffer)}: Failed to create framebuffer");
public unsafe RenderPass(Api api, SwapChain swapChain, DepthBuffer depthBuffer, AttachmentLoadOp colorBufferLoadOp, AttachmentLoadOp depthBufferLoadOp) { _api = api; var colorAttachment = new AttachmentDescription(); colorAttachment.Format = swapChain.Format; colorAttachment.Samples = SampleCountFlags.SampleCount1Bit; colorAttachment.LoadOp = colorBufferLoadOp; colorAttachment.StoreOp = AttachmentStoreOp.Store; colorAttachment.StencilLoadOp = AttachmentLoadOp.DontCare; colorAttachment.StencilStoreOp = AttachmentStoreOp.DontCare; colorAttachment.InitialLayout = colorBufferLoadOp == AttachmentLoadOp.Clear ? ImageLayout.Undefined : ImageLayout.PresentSrcKhr; colorAttachment.FinalLayout = ImageLayout.PresentSrcKhr; var depthAttachment = new AttachmentDescription(); depthAttachment.Format = depthBuffer.Format; depthAttachment.Samples = SampleCountFlags.SampleCount1Bit; depthAttachment.LoadOp = depthBufferLoadOp; depthAttachment.StoreOp = AttachmentStoreOp.DontCare; depthAttachment.StencilLoadOp = AttachmentLoadOp.DontCare; depthAttachment.StencilStoreOp = AttachmentStoreOp.DontCare; depthAttachment.InitialLayout = depthBufferLoadOp == AttachmentLoadOp.Clear ? ImageLayout.Undefined : ImageLayout.DepthStencilAttachmentOptimal; depthAttachment.FinalLayout = ImageLayout.DepthStencilAttachmentOptimal; var colorAttachmentRef = new AttachmentReference(); colorAttachmentRef.Attachment = 0; colorAttachmentRef.Layout = ImageLayout.ColorAttachmentOptimal; var depthAttachmentRef = new AttachmentReference(); depthAttachmentRef.Attachment = 1; depthAttachmentRef.Layout = ImageLayout.DepthStencilAttachmentOptimal; var subpass = new SubpassDescription(); subpass.PipelineBindPoint = PipelineBindPoint.Graphics; subpass.ColorAttachmentCount = 1; subpass.PColorAttachments = (AttachmentReference *)Unsafe.AsPointer(ref colorAttachmentRef); subpass.PDepthStencilAttachment = (AttachmentReference *)Unsafe.AsPointer(ref depthAttachmentRef); var dependency = new SubpassDependency(); dependency.SrcSubpass = Vk.SubpassExternal; dependency.DstSubpass = 0; dependency.SrcStageMask = PipelineStageFlags.PipelineStageColorAttachmentOutputBit; dependency.SrcAccessMask = 0; dependency.DstStageMask = PipelineStageFlags.PipelineStageColorAttachmentOutputBit; dependency.DstAccessMask = AccessFlags.AccessColorAttachmentReadBit | AccessFlags.AccessColorAttachmentWriteBit; Span <AttachmentDescription> attachments = stackalloc AttachmentDescription[] { colorAttachment, depthAttachment }; var renderPassInfo = new RenderPassCreateInfo(); renderPassInfo.SType = StructureType.RenderPassCreateInfo; renderPassInfo.AttachmentCount = (uint)attachments.Length; renderPassInfo.PAttachments = (AttachmentDescription *)Unsafe.AsPointer(ref attachments[0]); renderPassInfo.SubpassCount = 1; renderPassInfo.PSubpasses = (SubpassDescription *)Unsafe.AsPointer(ref subpass); renderPassInfo.DependencyCount = 1; renderPassInfo.PDependencies = (SubpassDependency *)Unsafe.AsPointer(ref dependency); Util.Verify( _api.Vk.CreateRenderPass(_api.Vk.CurrentDevice.Value, renderPassInfo, default, out _vkRenderPass),