{-# language CPP #-}
module Graphics.Vulkan.Extensions.VK_KHR_external_memory_win32 ( getMemoryWin32HandleKHR
, getMemoryWin32HandlePropertiesKHR
, ImportMemoryWin32HandleInfoKHR(..)
, ExportMemoryWin32HandleInfoKHR(..)
, MemoryWin32HandlePropertiesKHR(..)
, MemoryGetWin32HandleInfoKHR(..)
, KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION
, pattern KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION
, KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME
, pattern KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME
, HANDLE
, DWORD
, LPCWSTR
, SECURITY_ATTRIBUTES
) 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 Control.Monad.IO.Class (MonadIO)
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 Data.Word (Word32)
import Data.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import Graphics.Vulkan.Extensions.WSITypes (DWORD)
import Graphics.Vulkan.Core10.Handles (Device)
import Graphics.Vulkan.Core10.Handles (Device(..))
import Graphics.Vulkan.Dynamic (DeviceCmds(pVkGetMemoryWin32HandleKHR))
import Graphics.Vulkan.Dynamic (DeviceCmds(pVkGetMemoryWin32HandlePropertiesKHR))
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.Extensions.WSITypes (HANDLE)
import Graphics.Vulkan.Extensions.WSITypes (LPCWSTR)
import Graphics.Vulkan.Core10.Enums.Result (Result)
import Graphics.Vulkan.Core10.Enums.Result (Result(..))
import Graphics.Vulkan.Extensions.WSITypes (SECURITY_ATTRIBUTES)
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_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_IMPORT_MEMORY_WIN32_HANDLE_INFO_KHR))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_MEMORY_WIN32_HANDLE_PROPERTIES_KHR))
import Graphics.Vulkan.Core10.Enums.Result (Result(SUCCESS))
import Graphics.Vulkan.Extensions.WSITypes (DWORD)
import Graphics.Vulkan.Extensions.WSITypes (HANDLE)
import Graphics.Vulkan.Extensions.WSITypes (LPCWSTR)
import Graphics.Vulkan.Extensions.WSITypes (SECURITY_ATTRIBUTES)
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkGetMemoryWin32HandleKHR
:: FunPtr (Ptr Device_T -> Ptr MemoryGetWin32HandleInfoKHR -> Ptr HANDLE -> IO Result) -> Ptr Device_T -> Ptr MemoryGetWin32HandleInfoKHR -> Ptr HANDLE -> IO Result
getMemoryWin32HandleKHR :: forall io . MonadIO io => Device -> MemoryGetWin32HandleInfoKHR -> io (HANDLE)
getMemoryWin32HandleKHR device getWin32HandleInfo = liftIO . evalContT $ do
let vkGetMemoryWin32HandleKHR' = mkVkGetMemoryWin32HandleKHR (pVkGetMemoryWin32HandleKHR (deviceCmds (device :: Device)))
pGetWin32HandleInfo <- ContT $ withCStruct (getWin32HandleInfo)
pPHandle <- ContT $ bracket (callocBytes @HANDLE 8) free
r <- lift $ vkGetMemoryWin32HandleKHR' (deviceHandle (device)) pGetWin32HandleInfo (pPHandle)
lift $ when (r < SUCCESS) (throwIO (VulkanException r))
pHandle <- lift $ peek @HANDLE pPHandle
pure $ (pHandle)
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkGetMemoryWin32HandlePropertiesKHR
:: FunPtr (Ptr Device_T -> ExternalMemoryHandleTypeFlagBits -> HANDLE -> Ptr MemoryWin32HandlePropertiesKHR -> IO Result) -> Ptr Device_T -> ExternalMemoryHandleTypeFlagBits -> HANDLE -> Ptr MemoryWin32HandlePropertiesKHR -> IO Result
getMemoryWin32HandlePropertiesKHR :: forall io . MonadIO io => Device -> ExternalMemoryHandleTypeFlagBits -> HANDLE -> io (MemoryWin32HandlePropertiesKHR)
getMemoryWin32HandlePropertiesKHR device handleType handle = liftIO . evalContT $ do
let vkGetMemoryWin32HandlePropertiesKHR' = mkVkGetMemoryWin32HandlePropertiesKHR (pVkGetMemoryWin32HandlePropertiesKHR (deviceCmds (device :: Device)))
pPMemoryWin32HandleProperties <- ContT (withZeroCStruct @MemoryWin32HandlePropertiesKHR)
r <- lift $ vkGetMemoryWin32HandlePropertiesKHR' (deviceHandle (device)) (handleType) (handle) (pPMemoryWin32HandleProperties)
lift $ when (r < SUCCESS) (throwIO (VulkanException r))
pMemoryWin32HandleProperties <- lift $ peekCStruct @MemoryWin32HandlePropertiesKHR pPMemoryWin32HandleProperties
pure $ (pMemoryWin32HandleProperties)
data ImportMemoryWin32HandleInfoKHR = ImportMemoryWin32HandleInfoKHR
{
handleType :: ExternalMemoryHandleTypeFlagBits
,
handle :: HANDLE
,
name :: LPCWSTR
}
deriving (Typeable)
deriving instance Show ImportMemoryWin32HandleInfoKHR
instance ToCStruct ImportMemoryWin32HandleInfoKHR where
withCStruct x f = allocaBytesAligned 40 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p ImportMemoryWin32HandleInfoKHR{..} f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_IMPORT_MEMORY_WIN32_HANDLE_INFO_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr ExternalMemoryHandleTypeFlagBits)) (handleType)
poke ((p `plusPtr` 24 :: Ptr HANDLE)) (handle)
poke ((p `plusPtr` 32 :: Ptr LPCWSTR)) (name)
f
cStructSize = 40
cStructAlignment = 8
pokeZeroCStruct p f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_IMPORT_MEMORY_WIN32_HANDLE_INFO_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
f
instance FromCStruct ImportMemoryWin32HandleInfoKHR where
peekCStruct p = do
handleType <- peek @ExternalMemoryHandleTypeFlagBits ((p `plusPtr` 16 :: Ptr ExternalMemoryHandleTypeFlagBits))
handle <- peek @HANDLE ((p `plusPtr` 24 :: Ptr HANDLE))
name <- peek @LPCWSTR ((p `plusPtr` 32 :: Ptr LPCWSTR))
pure $ ImportMemoryWin32HandleInfoKHR
handleType handle name
instance Storable ImportMemoryWin32HandleInfoKHR where
sizeOf ~_ = 40
alignment ~_ = 8
peek = peekCStruct
poke ptr poked = pokeCStruct ptr poked (pure ())
instance Zero ImportMemoryWin32HandleInfoKHR where
zero = ImportMemoryWin32HandleInfoKHR
zero
zero
zero
data ExportMemoryWin32HandleInfoKHR = ExportMemoryWin32HandleInfoKHR
{
attributes :: Ptr SECURITY_ATTRIBUTES
,
dwAccess :: DWORD
,
name :: LPCWSTR
}
deriving (Typeable)
deriving instance Show ExportMemoryWin32HandleInfoKHR
instance ToCStruct ExportMemoryWin32HandleInfoKHR where
withCStruct x f = allocaBytesAligned 40 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p ExportMemoryWin32HandleInfoKHR{..} f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr (Ptr SECURITY_ATTRIBUTES))) (attributes)
poke ((p `plusPtr` 24 :: Ptr DWORD)) (dwAccess)
poke ((p `plusPtr` 32 :: Ptr LPCWSTR)) (name)
f
cStructSize = 40
cStructAlignment = 8
pokeZeroCStruct p f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 24 :: Ptr DWORD)) (zero)
poke ((p `plusPtr` 32 :: Ptr LPCWSTR)) (zero)
f
instance FromCStruct ExportMemoryWin32HandleInfoKHR where
peekCStruct p = do
pAttributes <- peek @(Ptr SECURITY_ATTRIBUTES) ((p `plusPtr` 16 :: Ptr (Ptr SECURITY_ATTRIBUTES)))
dwAccess <- peek @DWORD ((p `plusPtr` 24 :: Ptr DWORD))
name <- peek @LPCWSTR ((p `plusPtr` 32 :: Ptr LPCWSTR))
pure $ ExportMemoryWin32HandleInfoKHR
pAttributes dwAccess name
instance Storable ExportMemoryWin32HandleInfoKHR where
sizeOf ~_ = 40
alignment ~_ = 8
peek = peekCStruct
poke ptr poked = pokeCStruct ptr poked (pure ())
instance Zero ExportMemoryWin32HandleInfoKHR where
zero = ExportMemoryWin32HandleInfoKHR
zero
zero
zero
data MemoryWin32HandlePropertiesKHR = MemoryWin32HandlePropertiesKHR
{
memoryTypeBits :: Word32 }
deriving (Typeable)
deriving instance Show MemoryWin32HandlePropertiesKHR
instance ToCStruct MemoryWin32HandlePropertiesKHR where
withCStruct x f = allocaBytesAligned 24 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p MemoryWin32HandlePropertiesKHR{..} f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_MEMORY_WIN32_HANDLE_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_WIN32_HANDLE_PROPERTIES_KHR)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr Word32)) (zero)
f
instance FromCStruct MemoryWin32HandlePropertiesKHR where
peekCStruct p = do
memoryTypeBits <- peek @Word32 ((p `plusPtr` 16 :: Ptr Word32))
pure $ MemoryWin32HandlePropertiesKHR
memoryTypeBits
instance Storable MemoryWin32HandlePropertiesKHR where
sizeOf ~_ = 24
alignment ~_ = 8
peek = peekCStruct
poke ptr poked = pokeCStruct ptr poked (pure ())
instance Zero MemoryWin32HandlePropertiesKHR where
zero = MemoryWin32HandlePropertiesKHR
zero
data MemoryGetWin32HandleInfoKHR = MemoryGetWin32HandleInfoKHR
{
memory :: DeviceMemory
,
handleType :: ExternalMemoryHandleTypeFlagBits
}
deriving (Typeable)
deriving instance Show MemoryGetWin32HandleInfoKHR
instance ToCStruct MemoryGetWin32HandleInfoKHR where
withCStruct x f = allocaBytesAligned 32 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p MemoryGetWin32HandleInfoKHR{..} f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_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_WIN32_HANDLE_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 MemoryGetWin32HandleInfoKHR where
peekCStruct p = do
memory <- peek @DeviceMemory ((p `plusPtr` 16 :: Ptr DeviceMemory))
handleType <- peek @ExternalMemoryHandleTypeFlagBits ((p `plusPtr` 24 :: Ptr ExternalMemoryHandleTypeFlagBits))
pure $ MemoryGetWin32HandleInfoKHR
memory handleType
instance Storable MemoryGetWin32HandleInfoKHR where
sizeOf ~_ = 32
alignment ~_ = 8
peek = peekCStruct
poke ptr poked = pokeCStruct ptr poked (pure ())
instance Zero MemoryGetWin32HandleInfoKHR where
zero = MemoryGetWin32HandleInfoKHR
zero
zero
type KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION = 1
pattern KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION :: forall a . Integral a => a
pattern KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION = 1
type KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME = "VK_KHR_external_memory_win32"
pattern KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME = "VK_KHR_external_memory_win32"