{-# language CPP #-}
-- No documentation found for Chapter "Fence"
module Vulkan.Core10.Fence  ( createFence
                            , withFence
                            , destroyFence
                            , resetFences
                            , getFenceStatus
                            , waitForFences
                            , waitForFencesSafe
                            , FenceCreateInfo(..)
                            , Fence(..)
                            , FenceCreateFlagBits(..)
                            , FenceCreateFlags
                            ) where

import Vulkan.Internal.Utils (traceAroundEvent)
import Control.Exception.Base (bracket)
import Control.Monad (unless)
import Control.Monad.IO.Class (liftIO)
import Data.Typeable (eqT)
import Foreign.Marshal.Alloc (allocaBytes)
import Foreign.Marshal.Alloc (callocBytes)
import Foreign.Marshal.Alloc (free)
import GHC.Base (when)
import GHC.IO (throwIO)
import GHC.Ptr (castPtr)
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 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 Control.Monad.IO.Class (MonadIO)
import Data.Type.Equality ((:~:)(Refl))
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 (FunPtr)
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.Core10.FundamentalTypes (boolToBool32)
import Vulkan.CStruct.Extends (forgetExtensions)
import Vulkan.NamedType ((:::))
import Vulkan.Core10.AllocationCallbacks (AllocationCallbacks)
import Vulkan.Core10.FundamentalTypes (Bool32)
import Vulkan.Core10.FundamentalTypes (Bool32(..))
import Vulkan.CStruct.Extends (Chain)
import Vulkan.Core10.Handles (Device)
import Vulkan.Core10.Handles (Device(..))
import Vulkan.Core10.Handles (Device(Device))
import Vulkan.Dynamic (DeviceCmds(pVkCreateFence))
import Vulkan.Dynamic (DeviceCmds(pVkDestroyFence))
import Vulkan.Dynamic (DeviceCmds(pVkGetFenceStatus))
import Vulkan.Dynamic (DeviceCmds(pVkResetFences))
import Vulkan.Dynamic (DeviceCmds(pVkWaitForFences))
import Vulkan.Core10.Handles (Device_T)
import {-# SOURCE #-} Vulkan.Core11.Promoted_From_VK_KHR_external_fence (ExportFenceCreateInfo)
import {-# SOURCE #-} Vulkan.Extensions.VK_KHR_external_fence_win32 (ExportFenceWin32HandleInfoKHR)
import Vulkan.CStruct.Extends (Extends)
import Vulkan.CStruct.Extends (Extendss)
import Vulkan.CStruct.Extends (Extensible(..))
import Vulkan.Core10.Handles (Fence)
import Vulkan.Core10.Handles (Fence(..))
import Vulkan.Core10.Enums.FenceCreateFlagBits (FenceCreateFlags)
import Vulkan.CStruct.Extends (PeekChain)
import Vulkan.CStruct.Extends (PeekChain(..))
import Vulkan.CStruct.Extends (PokeChain)
import Vulkan.CStruct.Extends (PokeChain(..))
import Vulkan.Core10.Enums.Result (Result)
import Vulkan.Core10.Enums.Result (Result(..))
import Vulkan.CStruct.Extends (SomeStruct)
import Vulkan.Core10.Enums.StructureType (StructureType)
import Vulkan.Exception (VulkanException(..))
import Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_FENCE_CREATE_INFO))
import Vulkan.Core10.Enums.Result (Result(SUCCESS))
import Vulkan.Core10.Handles (Fence(..))
import Vulkan.Core10.Enums.FenceCreateFlagBits (FenceCreateFlagBits(..))
import Vulkan.Core10.Enums.FenceCreateFlagBits (FenceCreateFlags)
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkVkCreateFence
  :: FunPtr (Ptr Device_T -> Ptr (SomeStruct FenceCreateInfo) -> Ptr AllocationCallbacks -> Ptr Fence -> IO Result) -> Ptr Device_T -> Ptr (SomeStruct FenceCreateInfo) -> Ptr AllocationCallbacks -> Ptr Fence -> IO Result

-- | vkCreateFence - Create a new fence object
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-vkCreateFence-device-parameter# @device@ /must/ be a valid
--     'Vulkan.Core10.Handles.Device' handle
--
-- -   #VUID-vkCreateFence-pCreateInfo-parameter# @pCreateInfo@ /must/ be a
--     valid pointer to a valid 'FenceCreateInfo' structure
--
-- -   #VUID-vkCreateFence-pAllocator-parameter# If @pAllocator@ is not
--     @NULL@, @pAllocator@ /must/ be a valid pointer to a valid
--     'Vulkan.Core10.AllocationCallbacks.AllocationCallbacks' structure
--
-- -   #VUID-vkCreateFence-pFence-parameter# @pFence@ /must/ be a valid
--     pointer to a 'Vulkan.Core10.Handles.Fence' handle
--
-- == 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_OUT_OF_HOST_MEMORY'
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_OUT_OF_DEVICE_MEMORY'
--
-- = See Also
--
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_VERSION_1_0 VK_VERSION_1_0>,
-- 'Vulkan.Core10.AllocationCallbacks.AllocationCallbacks',
-- 'Vulkan.Core10.Handles.Device', 'Vulkan.Core10.Handles.Fence',
-- 'FenceCreateInfo'
createFence :: forall a io
             . (Extendss FenceCreateInfo a, PokeChain a, MonadIO io)
            => -- | @device@ is the logical device that creates the fence.
               Device
            -> -- | @pCreateInfo@ is a pointer to a 'FenceCreateInfo' structure containing
               -- information about how the fence is to be created.
               (FenceCreateInfo a)
            -> -- | @pAllocator@ controls host memory allocation as described in the
               -- <https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#memory-allocation Memory Allocation>
               -- chapter.
               ("allocator" ::: Maybe AllocationCallbacks)
            -> io (Fence)
createFence :: forall (a :: [*]) (io :: * -> *).
(Extendss FenceCreateInfo a, PokeChain a, MonadIO io) =>
Device
-> FenceCreateInfo a
-> ("allocator" ::: Maybe AllocationCallbacks)
-> io Fence
createFence Device
device FenceCreateInfo a
createInfo "allocator" ::: Maybe AllocationCallbacks
allocator = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT forall a b. (a -> b) -> a -> b
$ do
  let vkCreateFencePtr :: FunPtr
  (Ptr Device_T
   -> ("pCreateInfo" ::: Ptr (SomeStruct FenceCreateInfo))
   -> ("pAllocator" ::: Ptr AllocationCallbacks)
   -> ("pFence" ::: Ptr Fence)
   -> IO Result)
vkCreateFencePtr = DeviceCmds
-> FunPtr
     (Ptr Device_T
      -> ("pCreateInfo" ::: Ptr (SomeStruct FenceCreateInfo))
      -> ("pAllocator" ::: Ptr AllocationCallbacks)
      -> ("pFence" ::: Ptr Fence)
      -> IO Result)
pVkCreateFence (case Device
device of Device{DeviceCmds
$sel:deviceCmds:Device :: Device -> DeviceCmds
deviceCmds :: DeviceCmds
deviceCmds} -> DeviceCmds
deviceCmds)
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Device_T
   -> ("pCreateInfo" ::: Ptr (SomeStruct FenceCreateInfo))
   -> ("pAllocator" ::: Ptr AllocationCallbacks)
   -> ("pFence" ::: Ptr Fence)
   -> IO Result)
