{-# language CPP #-}
-- | = Name
--
-- VK_KHR_win32_keyed_mutex - device extension
--
-- == VK_KHR_win32_keyed_mutex
--
-- [__Name String__]
--     @VK_KHR_win32_keyed_mutex@
--
-- [__Extension Type__]
--     Device extension
--
-- [__Registered Extension Number__]
--     76
--
-- [__Revision__]
--     1
--
-- [__Extension and Version Dependencies__]
--
--     -   Requires support for Vulkan 1.0
--
--     -   Requires @VK_KHR_external_memory_win32@ to be enabled for any
--         device-level functionality
--
-- [__Contact__]
--
--     -   Carsten Rohde
--         <https://github.com/KhronosGroup/Vulkan-Docs/issues/new?body=[VK_KHR_win32_keyed_mutex] @crohde%0A*Here describe the issue or question you have about the VK_KHR_win32_keyed_mutex extension* >
--
-- == Other Extension Metadata
--
-- [__Last Modified Date__]
--     2016-10-21
--
-- [__IP Status__]
--     No known IP claims.
--
-- [__Contributors__]
--
--     -   James Jones, NVIDIA
--
--     -   Jeff Juliano, NVIDIA
--
--     -   Carsten Rohde, NVIDIA
--
-- == Description
--
-- Applications that wish to import Direct3D 11 memory objects into the
-- Vulkan API may wish to use the native keyed mutex mechanism to
-- synchronize access to the memory between Vulkan and Direct3D. This
-- extension provides a way for an application to access the keyed mutex
-- associated with an imported Vulkan memory object when submitting command
-- buffers to a queue.
--
-- == New Structures
--
-- -   Extending 'Vulkan.Core10.Queue.SubmitInfo',
--     'Vulkan.Core13.Promoted_From_VK_KHR_synchronization2.SubmitInfo2':
--
--     -   'Win32KeyedMutexAcquireReleaseInfoKHR'
--
-- == New Enum Constants
--
-- -   'KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME'
--
-- -   'KHR_WIN32_KEYED_MUTEX_SPEC_VERSION'
--
-- -   Extending 'Vulkan.Core10.Enums.StructureType.StructureType':
--
--     -   'Vulkan.Core10.Enums.StructureType.STRUCTURE_TYPE_WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_KHR'
--
-- == Version History
--
-- -   Revision 1, 2016-10-21 (James Jones)
--
--     -   Initial revision
--
-- == See Also
--
-- 'Win32KeyedMutexAcquireReleaseInfoKHR'
--
-- == Document Notes
--
-- For more information, see the
-- <https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VK_KHR_win32_keyed_mutex Vulkan Specification>
--
-- This page is a generated document. Fixes and changes should be made to
-- the generator scripts, not directly.
module Vulkan.Extensions.VK_KHR_win32_keyed_mutex  ( Win32KeyedMutexAcquireReleaseInfoKHR(..)
                                                   , KHR_WIN32_KEYED_MUTEX_SPEC_VERSION
                                                   , pattern KHR_WIN32_KEYED_MUTEX_SPEC_VERSION
                                                   , KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME
                                                   , pattern KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME
                                                   ) where

import Control.Monad (unless)
import Foreign.Marshal.Alloc (allocaBytes)
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 Data.Vector (generateM)
import qualified Data.Vector (imapM_)
import qualified Data.Vector (length)
import Vulkan.CStruct (FromCStruct)
import Vulkan.CStruct (FromCStruct(..))
import Vulkan.CStruct (ToCStruct)
import Vulkan.CStruct (ToCStruct(..))
import Vulkan.Zero (Zero(..))
import Data.String (IsString)
import Data.Typeable (Typeable)
import Foreign.Storable (Storable(peek))
import Foreign.Storable (Storable(poke))
import GHC.Generics (Generic)
import GHC.IO.Exception (IOErrorType(..))
import GHC.IO.Exception (IOException(..))
import Foreign.Ptr (Ptr)
import Data.Word (Word32)
import Data.Word (Word64)
import Data.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import Data.Vector (Vector)
import Vulkan.CStruct.Utils (advancePtrBytes)
import Vulkan.Core10.Handles (DeviceMemory)
import Vulkan.Core10.Enums.StructureType (StructureType)
import Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_KHR))
-- | VkWin32KeyedMutexAcquireReleaseInfoKHR - Use the Windows keyed mutex
-- mechanism to synchronize work
--
-- == Valid Usage
--
-- -   #VUID-VkWin32KeyedMutexAcquireReleaseInfoKHR-pAcquireSyncs-00081#
--     Each member of @pAcquireSyncs@ and @pReleaseSyncs@ /must/ be a
--     device memory object imported by setting
--     'Vulkan.Extensions.VK_KHR_external_memory_win32.ImportMemoryWin32HandleInfoKHR'::@handleType@
--     to
--     'Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits.EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT'
--     or
--     'Vulkan.Core11.Enums.ExternalMemoryHandleTypeFlagBits.EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT'
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-VkWin32KeyedMutexAcquireReleaseInfoKHR-sType-sType# @sType@
--     /must/ be
--     'Vulkan.Core10.Enums.StructureType.STRUCTURE_TYPE_WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_KHR'
--
-- -   #VUID-VkWin32KeyedMutexAcquireReleaseInfoKHR-pAcquireSyncs-parameter#
--     If @acquireCount@ is not @0@, @pAcquireSyncs@ /must/ be a valid
--     pointer to an array of @acquireCount@ valid
--     'Vulkan.Core10.Handles.DeviceMemory' handles
--
-- -   #VUID-VkWin32KeyedMutexAcquireReleaseInfoKHR-pAcquireKeys-parameter#
--     If @acquireCount@ is not @0@, @pAcquireKeys@ /must/ be a valid
--     pointer to an array of @acquireCount@ @uint64_t@ values
--
-- -   #VUID-VkWin32KeyedMutexAcquireReleaseInfoKHR-pAcquireTimeouts-parameter#
--     If @acquireCount@ is not @0@, @pAcquireTimeouts@ /must/ be a valid
--     pointer to an array of @acquireCount@ @uint32_t@ values
--
-- -   #VUID-VkWin32KeyedMutexAcquireReleaseInfoKHR-pReleaseSyncs-parameter#
--     If @releaseCount@ is not @0@, @pReleaseSyncs@ /must/ be a valid
--     pointer to an array of @releaseCount@ valid
--     'Vulkan.Core10.Handles.DeviceMemory' handles
--
-- -   #VUID-VkWin32KeyedMutexAcquireReleaseInfoKHR-pReleaseKeys-parameter#
--     If @releaseCount@ is not @0@, @pReleaseKeys@ /must/ be a valid
--     pointer to an array of @releaseCount@ @uint64_t@ values
--
-- -   #VUID-VkWin32KeyedMutexAcquireReleaseInfoKHR-commonparent# Both of
--     the elements of @pAcquireSyncs@, and the elements of @pReleaseSyncs@
--     that are valid handles of non-ignored parameters /must/ have been
--     created, allocated, or retrieved from the same
--     'Vulkan.Core10.Handles.Device'
--
-- = See Also
--
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_KHR_win32_keyed_mutex VK_KHR_win32_keyed_mutex>,
-- 'Vulkan.Core10.Handles.DeviceMemory',
-- 'Vulkan.Core10.Enums.StructureType.StructureType'
data Win32KeyedMutexAcquireReleaseInfoKHR = Win32KeyedMutexAcquireReleaseInfoKHR
  { -- | @pAcquireSyncs@ is a pointer to an array of
    -- 'Vulkan.Core10.Handles.DeviceMemory' objects which were imported from
    -- Direct3D 11 resources.
    Win32KeyedMutexAcquireReleaseInfoKHR -> Vector DeviceMemory
acquireSyncs :: Vector DeviceMemory
  , -- | @pAcquireKeys@ is a pointer to an array of mutex key values to wait for
    -- prior to beginning the submitted work. Entries refer to the keyed mutex
    -- associated with the corresponding entries in @pAcquireSyncs@.
    Win32KeyedMutexAcquireReleaseInfoKHR -> Vector Word64
acquireKeys :: Vector Word64
  , -- | @pAcquireTimeouts@ is a pointer to an array of timeout values, in
    -- millisecond units, for each acquire specified in @pAcquireKeys@.
    Win32KeyedMutexAcquireReleaseInfoKHR -> Vector Word32
acquireTimeouts :: Vector Word32
  , -- | @pReleaseSyncs@ is a pointer to an array of
    -- 'Vulkan.Core10.Handles.DeviceMemory' objects which were imported from
    -- Direct3D 11 resources.
    Win32KeyedMutexAcquireReleaseInfoKHR -> Vector DeviceMemory
releaseSyncs :: Vector DeviceMemory
  , -- | @pReleaseKeys@ is a pointer to an array of mutex key values to set when
    -- the submitted work has completed. Entries refer to the keyed mutex
    -- associated with the corresponding entries in @pReleaseSyncs@.
    Win32KeyedMutexAcquireReleaseInfoKHR -> Vector Word64
releaseKeys :: Vector Word64
  }
  deriving (Typeable)
