private void Recreate() { _device.WaitIdle(); _swapchain = CreateSwapchain(_instance, _device, _physicalDevice, _surface, out _swapchainExtent, _swapchain, _vsyncEnabled); CreateSwapchainImages(); _surfaceChanged = true; }
private VulkanDisplay(VulkanInstance instance, VulkanDevice device, VulkanPhysicalDevice physicalDevice, VulkanSurface surface, SwapchainKHR swapchain, Extent2D swapchainExtent) { _instance = instance; _device = device; _physicalDevice = physicalDevice; _swapchain = swapchain; _swapchainExtent = swapchainExtent; _surface = surface; CreateSwapchainImages(); _semaphorePair = new VulkanSemaphorePair(_device); CommandBufferPool = new VulkanCommandBufferPool(device, physicalDevice); }
public static unsafe SwapchainCreateInfoKHR SwapchainCreateInfo(SurfaceKHR surface, uint imageCount, SurfaceFormatKHR format, PresentModeKHR presentMode, Extent2D extent, uint graphicsQueueFamily, uint presentQueueFamily, SurfaceCapabilitiesKHR surfaceCapabilities, SwapchainKHR oldSwapchain) { uint[] queueFamilies = new uint[] { graphicsQueueFamily, presentQueueFamily }; SwapchainCreateInfoKHR swapchainCreateInfo = new() { SType = StructureType.SwapchainCreateInfoKhr, Surface = surface, MinImageCount = imageCount, ImageFormat = format.Format, ImageColorSpace = format.ColorSpace, ImageExtent = extent, ImageArrayLayers = 1, ImageUsage = ImageUsageFlags.ImageUsageColorAttachmentBit, ImageSharingMode = (graphicsQueueFamily == presentQueueFamily) ? SharingMode.Exclusive : SharingMode.Concurrent, QueueFamilyIndexCount = (uint)((graphicsQueueFamily == presentQueueFamily) ? 0 : 2), PreTransform = surfaceCapabilities.CurrentTransform, CompositeAlpha = CompositeAlphaFlagsKHR.CompositeAlphaOpaqueBitKhr, PresentMode = presentMode, Clipped = true, OldSwapchain = oldSwapchain }; fixed(uint *ptr = queueFamilies) { swapchainCreateInfo.PQueueFamilyIndices = ptr; } return(swapchainCreateInfo); }
public partial Result GetPastPresentationTiming([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] ref uint pPresentationTimingCount, [Count(Parameter = "pPresentationTimingCount"), Flow(FlowDirection.Out)] out PastPresentationTimingGOOGLE pPresentationTimings);
/// <summary>To be documented.</summary> public static unsafe Result AcquireNextImage(this KhrSwapchain thisApi, [Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] ulong timeout, [Count(Count = 0)] Semaphore semaphore, [Count(Count = 0)] Fence fence, [Count(Count = 0)] Span <uint> pImageIndex) { // SpanOverloader return(thisApi.AcquireNextImage(device, swapchain, timeout, semaphore, fence, ref pImageIndex.GetPinnableReference())); }
public abstract Result GetRefreshCycleDuration([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0), Flow(FlowDirection.Out)] out RefreshCycleDurationGOOGLE pDisplayTimingProperties);
protected override void Free() { // Do _not_ call base.Free(). Swapchain images are disposed automatically. Handle = VkImage.Null; Swapchain = null; }
/// <summary>To be documented.</summary> public static unsafe Result GetSwapchainCounter(this ExtDisplayControl thisApi, [Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] SurfaceCounterFlagsEXT counter, [Count(Count = 0), Flow(FlowDirection.Out)] Span <ulong> pCounterValue) { // SpanOverloader return(thisApi.GetSwapchainCounter(device, swapchain, counter, out pCounterValue.GetPinnableReference())); }
public abstract unsafe Result GetSwapchainImages([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] uint *pSwapchainImageCount, [Count(Computed = "pSwapchainImageCount"), Flow(FlowDirection.Out)] Image *pSwapchainImages);
public abstract Result CreateSwapchain([Count(Count = 0)] Device device, [Count(Count = 0), Flow(FlowDirection.In)] ref SwapchainCreateInfoKHR pCreateInfo, [Count(Count = 0), Flow(FlowDirection.In)] ref AllocationCallbacks pAllocator, [Count(Count = 0), Flow(FlowDirection.Out)] out SwapchainKHR pSwapchain);
public unsafe partial Result CreateSharedSwapchain([Count(Count = 0)] Device device, [Count(Count = 0)] uint swapchainCount, [Count(Parameter = "swapchainCount"), Flow(FlowDirection.In)] SwapchainCreateInfoKHR *pCreateInfos, [Count(Count = 0), Flow(FlowDirection.In)] AllocationCallbacks *pAllocator, [Count(Parameter = "swapchainCount"), Flow(FlowDirection.Out)] out SwapchainKHR pSwapchains);
public unsafe partial Result AcquireNextImage([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] ulong timeout, [Count(Count = 0)] Semaphore semaphore, [Count(Count = 0)] Fence fence, [Count(Count = 0)] uint *pImageIndex);
public partial Result GetSwapchainStatus([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain);
public partial Result WaitForPresent([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] ulong presentId, [Count(Count = 0)] ulong timeout);
public unsafe partial Result GetRefreshCycleDuration([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0), Flow(FlowDirection.Out)] RefreshCycleDurationGOOGLE *pDisplayTimingProperties);
public abstract void SetHdrMetadata([Count(Count = 0)] Device device, [Count(Count = 0)] uint swapchainCount, [Count(Computed = "swapchainCount"), Flow(FlowDirection.In)] ref SwapchainKHR pSwapchains, [Count(Computed = "swapchainCount"), Flow(FlowDirection.In)] ref HdrMetadataEXT pMetadata);
public abstract Result AcquireNextImage([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] ulong timeout, [Count(Count = 0)] Semaphore semaphore, [Count(Count = 0)] Fence fence, [Count(Count = 0)] ref uint pImageIndex);
/// <summary>To be documented.</summary> public static unsafe Result GetPastPresentationTiming(this GoogleDisplayTiming thisApi, [Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] Span <uint> pPresentationTimingCount, [Count(Computed = "pPresentationTimingCount"), Flow(FlowDirection.Out)] Span <PastPresentationTimingGOOGLE> pPresentationTimings) { // SpanOverloader return(thisApi.GetPastPresentationTiming(device, swapchain, ref pPresentationTimingCount.GetPinnableReference(), out pPresentationTimings.GetPinnableReference())); }
public abstract void DestroySwapchain([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0), Flow(FlowDirection.In)] ref AllocationCallbacks pAllocator);
/// <summary>To be documented.</summary> public static unsafe Result GetRefreshCycleDuration(this GoogleDisplayTiming thisApi, [Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0), Flow(FlowDirection.Out)] Span <RefreshCycleDurationGOOGLE> pDisplayTimingProperties) { // SpanOverloader return(thisApi.GetRefreshCycleDuration(device, swapchain, out pDisplayTimingProperties.GetPinnableReference())); }
public abstract Result GetSwapchainImages([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] ref uint pSwapchainImageCount, [Count(Computed = "pSwapchainImageCount"), Flow(FlowDirection.Out)] out Image pSwapchainImages);
void CreateSwapChain() { CanRender = false; if (!vulkan.Device.IsZero) { vk.DeviceWaitIdle(vulkan.Device); } if (vulkan.SwapChain.Images != null) { for (int i = 0; i < vulkan.SwapChain.Images.Length; ++i) { if (vulkan.SwapChain.Images[i].View != ImageView.Zero) { vk.DestroyImageView(vulkan.Device, vulkan.SwapChain.Images[i].View); } } } SurfaceCapabilitiesKHR surface_capabilities; khrSurface.GetPhysicalDeviceSurfaceCapabilitiesKHR(vulkan.PhysicalDevice, vulkan.PresentationSurface, out surface_capabilities).CheckError(); var surface_formats = DelegateUtility.EnumerateToArray <SurfaceFormatKHR> (khrSurface.GetPhysicalDeviceSurfaceFormatsKHR, (IntPtr)vulkan.PhysicalDevice, (ulong)vulkan.PresentationSurface); var present_modes = DelegateUtility.EnumerateToArray <int> (khrSurface.GetPhysicalDeviceSurfacePresentModesKHR, (IntPtr)vulkan.PhysicalDevice, (ulong)vulkan.PresentationSurface); uint desired_number_of_images = GetSwapChainNumImages(ref surface_capabilities); SurfaceFormatKHR desired_format = GetSwapChainFormat(surface_formats); Extent2D desired_extent = GetSwapChainExtent(ref surface_capabilities); ImageUsageFlagBits desired_usage = GetSwapChainUsageFlagBits(ref surface_capabilities); SurfaceTransformFlagBitsKHR desired_transform = GetSwapChainTransform(ref surface_capabilities); PresentModeKHR desired_present_mode = GetSwapChainPresentMode(present_modes); SwapchainKHR old_swap_chain = vulkan.SwapChain.Handle; if (desired_usage == (ImageUsageFlagBits)(-1)) { return; } if (desired_present_mode == (PresentModeKHR)(-1)) { return; } if ((desired_extent.width == 0) || (desired_extent.height == 0)) { // Current surface size is (0, 0) so we can't create a swap chain and render anything (CanRender == false) // But we don't wont to kill the application as this situation may occur i.e. when window gets minimized return; } SwapchainCreateInfoKHR swap_chain_create_info = new SwapchainCreateInfoKHR { sType = StructureType.SwapchainCreateInfoKhr, // VkStructureType sType pNext = IntPtr.Zero, // const void *pNext flags = 0, // VkSwapchainCreateFlagBitsKHR flags surface = vulkan.PresentationSurface, // VkSurfaceKHR surface minImageCount = desired_number_of_images, // uint32_t minImageCount imageFormat = desired_format.format, // VkFormat imageFormat imageColorSpace = desired_format.colorSpace, // VkColorSpaceKHR imageColorSpace imageExtent = desired_extent, // VkExtent2D imageExtent imageArrayLayers = 1, // uint32_t imageArrayLayers imageUsage = desired_usage, // VkImageUsageFlagBits imageUsage imageSharingMode = SharingMode.Exclusive, // VkSharingMode imageSharingMode queueFamilyIndexCount = 0, // uint32_t queueFamilyIndexCount pQueueFamilyIndices = (uint *)0, // const uint32_t *pQueueFamilyIndices preTransform = desired_transform, // VkSurfaceTransformFlagBitsKHR preTransform compositeAlpha = CompositeAlphaFlagBitsKHR.OpaqueBitKhr, // VkCompositeAlphaFlagBitsKHR compositeAlpha presentMode = desired_present_mode, // VkPresentModeKHR presentMode clipped = Boolean32.True, // VkBool32 clipped oldSwapchain = old_swap_chain // VkSwapchainKHR oldSwapchain }; khrSwapChain.CreateSwapchainKHR(vulkan.Device, ref swap_chain_create_info, (AllocationCallbacks *)0, out vulkan.SwapChain.Handle).CheckError(); if (!old_swap_chain.IsZero) { khrSwapChain.DestroySwapchainKHR(vulkan.Device, old_swap_chain); } vulkan.SwapChain.Format = desired_format.format; var images = DelegateUtility.EnumerateToArray <Image> (khrSwapChain.GetSwapchainImagesKHR, (IntPtr)vulkan.Device, (ulong)vulkan.SwapChain.Handle); if (vulkan.SwapChain.Images == null || vulkan.SwapChain.Images.Length != images.Length) { vulkan.SwapChain.Images = new ImageParameters[images.Length]; } for (int i = 0; i < images.Length; ++i) { vulkan.SwapChain.Images[i].Handle = images[i]; } vulkan.SwapChain.Extent = desired_extent; CreateSwapChainImageViews(); }
public SwapchainImage(SwapchainKHR swapchain, VkImage handle) : base(swapchain.Device, handle, swapchain.Format, new VkExtent3D() { Width = swapchain.Dimensions.Width, Height = swapchain.Dimensions.Height, Depth = 1 }, 1, 1) { Swapchain = swapchain; }
public override void Draw() { SwapchainKHR swap_chain = GetSwapChain.Handle; uint image_index; var result = khrSwapChain.AcquireNextImageKHR(GetDevice, swap_chain, ulong.MaxValue, Vulkan.ImageAvailableSemaphore, default(Fence), out image_index); switch (result) { case Result.Success: case Result.SuboptimalKhr: break; case Result.ErrorOutOfDateKhr: OnWindowSizeChanged(); return; default: //std::cout << "Problem occurred during swap chain image acquisition!" << std::endl; return; } var a = Vulkan.ImageAvailableSemaphore; var b = Vulkan.GraphicsCommandBuffers[image_index]; var c = Vulkan.RenderingFinishedSemaphore; PipelineStageFlagBits wait_dst_stage_mask = PipelineStageFlagBits.ColorAttachmentOutputBit; var submit_info = new SubmitInfo { sType = StructureType.SubmitInfo, // VkStructureType sType pNext = IntPtr.Zero, // const void *pNext waitSemaphoreCount = 1, // uint32_t waitSemaphoreCount pWaitSemaphores = &a, // const VkSemaphore *pWaitSemaphores pWaitDestinationStageMask = &wait_dst_stage_mask, // const VkPipelineStageFlagBits *pWaitDstStageMask; commandBufferCount = 1, // uint32_t commandBufferCount pCommandBuffers = &b, // const VkCommandBuffer *pCommandBuffers signalSemaphoreCount = 1, // uint32_t signalSemaphoreCount pSignalSemaphores = &c // const VkSemaphore *pSignalSemaphores }; vk.QueueSubmit(GetGraphicsQueue.Handle, 1, &submit_info, default(Fence)).CheckError(); var present_info = new PresentInfoKHR { sType = StructureType.PresentInfoKhr, // VkStructureType sType pNext = IntPtr.Zero, // const void *pNext waitSemaphoreCount = 1, // uint32_t waitSemaphoreCount pWaitSemaphores = &c, // const VkSemaphore *pWaitSemaphores swapchainCount = 1, // uint32_t swapchainCount pSwapchains = &swap_chain, // const VkSwapchainKHR *pSwapchains pImageIndices = &image_index, // const uint32_t *pImageIndices pResults = (Result *)0 // VkResult *pResults }; result = khrSwapChain.QueuePresentKHR(GetPresentQueue.Handle, ref present_info); switch (result) { case Result.Success: break; case Result.SuboptimalKhr: case Result.ErrorOutOfDateKhr: OnWindowSizeChanged(); return; default: //std::cout << "Problem occurred during image presentation!" << std::endl; return; } }
public abstract Result GetPastPresentationTiming([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] ref uint pPresentationTimingCount, [Count(Computed = "pPresentationTimingCount"), Flow(FlowDirection.Out)] out PastPresentationTimingGOOGLE pPresentationTimings);
protected SwapchainCreationExample() : base() { this.Swapchain = CreateSwapchain(out this.SwapchainExtent, out this.SwapchainImageFormat, out this.SwapchainImages); }
/// <summary>To be documented.</summary> public static unsafe Result GetSwapchainImages(this KhrSwapchain thisApi, [Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0)] Span <uint> pSwapchainImageCount, [Count(Computed = "pSwapchainImageCount"), Flow(FlowDirection.Out)] Span <Image> pSwapchainImages) { // SpanOverloader return(thisApi.GetSwapchainImages(device, swapchain, ref pSwapchainImageCount.GetPinnableReference(), out pSwapchainImages.GetPinnableReference())); }
public partial void SetLocalDimming([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapChain, [Count(Count = 0)] Bool32 localDimmingEnable);
/// <summary>To be documented.</summary> public static unsafe void DestroySwapchain(this KhrSwapchain thisApi, [Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain, [Count(Count = 0), Flow(FlowDirection.In)] ReadOnlySpan <AllocationCallbacks> pAllocator) { // SpanOverloader thisApi.DestroySwapchain(device, swapchain, in pAllocator.GetPinnableReference()); }
public partial Result AcquireFullScreenExclusiveMode([Count(Count = 0)] Device device, [Count(Count = 0)] SwapchainKHR swapchain);