vkCreateFencePtr forall a. Eq a => a -> a -> Bool
/= forall a. FunPtr a
nullFunPtr) forall a b. (a -> b) -> a -> b
$
    forall e a. Exception e => e -> IO a
throwIO forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError forall a. Maybe a
Nothing IOErrorType
InvalidArgument String
"" String
"The function pointer for vkCreateFence is null" forall a. Maybe a
Nothing forall a. Maybe a
Nothing
  let vkCreateFence' :: Ptr Device_T
-> ("pCreateInfo" ::: Ptr (SomeStruct FenceCreateInfo))
-> ("pAllocator" ::: Ptr AllocationCallbacks)
-> ("pFence" ::: Ptr Fence)
-> IO Result
vkCreateFence' = FunPtr
  (Ptr Device_T
   -> ("pCreateInfo" ::: Ptr (SomeStruct FenceCreateInfo))
   -> ("pAllocator" ::: Ptr AllocationCallbacks)
   -> ("pFence" ::: Ptr Fence)
   -> IO Result)
-> Ptr Device_T
-> ("pCreateInfo" ::: Ptr (SomeStruct FenceCreateInfo))
-> ("pAllocator" ::: Ptr AllocationCallbacks)
-> ("pFence" ::: Ptr Fence)
-> IO Result
mkVkCreateFence FunPtr
  (Ptr Device_T
   -> ("pCreateInfo" ::: Ptr (SomeStruct FenceCreateInfo))
   -> ("pAllocator" ::: Ptr AllocationCallbacks)
   -> ("pFence" ::: Ptr Fence)
   -> IO Result)
vkCreateFencePtr
  Ptr (FenceCreateInfo a)
pCreateInfo <- forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (FenceCreateInfo a
createInfo)
  "pAllocator" ::: Ptr AllocationCallbacks
pAllocator <- case ("allocator" ::: Maybe AllocationCallbacks
allocator) of
    "allocator" ::: Maybe AllocationCallbacks
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Ptr a
nullPtr
    Just AllocationCallbacks
j -> forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (AllocationCallbacks
j)
  "pFence" ::: Ptr Fence
pPFence <- forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (forall a. Int -> IO (Ptr a)
callocBytes @Fence Int
8) forall a. Ptr a -> IO ()
free
  Result
r <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. String -> IO a -> IO a
traceAroundEvent String
"vkCreateFence" (Ptr Device_T
-> ("pCreateInfo" ::: Ptr (SomeStruct FenceCreateInfo))
-> ("pAllocator" ::: Ptr AllocationCallbacks)
-> ("pFence" ::: Ptr Fence)
-> IO Result
vkCreateFence'
                                                  (Device -> Ptr Device_T
deviceHandle (Device
device))
                                                  (forall (a :: [*] -> *) (es :: [*]).
Ptr (a es) -> Ptr (SomeStruct a)
forgetExtensions Ptr (FenceCreateInfo a)
pCreateInfo)
                                                  "pAllocator" ::: Ptr AllocationCallbacks
pAllocator
                                                  ("pFence" ::: Ptr Fence
pPFence))
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  Fence
pFence <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> IO a
peek @Fence "pFence" ::: Ptr Fence
pPFence
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ (Fence
pFence)

-- | A convenience wrapper to make a compatible pair of calls to
-- 'createFence' and 'destroyFence'
--
-- To ensure that 'destroyFence' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the last argument.
-- To just extract the pair pass '(,)' as the last argument.
--
withFence :: forall a io r . (Extendss FenceCreateInfo a, PokeChain a, MonadIO io) => Device -> FenceCreateInfo a -> Maybe AllocationCallbacks -> (io Fence -> (Fence -> io ()) -> r) -> r
withFence :: forall (a :: [*]) (io :: * -> *) r.
(Extendss FenceCreateInfo a, PokeChain a, MonadIO io) =>
Device
-> FenceCreateInfo a
-> ("allocator" ::: Maybe AllocationCallbacks)
-> (io Fence -> (Fence -> io ()) -> r)
-> r
withFence Device
device FenceCreateInfo a
pCreateInfo "allocator" ::: Maybe AllocationCallbacks
pAllocator io Fence -> (Fence -> io ()) -> r
b =
  io Fence -> (Fence -> io ()) -> r
b (forall (a :: [*]) (io :: * -> *).
(Extendss FenceCreateInfo a, PokeChain a, MonadIO io) =>
Device
-> FenceCreateInfo a
-> ("allocator" ::: Maybe AllocationCallbacks)
-> io Fence
createFence Device
device FenceCreateInfo a
pCreateInfo "allocator" ::: Maybe AllocationCallbacks
pAllocator)
    (\(Fence
o0) -> forall (io :: * -> *).
MonadIO io =>
Device
-> Fence -> ("allocator" ::: Maybe AllocationCallbacks) -> io ()
destroyFence Device
device Fence
o0 "allocator" ::: Maybe AllocationCallbacks
pAllocator)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkVkDestroyFence
  :: FunPtr (Ptr Device_T -> Fence -> Ptr AllocationCallbacks -> IO ()) -> Ptr Device_T -> Fence -> Ptr AllocationCallbacks -> IO ()

