{-# language CPP #-}
module 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 (unless)
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 GHC.Ptr (nullFunPtr)
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 GHC.IO.Exception (IOErrorType(..))
import GHC.IO.Exception (IOException(..))
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 Vulkan.NamedType ((:::))
import Vulkan.Core10.Handles (Device)
import Vulkan.Core10.Handles (Device(..))
import Vulkan.Dynamic (DeviceCmds(pVkGetMemoryFdKHR))
import Vulkan.Dynamic (DeviceCmds(pVkGetMemoryFdPropertiesKHR))
import Vulkan.Core10.Handles (DeviceMemory)
import Vulkan.Core10.Handles (Device_T)
import Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits (ExternalMemoryHandleTypeFlagBits)
import Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits (ExternalMemoryHandleTypeFlagBits(..))
import Vulkan.CStruct (FromCStruct)
import Vulkan.CStruct (FromCStruct(..))
import Vulkan.Core10.Enums.Result (Result)
import Vulkan.Core10.Enums.Result (Result(..))
import Vulkan.Core10.Enums.StructureType (StructureType)
import Vulkan.CStruct (ToCStruct)
import Vulkan.CStruct (ToCStruct(..))
import Vulkan.Exception (VulkanException(..))
import Vulkan.Zero (Zero(..))
import Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR))
import Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR))
import Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR))
import 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

-- | vkGetMemoryFdKHR - Get a POSIX file descriptor for a memory object
--
-- = Parameters
--
-- -   @device@ is the logical device that created the device memory being
--     exported.
--
-- -   @pGetFdInfo@ is a pointer to a 'MemoryGetFdInfoKHR' structure
--     containing parameters of the export operation.
--
-- -   @pFd@ will return a file descriptor representing the underlying
--     resources of the device memory object.
--
-- = Description
--
-- Each call to 'getMemoryFdKHR' /must/ create a new file descriptor and
-- transfer ownership of it to the application. To avoid leaking resources,
-- the application /must/ release ownership of the file descriptor using
-- the @close@ system call when it is no longer needed, or by importing a
-- Vulkan memory object from it. Where supported by the operating system,
-- the implementation /must/ set the file descriptor to be closed
-- automatically when an @execve@ system call is made.
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-successcodes Success>]
--
--     -   'Vulkan.Core10.Enums.Result.SUCCESS'
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-errorcodes Failure>]
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_TOO_MANY_OBJECTS'
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_OUT_OF_HOST_MEMORY'
--
-- = See Also
--
-- 'Vulkan.Core10.Handles.Device', 'MemoryGetFdInfoKHR'
getMemoryFdKHR :: forall io . MonadIO io => Device -> MemoryGetFdInfoKHR -> io (("fd" ::: Int32))
getMemoryFdKHR :: Device -> MemoryGetFdInfoKHR -> io ("fd" ::: Int32)
getMemoryFdKHR device :: Device
device getFdInfo :: MemoryGetFdInfoKHR
getFdInfo = IO ("fd" ::: Int32) -> io ("fd" ::: Int32)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("fd" ::: Int32) -> io ("fd" ::: Int32))
-> (ContT ("fd" ::: Int32) IO ("fd" ::: Int32)
    -> IO ("fd" ::: Int32))
-> ContT ("fd" ::: Int32) IO ("fd" ::: Int32)
-> io ("fd" ::: Int32)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT ("fd" ::: Int32) IO ("fd" ::: Int32) -> IO ("fd" ::: Int32)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT ("fd" ::: Int32) IO ("fd" ::: Int32) -> io ("fd" ::: Int32))
-> ContT ("fd" ::: Int32) IO ("fd" ::: Int32)
-> io ("fd" ::: Int32)
forall a b. (a -> b) -> a -> b
$ do
  let vkGetMemoryFdKHRPtr :: FunPtr
  (Ptr Device_T
   -> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
   -> ("pFd" ::: Ptr CInt)
   -> IO Result)
vkGetMemoryFdKHRPtr = DeviceCmds
-> FunPtr
     (Ptr Device_T
      -> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
      -> ("pFd" ::: Ptr CInt)
      -> IO Result)
pVkGetMemoryFdKHR (Device -> DeviceCmds
deviceCmds (Device
device :: Device))
  IO () -> ContT ("fd" ::: Int32) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("fd" ::: Int32) IO ())
-> IO () -> ContT ("fd" ::: Int32) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Device_T
   -> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
   -> ("pFd" ::: Ptr CInt)
   -> IO Result)