#if defined(GENERIC_INSTANCES)
deriving instance Generic (Win32KeyedMutexAcquireReleaseInfoKHR)
#endif
deriving instance Show Win32KeyedMutexAcquireReleaseInfoKHR

instance ToCStruct Win32KeyedMutexAcquireReleaseInfoKHR where
  withCStruct :: forall b.
Win32KeyedMutexAcquireReleaseInfoKHR
-> (Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> IO b) -> IO b
withCStruct Win32KeyedMutexAcquireReleaseInfoKHR
x Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> IO b
f = Int -> (Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> IO b) -> IO b
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes Int
72 ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> IO b) -> IO b)
-> (Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p -> Ptr Win32KeyedMutexAcquireReleaseInfoKHR
-> Win32KeyedMutexAcquireReleaseInfoKHR -> IO b -> IO b
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Win32KeyedMutexAcquireReleaseInfoKHR
x (Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> IO b
f Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p)
  pokeCStruct :: forall b.
Ptr Win32KeyedMutexAcquireReleaseInfoKHR
-> Win32KeyedMutexAcquireReleaseInfoKHR -> IO b -> IO b
pokeCStruct Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Win32KeyedMutexAcquireReleaseInfoKHR{Vector Word32
Vector Word64
Vector DeviceMemory
releaseKeys :: Vector Word64
releaseSyncs :: Vector DeviceMemory
acquireTimeouts :: Vector Word32
acquireKeys :: Vector Word64
acquireSyncs :: Vector DeviceMemory
$sel:releaseKeys:Win32KeyedMutexAcquireReleaseInfoKHR :: Win32KeyedMutexAcquireReleaseInfoKHR -> Vector Word64
$sel:releaseSyncs:Win32KeyedMutexAcquireReleaseInfoKHR :: Win32KeyedMutexAcquireReleaseInfoKHR -> Vector DeviceMemory
$sel:acquireTimeouts:Win32KeyedMutexAcquireReleaseInfoKHR :: Win32KeyedMutexAcquireReleaseInfoKHR -> Vector Word32
$sel:acquireKeys:Win32KeyedMutexAcquireReleaseInfoKHR :: Win32KeyedMutexAcquireReleaseInfoKHR -> Vector Word64
$sel:acquireSyncs:Win32KeyedMutexAcquireReleaseInfoKHR :: Win32KeyedMutexAcquireReleaseInfoKHR -> Vector DeviceMemory
..} IO b
f = ContT b IO b -> IO b
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT b IO b -> IO b) -> ContT b IO b -> IO b
forall a b. (a -> b) -> a -> b
$ do
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR
-> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_KHR)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    let pAcquireSyncsLength :: Int
pAcquireSyncsLength = Vector DeviceMemory -> Int
forall a. Vector a -> Int
Data.Vector.length (Vector DeviceMemory -> Int) -> Vector DeviceMemory -> Int
forall a b. (a -> b) -> a -> b
$ (Vector DeviceMemory
acquireSyncs)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ((Vector Word64 -> Int
forall a. Vector a -> Int
Data.Vector.length (Vector Word64 -> Int) -> Vector Word64 -> Int
forall a b. (a -> b) -> a -> b
$ (Vector Word64
acquireKeys)) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
pAcquireSyncsLength) (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 String
"" String
"pAcquireKeys and pAcquireSyncs must have the same length" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ((Vector Word32 -> Int
forall a. Vector a -> Int
Data.Vector.length (Vector Word32 -> Int) -> Vector Word32 -> Int
forall a b. (a -> b) -> a -> b
$ (Vector Word32
acquireTimeouts)) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
pAcquireSyncsLength) (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 String
"" String
"pAcquireTimeouts and pAcquireSyncs must have the same length" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16 :: Ptr Word32)) ((Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
pAcquireSyncsLength :: Word32))
    Ptr DeviceMemory