-- | vkDestroyFence - Destroy a fence object
--
-- == Valid Usage
--
-- -   #VUID-vkDestroyFence-fence-01120# All
--     <https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#devsandqueues-submission queue submission>
--     commands that refer to @fence@ /must/ have completed execution
--
-- -   #VUID-vkDestroyFence-fence-01121# If
--     'Vulkan.Core10.AllocationCallbacks.AllocationCallbacks' were
--     provided when @fence@ was created, a compatible set of callbacks
--     /must/ be provided here
--
-- -   #VUID-vkDestroyFence-fence-01122# If no
--     'Vulkan.Core10.AllocationCallbacks.AllocationCallbacks' were
--     provided when @fence@ was created, @pAllocator@ /must/ be @NULL@
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-vkDestroyFence-device-parameter# @device@ /must/ be a valid
--     'Vulkan.Core10.Handles.Device' handle
--
-- -   #VUID-vkDestroyFence-fence-parameter# If @fence@ is not
--     'Vulkan.Core10.APIConstants.NULL_HANDLE', @fence@ /must/ be a valid
--     'Vulkan.Core10.Handles.Fence' handle
--
-- -   #VUID-vkDestroyFence-pAllocator-parameter# If @pAllocator@ is not
--     @NULL@, @pAllocator@ /must/ be a valid pointer to a valid
--     'Vulkan.Core10.AllocationCallbacks.AllocationCallbacks' structure
--
-- -   #VUID-vkDestroyFence-fence-parent# If @fence@ is a valid handle, it
--     /must/ have been created, allocated, or retrieved from @device@
--
-- == Host Synchronization
--
-- -   Host access to @fence@ /must/ be externally synchronized
--
-- = See Also
--
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_VERSION_1_0 VK_VERSION_1_0>,
-- 'Vulkan.Core10.AllocationCallbacks.AllocationCallbacks',
-- 'Vulkan.Core10.Handles.Device', 'Vulkan.Core10.Handles.Fence'
destroyFence :: forall io
              . (MonadIO io)
             => -- | @device@ is the logical device that destroys the fence.
                Device
             -> -- | @fence@ is the handle of the fence to destroy.
                Fence
             -> -- | @pAllocator@ controls host memory allocation as described in the
                -- <https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#memory-allocation Memory Allocation>
                -- chapter.
                ("allocator" ::: Maybe AllocationCallbacks)
             -> io ()
destroyFence :: forall (io :: * -> *).
MonadIO io =>
Device
-> Fence -> ("allocator" ::: Maybe AllocationCallbacks) -> io ()
destroyFence Device
device Fence
fence "allocator" ::: Maybe AllocationCallbacks
allocator = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT forall a b. (a -> b) -> a -> b
$ do
  let vkDestroyFencePtr :: FunPtr
  (Ptr Device_T
   -> Fence -> ("pAllocator" ::: Ptr AllocationCallbacks) -> IO ())
vkDestroyFencePtr = DeviceCmds
-> FunPtr
     (Ptr Device_T
      -> Fence -> ("pAllocator" ::: Ptr AllocationCallbacks) -> IO ())
pVkDestroyFence (case Device
device of Device{DeviceCmds
deviceCmds :: DeviceCmds
$sel:deviceCmds:Device :: Device -> DeviceCmds
deviceCmds} -> DeviceCmds
deviceCmds)
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Device_T
   -> Fence -> ("pAllocator" ::: Ptr AllocationCallbacks) -> IO ())
vkDestroyFencePtr forall a. Eq a => a -> a -> Bool
/= forall a. FunPtr a
nullFunPtr) forall a b. (a -> b) -> a -> b
$
    forall e a. Exception e => e -> IO a
throwIO forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError forall a. Maybe a
Nothing IOErrorType
InvalidArgument String
"" String
"The function pointer for vkDestroyFence is null" forall a. Maybe a
Nothing forall a. Maybe a
Nothing
  let vkDestroyFence' :: Ptr Device_T
-> Fence -> ("pAllocator" ::: Ptr AllocationCallbacks) -> IO ()
vkDestroyFence' = FunPtr
  (Ptr Device_T
   -> Fence -> ("pAllocator" ::: Ptr AllocationCallbacks) -> IO ())
-> Ptr Device_T
-> Fence
-> ("pAllocator" ::: Ptr AllocationCallbacks)
-> IO ()
mkVkDestroyFence FunPtr
  (Ptr Device_T
   -> Fence -> ("pAllocator" ::: Ptr AllocationCallbacks) -> IO ())
vkDestroyFencePtr
  "pAllocator" ::: Ptr AllocationCallbacks
pAllocator <- case ("allocator" ::: Maybe AllocationCallbacks
allocator) of
    "allocator" ::: Maybe AllocationCallbacks
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Ptr a
nullPtr
    Just AllocationCallbacks
j -> forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (AllocationCallbacks
j)
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. String -> IO a -> IO a
traceAroundEvent String
"vkDestroyFence" (Ptr Device_T
-> Fence -> ("pAllocator" ::: Ptr AllocationCallbacks) -> IO ()
vkDestroyFence'
                                              (Device -> Ptr Device_T
deviceHandle (Device
device))
                                              (Fence
fence)
                                              "pAllocator" ::: Ptr AllocationCallbacks
pAllocator)
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkVkResetFences
  :: FunPtr (Ptr Device_T -> Word32 -> Ptr Fence -> IO Result) -> Ptr Device_T -> Word32 -> Ptr Fence -> IO Result