vkGetMemoryFdKHRPtr FunPtr
  (Ptr Device_T
   -> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
   -> ("pFd" ::: Ptr CInt)
   -> IO Result)
-> FunPtr
     (Ptr Device_T
      -> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
      -> ("pFd" ::: Ptr CInt)
      -> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
  (Ptr Device_T
   -> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
   -> ("pFd" ::: Ptr CInt)
   -> IO Result)
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for vkGetMemoryFdKHR is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let vkGetMemoryFdKHR' :: Ptr Device_T
-> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> ("pFd" ::: Ptr CInt)
-> IO Result
vkGetMemoryFdKHR' = FunPtr
  (Ptr Device_T
   -> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
   -> ("pFd" ::: Ptr CInt)
   -> IO Result)
-> Ptr Device_T
-> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> ("pFd" ::: Ptr CInt)
-> IO Result
mkVkGetMemoryFdKHR FunPtr
  (Ptr Device_T
   -> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
   -> ("pFd" ::: Ptr CInt)
   -> IO Result)
vkGetMemoryFdKHRPtr
  "pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
pGetFdInfo <- ((("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO ("fd" ::: Int32))
 -> IO ("fd" ::: Int32))
-> ContT
     ("fd" ::: Int32) IO ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
   -> IO ("fd" ::: Int32))
  -> IO ("fd" ::: Int32))
 -> ContT
      ("fd" ::: Int32) IO ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR))
-> ((("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
     -> IO ("fd" ::: Int32))
    -> IO ("fd" ::: Int32))
-> ContT
     ("fd" ::: Int32) IO ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
forall a b. (a -> b) -> a -> b
$ MemoryGetFdInfoKHR
-> (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
    -> IO ("fd" ::: Int32))
-> IO ("fd" ::: Int32)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (MemoryGetFdInfoKHR
getFdInfo)
  "pFd" ::: Ptr CInt
pPFd <- ((("pFd" ::: Ptr CInt) -> IO ("fd" ::: Int32))
 -> IO ("fd" ::: Int32))
-> ContT ("fd" ::: Int32) IO ("pFd" ::: Ptr CInt)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("pFd" ::: Ptr CInt) -> IO ("fd" ::: Int32))
  -> IO ("fd" ::: Int32))
 -> ContT ("fd" ::: Int32) IO ("pFd" ::: Ptr CInt))
-> ((("pFd" ::: Ptr CInt) -> IO ("fd" ::: Int32))
    -> IO ("fd" ::: Int32))
-> ContT ("fd" ::: Int32) IO ("pFd" ::: Ptr CInt)
forall a b. (a -> b) -> a -> b
$ IO ("pFd" ::: Ptr CInt)
-> (("pFd" ::: Ptr CInt) -> IO ())
-> (("pFd" ::: Ptr CInt) -> IO ("fd" ::: Int32))
-> IO ("fd" ::: Int32)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO ("pFd" ::: Ptr CInt)
forall a. Int -> IO (Ptr a)
callocBytes @CInt 4) ("pFd" ::: Ptr CInt) -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT ("fd" ::: Int32) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT ("fd" ::: Int32) IO Result)
-> IO Result -> ContT ("fd" ::: Int32) IO Result
forall a b. (a -> b) -> a -> b
$ Ptr Device_T
-> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> ("pFd" ::: Ptr CInt)
-> IO Result
vkGetMemoryFdKHR' (Device -> Ptr Device_T
deviceHandle (Device
device)) "pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
pGetFdInfo ("pFd" ::: Ptr CInt
pPFd)
  IO () -> ContT ("fd" ::: Int32) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("fd" ::: Int32) IO ())
-> IO () -> ContT ("fd" ::: Int32) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  CInt
pFd <- IO CInt -> ContT ("fd" ::: Int32) IO CInt
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO CInt -> ContT ("fd" ::: Int32) IO CInt)
-> IO CInt -> ContT ("fd" ::: Int32) IO CInt
forall a b. (a -> b) -> a -> b
$ ("pFd" ::: Ptr CInt) -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek @CInt "pFd" ::: Ptr CInt
pPFd
  ("fd" ::: Int32) -> ContT ("fd" ::: Int32) IO ("fd" ::: Int32)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("fd" ::: Int32) -> ContT ("fd" ::: Int32) IO ("fd" ::: Int32))