pPAcquireSyncs' <- ((Ptr DeviceMemory -> IO b) -> IO b)
-> ContT b IO (Ptr DeviceMemory)
forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr DeviceMemory -> IO b) -> IO b)
 -> ContT b IO (Ptr DeviceMemory))
-> ((Ptr DeviceMemory -> IO b) -> IO b)
-> ContT b IO (Ptr DeviceMemory)
forall a b. (a -> b) -> a -> b
$ forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes @DeviceMemory ((Vector DeviceMemory -> Int
forall a. Vector a -> Int
Data.Vector.length (Vector DeviceMemory
acquireSyncs)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
8)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> DeviceMemory -> IO ()) -> Vector DeviceMemory -> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\Int
i DeviceMemory
e -> Ptr DeviceMemory -> DeviceMemory -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr DeviceMemory
pPAcquireSyncs' Ptr DeviceMemory -> Int -> Ptr DeviceMemory
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceMemory) (DeviceMemory
e)) (Vector DeviceMemory
acquireSyncs)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Ptr (Ptr DeviceMemory) -> Ptr DeviceMemory -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR
-> Int -> Ptr (Ptr DeviceMemory)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
24 :: Ptr (Ptr DeviceMemory))) (Ptr DeviceMemory
pPAcquireSyncs')
    Ptr Word64
pPAcquireKeys' <- ((Ptr Word64 -> IO b) -> IO b) -> ContT b IO (Ptr Word64)
forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Word64 -> IO b) -> IO b) -> ContT b IO (Ptr Word64))
-> ((Ptr Word64 -> IO b) -> IO b) -> ContT b IO (Ptr Word64)
forall a b. (a -> b) -> a -> b
$ forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes @Word64 ((Vector Word64 -> Int
forall a. Vector a -> Int
Data.Vector.length (Vector Word64
acquireKeys)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
8)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> Word64 -> IO ()) -> Vector Word64 -> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\Int
i Word64
e -> Ptr Word64 -> Word64 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Word64
pPAcquireKeys' Ptr Word64 -> Int -> Ptr Word64
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Word64) (Word64
e)) (Vector Word64
acquireKeys)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Ptr (Ptr Word64) -> Ptr Word64 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr (Ptr Word64)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
32 :: Ptr (Ptr Word64))) (Ptr Word64
pPAcquireKeys')
    Ptr Word32
pPAcquireTimeouts' <- ((Ptr Word32 -> IO b) -> IO b) -> ContT b IO (Ptr Word32)
forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Word32 -> IO b) -> IO b) -> ContT b IO (Ptr Word32))
-> ((Ptr Word32 -> IO b) -> IO b) -> ContT b IO (Ptr Word32)
forall a b. (a -> b) -> a -> b
$ forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes @Word32 ((Vector Word32 -> Int
forall a. Vector a -> Int
Data.Vector.length (Vector Word32
acquireTimeouts)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
4)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> Word32 -> IO ()) -> Vector Word32 -> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\Int
i Word32
e -> Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Word32
pPAcquireTimeouts' Ptr Word32 -> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
4 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Word32) (Word32
e)) (Vector Word32
acquireTimeouts)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Ptr (Ptr Word32) -> Ptr Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr (Ptr Word32)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
40 :: Ptr (Ptr Word32))) (Ptr Word32
pPAcquireTimeouts')
    let pReleaseSyncsLength :: Int
pReleaseSyncsLength = Vector DeviceMemory -> Int
forall a. Vector a -> Int
Data.Vector.length (Vector DeviceMemory -> Int) -> Vector DeviceMemory -> Int
forall a b. (a -> b) -> a -> b
$ (Vector DeviceMemory
releaseSyncs)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ((Vector Word64 -> Int
forall a. Vector a -> Int
Data.Vector.length (Vector Word64 -> Int) -> Vector Word64 -> Int
forall a b. (a -> b) -> a -> b
$ (Vector Word64
releaseKeys)) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
pReleaseSyncsLength) (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 String
"" String
"pReleaseKeys and pReleaseSyncs must have the same length" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
48 :: Ptr Word32)) ((Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
pReleaseSyncsLength :: Word32))
    Ptr DeviceMemory
