예제 #1
0
        Extent2D GetSwapChainExtent(ref SurfaceCapabilitiesKHR surface_capabilities)
        {
            // Special value of surface extent is width == height == -1
            // If this is so we define the size by ourselves but it must fit within defined confines
            if (surface_capabilities.currentExtent.width == unchecked ((uint)(-1)))
            {
                Extent2D swap_chain_extent = new Extent2D {
                    width = 640, height = 480
                };
                if (swap_chain_extent.width < surface_capabilities.minImageExtent.width)
                {
                    swap_chain_extent.width = surface_capabilities.minImageExtent.width;
                }
                if (swap_chain_extent.height < surface_capabilities.minImageExtent.height)
                {
                    swap_chain_extent.height = surface_capabilities.minImageExtent.height;
                }
                if (swap_chain_extent.width > surface_capabilities.maxImageExtent.width)
                {
                    swap_chain_extent.width = surface_capabilities.maxImageExtent.width;
                }
                if (swap_chain_extent.height > surface_capabilities.maxImageExtent.height)
                {
                    swap_chain_extent.height = surface_capabilities.maxImageExtent.height;
                }
                return(swap_chain_extent);
            }

            // Most of the cases we define size of the swap_chain images equal to current window's size
            return(surface_capabilities.currentExtent);
        }
예제 #2
0
            static uint GetMaxImageCountImpl(SurfaceCapabilitiesKHR surfaceCapabilities)
            {
                uint minImageCount = surfaceCapabilities.MinImageCount + 1;

                if ((surfaceCapabilities.MinImageCount > 0) && (minImageCount > surfaceCapabilities.MaxImageCount))
                {
                    minImageCount = surfaceCapabilities.MaxImageCount;
                }

                return(minImageCount);
            }
예제 #3
0
        uint GetSwapChainNumImages(ref SurfaceCapabilitiesKHR surface_capabilities)
        {
            // Set of images defined in a swap chain may not always be available for application to render to:
            // One may be displayed and one may wait in a queue to be presented
            // If application wants to use more images at the same time it must ask for more images
            uint image_count = surface_capabilities.minImageCount + 1;

            if ((surface_capabilities.maxImageCount > 0) &&
                (image_count > surface_capabilities.maxImageCount))
            {
                image_count = surface_capabilities.maxImageCount;
            }
            return(image_count);
        }
예제 #4
0
        public static Extent2D ChooseSwapExtent(SurfaceCapabilitiesKHR capabilities)
        {
            if (capabilities.CurrentExtent.Width != uint.MaxValue)
            {
                return(capabilities.CurrentExtent);
            }
            else
            {
                uint width  = Math.Max(capabilities.MinImageExtent.Width, Math.Min(capabilities.MaxImageExtent.Width, SurfaceWidth));
                uint height = Math.Max(capabilities.MinImageExtent.Height, Math.Min(capabilities.MaxImageExtent.Height, SurfaceHeight));

                return(new Extent2D(width, height));
            }
        }
예제 #5
0
        private static unsafe CompositeAlphaFlagsKHR GetSuitableCompositeAlphaFlags(SurfaceCapabilitiesKHR capabilities)
        {
            var compositeAlphaFlags = CompositeAlphaFlagsKHR.CompositeAlphaOpaqueBitKhr;

            if (capabilities.SupportedCompositeAlpha.HasFlag(CompositeAlphaFlagsKHR.CompositeAlphaPostMultipliedBitKhr))
            {
                compositeAlphaFlags = CompositeAlphaFlagsKHR.CompositeAlphaPostMultipliedBitKhr;
            }
            else if (capabilities.SupportedCompositeAlpha.HasFlag(CompositeAlphaFlagsKHR.CompositeAlphaPreMultipliedBitKhr))
            {
                compositeAlphaFlags = CompositeAlphaFlagsKHR.CompositeAlphaPreMultipliedBitKhr;
            }

            return(compositeAlphaFlags);
        }