-> ("fd" ::: Int32) -> ContT ("fd" ::: Int32) IO ("fd" ::: Int32)
forall a b. (a -> b) -> a -> b
$ (((\(CInt a :: "fd" ::: Int32
a) -> "fd" ::: Int32
a) CInt
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

-- | vkGetMemoryFdPropertiesKHR - Get Properties of External Memory File
-- Descriptors
--
-- = Parameters
--
-- -   @device@ is the logical device that will be importing @fd@.
--
-- -   @handleType@ is the type of the handle @fd@.
--
-- -   @fd@ is the handle which will be imported.
--
-- -   @pMemoryFdProperties@ is a pointer to a 'MemoryFdPropertiesKHR'
--     structure in which the properties of the handle @fd@ are returned.
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-successcodes Success>]
--
--     -   'Vulkan.Core10.Enums.Result.SUCCESS'
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-errorcodes Failure>]
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_INVALID_EXTERNAL_HANDLE'
--
-- = See Also
--
-- 'Vulkan.Core10.Handles.Device',
-- 'Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits.ExternalMemoryHandleTypeFlagBits',
-- 'MemoryFdPropertiesKHR'
getMemoryFdPropertiesKHR :: forall io . MonadIO io => Device -> ExternalMemoryHandleTypeFlagBits -> ("fd" ::: Int32) -> io (MemoryFdPropertiesKHR)
getMemoryFdPropertiesKHR :: Device
-> ExternalMemoryHandleTypeFlagBits
-> ("fd" ::: Int32)
-> io MemoryFdPropertiesKHR
getMemoryFdPropertiesKHR device :: Device
device handleType :: ExternalMemoryHandleTypeFlagBits
handleType fd :: "fd" ::: Int32
fd = IO MemoryFdPropertiesKHR -> io MemoryFdPropertiesKHR
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MemoryFdPropertiesKHR -> io MemoryFdPropertiesKHR)
-> (ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR
    -> IO MemoryFdPropertiesKHR)
-> ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR
-> io MemoryFdPropertiesKHR
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR
-> IO MemoryFdPropertiesKHR
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR
 -> io MemoryFdPropertiesKHR)
-> ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR
-> io MemoryFdPropertiesKHR
forall a b. (a -> b) -> a -> b
$ do
  let vkGetMemoryFdPropertiesKHRPtr :: FunPtr
  (Ptr Device_T
   -> ExternalMemoryHandleTypeFlagBits
   -> CInt
   -> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
   -> IO Result)
vkGetMemoryFdPropertiesKHRPtr = DeviceCmds
-> FunPtr
     (Ptr Device_T
      -> ExternalMemoryHandleTypeFlagBits
      -> CInt
      -> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
      -> IO Result)
pVkGetMemoryFdPropertiesKHR (Device -> DeviceCmds
deviceCmds (Device
device :: Device))
  IO () -> ContT MemoryFdPropertiesKHR IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT MemoryFdPropertiesKHR IO ())
-> IO () -> ContT MemoryFdPropertiesKHR IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Device_T
   -> ExternalMemoryHandleTypeFlagBits
   -> CInt
   -> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
   -> IO Result)
vkGetMemoryFdPropertiesKHRPtr FunPtr
  (Ptr Device_T
   -> ExternalMemoryHandleTypeFlagBits
   -> CInt
   -> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
   -> IO Result)