pPReleaseSyncs' <- ((Ptr DeviceMemory -> IO b) -> IO b)
-> ContT b IO (Ptr DeviceMemory)
forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr DeviceMemory -> IO b) -> IO b)
 -> ContT b IO (Ptr DeviceMemory))
-> ((Ptr DeviceMemory -> IO b) -> IO b)
-> ContT b IO (Ptr DeviceMemory)
forall a b. (a -> b) -> a -> b
$ forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes @DeviceMemory ((Vector DeviceMemory -> Int
forall a. Vector a -> Int
Data.Vector.length (Vector DeviceMemory
releaseSyncs)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
8)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> DeviceMemory -> IO ()) -> Vector DeviceMemory -> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\Int
i DeviceMemory
e -> Ptr DeviceMemory -> DeviceMemory -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr DeviceMemory
pPReleaseSyncs' Ptr DeviceMemory -> Int -> Ptr DeviceMemory
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceMemory) (DeviceMemory
e)) (Vector DeviceMemory
releaseSyncs)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Ptr (Ptr DeviceMemory) -> Ptr DeviceMemory -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR
-> Int -> Ptr (Ptr DeviceMemory)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
56 :: Ptr (Ptr DeviceMemory))) (Ptr DeviceMemory
pPReleaseSyncs')
    Ptr Word64
pPReleaseKeys' <- ((Ptr Word64 -> IO b) -> IO b) -> ContT b IO (Ptr Word64)
forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Word64 -> IO b) -> IO b) -> ContT b IO (Ptr Word64))
-> ((Ptr Word64 -> IO b) -> IO b) -> ContT b IO (Ptr Word64)
forall a b. (a -> b) -> a -> b
$ forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes @Word64 ((Vector Word64 -> Int
forall a. Vector a -> Int
Data.Vector.length (Vector Word64
releaseKeys)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
8)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> Word64 -> IO ()) -> Vector Word64 -> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\Int
i Word64
e -> Ptr Word64 -> Word64 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Word64
pPReleaseKeys' Ptr Word64 -> Int -> Ptr Word64
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Word64) (Word64
e)) (Vector Word64
releaseKeys)
    IO () -> ContT b IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT b IO ()) -> IO () -> ContT b IO ()
