{-# language CPP #-}
module Graphics.Vulkan.Extensions.VK_EXT_metal_surface ( createMetalSurfaceEXT
, MetalSurfaceCreateInfoEXT(..)
, MetalSurfaceCreateFlagsEXT(..)
, EXT_METAL_SURFACE_SPEC_VERSION
, pattern EXT_METAL_SURFACE_SPEC_VERSION
, EXT_METAL_SURFACE_EXTENSION_NAME
, pattern EXT_METAL_SURFACE_EXTENSION_NAME
, SurfaceKHR(..)
, CAMetalLayer
) where
import Control.Exception.Base (bracket)
import Control.Monad.IO.Class (liftIO)
import Foreign.Marshal.Alloc (allocaBytesAligned)
import Foreign.Marshal.Alloc (callocBytes)
import Foreign.Marshal.Alloc (free)
import GHC.Base (when)
import GHC.IO (throwIO)
import Foreign.Ptr (nullPtr)
import Foreign.Ptr (plusPtr)
import GHC.Read (choose)
import GHC.Read (expectP)
import GHC.Read (parens)
import GHC.Show (showParen)
import GHC.Show (showString)
import Numeric (showHex)
import Text.ParserCombinators.ReadPrec ((+++))
import Text.ParserCombinators.ReadPrec (prec)
import Text.ParserCombinators.ReadPrec (step)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Cont (evalContT)
import Control.Monad.IO.Class (MonadIO)
import Data.Bits (Bits)
import Data.String (IsString)
import Data.Typeable (Typeable)
import Foreign.Storable (Storable)
import Foreign.Storable (Storable(peek))
import Foreign.Storable (Storable(poke))
import qualified Foreign.Storable (Storable(..))
import Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import GHC.Read (Read(readPrec))
import Text.Read.Lex (Lexeme(Ident))
import Data.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import Graphics.Vulkan.NamedType ((:::))
import Graphics.Vulkan.Core10.AllocationCallbacks (AllocationCallbacks)
import Graphics.Vulkan.Extensions.WSITypes (CAMetalLayer)
import Graphics.Vulkan.Core10.BaseType (Flags)
import Graphics.Vulkan.CStruct (FromCStruct)
import Graphics.Vulkan.CStruct (FromCStruct(..))
import Graphics.Vulkan.Core10.Handles (Instance)
import Graphics.Vulkan.Core10.Handles (Instance(..))
import Graphics.Vulkan.Dynamic (InstanceCmds(pVkCreateMetalSurfaceEXT))
import Graphics.Vulkan.Core10.Handles (Instance_T)
import Graphics.Vulkan.Core10.Enums.Result (Result)
import Graphics.Vulkan.Core10.Enums.Result (Result(..))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType)
import Graphics.Vulkan.Extensions.Handles (SurfaceKHR)
import Graphics.Vulkan.Extensions.Handles (SurfaceKHR(..))
import Graphics.Vulkan.CStruct (ToCStruct)
import Graphics.Vulkan.CStruct (ToCStruct(..))
import Graphics.Vulkan.Exception (VulkanException(..))
import Graphics.Vulkan.Zero (Zero)
import Graphics.Vulkan.Zero (Zero(..))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT))
import Graphics.Vulkan.Core10.Enums.Result (Result(SUCCESS))
import Graphics.Vulkan.Extensions.WSITypes (CAMetalLayer)
import Graphics.Vulkan.Extensions.Handles (SurfaceKHR(..))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkCreateMetalSurfaceEXT
:: FunPtr (Ptr Instance_T -> Ptr MetalSurfaceCreateInfoEXT -> Ptr AllocationCallbacks -> Ptr SurfaceKHR -> IO Result) -> Ptr Instance_T -> Ptr MetalSurfaceCreateInfoEXT -> Ptr AllocationCallbacks -> Ptr SurfaceKHR -> IO Result
createMetalSurfaceEXT :: forall io . MonadIO io => Instance -> MetalSurfaceCreateInfoEXT -> ("allocator" ::: Maybe AllocationCallbacks) -> io (SurfaceKHR)
createMetalSurfaceEXT instance' createInfo allocator = liftIO . evalContT $ do
let vkCreateMetalSurfaceEXT' = mkVkCreateMetalSurfaceEXT (pVkCreateMetalSurfaceEXT (instanceCmds (instance' :: Instance)))
pCreateInfo <- ContT $ withCStruct (createInfo)
pAllocator <- case (allocator) of
Nothing -> pure nullPtr
Just j -> ContT $ withCStruct (j)
pPSurface <- ContT $ bracket (callocBytes @SurfaceKHR 8) free
r <- lift $ vkCreateMetalSurfaceEXT' (instanceHandle (instance')) pCreateInfo pAllocator (pPSurface)
lift $ when (r < SUCCESS) (throwIO (VulkanException r))
pSurface <- lift $ peek @SurfaceKHR pPSurface
pure $ (pSurface)
data MetalSurfaceCreateInfoEXT = MetalSurfaceCreateInfoEXT
{
flags :: MetalSurfaceCreateFlagsEXT
,
layer :: Ptr CAMetalLayer
}
deriving (Typeable)
deriving instance Show MetalSurfaceCreateInfoEXT
instance ToCStruct MetalSurfaceCreateInfoEXT where
withCStruct x f = allocaBytesAligned 32 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p MetalSurfaceCreateInfoEXT{..} f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr MetalSurfaceCreateFlagsEXT)) (flags)
poke ((p `plusPtr` 24 :: Ptr (Ptr CAMetalLayer))) (layer)
f
cStructSize = 32
cStructAlignment = 8
pokeZeroCStruct p f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 24 :: Ptr (Ptr CAMetalLayer))) (zero)
f
instance FromCStruct MetalSurfaceCreateInfoEXT where
peekCStruct p = do
flags <- peek @MetalSurfaceCreateFlagsEXT ((p `plusPtr` 16 :: Ptr MetalSurfaceCreateFlagsEXT))
pLayer <- peek @(Ptr CAMetalLayer) ((p `plusPtr` 24 :: Ptr (Ptr CAMetalLayer)))
pure $ MetalSurfaceCreateInfoEXT
flags pLayer
instance Storable MetalSurfaceCreateInfoEXT where
sizeOf ~_ = 32
alignment ~_ = 8
peek = peekCStruct
poke ptr poked = pokeCStruct ptr poked (pure ())
instance Zero MetalSurfaceCreateInfoEXT where
zero = MetalSurfaceCreateInfoEXT
zero
zero
newtype MetalSurfaceCreateFlagsEXT = MetalSurfaceCreateFlagsEXT Flags
deriving newtype (Eq, Ord, Storable, Zero, Bits)
instance Show MetalSurfaceCreateFlagsEXT where
showsPrec p = \case
MetalSurfaceCreateFlagsEXT x -> showParen (p >= 11) (showString "MetalSurfaceCreateFlagsEXT 0x" . showHex x)
instance Read MetalSurfaceCreateFlagsEXT where
readPrec = parens (choose []
+++
prec 10 (do
expectP (Ident "MetalSurfaceCreateFlagsEXT")
v <- step readPrec
pure (MetalSurfaceCreateFlagsEXT v)))
type EXT_METAL_SURFACE_SPEC_VERSION = 1
pattern EXT_METAL_SURFACE_SPEC_VERSION :: forall a . Integral a => a
pattern EXT_METAL_SURFACE_SPEC_VERSION = 1
type EXT_METAL_SURFACE_EXTENSION_NAME = "VK_EXT_metal_surface"
pattern EXT_METAL_SURFACE_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern EXT_METAL_SURFACE_EXTENSION_NAME = "VK_EXT_metal_surface"