-> FunPtr
     (Ptr Device_T
      -> ExternalMemoryHandleTypeFlagBits
      -> CInt
      -> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
      -> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
  (Ptr Device_T
   -> ExternalMemoryHandleTypeFlagBits
   -> CInt
   -> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
   -> IO Result)
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for vkGetMemoryFdPropertiesKHR is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let vkGetMemoryFdPropertiesKHR' :: Ptr Device_T
-> ExternalMemoryHandleTypeFlagBits
-> CInt
-> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> IO Result
vkGetMemoryFdPropertiesKHR' = FunPtr
  (Ptr Device_T
   -> ExternalMemoryHandleTypeFlagBits
   -> CInt
   -> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
   -> IO Result)
-> Ptr Device_T
-> ExternalMemoryHandleTypeFlagBits
-> CInt
-> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> IO Result
mkVkGetMemoryFdPropertiesKHR FunPtr
  (Ptr Device_T
   -> ExternalMemoryHandleTypeFlagBits
   -> CInt
   -> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
   -> IO Result)
vkGetMemoryFdPropertiesKHRPtr
  "pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
pPMemoryFdProperties <- ((("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
  -> IO MemoryFdPropertiesKHR)
 -> IO MemoryFdPropertiesKHR)
-> ContT
     MemoryFdPropertiesKHR
     IO
     ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct MemoryFdPropertiesKHR =>
(("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR) -> IO b)
-> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @MemoryFdPropertiesKHR)
  Result
r <- IO Result -> ContT MemoryFdPropertiesKHR IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT MemoryFdPropertiesKHR IO Result)
-> IO Result -> ContT MemoryFdPropertiesKHR IO Result
forall a b. (a -> b) -> a -> b
$ Ptr Device_T
-> ExternalMemoryHandleTypeFlagBits
-> CInt
-> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> IO Result
vkGetMemoryFdPropertiesKHR' (Device -> Ptr Device_T
deviceHandle (Device
device)) (ExternalMemoryHandleTypeFlagBits
handleType) (("fd" ::: Int32) -> CInt
CInt ("fd" ::: Int32
fd)) ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
pPMemoryFdProperties)
  IO () -> ContT MemoryFdPropertiesKHR IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT MemoryFdPropertiesKHR IO ())
-> IO () -> ContT MemoryFdPropertiesKHR IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  MemoryFdPropertiesKHR
pMemoryFdProperties <- IO MemoryFdPropertiesKHR
-> ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO MemoryFdPropertiesKHR
 -> ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR)
-> IO MemoryFdPropertiesKHR
-> ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR
forall a b. (a -> b) -> a -> b
$ ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> IO MemoryFdPropertiesKHR
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @MemoryFdPropertiesKHR "pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
pPMemoryFdProperties
  MemoryFdPropertiesKHR
-> ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MemoryFdPropertiesKHR
 -> ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR)
-> MemoryFdPropertiesKHR
-> ContT MemoryFdPropertiesKHR IO MemoryFdPropertiesKHR
forall a b. (a -> b) -> a -> b
$ (MemoryFdPropertiesKHR
pMemoryFdProperties)


-- | VkImportMemoryFdInfoKHR - import memory created on the same physical
-- device from a file descriptor
--
-- = Description
--
-- Importing memory from a file descriptor transfers ownership of the file
-- descriptor from the application to the Vulkan implementation. The
-- application /must/ not perform any operations on the file descriptor
-- after a successful import.
--
-- Applications /can/ import the same underlying memory into multiple
-- instances of Vulkan, into the same instance from which it was exported,
-- and multiple times into a given Vulkan instance. In all cases, each
-- import operation /must/ create a distinct
-- 'Vulkan.Core10.Handles.DeviceMemory' object.
--
-- == Valid Usage
--
-- -   If @handleType@ is not @0@, it /must/ be supported for import, as
--     reported by
--     'Vulkan.Core11.Promoted_From_VK_KHR_external_memory_capabilities.ExternalImageFormatProperties'
--     or
--     'Vulkan.Core11.Promoted_From_VK_KHR_external_memory_capabilities.ExternalBufferProperties'
--
-- -   The memory from which @fd@ was exported /must/ have been created on
--     the same underlying physical device as @device@
--
-- -   If @handleType@ is not @0@, it /must/ be defined as a POSIX file
--     descriptor handle
--
-- -   If @handleType@ is not @0@, @fd@ /must/ be a valid handle of the
--     type specified by @handleType@
--
-- -   The memory represented by @fd@ /must/ have been created from a
--     physical device and driver that is compatible with @device@ and
--     @handleType@, as described in
--     <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#external-memory-handle-types-compatibility>
--
-- -   @fd@ /must/ obey any requirements listed for @handleType@ in
--     <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#external-memory-handle-types-compatibility external memory handle types compatibility>
--
-- == Valid Usage (Implicit)
--
-- -   @sType@ /must/ be
--     'Vulkan.Core10.Enums.StructureType.STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR'
--
-- -   If @handleType@ is not @0@, @handleType@ /must/ be a valid
--     'Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits.ExternalMemoryHandleTypeFlagBits'
--     value
--
-- = See Also
--
-- 'Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits.ExternalMemoryHandleTypeFlagBits',
-- 'Vulkan.Core10.Enums.StructureType.StructureType'
data ImportMemoryFdInfoKHR = ImportMemoryFdInfoKHR
  { -- | @handleType@ specifies the handle type of @fd@.
    ImportMemoryFdInfoKHR -> ExternalMemoryHandleTypeFlagBits
handleType :: ExternalMemoryHandleTypeFlagBits
  , -- | @fd@ is the external handle to import.
    ImportMemoryFdInfoKHR -> "fd" ::: Int32
fd :: Int32
  }
  deriving (Typeable)