예제 #6
0
 SurfaceTransformFlagBitsKHR GetSwapChainTransform(ref SurfaceCapabilitiesKHR surface_capabilities)
 {
     // Sometimes images must be transformed before they are presented (i.e. due to device's orienation
     // being other than default orientation)
     // If the specified transform is other than current transform, presentation engine will transform image
     // during presentation operation; this operation may hit performance on some platforms
     // Here we don't want any transformations to occur so if the identity transform is supported use it
     // otherwise just use the same transform as current transform
     if ((surface_capabilities.supportedTransforms & SurfaceTransformFlagBitsKHR.IdentityBitKhr) > 0)
     {
         return(SurfaceTransformFlagBitsKHR.IdentityBitKhr);
     }
     else
     {
         return(surface_capabilities.currentTransform);
     }
 }
예제 #7
0
        private static unsafe Extent2D GetSwapchainExtent(VulkanSurface surface, SurfaceCapabilitiesKHR capabilities)
        {
            Extent2D swapchainExtent;

            if (capabilities.CurrentExtent.Width != uint.MaxValue)
            {
                swapchainExtent = capabilities.CurrentExtent;
            }
            else
            {
                var surfaceSize = surface.SurfaceSize;

                var width  = Math.Clamp((uint)surfaceSize.Width, capabilities.MinImageExtent.Width, capabilities.MaxImageExtent.Width);
                var height = Math.Clamp((uint)surfaceSize.Height, capabilities.MinImageExtent.Height, capabilities.MaxImageExtent.Height);

                swapchainExtent = new Extent2D(width, height);
            }

            return(swapchainExtent);
        }
예제 #8
0
 ImageUsageFlagBits GetSwapChainUsageFlagBits(ref SurfaceCapabilitiesKHR surface_capabilities)
 {
     // Color attachment flag must always be supported
     // We can define other usage flags but we always need to check if they are supported
     if ((surface_capabilities.supportedUsageFlags & ImageUsageFlagBits.ColorAttachmentBit) > 0)
     {
         return(ImageUsageFlagBits.ColorAttachmentBit);
     }
     //std::cout << "VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT image usage is not supported by the swap chain!" << std::endl
     //  << "Supported swap chain's image usages include:" << std::endl
     //  << (surface_capabilities.supportedUsageFlagBits & VK_IMAGE_USAGE_TRANSFER_SRC_BIT ? "    VK_IMAGE_USAGE_TRANSFER_SRC\n" : "")
     //  << (surface_capabilities.supportedUsageFlagBits & VK_IMAGE_USAGE_TRANSFER_DST_BIT ? "    VK_IMAGE_USAGE_TRANSFER_DST\n" : "")
     //  << (surface_capabilities.supportedUsageFlagBits & VK_IMAGE_USAGE_SAMPLED_BIT ? "    VK_IMAGE_USAGE_SAMPLED\n" : "")
     //  << (surface_capabilities.supportedUsageFlagBits & VK_IMAGE_USAGE_STORAGE_BIT ? "    VK_IMAGE_USAGE_STORAGE\n" : "")
     //  << (surface_capabilities.supportedUsageFlagBits & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ? "    VK_IMAGE_USAGE_COLOR_ATTACHMENT\n" : "")
     //  << (surface_capabilities.supportedUsageFlagBits & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT ? "    VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT\n" : "")
     //  << (surface_capabilities.supportedUsageFlagBits & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT ? "    VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT\n" : "")
     //  << (surface_capabilities.supportedUsageFlagBits & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT ? "    VK_IMAGE_USAGE_INPUT_ATTACHMENT" : "")
     //  << std::endl;
     return((ImageUsageFlagBits)(-1));
 }
예제 #9
0
 public abstract Result GetPhysicalDeviceSurfaceCapabilities([Count(Count = 0)] PhysicalDevice physicalDevice, [Count(Count = 0)] SurfaceKHR surface, [Count(Count = 0), Flow(FlowDirection.Out)] out SurfaceCapabilitiesKHR pSurfaceCapabilities);
예제 #10
0
        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);
        }