-- | vkResetFences - Resets one or more fence objects
--
-- = Description
--
-- If any member of @pFences@ currently has its
-- <https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#synchronization-fences-importing payload imported>
-- with temporary permanence, that fence’s prior permanent payload is first
-- restored. The remaining operations described therefore operate on the
-- restored payload.
--
-- When 'resetFences' is executed on the host, it defines a /fence unsignal
-- operation/ for each fence, which resets the fence to the unsignaled
-- state.
--
-- If any member of @pFences@ is already in the unsignaled state when
-- 'resetFences' is executed, then 'resetFences' has no effect on that
-- fence.
--
-- == Valid Usage
--
-- -   #VUID-vkResetFences-pFences-01123# Each element of @pFences@ /must/
--     not be currently associated with any queue command that has not yet
--     completed execution on that queue
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-vkResetFences-device-parameter# @device@ /must/ be a valid
--     'Vulkan.Core10.Handles.Device' handle
--
-- -   #VUID-vkResetFences-pFences-parameter# @pFences@ /must/ be a valid
--     pointer to an array of @fenceCount@ valid
--     'Vulkan.Core10.Handles.Fence' handles
--
-- -   #VUID-vkResetFences-fenceCount-arraylength# @fenceCount@ /must/ be
--     greater than @0@
--
-- -   #VUID-vkResetFences-pFences-parent# Each element of @pFences@ /must/
--     have been created, allocated, or retrieved from @device@
--
-- == Host Synchronization
--
-- -   Host access to each member of @pFences@ /must/ be externally
--     synchronized
--
-- == 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_OUT_OF_DEVICE_MEMORY'
--
-- = See Also
--
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_VERSION_1_0 VK_VERSION_1_0>,
-- 'Vulkan.Core10.Handles.Device', 'Vulkan.Core10.Handles.Fence'
resetFences :: forall io
             . (MonadIO io)
            => -- | @device@ is the logical device that owns the fences.
               Device
            -> -- | @pFences@ is a pointer to an array of fence handles to reset.
               ("fences" ::: Vector Fence)
            -> io ()
resetFences :: forall (io :: * -> *).
MonadIO io =>
Device -> ("fences" ::: Vector Fence) -> io ()
resetFences Device
device "fences" ::: Vector Fence
fences = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT forall a b. (a -> b) -> a -> b
$ do
  let vkResetFencesPtr :: FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> IO Result)
vkResetFencesPtr = DeviceCmds
-> FunPtr
     (Ptr Device_T
      -> ("fenceCount" ::: Word32)
      -> ("pFence" ::: Ptr Fence)
      -> IO Result)
pVkResetFences (case Device
device of Device{DeviceCmds
deviceCmds :: DeviceCmds
$sel:deviceCmds:Device :: Device -> DeviceCmds
deviceCmds} -> DeviceCmds
deviceCmds)
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> IO Result)
vkResetFencesPtr forall a. Eq a => a -> a -> Bool
/= forall a. FunPtr a
nullFunPtr) forall a b. (a -> b) -> a -> b
$
    forall e a. Exception e => e -> IO a
throwIO forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError forall a. Maybe a
Nothing IOErrorType
InvalidArgument String
"" String
"The function pointer for vkResetFences is null" forall a. Maybe a
Nothing forall a. Maybe a
Nothing
  let vkResetFences' :: Ptr Device_T
-> ("fenceCount" ::: Word32)
-> ("pFence" ::: Ptr Fence)
-> IO Result
vkResetFences' = FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> IO Result)
-> Ptr Device_T
-> ("fenceCount" ::: Word32)
-> ("pFence" ::: Ptr Fence)
-> IO Result
mkVkResetFences FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> IO Result)
vkResetFencesPtr
  "pFence" ::: Ptr Fence
pPFences <- forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes @Fence ((forall a. Vector a -> Int
Data.Vector.length ("fences" ::: Vector Fence
fences)) forall a. Num a => a -> a -> a
* Int
8)
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\Int
i Fence
e -> forall a. Storable a => Ptr a -> a -> IO ()
poke ("pFence" ::: Ptr Fence
pPFences forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
8 forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Fence) (Fence
e)) ("fences" ::: Vector Fence
fences)
  Result
r <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. String -> IO a -> IO a
traceAroundEvent String
"vkResetFences" (Ptr Device_T
-> ("fenceCount" ::: Word32)
-> ("pFence" ::: Ptr Fence)
-> IO Result
vkResetFences'
                                                  (Device -> Ptr Device_T
deviceHandle (Device
device))
                                                  ((forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Vector a -> Int
Data.Vector.length forall a b. (a -> b) -> a -> b
$ ("fences" ::: Vector Fence
fences)) :: Word32))
                                                  ("pFence" ::: Ptr Fence
pPFences))
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkVkGetFenceStatus
  :: FunPtr (Ptr Device_T -> Fence -> IO Result) -> Ptr Device_T -> Fence -> IO Result

-- | vkGetFenceStatus - Return the status of a fence
--
-- = Description
--
-- Upon success, 'getFenceStatus' returns the status of the fence object,
-- with the following return codes:
--
-- +------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
-- | Status                                         | Meaning                                                                                                            |
-- +================================================+====================================================================================================================+
-- | 'Vulkan.Core10.Enums.Result.SUCCESS'           | The fence specified by @fence@ is signaled.                                                                        |
-- +------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
-- | 'Vulkan.Core10.Enums.Result.NOT_READY'         | The fence specified by @fence@ is unsignaled.                                                                      |
-- +------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
-- | 'Vulkan.Core10.Enums.Result.ERROR_DEVICE_LOST' | The device has been lost. See                                                                                      |
-- |                                                | <https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#devsandqueues-lost-device Lost Device>. |
-- +------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
--
-- Fence Object Status Codes
--
-- If a
-- <https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#devsandqueues-submission queue submission>
-- command is pending execution, then the value returned by this command
-- /may/ immediately be out of date.
--
-- If the device has been lost (see
-- <https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#devsandqueues-lost-device Lost Device>),
-- 'getFenceStatus' /may/ return any of the above status codes. If the
-- device has been lost and 'getFenceStatus' is called repeatedly, it will
-- eventually return either 'Vulkan.Core10.Enums.Result.SUCCESS' or
-- 'Vulkan.Core10.Enums.Result.ERROR_DEVICE_LOST'.
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-successcodes Success>]
--
--     -   'Vulkan.Core10.Enums.Result.SUCCESS'
--
--     -   'Vulkan.Core10.Enums.Result.NOT_READY'
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-errorcodes Failure>]
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_OUT_OF_HOST_MEMORY'
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_OUT_OF_DEVICE_MEMORY'
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_DEVICE_LOST'
--
-- = See Also
--
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_VERSION_1_0 VK_VERSION_1_0>,
-- 'Vulkan.Core10.Handles.Device', 'Vulkan.Core10.Handles.Fence'
getFenceStatus :: forall io
                . (MonadIO io)
               => -- | @device@ is the logical device that owns the fence.
                  --
                  -- #VUID-vkGetFenceStatus-device-parameter# @device@ /must/ be a valid
                  -- 'Vulkan.Core10.Handles.Device' handle
                  Device
               -> -- | @fence@ is the handle of the fence to query.
                  --
                  -- #VUID-vkGetFenceStatus-fence-parameter# @fence@ /must/ be a valid
                  -- 'Vulkan.Core10.Handles.Fence' handle
                  --
                  -- #VUID-vkGetFenceStatus-fence-parent# @fence@ /must/ have been created,
                  -- allocated, or retrieved from @device@
                  Fence
               -> io (Result)