deriving instance Show ImportMemoryFdInfoKHR

instance ToCStruct ImportMemoryFdInfoKHR where
  withCStruct :: ImportMemoryFdInfoKHR
-> (Ptr ImportMemoryFdInfoKHR -> IO b) -> IO b
withCStruct x :: ImportMemoryFdInfoKHR
x f :: Ptr ImportMemoryFdInfoKHR -> IO b
f = Int -> Int -> (Ptr ImportMemoryFdInfoKHR -> IO b) -> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned 24 8 ((Ptr ImportMemoryFdInfoKHR -> IO b) -> IO b)
-> (Ptr ImportMemoryFdInfoKHR -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \p :: Ptr ImportMemoryFdInfoKHR
p -> Ptr ImportMemoryFdInfoKHR -> ImportMemoryFdInfoKHR -> IO b -> IO b
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr ImportMemoryFdInfoKHR
p ImportMemoryFdInfoKHR
x (Ptr ImportMemoryFdInfoKHR -> IO b
f Ptr ImportMemoryFdInfoKHR
p)
  pokeCStruct :: Ptr ImportMemoryFdInfoKHR -> ImportMemoryFdInfoKHR -> IO b -> IO b
pokeCStruct p :: Ptr ImportMemoryFdInfoKHR
p ImportMemoryFdInfoKHR{..} f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr ImportMemoryFdInfoKHR
p Ptr ImportMemoryFdInfoKHR -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr ImportMemoryFdInfoKHR
p Ptr ImportMemoryFdInfoKHR -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    Ptr ExternalMemoryHandleTypeFlagBits
-> ExternalMemoryHandleTypeFlagBits -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr ImportMemoryFdInfoKHR
p Ptr ImportMemoryFdInfoKHR
-> Int -> Ptr ExternalMemoryHandleTypeFlagBits
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr ExternalMemoryHandleTypeFlagBits)) (ExternalMemoryHandleTypeFlagBits
handleType)
    ("pFd" ::: Ptr CInt) -> CInt -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr ImportMemoryFdInfoKHR
p Ptr ImportMemoryFdInfoKHR -> Int -> "pFd" ::: Ptr CInt
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 20 :: Ptr CInt)) (("fd" ::: Int32) -> CInt
CInt ("fd" ::: Int32
fd))
    IO b
f
  cStructSize :: Int
cStructSize = 24
  cStructAlignment :: Int
cStructAlignment = 8
  pokeZeroCStruct :: Ptr ImportMemoryFdInfoKHR -> IO b -> IO b
pokeZeroCStruct p :: Ptr ImportMemoryFdInfoKHR
p f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr ImportMemoryFdInfoKHR
p Ptr ImportMemoryFdInfoKHR -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr ImportMemoryFdInfoKHR
p Ptr ImportMemoryFdInfoKHR -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    ("pFd" ::: Ptr CInt) -> CInt -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr ImportMemoryFdInfoKHR
p Ptr ImportMemoryFdInfoKHR -> Int -> "pFd" ::: Ptr CInt
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 20 :: Ptr CInt)) (("fd" ::: Int32) -> CInt
CInt ("fd" ::: Int32
forall a. Zero a => a
zero))
    IO b
f

instance FromCStruct ImportMemoryFdInfoKHR where
  peekCStruct :: Ptr ImportMemoryFdInfoKHR -> IO ImportMemoryFdInfoKHR
peekCStruct p :: Ptr ImportMemoryFdInfoKHR
p = do
    ExternalMemoryHandleTypeFlagBits
handleType <- Ptr ExternalMemoryHandleTypeFlagBits
-> IO ExternalMemoryHandleTypeFlagBits
forall a. Storable a => Ptr a -> IO a
peek @ExternalMemoryHandleTypeFlagBits ((Ptr ImportMemoryFdInfoKHR
p Ptr ImportMemoryFdInfoKHR
-> Int -> Ptr ExternalMemoryHandleTypeFlagBits
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr ExternalMemoryHandleTypeFlagBits))
    CInt