forall a b. (a -> b) -> a -> b
$ Ptr (Ptr Word64) -> Ptr Word64 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr (Ptr Word64)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
64 :: Ptr (Ptr Word64))) (Ptr Word64
pPReleaseKeys')
    IO b -> ContT b IO b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO b -> ContT b IO b) -> IO b -> ContT b IO b
forall a b. (a -> b) -> a -> b
$ IO b
f
  cStructSize :: Int
cStructSize = Int
72
  cStructAlignment :: Int
cStructAlignment = Int
8
  pokeZeroCStruct :: forall b. Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> IO b -> IO b
pokeZeroCStruct Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR
-> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_KHR)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    IO b
f

instance FromCStruct Win32KeyedMutexAcquireReleaseInfoKHR where
  peekCStruct :: Ptr Win32KeyedMutexAcquireReleaseInfoKHR
-> IO Win32KeyedMutexAcquireReleaseInfoKHR
peekCStruct Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p = do
    Word32
acquireCount <- forall a. Storable a => Ptr a -> IO a
peek @Word32 ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16 :: Ptr Word32))
    Ptr DeviceMemory
pAcquireSyncs <- forall a. Storable a => Ptr a -> IO a
peek @(Ptr DeviceMemory) ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR
-> Int -> Ptr (Ptr DeviceMemory)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
24 :: Ptr (Ptr DeviceMemory)))
    Vector DeviceMemory
pAcquireSyncs' <- Int -> (Int -> IO DeviceMemory) -> IO (Vector DeviceMemory)
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
acquireCount) (\Int
i -> forall a. Storable a => Ptr a -> IO a
peek @DeviceMemory ((Ptr DeviceMemory
pAcquireSyncs Ptr DeviceMemory -> Int -> Ptr DeviceMemory
forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceMemory)))
    Ptr Word64
pAcquireKeys <- forall a. Storable a => Ptr a -> IO a
peek @(Ptr Word64) ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr (Ptr Word64)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
32 :: Ptr (Ptr Word64)))
    Vector Word64
pAcquireKeys' <- Int -> (Int -> IO Word64) -> IO (Vector Word64)
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
acquireCount) (\Int
i -> forall a. Storable a => Ptr a -> IO a
peek @Word64 ((Ptr Word64
pAcquireKeys Ptr Word64 -> Int -> Ptr Word64
forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Word64)))
    Ptr Word32
pAcquireTimeouts <- forall a. Storable a => Ptr a -> IO a
peek @(Ptr Word32) ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr (Ptr Word32)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
40 :: Ptr (Ptr Word32)))
    Vector Word32
pAcquireTimeouts' <- Int -> (Int -> IO Word32) -> IO (Vector Word32)
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
acquireCount) (\Int
i -> forall a. Storable a => Ptr a -> IO a
peek @Word32 ((Ptr Word32
pAcquireTimeouts Ptr Word32 -> Int -> Ptr Word32
forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
4 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Word32)))
    Word32
