예제 #1
0
 /// <summary>
 ///
 /// </summary>
 public SurfaceCapabilities(uint minImageCount, uint maxImageCount, Extent2D currentExtent, Extent2D minImageExtent, Extent2D maxImageExtent, uint maxImageArrayLayers, SurfaceTransformFlags supportedTransforms, SurfaceTransformFlags currentTransform, CompositeAlphaFlags supportedCompositeAlpha, ImageUsageFlags supportedUsageFlags)
 {
     this.MinImageCount           = minImageCount;
     this.MaxImageCount           = maxImageCount;
     this.CurrentExtent           = currentExtent;
     this.MinImageExtent          = minImageExtent;
     this.MaxImageExtent          = maxImageExtent;
     this.MaxImageArrayLayers     = maxImageArrayLayers;
     this.SupportedTransforms     = supportedTransforms;
     this.CurrentTransform        = currentTransform;
     this.SupportedCompositeAlpha = supportedCompositeAlpha;
     this.SupportedUsageFlags     = supportedUsageFlags;
 }
예제 #2
0
 /// <summary>
 /// Returns the granularity for optimal render area.
 /// </summary>
 public Extent2D GetRenderAreaGranularity()
 {
     unsafe
     {
         try
         {
             Extent2D result = default(Extent2D);
             Interop.Commands.vkGetRenderAreaGranularity(this.parent.handle, this.handle, &result);
             return(result);
         }
         finally
         {
             Interop.HeapUtil.FreeLog();
         }
     }
 }
예제 #3
0
        private void CreateSwapChain()
        {
            SwapChainSupportDetails swapChainSupport = this.QuerySwapChainSupport(this.physicalDevice);

            uint imageCount = swapChainSupport.Capabilities.MinImageCount + 1;

            if (swapChainSupport.Capabilities.MaxImageCount > 0 && imageCount > swapChainSupport.Capabilities.MaxImageCount)
            {
                imageCount = swapChainSupport.Capabilities.MaxImageCount;
            }

            SurfaceFormat surfaceFormat = this.ChooseSwapSurfaceFormat(swapChainSupport.Formats);

            QueueFamilyIndices queueFamilies = this.FindQueueFamilies(this.physicalDevice);

            var indices = queueFamilies.Indices.ToArray();

            Extent2D extent = this.ChooseSwapExtent(swapChainSupport.Capabilities);

            this.swapChain = device.CreateSwapchain(new SwapchainCreateInfo
            {
                Surface          = surface,
                Flags            = SwapchainCreateFlags.None,
                PresentMode      = this.ChooseSwapPresentMode(swapChainSupport.PresentModes),
                MinImageCount    = imageCount,
                ImageExtent      = extent,
                ImageUsage       = ImageUsageFlags.ColorAttachment,
                PreTransform     = swapChainSupport.Capabilities.CurrentTransform,
                ImageArrayLayers = 1,
                ImageSharingMode = indices.Length == 1
                                    ? SharingMode.Exclusive
                                    : SharingMode.Concurrent,
                QueueFamilyIndices = indices,
                ImageFormat        = surfaceFormat.Format,
                ImageColorSpace    = surfaceFormat.ColorSpace,
                Clipped            = true,
                CompositeAlpha     = CompositeAlphaFlags.Opaque,
                OldSwapchain       = this.swapChain
            });

            this.swapChainImages = this.swapChain.GetImages();
            this.swapChainFormat = surfaceFormat.Format;
            this.swapChainExtent = extent;
        }
