{-# language CPP #-}
module Graphics.Vulkan.Extensions.VK_KHR_external_memory_fd ( getMemoryFdKHR
, getMemoryFdPropertiesKHR
, ImportMemoryFdInfoKHR(..)
, MemoryFdPropertiesKHR(..)
, MemoryGetFdInfoKHR(..)
, KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION
, pattern KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION
, KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME
, pattern KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME
) 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 Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Cont (evalContT)
import Foreign.C.Types (CInt(..))
import Control.Monad.IO.Class (MonadIO)
import Data.String (IsString)
import Data.Typeable (Typeable)
import Foreign.C.Types (CInt)
import Foreign.C.Types (CInt(CInt))
import Foreign.Storable (Storable)
import Foreign.Storable (Storable(peek))
import Foreign.Storable (Storable(poke))
import qualified Foreign.Storable (Storable(..))
import Data.Int (Int32)
import Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import Data.Word (Word32)
import Data.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import Graphics.Vulkan.NamedType ((:::))
import Graphics.Vulkan.Core10.Handles (Device)
import Graphics.Vulkan.Core10.Handles (Device(..))
import Graphics.Vulkan.Dynamic (DeviceCmds(pVkGetMemoryFdKHR))
import Graphics.Vulkan.Dynamic (DeviceCmds(pVkGetMemoryFdPropertiesKHR))
import Graphics.Vulkan.Core10.Handles (DeviceMemory)
import Graphics.Vulkan.Core10.Handles (Device_T)
import Graphics.Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits (ExternalMemoryHandleTypeFlagBits)
import Graphics.Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits (ExternalMemoryHandleTypeFlagBits(..))
import Graphics.Vulkan.CStruct (FromCStruct)
import Graphics.Vulkan.CStruct (FromCStruct(..))
import Graphics.Vulkan.Core10.Enums.Result (Result)
import Graphics.Vulkan.Core10.Enums.Result (Result(..))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType)
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_IMPORT_MEMORY_FD_INFO_KHR))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR))
import Graphics.Vulkan.Core10.Enums.Result (Result(SUCCESS))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkGetMemoryFdKHR
:: FunPtr (Ptr Device_T -> Ptr MemoryGetFdInfoKHR -> Ptr CInt -> IO Result) -> Ptr Device_T -> Ptr MemoryGetFdInfoKHR -> Ptr CInt -> IO Result
getMemoryFdKHR :: forall io . MonadIO io => Device -> MemoryGetFdInfoKHR -> io (("fd" ::: Int32))
getMemoryFdKHR device getFdInfo = liftIO . evalContT $ do
let vkGetMemoryFdKHR' = mkVkGetMemoryFdKHR (pVkGetMemoryFdKHR (deviceCmds (device :: Device)))
pGetFdInfo <- ContT $ withCStruct (getFdInfo)
pPFd <- ContT $ bracket (callocBytes @CInt 4) free
r <- lift $ vkGetMemoryFdKHR' (deviceHandle (device)) pGetFdInfo (pPFd)
lift $ when (r < SUCCESS) (throwIO (VulkanException r))
pFd <- lift $ peek @CInt pPFd
pure $ (((\(CInt a) -> a) pFd))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkGetMemoryFdPropertiesKHR
:: FunPtr (Ptr Device_T -> ExternalMemoryHandleTypeFlagBits -> CInt -> Ptr MemoryFdPropertiesKHR -> IO Result) -> Ptr Device_T -> ExternalMemoryHandleTypeFlagBits -> CInt -> Ptr MemoryFdPropertiesKHR -> IO Result
getMemoryFdPropertiesKHR :: forall io . MonadIO io => Device -> ExternalMemoryHandleTypeFlagBits -> ("fd" ::: Int32) -> io (MemoryFdPropertiesKHR)
getMemoryFdPropertiesKHR device handleType fd = liftIO . evalContT $ do
let vkGetMemoryFdPropertiesKHR' = mkVkGetMemoryFdPropertiesKHR (pVkGetMemoryFdPropertiesKHR (deviceCmds (device :: Device)))
pPMemoryFdProperties <- ContT (withZeroCStruct @MemoryFdPropertiesKHR)
r <- lift $ vkGetMemoryFdPropertiesKHR' (deviceHandle (device)) (handleType) (CInt (fd)) (pPMemoryFdProperties)
lift $ when (r < SUCCESS) (throwIO (VulkanException r))
pMemoryFdProperties <- lift $ peekCStruct @MemoryFdPropertiesKHR pPMemoryFdProperties
pure $ (pMemoryFdProperties)
data ImportMemoryFdInfoKHR = ImportMemoryFdInfoKHR
{
handleType :: ExternalMemoryHandleTypeFlagBits
,
fd :: Int32
}
deriving (Typeable)
deriving instance Show ImportMemoryFdInfoKHR
instance ToCStruct ImportMemoryFdInfoKHR where
withCStruct x f = allocaBytesAligned 24 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p ImportMemoryFdInfoKHR{..} f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr ExternalMemoryHandleTypeFlagBits)) (handleType)
poke ((p `plusPtr` 20 :: Ptr CInt)) (CInt (fd))
f
cStructSize = 24
cStructAlignment = 8
pokeZeroCStruct p f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 20 :: Ptr CInt)) (CInt (zero))
f
instance FromCStruct ImportMemoryFdInfoKHR where
peekCStruct p = do
handleType <- peek @ExternalMemoryHandleTypeFlagBits ((p `plusPtr` 16 :: Ptr ExternalMemoryHandleTypeFlagBits))
fd <- peek @CInt ((p `plusPtr` 20 :: Ptr CInt))
pure $ ImportMemoryFdInfoKHR
handleType ((\(CInt a) -> a) fd)
instance Storable ImportMemoryFdInfoKHR where
sizeOf ~_ = 24
alignment ~_ = 8
peek = peekCStruct
poke ptr poked = pokeCStruct ptr poked (pure ())
instance Zero ImportMemoryFdInfoKHR where
zero = ImportMemoryFdInfoKHR
zero
zero
data MemoryFdPropertiesKHR = MemoryFdPropertiesKHR
{
memoryTypeBits :: Word32 }
deriving (Typeable)
deriving instance Show MemoryFdPropertiesKHR
instance ToCStruct MemoryFdPropertiesKHR where
withCStruct x f = allocaBytesAligned 24 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p MemoryFdPropertiesKHR{..} f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr Word32)) (memoryTypeBits)
f
cStructSize = 24
cStructAlignment = 8
pokeZeroCStruct p f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr Word32)) (zero)
f
instance FromCStruct MemoryFdPropertiesKHR where
peekCStruct p = do
memoryTypeBits <- peek @Word32 ((p `plusPtr` 16 :: Ptr Word32))
pure $ MemoryFdPropertiesKHR
memoryTypeBits
instance Storable MemoryFdPropertiesKHR where
sizeOf ~_ = 24
alignment ~_ = 8
peek = peekCStruct
poke ptr poked = pokeCStruct ptr poked (pure ())
instance Zero MemoryFdPropertiesKHR where
zero = MemoryFdPropertiesKHR
zero
data MemoryGetFdInfoKHR = MemoryGetFdInfoKHR
{
memory :: DeviceMemory
,
handleType :: ExternalMemoryHandleTypeFlagBits
}
deriving (Typeable)
deriving instance Show MemoryGetFdInfoKHR
instance ToCStruct MemoryGetFdInfoKHR where
withCStruct x f = allocaBytesAligned 32 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p MemoryGetFdInfoKHR{..} f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr DeviceMemory)) (memory)
poke ((p `plusPtr` 24 :: Ptr ExternalMemoryHandleTypeFlagBits)) (handleType)
f
cStructSize = 32
cStructAlignment = 8
pokeZeroCStruct p f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr DeviceMemory)) (zero)
poke ((p `plusPtr` 24 :: Ptr ExternalMemoryHandleTypeFlagBits)) (zero)
f
instance FromCStruct MemoryGetFdInfoKHR where
peekCStruct p = do
memory <- peek @DeviceMemory ((p `plusPtr` 16 :: Ptr DeviceMemory))
handleType <- peek @ExternalMemoryHandleTypeFlagBits ((p `plusPtr` 24 :: Ptr ExternalMemoryHandleTypeFlagBits))
pure $ MemoryGetFdInfoKHR
memory handleType
instance Storable MemoryGetFdInfoKHR where
sizeOf ~_ = 32
alignment ~_ = 8
peek = peekCStruct
poke ptr poked = pokeCStruct ptr poked (pure ())
instance Zero MemoryGetFdInfoKHR where
zero = MemoryGetFdInfoKHR
zero
zero
type KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION = 1
pattern KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION :: forall a . Integral a => a
pattern KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION = 1
type KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME = "VK_KHR_external_memory_fd"
pattern KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME = "VK_KHR_external_memory_fd"