fd <- ("pFd" ::: Ptr CInt) -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek @CInt ((Ptr ImportMemoryFdInfoKHR
p Ptr ImportMemoryFdInfoKHR -> Int -> "pFd" ::: Ptr CInt
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 20 :: Ptr CInt))
    ImportMemoryFdInfoKHR -> IO ImportMemoryFdInfoKHR
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ImportMemoryFdInfoKHR -> IO ImportMemoryFdInfoKHR)
-> ImportMemoryFdInfoKHR -> IO ImportMemoryFdInfoKHR
forall a b. (a -> b) -> a -> b
$ ExternalMemoryHandleTypeFlagBits
-> ("fd" ::: Int32) -> ImportMemoryFdInfoKHR
ImportMemoryFdInfoKHR
             ExternalMemoryHandleTypeFlagBits
handleType ((\(CInt a :: "fd" ::: Int32
a) -> "fd" ::: Int32
a) CInt
fd)

instance Storable ImportMemoryFdInfoKHR where
  sizeOf :: ImportMemoryFdInfoKHR -> Int
sizeOf ~ImportMemoryFdInfoKHR
_ = 24
  alignment :: ImportMemoryFdInfoKHR -> Int
alignment ~ImportMemoryFdInfoKHR
_ = 8
  peek :: Ptr ImportMemoryFdInfoKHR -> IO ImportMemoryFdInfoKHR
peek = Ptr ImportMemoryFdInfoKHR -> IO ImportMemoryFdInfoKHR
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
  poke :: Ptr ImportMemoryFdInfoKHR -> ImportMemoryFdInfoKHR -> IO ()
poke ptr :: Ptr ImportMemoryFdInfoKHR
ptr poked :: ImportMemoryFdInfoKHR
poked = Ptr ImportMemoryFdInfoKHR
-> ImportMemoryFdInfoKHR -> IO () -> IO ()
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr ImportMemoryFdInfoKHR
ptr ImportMemoryFdInfoKHR
poked (() -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

instance Zero ImportMemoryFdInfoKHR where
  zero :: ImportMemoryFdInfoKHR
zero = ExternalMemoryHandleTypeFlagBits
-> ("fd" ::: Int32) -> ImportMemoryFdInfoKHR
ImportMemoryFdInfoKHR
           ExternalMemoryHandleTypeFlagBits
forall a. Zero a => a
zero
           "fd" ::: Int32
forall a. Zero a => a
zero


-- | VkMemoryFdPropertiesKHR - Properties of External Memory File Descriptors
--
-- == Valid Usage (Implicit)
--
-- = See Also
--
-- 'Vulkan.Core10.Enums.StructureType.StructureType',
-- 'getMemoryFdPropertiesKHR'
data MemoryFdPropertiesKHR = MemoryFdPropertiesKHR
  { -- | @memoryTypeBits@ is a bitmask containing one bit set for every memory
    -- type which the specified file descriptor /can/ be imported as.
    MemoryFdPropertiesKHR -> Word32
memoryTypeBits :: Word32 }
  deriving (Typeable)
deriving instance Show MemoryFdPropertiesKHR

instance ToCStruct MemoryFdPropertiesKHR where
  withCStruct :: MemoryFdPropertiesKHR
-> (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR) -> IO b)
-> IO b
withCStruct x :: MemoryFdPropertiesKHR
x f :: ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR) -> IO b
f = Int
-> Int
-> (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR) -> IO b)
-> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned 24 8 ((("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR) -> IO b)
 -> IO b)
-> (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR) -> IO b)
-> IO b
forall a b. (a -> b) -> a -> b
$ \p :: "pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p -> ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> MemoryFdPropertiesKHR -> IO b -> IO b
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct "pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p MemoryFdPropertiesKHR
x (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR) -> IO b
f "pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p)
  pokeCStruct :: ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> MemoryFdPropertiesKHR -> IO b -> IO b
pokeCStruct p :: "pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p MemoryFdPropertiesKHR{..} f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr Word32)) (Word32
memoryTypeBits)
    IO b
f
  cStructSize :: Int
cStructSize = 24
  cStructAlignment :: Int
cStructAlignment = 8
  pokeZeroCStruct :: ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> IO b -> IO b
pokeZeroCStruct p :: "pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr Word32)) (Word32
forall a. Zero a => a
zero)
    IO b
f

instance FromCStruct MemoryFdPropertiesKHR where
  peekCStruct :: ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> IO MemoryFdPropertiesKHR