releaseCount <- forall a. Storable a => Ptr a -> IO a
peek @Word32 ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
48 :: Ptr Word32))
    Ptr DeviceMemory
pReleaseSyncs <- forall a. Storable a => Ptr a -> IO a
peek @(Ptr DeviceMemory) ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR
-> Int -> Ptr (Ptr DeviceMemory)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
56 :: Ptr (Ptr DeviceMemory)))
    Vector DeviceMemory
pReleaseSyncs' <- Int -> (Int -> IO DeviceMemory) -> IO (Vector DeviceMemory)
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
releaseCount) (\Int
i -> forall a. Storable a => Ptr a -> IO a
peek @DeviceMemory ((Ptr DeviceMemory
pReleaseSyncs Ptr DeviceMemory -> Int -> Ptr DeviceMemory
forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceMemory)))
    Ptr Word64
pReleaseKeys <- forall a. Storable a => Ptr a -> IO a
peek @(Ptr Word64) ((Ptr Win32KeyedMutexAcquireReleaseInfoKHR
p Ptr Win32KeyedMutexAcquireReleaseInfoKHR -> Int -> Ptr (Ptr Word64)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
64 :: Ptr (Ptr Word64)))
    Vector Word64
pReleaseKeys' <- Int -> (Int -> IO Word64) -> IO (Vector Word64)
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
releaseCount) (\Int
i -> forall a. Storable a => Ptr a -> IO a
peek @Word64 ((Ptr Word64
pReleaseKeys Ptr Word64 -> Int -> Ptr Word64
forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Word64)))
    Win32KeyedMutexAcquireReleaseInfoKHR
-> IO Win32KeyedMutexAcquireReleaseInfoKHR
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Win32KeyedMutexAcquireReleaseInfoKHR
 -> IO Win32KeyedMutexAcquireReleaseInfoKHR)
-> Win32KeyedMutexAcquireReleaseInfoKHR
-> IO Win32KeyedMutexAcquireReleaseInfoKHR
forall a b. (a -> b) -> a -> b
$ Vector DeviceMemory
-> Vector Word64
-> Vector Word32
-> Vector DeviceMemory
-> Vector Word64
-> Win32KeyedMutexAcquireReleaseInfoKHR
Win32KeyedMutexAcquireReleaseInfoKHR
             Vector DeviceMemory
pAcquireSyncs'
             Vector Word64
pAcquireKeys'
             Vector Word32
pAcquireTimeouts'
             Vector DeviceMemory
pReleaseSyncs'
             Vector Word64
pReleaseKeys'

instance Zero Win32KeyedMutexAcquireReleaseInfoKHR where
  zero :: Win32KeyedMutexAcquireReleaseInfoKHR
zero = Vector DeviceMemory
-> Vector Word64
-> Vector Word32
-> Vector DeviceMemory
-> Vector Word64
-> Win32KeyedMutexAcquireReleaseInfoKHR
Win32KeyedMutexAcquireReleaseInfoKHR
           Vector DeviceMemory
forall a. Monoid a => a
mempty
           Vector Word64
forall a. Monoid a => a
mempty
           Vector Word32
forall a. Monoid a => a
mempty
           Vector DeviceMemory
forall a. Monoid a => a
mempty
           Vector Word64
forall a. Monoid a => a
mempty


type KHR_WIN32_KEYED_MUTEX_SPEC_VERSION = 1

-- No documentation found for TopLevel "VK_KHR_WIN32_KEYED_MUTEX_SPEC_VERSION"
pattern KHR_WIN32_KEYED_MUTEX_SPEC_VERSION :: forall a . Integral a => a
pattern $bKHR_WIN32_KEYED_MUTEX_SPEC_VERSION :: forall a. Integral a => a
$mKHR_WIN32_KEYED_MUTEX_SPEC_VERSION :: forall {r} {a}.
Integral a =>
a -> (Void# -> r) -> (Void# -> r) -> r
KHR_WIN32_KEYED_MUTEX_SPEC_VERSION = 1


type KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME = "VK_KHR_win32_keyed_mutex"

-- No documentation found for TopLevel "VK_KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME"
pattern KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern $bKHR_WIN32_KEYED_MUTEX_EXTENSION_NAME :: forall a. (Eq a, IsString a) => a
$mKHR_WIN32_KEYED_MUTEX_EXTENSION_NAME :: forall {r} {a}.
(Eq a, IsString a) =>
a -> (Void# -> r) -> (Void# -> r) -> r
KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME = "VK_KHR_win32_keyed_mutex"