getFenceStatus :: forall (io :: * -> *). MonadIO io => Device -> Fence -> io Result
getFenceStatus Device
device Fence
fence = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
  let vkGetFenceStatusPtr :: FunPtr (Ptr Device_T -> Fence -> IO Result)
vkGetFenceStatusPtr = DeviceCmds -> FunPtr (Ptr Device_T -> Fence -> IO Result)
pVkGetFenceStatus (case Device
device of Device{DeviceCmds
deviceCmds :: DeviceCmds
$sel:deviceCmds:Device :: Device -> DeviceCmds
deviceCmds} -> DeviceCmds
deviceCmds)
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr (Ptr Device_T -> Fence -> IO Result)
vkGetFenceStatusPtr forall a. Eq a => a -> a -> Bool
/= forall a. FunPtr a
nullFunPtr) forall a b. (a -> b) -> a -> b
$
    forall e a. Exception e => e -> IO a
throwIO forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError forall a. Maybe a
Nothing IOErrorType
InvalidArgument String
"" String
"The function pointer for vkGetFenceStatus is null" forall a. Maybe a
Nothing forall a. Maybe a
Nothing
  let vkGetFenceStatus' :: Ptr Device_T -> Fence -> IO Result
vkGetFenceStatus' = FunPtr (Ptr Device_T -> Fence -> IO Result)
-> Ptr Device_T -> Fence -> IO Result
mkVkGetFenceStatus FunPtr (Ptr Device_T -> Fence -> IO Result)
vkGetFenceStatusPtr
  Result
r <- forall a. String -> IO a -> IO a
traceAroundEvent String
"vkGetFenceStatus" (Ptr Device_T -> Fence -> IO Result
vkGetFenceStatus'
                                              (Device -> Ptr Device_T
deviceHandle (Device
device))
                                              (Fence
fence))
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ (Result
r)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkVkWaitForFencesUnsafe
  :: FunPtr (Ptr Device_T -> Word32 -> Ptr Fence -> Bool32 -> Word64 -> IO Result) -> Ptr Device_T -> Word32 -> Ptr Fence -> Bool32 -> Word64 -> IO Result

foreign import ccall
  "dynamic" mkVkWaitForFencesSafe
  :: FunPtr (Ptr Device_T -> Word32 -> Ptr Fence -> Bool32 -> Word64 -> IO Result) -> Ptr Device_T -> Word32 -> Ptr Fence -> Bool32 -> Word64 -> IO Result

-- | waitForFences with selectable safeness
waitForFencesSafeOrUnsafe :: forall io
                           . (MonadIO io)
                          => (FunPtr (Ptr Device_T -> Word32 -> Ptr Fence -> Bool32 -> Word64 -> IO Result) -> Ptr Device_T -> Word32 -> Ptr Fence -> Bool32 -> Word64 -> IO Result)
                          -> -- | @device@ is the logical device that owns the fences.
                             Device
                          -> -- | @pFences@ is a pointer to an array of @fenceCount@ fence handles.
                             ("fences" ::: Vector Fence)
                          -> -- | @waitAll@ is the condition that /must/ be satisfied to successfully
                             -- unblock the wait. If @waitAll@ is 'Vulkan.Core10.FundamentalTypes.TRUE',
                             -- then the condition is that all fences in @pFences@ are signaled.
                             -- Otherwise, the condition is that at least one fence in @pFences@ is
                             -- signaled.
                             ("waitAll" ::: Bool)
                          -> -- | @timeout@ is the timeout period in units of nanoseconds. @timeout@ is
                             -- adjusted to the closest value allowed by the implementation-dependent
                             -- timeout accuracy, which /may/ be substantially longer than one
                             -- nanosecond, and /may/ be longer than the requested period.
                             ("timeout" ::: Word64)
                          -> io (Result)
waitForFencesSafeOrUnsafe :: forall (io :: * -> *).
MonadIO io =>
(FunPtr
   (Ptr Device_T
    -> ("fenceCount" ::: Word32)
    -> ("pFence" ::: Ptr Fence)
    -> Bool32
    -> Word64
    -> IO Result)
 -> Ptr Device_T
 -> ("fenceCount" ::: Word32)
 -> ("pFence" ::: Ptr Fence)
 -> Bool32
 -> Word64
 -> IO Result)
-> Device
-> ("fences" ::: Vector Fence)
-> Bool
-> Word64
-> io Result
waitForFencesSafeOrUnsafe FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> Bool32
   -> Word64
   -> IO Result)
-> Ptr Device_T
-> ("fenceCount" ::: Word32)
-> ("pFence" ::: Ptr Fence)
-> Bool32
-> Word64
-> IO Result
mkVkWaitForFences Device
device
                                              "fences" ::: Vector Fence
fences
                                              Bool
waitAll
                                              Word64
timeout = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT forall a b. (a -> b) -> a -> b
$ do
  let vkWaitForFencesPtr :: FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> Bool32
   -> Word64
   -> IO Result)
vkWaitForFencesPtr = DeviceCmds
-> FunPtr
     (Ptr Device_T
      -> ("fenceCount" ::: Word32)
      -> ("pFence" ::: Ptr Fence)
      -> Bool32
      -> Word64
      -> IO Result)