peekCStruct p :: "pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p = do
    Word32
memoryTypeBits <- Ptr Word32 -> IO Word32
forall a. Storable a => Ptr a -> IO a
peek @Word32 (("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
p ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr Word32))
    MemoryFdPropertiesKHR -> IO MemoryFdPropertiesKHR
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MemoryFdPropertiesKHR -> IO MemoryFdPropertiesKHR)
-> MemoryFdPropertiesKHR -> IO MemoryFdPropertiesKHR
forall a b. (a -> b) -> a -> b
$ Word32 -> MemoryFdPropertiesKHR
MemoryFdPropertiesKHR
             Word32
memoryTypeBits

instance Storable MemoryFdPropertiesKHR where
  sizeOf :: MemoryFdPropertiesKHR -> Int
sizeOf ~MemoryFdPropertiesKHR
_ = 24
  alignment :: MemoryFdPropertiesKHR -> Int
alignment ~MemoryFdPropertiesKHR
_ = 8
  peek :: ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> IO MemoryFdPropertiesKHR
peek = ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> IO MemoryFdPropertiesKHR
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
  poke :: ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> MemoryFdPropertiesKHR -> IO ()
poke ptr :: "pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
ptr poked :: MemoryFdPropertiesKHR
poked = ("pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR)
-> MemoryFdPropertiesKHR -> IO () -> IO ()
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct "pMemoryFdProperties" ::: Ptr MemoryFdPropertiesKHR
ptr MemoryFdPropertiesKHR
poked (() -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

instance Zero MemoryFdPropertiesKHR where
  zero :: MemoryFdPropertiesKHR
zero = Word32 -> MemoryFdPropertiesKHR
MemoryFdPropertiesKHR
           Word32
forall a. Zero a => a
zero


-- | VkMemoryGetFdInfoKHR - Structure describing a POSIX FD semaphore export
-- operation
--
-- = Description
--
-- The properties of the file descriptor exported depend on the value of
-- @handleType@. See
-- 'Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits.ExternalMemoryHandleTypeFlagBits'
-- for a description of the properties of the defined external memory
-- handle types.
--
-- Note
--
-- The size of the exported file /may/ be larger than the size requested by
-- 'Vulkan.Core10.Memory.MemoryAllocateInfo'::allocationSize. If
-- @handleType@ is
-- 'Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits.EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT',
-- then the application /can/ query the file’s actual size with
-- <man:lseek(2) lseek(2)>.
--
-- == Valid Usage (Implicit)
--
-- = See Also
--
-- 'Vulkan.Core10.Handles.DeviceMemory',
-- 'Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits.ExternalMemoryHandleTypeFlagBits',
-- 'Vulkan.Core10.Enums.StructureType.StructureType', 'getMemoryFdKHR'
data MemoryGetFdInfoKHR = MemoryGetFdInfoKHR
  { -- | @memory@ /must/ be a valid 'Vulkan.Core10.Handles.DeviceMemory' handle
    MemoryGetFdInfoKHR -> DeviceMemory
memory :: DeviceMemory
  , -- | @handleType@ /must/ be a valid
    -- 'Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits.ExternalMemoryHandleTypeFlagBits'
    -- value
    MemoryGetFdInfoKHR -> ExternalMemoryHandleTypeFlagBits
handleType :: ExternalMemoryHandleTypeFlagBits
  }
  deriving (Typeable)
deriving instance Show MemoryGetFdInfoKHR

instance ToCStruct MemoryGetFdInfoKHR where
  withCStruct :: MemoryGetFdInfoKHR
-> (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO b) -> IO b
withCStruct x :: MemoryGetFdInfoKHR
x f :: ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO b
f = Int
-> Int
-> (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO b)
-> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned 32 8 ((("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO b) -> IO b)
-> (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \p :: "pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p -> ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> MemoryGetFdInfoKHR -> IO b -> IO b
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct "pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p MemoryGetFdInfoKHR
x (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO b
f "pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p)
  pokeCStruct :: ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> MemoryGetFdInfoKHR -> IO b -> IO b
pokeCStruct p :: "pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p MemoryGetFdInfoKHR{..} f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    Ptr DeviceMemory -> DeviceMemory -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> Int -> Ptr DeviceMemory
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr DeviceMemory)) (DeviceMemory
memory)
    Ptr ExternalMemoryHandleTypeFlagBits
-> ExternalMemoryHandleTypeFlagBits -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> Int -> Ptr ExternalMemoryHandleTypeFlagBits
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr ExternalMemoryHandleTypeFlagBits)) (ExternalMemoryHandleTypeFlagBits
handleType)
    IO b
f
  cStructSize :: Int
cStructSize = 32
  cStructAlignment :: Int
cStructAlignment = 8
  pokeZeroCStruct :: ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO b -> IO b
pokeZeroCStruct p :: "pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    Ptr DeviceMemory -> DeviceMemory -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> Int -> Ptr DeviceMemory
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr DeviceMemory)) (DeviceMemory
forall a. Zero a => a
zero)
    Ptr ExternalMemoryHandleTypeFlagBits
-> ExternalMemoryHandleTypeFlagBits -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> Int -> Ptr ExternalMemoryHandleTypeFlagBits
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr ExternalMemoryHandleTypeFlagBits)) (ExternalMemoryHandleTypeFlagBits
forall a. Zero a => a
zero)
    IO b
