Пример #1
0
 public override void Activate()
 {
     if (state != ActivableState.Activated)
     {
         presentComplete = Dev.CreateSemaphore();
         presentComplete.SetDebugMarkerName(Dev, "Semaphore PresentComplete");
     }
     base.Activate();
 }
Пример #2
0
        /// <summary>
        /// Create/recreate swapchain and populate images array
        /// </summary>
        public void Create()
        {
            Dev.WaitIdle();

            VkSurfaceCapabilitiesKHR capabilities = Dev.phy.GetSurfaceCapabilities(presentQueue.Surface);

            createInfos.minImageCount = capabilities.minImageCount;
            createInfos.preTransform  = capabilities.currentTransform;
            createInfos.oldSwapchain  = Handle;

            if (capabilities.currentExtent.width == 0xFFFFFFFF)
            {
                if (createInfos.imageExtent.width < capabilities.minImageExtent.width)
                {
                    createInfos.imageExtent.width = capabilities.minImageExtent.width;
                }
                else if (createInfos.imageExtent.width > capabilities.maxImageExtent.width)
                {
                    createInfos.imageExtent.width = capabilities.maxImageExtent.width;
                }

                if (createInfos.imageExtent.height < capabilities.minImageExtent.height)
                {
                    createInfos.imageExtent.height = capabilities.minImageExtent.height;
                }
                else if (createInfos.imageExtent.height > capabilities.maxImageExtent.height)
                {
                    createInfos.imageExtent.height = capabilities.maxImageExtent.height;
                }
            }
            else
            {
                createInfos.imageExtent = capabilities.currentExtent;
            }

            Utils.CheckResult(vkCreateSwapchainKHR(Dev.VkDev, ref createInfos, IntPtr.Zero, out VkSwapchainKHR newSwapChain));

            if (Handle.Handle != 0)
            {
                _destroy();
            }

            presentComplete = Dev.CreateSemaphore();
            presentComplete.SetDebugMarkerName(Dev, "Semaphore PresentComplete");
            Handle = newSwapChain;

            Utils.CheckResult(vkGetSwapchainImagesKHR(Dev.VkDev, Handle, out uint imageCount, IntPtr.Zero));
            if (imageCount == 0)
            {
                throw new Exception("Swapchain image count is 0.");
            }
            VkImage[] imgs = new VkImage[imageCount];
            Utils.CheckResult(vkGetSwapchainImagesKHR(Dev.VkDev, Handle, out imageCount, imgs.Pin()));
            imgs.Unpin();

            images = new Image[imgs.Length];
            for (int i = 0; i < imgs.Length; i++)
            {
                images[i] = new Image(Dev, imgs[i], ColorFormat, ImageUsage, Width, Height);
                images[i].CreateView();
                images[i].SetName("SwapChain Img" + i);
                images[i].Descriptor.imageView.SetDebugMarkerName(Dev, "SwapChain Img" + i + " view");
            }
        }