pVkWaitForFences (case Device
device of Device{DeviceCmds
deviceCmds :: DeviceCmds
$sel:deviceCmds:Device :: Device -> DeviceCmds
deviceCmds} -> DeviceCmds
deviceCmds)
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> Bool32
   -> Word64
   -> IO Result)
vkWaitForFencesPtr forall a. Eq a => a -> a -> Bool
/= forall a. FunPtr a
nullFunPtr) forall a b. (a -> b) -> a -> b
$
    forall e a. Exception e => e -> IO a
throwIO forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError forall a. Maybe a
Nothing IOErrorType
InvalidArgument String
"" String
"The function pointer for vkWaitForFences is null" forall a. Maybe a
Nothing forall a. Maybe a
Nothing
  let vkWaitForFences' :: Ptr Device_T
-> ("fenceCount" ::: Word32)
-> ("pFence" ::: Ptr Fence)
-> Bool32
-> Word64
-> IO Result
vkWaitForFences' = FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> Bool32
   -> Word64
   -> IO Result)
-> Ptr Device_T
-> ("fenceCount" ::: Word32)
-> ("pFence" ::: Ptr Fence)
-> Bool32
-> Word64
-> IO Result
mkVkWaitForFences FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> Bool32
   -> Word64
   -> IO Result)
vkWaitForFencesPtr
  "pFence" ::: Ptr Fence
pPFences <- forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes @Fence ((forall a. Vector a -> Int
Data.Vector.length ("fences" ::: Vector Fence
fences)) forall a. Num a => a -> a -> a
* Int
8)
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\Int
i Fence
e -> forall a. Storable a => Ptr a -> a -> IO ()
poke ("pFence" ::: Ptr Fence
pPFences forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
8 forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Fence) (Fence
e)) ("fences" ::: Vector Fence
fences)
  Result
r <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. String -> IO a -> IO a
traceAroundEvent String
"vkWaitForFences" (Ptr Device_T
-> ("fenceCount" ::: Word32)
-> ("pFence" ::: Ptr Fence)
-> Bool32
-> Word64
-> IO Result
vkWaitForFences'
                                                    (Device -> Ptr Device_T
deviceHandle (Device
device))
                                                    ((forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Vector a -> Int
Data.Vector.length forall a b. (a -> b) -> a -> b
$ ("fences" ::: Vector Fence
fences)) :: Word32))
                                                    ("pFence" ::: Ptr Fence
pPFences)
                                                    (Bool -> Bool32
boolToBool32 (Bool
waitAll))
                                                    (Word64
timeout))
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ (Result
r)

-- | vkWaitForFences - Wait for one or more fences to become signaled
--
-- = Description
--
-- If the condition is satisfied when 'waitForFences' is called, then
-- 'waitForFences' returns immediately. If the condition is not satisfied
-- at the time 'waitForFences' is called, then 'waitForFences' will block
-- and wait until the condition is satisfied or the @timeout@ has expired,
-- whichever is sooner.
--
-- If @timeout@ is zero, then 'waitForFences' does not wait, but simply
-- returns the current state of the fences.
-- 'Vulkan.Core10.Enums.Result.TIMEOUT' will be returned in this case if
-- the condition is not satisfied, even though no actual wait was
-- performed.
--
-- If the condition is satisfied before the @timeout@ has expired,
-- 'waitForFences' returns 'Vulkan.Core10.Enums.Result.SUCCESS'. Otherwise,
-- 'waitForFences' returns 'Vulkan.Core10.Enums.Result.TIMEOUT' after the
-- @timeout@ has expired.
--
-- If device loss occurs (see
-- <https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#devsandqueues-lost-device Lost Device>)
-- before the timeout has expired, 'waitForFences' /must/ return in finite
-- time with either 'Vulkan.Core10.Enums.Result.SUCCESS' or
-- 'Vulkan.Core10.Enums.Result.ERROR_DEVICE_LOST'.
--
-- Note
--
-- While we guarantee that 'waitForFences' /must/ return in finite time, no
-- guarantees are made that it returns immediately upon device loss.
-- However, the client can reasonably expect that the delay will be on the
-- order of seconds and that calling 'waitForFences' will not result in a
-- permanently (or seemingly permanently) dead process.
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-vkWaitForFences-device-parameter# @device@ /must/ be a valid
--     'Vulkan.Core10.Handles.Device' handle
--
-- -   #VUID-vkWaitForFences-pFences-parameter# @pFences@ /must/ be a valid
--     pointer to an array of @fenceCount@ valid
--     'Vulkan.Core10.Handles.Fence' handles
--
-- -   #VUID-vkWaitForFences-fenceCount-arraylength# @fenceCount@ /must/ be
--     greater than @0@
--
-- -   #VUID-vkWaitForFences-pFences-parent# Each element of @pFences@
--     /must/ have been created, allocated, or retrieved from @device@
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-successcodes Success>]
--
--     -   'Vulkan.Core10.Enums.Result.SUCCESS'
--
--     -   'Vulkan.Core10.Enums.Result.TIMEOUT'
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-errorcodes Failure>]
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_OUT_OF_HOST_MEMORY'
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_OUT_OF_DEVICE_MEMORY'
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_DEVICE_LOST'
--
-- = See Also
--
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_VERSION_1_0 VK_VERSION_1_0>,
-- 'Vulkan.Core10.FundamentalTypes.Bool32', 'Vulkan.Core10.Handles.Device',
-- 'Vulkan.Core10.Handles.Fence'
waitForFences :: forall io
               . (MonadIO io)
              => -- | @device@ is the logical device that owns the fences.
                 Device
              -> -- | @pFences@ is a pointer to an array of @fenceCount@ fence handles.
                 ("fences" ::: Vector Fence)
              -> -- | @waitAll@ is the condition that /must/ be satisfied to successfully
                 -- unblock the wait. If @waitAll@ is 'Vulkan.Core10.FundamentalTypes.TRUE',
                 -- then the condition is that all fences in @pFences@ are signaled.
                 -- Otherwise, the condition is that at least one fence in @pFences@ is
                 -- signaled.
                 ("waitAll" ::: Bool)
              -> -- | @timeout@ is the timeout period in units of nanoseconds. @timeout@ is
                 -- adjusted to the closest value allowed by the implementation-dependent
                 -- timeout accuracy, which /may/ be substantially longer than one
                 -- nanosecond, and /may/ be longer than the requested period.
                 ("timeout" ::: Word64)
              -> io (Result)