f

instance FromCStruct MemoryGetFdInfoKHR where
  peekCStruct :: ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO MemoryGetFdInfoKHR
peekCStruct p :: "pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p = do
    DeviceMemory
memory <- Ptr DeviceMemory -> IO DeviceMemory
forall a. Storable a => Ptr a -> IO a
peek @DeviceMemory (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> Int -> Ptr DeviceMemory
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr DeviceMemory))
    ExternalMemoryHandleTypeFlagBits
handleType <- Ptr ExternalMemoryHandleTypeFlagBits
-> IO ExternalMemoryHandleTypeFlagBits
forall a. Storable a => Ptr a -> IO a
peek @ExternalMemoryHandleTypeFlagBits (("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
p ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> Int -> Ptr ExternalMemoryHandleTypeFlagBits
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr ExternalMemoryHandleTypeFlagBits))
    MemoryGetFdInfoKHR -> IO MemoryGetFdInfoKHR
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MemoryGetFdInfoKHR -> IO MemoryGetFdInfoKHR)
-> MemoryGetFdInfoKHR -> IO MemoryGetFdInfoKHR
forall a b. (a -> b) -> a -> b
$ DeviceMemory
-> ExternalMemoryHandleTypeFlagBits -> MemoryGetFdInfoKHR
MemoryGetFdInfoKHR
             DeviceMemory
memory ExternalMemoryHandleTypeFlagBits
handleType

instance Storable MemoryGetFdInfoKHR where
  sizeOf :: MemoryGetFdInfoKHR -> Int
sizeOf ~MemoryGetFdInfoKHR
_ = 32
  alignment :: MemoryGetFdInfoKHR -> Int
alignment ~MemoryGetFdInfoKHR
_ = 8
  peek :: ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO MemoryGetFdInfoKHR
peek = ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR) -> IO MemoryGetFdInfoKHR
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
  poke :: ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> MemoryGetFdInfoKHR -> IO ()
poke ptr :: "pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
ptr poked :: MemoryGetFdInfoKHR
poked = ("pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR)
-> MemoryGetFdInfoKHR -> IO () -> IO ()
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct "pGetFdInfo" ::: Ptr MemoryGetFdInfoKHR
ptr MemoryGetFdInfoKHR
poked (() -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

instance Zero MemoryGetFdInfoKHR where
  zero :: MemoryGetFdInfoKHR
zero = DeviceMemory
-> ExternalMemoryHandleTypeFlagBits -> MemoryGetFdInfoKHR
MemoryGetFdInfoKHR
           DeviceMemory
forall a. Zero a => a
zero
           ExternalMemoryHandleTypeFlagBits
forall a. Zero a => a
zero


type KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION = 1

-- No documentation found for TopLevel "VK_KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION"
pattern KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION :: forall a . Integral a => a
pattern $bKHR_EXTERNAL_MEMORY_FD_SPEC_VERSION :: a
$mKHR_EXTERNAL_MEMORY_FD_SPEC_VERSION :: forall r a. Integral a => a -> (Void# -> r) -> (Void# -> r) -> r
KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION = 1


type KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME = "VK_KHR_external_memory_fd"

-- No documentation found for TopLevel "VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME"
pattern KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern $bKHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME :: a
$mKHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME :: forall r a.
(Eq a, IsString a) =>
a -> (Void# -> r) -> (Void# -> r) -> r
KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME = "VK_KHR_external_memory_fd"