예제 #4
0
        /// <summary>
        /// Initialize this swap chain on a specified surface.
        /// </summary>
        /// <param name="surface">Target video surface.</param>
        /// <param name="surfaceSize">Swap queue target size.</param>
        public void Initialize(Surface surface, Vector2i surfaceSize)
        {
            base.Initialize(surface, surfaceSize);

            VKSurface vkSurface = surface as VKSurface;

            // - Get capabilites and hardware information
            SurfaceCapabilities Capabilities = GraphicsCard.Handle.GetSurfaceCapabilities(vkSurface.Handle);

            formats      = GraphicsCard.Handle.GetSurfaceFormats(vkSurface.Handle);
            presentModes = GraphicsCard.Handle.GetSurfacePresentModes(vkSurface.Handle);

            uint imageCount = Capabilities.MinImageCount + 1;

            if (Capabilities.MaxImageCount > 0 && imageCount > Capabilities.MaxImageCount)
            {
                imageCount = Capabilities.MaxImageCount;
            }

            // - Default video format -> the first one
            surfaceFormat = formats[0];

            // - Checks for a BGRA32 video format
            foreach (var format in formats)
            {
                if (format.Format == Format.B8G8R8A8UNorm && format.ColorSpace == ColorSpace.SrgbNonlinear)
                {
                    surfaceFormat = format;
                    break;
                }
            }

            // - Checks if ther're no avaiable formats and we create a new one
            if (formats.Length == 1 && formats[0].Format == Format.Undefined)
            {
                surfaceFormat = new SharpVk.Khronos.SurfaceFormat
                {
                    Format     = Format.B8G8R8A8UNorm,
                    ColorSpace = ColorSpace.SrgbNonlinear
                };
            }

            // - Computes the swap chain drawing surface size
            Extent2D extent = Capabilities.CurrentExtent;

            if (extent.Width != uint.MaxValue)
            {
                long Width  = Math.Max(Capabilities.MinImageExtent.Width, Math.Min(Capabilities.MaxImageExtent.Width, surfaceSize.Width));
                long Height = Math.Max(Capabilities.MinImageExtent.Height, Math.Min(Capabilities.MaxImageExtent.Height, surfaceSize.Height));
                extent = new Extent2D((uint)Width, (uint)Height);
            }

            // - Shortcut (to avoid long parameters on the next call)
            var  queues    = new[] { RenderDevice.PresentQueueIndex, RenderDevice.GraphicQueueIndex };
            bool exclusive = RenderDevice.GraphicQueueIndex == RenderDevice.PresentQueueIndex;

            Handle = RenderDevice.Handle.CreateSwapchain
                     (
                vkSurface.Handle, imageCount,
                surfaceFormat.Format,
                surfaceFormat.ColorSpace,
                extent, 1, ImageUsageFlags.ColorAttachment,
                exclusive ? SharingMode.Exclusive : SharingMode.Concurrent, exclusive ? null : queues,
                Capabilities.CurrentTransform, CompositeAlphaFlags.Opaque,
                PresentModes.Contains(PresentMode.Mailbox) ? PresentMode.Mailbox : PresentMode.Fifo,
                true, Handle
                     );

            images      = Handle.GetImages();
            this.extent = extent;
        }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 public DisplayModeParameters(Extent2D visibleRegion, uint refreshRate)
 {
     this.VisibleRegion = visibleRegion;
     this.RefreshRate   = refreshRate;
 }
예제 #6
0
 /// <summary>
 ///
 /// </summary>
 public DisplayPlaneCapabilities(DisplayPlaneAlphaFlags supportedAlpha, Offset2D minSourcePosition, Offset2D maxSourcePosition, Extent2D minSourceExtent, Extent2D maxSourceExtent, Offset2D minDestinationPosition, Offset2D maxDestinationPosition, Extent2D minDestinationExtent, Extent2D maxDestinationExtent)
 {
     this.SupportedAlpha         = supportedAlpha;
     this.MinSourcePosition      = minSourcePosition;
     this.MaxSourcePosition      = maxSourcePosition;
     this.MinSourceExtent        = minSourceExtent;
     this.MaxSourceExtent        = maxSourceExtent;
     this.MinDestinationPosition = minDestinationPosition;
     this.MaxDestinationPosition = maxDestinationPosition;
     this.MinDestinationExtent   = minDestinationExtent;
     this.MaxDestinationExtent   = maxDestinationExtent;
 }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 public Rect2D(Offset2D offset, Extent2D extent)
 {
     this.Offset = offset;
     this.Extent = extent;
 }