waitForFences :: forall (io :: * -> *).
MonadIO io =>
Device
-> ("fences" ::: Vector Fence) -> Bool -> Word64 -> io Result
waitForFences = forall (io :: * -> *).
MonadIO io =>
(FunPtr
   (Ptr Device_T
    -> ("fenceCount" ::: Word32)
    -> ("pFence" ::: Ptr Fence)
    -> Bool32
    -> Word64
    -> IO Result)
 -> Ptr Device_T
 -> ("fenceCount" ::: Word32)
 -> ("pFence" ::: Ptr Fence)
 -> Bool32
 -> Word64
 -> IO Result)
-> Device
-> ("fences" ::: Vector Fence)
-> Bool
-> Word64
-> io Result
waitForFencesSafeOrUnsafe FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> Bool32
   -> Word64
   -> IO Result)
-> Ptr Device_T
-> ("fenceCount" ::: Word32)
-> ("pFence" ::: Ptr Fence)
-> Bool32
-> Word64
-> IO Result
mkVkWaitForFencesUnsafe

-- | A variant of 'waitForFences' which makes a *safe* FFI call
waitForFencesSafe :: forall io
                   . (MonadIO io)
                  => -- | @device@ is the logical device that owns the fences.
                     Device
                  -> -- | @pFences@ is a pointer to an array of @fenceCount@ fence handles.
                     ("fences" ::: Vector Fence)
                  -> -- | @waitAll@ is the condition that /must/ be satisfied to successfully
                     -- unblock the wait. If @waitAll@ is 'Vulkan.Core10.FundamentalTypes.TRUE',
                     -- then the condition is that all fences in @pFences@ are signaled.
                     -- Otherwise, the condition is that at least one fence in @pFences@ is
                     -- signaled.
                     ("waitAll" ::: Bool)
                  -> -- | @timeout@ is the timeout period in units of nanoseconds. @timeout@ is
                     -- adjusted to the closest value allowed by the implementation-dependent
                     -- timeout accuracy, which /may/ be substantially longer than one
                     -- nanosecond, and /may/ be longer than the requested period.
                     ("timeout" ::: Word64)
                  -> io (Result)
waitForFencesSafe :: forall (io :: * -> *).
MonadIO io =>
Device
-> ("fences" ::: Vector Fence) -> Bool -> Word64 -> io Result
waitForFencesSafe = forall (io :: * -> *).
MonadIO io =>
(FunPtr
   (Ptr Device_T
    -> ("fenceCount" ::: Word32)
    -> ("pFence" ::: Ptr Fence)
    -> Bool32
    -> Word64
    -> IO Result)
 -> Ptr Device_T
 -> ("fenceCount" ::: Word32)
 -> ("pFence" ::: Ptr Fence)
 -> Bool32
 -> Word64
 -> IO Result)
-> Device
-> ("fences" ::: Vector Fence)
-> Bool
-> Word64
-> io Result
waitForFencesSafeOrUnsafe FunPtr
  (Ptr Device_T
   -> ("fenceCount" ::: Word32)
   -> ("pFence" ::: Ptr Fence)
   -> Bool32
   -> Word64
   -> IO Result)
-> Ptr Device_T
-> ("fenceCount" ::: Word32)
-> ("pFence" ::: Ptr Fence)
-> Bool32
-> Word64
-> IO Result
mkVkWaitForFencesSafe


-- | VkFenceCreateInfo - Structure specifying parameters of a newly created
-- fence
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-VkFenceCreateInfo-sType-sType# @sType@ /must/ be
--     'Vulkan.Core10.Enums.StructureType.STRUCTURE_TYPE_FENCE_CREATE_INFO'
--
-- -   #VUID-VkFenceCreateInfo-pNext-pNext# Each @pNext@ member of any
--     structure (including this one) in the @pNext@ chain /must/ be either
--     @NULL@ or a pointer to a valid instance of
--     'Vulkan.Core11.Promoted_From_VK_KHR_external_fence.ExportFenceCreateInfo'
--     or
--     'Vulkan.Extensions.VK_KHR_external_fence_win32.ExportFenceWin32HandleInfoKHR'
--
-- -   #VUID-VkFenceCreateInfo-sType-unique# The @sType@ value of each
--     struct in the @pNext@ chain /must/ be unique
--
-- -   #VUID-VkFenceCreateInfo-flags-parameter# @flags@ /must/ be a valid
--     combination of
--     'Vulkan.Core10.Enums.FenceCreateFlagBits.FenceCreateFlagBits' values
--
-- = See Also
--
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_VERSION_1_0 VK_VERSION_1_0>,
-- 'Vulkan.Core10.Enums.FenceCreateFlagBits.FenceCreateFlags',
-- 'Vulkan.Core10.Enums.StructureType.StructureType', 'createFence'
data FenceCreateInfo (es :: [Type]) = FenceCreateInfo
  { -- | @pNext@ is @NULL@ or a pointer to a structure extending this structure.
    forall (es :: [*]). FenceCreateInfo es -> Chain es
next :: Chain es
  , -- | @flags@ is a bitmask of
    -- 'Vulkan.Core10.Enums.FenceCreateFlagBits.FenceCreateFlagBits' specifying
    -- the initial state and behavior of the fence.
    forall (es :: [*]). FenceCreateInfo es -> FenceCreateFlags
flags :: FenceCreateFlags
  }
  deriving (Typeable)
#if defined(GENERIC_INSTANCES)
deriving instance Generic (FenceCreateInfo (es :: [Type]))
#endif
deriving instance Show (Chain es) => Show (FenceCreateInfo es)

instance Extensible FenceCreateInfo where
  extensibleTypeName :: String
extensibleTypeName = String
"FenceCreateInfo"
  setNext :: forall (ds :: [*]) (es :: [*]).
