{-# language CPP #-}
module Graphics.Vulkan.Extensions.VK_KHR_get_surface_capabilities2 ( getPhysicalDeviceSurfaceCapabilities2KHR
, getPhysicalDeviceSurfaceFormats2KHR
, PhysicalDeviceSurfaceInfo2KHR(..)
, SurfaceCapabilities2KHR(..)
, SurfaceFormat2KHR(..)
, KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION
, pattern KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION
, KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME
, pattern KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME
, SurfaceKHR(..)
, SurfaceCapabilitiesKHR(..)
, SurfaceFormatKHR(..)
, ColorSpaceKHR(..)
, CompositeAlphaFlagBitsKHR(..)
, CompositeAlphaFlagsKHR
, SurfaceTransformFlagBitsKHR(..)
, SurfaceTransformFlagsKHR
) where
import Control.Exception.Base (bracket)
import Data.Typeable (eqT)
import Foreign.Marshal.Alloc (allocaBytesAligned)
import Foreign.Marshal.Alloc (callocBytes)
import Foreign.Marshal.Alloc (free)
import GHC.Base (when)
import GHC.IO (throwIO)
import GHC.Ptr (castPtr)
import Foreign.Ptr (nullPtr)
import Foreign.Ptr (plusPtr)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Cont (evalContT)
import Data.Vector (generateM)
import Data.String (IsString)
import Data.Type.Equality ((:~:)(Refl))
import Data.Typeable (Typeable)
import Foreign.Storable (Storable(peek))
import Foreign.Storable (Storable(poke))
import Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import Data.Word (Word32)
import Data.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import Data.Vector (Vector)
import Graphics.Vulkan.CStruct.Utils (advancePtrBytes)
import Graphics.Vulkan.NamedType ((:::))
import Graphics.Vulkan.CStruct.Extends (Chain)
import {-# SOURCE #-} Graphics.Vulkan.Extensions.VK_AMD_display_native_hdr (DisplayNativeHdrSurfaceCapabilitiesAMD)
import Graphics.Vulkan.CStruct.Extends (Extends)
import Graphics.Vulkan.CStruct.Extends (Extensible(..))
import Graphics.Vulkan.CStruct (FromCStruct)
import Graphics.Vulkan.CStruct (FromCStruct(..))
import Graphics.Vulkan.Dynamic (InstanceCmds(pVkGetPhysicalDeviceSurfaceCapabilities2KHR))
import Graphics.Vulkan.Dynamic (InstanceCmds(pVkGetPhysicalDeviceSurfaceFormats2KHR))
import Graphics.Vulkan.CStruct.Extends (PeekChain)
import Graphics.Vulkan.CStruct.Extends (PeekChain(..))
import Graphics.Vulkan.Core10.Handles (PhysicalDevice)
import Graphics.Vulkan.Core10.Handles (PhysicalDevice(..))
import Graphics.Vulkan.Core10.Handles (PhysicalDevice_T)
import Graphics.Vulkan.CStruct.Extends (PokeChain)
import Graphics.Vulkan.CStruct.Extends (PokeChain(..))
import Graphics.Vulkan.Core10.Enums.Result (Result)
import Graphics.Vulkan.Core10.Enums.Result (Result(..))
import {-# SOURCE #-} Graphics.Vulkan.Extensions.VK_KHR_shared_presentable_image (SharedPresentSurfaceCapabilitiesKHR)
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType)
import {-# SOURCE #-} Graphics.Vulkan.Extensions.VK_EXT_full_screen_exclusive (SurfaceCapabilitiesFullScreenExclusiveEXT)
import Graphics.Vulkan.Extensions.VK_KHR_surface (SurfaceCapabilitiesKHR)
import Graphics.Vulkan.Extensions.VK_KHR_surface (SurfaceFormatKHR)
import {-# SOURCE #-} Graphics.Vulkan.Extensions.VK_EXT_full_screen_exclusive (SurfaceFullScreenExclusiveInfoEXT)
import {-# SOURCE #-} Graphics.Vulkan.Extensions.VK_EXT_full_screen_exclusive (SurfaceFullScreenExclusiveWin32InfoEXT)
import Graphics.Vulkan.Extensions.Handles (SurfaceKHR)
import {-# SOURCE #-} Graphics.Vulkan.Extensions.VK_KHR_surface_protected_capabilities (SurfaceProtectedCapabilitiesKHR)
import Graphics.Vulkan.CStruct (ToCStruct)
import Graphics.Vulkan.CStruct (ToCStruct(..))
import Graphics.Vulkan.Exception (VulkanException(..))
import Graphics.Vulkan.Zero (Zero(..))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR))
import Graphics.Vulkan.Core10.Enums.Result (Result(SUCCESS))
import Graphics.Vulkan.Extensions.VK_EXT_swapchain_colorspace (ColorSpaceKHR(..))
import Graphics.Vulkan.Extensions.VK_EXT_display_surface_counter (CompositeAlphaFlagBitsKHR(..))
import Graphics.Vulkan.Extensions.VK_EXT_display_surface_counter (CompositeAlphaFlagsKHR)
import Graphics.Vulkan.Extensions.VK_KHR_surface (SurfaceCapabilitiesKHR(..))
import Graphics.Vulkan.Extensions.VK_KHR_surface (SurfaceFormatKHR(..))
import Graphics.Vulkan.Extensions.Handles (SurfaceKHR(..))
import Graphics.Vulkan.Extensions.VK_KHR_display (SurfaceTransformFlagBitsKHR(..))
import Graphics.Vulkan.Extensions.VK_KHR_display (SurfaceTransformFlagsKHR)
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkGetPhysicalDeviceSurfaceCapabilities2KHR
:: FunPtr (Ptr PhysicalDevice_T -> Ptr (PhysicalDeviceSurfaceInfo2KHR a) -> Ptr (SurfaceCapabilities2KHR b) -> IO Result) -> Ptr PhysicalDevice_T -> Ptr (PhysicalDeviceSurfaceInfo2KHR a) -> Ptr (SurfaceCapabilities2KHR b) -> IO Result
getPhysicalDeviceSurfaceCapabilities2KHR :: (PokeChain a, PokeChain b, PeekChain b) => PhysicalDevice -> PhysicalDeviceSurfaceInfo2KHR a -> IO (SurfaceCapabilities2KHR b)
getPhysicalDeviceSurfaceCapabilities2KHR physicalDevice surfaceInfo = evalContT $ do
let vkGetPhysicalDeviceSurfaceCapabilities2KHR' = mkVkGetPhysicalDeviceSurfaceCapabilities2KHR (pVkGetPhysicalDeviceSurfaceCapabilities2KHR (instanceCmds (physicalDevice :: PhysicalDevice)))
pSurfaceInfo <- ContT $ withCStruct (surfaceInfo)
pPSurfaceCapabilities <- ContT (withZeroCStruct @(SurfaceCapabilities2KHR _))
r <- lift $ vkGetPhysicalDeviceSurfaceCapabilities2KHR' (physicalDeviceHandle (physicalDevice)) pSurfaceInfo (pPSurfaceCapabilities)
lift $ when (r < SUCCESS) (throwIO (VulkanException r))
pSurfaceCapabilities <- lift $ peekCStruct @(SurfaceCapabilities2KHR _) pPSurfaceCapabilities
pure $ (pSurfaceCapabilities)
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkGetPhysicalDeviceSurfaceFormats2KHR
:: FunPtr (Ptr PhysicalDevice_T -> Ptr (PhysicalDeviceSurfaceInfo2KHR a) -> Ptr Word32 -> Ptr SurfaceFormat2KHR -> IO Result) -> Ptr PhysicalDevice_T -> Ptr (PhysicalDeviceSurfaceInfo2KHR a) -> Ptr Word32 -> Ptr SurfaceFormat2KHR -> IO Result
getPhysicalDeviceSurfaceFormats2KHR :: PokeChain a => PhysicalDevice -> PhysicalDeviceSurfaceInfo2KHR a -> IO (Result, ("surfaceFormats" ::: Vector SurfaceFormat2KHR))
getPhysicalDeviceSurfaceFormats2KHR physicalDevice surfaceInfo = evalContT $ do
let vkGetPhysicalDeviceSurfaceFormats2KHR' = mkVkGetPhysicalDeviceSurfaceFormats2KHR (pVkGetPhysicalDeviceSurfaceFormats2KHR (instanceCmds (physicalDevice :: PhysicalDevice)))
let physicalDevice' = physicalDeviceHandle (physicalDevice)
pSurfaceInfo <- ContT $ withCStruct (surfaceInfo)
pPSurfaceFormatCount <- ContT $ bracket (callocBytes @Word32 4) free
r <- lift $ vkGetPhysicalDeviceSurfaceFormats2KHR' physicalDevice' pSurfaceInfo (pPSurfaceFormatCount) (nullPtr)
lift $ when (r < SUCCESS) (throwIO (VulkanException r))
pSurfaceFormatCount <- lift $ peek @Word32 pPSurfaceFormatCount
pPSurfaceFormats <- ContT $ bracket (callocBytes @SurfaceFormat2KHR ((fromIntegral (pSurfaceFormatCount)) * 24)) free
_ <- traverse (\i -> ContT $ pokeZeroCStruct (pPSurfaceFormats `advancePtrBytes` (i * 24) :: Ptr SurfaceFormat2KHR) . ($ ())) [0..(fromIntegral (pSurfaceFormatCount)) - 1]
r' <- lift $ vkGetPhysicalDeviceSurfaceFormats2KHR' physicalDevice' pSurfaceInfo (pPSurfaceFormatCount) ((pPSurfaceFormats))
lift $ when (r' < SUCCESS) (throwIO (VulkanException r'))
pSurfaceFormatCount' <- lift $ peek @Word32 pPSurfaceFormatCount
pSurfaceFormats' <- lift $ generateM (fromIntegral (pSurfaceFormatCount')) (\i -> peekCStruct @SurfaceFormat2KHR (((pPSurfaceFormats) `advancePtrBytes` (24 * (i)) :: Ptr SurfaceFormat2KHR)))
pure $ ((r'), pSurfaceFormats')
data PhysicalDeviceSurfaceInfo2KHR (es :: [Type]) = PhysicalDeviceSurfaceInfo2KHR
{
next :: Chain es
,
surface :: SurfaceKHR
}
deriving (Typeable)
deriving instance Show (Chain es) => Show (PhysicalDeviceSurfaceInfo2KHR es)
instance Extensible PhysicalDeviceSurfaceInfo2KHR where
extensibleType = STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR
setNext x next = x{next = next}
getNext PhysicalDeviceSurfaceInfo2KHR{..} = next
extends :: forall e b proxy. Typeable e => proxy e -> (Extends PhysicalDeviceSurfaceInfo2KHR e => b) -> Maybe b
extends _ f
| Just Refl <- eqT @e @SurfaceFullScreenExclusiveWin32InfoEXT = Just f
| Just Refl <- eqT @e @SurfaceFullScreenExclusiveInfoEXT = Just f
| otherwise = Nothing
instance PokeChain es => ToCStruct (PhysicalDeviceSurfaceInfo2KHR es) where
withCStruct x f = allocaBytesAligned 24 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p PhysicalDeviceSurfaceInfo2KHR{..} f = evalContT $ do
lift $ poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR)
pNext'' <- fmap castPtr . ContT $ withChain (next)
lift $ poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) pNext''
lift $ poke ((p `plusPtr` 16 :: Ptr SurfaceKHR)) (surface)
lift $ f
cStructSize = 24
cStructAlignment = 8
pokeZeroCStruct p f = evalContT $ do
lift $ poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR)
pNext' <- fmap castPtr . ContT $ withZeroChain @es
lift $ poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) pNext'
lift $ poke ((p `plusPtr` 16 :: Ptr SurfaceKHR)) (zero)
lift $ f
instance PeekChain es => FromCStruct (PhysicalDeviceSurfaceInfo2KHR es) where
peekCStruct p = do
pNext <- peek @(Ptr ()) ((p `plusPtr` 8 :: Ptr (Ptr ())))
next <- peekChain (castPtr pNext)
surface <- peek @SurfaceKHR ((p `plusPtr` 16 :: Ptr SurfaceKHR))
pure $ PhysicalDeviceSurfaceInfo2KHR
next surface
instance es ~ '[] => Zero (PhysicalDeviceSurfaceInfo2KHR es) where
zero = PhysicalDeviceSurfaceInfo2KHR
()
zero
data SurfaceCapabilities2KHR (es :: [Type]) = SurfaceCapabilities2KHR
{
next :: Chain es
,
surfaceCapabilities :: SurfaceCapabilitiesKHR
}
deriving (Typeable)
deriving instance Show (Chain es) => Show (SurfaceCapabilities2KHR es)
instance Extensible SurfaceCapabilities2KHR where
extensibleType = STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR
setNext x next = x{next = next}
getNext SurfaceCapabilities2KHR{..} = next
extends :: forall e b proxy. Typeable e => proxy e -> (Extends SurfaceCapabilities2KHR e => b) -> Maybe b
extends _ f
| Just Refl <- eqT @e @SurfaceCapabilitiesFullScreenExclusiveEXT = Just f
| Just Refl <- eqT @e @SurfaceProtectedCapabilitiesKHR = Just f
| Just Refl <- eqT @e @SharedPresentSurfaceCapabilitiesKHR = Just f
| Just Refl <- eqT @e @DisplayNativeHdrSurfaceCapabilitiesAMD = Just f
| otherwise = Nothing
instance PokeChain es => ToCStruct (SurfaceCapabilities2KHR es) where
withCStruct x f = allocaBytesAligned 72 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p SurfaceCapabilities2KHR{..} f = evalContT $ do
lift $ poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR)
pNext'' <- fmap castPtr . ContT $ withChain (next)
lift $ poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) pNext''
ContT $ pokeCStruct ((p `plusPtr` 16 :: Ptr SurfaceCapabilitiesKHR)) (surfaceCapabilities) . ($ ())
lift $ f
cStructSize = 72
cStructAlignment = 8
pokeZeroCStruct p f = evalContT $ do
lift $ poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR)
pNext' <- fmap castPtr . ContT $ withZeroChain @es
lift $ poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) pNext'
ContT $ pokeCStruct ((p `plusPtr` 16 :: Ptr SurfaceCapabilitiesKHR)) (zero) . ($ ())
lift $ f
instance PeekChain es => FromCStruct (SurfaceCapabilities2KHR es) where
peekCStruct p = do
pNext <- peek @(Ptr ()) ((p `plusPtr` 8 :: Ptr (Ptr ())))
next <- peekChain (castPtr pNext)
surfaceCapabilities <- peekCStruct @SurfaceCapabilitiesKHR ((p `plusPtr` 16 :: Ptr SurfaceCapabilitiesKHR))
pure $ SurfaceCapabilities2KHR
next surfaceCapabilities
instance es ~ '[] => Zero (SurfaceCapabilities2KHR es) where
zero = SurfaceCapabilities2KHR
()
zero
data SurfaceFormat2KHR = SurfaceFormat2KHR
{
surfaceFormat :: SurfaceFormatKHR }
deriving (Typeable)
deriving instance Show SurfaceFormat2KHR
instance ToCStruct SurfaceFormat2KHR where
withCStruct x f = allocaBytesAligned 24 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p SurfaceFormat2KHR{..} f = evalContT $ do
lift $ poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR)
lift $ poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
ContT $ pokeCStruct ((p `plusPtr` 16 :: Ptr SurfaceFormatKHR)) (surfaceFormat) . ($ ())
lift $ f
cStructSize = 24
cStructAlignment = 8
pokeZeroCStruct p f = evalContT $ do
lift $ poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR)
lift $ poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
ContT $ pokeCStruct ((p `plusPtr` 16 :: Ptr SurfaceFormatKHR)) (zero) . ($ ())
lift $ f
instance FromCStruct SurfaceFormat2KHR where
peekCStruct p = do
surfaceFormat <- peekCStruct @SurfaceFormatKHR ((p `plusPtr` 16 :: Ptr SurfaceFormatKHR))
pure $ SurfaceFormat2KHR
surfaceFormat
instance Zero SurfaceFormat2KHR where
zero = SurfaceFormat2KHR
zero
type KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION = 1
pattern KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION :: forall a . Integral a => a
pattern KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION = 1
type KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME = "VK_KHR_get_surface_capabilities2"
pattern KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME = "VK_KHR_get_surface_capabilities2"