FenceCreateInfo ds -> Chain es -> FenceCreateInfo es
setNext FenceCreateInfo{Chain ds
FenceCreateFlags
flags :: FenceCreateFlags
next :: Chain ds
$sel:flags:FenceCreateInfo :: forall (es :: [*]). FenceCreateInfo es -> FenceCreateFlags
$sel:next:FenceCreateInfo :: forall (es :: [*]). FenceCreateInfo es -> Chain es
..} Chain es
next' = FenceCreateInfo{$sel:next:FenceCreateInfo :: Chain es
next = Chain es
next', FenceCreateFlags
flags :: FenceCreateFlags
$sel:flags:FenceCreateInfo :: FenceCreateFlags
..}
  getNext :: forall (es :: [*]). FenceCreateInfo es -> Chain es
getNext FenceCreateInfo{Chain es
FenceCreateFlags
flags :: FenceCreateFlags
next :: Chain es
$sel:flags:FenceCreateInfo :: forall (es :: [*]). FenceCreateInfo es -> FenceCreateFlags
$sel:next:FenceCreateInfo :: forall (es :: [*]). FenceCreateInfo es -> Chain es
..} = Chain es
next
  extends :: forall e b proxy. Typeable e => proxy e -> (Extends FenceCreateInfo e => b) -> Maybe b
  extends :: forall e b (proxy :: * -> *).
Typeable e =>
proxy e -> (Extends FenceCreateInfo e => b) -> Maybe b
extends proxy e
_ Extends FenceCreateInfo e => b
f
    | Just e :~: ExportFenceWin32HandleInfoKHR
Refl <- forall {k} (a :: k) (b :: k).
(Typeable a, Typeable b) =>
Maybe (a :~: b)
eqT @e @ExportFenceWin32HandleInfoKHR = forall a. a -> Maybe a
Just Extends FenceCreateInfo e => b
f
    | Just e :~: ExportFenceCreateInfo
Refl <- forall {k} (a :: k) (b :: k).
(Typeable a, Typeable b) =>
Maybe (a :~: b)
eqT @e @ExportFenceCreateInfo = forall a. a -> Maybe a
Just Extends FenceCreateInfo e => b
f
    | Bool
otherwise = forall a. Maybe a
Nothing

instance ( Extendss FenceCreateInfo es
         , PokeChain es ) => ToCStruct (FenceCreateInfo es) where
  withCStruct :: forall b.
FenceCreateInfo es -> (Ptr (FenceCreateInfo es) -> IO b) -> IO b
withCStruct FenceCreateInfo es
x Ptr (FenceCreateInfo es) -> IO b
f = forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes Int
24 forall a b. (a -> b) -> a -> b
$ \Ptr (FenceCreateInfo es)
p -> forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr (FenceCreateInfo es)
p FenceCreateInfo es
x (Ptr (FenceCreateInfo es) -> IO b
f Ptr (FenceCreateInfo es)
p)
  pokeCStruct :: forall b.
Ptr (FenceCreateInfo es) -> FenceCreateInfo es -> IO b -> IO b
pokeCStruct Ptr (FenceCreateInfo es)
p FenceCreateInfo{Chain es
FenceCreateFlags
flags :: FenceCreateFlags
next :: Chain es
$sel:flags:FenceCreateInfo :: forall (es :: [*]). FenceCreateInfo es -> FenceCreateFlags
$sel:next:FenceCreateInfo :: forall (es :: [*]). FenceCreateInfo es -> Chain es
..} IO b
f = forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT forall a b. (a -> b) -> a -> b
$ do
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr (FenceCreateInfo es)
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_FENCE_CREATE_INFO)
    Ptr ()
pNext'' <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. Ptr a -> Ptr b
castPtr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall (es :: [*]) a.
PokeChain es =>
Chain es -> (Ptr (Chain es) -> IO a) -> IO a
withChain (Chain es
next)
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr (FenceCreateInfo es)
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8 :: Ptr (Ptr ()))) Ptr ()
pNext''
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr (FenceCreateInfo es)
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16 :: Ptr FenceCreateFlags)) (FenceCreateFlags
flags)
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ IO b
f
  cStructSize :: Int
cStructSize = Int
24
  cStructAlignment :: Int
cStructAlignment = Int
8
  pokeZeroCStruct :: forall b. Ptr (FenceCreateInfo es) -> IO b -> IO b
pokeZeroCStruct Ptr (FenceCreateInfo es)
p IO b
f = forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT forall a b. (a -> b) -> a -> b
$ do
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr (FenceCreateInfo es)
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_FENCE_CREATE_INFO)
    Ptr ()
pNext' <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. Ptr a -> Ptr b
castPtr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall (es :: [*]) a.
PokeChain es =>
(Ptr (Chain es) -> IO a) -> IO a
withZeroChain @es
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr (FenceCreateInfo es)
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8 :: Ptr (Ptr ()))) Ptr ()
pNext'
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ IO b
f

instance ( Extendss FenceCreateInfo es
         , PeekChain es ) => FromCStruct (FenceCreateInfo es) where
  peekCStruct :: Ptr (FenceCreateInfo es) -> IO (FenceCreateInfo es)
peekCStruct Ptr (FenceCreateInfo es)
p = do
    Ptr ()
pNext <- forall a. Storable a => Ptr a -> IO a
peek @(Ptr ()) ((Ptr (FenceCreateInfo es)
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8 :: Ptr (Ptr ())))
    Chain es
next <- forall (es :: [*]). PeekChain es => Ptr (Chain es) -> IO (Chain es)
peekChain (forall a b. Ptr a -> Ptr b
castPtr Ptr ()
pNext)
    FenceCreateFlags
flags <- forall a. Storable a => Ptr a -> IO a
peek @FenceCreateFlags ((Ptr (FenceCreateInfo es)
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16 :: Ptr FenceCreateFlags))
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (es :: [*]).
Chain es -> FenceCreateFlags -> FenceCreateInfo es
FenceCreateInfo
             Chain es
next FenceCreateFlags
flags

instance es ~ '[] => Zero (FenceCreateInfo es) where
  zero :: FenceCreateInfo es
zero = forall (es :: [*]).
Chain es -> FenceCreateFlags -> FenceCreateInfo es
FenceCreateInfo
           ()
           forall a. Zero a => a
zero