{-# language CPP #-}
module VulkanMemoryAllocator  ( createAllocator
                              , withAllocator
                              , destroyAllocator
                              , getAllocatorInfo
                              , getPhysicalDeviceProperties
                              , getMemoryProperties
                              , getMemoryTypeProperties
                              , setCurrentFrameIndex
                              , calculateStats
                              , getBudget
                              , buildStatsString
                              , freeStatsString
                              , findMemoryTypeIndex
                              , findMemoryTypeIndexForBufferInfo
                              , findMemoryTypeIndexForImageInfo
                              , createPool
                              , withPool
                              , destroyPool
                              , getPoolStats
                              , makePoolAllocationsLost
                              , checkPoolCorruption
                              , getPoolName
                              , setPoolName
                              , allocateMemory
                              , withMemory
                              , allocateMemoryPages
                              , withMemoryPages
                              , allocateMemoryForBuffer
                              , withMemoryForBuffer
                              , allocateMemoryForImage
                              , withMemoryForImage
                              , freeMemory
                              , freeMemoryPages
                              , resizeAllocation
                              , getAllocationInfo
                              , touchAllocation
                              , setAllocationUserData
                              , createLostAllocation
                              , withLostAllocation
                              , mapMemory
                              , withMappedMemory
                              , unmapMemory
                              , flushAllocation
                              , invalidateAllocation
                              , flushAllocations
                              , invalidateAllocations
                              , checkCorruption
                              , defragmentationBegin
                              , withDefragmentation
                              , defragmentationEnd
                              , beginDefragmentationPass
                              , useDefragmentationPass
                              , endDefragmentationPass
                              , defragment
                              , bindBufferMemory
                              , bindBufferMemory2
                              , bindImageMemory
                              , bindImageMemory2
                              , createBuffer
                              , withBuffer
                              , destroyBuffer
                              , createImage
                              , withImage
                              , destroyImage
                              , Allocator(..)
                              , PFN_vmaAllocateDeviceMemoryFunction
                              , FN_vmaAllocateDeviceMemoryFunction
                              , PFN_vmaFreeDeviceMemoryFunction
                              , FN_vmaFreeDeviceMemoryFunction
                              , DeviceMemoryCallbacks(..)
                              , AllocatorCreateFlagBits( ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT
                                                       , ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT
                                                       , ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT
                                                       , ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT
                                                       , ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT
                                                       , ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT
                                                       , ..
                                                       )
                              , AllocatorCreateFlags
                              , VulkanFunctions(..)
                              , RecordFlagBits( RECORD_FLUSH_AFTER_CALL_BIT
                                              , ..
                                              )
                              , RecordFlags
                              , RecordSettings(..)
                              , AllocatorCreateInfo(..)
                              , AllocatorInfo(..)
                              , StatInfo(..)
                              , Stats(..)
                              , Budget(..)
                              , Pool(..)
                              , MemoryUsage( MEMORY_USAGE_UNKNOWN
                                           , MEMORY_USAGE_GPU_ONLY
                                           , MEMORY_USAGE_CPU_ONLY
                                           , MEMORY_USAGE_CPU_TO_GPU
                                           , MEMORY_USAGE_GPU_TO_CPU
                                           , MEMORY_USAGE_CPU_COPY
                                           , MEMORY_USAGE_GPU_LAZILY_ALLOCATED
                                           , ..
                                           )
                              , AllocationCreateFlagBits( ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
                                                        , ALLOCATION_CREATE_NEVER_ALLOCATE_BIT
                                                        , ALLOCATION_CREATE_MAPPED_BIT
                                                        , ALLOCATION_CREATE_CAN_BECOME_LOST_BIT
                                                        , ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT
                                                        , ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT
                                                        , ALLOCATION_CREATE_UPPER_ADDRESS_BIT
                                                        , ALLOCATION_CREATE_DONT_BIND_BIT
                                                        , ALLOCATION_CREATE_WITHIN_BUDGET_BIT
                                                        , ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT
                                                        , ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT
                                                        , ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT
                                                        , ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT
                                                        , ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT
                                                        , ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT
                                                        , ALLOCATION_CREATE_STRATEGY_MASK
                                                        , ..
                                                        )
                              , AllocationCreateFlags
                              , AllocationCreateInfo(..)
                              , PoolCreateFlagBits( POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT
                                                  , POOL_CREATE_LINEAR_ALGORITHM_BIT
                                                  , POOL_CREATE_BUDDY_ALGORITHM_BIT
                                                  , POOL_CREATE_ALGORITHM_MASK
                                                  , ..
                                                  )
                              , PoolCreateFlags
                              , PoolCreateInfo(..)
                              , PoolStats(..)
                              , Allocation(..)
                              , AllocationInfo(..)
                              , DefragmentationContext(..)
                              , DefragmentationFlagBits( DEFRAGMENTATION_FLAG_INCREMENTAL
                                                       , ..
                                                       )
                              , DefragmentationFlags
                              , DefragmentationInfo2(..)
                              , DefragmentationPassMoveInfo(..)
                              , DefragmentationPassInfo(..)
                              , DefragmentationInfo(..)
                              , DefragmentationStats(..)
                              ) where

import Vulkan (AllocationCallbacks)
import Vulkan (BindBufferMemoryInfo)
import Vulkan (BindImageMemoryInfo)
import Vulkan (Bool32)
import Vulkan (Buffer)
import Vulkan (BufferCopy)
import Vulkan (BufferCreateInfo)
import Vulkan (BufferMemoryRequirementsInfo2)
import Vulkan (CommandBuffer_T)
import Vulkan (DeviceMemory)
import Vulkan (DeviceSize)
import Vulkan (Device_T)
import Vulkan (Flags)
import Vulkan (Image)
import Vulkan (ImageCreateInfo)
import Vulkan (ImageMemoryRequirementsInfo2)
import Vulkan (Instance_T)
import Vulkan (MappedMemoryRange)
import Vulkan (MemoryAllocateInfo)
import Vulkan (MemoryMapFlags)
import Vulkan (MemoryPropertyFlags)
import Vulkan (MemoryRequirements)
import Vulkan (MemoryRequirements2)
import Vulkan (PhysicalDeviceMemoryProperties)
import Vulkan (PhysicalDeviceMemoryProperties2)
import Vulkan (PhysicalDeviceProperties)
import Vulkan (PhysicalDevice_T)
import Vulkan (Result)
import Vulkan.CStruct.Utils (FixedArray)
import Vulkan.CStruct.Extends (forgetExtensions)
import Vulkan.CStruct.Utils (advancePtrBytes)
import Vulkan.CStruct.Utils (lowerArrayPtr)
import Vulkan.Core10.FundamentalTypes (bool32ToBool)
import Vulkan.Core10.FundamentalTypes (boolToBool32)
import Control.Exception.Base (bracket)
import Control.Monad (unless)
import Control.Monad.IO.Class (liftIO)
import Foreign.Marshal.Alloc (allocaBytesAligned)
import Foreign.Marshal.Alloc (callocBytes)
import Foreign.Marshal.Alloc (free)
import Foreign.Marshal.Utils (maybePeek)
import GHC.Base (when)
import GHC.IO (throwIO)
import Foreign.Ptr (nullPtr)
import Foreign.Ptr (plusPtr)
import GHC.Read (choose)
import GHC.Read (expectP)
import GHC.Read (parens)
import GHC.Show (showParen)
import GHC.Show (showString)
import GHC.Show (showsPrec)
import Numeric (showHex)
import Text.ParserCombinators.ReadPrec ((+++))
import Text.ParserCombinators.ReadPrec (prec)
import Text.ParserCombinators.ReadPrec (step)
import Data.ByteString (packCString)
import Data.ByteString (useAsCString)
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 qualified Data.Vector (null)
import Vulkan.Core10.APIConstants (pattern MAX_MEMORY_HEAPS)
import Vulkan.Core10.APIConstants (pattern MAX_MEMORY_TYPES)
import Vulkan.Core10.Enums.Result (pattern SUCCESS)
import Foreign.C.Types (CChar(..))
import Foreign.C.Types (CSize(..))
import Vulkan (Bool32(..))
import Vulkan (Buffer(..))
import Vulkan (Image(..))
import Vulkan (MemoryPropertyFlagBits(..))
import Vulkan (Result(..))
import Vulkan.CStruct (FromCStruct)
import Vulkan.CStruct (FromCStruct(..))
import Vulkan.CStruct (ToCStruct)
import Vulkan.CStruct (ToCStruct(..))
import Vulkan.CStruct.Extends (Extendss)
import Vulkan.CStruct.Extends (PokeChain)
import Vulkan.CStruct.Extends (SomeStruct)
import Vulkan.Core10.APIConstants (IsHandle)
import Vulkan.Core10.APIConstants (MAX_MEMORY_HEAPS)
import Vulkan.Core10.APIConstants (MAX_MEMORY_TYPES)
import Vulkan.Exception (VulkanException(..))
import Vulkan.NamedType ((:::))
import Vulkan.Zero (Zero)
import Vulkan.Zero (Zero(..))
import Control.Monad.IO.Class (MonadIO)
import Data.Bits (Bits)
import Data.Typeable (Typeable)
import Foreign.C.Types (CChar)
import Foreign.C.Types (CSize)
import Foreign.C.Types (CSize(CSize))
import Foreign.Storable (Storable)
import Foreign.Storable (Storable(peek))
import Foreign.Storable (Storable(poke))
import qualified Foreign.Storable (Storable(..))
import GHC.Generics (Generic)
import GHC.IO.Exception (IOErrorType(..))
import GHC.IO.Exception (IOException(..))
import Data.Int (Int32)
import Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import GHC.Read (Read(readPrec))
import Data.Word (Word32)
import Data.Word (Word64)
import Text.Read.Lex (Lexeme(Ident))
import Data.ByteString (ByteString)
import Data.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import Data.Vector (Vector)

foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaCreateAllocator" ffiVmaCreateAllocator
  :: Ptr AllocatorCreateInfo -> Ptr Allocator -> IO Result

-- | Creates Allocator object.
createAllocator :: forall io
                 . (MonadIO io)
                => -- No documentation found for Nested "vmaCreateAllocator" "pCreateInfo"
                   AllocatorCreateInfo
                -> io (Allocator)
createAllocator :: AllocatorCreateInfo -> io Allocator
createAllocator createInfo :: AllocatorCreateInfo
createInfo = IO Allocator -> io Allocator
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Allocator -> io Allocator)
-> (ContT Allocator IO Allocator -> IO Allocator)
-> ContT Allocator IO Allocator
-> io Allocator
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT Allocator IO Allocator -> IO Allocator
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT Allocator IO Allocator -> io Allocator)
-> ContT Allocator IO Allocator -> io Allocator
forall a b. (a -> b) -> a -> b
$ do
  Ptr AllocatorCreateInfo
pCreateInfo <- ((Ptr AllocatorCreateInfo -> IO Allocator) -> IO Allocator)
-> ContT Allocator IO (Ptr AllocatorCreateInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr AllocatorCreateInfo -> IO Allocator) -> IO Allocator)
 -> ContT Allocator IO (Ptr AllocatorCreateInfo))
-> ((Ptr AllocatorCreateInfo -> IO Allocator) -> IO Allocator)
-> ContT Allocator IO (Ptr AllocatorCreateInfo)
forall a b. (a -> b) -> a -> b
$ AllocatorCreateInfo
-> (Ptr AllocatorCreateInfo -> IO Allocator) -> IO Allocator
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (AllocatorCreateInfo
createInfo)
  Ptr Allocator
pPAllocator <- ((Ptr Allocator -> IO Allocator) -> IO Allocator)
-> ContT Allocator IO (Ptr Allocator)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocator -> IO Allocator) -> IO Allocator)
 -> ContT Allocator IO (Ptr Allocator))
-> ((Ptr Allocator -> IO Allocator) -> IO Allocator)
-> ContT Allocator IO (Ptr Allocator)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Allocator)
-> (Ptr Allocator -> IO ())
-> (Ptr Allocator -> IO Allocator)
-> IO Allocator
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Allocator)
forall a. Int -> IO (Ptr a)
callocBytes @Allocator 8) Ptr Allocator -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT Allocator IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT Allocator IO Result)
-> IO Result -> ContT Allocator IO Result
forall a b. (a -> b) -> a -> b
$ (Ptr AllocatorCreateInfo -> Ptr Allocator -> IO Result
ffiVmaCreateAllocator) Ptr AllocatorCreateInfo
pCreateInfo (Ptr Allocator
pPAllocator)
  IO () -> ContT Allocator IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Allocator IO ()) -> IO () -> ContT Allocator IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  Allocator
pAllocator <- IO Allocator -> ContT Allocator IO Allocator
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Allocator -> ContT Allocator IO Allocator)
-> IO Allocator -> ContT Allocator IO Allocator
forall a b. (a -> b) -> a -> b
$ Ptr Allocator -> IO Allocator
forall a. Storable a => Ptr a -> IO a
peek @Allocator Ptr Allocator
pPAllocator
  Allocator -> ContT Allocator IO Allocator
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Allocator -> ContT Allocator IO Allocator)
-> Allocator -> ContT Allocator IO Allocator
forall a b. (a -> b) -> a -> b
$ (Allocator
pAllocator)

-- | A convenience wrapper to make a compatible pair of calls to
-- 'createAllocator' and 'destroyAllocator'
--
-- To ensure that 'destroyAllocator' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the first argument.
-- To just extract the pair pass '(,)' as the first argument.
--
withAllocator :: forall io r . MonadIO io => AllocatorCreateInfo -> (io (Allocator) -> ((Allocator) -> io ()) -> r) -> r
withAllocator :: AllocatorCreateInfo
-> (io Allocator -> (Allocator -> io ()) -> r) -> r
withAllocator pCreateInfo :: AllocatorCreateInfo
pCreateInfo b :: io Allocator -> (Allocator -> io ()) -> r
b =
  io Allocator -> (Allocator -> io ()) -> r
b (AllocatorCreateInfo -> io Allocator
forall (io :: * -> *).
MonadIO io =>
AllocatorCreateInfo -> io Allocator
createAllocator AllocatorCreateInfo
pCreateInfo)
    (\(Allocator
o0) -> Allocator -> io ()
forall (io :: * -> *). MonadIO io => Allocator -> io ()
destroyAllocator Allocator
o0)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaDestroyAllocator" ffiVmaDestroyAllocator
  :: Allocator -> IO ()

-- | Destroys allocator object.
destroyAllocator :: forall io
                  . (MonadIO io)
                 => -- No documentation found for Nested "vmaDestroyAllocator" "allocator"
                    Allocator
                 -> io ()
destroyAllocator :: Allocator -> io ()
destroyAllocator allocator :: Allocator
allocator = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  (Allocator -> IO ()
ffiVmaDestroyAllocator) (Allocator
allocator)
  () -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> IO ()) -> () -> IO ()
forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaGetAllocatorInfo" ffiVmaGetAllocatorInfo
  :: Allocator -> Ptr AllocatorInfo -> IO ()

-- | Returns information about existing 'Allocator' object - handle to Vulkan
-- device etc.
--
-- It might be useful if you want to keep just the 'Allocator' handle and
-- fetch other required handles to @VkPhysicalDevice@, @VkDevice@ etc.
-- every time using this function.
getAllocatorInfo :: forall io
                  . (MonadIO io)
                 => -- No documentation found for Nested "vmaGetAllocatorInfo" "allocator"
                    Allocator
                 -> io (AllocatorInfo)
getAllocatorInfo :: Allocator -> io AllocatorInfo
getAllocatorInfo allocator :: Allocator
allocator = IO AllocatorInfo -> io AllocatorInfo
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO AllocatorInfo -> io AllocatorInfo)
-> (ContT AllocatorInfo IO AllocatorInfo -> IO AllocatorInfo)
-> ContT AllocatorInfo IO AllocatorInfo
-> io AllocatorInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT AllocatorInfo IO AllocatorInfo -> IO AllocatorInfo
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT AllocatorInfo IO AllocatorInfo -> io AllocatorInfo)
-> ContT AllocatorInfo IO AllocatorInfo -> io AllocatorInfo
forall a b. (a -> b) -> a -> b
$ do
  Ptr AllocatorInfo
pPAllocatorInfo <- ((Ptr AllocatorInfo -> IO AllocatorInfo) -> IO AllocatorInfo)
-> ContT AllocatorInfo IO (Ptr AllocatorInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct AllocatorInfo =>
(Ptr AllocatorInfo -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @AllocatorInfo)
  IO () -> ContT AllocatorInfo IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT AllocatorInfo IO ())
-> IO () -> ContT AllocatorInfo IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Ptr AllocatorInfo -> IO ()
ffiVmaGetAllocatorInfo) (Allocator
allocator) (Ptr AllocatorInfo
pPAllocatorInfo)
  AllocatorInfo
pAllocatorInfo <- IO AllocatorInfo -> ContT AllocatorInfo IO AllocatorInfo
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO AllocatorInfo -> ContT AllocatorInfo IO AllocatorInfo)
-> IO AllocatorInfo -> ContT AllocatorInfo IO AllocatorInfo
forall a b. (a -> b) -> a -> b
$ Ptr AllocatorInfo -> IO AllocatorInfo
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @AllocatorInfo Ptr AllocatorInfo
pPAllocatorInfo
  AllocatorInfo -> ContT AllocatorInfo IO AllocatorInfo
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AllocatorInfo -> ContT AllocatorInfo IO AllocatorInfo)
-> AllocatorInfo -> ContT AllocatorInfo IO AllocatorInfo
forall a b. (a -> b) -> a -> b
$ (AllocatorInfo
pAllocatorInfo)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaGetPhysicalDeviceProperties" ffiVmaGetPhysicalDeviceProperties
  :: Allocator -> Ptr (Ptr PhysicalDeviceProperties) -> IO ()

-- | PhysicalDeviceProperties are fetched from physicalDevice by the
-- allocator. You can access it here, without fetching it again on your
-- own.
getPhysicalDeviceProperties :: forall io
                             . (MonadIO io)
                            => -- No documentation found for Nested "vmaGetPhysicalDeviceProperties" "allocator"
                               Allocator
                            -> io (Ptr PhysicalDeviceProperties)
getPhysicalDeviceProperties :: Allocator -> io (Ptr PhysicalDeviceProperties)
getPhysicalDeviceProperties allocator :: Allocator
allocator = IO (Ptr PhysicalDeviceProperties)
-> io (Ptr PhysicalDeviceProperties)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr PhysicalDeviceProperties)
 -> io (Ptr PhysicalDeviceProperties))
-> (ContT
      (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties)
    -> IO (Ptr PhysicalDeviceProperties))
-> ContT
     (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties)
-> io (Ptr PhysicalDeviceProperties)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties)
-> IO (Ptr PhysicalDeviceProperties)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties)
 -> io (Ptr PhysicalDeviceProperties))
-> ContT
     (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties)
-> io (Ptr PhysicalDeviceProperties)
forall a b. (a -> b) -> a -> b
$ do
  Ptr (Ptr PhysicalDeviceProperties)
pPpPhysicalDeviceProperties <- ((Ptr (Ptr PhysicalDeviceProperties)
  -> IO (Ptr PhysicalDeviceProperties))
 -> IO (Ptr PhysicalDeviceProperties))
-> ContT
     (Ptr PhysicalDeviceProperties)
     IO
     (Ptr (Ptr PhysicalDeviceProperties))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr (Ptr PhysicalDeviceProperties)
   -> IO (Ptr PhysicalDeviceProperties))
  -> IO (Ptr PhysicalDeviceProperties))
 -> ContT
      (Ptr PhysicalDeviceProperties)
      IO
      (Ptr (Ptr PhysicalDeviceProperties)))
-> ((Ptr (Ptr PhysicalDeviceProperties)
     -> IO (Ptr PhysicalDeviceProperties))
    -> IO (Ptr PhysicalDeviceProperties))
-> ContT
     (Ptr PhysicalDeviceProperties)
     IO
     (Ptr (Ptr PhysicalDeviceProperties))
forall a b. (a -> b) -> a -> b
$ IO (Ptr (Ptr PhysicalDeviceProperties))
-> (Ptr (Ptr PhysicalDeviceProperties) -> IO ())
-> (Ptr (Ptr PhysicalDeviceProperties)
    -> IO (Ptr PhysicalDeviceProperties))
-> IO (Ptr PhysicalDeviceProperties)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr (Ptr PhysicalDeviceProperties))
forall a. Int -> IO (Ptr a)
callocBytes @(Ptr PhysicalDeviceProperties) 8) Ptr (Ptr PhysicalDeviceProperties) -> IO ()
forall a. Ptr a -> IO ()
free
  IO () -> ContT (Ptr PhysicalDeviceProperties) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT (Ptr PhysicalDeviceProperties) IO ())
-> IO () -> ContT (Ptr PhysicalDeviceProperties) IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Ptr (Ptr PhysicalDeviceProperties) -> IO ()
ffiVmaGetPhysicalDeviceProperties) (Allocator
allocator) (Ptr (Ptr PhysicalDeviceProperties)
pPpPhysicalDeviceProperties)
  Ptr PhysicalDeviceProperties
ppPhysicalDeviceProperties <- IO (Ptr PhysicalDeviceProperties)
-> ContT
     (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO (Ptr PhysicalDeviceProperties)
 -> ContT
      (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties))
-> IO (Ptr PhysicalDeviceProperties)
-> ContT
     (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties)
forall a b. (a -> b) -> a -> b
$ Ptr (Ptr PhysicalDeviceProperties)
-> IO (Ptr PhysicalDeviceProperties)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr PhysicalDeviceProperties) Ptr (Ptr PhysicalDeviceProperties)
pPpPhysicalDeviceProperties
  Ptr PhysicalDeviceProperties
-> ContT
     (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ptr PhysicalDeviceProperties
 -> ContT
      (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties))
-> Ptr PhysicalDeviceProperties
-> ContT
     (Ptr PhysicalDeviceProperties) IO (Ptr PhysicalDeviceProperties)
forall a b. (a -> b) -> a -> b
$ (Ptr PhysicalDeviceProperties
ppPhysicalDeviceProperties)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaGetMemoryProperties" ffiVmaGetMemoryProperties
  :: Allocator -> Ptr (Ptr PhysicalDeviceMemoryProperties) -> IO ()

-- | PhysicalDeviceMemoryProperties are fetched from physicalDevice by the
-- allocator. You can access it here, without fetching it again on your
-- own.
getMemoryProperties :: forall io
                     . (MonadIO io)
                    => -- No documentation found for Nested "vmaGetMemoryProperties" "allocator"
                       Allocator
                    -> io (Ptr PhysicalDeviceMemoryProperties)
getMemoryProperties :: Allocator -> io (Ptr PhysicalDeviceMemoryProperties)
getMemoryProperties allocator :: Allocator
allocator = IO (Ptr PhysicalDeviceMemoryProperties)
-> io (Ptr PhysicalDeviceMemoryProperties)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr PhysicalDeviceMemoryProperties)
 -> io (Ptr PhysicalDeviceMemoryProperties))
-> (ContT
      (Ptr PhysicalDeviceMemoryProperties)
      IO
      (Ptr PhysicalDeviceMemoryProperties)
    -> IO (Ptr PhysicalDeviceMemoryProperties))
-> ContT
     (Ptr PhysicalDeviceMemoryProperties)
     IO
     (Ptr PhysicalDeviceMemoryProperties)
-> io (Ptr PhysicalDeviceMemoryProperties)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  (Ptr PhysicalDeviceMemoryProperties)
  IO
  (Ptr PhysicalDeviceMemoryProperties)
-> IO (Ptr PhysicalDeviceMemoryProperties)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   (Ptr PhysicalDeviceMemoryProperties)
   IO
   (Ptr PhysicalDeviceMemoryProperties)
 -> io (Ptr PhysicalDeviceMemoryProperties))
-> ContT
     (Ptr PhysicalDeviceMemoryProperties)
     IO
     (Ptr PhysicalDeviceMemoryProperties)
-> io (Ptr PhysicalDeviceMemoryProperties)
forall a b. (a -> b) -> a -> b
$ do
  Ptr (Ptr PhysicalDeviceMemoryProperties)
pPpPhysicalDeviceMemoryProperties <- ((Ptr (Ptr PhysicalDeviceMemoryProperties)
  -> IO (Ptr PhysicalDeviceMemoryProperties))
 -> IO (Ptr PhysicalDeviceMemoryProperties))
-> ContT
     (Ptr PhysicalDeviceMemoryProperties)
     IO
     (Ptr (Ptr PhysicalDeviceMemoryProperties))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr (Ptr PhysicalDeviceMemoryProperties)
   -> IO (Ptr PhysicalDeviceMemoryProperties))
  -> IO (Ptr PhysicalDeviceMemoryProperties))
 -> ContT
      (Ptr PhysicalDeviceMemoryProperties)
      IO
      (Ptr (Ptr PhysicalDeviceMemoryProperties)))
-> ((Ptr (Ptr PhysicalDeviceMemoryProperties)
     -> IO (Ptr PhysicalDeviceMemoryProperties))
    -> IO (Ptr PhysicalDeviceMemoryProperties))
-> ContT
     (Ptr PhysicalDeviceMemoryProperties)
     IO
     (Ptr (Ptr PhysicalDeviceMemoryProperties))
forall a b. (a -> b) -> a -> b
$ IO (Ptr (Ptr PhysicalDeviceMemoryProperties))
-> (Ptr (Ptr PhysicalDeviceMemoryProperties) -> IO ())
-> (Ptr (Ptr PhysicalDeviceMemoryProperties)
    -> IO (Ptr PhysicalDeviceMemoryProperties))
-> IO (Ptr PhysicalDeviceMemoryProperties)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr (Ptr PhysicalDeviceMemoryProperties))
forall a. Int -> IO (Ptr a)
callocBytes @(Ptr PhysicalDeviceMemoryProperties) 8) Ptr (Ptr PhysicalDeviceMemoryProperties) -> IO ()
forall a. Ptr a -> IO ()
free
  IO () -> ContT (Ptr PhysicalDeviceMemoryProperties) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT (Ptr PhysicalDeviceMemoryProperties) IO ())
-> IO () -> ContT (Ptr PhysicalDeviceMemoryProperties) IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Ptr (Ptr PhysicalDeviceMemoryProperties) -> IO ()
ffiVmaGetMemoryProperties) (Allocator
allocator) (Ptr (Ptr PhysicalDeviceMemoryProperties)
pPpPhysicalDeviceMemoryProperties)
  Ptr PhysicalDeviceMemoryProperties
ppPhysicalDeviceMemoryProperties <- IO (Ptr PhysicalDeviceMemoryProperties)
-> ContT
     (Ptr PhysicalDeviceMemoryProperties)
     IO
     (Ptr PhysicalDeviceMemoryProperties)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO (Ptr PhysicalDeviceMemoryProperties)
 -> ContT
      (Ptr PhysicalDeviceMemoryProperties)
      IO
      (Ptr PhysicalDeviceMemoryProperties))
-> IO (Ptr PhysicalDeviceMemoryProperties)
-> ContT
     (Ptr PhysicalDeviceMemoryProperties)
     IO
     (Ptr PhysicalDeviceMemoryProperties)
forall a b. (a -> b) -> a -> b
$ Ptr (Ptr PhysicalDeviceMemoryProperties)
-> IO (Ptr PhysicalDeviceMemoryProperties)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr PhysicalDeviceMemoryProperties) Ptr (Ptr PhysicalDeviceMemoryProperties)
pPpPhysicalDeviceMemoryProperties
  Ptr PhysicalDeviceMemoryProperties
-> ContT
     (Ptr PhysicalDeviceMemoryProperties)
     IO
     (Ptr PhysicalDeviceMemoryProperties)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ptr PhysicalDeviceMemoryProperties
 -> ContT
      (Ptr PhysicalDeviceMemoryProperties)
      IO
      (Ptr PhysicalDeviceMemoryProperties))
-> Ptr PhysicalDeviceMemoryProperties
-> ContT
     (Ptr PhysicalDeviceMemoryProperties)
     IO
     (Ptr PhysicalDeviceMemoryProperties)
forall a b. (a -> b) -> a -> b
$ (Ptr PhysicalDeviceMemoryProperties
ppPhysicalDeviceMemoryProperties)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaGetMemoryTypeProperties" ffiVmaGetMemoryTypeProperties
  :: Allocator -> Word32 -> Ptr MemoryPropertyFlags -> IO ()

-- | Given Memory Type Index, returns Property Flags of this memory type.
--
-- This is just a convenience function. Same information can be obtained
-- using 'getMemoryProperties'.
getMemoryTypeProperties :: forall io
                         . (MonadIO io)
                        => -- No documentation found for Nested "vmaGetMemoryTypeProperties" "allocator"
                           Allocator
                        -> -- No documentation found for Nested "vmaGetMemoryTypeProperties" "memoryTypeIndex"
                           ("memoryTypeIndex" ::: Word32)
                        -> io (MemoryPropertyFlags)
getMemoryTypeProperties :: Allocator
-> ("memoryTypeIndex" ::: Word32) -> io MemoryPropertyFlags
getMemoryTypeProperties allocator :: Allocator
allocator memoryTypeIndex :: "memoryTypeIndex" ::: Word32
memoryTypeIndex = IO MemoryPropertyFlags -> io MemoryPropertyFlags
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MemoryPropertyFlags -> io MemoryPropertyFlags)
-> (ContT MemoryPropertyFlags IO MemoryPropertyFlags
    -> IO MemoryPropertyFlags)
-> ContT MemoryPropertyFlags IO MemoryPropertyFlags
-> io MemoryPropertyFlags
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT MemoryPropertyFlags IO MemoryPropertyFlags
-> IO MemoryPropertyFlags
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT MemoryPropertyFlags IO MemoryPropertyFlags
 -> io MemoryPropertyFlags)
-> ContT MemoryPropertyFlags IO MemoryPropertyFlags
-> io MemoryPropertyFlags
forall a b. (a -> b) -> a -> b
$ do
  Ptr MemoryPropertyFlags
pPFlags <- ((Ptr MemoryPropertyFlags -> IO MemoryPropertyFlags)
 -> IO MemoryPropertyFlags)
-> ContT MemoryPropertyFlags IO (Ptr MemoryPropertyFlags)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr MemoryPropertyFlags -> IO MemoryPropertyFlags)
  -> IO MemoryPropertyFlags)
 -> ContT MemoryPropertyFlags IO (Ptr MemoryPropertyFlags))
-> ((Ptr MemoryPropertyFlags -> IO MemoryPropertyFlags)
    -> IO MemoryPropertyFlags)
-> ContT MemoryPropertyFlags IO (Ptr MemoryPropertyFlags)
forall a b. (a -> b) -> a -> b
$ IO (Ptr MemoryPropertyFlags)
-> (Ptr MemoryPropertyFlags -> IO ())
-> (Ptr MemoryPropertyFlags -> IO MemoryPropertyFlags)
-> IO MemoryPropertyFlags
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr MemoryPropertyFlags)
forall a. Int -> IO (Ptr a)
callocBytes @MemoryPropertyFlags 4) Ptr MemoryPropertyFlags -> IO ()
forall a. Ptr a -> IO ()
free
  IO () -> ContT MemoryPropertyFlags IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT MemoryPropertyFlags IO ())
-> IO () -> ContT MemoryPropertyFlags IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator
-> ("memoryTypeIndex" ::: Word32)
-> Ptr MemoryPropertyFlags
-> IO ()
ffiVmaGetMemoryTypeProperties) (Allocator
allocator) ("memoryTypeIndex" ::: Word32
memoryTypeIndex) (Ptr MemoryPropertyFlags
pPFlags)
  MemoryPropertyFlags
pFlags <- IO MemoryPropertyFlags
-> ContT MemoryPropertyFlags IO MemoryPropertyFlags
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO MemoryPropertyFlags
 -> ContT MemoryPropertyFlags IO MemoryPropertyFlags)
-> IO MemoryPropertyFlags
-> ContT MemoryPropertyFlags IO MemoryPropertyFlags
forall a b. (a -> b) -> a -> b
$ Ptr MemoryPropertyFlags -> IO MemoryPropertyFlags
forall a. Storable a => Ptr a -> IO a
peek @MemoryPropertyFlags Ptr MemoryPropertyFlags
pPFlags
  MemoryPropertyFlags
-> ContT MemoryPropertyFlags IO MemoryPropertyFlags
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MemoryPropertyFlags
 -> ContT MemoryPropertyFlags IO MemoryPropertyFlags)
-> MemoryPropertyFlags
-> ContT MemoryPropertyFlags IO MemoryPropertyFlags
forall a b. (a -> b) -> a -> b
$ (MemoryPropertyFlags
pFlags)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaSetCurrentFrameIndex" ffiVmaSetCurrentFrameIndex
  :: Allocator -> Word32 -> IO ()

-- | Sets index of the current frame.
--
-- This function must be used if you make allocations with
-- 'ALLOCATION_CREATE_CAN_BECOME_LOST_BIT' and
-- 'ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT' flags to inform the
-- allocator when a new frame begins. Allocations queried using
-- 'getAllocationInfo' cannot become lost in the current frame.
setCurrentFrameIndex :: forall io
                      . (MonadIO io)
                     => -- No documentation found for Nested "vmaSetCurrentFrameIndex" "allocator"
                        Allocator
                     -> -- No documentation found for Nested "vmaSetCurrentFrameIndex" "frameIndex"
                        ("frameIndex" ::: Word32)
                     -> io ()
setCurrentFrameIndex :: Allocator -> ("memoryTypeIndex" ::: Word32) -> io ()
setCurrentFrameIndex allocator :: Allocator
allocator frameIndex :: "memoryTypeIndex" ::: Word32
frameIndex = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  (Allocator -> ("memoryTypeIndex" ::: Word32) -> IO ()
ffiVmaSetCurrentFrameIndex) (Allocator
allocator) ("memoryTypeIndex" ::: Word32
frameIndex)
  () -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> IO ()) -> () -> IO ()
forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaCalculateStats" ffiVmaCalculateStats
  :: Allocator -> Ptr Stats -> IO ()

-- | Retrieves statistics from current state of the Allocator.
--
-- This function is called \"calculate\" not \"get\" because it has to
-- traverse all internal data structures, so it may be quite slow. For
-- faster but more brief statistics suitable to be called every frame or
-- every allocation, use 'getBudget'.
--
-- Note that when using allocator from multiple threads, returned
-- information may immediately become outdated.
calculateStats :: forall io
                . (MonadIO io)
               => -- No documentation found for Nested "vmaCalculateStats" "allocator"
                  Allocator
               -> io (Stats)
calculateStats :: Allocator -> io Stats
calculateStats allocator :: Allocator
allocator = IO Stats -> io Stats
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Stats -> io Stats)
-> (ContT Stats IO Stats -> IO Stats)
-> ContT Stats IO Stats
-> io Stats
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT Stats IO Stats -> IO Stats
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT Stats IO Stats -> io Stats)
-> ContT Stats IO Stats -> io Stats
forall a b. (a -> b) -> a -> b
$ do
  Ptr Stats
pPStats <- ((Ptr Stats -> IO Stats) -> IO Stats) -> ContT Stats IO (Ptr Stats)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b. ToCStruct Stats => (Ptr Stats -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @Stats)
  IO () -> ContT Stats IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Stats IO ()) -> IO () -> ContT Stats IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Ptr Stats -> IO ()
ffiVmaCalculateStats) (Allocator
allocator) (Ptr Stats
pPStats)
  Stats
pStats <- IO Stats -> ContT Stats IO Stats
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Stats -> ContT Stats IO Stats)
-> IO Stats -> ContT Stats IO Stats
forall a b. (a -> b) -> a -> b
$ Ptr Stats -> IO Stats
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @Stats Ptr Stats
pPStats
  Stats -> ContT Stats IO Stats
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Stats -> ContT Stats IO Stats) -> Stats -> ContT Stats IO Stats
forall a b. (a -> b) -> a -> b
$ (Stats
pStats)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaGetBudget" ffiVmaGetBudget
  :: Allocator -> Ptr Budget -> IO ()

-- | Retrieves information about current memory budget for all memory heaps.
--
-- __Parameters.__
--
-- +-----------+-----------+-----------------------------------------------+
-- | out       | pBudget   | Must point to array with number of elements   |
-- |           |           | at least equal to number of memory heaps in   |
-- |           |           | physical device used.                         |
-- +-----------+-----------+-----------------------------------------------+
--
-- This function is called \"get\" not \"calculate\" because it is very
-- fast, suitable to be called every frame or every allocation. For more
-- detailed statistics use 'calculateStats'.
--
-- Note that when using allocator from multiple threads, returned
-- information may immediately become outdated.
getBudget :: forall io
           . (MonadIO io)
          => -- No documentation found for Nested "vmaGetBudget" "allocator"
             Allocator
          -> io (Budget)
getBudget :: Allocator -> io Budget
getBudget allocator :: Allocator
allocator = IO Budget -> io Budget
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Budget -> io Budget)
-> (ContT Budget IO Budget -> IO Budget)
-> ContT Budget IO Budget
-> io Budget
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT Budget IO Budget -> IO Budget
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT Budget IO Budget -> io Budget)
-> ContT Budget IO Budget -> io Budget
forall a b. (a -> b) -> a -> b
$ do
  Ptr Budget
pPBudget <- ((Ptr Budget -> IO Budget) -> IO Budget)
-> ContT Budget IO (Ptr Budget)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b. ToCStruct Budget => (Ptr Budget -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @Budget)
  IO () -> ContT Budget IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Budget IO ()) -> IO () -> ContT Budget IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Ptr Budget -> IO ()
ffiVmaGetBudget) (Allocator
allocator) (Ptr Budget
pPBudget)
  Budget
pBudget <- IO Budget -> ContT Budget IO Budget
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Budget -> ContT Budget IO Budget)
-> IO Budget -> ContT Budget IO Budget
forall a b. (a -> b) -> a -> b
$ Ptr Budget -> IO Budget
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @Budget Ptr Budget
pPBudget
  Budget -> ContT Budget IO Budget
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Budget -> ContT Budget IO Budget)
-> Budget -> ContT Budget IO Budget
forall a b. (a -> b) -> a -> b
$ (Budget
pBudget)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaBuildStatsString" ffiVmaBuildStatsString
  :: Allocator -> Ptr (Ptr CChar) -> Bool32 -> IO ()

-- | Builds and returns statistics as string in JSON format.
--
-- __Parameters.__
--
-- +-----------+---------------+-----------------------------------------------+
-- | out       | ppStatsString | Must be freed using 'freeStatsString'         |
-- |           |               | function.                                     |
-- +-----------+---------------+-----------------------------------------------+
buildStatsString :: forall io
                  . (MonadIO io)
                 => -- No documentation found for Nested "vmaBuildStatsString" "allocator"
                    Allocator
                 -> -- No documentation found for Nested "vmaBuildStatsString" "detailedMap"
                    ("detailedMap" ::: Bool)
                 -> io (("statsString" ::: Ptr CChar))
buildStatsString :: Allocator -> Bool -> io ("statsString" ::: Ptr CChar)
buildStatsString allocator :: Allocator
allocator detailedMap :: Bool
detailedMap = IO ("statsString" ::: Ptr CChar)
-> io ("statsString" ::: Ptr CChar)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("statsString" ::: Ptr CChar)
 -> io ("statsString" ::: Ptr CChar))
-> (ContT
      ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
    -> IO ("statsString" ::: Ptr CChar))
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
-> io ("statsString" ::: Ptr CChar)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
-> IO ("statsString" ::: Ptr CChar)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
 -> io ("statsString" ::: Ptr CChar))
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
-> io ("statsString" ::: Ptr CChar)
forall a b. (a -> b) -> a -> b
$ do
  Ptr ("statsString" ::: Ptr CChar)
pPpStatsString <- ((Ptr ("statsString" ::: Ptr CChar)
  -> IO ("statsString" ::: Ptr CChar))
 -> IO ("statsString" ::: Ptr CChar))
-> ContT
     ("statsString" ::: Ptr CChar)
     IO
     (Ptr ("statsString" ::: Ptr CChar))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("statsString" ::: Ptr CChar)
   -> IO ("statsString" ::: Ptr CChar))
  -> IO ("statsString" ::: Ptr CChar))
 -> ContT
      ("statsString" ::: Ptr CChar)
      IO
      (Ptr ("statsString" ::: Ptr CChar)))
-> ((Ptr ("statsString" ::: Ptr CChar)
     -> IO ("statsString" ::: Ptr CChar))
    -> IO ("statsString" ::: Ptr CChar))
-> ContT
     ("statsString" ::: Ptr CChar)
     IO
     (Ptr ("statsString" ::: Ptr CChar))
forall a b. (a -> b) -> a -> b
$ IO (Ptr ("statsString" ::: Ptr CChar))
-> (Ptr ("statsString" ::: Ptr CChar) -> IO ())
-> (Ptr ("statsString" ::: Ptr CChar)
    -> IO ("statsString" ::: Ptr CChar))
-> IO ("statsString" ::: Ptr CChar)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr ("statsString" ::: Ptr CChar))
forall a. Int -> IO (Ptr a)
callocBytes @(Ptr CChar) 8) Ptr ("statsString" ::: Ptr CChar) -> IO ()
forall a. Ptr a -> IO ()
free
  IO () -> ContT ("statsString" ::: Ptr CChar) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("statsString" ::: Ptr CChar) IO ())
-> IO () -> ContT ("statsString" ::: Ptr CChar) IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Ptr ("statsString" ::: Ptr CChar) -> Bool32 -> IO ()
ffiVmaBuildStatsString) (Allocator
allocator) (Ptr ("statsString" ::: Ptr CChar)
pPpStatsString) (Bool -> Bool32
boolToBool32 (Bool
detailedMap))
  "statsString" ::: Ptr CChar
ppStatsString <- IO ("statsString" ::: Ptr CChar)
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("statsString" ::: Ptr CChar)
 -> ContT
      ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar))
-> IO ("statsString" ::: Ptr CChar)
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
forall a b. (a -> b) -> a -> b
$ Ptr ("statsString" ::: Ptr CChar)
-> IO ("statsString" ::: Ptr CChar)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr CChar) Ptr ("statsString" ::: Ptr CChar)
pPpStatsString
  ("statsString" ::: Ptr CChar)
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("statsString" ::: Ptr CChar)
 -> ContT
      ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar))
-> ("statsString" ::: Ptr CChar)
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
forall a b. (a -> b) -> a -> b
$ ("statsString" ::: Ptr CChar
ppStatsString)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaFreeStatsString" ffiVmaFreeStatsString
  :: Allocator -> Ptr CChar -> IO ()


freeStatsString :: forall io
                 . (MonadIO io)
                => -- No documentation found for Nested "vmaFreeStatsString" "allocator"
                   Allocator
                -> -- No documentation found for Nested "vmaFreeStatsString" "pStatsString"
                   ("statsString" ::: Ptr CChar)
                -> io ()
freeStatsString :: Allocator -> ("statsString" ::: Ptr CChar) -> io ()
freeStatsString allocator :: Allocator
allocator statsString :: "statsString" ::: Ptr CChar
statsString = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  (Allocator -> ("statsString" ::: Ptr CChar) -> IO ()
ffiVmaFreeStatsString) (Allocator
allocator) ("statsString" ::: Ptr CChar
statsString)
  () -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> IO ()) -> () -> IO ()
forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaFindMemoryTypeIndex" ffiVmaFindMemoryTypeIndex
  :: Allocator -> Word32 -> Ptr AllocationCreateInfo -> Ptr Word32 -> IO Result

-- | Helps to find memoryTypeIndex, given memoryTypeBits and
-- 'AllocationCreateInfo'.
--
-- This algorithm tries to find a memory type that:
--
-- -   Is allowed by memoryTypeBits.
--
-- -   Contains all the flags from pAllocationCreateInfo->requiredFlags.
--
-- -   Matches intended usage.
--
-- -   Has as many flags from pAllocationCreateInfo->preferredFlags as
--     possible.
--
-- __Returns.__
--
-- Returns VK_ERROR_FEATURE_NOT_PRESENT if not found. Receiving such result
-- from this function or any other allocating function probably means that
-- your device doesn\'t support any memory type with requested features for
-- the specific type of resource you want to use it for. Please check
-- parameters of your resource, like image layout (OPTIMAL versus LINEAR)
-- or mip level count.
findMemoryTypeIndex :: forall io
                     . (MonadIO io)
                    => -- No documentation found for Nested "vmaFindMemoryTypeIndex" "allocator"
                       Allocator
                    -> -- No documentation found for Nested "vmaFindMemoryTypeIndex" "memoryTypeBits"
                       ("memoryTypeBits" ::: Word32)
                    -> -- No documentation found for Nested "vmaFindMemoryTypeIndex" "pAllocationCreateInfo"
                       AllocationCreateInfo
                    -> io (("memoryTypeIndex" ::: Word32))
findMemoryTypeIndex :: Allocator
-> ("memoryTypeIndex" ::: Word32)
-> AllocationCreateInfo
-> io ("memoryTypeIndex" ::: Word32)
findMemoryTypeIndex allocator :: Allocator
allocator memoryTypeBits :: "memoryTypeIndex" ::: Word32
memoryTypeBits allocationCreateInfo :: AllocationCreateInfo
allocationCreateInfo = IO ("memoryTypeIndex" ::: Word32)
-> io ("memoryTypeIndex" ::: Word32)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("memoryTypeIndex" ::: Word32)
 -> io ("memoryTypeIndex" ::: Word32))
-> (ContT
      ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
-> io ("memoryTypeIndex" ::: Word32)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
-> IO ("memoryTypeIndex" ::: Word32)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
 -> io ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
-> io ("memoryTypeIndex" ::: Word32)
forall a b. (a -> b) -> a -> b
$ do
  Ptr AllocationCreateInfo
pAllocationCreateInfo <- ((Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
 -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO (Ptr AllocationCreateInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
  -> IO ("memoryTypeIndex" ::: Word32))
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO (Ptr AllocationCreateInfo))
-> ((Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO (Ptr AllocationCreateInfo)
forall a b. (a -> b) -> a -> b
$ AllocationCreateInfo
-> (Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (AllocationCreateInfo
allocationCreateInfo)
  Ptr ("memoryTypeIndex" ::: Word32)
pPMemoryTypeIndex <- ((Ptr ("memoryTypeIndex" ::: Word32)
  -> IO ("memoryTypeIndex" ::: Word32))
 -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32)
     IO
     (Ptr ("memoryTypeIndex" ::: Word32))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("memoryTypeIndex" ::: Word32)
   -> IO ("memoryTypeIndex" ::: Word32))
  -> IO ("memoryTypeIndex" ::: Word32))
 -> ContT
      ("memoryTypeIndex" ::: Word32)
      IO
      (Ptr ("memoryTypeIndex" ::: Word32)))
-> ((Ptr ("memoryTypeIndex" ::: Word32)
     -> IO ("memoryTypeIndex" ::: Word32))
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32)
     IO
     (Ptr ("memoryTypeIndex" ::: Word32))
forall a b. (a -> b) -> a -> b
$ IO (Ptr ("memoryTypeIndex" ::: Word32))
-> (Ptr ("memoryTypeIndex" ::: Word32) -> IO ())
-> (Ptr ("memoryTypeIndex" ::: Word32)
    -> IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr ("memoryTypeIndex" ::: Word32))
forall a. Int -> IO (Ptr a)
callocBytes @Word32 4) Ptr ("memoryTypeIndex" ::: Word32) -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT ("memoryTypeIndex" ::: Word32) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT ("memoryTypeIndex" ::: Word32) IO Result)
-> IO Result -> ContT ("memoryTypeIndex" ::: Word32) IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> ("memoryTypeIndex" ::: Word32)
-> Ptr AllocationCreateInfo
-> Ptr ("memoryTypeIndex" ::: Word32)
-> IO Result
ffiVmaFindMemoryTypeIndex) (Allocator
allocator) ("memoryTypeIndex" ::: Word32
memoryTypeBits) Ptr AllocationCreateInfo
pAllocationCreateInfo (Ptr ("memoryTypeIndex" ::: Word32)
pPMemoryTypeIndex)
  IO () -> ContT ("memoryTypeIndex" ::: Word32) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("memoryTypeIndex" ::: Word32) IO ())
-> IO () -> ContT ("memoryTypeIndex" ::: Word32) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  "memoryTypeIndex" ::: Word32
pMemoryTypeIndex <- IO ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("memoryTypeIndex" ::: Word32)
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall a b. (a -> b) -> a -> b
$ Ptr ("memoryTypeIndex" ::: Word32)
-> IO ("memoryTypeIndex" ::: Word32)
forall a. Storable a => Ptr a -> IO a
peek @Word32 Ptr ("memoryTypeIndex" ::: Word32)
pPMemoryTypeIndex
  ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("memoryTypeIndex" ::: Word32)
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32))
-> ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall a b. (a -> b) -> a -> b
$ ("memoryTypeIndex" ::: Word32
pMemoryTypeIndex)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaFindMemoryTypeIndexForBufferInfo" ffiVmaFindMemoryTypeIndexForBufferInfo
  :: Allocator -> Ptr (SomeStruct BufferCreateInfo) -> Ptr AllocationCreateInfo -> Ptr Word32 -> IO Result

-- | Helps to find memoryTypeIndex, given VkBufferCreateInfo and
-- 'AllocationCreateInfo'.
--
-- It can be useful e.g. to determine value to be used as
-- /VmaPoolCreateInfo::memoryTypeIndex/. It internally creates a temporary,
-- dummy buffer that never has memory bound. It is just a convenience
-- function, equivalent to calling:
--
-- -   @vkCreateBuffer@
--
-- -   @vkGetBufferMemoryRequirements@
--
-- -   'findMemoryTypeIndex'
--
-- -   @vkDestroyBuffer@
findMemoryTypeIndexForBufferInfo :: forall a io
                                  . (Extendss BufferCreateInfo a, PokeChain a, MonadIO io)
                                 => -- No documentation found for Nested "vmaFindMemoryTypeIndexForBufferInfo" "allocator"
                                    Allocator
                                 -> -- No documentation found for Nested "vmaFindMemoryTypeIndexForBufferInfo" "pBufferCreateInfo"
                                    (BufferCreateInfo a)
                                 -> -- No documentation found for Nested "vmaFindMemoryTypeIndexForBufferInfo" "pAllocationCreateInfo"
                                    AllocationCreateInfo
                                 -> io (("memoryTypeIndex" ::: Word32))
findMemoryTypeIndexForBufferInfo :: Allocator
-> BufferCreateInfo a
-> AllocationCreateInfo
-> io ("memoryTypeIndex" ::: Word32)
findMemoryTypeIndexForBufferInfo allocator :: Allocator
allocator bufferCreateInfo :: BufferCreateInfo a
bufferCreateInfo allocationCreateInfo :: AllocationCreateInfo
allocationCreateInfo = IO ("memoryTypeIndex" ::: Word32)
-> io ("memoryTypeIndex" ::: Word32)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("memoryTypeIndex" ::: Word32)
 -> io ("memoryTypeIndex" ::: Word32))
-> (ContT
      ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
-> io ("memoryTypeIndex" ::: Word32)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
-> IO ("memoryTypeIndex" ::: Word32)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
 -> io ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
-> io ("memoryTypeIndex" ::: Word32)
forall a b. (a -> b) -> a -> b
$ do
  Ptr (BufferCreateInfo a)
pBufferCreateInfo <- ((Ptr (BufferCreateInfo a) -> IO ("memoryTypeIndex" ::: Word32))
 -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO (Ptr (BufferCreateInfo a))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr (BufferCreateInfo a) -> IO ("memoryTypeIndex" ::: Word32))
  -> IO ("memoryTypeIndex" ::: Word32))
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO (Ptr (BufferCreateInfo a)))
-> ((Ptr (BufferCreateInfo a) -> IO ("memoryTypeIndex" ::: Word32))
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO (Ptr (BufferCreateInfo a))
forall a b. (a -> b) -> a -> b
$ BufferCreateInfo a
-> (Ptr (BufferCreateInfo a) -> IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (BufferCreateInfo a
bufferCreateInfo)
  Ptr AllocationCreateInfo
pAllocationCreateInfo <- ((Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
 -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO (Ptr AllocationCreateInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
  -> IO ("memoryTypeIndex" ::: Word32))
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO (Ptr AllocationCreateInfo))
-> ((Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO (Ptr AllocationCreateInfo)
forall a b. (a -> b) -> a -> b
$ AllocationCreateInfo
-> (Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (AllocationCreateInfo
allocationCreateInfo)
  Ptr ("memoryTypeIndex" ::: Word32)
pPMemoryTypeIndex <- ((Ptr ("memoryTypeIndex" ::: Word32)
  -> IO ("memoryTypeIndex" ::: Word32))
 -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32)
     IO
     (Ptr ("memoryTypeIndex" ::: Word32))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("memoryTypeIndex" ::: Word32)
   -> IO ("memoryTypeIndex" ::: Word32))
  -> IO ("memoryTypeIndex" ::: Word32))
 -> ContT
      ("memoryTypeIndex" ::: Word32)
      IO
      (Ptr ("memoryTypeIndex" ::: Word32)))
-> ((Ptr ("memoryTypeIndex" ::: Word32)
     -> IO ("memoryTypeIndex" ::: Word32))
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32)
     IO
     (Ptr ("memoryTypeIndex" ::: Word32))
forall a b. (a -> b) -> a -> b
$ IO (Ptr ("memoryTypeIndex" ::: Word32))
-> (Ptr ("memoryTypeIndex" ::: Word32) -> IO ())
-> (Ptr ("memoryTypeIndex" ::: Word32)
    -> IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr ("memoryTypeIndex" ::: Word32))
forall a. Int -> IO (Ptr a)
callocBytes @Word32 4) Ptr ("memoryTypeIndex" ::: Word32) -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT ("memoryTypeIndex" ::: Word32) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT ("memoryTypeIndex" ::: Word32) IO Result)
-> IO Result -> ContT ("memoryTypeIndex" ::: Word32) IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> Ptr (SomeStruct BufferCreateInfo)
-> Ptr AllocationCreateInfo
-> Ptr ("memoryTypeIndex" ::: Word32)
-> IO Result
ffiVmaFindMemoryTypeIndexForBufferInfo) (Allocator
allocator) (Ptr (BufferCreateInfo a) -> Ptr (SomeStruct BufferCreateInfo)
forall (a :: [*] -> *) (es :: [*]).
Ptr (a es) -> Ptr (SomeStruct a)
forgetExtensions Ptr (BufferCreateInfo a)
pBufferCreateInfo) Ptr AllocationCreateInfo
pAllocationCreateInfo (Ptr ("memoryTypeIndex" ::: Word32)
pPMemoryTypeIndex)
  IO () -> ContT ("memoryTypeIndex" ::: Word32) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("memoryTypeIndex" ::: Word32) IO ())
-> IO () -> ContT ("memoryTypeIndex" ::: Word32) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  "memoryTypeIndex" ::: Word32
pMemoryTypeIndex <- IO ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("memoryTypeIndex" ::: Word32)
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall a b. (a -> b) -> a -> b
$ Ptr ("memoryTypeIndex" ::: Word32)
-> IO ("memoryTypeIndex" ::: Word32)
forall a. Storable a => Ptr a -> IO a
peek @Word32 Ptr ("memoryTypeIndex" ::: Word32)
pPMemoryTypeIndex
  ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("memoryTypeIndex" ::: Word32)
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32))
-> ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall a b. (a -> b) -> a -> b
$ ("memoryTypeIndex" ::: Word32
pMemoryTypeIndex)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaFindMemoryTypeIndexForImageInfo" ffiVmaFindMemoryTypeIndexForImageInfo
  :: Allocator -> Ptr (SomeStruct ImageCreateInfo) -> Ptr AllocationCreateInfo -> Ptr Word32 -> IO Result

-- | Helps to find memoryTypeIndex, given VkImageCreateInfo and
-- 'AllocationCreateInfo'.
--
-- It can be useful e.g. to determine value to be used as
-- /VmaPoolCreateInfo::memoryTypeIndex/. It internally creates a temporary,
-- dummy image that never has memory bound. It is just a convenience
-- function, equivalent to calling:
--
-- -   @vkCreateImage@
--
-- -   @vkGetImageMemoryRequirements@
--
-- -   'findMemoryTypeIndex'
--
-- -   @vkDestroyImage@
findMemoryTypeIndexForImageInfo :: forall a io
                                 . (Extendss ImageCreateInfo a, PokeChain a, MonadIO io)
                                => -- No documentation found for Nested "vmaFindMemoryTypeIndexForImageInfo" "allocator"
                                   Allocator
                                -> -- No documentation found for Nested "vmaFindMemoryTypeIndexForImageInfo" "pImageCreateInfo"
                                   (ImageCreateInfo a)
                                -> -- No documentation found for Nested "vmaFindMemoryTypeIndexForImageInfo" "pAllocationCreateInfo"
                                   AllocationCreateInfo
                                -> io (("memoryTypeIndex" ::: Word32))
findMemoryTypeIndexForImageInfo :: Allocator
-> ImageCreateInfo a
-> AllocationCreateInfo
-> io ("memoryTypeIndex" ::: Word32)
findMemoryTypeIndexForImageInfo allocator :: Allocator
allocator imageCreateInfo :: ImageCreateInfo a
imageCreateInfo allocationCreateInfo :: AllocationCreateInfo
allocationCreateInfo = IO ("memoryTypeIndex" ::: Word32)
-> io ("memoryTypeIndex" ::: Word32)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("memoryTypeIndex" ::: Word32)
 -> io ("memoryTypeIndex" ::: Word32))
-> (ContT
      ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
-> io ("memoryTypeIndex" ::: Word32)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
-> IO ("memoryTypeIndex" ::: Word32)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
 -> io ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
-> io ("memoryTypeIndex" ::: Word32)
forall a b. (a -> b) -> a -> b
$ do
  Ptr (ImageCreateInfo a)
pImageCreateInfo <- ((Ptr (ImageCreateInfo a) -> IO ("memoryTypeIndex" ::: Word32))
 -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO (Ptr (ImageCreateInfo a))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr (ImageCreateInfo a) -> IO ("memoryTypeIndex" ::: Word32))
  -> IO ("memoryTypeIndex" ::: Word32))
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO (Ptr (ImageCreateInfo a)))
-> ((Ptr (ImageCreateInfo a) -> IO ("memoryTypeIndex" ::: Word32))
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO (Ptr (ImageCreateInfo a))
forall a b. (a -> b) -> a -> b
$ ImageCreateInfo a
-> (Ptr (ImageCreateInfo a) -> IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (ImageCreateInfo a
imageCreateInfo)
  Ptr AllocationCreateInfo
pAllocationCreateInfo <- ((Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
 -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO (Ptr AllocationCreateInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
  -> IO ("memoryTypeIndex" ::: Word32))
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO (Ptr AllocationCreateInfo))
-> ((Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32) IO (Ptr AllocationCreateInfo)
forall a b. (a -> b) -> a -> b
$ AllocationCreateInfo
-> (Ptr AllocationCreateInfo -> IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (AllocationCreateInfo
allocationCreateInfo)
  Ptr ("memoryTypeIndex" ::: Word32)
pPMemoryTypeIndex <- ((Ptr ("memoryTypeIndex" ::: Word32)
  -> IO ("memoryTypeIndex" ::: Word32))
 -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32)
     IO
     (Ptr ("memoryTypeIndex" ::: Word32))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("memoryTypeIndex" ::: Word32)
   -> IO ("memoryTypeIndex" ::: Word32))
  -> IO ("memoryTypeIndex" ::: Word32))
 -> ContT
      ("memoryTypeIndex" ::: Word32)
      IO
      (Ptr ("memoryTypeIndex" ::: Word32)))
-> ((Ptr ("memoryTypeIndex" ::: Word32)
     -> IO ("memoryTypeIndex" ::: Word32))
    -> IO ("memoryTypeIndex" ::: Word32))
-> ContT
     ("memoryTypeIndex" ::: Word32)
     IO
     (Ptr ("memoryTypeIndex" ::: Word32))
forall a b. (a -> b) -> a -> b
$ IO (Ptr ("memoryTypeIndex" ::: Word32))
-> (Ptr ("memoryTypeIndex" ::: Word32) -> IO ())
-> (Ptr ("memoryTypeIndex" ::: Word32)
    -> IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr ("memoryTypeIndex" ::: Word32))
forall a. Int -> IO (Ptr a)
callocBytes @Word32 4) Ptr ("memoryTypeIndex" ::: Word32) -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT ("memoryTypeIndex" ::: Word32) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT ("memoryTypeIndex" ::: Word32) IO Result)
-> IO Result -> ContT ("memoryTypeIndex" ::: Word32) IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> Ptr (SomeStruct ImageCreateInfo)
-> Ptr AllocationCreateInfo
-> Ptr ("memoryTypeIndex" ::: Word32)
-> IO Result
ffiVmaFindMemoryTypeIndexForImageInfo) (Allocator
allocator) (Ptr (ImageCreateInfo a) -> Ptr (SomeStruct ImageCreateInfo)
forall (a :: [*] -> *) (es :: [*]).
Ptr (a es) -> Ptr (SomeStruct a)
forgetExtensions Ptr (ImageCreateInfo a)
pImageCreateInfo) Ptr AllocationCreateInfo
pAllocationCreateInfo (Ptr ("memoryTypeIndex" ::: Word32)
pPMemoryTypeIndex)
  IO () -> ContT ("memoryTypeIndex" ::: Word32) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("memoryTypeIndex" ::: Word32) IO ())
-> IO () -> ContT ("memoryTypeIndex" ::: Word32) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  "memoryTypeIndex" ::: Word32
pMemoryTypeIndex <- IO ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("memoryTypeIndex" ::: Word32)
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32))
-> IO ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall a b. (a -> b) -> a -> b
$ Ptr ("memoryTypeIndex" ::: Word32)
-> IO ("memoryTypeIndex" ::: Word32)
forall a. Storable a => Ptr a -> IO a
peek @Word32 Ptr ("memoryTypeIndex" ::: Word32)
pPMemoryTypeIndex
  ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("memoryTypeIndex" ::: Word32)
 -> ContT
      ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32))
-> ("memoryTypeIndex" ::: Word32)
-> ContT
     ("memoryTypeIndex" ::: Word32) IO ("memoryTypeIndex" ::: Word32)
forall a b. (a -> b) -> a -> b
$ ("memoryTypeIndex" ::: Word32
pMemoryTypeIndex)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaCreatePool" ffiVmaCreatePool
  :: Allocator -> Ptr PoolCreateInfo -> Ptr Pool -> IO Result

-- | Allocates Vulkan device memory and creates 'Pool' object.
--
-- __Parameters.__
--
-- +-----------+-------------+-----------------------------------------------+
-- |           | allocator   | Allocator object.                             |
-- +-----------+-------------+-----------------------------------------------+
-- |           | pCreateInfo | Parameters of pool to create.                 |
-- +-----------+-------------+-----------------------------------------------+
-- | out       | pPool       | Handle to created pool.                       |
-- +-----------+-------------+-----------------------------------------------+
createPool :: forall io
            . (MonadIO io)
           => -- No documentation found for Nested "vmaCreatePool" "allocator"
              Allocator
           -> -- No documentation found for Nested "vmaCreatePool" "pCreateInfo"
              PoolCreateInfo
           -> io (Pool)
createPool :: Allocator -> PoolCreateInfo -> io Pool
createPool allocator :: Allocator
allocator createInfo :: PoolCreateInfo
createInfo = IO Pool -> io Pool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Pool -> io Pool)
-> (ContT Pool IO Pool -> IO Pool) -> ContT Pool IO Pool -> io Pool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT Pool IO Pool -> IO Pool
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT Pool IO Pool -> io Pool) -> ContT Pool IO Pool -> io Pool
forall a b. (a -> b) -> a -> b
$ do
  Ptr PoolCreateInfo
pCreateInfo <- ((Ptr PoolCreateInfo -> IO Pool) -> IO Pool)
-> ContT Pool IO (Ptr PoolCreateInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr PoolCreateInfo -> IO Pool) -> IO Pool)
 -> ContT Pool IO (Ptr PoolCreateInfo))
-> ((Ptr PoolCreateInfo -> IO Pool) -> IO Pool)
-> ContT Pool IO (Ptr PoolCreateInfo)
forall a b. (a -> b) -> a -> b
$ PoolCreateInfo -> (Ptr PoolCreateInfo -> IO Pool) -> IO Pool
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (PoolCreateInfo
createInfo)
  Ptr Pool
pPPool <- ((Ptr Pool -> IO Pool) -> IO Pool) -> ContT Pool IO (Ptr Pool)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Pool -> IO Pool) -> IO Pool) -> ContT Pool IO (Ptr Pool))
-> ((Ptr Pool -> IO Pool) -> IO Pool) -> ContT Pool IO (Ptr Pool)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Pool)
-> (Ptr Pool -> IO ()) -> (Ptr Pool -> IO Pool) -> IO Pool
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Pool)
forall a. Int -> IO (Ptr a)
callocBytes @Pool 8) Ptr Pool -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT Pool IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT Pool IO Result)
-> IO Result -> ContT Pool IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator -> Ptr PoolCreateInfo -> Ptr Pool -> IO Result
ffiVmaCreatePool) (Allocator
allocator) Ptr PoolCreateInfo
pCreateInfo (Ptr Pool
pPPool)
  IO () -> ContT Pool IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Pool IO ()) -> IO () -> ContT Pool IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  Pool
pPool <- IO Pool -> ContT Pool IO Pool
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Pool -> ContT Pool IO Pool) -> IO Pool -> ContT Pool IO Pool
forall a b. (a -> b) -> a -> b
$ Ptr Pool -> IO Pool
forall a. Storable a => Ptr a -> IO a
peek @Pool Ptr Pool
pPPool
  Pool -> ContT Pool IO Pool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pool -> ContT Pool IO Pool) -> Pool -> ContT Pool IO Pool
forall a b. (a -> b) -> a -> b
$ (Pool
pPool)

-- | A convenience wrapper to make a compatible pair of calls to 'createPool'
-- and 'destroyPool'
--
-- To ensure that 'destroyPool' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the first argument.
-- To just extract the pair pass '(,)' as the first argument.
--
withPool :: forall io r . MonadIO io => Allocator -> PoolCreateInfo -> (io (Pool) -> ((Pool) -> io ()) -> r) -> r
withPool :: Allocator
-> PoolCreateInfo -> (io Pool -> (Pool -> io ()) -> r) -> r
withPool allocator :: Allocator
allocator pCreateInfo :: PoolCreateInfo
pCreateInfo b :: io Pool -> (Pool -> io ()) -> r
b =
  io Pool -> (Pool -> io ()) -> r
b (Allocator -> PoolCreateInfo -> io Pool
forall (io :: * -> *).
MonadIO io =>
Allocator -> PoolCreateInfo -> io Pool
createPool Allocator
allocator PoolCreateInfo
pCreateInfo)
    (\(Pool
o0) -> Allocator -> Pool -> io ()
forall (io :: * -> *). MonadIO io => Allocator -> Pool -> io ()
destroyPool Allocator
allocator Pool
o0)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaDestroyPool" ffiVmaDestroyPool
  :: Allocator -> Pool -> IO ()

-- | Destroys 'Pool' object and frees Vulkan device memory.
destroyPool :: forall io
             . (MonadIO io)
            => -- No documentation found for Nested "vmaDestroyPool" "allocator"
               Allocator
            -> -- No documentation found for Nested "vmaDestroyPool" "pool"
               Pool
            -> io ()
destroyPool :: Allocator -> Pool -> io ()
destroyPool allocator :: Allocator
allocator pool :: Pool
pool = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  (Allocator -> Pool -> IO ()
ffiVmaDestroyPool) (Allocator
allocator) (Pool
pool)
  () -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> IO ()) -> () -> IO ()
forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaGetPoolStats" ffiVmaGetPoolStats
  :: Allocator -> Pool -> Ptr PoolStats -> IO ()

-- | Retrieves statistics of existing 'Pool' object.
--
-- __Parameters.__
--
-- +-----------+------------+-----------------------------------------------+
-- |           | allocator  | Allocator object.                             |
-- +-----------+------------+-----------------------------------------------+
-- |           | pool       | Pool object.                                  |
-- +-----------+------------+-----------------------------------------------+
-- | out       | pPoolStats | Statistics of specified pool.                 |
-- +-----------+------------+-----------------------------------------------+
getPoolStats :: forall io
              . (MonadIO io)
             => -- No documentation found for Nested "vmaGetPoolStats" "allocator"
                Allocator
             -> -- No documentation found for Nested "vmaGetPoolStats" "pool"
                Pool
             -> io (PoolStats)
getPoolStats :: Allocator -> Pool -> io PoolStats
getPoolStats allocator :: Allocator
allocator pool :: Pool
pool = IO PoolStats -> io PoolStats
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO PoolStats -> io PoolStats)
-> (ContT PoolStats IO PoolStats -> IO PoolStats)
-> ContT PoolStats IO PoolStats
-> io PoolStats
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT PoolStats IO PoolStats -> IO PoolStats
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT PoolStats IO PoolStats -> io PoolStats)
-> ContT PoolStats IO PoolStats -> io PoolStats
forall a b. (a -> b) -> a -> b
$ do
  Ptr PoolStats
pPPoolStats <- ((Ptr PoolStats -> IO PoolStats) -> IO PoolStats)
-> ContT PoolStats IO (Ptr PoolStats)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b. ToCStruct PoolStats => (Ptr PoolStats -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @PoolStats)
  IO () -> ContT PoolStats IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT PoolStats IO ()) -> IO () -> ContT PoolStats IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Pool -> Ptr PoolStats -> IO ()
ffiVmaGetPoolStats) (Allocator
allocator) (Pool
pool) (Ptr PoolStats
pPPoolStats)
  PoolStats
pPoolStats <- IO PoolStats -> ContT PoolStats IO PoolStats
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO PoolStats -> ContT PoolStats IO PoolStats)
-> IO PoolStats -> ContT PoolStats IO PoolStats
forall a b. (a -> b) -> a -> b
$ Ptr PoolStats -> IO PoolStats
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @PoolStats Ptr PoolStats
pPPoolStats
  PoolStats -> ContT PoolStats IO PoolStats
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PoolStats -> ContT PoolStats IO PoolStats)
-> PoolStats -> ContT PoolStats IO PoolStats
forall a b. (a -> b) -> a -> b
$ (PoolStats
pPoolStats)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaMakePoolAllocationsLost" ffiVmaMakePoolAllocationsLost
  :: Allocator -> Pool -> Ptr CSize -> IO ()

-- | Marks all allocations in given pool as lost if they are not used in
-- current frame or /VmaPoolCreateInfo::frameInUseCount/ back from now.
--
-- __Parameters.__
--
-- +-----------+----------------------+-----------------------------------------------+
-- |           | allocator            | Allocator object.                             |
-- +-----------+----------------------+-----------------------------------------------+
-- |           | pool                 | Pool.                                         |
-- +-----------+----------------------+-----------------------------------------------+
-- | out       | pLostAllocationCount | Number of allocations marked as lost.         |
-- |           |                      | Optional - pass null if you don\'t need this  |
-- |           |                      | information.                                  |
-- +-----------+----------------------+-----------------------------------------------+
makePoolAllocationsLost :: forall io
                         . (MonadIO io)
                        => -- No documentation found for Nested "vmaMakePoolAllocationsLost" "allocator"
                           Allocator
                        -> -- No documentation found for Nested "vmaMakePoolAllocationsLost" "pool"
                           Pool
                        -> io (("lostAllocationCount" ::: Word64))
makePoolAllocationsLost :: Allocator -> Pool -> io ("lostAllocationCount" ::: Word64)
makePoolAllocationsLost allocator :: Allocator
allocator pool :: Pool
pool = IO ("lostAllocationCount" ::: Word64)
-> io ("lostAllocationCount" ::: Word64)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("lostAllocationCount" ::: Word64)
 -> io ("lostAllocationCount" ::: Word64))
-> (ContT
      ("lostAllocationCount" ::: Word64)
      IO
      ("lostAllocationCount" ::: Word64)
    -> IO ("lostAllocationCount" ::: Word64))
-> ContT
     ("lostAllocationCount" ::: Word64)
     IO
     ("lostAllocationCount" ::: Word64)
-> io ("lostAllocationCount" ::: Word64)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  ("lostAllocationCount" ::: Word64)
  IO
  ("lostAllocationCount" ::: Word64)
-> IO ("lostAllocationCount" ::: Word64)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   ("lostAllocationCount" ::: Word64)
   IO
   ("lostAllocationCount" ::: Word64)
 -> io ("lostAllocationCount" ::: Word64))
-> ContT
     ("lostAllocationCount" ::: Word64)
     IO
     ("lostAllocationCount" ::: Word64)
-> io ("lostAllocationCount" ::: Word64)
forall a b. (a -> b) -> a -> b
$ do
  Ptr CSize
pPLostAllocationCount <- ((Ptr CSize -> IO ("lostAllocationCount" ::: Word64))
 -> IO ("lostAllocationCount" ::: Word64))
-> ContT ("lostAllocationCount" ::: Word64) IO (Ptr CSize)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr CSize -> IO ("lostAllocationCount" ::: Word64))
  -> IO ("lostAllocationCount" ::: Word64))
 -> ContT ("lostAllocationCount" ::: Word64) IO (Ptr CSize))
-> ((Ptr CSize -> IO ("lostAllocationCount" ::: Word64))
    -> IO ("lostAllocationCount" ::: Word64))
-> ContT ("lostAllocationCount" ::: Word64) IO (Ptr CSize)
forall a b. (a -> b) -> a -> b
$ IO (Ptr CSize)
-> (Ptr CSize -> IO ())
-> (Ptr CSize -> IO ("lostAllocationCount" ::: Word64))
-> IO ("lostAllocationCount" ::: Word64)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr CSize)
forall a. Int -> IO (Ptr a)
callocBytes @CSize 8) Ptr CSize -> IO ()
forall a. Ptr a -> IO ()
free
  IO () -> ContT ("lostAllocationCount" ::: Word64) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("lostAllocationCount" ::: Word64) IO ())
-> IO () -> ContT ("lostAllocationCount" ::: Word64) IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Pool -> Ptr CSize -> IO ()
ffiVmaMakePoolAllocationsLost) (Allocator
allocator) (Pool
pool) (Ptr CSize
pPLostAllocationCount)
  CSize
pLostAllocationCount <- IO CSize -> ContT ("lostAllocationCount" ::: Word64) IO CSize
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO CSize -> ContT ("lostAllocationCount" ::: Word64) IO CSize)
-> IO CSize -> ContT ("lostAllocationCount" ::: Word64) IO CSize
forall a b. (a -> b) -> a -> b
$ Ptr CSize -> IO CSize
forall a. Storable a => Ptr a -> IO a
peek @CSize Ptr CSize
pPLostAllocationCount
  ("lostAllocationCount" ::: Word64)
-> ContT
     ("lostAllocationCount" ::: Word64)
     IO
     ("lostAllocationCount" ::: Word64)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("lostAllocationCount" ::: Word64)
 -> ContT
      ("lostAllocationCount" ::: Word64)
      IO
      ("lostAllocationCount" ::: Word64))
-> ("lostAllocationCount" ::: Word64)
-> ContT
     ("lostAllocationCount" ::: Word64)
     IO
     ("lostAllocationCount" ::: Word64)
forall a b. (a -> b) -> a -> b
$ (((\(CSize a :: "lostAllocationCount" ::: Word64
a) -> "lostAllocationCount" ::: Word64
a) CSize
pLostAllocationCount))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaCheckPoolCorruption" ffiVmaCheckPoolCorruption
  :: Allocator -> Pool -> IO Result

-- | Checks magic number in margins around all allocations in given memory
-- pool in search for corruptions.
--
-- Corruption detection is enabled only when @VMA_DEBUG_DETECT_CORRUPTION@
-- macro is defined to nonzero, @VMA_DEBUG_MARGIN@ is defined to nonzero
-- and the pool is created in memory type that is @HOST_VISIBLE@ and
-- @HOST_COHERENT@. For more information, see /Corruption detection/.
--
-- Possible return values:
--
-- -   @VK_ERROR_FEATURE_NOT_PRESENT@ - corruption detection is not enabled
--     for specified pool.
--
-- -   @VK_SUCCESS@ - corruption detection has been performed and
--     succeeded.
--
-- -   @VK_ERROR_VALIDATION_FAILED_EXT@ - corruption detection has been
--     performed and found memory corruptions around one of the
--     allocations. @VMA_ASSERT@ is also fired in that case.
--
-- -   Other value: Error returned by Vulkan, e.g. memory mapping failure.
checkPoolCorruption :: forall io
                     . (MonadIO io)
                    => -- No documentation found for Nested "vmaCheckPoolCorruption" "allocator"
                       Allocator
                    -> -- No documentation found for Nested "vmaCheckPoolCorruption" "pool"
                       Pool
                    -> io ()
checkPoolCorruption :: Allocator -> Pool -> io ()
checkPoolCorruption allocator :: Allocator
allocator pool :: Pool
pool = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator -> Pool -> IO Result
ffiVmaCheckPoolCorruption) (Allocator
allocator) (Pool
pool)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaGetPoolName" ffiVmaGetPoolName
  :: Allocator -> Pool -> Ptr (Ptr CChar) -> IO ()

-- | Retrieves name of a custom pool.
--
-- After the call @ppName@ is either null or points to an internally-owned
-- null-terminated string containing name of the pool that was previously
-- set. The pointer becomes invalid when the pool is destroyed or its name
-- is changed using 'setPoolName'.
getPoolName :: forall io
             . (MonadIO io)
            => -- No documentation found for Nested "vmaGetPoolName" "allocator"
               Allocator
            -> -- No documentation found for Nested "vmaGetPoolName" "pool"
               Pool
            -> io (("name" ::: Ptr CChar))
getPoolName :: Allocator -> Pool -> io ("statsString" ::: Ptr CChar)
getPoolName allocator :: Allocator
allocator pool :: Pool
pool = IO ("statsString" ::: Ptr CChar)
-> io ("statsString" ::: Ptr CChar)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("statsString" ::: Ptr CChar)
 -> io ("statsString" ::: Ptr CChar))
-> (ContT
      ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
    -> IO ("statsString" ::: Ptr CChar))
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
-> io ("statsString" ::: Ptr CChar)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
-> IO ("statsString" ::: Ptr CChar)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
 -> io ("statsString" ::: Ptr CChar))
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
-> io ("statsString" ::: Ptr CChar)
forall a b. (a -> b) -> a -> b
$ do
  Ptr ("statsString" ::: Ptr CChar)
pPpName <- ((Ptr ("statsString" ::: Ptr CChar)
  -> IO ("statsString" ::: Ptr CChar))
 -> IO ("statsString" ::: Ptr CChar))
-> ContT
     ("statsString" ::: Ptr CChar)
     IO
     (Ptr ("statsString" ::: Ptr CChar))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("statsString" ::: Ptr CChar)
   -> IO ("statsString" ::: Ptr CChar))
  -> IO ("statsString" ::: Ptr CChar))
 -> ContT
      ("statsString" ::: Ptr CChar)
      IO
      (Ptr ("statsString" ::: Ptr CChar)))
-> ((Ptr ("statsString" ::: Ptr CChar)
     -> IO ("statsString" ::: Ptr CChar))
    -> IO ("statsString" ::: Ptr CChar))
-> ContT
     ("statsString" ::: Ptr CChar)
     IO
     (Ptr ("statsString" ::: Ptr CChar))
forall a b. (a -> b) -> a -> b
$ IO (Ptr ("statsString" ::: Ptr CChar))
-> (Ptr ("statsString" ::: Ptr CChar) -> IO ())
-> (Ptr ("statsString" ::: Ptr CChar)
    -> IO ("statsString" ::: Ptr CChar))
-> IO ("statsString" ::: Ptr CChar)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr ("statsString" ::: Ptr CChar))
forall a. Int -> IO (Ptr a)
callocBytes @(Ptr CChar) 8) Ptr ("statsString" ::: Ptr CChar) -> IO ()
forall a. Ptr a -> IO ()
free
  IO () -> ContT ("statsString" ::: Ptr CChar) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("statsString" ::: Ptr CChar) IO ())
-> IO () -> ContT ("statsString" ::: Ptr CChar) IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Pool -> Ptr ("statsString" ::: Ptr CChar) -> IO ()
ffiVmaGetPoolName) (Allocator
allocator) (Pool
pool) (Ptr ("statsString" ::: Ptr CChar)
pPpName)
  "statsString" ::: Ptr CChar
ppName <- IO ("statsString" ::: Ptr CChar)
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("statsString" ::: Ptr CChar)
 -> ContT
      ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar))
-> IO ("statsString" ::: Ptr CChar)
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
forall a b. (a -> b) -> a -> b
$ Ptr ("statsString" ::: Ptr CChar)
-> IO ("statsString" ::: Ptr CChar)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr CChar) Ptr ("statsString" ::: Ptr CChar)
pPpName
  ("statsString" ::: Ptr CChar)
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("statsString" ::: Ptr CChar)
 -> ContT
      ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar))
-> ("statsString" ::: Ptr CChar)
-> ContT
     ("statsString" ::: Ptr CChar) IO ("statsString" ::: Ptr CChar)
forall a b. (a -> b) -> a -> b
$ ("statsString" ::: Ptr CChar
ppName)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaSetPoolName" ffiVmaSetPoolName
  :: Allocator -> Pool -> Ptr CChar -> IO ()

-- | Sets name of a custom pool.
--
-- @pName@ can be either null or pointer to a null-terminated string with
-- new name for the pool. Function makes internal copy of the string, so it
-- can be changed or freed immediately after this call.
setPoolName :: forall io
             . (MonadIO io)
            => -- No documentation found for Nested "vmaSetPoolName" "allocator"
               Allocator
            -> -- No documentation found for Nested "vmaSetPoolName" "pool"
               Pool
            -> -- No documentation found for Nested "vmaSetPoolName" "pName"
               ("name" ::: Maybe ByteString)
            -> io ()
setPoolName :: Allocator -> Pool -> ("name" ::: Maybe ByteString) -> io ()
setPoolName allocator :: Allocator
allocator pool :: Pool
pool name :: "name" ::: Maybe ByteString
name = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ())
-> (ContT () IO () -> IO ()) -> ContT () IO () -> io ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> io ()) -> ContT () IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  "statsString" ::: Ptr CChar
pName <- case ("name" ::: Maybe ByteString
name) of
    Nothing -> ("statsString" ::: Ptr CChar)
-> ContT () IO ("statsString" ::: Ptr CChar)
forall (f :: * -> *) a. Applicative f => a -> f a
pure "statsString" ::: Ptr CChar
forall a. Ptr a
nullPtr
    Just j :: ByteString
j -> ((("statsString" ::: Ptr CChar) -> IO ()) -> IO ())
-> ContT () IO ("statsString" ::: Ptr CChar)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("statsString" ::: Ptr CChar) -> IO ()) -> IO ())
 -> ContT () IO ("statsString" ::: Ptr CChar))
-> ((("statsString" ::: Ptr CChar) -> IO ()) -> IO ())
-> ContT () IO ("statsString" ::: Ptr CChar)
forall a b. (a -> b) -> a -> b
$ ByteString -> (("statsString" ::: Ptr CChar) -> IO ()) -> IO ()
forall a.
ByteString -> (("statsString" ::: Ptr CChar) -> IO a) -> IO a
useAsCString (ByteString
j)
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Pool -> ("statsString" ::: Ptr CChar) -> IO ()
ffiVmaSetPoolName) (Allocator
allocator) (Pool
pool) "statsString" ::: Ptr CChar
pName
  () -> ContT () IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> ContT () IO ()) -> () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaAllocateMemory" ffiVmaAllocateMemory
  :: Allocator -> Ptr MemoryRequirements -> Ptr AllocationCreateInfo -> Ptr Allocation -> Ptr AllocationInfo -> IO Result

-- | General purpose memory allocation.
--
-- __Parameters.__
--
-- +-----------+-----------------+-----------------------------------------------+
-- | out       | pAllocation     | Handle to allocated memory.                   |
-- +-----------+-----------------+-----------------------------------------------+
-- | out       | pAllocationInfo | Optional. Information about allocated memory. |
-- |           |                 | It can be later fetched using function        |
-- |           |                 | 'getAllocationInfo'.                          |
-- +-----------+-----------------+-----------------------------------------------+
--
-- You should free the memory using 'freeMemory' or 'freeMemoryPages'.
--
-- It is recommended to use 'allocateMemoryForBuffer',
-- 'allocateMemoryForImage', 'createBuffer', 'createImage' instead whenever
-- possible.
allocateMemory :: forall io
                . (MonadIO io)
               => -- No documentation found for Nested "vmaAllocateMemory" "allocator"
                  Allocator
               -> -- No documentation found for Nested "vmaAllocateMemory" "pVkMemoryRequirements"
                  ("vkMemoryRequirements" ::: MemoryRequirements)
               -> -- No documentation found for Nested "vmaAllocateMemory" "pCreateInfo"
                  AllocationCreateInfo
               -> io (Allocation, AllocationInfo)
allocateMemory :: Allocator
-> ("vkMemoryRequirements" ::: MemoryRequirements)
-> AllocationCreateInfo
-> io (Allocation, AllocationInfo)
allocateMemory allocator :: Allocator
allocator vkMemoryRequirements :: "vkMemoryRequirements" ::: MemoryRequirements
vkMemoryRequirements createInfo :: AllocationCreateInfo
createInfo = IO (Allocation, AllocationInfo) -> io (Allocation, AllocationInfo)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Allocation, AllocationInfo)
 -> io (Allocation, AllocationInfo))
-> (ContT
      (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
    -> IO (Allocation, AllocationInfo))
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
-> io (Allocation, AllocationInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
-> IO (Allocation, AllocationInfo)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
 -> io (Allocation, AllocationInfo))
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
-> io (Allocation, AllocationInfo)
forall a b. (a -> b) -> a -> b
$ do
  Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
pVkMemoryRequirements <- ((Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
  -> IO (Allocation, AllocationInfo))
 -> IO (Allocation, AllocationInfo))
-> ContT
     (Allocation, AllocationInfo)
     IO
     (Ptr ("vkMemoryRequirements" ::: MemoryRequirements))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
   -> IO (Allocation, AllocationInfo))
  -> IO (Allocation, AllocationInfo))
 -> ContT
      (Allocation, AllocationInfo)
      IO
      (Ptr ("vkMemoryRequirements" ::: MemoryRequirements)))
-> ((Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
     -> IO (Allocation, AllocationInfo))
    -> IO (Allocation, AllocationInfo))
-> ContT
     (Allocation, AllocationInfo)
     IO
     (Ptr ("vkMemoryRequirements" ::: MemoryRequirements))
forall a b. (a -> b) -> a -> b
$ ("vkMemoryRequirements" ::: MemoryRequirements)
-> (Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
    -> IO (Allocation, AllocationInfo))
-> IO (Allocation, AllocationInfo)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct ("vkMemoryRequirements" ::: MemoryRequirements
vkMemoryRequirements)
  Ptr AllocationCreateInfo
pCreateInfo <- ((Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
 -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
  -> IO (Allocation, AllocationInfo))
 -> ContT
      (Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo))
-> ((Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
    -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo)
forall a b. (a -> b) -> a -> b
$ AllocationCreateInfo
-> (Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
-> IO (Allocation, AllocationInfo)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (AllocationCreateInfo
createInfo)
  Ptr Allocation
pPAllocation <- ((Ptr Allocation -> IO (Allocation, AllocationInfo))
 -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr Allocation)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocation -> IO (Allocation, AllocationInfo))
  -> IO (Allocation, AllocationInfo))
 -> ContT (Allocation, AllocationInfo) IO (Ptr Allocation))
-> ((Ptr Allocation -> IO (Allocation, AllocationInfo))
    -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr Allocation)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Allocation)
-> (Ptr Allocation -> IO ())
-> (Ptr Allocation -> IO (Allocation, AllocationInfo))
-> IO (Allocation, AllocationInfo)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Allocation)
forall a. Int -> IO (Ptr a)
callocBytes @Allocation 8) Ptr Allocation -> IO ()
forall a. Ptr a -> IO ()
free
  Ptr AllocationInfo
pPAllocationInfo <- ((Ptr AllocationInfo -> IO (Allocation, AllocationInfo))
 -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr AllocationInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct AllocationInfo =>
(Ptr AllocationInfo -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @AllocationInfo)
  Result
r <- IO Result -> ContT (Allocation, AllocationInfo) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT (Allocation, AllocationInfo) IO Result)
-> IO Result -> ContT (Allocation, AllocationInfo) IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
-> Ptr AllocationCreateInfo
-> Ptr Allocation
-> Ptr AllocationInfo
-> IO Result
ffiVmaAllocateMemory) (Allocator
allocator) Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
pVkMemoryRequirements Ptr AllocationCreateInfo
pCreateInfo (Ptr Allocation
pPAllocation) (Ptr AllocationInfo
pPAllocationInfo)
  IO () -> ContT (Allocation, AllocationInfo) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT (Allocation, AllocationInfo) IO ())
-> IO () -> ContT (Allocation, AllocationInfo) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  Allocation
pAllocation <- IO Allocation -> ContT (Allocation, AllocationInfo) IO Allocation
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Allocation -> ContT (Allocation, AllocationInfo) IO Allocation)
-> IO Allocation
-> ContT (Allocation, AllocationInfo) IO Allocation
forall a b. (a -> b) -> a -> b
$ Ptr Allocation -> IO Allocation
forall a. Storable a => Ptr a -> IO a
peek @Allocation Ptr Allocation
pPAllocation
  AllocationInfo
pAllocationInfo <- IO AllocationInfo
-> ContT (Allocation, AllocationInfo) IO AllocationInfo
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO AllocationInfo
 -> ContT (Allocation, AllocationInfo) IO AllocationInfo)
-> IO AllocationInfo
-> ContT (Allocation, AllocationInfo) IO AllocationInfo
forall a b. (a -> b) -> a -> b
$ Ptr AllocationInfo -> IO AllocationInfo
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @AllocationInfo Ptr AllocationInfo
pPAllocationInfo
  (Allocation, AllocationInfo)
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Allocation, AllocationInfo)
 -> ContT
      (Allocation, AllocationInfo) IO (Allocation, AllocationInfo))
-> (Allocation, AllocationInfo)
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
forall a b. (a -> b) -> a -> b
$ (Allocation
pAllocation, AllocationInfo
pAllocationInfo)

-- | A convenience wrapper to make a compatible pair of calls to
-- 'allocateMemory' and 'freeMemory'
--
-- To ensure that 'freeMemory' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the first argument.
-- To just extract the pair pass '(,)' as the first argument.
--
withMemory :: forall io r . MonadIO io => Allocator -> MemoryRequirements -> AllocationCreateInfo -> (io (Allocation, AllocationInfo) -> ((Allocation, AllocationInfo) -> io ()) -> r) -> r
withMemory :: Allocator
-> ("vkMemoryRequirements" ::: MemoryRequirements)
-> AllocationCreateInfo
-> (io (Allocation, AllocationInfo)
    -> ((Allocation, AllocationInfo) -> io ()) -> r)
-> r
withMemory allocator :: Allocator
allocator pVkMemoryRequirements :: "vkMemoryRequirements" ::: MemoryRequirements
pVkMemoryRequirements pCreateInfo :: AllocationCreateInfo
pCreateInfo b :: io (Allocation, AllocationInfo)
-> ((Allocation, AllocationInfo) -> io ()) -> r
b =
  io (Allocation, AllocationInfo)
-> ((Allocation, AllocationInfo) -> io ()) -> r
b (Allocator
-> ("vkMemoryRequirements" ::: MemoryRequirements)
-> AllocationCreateInfo
-> io (Allocation, AllocationInfo)
forall (io :: * -> *).
MonadIO io =>
Allocator
-> ("vkMemoryRequirements" ::: MemoryRequirements)
-> AllocationCreateInfo
-> io (Allocation, AllocationInfo)
allocateMemory Allocator
allocator "vkMemoryRequirements" ::: MemoryRequirements
pVkMemoryRequirements AllocationCreateInfo
pCreateInfo)
    (\(o0 :: Allocation
o0, _) -> Allocator -> Allocation -> io ()
forall (io :: * -> *).
MonadIO io =>
Allocator -> Allocation -> io ()
freeMemory Allocator
allocator Allocation
o0)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaAllocateMemoryPages" ffiVmaAllocateMemoryPages
  :: Allocator -> Ptr MemoryRequirements -> Ptr AllocationCreateInfo -> CSize -> Ptr Allocation -> Ptr AllocationInfo -> IO Result

-- | General purpose memory allocation for multiple allocation objects at
-- once.
--
-- __Parameters.__
--
-- +-----------+-----------------------+-----------------------------------------------+
-- |           | allocator             | Allocator object.                             |
-- +-----------+-----------------------+-----------------------------------------------+
-- |           | pVkMemoryRequirements | Memory requirements for each allocation.      |
-- +-----------+-----------------------+-----------------------------------------------+
-- |           | pCreateInfo           | Creation parameters for each alloction.       |
-- +-----------+-----------------------+-----------------------------------------------+
-- |           | allocationCount       | Number of allocations to make.                |
-- +-----------+-----------------------+-----------------------------------------------+
-- | out       | pAllocations          | Pointer to array that will be filled with     |
-- |           |                       | handles to created allocations.               |
-- +-----------+-----------------------+-----------------------------------------------+
-- | out       | pAllocationInfo       | Optional. Pointer to array that will be       |
-- |           |                       | filled with parameters of created             |
-- |           |                       | allocations.                                  |
-- +-----------+-----------------------+-----------------------------------------------+
--
-- You should free the memory using 'freeMemory' or 'freeMemoryPages'.
--
-- Word \"pages\" is just a suggestion to use this function to allocate
-- pieces of memory needed for sparse binding. It is just a general purpose
-- allocation function able to make multiple allocations at once. It may be
-- internally optimized to be more efficient than calling 'allocateMemory'
-- @allocationCount@ times.
--
-- All allocations are made using same parameters. All of them are created
-- out of the same memory pool and type. If any allocation fails, all
-- allocations already made within this function call are also freed, so
-- that when returned result is not @VK_SUCCESS@, @pAllocation@ array is
-- always entirely filled with @VK_NULL_HANDLE@.
allocateMemoryPages :: forall io
                     . (MonadIO io)
                    => -- No documentation found for Nested "vmaAllocateMemoryPages" "allocator"
                       Allocator
                    -> -- No documentation found for Nested "vmaAllocateMemoryPages" "pVkMemoryRequirements"
                       ("vkMemoryRequirements" ::: Vector MemoryRequirements)
                    -> -- No documentation found for Nested "vmaAllocateMemoryPages" "pCreateInfo"
                       ("createInfo" ::: Vector AllocationCreateInfo)
                    -> io (("allocations" ::: Vector Allocation), ("allocationInfo" ::: Vector AllocationInfo))
allocateMemoryPages :: Allocator
-> ("vkMemoryRequirements"
    ::: Vector ("vkMemoryRequirements" ::: MemoryRequirements))
-> ("createInfo" ::: Vector AllocationCreateInfo)
-> io
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
allocateMemoryPages allocator :: Allocator
allocator vkMemoryRequirements :: "vkMemoryRequirements"
::: Vector ("vkMemoryRequirements" ::: MemoryRequirements)
vkMemoryRequirements createInfo :: "createInfo" ::: Vector AllocationCreateInfo
createInfo = IO
  ("allocations" ::: Vector Allocation,
   "allocationInfo" ::: Vector AllocationInfo)
-> io
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO
   ("allocations" ::: Vector Allocation,
    "allocationInfo" ::: Vector AllocationInfo)
 -> io
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> (ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
-> io
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  ("allocations" ::: Vector Allocation,
   "allocationInfo" ::: Vector AllocationInfo)
  IO
  ("allocations" ::: Vector Allocation,
   "allocationInfo" ::: Vector AllocationInfo)
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   ("allocations" ::: Vector Allocation,
    "allocationInfo" ::: Vector AllocationInfo)
   IO
   ("allocations" ::: Vector Allocation,
    "allocationInfo" ::: Vector AllocationInfo)
 -> io
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
-> io
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall a b. (a -> b) -> a -> b
$ do
  Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
pPVkMemoryRequirements <- ((Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     (Ptr ("vkMemoryRequirements" ::: MemoryRequirements))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
   -> IO
        ("allocations" ::: Vector Allocation,
         "allocationInfo" ::: Vector AllocationInfo))
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      (Ptr ("vkMemoryRequirements" ::: MemoryRequirements)))
-> ((Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
     -> IO
          ("allocations" ::: Vector Allocation,
           "allocationInfo" ::: Vector AllocationInfo))
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     (Ptr ("vkMemoryRequirements" ::: MemoryRequirements))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> (Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned @MemoryRequirements ((("vkMemoryRequirements"
 ::: Vector ("vkMemoryRequirements" ::: MemoryRequirements))
-> Int
forall a. Vector a -> Int
Data.Vector.length ("vkMemoryRequirements"
::: Vector ("vkMemoryRequirements" ::: MemoryRequirements)
vkMemoryRequirements)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 24) 8
  (Int
 -> ("vkMemoryRequirements" ::: MemoryRequirements)
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ())
-> ("vkMemoryRequirements"
    ::: Vector ("vkMemoryRequirements" ::: MemoryRequirements))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\i :: Int
i e :: "vkMemoryRequirements" ::: MemoryRequirements
e -> ((()
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((()
   -> IO
        ("allocations" ::: Vector Allocation,
         "allocationInfo" ::: Vector AllocationInfo))
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ())
-> ((()
     -> IO
          ("allocations" ::: Vector Allocation,
           "allocationInfo" ::: Vector AllocationInfo))
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall a b. (a -> b) -> a -> b
$ Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
-> ("vkMemoryRequirements" ::: MemoryRequirements)
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct (Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
pPVkMemoryRequirements Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
-> Int -> Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (24 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr MemoryRequirements) ("vkMemoryRequirements" ::: MemoryRequirements
e) (IO
   ("allocations" ::: Vector Allocation,
    "allocationInfo" ::: Vector AllocationInfo)
 -> IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ((()
     -> IO
          ("allocations" ::: Vector Allocation,
           "allocationInfo" ::: Vector AllocationInfo))
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> (()
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((()
 -> IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ()
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall a b. (a -> b) -> a -> b
$ ())) ("vkMemoryRequirements"
::: Vector ("vkMemoryRequirements" ::: MemoryRequirements)
vkMemoryRequirements)
  Ptr AllocationCreateInfo
pPCreateInfo <- ((Ptr AllocationCreateInfo
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     (Ptr AllocationCreateInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr AllocationCreateInfo
   -> IO
        ("allocations" ::: Vector Allocation,
         "allocationInfo" ::: Vector AllocationInfo))
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      (Ptr AllocationCreateInfo))
-> ((Ptr AllocationCreateInfo
     -> IO
          ("allocations" ::: Vector Allocation,
           "allocationInfo" ::: Vector AllocationInfo))
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     (Ptr AllocationCreateInfo)
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> (Ptr AllocationCreateInfo
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned @AllocationCreateInfo ((("createInfo" ::: Vector AllocationCreateInfo) -> Int
forall a. Vector a -> Int
Data.Vector.length ("createInfo" ::: Vector AllocationCreateInfo
createInfo)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 40) 8
  IO ()
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ()
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ())
-> IO ()
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall a b. (a -> b) -> a -> b
$ (Int -> AllocationCreateInfo -> IO ())
-> ("createInfo" ::: Vector AllocationCreateInfo) -> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\i :: Int
i e :: AllocationCreateInfo
e -> Ptr AllocationCreateInfo -> AllocationCreateInfo -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr AllocationCreateInfo
pPCreateInfo Ptr AllocationCreateInfo -> Int -> Ptr AllocationCreateInfo
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (40 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr AllocationCreateInfo) (AllocationCreateInfo
e)) ("createInfo" ::: Vector AllocationCreateInfo
createInfo)
  let pVkMemoryRequirementsLength :: Int
pVkMemoryRequirementsLength = ("vkMemoryRequirements"
 ::: Vector ("vkMemoryRequirements" ::: MemoryRequirements))
-> Int
forall a. Vector a -> Int
Data.Vector.length (("vkMemoryRequirements"
  ::: Vector ("vkMemoryRequirements" ::: MemoryRequirements))
 -> Int)
-> ("vkMemoryRequirements"
    ::: Vector ("vkMemoryRequirements" ::: MemoryRequirements))
-> Int
forall a b. (a -> b) -> a -> b
$ ("vkMemoryRequirements"
::: Vector ("vkMemoryRequirements" ::: MemoryRequirements)
vkMemoryRequirements)
  IO ()
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ()
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ())
-> IO ()
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ((("createInfo" ::: Vector AllocationCreateInfo) -> Int
forall a. Vector a -> Int
Data.Vector.length (("createInfo" ::: Vector AllocationCreateInfo) -> Int)
-> ("createInfo" ::: Vector AllocationCreateInfo) -> Int
forall a b. (a -> b) -> a -> b
$ ("createInfo" ::: Vector AllocationCreateInfo
createInfo)) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
pVkMemoryRequirementsLength) (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 "" "pCreateInfo and pVkMemoryRequirements must have the same length" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  Ptr Allocation
pPAllocations <- ((Ptr Allocation
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     (Ptr Allocation)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocation
   -> IO
        ("allocations" ::: Vector Allocation,
         "allocationInfo" ::: Vector AllocationInfo))
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      (Ptr Allocation))
-> ((Ptr Allocation
     -> IO
          ("allocations" ::: Vector Allocation,
           "allocationInfo" ::: Vector AllocationInfo))
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     (Ptr Allocation)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Allocation)
-> (Ptr Allocation -> IO ())
-> (Ptr Allocation
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Allocation)
forall a. Int -> IO (Ptr a)
callocBytes @Allocation ((CSize -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
pVkMemoryRequirementsLength :: CSize))) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8)) Ptr Allocation -> IO ()
forall a. Ptr a -> IO ()
free
  Ptr AllocationInfo
pPAllocationInfo <- ((Ptr AllocationInfo
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     (Ptr AllocationInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr AllocationInfo
   -> IO
        ("allocations" ::: Vector Allocation,
         "allocationInfo" ::: Vector AllocationInfo))
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      (Ptr AllocationInfo))
-> ((Ptr AllocationInfo
     -> IO
          ("allocations" ::: Vector Allocation,
           "allocationInfo" ::: Vector AllocationInfo))
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     (Ptr AllocationInfo)
forall a b. (a -> b) -> a -> b
$ IO (Ptr AllocationInfo)
-> (Ptr AllocationInfo -> IO ())
-> (Ptr AllocationInfo
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr AllocationInfo)
forall a. Int -> IO (Ptr a)
callocBytes @AllocationInfo ((CSize -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
pVkMemoryRequirementsLength :: CSize))) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 48)) Ptr AllocationInfo -> IO ()
forall a. Ptr a -> IO ()
free
  [()]
_ <- (Int
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ())
-> [Int]
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     [()]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (\i :: Int
i -> ((()
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((()
   -> IO
        ("allocations" ::: Vector Allocation,
         "allocationInfo" ::: Vector AllocationInfo))
  -> IO
       ("allocations" ::: Vector Allocation,
        "allocationInfo" ::: Vector AllocationInfo))
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ())
-> ((()
     -> IO
          ("allocations" ::: Vector Allocation,
           "allocationInfo" ::: Vector AllocationInfo))
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall a b. (a -> b) -> a -> b
$ Ptr AllocationInfo
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall a b. ToCStruct a => Ptr a -> IO b -> IO b
pokeZeroCStruct (Ptr AllocationInfo
pPAllocationInfo Ptr AllocationInfo -> Int -> Ptr AllocationInfo
forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
* 48) :: Ptr AllocationInfo) (IO
   ("allocations" ::: Vector Allocation,
    "allocationInfo" ::: Vector AllocationInfo)
 -> IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ((()
     -> IO
          ("allocations" ::: Vector Allocation,
           "allocationInfo" ::: Vector AllocationInfo))
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> (()
    -> IO
         ("allocations" ::: Vector Allocation,
          "allocationInfo" ::: Vector AllocationInfo))
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((()
 -> IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ()
-> IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall a b. (a -> b) -> a -> b
$ ())) [0..(CSize -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
pVkMemoryRequirementsLength :: CSize))) Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1]
  Result
r <- IO Result
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      Result)
-> IO Result
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
-> Ptr AllocationCreateInfo
-> CSize
-> Ptr Allocation
-> Ptr AllocationInfo
-> IO Result
ffiVmaAllocateMemoryPages) (Allocator
allocator) (Ptr ("vkMemoryRequirements" ::: MemoryRequirements)
pPVkMemoryRequirements) (Ptr AllocationCreateInfo
pPCreateInfo) ((Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
pVkMemoryRequirementsLength :: CSize)) (Ptr Allocation
pPAllocations) ((Ptr AllocationInfo
pPAllocationInfo))
  IO ()
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ()
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ())
-> IO ()
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  "allocations" ::: Vector Allocation
pAllocations <- IO ("allocations" ::: Vector Allocation)
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ("allocations" ::: Vector Allocation)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("allocations" ::: Vector Allocation)
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ("allocations" ::: Vector Allocation))
-> IO ("allocations" ::: Vector Allocation)
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ("allocations" ::: Vector Allocation)
forall a b. (a -> b) -> a -> b
$ Int
-> (Int -> IO Allocation)
-> IO ("allocations" ::: Vector Allocation)
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (CSize -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
pVkMemoryRequirementsLength :: CSize))) (\i :: Int
i -> Ptr Allocation -> IO Allocation
forall a. Storable a => Ptr a -> IO a
peek @Allocation ((Ptr Allocation
pPAllocations Ptr Allocation -> Int -> Ptr Allocation
forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Allocation)))
  "allocationInfo" ::: Vector AllocationInfo
pAllocationInfo <- IO ("allocationInfo" ::: Vector AllocationInfo)
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ("allocationInfo" ::: Vector AllocationInfo)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("allocationInfo" ::: Vector AllocationInfo)
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ("allocationInfo" ::: Vector AllocationInfo))
-> IO ("allocationInfo" ::: Vector AllocationInfo)
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ("allocationInfo" ::: Vector AllocationInfo)
forall a b. (a -> b) -> a -> b
$ Int
-> (Int -> IO AllocationInfo)
-> IO ("allocationInfo" ::: Vector AllocationInfo)
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (CSize -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
pVkMemoryRequirementsLength :: CSize))) (\i :: Int
i -> Ptr AllocationInfo -> IO AllocationInfo
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @AllocationInfo (((Ptr AllocationInfo
pPAllocationInfo) Ptr AllocationInfo -> Int -> Ptr AllocationInfo
forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (48 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr AllocationInfo)))
  ("allocations" ::: Vector Allocation,
 "allocationInfo" ::: Vector AllocationInfo)
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("allocations" ::: Vector Allocation,
  "allocationInfo" ::: Vector AllocationInfo)
 -> ContT
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
      IO
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo))
-> ("allocations" ::: Vector Allocation,
    "allocationInfo" ::: Vector AllocationInfo)
-> ContT
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
     IO
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall a b. (a -> b) -> a -> b
$ ("allocations" ::: Vector Allocation
pAllocations, "allocationInfo" ::: Vector AllocationInfo
pAllocationInfo)

-- | A convenience wrapper to make a compatible pair of calls to
-- 'allocateMemoryPages' and 'freeMemoryPages'
--
-- To ensure that 'freeMemoryPages' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the first argument.
-- To just extract the pair pass '(,)' as the first argument.
--
withMemoryPages :: forall io r . MonadIO io => Allocator -> Vector MemoryRequirements -> Vector AllocationCreateInfo -> (io (Vector Allocation, Vector AllocationInfo) -> ((Vector Allocation, Vector AllocationInfo) -> io ()) -> r) -> r
withMemoryPages :: Allocator
-> ("vkMemoryRequirements"
    ::: Vector ("vkMemoryRequirements" ::: MemoryRequirements))
-> ("createInfo" ::: Vector AllocationCreateInfo)
-> (io
      ("allocations" ::: Vector Allocation,
       "allocationInfo" ::: Vector AllocationInfo)
    -> (("allocations" ::: Vector Allocation,
         "allocationInfo" ::: Vector AllocationInfo)
        -> io ())
    -> r)
-> r
withMemoryPages allocator :: Allocator
allocator pVkMemoryRequirements :: "vkMemoryRequirements"
::: Vector ("vkMemoryRequirements" ::: MemoryRequirements)
pVkMemoryRequirements pCreateInfo :: "createInfo" ::: Vector AllocationCreateInfo
pCreateInfo b :: io
  ("allocations" ::: Vector Allocation,
   "allocationInfo" ::: Vector AllocationInfo)
-> (("allocations" ::: Vector Allocation,
     "allocationInfo" ::: Vector AllocationInfo)
    -> io ())
-> r
b =
  io
  ("allocations" ::: Vector Allocation,
   "allocationInfo" ::: Vector AllocationInfo)
-> (("allocations" ::: Vector Allocation,
     "allocationInfo" ::: Vector AllocationInfo)
    -> io ())
-> r
b (Allocator
-> ("vkMemoryRequirements"
    ::: Vector ("vkMemoryRequirements" ::: MemoryRequirements))
-> ("createInfo" ::: Vector AllocationCreateInfo)
-> io
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
forall (io :: * -> *).
MonadIO io =>
Allocator
-> ("vkMemoryRequirements"
    ::: Vector ("vkMemoryRequirements" ::: MemoryRequirements))
-> ("createInfo" ::: Vector AllocationCreateInfo)
-> io
     ("allocations" ::: Vector Allocation,
      "allocationInfo" ::: Vector AllocationInfo)
allocateMemoryPages Allocator
allocator "vkMemoryRequirements"
::: Vector ("vkMemoryRequirements" ::: MemoryRequirements)
pVkMemoryRequirements "createInfo" ::: Vector AllocationCreateInfo
pCreateInfo)
    (\(o0 :: "allocations" ::: Vector Allocation
o0, _) -> Allocator -> ("allocations" ::: Vector Allocation) -> io ()
forall (io :: * -> *).
MonadIO io =>
Allocator -> ("allocations" ::: Vector Allocation) -> io ()
freeMemoryPages Allocator
allocator "allocations" ::: Vector Allocation
o0)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaAllocateMemoryForBuffer" ffiVmaAllocateMemoryForBuffer
  :: Allocator -> Buffer -> Ptr AllocationCreateInfo -> Ptr Allocation -> Ptr AllocationInfo -> IO Result

-- | __Parameters.__
--
-- +-----------+-----------------+-----------------------------------------------+
-- | out       | pAllocation     | Handle to allocated memory.                   |
-- +-----------+-----------------+-----------------------------------------------+
-- | out       | pAllocationInfo | Optional. Information about allocated memory. |
-- |           |                 | It can be later fetched using function        |
-- |           |                 | 'getAllocationInfo'.                          |
-- +-----------+-----------------+-----------------------------------------------+
--
-- You should free the memory using 'freeMemory'.
allocateMemoryForBuffer :: forall io
                         . (MonadIO io)
                        => -- No documentation found for Nested "vmaAllocateMemoryForBuffer" "allocator"
                           Allocator
                        -> -- No documentation found for Nested "vmaAllocateMemoryForBuffer" "buffer"
                           Buffer
                        -> -- No documentation found for Nested "vmaAllocateMemoryForBuffer" "pCreateInfo"
                           AllocationCreateInfo
                        -> io (Allocation, AllocationInfo)
allocateMemoryForBuffer :: Allocator
-> Buffer
-> AllocationCreateInfo
-> io (Allocation, AllocationInfo)
allocateMemoryForBuffer allocator :: Allocator
allocator buffer :: Buffer
buffer createInfo :: AllocationCreateInfo
createInfo = IO (Allocation, AllocationInfo) -> io (Allocation, AllocationInfo)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Allocation, AllocationInfo)
 -> io (Allocation, AllocationInfo))
-> (ContT
      (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
    -> IO (Allocation, AllocationInfo))
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
-> io (Allocation, AllocationInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
-> IO (Allocation, AllocationInfo)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
 -> io (Allocation, AllocationInfo))
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
-> io (Allocation, AllocationInfo)
forall a b. (a -> b) -> a -> b
$ do
  Ptr AllocationCreateInfo
pCreateInfo <- ((Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
 -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
  -> IO (Allocation, AllocationInfo))
 -> ContT
      (Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo))
-> ((Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
    -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo)
forall a b. (a -> b) -> a -> b
$ AllocationCreateInfo
-> (Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
-> IO (Allocation, AllocationInfo)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (AllocationCreateInfo
createInfo)
  Ptr Allocation
pPAllocation <- ((Ptr Allocation -> IO (Allocation, AllocationInfo))
 -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr Allocation)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocation -> IO (Allocation, AllocationInfo))
  -> IO (Allocation, AllocationInfo))
 -> ContT (Allocation, AllocationInfo) IO (Ptr Allocation))
-> ((Ptr Allocation -> IO (Allocation, AllocationInfo))
    -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr Allocation)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Allocation)
-> (Ptr Allocation -> IO ())
-> (Ptr Allocation -> IO (Allocation, AllocationInfo))
-> IO (Allocation, AllocationInfo)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Allocation)
forall a. Int -> IO (Ptr a)
callocBytes @Allocation 8) Ptr Allocation -> IO ()
forall a. Ptr a -> IO ()
free
  Ptr AllocationInfo
pPAllocationInfo <- ((Ptr AllocationInfo -> IO (Allocation, AllocationInfo))
 -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr AllocationInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct AllocationInfo =>
(Ptr AllocationInfo -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @AllocationInfo)
  Result
r <- IO Result -> ContT (Allocation, AllocationInfo) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT (Allocation, AllocationInfo) IO Result)
-> IO Result -> ContT (Allocation, AllocationInfo) IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> Buffer
-> Ptr AllocationCreateInfo
-> Ptr Allocation
-> Ptr AllocationInfo
-> IO Result
ffiVmaAllocateMemoryForBuffer) (Allocator
allocator) (Buffer
buffer) Ptr AllocationCreateInfo
pCreateInfo (Ptr Allocation
pPAllocation) (Ptr AllocationInfo
pPAllocationInfo)
  IO () -> ContT (Allocation, AllocationInfo) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT (Allocation, AllocationInfo) IO ())
-> IO () -> ContT (Allocation, AllocationInfo) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  Allocation
pAllocation <- IO Allocation -> ContT (Allocation, AllocationInfo) IO Allocation
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Allocation -> ContT (Allocation, AllocationInfo) IO Allocation)
-> IO Allocation
-> ContT (Allocation, AllocationInfo) IO Allocation
forall a b. (a -> b) -> a -> b
$ Ptr Allocation -> IO Allocation
forall a. Storable a => Ptr a -> IO a
peek @Allocation Ptr Allocation
pPAllocation
  AllocationInfo
pAllocationInfo <- IO AllocationInfo
-> ContT (Allocation, AllocationInfo) IO AllocationInfo
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO AllocationInfo
 -> ContT (Allocation, AllocationInfo) IO AllocationInfo)
-> IO AllocationInfo
-> ContT (Allocation, AllocationInfo) IO AllocationInfo
forall a b. (a -> b) -> a -> b
$ Ptr AllocationInfo -> IO AllocationInfo
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @AllocationInfo Ptr AllocationInfo
pPAllocationInfo
  (Allocation, AllocationInfo)
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Allocation, AllocationInfo)
 -> ContT
      (Allocation, AllocationInfo) IO (Allocation, AllocationInfo))
-> (Allocation, AllocationInfo)
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
forall a b. (a -> b) -> a -> b
$ (Allocation
pAllocation, AllocationInfo
pAllocationInfo)

-- | A convenience wrapper to make a compatible pair of calls to
-- 'allocateMemoryForBuffer' and 'freeMemory'
--
-- To ensure that 'freeMemory' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the first argument.
-- To just extract the pair pass '(,)' as the first argument.
--
withMemoryForBuffer :: forall io r . MonadIO io => Allocator -> Buffer -> AllocationCreateInfo -> (io (Allocation, AllocationInfo) -> ((Allocation, AllocationInfo) -> io ()) -> r) -> r
withMemoryForBuffer :: Allocator
-> Buffer
-> AllocationCreateInfo
-> (io (Allocation, AllocationInfo)
    -> ((Allocation, AllocationInfo) -> io ()) -> r)
-> r
withMemoryForBuffer allocator :: Allocator
allocator buffer :: Buffer
buffer pCreateInfo :: AllocationCreateInfo
pCreateInfo b :: io (Allocation, AllocationInfo)
-> ((Allocation, AllocationInfo) -> io ()) -> r
b =
  io (Allocation, AllocationInfo)
-> ((Allocation, AllocationInfo) -> io ()) -> r
b (Allocator
-> Buffer
-> AllocationCreateInfo
-> io (Allocation, AllocationInfo)
forall (io :: * -> *).
MonadIO io =>
Allocator
-> Buffer
-> AllocationCreateInfo
-> io (Allocation, AllocationInfo)
allocateMemoryForBuffer Allocator
allocator Buffer
buffer AllocationCreateInfo
pCreateInfo)
    (\(o0 :: Allocation
o0, _) -> Allocator -> Allocation -> io ()
forall (io :: * -> *).
MonadIO io =>
Allocator -> Allocation -> io ()
freeMemory Allocator
allocator Allocation
o0)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaAllocateMemoryForImage" ffiVmaAllocateMemoryForImage
  :: Allocator -> Image -> Ptr AllocationCreateInfo -> Ptr Allocation -> Ptr AllocationInfo -> IO Result

-- | Function similar to 'allocateMemoryForBuffer'.
allocateMemoryForImage :: forall io
                        . (MonadIO io)
                       => -- No documentation found for Nested "vmaAllocateMemoryForImage" "allocator"
                          Allocator
                       -> -- No documentation found for Nested "vmaAllocateMemoryForImage" "image"
                          Image
                       -> -- No documentation found for Nested "vmaAllocateMemoryForImage" "pCreateInfo"
                          AllocationCreateInfo
                       -> io (Allocation, AllocationInfo)
allocateMemoryForImage :: Allocator
-> Image -> AllocationCreateInfo -> io (Allocation, AllocationInfo)
allocateMemoryForImage allocator :: Allocator
allocator image :: Image
image createInfo :: AllocationCreateInfo
createInfo = IO (Allocation, AllocationInfo) -> io (Allocation, AllocationInfo)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Allocation, AllocationInfo)
 -> io (Allocation, AllocationInfo))
-> (ContT
      (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
    -> IO (Allocation, AllocationInfo))
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
-> io (Allocation, AllocationInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
-> IO (Allocation, AllocationInfo)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
 -> io (Allocation, AllocationInfo))
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
-> io (Allocation, AllocationInfo)
forall a b. (a -> b) -> a -> b
$ do
  Ptr AllocationCreateInfo
pCreateInfo <- ((Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
 -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
  -> IO (Allocation, AllocationInfo))
 -> ContT
      (Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo))
-> ((Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
    -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo)
forall a b. (a -> b) -> a -> b
$ AllocationCreateInfo
-> (Ptr AllocationCreateInfo -> IO (Allocation, AllocationInfo))
-> IO (Allocation, AllocationInfo)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (AllocationCreateInfo
createInfo)
  Ptr Allocation
pPAllocation <- ((Ptr Allocation -> IO (Allocation, AllocationInfo))
 -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr Allocation)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocation -> IO (Allocation, AllocationInfo))
  -> IO (Allocation, AllocationInfo))
 -> ContT (Allocation, AllocationInfo) IO (Ptr Allocation))
-> ((Ptr Allocation -> IO (Allocation, AllocationInfo))
    -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr Allocation)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Allocation)
-> (Ptr Allocation -> IO ())
-> (Ptr Allocation -> IO (Allocation, AllocationInfo))
-> IO (Allocation, AllocationInfo)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Allocation)
forall a. Int -> IO (Ptr a)
callocBytes @Allocation 8) Ptr Allocation -> IO ()
forall a. Ptr a -> IO ()
free
  Ptr AllocationInfo
pPAllocationInfo <- ((Ptr AllocationInfo -> IO (Allocation, AllocationInfo))
 -> IO (Allocation, AllocationInfo))
-> ContT (Allocation, AllocationInfo) IO (Ptr AllocationInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct AllocationInfo =>
(Ptr AllocationInfo -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @AllocationInfo)
  Result
r <- IO Result -> ContT (Allocation, AllocationInfo) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT (Allocation, AllocationInfo) IO Result)
-> IO Result -> ContT (Allocation, AllocationInfo) IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> Image
-> Ptr AllocationCreateInfo
-> Ptr Allocation
-> Ptr AllocationInfo
-> IO Result
ffiVmaAllocateMemoryForImage) (Allocator
allocator) (Image
image) Ptr AllocationCreateInfo
pCreateInfo (Ptr Allocation
pPAllocation) (Ptr AllocationInfo
pPAllocationInfo)
  IO () -> ContT (Allocation, AllocationInfo) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT (Allocation, AllocationInfo) IO ())
-> IO () -> ContT (Allocation, AllocationInfo) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  Allocation
pAllocation <- IO Allocation -> ContT (Allocation, AllocationInfo) IO Allocation
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Allocation -> ContT (Allocation, AllocationInfo) IO Allocation)
-> IO Allocation
-> ContT (Allocation, AllocationInfo) IO Allocation
forall a b. (a -> b) -> a -> b
$ Ptr Allocation -> IO Allocation
forall a. Storable a => Ptr a -> IO a
peek @Allocation Ptr Allocation
pPAllocation
  AllocationInfo
pAllocationInfo <- IO AllocationInfo
-> ContT (Allocation, AllocationInfo) IO AllocationInfo
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO AllocationInfo
 -> ContT (Allocation, AllocationInfo) IO AllocationInfo)
-> IO AllocationInfo
-> ContT (Allocation, AllocationInfo) IO AllocationInfo
forall a b. (a -> b) -> a -> b
$ Ptr AllocationInfo -> IO AllocationInfo
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @AllocationInfo Ptr AllocationInfo
pPAllocationInfo
  (Allocation, AllocationInfo)
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Allocation, AllocationInfo)
 -> ContT
      (Allocation, AllocationInfo) IO (Allocation, AllocationInfo))
-> (Allocation, AllocationInfo)
-> ContT
     (Allocation, AllocationInfo) IO (Allocation, AllocationInfo)
forall a b. (a -> b) -> a -> b
$ (Allocation
pAllocation, AllocationInfo
pAllocationInfo)

-- | A convenience wrapper to make a compatible pair of calls to
-- 'allocateMemoryForImage' and 'freeMemory'
--
-- To ensure that 'freeMemory' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the first argument.
-- To just extract the pair pass '(,)' as the first argument.
--
withMemoryForImage :: forall io r . MonadIO io => Allocator -> Image -> AllocationCreateInfo -> (io (Allocation, AllocationInfo) -> ((Allocation, AllocationInfo) -> io ()) -> r) -> r
withMemoryForImage :: Allocator
-> Image
-> AllocationCreateInfo
-> (io (Allocation, AllocationInfo)
    -> ((Allocation, AllocationInfo) -> io ()) -> r)
-> r
withMemoryForImage allocator :: Allocator
allocator image :: Image
image pCreateInfo :: AllocationCreateInfo
pCreateInfo b :: io (Allocation, AllocationInfo)
-> ((Allocation, AllocationInfo) -> io ()) -> r
b =
  io (Allocation, AllocationInfo)
-> ((Allocation, AllocationInfo) -> io ()) -> r
b (Allocator
-> Image -> AllocationCreateInfo -> io (Allocation, AllocationInfo)
forall (io :: * -> *).
MonadIO io =>
Allocator
-> Image -> AllocationCreateInfo -> io (Allocation, AllocationInfo)
allocateMemoryForImage Allocator
allocator Image
image AllocationCreateInfo
pCreateInfo)
    (\(o0 :: Allocation
o0, _) -> Allocator -> Allocation -> io ()
forall (io :: * -> *).
MonadIO io =>
Allocator -> Allocation -> io ()
freeMemory Allocator
allocator Allocation
o0)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaFreeMemory" ffiVmaFreeMemory
  :: Allocator -> Allocation -> IO ()

-- | Frees memory previously allocated using 'allocateMemory',
-- 'allocateMemoryForBuffer', or 'allocateMemoryForImage'.
--
-- Passing @VK_NULL_HANDLE@ as @allocation@ is valid. Such function call is
-- just skipped.
freeMemory :: forall io
            . (MonadIO io)
           => -- No documentation found for Nested "vmaFreeMemory" "allocator"
              Allocator
           -> -- No documentation found for Nested "vmaFreeMemory" "allocation"
              Allocation
           -> io ()
freeMemory :: Allocator -> Allocation -> io ()
freeMemory allocator :: Allocator
allocator allocation :: Allocation
allocation = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  (Allocator -> Allocation -> IO ()
ffiVmaFreeMemory) (Allocator
allocator) (Allocation
allocation)
  () -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> IO ()) -> () -> IO ()
forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaFreeMemoryPages" ffiVmaFreeMemoryPages
  :: Allocator -> CSize -> Ptr Allocation -> IO ()

-- | Frees memory and destroys multiple allocations.
--
-- Word \"pages\" is just a suggestion to use this function to free pieces
-- of memory used for sparse binding. It is just a general purpose function
-- to free memory and destroy allocations made using e.g. 'allocateMemory',
-- 'allocateMemoryPages' and other functions. It may be internally
-- optimized to be more efficient than calling 'freeMemory'
-- @allocationCount@ times.
--
-- Allocations in @pAllocations@ array can come from any memory pools and
-- types. Passing @VK_NULL_HANDLE@ as elements of @pAllocations@ array is
-- valid. Such entries are just skipped.
freeMemoryPages :: forall io
                 . (MonadIO io)
                => -- No documentation found for Nested "vmaFreeMemoryPages" "allocator"
                   Allocator
                -> -- No documentation found for Nested "vmaFreeMemoryPages" "pAllocations"
                   ("allocations" ::: Vector Allocation)
                -> io ()
freeMemoryPages :: Allocator -> ("allocations" ::: Vector Allocation) -> io ()
freeMemoryPages allocator :: Allocator
allocator allocations :: "allocations" ::: Vector Allocation
allocations = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ())
-> (ContT () IO () -> IO ()) -> ContT () IO () -> io ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> io ()) -> ContT () IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Ptr Allocation
pPAllocations <- ((Ptr Allocation -> IO ()) -> IO ())
-> ContT () IO (Ptr Allocation)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocation -> IO ()) -> IO ())
 -> ContT () IO (Ptr Allocation))
-> ((Ptr Allocation -> IO ()) -> IO ())
-> ContT () IO (Ptr Allocation)
forall a b. (a -> b) -> a -> b
$ Int -> Int -> (Ptr Allocation -> IO ()) -> IO ()
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned @Allocation ((("allocations" ::: Vector Allocation) -> Int
forall a. Vector a -> Int
Data.Vector.length ("allocations" ::: Vector Allocation
allocations)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8) 8
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> Allocation -> IO ())
-> ("allocations" ::: Vector Allocation) -> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\i :: Int
i e :: Allocation
e -> Ptr Allocation -> Allocation -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Allocation
pPAllocations Ptr Allocation -> Int -> Ptr Allocation
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Allocation) (Allocation
e)) ("allocations" ::: Vector Allocation
allocations)
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> CSize -> Ptr Allocation -> IO ()
ffiVmaFreeMemoryPages) (Allocator
allocator) ((Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral (("allocations" ::: Vector Allocation) -> Int
forall a. Vector a -> Int
Data.Vector.length (("allocations" ::: Vector Allocation) -> Int)
-> ("allocations" ::: Vector Allocation) -> Int
forall a b. (a -> b) -> a -> b
$ ("allocations" ::: Vector Allocation
allocations)) :: CSize)) (Ptr Allocation
pPAllocations)
  () -> ContT () IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> ContT () IO ()) -> () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaResizeAllocation" ffiVmaResizeAllocation
  :: Allocator -> Allocation -> DeviceSize -> IO Result

-- | Deprecated.
--
-- /Deprecated/
--
-- In version 2.2.0 it used to try to change allocation\'s size without
-- moving or reallocating it. In current version it returns @VK_SUCCESS@
-- only if @newSize@ equals current allocation\'s size. Otherwise returns
-- @VK_ERROR_OUT_OF_POOL_MEMORY@, indicating that allocation\'s size could
-- not be changed.
resizeAllocation :: forall io
                  . (MonadIO io)
                 => -- No documentation found for Nested "vmaResizeAllocation" "allocator"
                    Allocator
                 -> -- No documentation found for Nested "vmaResizeAllocation" "allocation"
                    Allocation
                 -> -- No documentation found for Nested "vmaResizeAllocation" "newSize"
                    ("newSize" ::: DeviceSize)
                 -> io ()
resizeAllocation :: Allocator
-> Allocation -> ("lostAllocationCount" ::: Word64) -> io ()
resizeAllocation allocator :: Allocator
allocator allocation :: Allocation
allocation newSize :: "lostAllocationCount" ::: Word64
newSize = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator
-> Allocation -> ("lostAllocationCount" ::: Word64) -> IO Result
ffiVmaResizeAllocation) (Allocator
allocator) (Allocation
allocation) ("lostAllocationCount" ::: Word64
newSize)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaGetAllocationInfo" ffiVmaGetAllocationInfo
  :: Allocator -> Allocation -> Ptr AllocationInfo -> IO ()

-- | Returns current information about specified allocation and atomically
-- marks it as used in current frame.
--
-- Current paramters of given allocation are returned in @pAllocationInfo@.
--
-- This function also atomically \"touches\" allocation - marks it as used
-- in current frame, just like 'touchAllocation'. If the allocation is in
-- lost state, @pAllocationInfo->deviceMemory == VK_NULL_HANDLE@.
--
-- Although this function uses atomics and doesn\'t lock any mutex, so it
-- should be quite efficient, you can avoid calling it too often.
--
-- -   You can retrieve same 'AllocationInfo' structure while creating your
--     resource, from function 'createBuffer', 'createImage'. You can
--     remember it if you are sure parameters don\'t change (e.g. due to
--     defragmentation or allocation becoming lost).
--
-- -   If you just want to check if allocation is not lost,
--     'touchAllocation' will work faster.
getAllocationInfo :: forall io
                   . (MonadIO io)
                  => -- No documentation found for Nested "vmaGetAllocationInfo" "allocator"
                     Allocator
                  -> -- No documentation found for Nested "vmaGetAllocationInfo" "allocation"
                     Allocation
                  -> io (AllocationInfo)
getAllocationInfo :: Allocator -> Allocation -> io AllocationInfo
getAllocationInfo allocator :: Allocator
allocator allocation :: Allocation
allocation = IO AllocationInfo -> io AllocationInfo
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO AllocationInfo -> io AllocationInfo)
-> (ContT AllocationInfo IO AllocationInfo -> IO AllocationInfo)
-> ContT AllocationInfo IO AllocationInfo
-> io AllocationInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT AllocationInfo IO AllocationInfo -> IO AllocationInfo
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT AllocationInfo IO AllocationInfo -> io AllocationInfo)
-> ContT AllocationInfo IO AllocationInfo -> io AllocationInfo
forall a b. (a -> b) -> a -> b
$ do
  Ptr AllocationInfo
pPAllocationInfo <- ((Ptr AllocationInfo -> IO AllocationInfo) -> IO AllocationInfo)
-> ContT AllocationInfo IO (Ptr AllocationInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct AllocationInfo =>
(Ptr AllocationInfo -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @AllocationInfo)
  IO () -> ContT AllocationInfo IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT AllocationInfo IO ())
-> IO () -> ContT AllocationInfo IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Allocation -> Ptr AllocationInfo -> IO ()
ffiVmaGetAllocationInfo) (Allocator
allocator) (Allocation
allocation) (Ptr AllocationInfo
pPAllocationInfo)
  AllocationInfo
pAllocationInfo <- IO AllocationInfo -> ContT AllocationInfo IO AllocationInfo
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO AllocationInfo -> ContT AllocationInfo IO AllocationInfo)
-> IO AllocationInfo -> ContT AllocationInfo IO AllocationInfo
forall a b. (a -> b) -> a -> b
$ Ptr AllocationInfo -> IO AllocationInfo
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @AllocationInfo Ptr AllocationInfo
pPAllocationInfo
  AllocationInfo -> ContT AllocationInfo IO AllocationInfo
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AllocationInfo -> ContT AllocationInfo IO AllocationInfo)
-> AllocationInfo -> ContT AllocationInfo IO AllocationInfo
forall a b. (a -> b) -> a -> b
$ (AllocationInfo
pAllocationInfo)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaTouchAllocation" ffiVmaTouchAllocation
  :: Allocator -> Allocation -> IO Bool32

-- | Returns @VK_TRUE@ if allocation is not lost and atomically marks it as
-- used in current frame.
--
-- If the allocation has been created with
-- 'ALLOCATION_CREATE_CAN_BECOME_LOST_BIT' flag, this function returns
-- @VK_TRUE@ if it\'s not in lost state, so it can still be used. It then
-- also atomically \"touches\" the allocation - marks it as used in current
-- frame, so that you can be sure it won\'t become lost in current frame or
-- next @frameInUseCount@ frames.
--
-- If the allocation is in lost state, the function returns @VK_FALSE@.
-- Memory of such allocation, as well as buffer or image bound to it,
-- should not be used. Lost allocation and the buffer\/image still need to
-- be destroyed.
--
-- If the allocation has been created without
-- 'ALLOCATION_CREATE_CAN_BECOME_LOST_BIT' flag, this function always
-- returns @VK_TRUE@.
touchAllocation :: forall io
                 . (MonadIO io)
                => -- No documentation found for Nested "vmaTouchAllocation" "allocator"
                   Allocator
                -> -- No documentation found for Nested "vmaTouchAllocation" "allocation"
                   Allocation
                -> io (Bool)
touchAllocation :: Allocator -> Allocation -> io Bool
touchAllocation allocator :: Allocator
allocator allocation :: Allocation
allocation = IO Bool -> io Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> io Bool) -> IO Bool -> io Bool
forall a b. (a -> b) -> a -> b
$ do
  Bool32
r <- (Allocator -> Allocation -> IO Bool32
ffiVmaTouchAllocation) (Allocator
allocator) (Allocation
allocation)
  Bool -> IO Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> IO Bool) -> Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ ((Bool32 -> Bool
bool32ToBool Bool32
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaSetAllocationUserData" ffiVmaSetAllocationUserData
  :: Allocator -> Allocation -> Ptr () -> IO ()

-- | Sets pUserData in given allocation to new value.
--
-- If the allocation was created with
-- VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT, pUserData must be
-- either null, or pointer to a null-terminated string. The function makes
-- local copy of the string and sets it as allocation\'s @pUserData@.
-- String passed as pUserData doesn\'t need to be valid for whole lifetime
-- of the allocation - you can free it after this call. String previously
-- pointed by allocation\'s pUserData is freed from memory.
--
-- If the flag was not used, the value of pointer @pUserData@ is just
-- copied to allocation\'s @pUserData@. It is opaque, so you can use it
-- however you want - e.g. as a pointer, ordinal number or some handle to
-- you own data.
setAllocationUserData :: forall io
                       . (MonadIO io)
                      => -- No documentation found for Nested "vmaSetAllocationUserData" "allocator"
                         Allocator
                      -> -- No documentation found for Nested "vmaSetAllocationUserData" "allocation"
                         Allocation
                      -> -- No documentation found for Nested "vmaSetAllocationUserData" "pUserData"
                         ("userData" ::: Ptr ())
                      -> io ()
setAllocationUserData :: Allocator -> Allocation -> ("userData" ::: Ptr ()) -> io ()
setAllocationUserData allocator :: Allocator
allocator allocation :: Allocation
allocation userData :: "userData" ::: Ptr ()
userData = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  (Allocator -> Allocation -> ("userData" ::: Ptr ()) -> IO ()
ffiVmaSetAllocationUserData) (Allocator
allocator) (Allocation
allocation) ("userData" ::: Ptr ()
userData)
  () -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> IO ()) -> () -> IO ()
forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaCreateLostAllocation" ffiVmaCreateLostAllocation
  :: Allocator -> Ptr Allocation -> IO ()

-- | Creates new allocation that is in lost state from the beginning.
--
-- It can be useful if you need a dummy, non-null allocation.
--
-- You still need to destroy created object using 'freeMemory'.
--
-- Returned allocation is not tied to any specific memory pool or memory
-- type and not bound to any image or buffer. It has size = 0. It cannot be
-- turned into a real, non-empty allocation.
createLostAllocation :: forall io
                      . (MonadIO io)
                     => -- No documentation found for Nested "vmaCreateLostAllocation" "allocator"
                        Allocator
                     -> io (Allocation)
createLostAllocation :: Allocator -> io Allocation
createLostAllocation allocator :: Allocator
allocator = IO Allocation -> io Allocation
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Allocation -> io Allocation)
-> (ContT Allocation IO Allocation -> IO Allocation)
-> ContT Allocation IO Allocation
-> io Allocation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT Allocation IO Allocation -> IO Allocation
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT Allocation IO Allocation -> io Allocation)
-> ContT Allocation IO Allocation -> io Allocation
forall a b. (a -> b) -> a -> b
$ do
  Ptr Allocation
pPAllocation <- ((Ptr Allocation -> IO Allocation) -> IO Allocation)
-> ContT Allocation IO (Ptr Allocation)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocation -> IO Allocation) -> IO Allocation)
 -> ContT Allocation IO (Ptr Allocation))
-> ((Ptr Allocation -> IO Allocation) -> IO Allocation)
-> ContT Allocation IO (Ptr Allocation)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Allocation)
-> (Ptr Allocation -> IO ())
-> (Ptr Allocation -> IO Allocation)
-> IO Allocation
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Allocation)
forall a. Int -> IO (Ptr a)
callocBytes @Allocation 8) Ptr Allocation -> IO ()
forall a. Ptr a -> IO ()
free
  IO () -> ContT Allocation IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Allocation IO ())
-> IO () -> ContT Allocation IO ()
forall a b. (a -> b) -> a -> b
$ (Allocator -> Ptr Allocation -> IO ()
ffiVmaCreateLostAllocation) (Allocator
allocator) (Ptr Allocation
pPAllocation)
  Allocation
pAllocation <- IO Allocation -> ContT Allocation IO Allocation
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Allocation -> ContT Allocation IO Allocation)
-> IO Allocation -> ContT Allocation IO Allocation
forall a b. (a -> b) -> a -> b
$ Ptr Allocation -> IO Allocation
forall a. Storable a => Ptr a -> IO a
peek @Allocation Ptr Allocation
pPAllocation
  Allocation -> ContT Allocation IO Allocation
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Allocation -> ContT Allocation IO Allocation)
-> Allocation -> ContT Allocation IO Allocation
forall a b. (a -> b) -> a -> b
$ (Allocation
pAllocation)

-- | A convenience wrapper to make a compatible pair of calls to
-- 'createLostAllocation' and 'freeMemory'
--
-- To ensure that 'freeMemory' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the first argument.
-- To just extract the pair pass '(,)' as the first argument.
--
withLostAllocation :: forall io r . MonadIO io => Allocator -> (io (Allocation) -> ((Allocation) -> io ()) -> r) -> r
withLostAllocation :: Allocator -> (io Allocation -> (Allocation -> io ()) -> r) -> r
withLostAllocation allocator :: Allocator
allocator b :: io Allocation -> (Allocation -> io ()) -> r
b =
  io Allocation -> (Allocation -> io ()) -> r
b (Allocator -> io Allocation
forall (io :: * -> *). MonadIO io => Allocator -> io Allocation
createLostAllocation Allocator
allocator)
    (\(Allocation
o0) -> Allocator -> Allocation -> io ()
forall (io :: * -> *).
MonadIO io =>
Allocator -> Allocation -> io ()
freeMemory Allocator
allocator Allocation
o0)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaMapMemory" ffiVmaMapMemory
  :: Allocator -> Allocation -> Ptr (Ptr ()) -> IO Result

-- | Maps memory represented by given allocation and returns pointer to it.
--
-- Maps memory represented by given allocation to make it accessible to CPU
-- code. When succeeded, @*ppData@ contains pointer to first byte of this
-- memory. If the allocation is part of bigger @VkDeviceMemory@ block, the
-- pointer is correctly offseted to the beginning of region assigned to
-- this particular allocation.
--
-- Mapping is internally reference-counted and synchronized, so despite raw
-- Vulkan function @vkMapMemory()@ cannot be used to map same block of
-- @VkDeviceMemory@ multiple times simultaneously, it is safe to call this
-- function on allocations assigned to the same memory block. Actual Vulkan
-- memory will be mapped on first mapping and unmapped on last unmapping.
--
-- If the function succeeded, you must call 'unmapMemory' to unmap the
-- allocation when mapping is no longer needed or before freeing the
-- allocation, at the latest.
--
-- It also safe to call this function multiple times on the same
-- allocation. You must call 'unmapMemory' same number of times as you
-- called 'mapMemory'.
--
-- It is also safe to call this function on allocation created with
-- 'ALLOCATION_CREATE_MAPPED_BIT' flag. Its memory stays mapped all the
-- time. You must still call 'unmapMemory' same number of times as you
-- called 'mapMemory'. You must not call 'unmapMemory' additional time to
-- free the \"0-th\" mapping made automatically due to
-- 'ALLOCATION_CREATE_MAPPED_BIT' flag.
--
-- This function fails when used on allocation made in memory type that is
-- not @HOST_VISIBLE@.
--
-- This function always fails when called for allocation that was created
-- with 'ALLOCATION_CREATE_CAN_BECOME_LOST_BIT' flag. Such allocations
-- cannot be mapped.
--
-- This function doesn\'t automatically flush or invalidate caches. If the
-- allocation is made from a memory types that is not @HOST_COHERENT@, you
-- also need to use 'invalidateAllocation' \/ 'flushAllocation', as
-- required by Vulkan specification.
mapMemory :: forall io
           . (MonadIO io)
          => -- No documentation found for Nested "vmaMapMemory" "allocator"
             Allocator
          -> -- No documentation found for Nested "vmaMapMemory" "allocation"
             Allocation
          -> io (("data" ::: Ptr ()))
mapMemory :: Allocator -> Allocation -> io ("userData" ::: Ptr ())
mapMemory allocator :: Allocator
allocator allocation :: Allocation
allocation = IO ("userData" ::: Ptr ()) -> io ("userData" ::: Ptr ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("userData" ::: Ptr ()) -> io ("userData" ::: Ptr ()))
-> (ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ())
    -> IO ("userData" ::: Ptr ()))
-> ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ())
-> io ("userData" ::: Ptr ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ())
-> IO ("userData" ::: Ptr ())
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ())
 -> io ("userData" ::: Ptr ()))
-> ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ())
-> io ("userData" ::: Ptr ())
forall a b. (a -> b) -> a -> b
$ do
  Ptr ("userData" ::: Ptr ())
pPpData <- ((Ptr ("userData" ::: Ptr ()) -> IO ("userData" ::: Ptr ()))
 -> IO ("userData" ::: Ptr ()))
-> ContT ("userData" ::: Ptr ()) IO (Ptr ("userData" ::: Ptr ()))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("userData" ::: Ptr ()) -> IO ("userData" ::: Ptr ()))
  -> IO ("userData" ::: Ptr ()))
 -> ContT ("userData" ::: Ptr ()) IO (Ptr ("userData" ::: Ptr ())))
-> ((Ptr ("userData" ::: Ptr ()) -> IO ("userData" ::: Ptr ()))
    -> IO ("userData" ::: Ptr ()))
-> ContT ("userData" ::: Ptr ()) IO (Ptr ("userData" ::: Ptr ()))
forall a b. (a -> b) -> a -> b
$ IO (Ptr ("userData" ::: Ptr ()))
-> (Ptr ("userData" ::: Ptr ()) -> IO ())
-> (Ptr ("userData" ::: Ptr ()) -> IO ("userData" ::: Ptr ()))
-> IO ("userData" ::: Ptr ())
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr ("userData" ::: Ptr ()))
forall a. Int -> IO (Ptr a)
callocBytes @(Ptr ()) 8) Ptr ("userData" ::: Ptr ()) -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT ("userData" ::: Ptr ()) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT ("userData" ::: Ptr ()) IO Result)
-> IO Result -> ContT ("userData" ::: Ptr ()) IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator -> Allocation -> Ptr ("userData" ::: Ptr ()) -> IO Result
ffiVmaMapMemory) (Allocator
allocator) (Allocation
allocation) (Ptr ("userData" ::: Ptr ())
pPpData)
  IO () -> ContT ("userData" ::: Ptr ()) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT ("userData" ::: Ptr ()) IO ())
-> IO () -> ContT ("userData" ::: Ptr ()) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  "userData" ::: Ptr ()
ppData <- IO ("userData" ::: Ptr ())
-> ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ())
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("userData" ::: Ptr ())
 -> ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ()))
-> IO ("userData" ::: Ptr ())
-> ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ())
forall a b. (a -> b) -> a -> b
$ Ptr ("userData" ::: Ptr ()) -> IO ("userData" ::: Ptr ())
forall a. Storable a => Ptr a -> IO a
peek @(Ptr ()) Ptr ("userData" ::: Ptr ())
pPpData
  ("userData" ::: Ptr ())
-> ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ())
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("userData" ::: Ptr ())
 -> ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ()))
-> ("userData" ::: Ptr ())
-> ContT ("userData" ::: Ptr ()) IO ("userData" ::: Ptr ())
forall a b. (a -> b) -> a -> b
$ ("userData" ::: Ptr ()
ppData)

-- | A convenience wrapper to make a compatible pair of calls to 'mapMemory'
-- and 'unmapMemory'
--
-- To ensure that 'unmapMemory' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the first argument.
-- To just extract the pair pass '(,)' as the first argument.
--
withMappedMemory :: forall io r . MonadIO io => Allocator -> Allocation -> (io (Ptr ()) -> ((Ptr ()) -> io ()) -> r) -> r
withMappedMemory :: Allocator
-> Allocation
-> (io ("userData" ::: Ptr ())
    -> (("userData" ::: Ptr ()) -> io ()) -> r)
-> r
withMappedMemory allocator :: Allocator
allocator allocation :: Allocation
allocation b :: io ("userData" ::: Ptr ())
-> (("userData" ::: Ptr ()) -> io ()) -> r
b =
  io ("userData" ::: Ptr ())
-> (("userData" ::: Ptr ()) -> io ()) -> r
b (Allocator -> Allocation -> io ("userData" ::: Ptr ())
forall (io :: * -> *).
MonadIO io =>
Allocator -> Allocation -> io ("userData" ::: Ptr ())
mapMemory Allocator
allocator Allocation
allocation)
    (\("userData" ::: Ptr ()
_) -> Allocator -> Allocation -> io ()
forall (io :: * -> *).
MonadIO io =>
Allocator -> Allocation -> io ()
unmapMemory Allocator
allocator Allocation
allocation)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaUnmapMemory" ffiVmaUnmapMemory
  :: Allocator -> Allocation -> IO ()

-- | Unmaps memory represented by given allocation, mapped previously using
-- 'mapMemory'.
--
-- For details, see description of 'mapMemory'.
--
-- This function doesn\'t automatically flush or invalidate caches. If the
-- allocation is made from a memory types that is not @HOST_COHERENT@, you
-- also need to use 'invalidateAllocation' \/ 'flushAllocation', as
-- required by Vulkan specification.
unmapMemory :: forall io
             . (MonadIO io)
            => -- No documentation found for Nested "vmaUnmapMemory" "allocator"
               Allocator
            -> -- No documentation found for Nested "vmaUnmapMemory" "allocation"
               Allocation
            -> io ()
unmapMemory :: Allocator -> Allocation -> io ()
unmapMemory allocator :: Allocator
allocator allocation :: Allocation
allocation = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  (Allocator -> Allocation -> IO ()
ffiVmaUnmapMemory) (Allocator
allocator) (Allocation
allocation)
  () -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> IO ()) -> () -> IO ()
forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaFlushAllocation" ffiVmaFlushAllocation
  :: Allocator -> Allocation -> DeviceSize -> DeviceSize -> IO Result

-- | Flushes memory of given allocation.
--
-- Calls @vkFlushMappedMemoryRanges()@ for memory associated with given
-- range of given allocation. It needs to be called after writing to a
-- mapped memory for memory types that are not @HOST_COHERENT@. Unmap
-- operation doesn\'t do that automatically.
--
-- -   @offset@ must be relative to the beginning of allocation.
--
-- -   @size@ can be @VK_WHOLE_SIZE@. It means all memory from @offset@ the
--     the end of given allocation.
--
-- -   @offset@ and @size@ don\'t have to be aligned. They are internally
--     rounded down\/up to multiply of @nonCoherentAtomSize@.
--
-- -   If @size@ is 0, this call is ignored.
--
-- -   If memory type that the @allocation@ belongs to is not
--     @HOST_VISIBLE@ or it is @HOST_COHERENT@, this call is ignored.
--
-- Warning! @offset@ and @size@ are relative to the contents of given
-- @allocation@. If you mean whole allocation, you can pass 0 and
-- @VK_WHOLE_SIZE@, respectively. Do not pass allocation\'s offset as
-- @offset@!!!
--
-- This function returns the @VkResult@ from @vkFlushMappedMemoryRanges@ if
-- it is called, otherwise @VK_SUCCESS@.
flushAllocation :: forall io
                 . (MonadIO io)
                => -- No documentation found for Nested "vmaFlushAllocation" "allocator"
                   Allocator
                -> -- No documentation found for Nested "vmaFlushAllocation" "allocation"
                   Allocation
                -> -- No documentation found for Nested "vmaFlushAllocation" "offset"
                   ("offset" ::: DeviceSize)
                -> -- No documentation found for Nested "vmaFlushAllocation" "size"
                   DeviceSize
                -> io ()
flushAllocation :: Allocator
-> Allocation
-> ("lostAllocationCount" ::: Word64)
-> ("lostAllocationCount" ::: Word64)
-> io ()
flushAllocation allocator :: Allocator
allocator allocation :: Allocation
allocation offset :: "lostAllocationCount" ::: Word64
offset size :: "lostAllocationCount" ::: Word64
size = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator
-> Allocation
-> ("lostAllocationCount" ::: Word64)
-> ("lostAllocationCount" ::: Word64)
-> IO Result
ffiVmaFlushAllocation) (Allocator
allocator) (Allocation
allocation) ("lostAllocationCount" ::: Word64
offset) ("lostAllocationCount" ::: Word64
size)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaInvalidateAllocation" ffiVmaInvalidateAllocation
  :: Allocator -> Allocation -> DeviceSize -> DeviceSize -> IO Result

-- | Invalidates memory of given allocation.
--
-- Calls @vkInvalidateMappedMemoryRanges()@ for memory associated with
-- given range of given allocation. It needs to be called before reading
-- from a mapped memory for memory types that are not @HOST_COHERENT@. Map
-- operation doesn\'t do that automatically.
--
-- -   @offset@ must be relative to the beginning of allocation.
--
-- -   @size@ can be @VK_WHOLE_SIZE@. It means all memory from @offset@ the
--     the end of given allocation.
--
-- -   @offset@ and @size@ don\'t have to be aligned. They are internally
--     rounded down\/up to multiply of @nonCoherentAtomSize@.
--
-- -   If @size@ is 0, this call is ignored.
--
-- -   If memory type that the @allocation@ belongs to is not
--     @HOST_VISIBLE@ or it is @HOST_COHERENT@, this call is ignored.
--
-- Warning! @offset@ and @size@ are relative to the contents of given
-- @allocation@. If you mean whole allocation, you can pass 0 and
-- @VK_WHOLE_SIZE@, respectively. Do not pass allocation\'s offset as
-- @offset@!!!
--
-- This function returns the @VkResult@ from
-- @vkInvalidateMappedMemoryRanges@ if it is called, otherwise
-- @VK_SUCCESS@.
invalidateAllocation :: forall io
                      . (MonadIO io)
                     => -- No documentation found for Nested "vmaInvalidateAllocation" "allocator"
                        Allocator
                     -> -- No documentation found for Nested "vmaInvalidateAllocation" "allocation"
                        Allocation
                     -> -- No documentation found for Nested "vmaInvalidateAllocation" "offset"
                        ("offset" ::: DeviceSize)
                     -> -- No documentation found for Nested "vmaInvalidateAllocation" "size"
                        DeviceSize
                     -> io ()
invalidateAllocation :: Allocator
-> Allocation
-> ("lostAllocationCount" ::: Word64)
-> ("lostAllocationCount" ::: Word64)
-> io ()
invalidateAllocation allocator :: Allocator
allocator allocation :: Allocation
allocation offset :: "lostAllocationCount" ::: Word64
offset size :: "lostAllocationCount" ::: Word64
size = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator
-> Allocation
-> ("lostAllocationCount" ::: Word64)
-> ("lostAllocationCount" ::: Word64)
-> IO Result
ffiVmaInvalidateAllocation) (Allocator
allocator) (Allocation
allocation) ("lostAllocationCount" ::: Word64
offset) ("lostAllocationCount" ::: Word64
size)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaFlushAllocations" ffiVmaFlushAllocations
  :: Allocator -> Word32 -> Ptr Allocation -> Ptr DeviceSize -> Ptr DeviceSize -> IO Result

-- | Flushes memory of given set of allocations.
--
-- Calls @vkFlushMappedMemoryRanges()@ for memory associated with given
-- ranges of given allocations. For more information, see documentation of
-- 'flushAllocation'.
--
-- __Parameters.__
--
-- +-----------------+--------------------------------------------------------+
-- | allocator       |                                                        |
-- +-----------------+--------------------------------------------------------+
-- | allocationCount |                                                        |
-- +-----------------+--------------------------------------------------------+
-- | allocations     |                                                        |
-- +-----------------+--------------------------------------------------------+
-- | offsets         | If not null, it must point to an array of offsets of   |
-- |                 | regions to flush, relative to the beginning of         |
-- |                 | respective allocations. Null means all ofsets are      |
-- |                 | zero.                                                  |
-- +-----------------+--------------------------------------------------------+
-- | sizes           | If not null, it must point to an array of sizes of     |
-- |                 | regions to flush in respective allocations. Null means |
-- |                 | @VK_WHOLE_SIZE@ for all allocations.                   |
-- +-----------------+--------------------------------------------------------+
--
-- This function returns the @VkResult@ from @vkFlushMappedMemoryRanges@ if
-- it is called, otherwise @VK_SUCCESS@.
flushAllocations :: forall io
                  . (MonadIO io)
                 => -- No documentation found for Nested "vmaFlushAllocations" "allocator"
                    Allocator
                 -> -- No documentation found for Nested "vmaFlushAllocations" "allocations"
                    ("allocations" ::: Vector Allocation)
                 -> -- No documentation found for Nested "vmaFlushAllocations" "offsets"
                    ("offsets" ::: Vector DeviceSize)
                 -> -- No documentation found for Nested "vmaFlushAllocations" "sizes"
                    ("sizes" ::: Vector DeviceSize)
                 -> io ()
flushAllocations :: Allocator
-> ("allocations" ::: Vector Allocation)
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64))
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64))
-> io ()
flushAllocations allocator :: Allocator
allocator allocations :: "allocations" ::: Vector Allocation
allocations offsets :: "offsets" ::: Vector ("lostAllocationCount" ::: Word64)
offsets sizes :: "offsets" ::: Vector ("lostAllocationCount" ::: Word64)
sizes = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ())
-> (ContT () IO () -> IO ()) -> ContT () IO () -> io ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> io ()) -> ContT () IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  let allocationsLength :: Int
allocationsLength = ("allocations" ::: Vector Allocation) -> Int
forall a. Vector a -> Int
Data.Vector.length (("allocations" ::: Vector Allocation) -> Int)
-> ("allocations" ::: Vector Allocation) -> Int
forall a b. (a -> b) -> a -> b
$ ("allocations" ::: Vector Allocation
allocations)
  let offsetsLength :: Int
offsetsLength = ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a. Vector a -> Int
Data.Vector.length (("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int)
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a b. (a -> b) -> a -> b
$ ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
offsets)
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
offsetsLength Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
allocationsLength Bool -> Bool -> Bool
|| Int
offsetsLength Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0) (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 "" "offsets and allocations must have the same length" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let sizesLength :: Int
sizesLength = ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a. Vector a -> Int
Data.Vector.length (("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int)
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a b. (a -> b) -> a -> b
$ ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
sizes)
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
sizesLength Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
allocationsLength Bool -> Bool -> Bool
|| Int
sizesLength Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0) (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 "" "sizes and allocations must have the same length" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  Ptr Allocation
pAllocations <- ((Ptr Allocation -> IO ()) -> IO ())
-> ContT () IO (Ptr Allocation)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocation -> IO ()) -> IO ())
 -> ContT () IO (Ptr Allocation))
-> ((Ptr Allocation -> IO ()) -> IO ())
-> ContT () IO (Ptr Allocation)
forall a b. (a -> b) -> a -> b
$ Int -> Int -> (Ptr Allocation -> IO ()) -> IO ()
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned @Allocation ((("allocations" ::: Vector Allocation) -> Int
forall a. Vector a -> Int
Data.Vector.length ("allocations" ::: Vector Allocation
allocations)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8) 8
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> Allocation -> IO ())
-> ("allocations" ::: Vector Allocation) -> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\i :: Int
i e :: Allocation
e -> Ptr Allocation -> Allocation -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Allocation
pAllocations Ptr Allocation -> Int -> Ptr Allocation
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Allocation) (Allocation
e)) ("allocations" ::: Vector Allocation
allocations)
  Ptr ("lostAllocationCount" ::: Word64)
offsets' <- if ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Bool
forall a. Vector a -> Bool
Data.Vector.null ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
offsets)
    then Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ptr ("lostAllocationCount" ::: Word64)
forall a. Ptr a
nullPtr
    else do
      Ptr ("lostAllocationCount" ::: Word64)
pOffsets <- ((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
 -> ContT () IO (Ptr ("lostAllocationCount" ::: Word64)))
-> ((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> (Ptr ("lostAllocationCount" ::: Word64) -> IO ())
-> IO ()
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned @DeviceSize (((("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a. Vector a -> Int
Data.Vector.length ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
offsets))) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8) 8
      IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> ("lostAllocationCount" ::: Word64) -> IO ())
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64))
-> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\i :: Int
i e :: "lostAllocationCount" ::: Word64
e -> Ptr ("lostAllocationCount" ::: Word64)
-> ("lostAllocationCount" ::: Word64) -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr ("lostAllocationCount" ::: Word64)
pOffsets Ptr ("lostAllocationCount" ::: Word64)
-> Int -> Ptr ("lostAllocationCount" ::: Word64)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceSize) ("lostAllocationCount" ::: Word64
e)) (("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
offsets))
      Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ptr ("lostAllocationCount" ::: Word64)
 -> ContT () IO (Ptr ("lostAllocationCount" ::: Word64)))
-> Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall a b. (a -> b) -> a -> b
$ Ptr ("lostAllocationCount" ::: Word64)
pOffsets
  Ptr ("lostAllocationCount" ::: Word64)
sizes' <- if ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Bool
forall a. Vector a -> Bool
Data.Vector.null ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
sizes)
    then Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ptr ("lostAllocationCount" ::: Word64)
forall a. Ptr a
nullPtr
    else do
      Ptr ("lostAllocationCount" ::: Word64)
pSizes <- ((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
 -> ContT () IO (Ptr ("lostAllocationCount" ::: Word64)))
-> ((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> (Ptr ("lostAllocationCount" ::: Word64) -> IO ())
-> IO ()
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned @DeviceSize (((("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a. Vector a -> Int
Data.Vector.length ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
sizes))) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8) 8
      IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> ("lostAllocationCount" ::: Word64) -> IO ())
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64))
-> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\i :: Int
i e :: "lostAllocationCount" ::: Word64
e -> Ptr ("lostAllocationCount" ::: Word64)
-> ("lostAllocationCount" ::: Word64) -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr ("lostAllocationCount" ::: Word64)
pSizes Ptr ("lostAllocationCount" ::: Word64)
-> Int -> Ptr ("lostAllocationCount" ::: Word64)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceSize) ("lostAllocationCount" ::: Word64
e)) (("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
sizes))
      Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ptr ("lostAllocationCount" ::: Word64)
 -> ContT () IO (Ptr ("lostAllocationCount" ::: Word64)))
-> Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall a b. (a -> b) -> a -> b
$ Ptr ("lostAllocationCount" ::: Word64)
pSizes
  Result
r <- IO Result -> ContT () IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT () IO Result)
-> IO Result -> ContT () IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> ("memoryTypeIndex" ::: Word32)
-> Ptr Allocation
-> Ptr ("lostAllocationCount" ::: Word64)
-> Ptr ("lostAllocationCount" ::: Word64)
-> IO Result
ffiVmaFlushAllocations) (Allocator
allocator) ((Int -> "memoryTypeIndex" ::: Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
allocationsLength :: Word32)) (Ptr Allocation
pAllocations) Ptr ("lostAllocationCount" ::: Word64)
offsets' Ptr ("lostAllocationCount" ::: Word64)
sizes'
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaInvalidateAllocations" ffiVmaInvalidateAllocations
  :: Allocator -> Word32 -> Ptr Allocation -> Ptr DeviceSize -> Ptr DeviceSize -> IO Result

-- | Invalidates memory of given set of allocations.
--
-- Calls @vkInvalidateMappedMemoryRanges()@ for memory associated with
-- given ranges of given allocations. For more information, see
-- documentation of 'invalidateAllocation'.
--
-- __Parameters.__
--
-- +-----------------+--------------------------------------------------------+
-- | allocator       |                                                        |
-- +-----------------+--------------------------------------------------------+
-- | allocationCount |                                                        |
-- +-----------------+--------------------------------------------------------+
-- | allocations     |                                                        |
-- +-----------------+--------------------------------------------------------+
-- | offsets         | If not null, it must point to an array of offsets of   |
-- |                 | regions to flush, relative to the beginning of         |
-- |                 | respective allocations. Null means all ofsets are      |
-- |                 | zero.                                                  |
-- +-----------------+--------------------------------------------------------+
-- | sizes           | If not null, it must point to an array of sizes of     |
-- |                 | regions to flush in respective allocations. Null means |
-- |                 | @VK_WHOLE_SIZE@ for all allocations.                   |
-- +-----------------+--------------------------------------------------------+
--
-- This function returns the @VkResult@ from
-- @vkInvalidateMappedMemoryRanges@ if it is called, otherwise
-- @VK_SUCCESS@.
invalidateAllocations :: forall io
                       . (MonadIO io)
                      => -- No documentation found for Nested "vmaInvalidateAllocations" "allocator"
                         Allocator
                      -> -- No documentation found for Nested "vmaInvalidateAllocations" "allocations"
                         ("allocations" ::: Vector Allocation)
                      -> -- No documentation found for Nested "vmaInvalidateAllocations" "offsets"
                         ("offsets" ::: Vector DeviceSize)
                      -> -- No documentation found for Nested "vmaInvalidateAllocations" "sizes"
                         ("sizes" ::: Vector DeviceSize)
                      -> io ()
invalidateAllocations :: Allocator
-> ("allocations" ::: Vector Allocation)
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64))
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64))
-> io ()
invalidateAllocations allocator :: Allocator
allocator allocations :: "allocations" ::: Vector Allocation
allocations offsets :: "offsets" ::: Vector ("lostAllocationCount" ::: Word64)
offsets sizes :: "offsets" ::: Vector ("lostAllocationCount" ::: Word64)
sizes = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ())
-> (ContT () IO () -> IO ()) -> ContT () IO () -> io ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> io ()) -> ContT () IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  let allocationsLength :: Int
allocationsLength = ("allocations" ::: Vector Allocation) -> Int
forall a. Vector a -> Int
Data.Vector.length (("allocations" ::: Vector Allocation) -> Int)
-> ("allocations" ::: Vector Allocation) -> Int
forall a b. (a -> b) -> a -> b
$ ("allocations" ::: Vector Allocation
allocations)
  let offsetsLength :: Int
offsetsLength = ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a. Vector a -> Int
Data.Vector.length (("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int)
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a b. (a -> b) -> a -> b
$ ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
offsets)
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
offsetsLength Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
allocationsLength Bool -> Bool -> Bool
|| Int
offsetsLength Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0) (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 "" "offsets and allocations must have the same length" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let sizesLength :: Int
sizesLength = ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a. Vector a -> Int
Data.Vector.length (("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int)
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a b. (a -> b) -> a -> b
$ ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
sizes)
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
sizesLength Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
allocationsLength Bool -> Bool -> Bool
|| Int
sizesLength Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0) (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 "" "sizes and allocations must have the same length" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  Ptr Allocation
pAllocations <- ((Ptr Allocation -> IO ()) -> IO ())
-> ContT () IO (Ptr Allocation)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocation -> IO ()) -> IO ())
 -> ContT () IO (Ptr Allocation))
-> ((Ptr Allocation -> IO ()) -> IO ())
-> ContT () IO (Ptr Allocation)
forall a b. (a -> b) -> a -> b
$ Int -> Int -> (Ptr Allocation -> IO ()) -> IO ()
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned @Allocation ((("allocations" ::: Vector Allocation) -> Int
forall a. Vector a -> Int
Data.Vector.length ("allocations" ::: Vector Allocation
allocations)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8) 8
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> Allocation -> IO ())
-> ("allocations" ::: Vector Allocation) -> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\i :: Int
i e :: Allocation
e -> Ptr Allocation -> Allocation -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Allocation
pAllocations Ptr Allocation -> Int -> Ptr Allocation
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Allocation) (Allocation
e)) ("allocations" ::: Vector Allocation
allocations)
  Ptr ("lostAllocationCount" ::: Word64)
offsets' <- if ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Bool
forall a. Vector a -> Bool
Data.Vector.null ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
offsets)
    then Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ptr ("lostAllocationCount" ::: Word64)
forall a. Ptr a
nullPtr
    else do
      Ptr ("lostAllocationCount" ::: Word64)
pOffsets <- ((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
 -> ContT () IO (Ptr ("lostAllocationCount" ::: Word64)))
-> ((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> (Ptr ("lostAllocationCount" ::: Word64) -> IO ())
-> IO ()
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned @DeviceSize (((("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a. Vector a -> Int
Data.Vector.length ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
offsets))) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8) 8
      IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> ("lostAllocationCount" ::: Word64) -> IO ())
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64))
-> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\i :: Int
i e :: "lostAllocationCount" ::: Word64
e -> Ptr ("lostAllocationCount" ::: Word64)
-> ("lostAllocationCount" ::: Word64) -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr ("lostAllocationCount" ::: Word64)
pOffsets Ptr ("lostAllocationCount" ::: Word64)
-> Int -> Ptr ("lostAllocationCount" ::: Word64)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceSize) ("lostAllocationCount" ::: Word64
e)) (("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
offsets))
      Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ptr ("lostAllocationCount" ::: Word64)
 -> ContT () IO (Ptr ("lostAllocationCount" ::: Word64)))
-> Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall a b. (a -> b) -> a -> b
$ Ptr ("lostAllocationCount" ::: Word64)
pOffsets
  Ptr ("lostAllocationCount" ::: Word64)
sizes' <- if ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Bool
forall a. Vector a -> Bool
Data.Vector.null ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
sizes)
    then Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ptr ("lostAllocationCount" ::: Word64)
forall a. Ptr a
nullPtr
    else do
      Ptr ("lostAllocationCount" ::: Word64)
pSizes <- ((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
 -> ContT () IO (Ptr ("lostAllocationCount" ::: Word64)))
-> ((Ptr ("lostAllocationCount" ::: Word64) -> IO ()) -> IO ())
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> (Ptr ("lostAllocationCount" ::: Word64) -> IO ())
-> IO ()
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned @DeviceSize (((("offsets" ::: Vector ("lostAllocationCount" ::: Word64)) -> Int
forall a. Vector a -> Int
Data.Vector.length ("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
sizes))) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8) 8
      IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> ("lostAllocationCount" ::: Word64) -> IO ())
-> ("offsets" ::: Vector ("lostAllocationCount" ::: Word64))
-> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\i :: Int
i e :: "lostAllocationCount" ::: Word64
e -> Ptr ("lostAllocationCount" ::: Word64)
-> ("lostAllocationCount" ::: Word64) -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr ("lostAllocationCount" ::: Word64)
pSizes Ptr ("lostAllocationCount" ::: Word64)
-> Int -> Ptr ("lostAllocationCount" ::: Word64)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceSize) ("lostAllocationCount" ::: Word64
e)) (("offsets" ::: Vector ("lostAllocationCount" ::: Word64)
sizes))
      Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ptr ("lostAllocationCount" ::: Word64)
 -> ContT () IO (Ptr ("lostAllocationCount" ::: Word64)))
-> Ptr ("lostAllocationCount" ::: Word64)
-> ContT () IO (Ptr ("lostAllocationCount" ::: Word64))
forall a b. (a -> b) -> a -> b
$ Ptr ("lostAllocationCount" ::: Word64)
pSizes
  Result
r <- IO Result -> ContT () IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT () IO Result)
-> IO Result -> ContT () IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> ("memoryTypeIndex" ::: Word32)
-> Ptr Allocation
-> Ptr ("lostAllocationCount" ::: Word64)
-> Ptr ("lostAllocationCount" ::: Word64)
-> IO Result
ffiVmaInvalidateAllocations) (Allocator
allocator) ((Int -> "memoryTypeIndex" ::: Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
allocationsLength :: Word32)) (Ptr Allocation
pAllocations) Ptr ("lostAllocationCount" ::: Word64)
offsets' Ptr ("lostAllocationCount" ::: Word64)
sizes'
  IO () -> ContT () IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaCheckCorruption" ffiVmaCheckCorruption
  :: Allocator -> Word32 -> IO Result

-- | Checks magic number in margins around all allocations in given memory
-- types (in both default and custom pools) in search for corruptions.
--
-- __Parameters.__
--
-- +----------------+--------------------------------------------------------+
-- | memoryTypeBits | Bit mask, where each bit set means that a memory type  |
-- |                | with that index should be checked.                     |
-- +----------------+--------------------------------------------------------+
--
-- Corruption detection is enabled only when @VMA_DEBUG_DETECT_CORRUPTION@
-- macro is defined to nonzero, @VMA_DEBUG_MARGIN@ is defined to nonzero
-- and only for memory types that are @HOST_VISIBLE@ and @HOST_COHERENT@.
-- For more information, see /Corruption detection/.
--
-- Possible return values:
--
-- -   @VK_ERROR_FEATURE_NOT_PRESENT@ - corruption detection is not enabled
--     for any of specified memory types.
--
-- -   @VK_SUCCESS@ - corruption detection has been performed and
--     succeeded.
--
-- -   @VK_ERROR_VALIDATION_FAILED_EXT@ - corruption detection has been
--     performed and found memory corruptions around one of the
--     allocations. @VMA_ASSERT@ is also fired in that case.
--
-- -   Other value: Error returned by Vulkan, e.g. memory mapping failure.
checkCorruption :: forall io
                 . (MonadIO io)
                => -- No documentation found for Nested "vmaCheckCorruption" "allocator"
                   Allocator
                -> -- No documentation found for Nested "vmaCheckCorruption" "memoryTypeBits"
                   ("memoryTypeBits" ::: Word32)
                -> io ()
checkCorruption :: Allocator -> ("memoryTypeIndex" ::: Word32) -> io ()
checkCorruption allocator :: Allocator
allocator memoryTypeBits :: "memoryTypeIndex" ::: Word32
memoryTypeBits = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator -> ("memoryTypeIndex" ::: Word32) -> IO Result
ffiVmaCheckCorruption) (Allocator
allocator) ("memoryTypeIndex" ::: Word32
memoryTypeBits)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaDefragmentationBegin" ffiVmaDefragmentationBegin
  :: Allocator -> Ptr DefragmentationInfo2 -> Ptr DefragmentationStats -> Ptr DefragmentationContext -> IO Result

-- | Begins defragmentation process.
--
-- __Parameters.__
--
-- +-----------+-----------+-----------------------------------------------+
-- |           | allocator | Allocator object.                             |
-- +-----------+-----------+-----------------------------------------------+
-- |           | pInfo     | Structure filled with parameters of           |
-- |           |           | defragmentation.                              |
-- +-----------+-----------+-----------------------------------------------+
-- | out       | pStats    | Optional. Statistics of defragmentation. You  |
-- |           |           | can pass null if you are not interested in    |
-- |           |           | this information.                             |
-- +-----------+-----------+-----------------------------------------------+
-- | out       | pContext  | Context object that must be passed to         |
-- |           |           | 'defragmentationEnd' to finish                |
-- |           |           | defragmentation.                              |
-- +-----------+-----------+-----------------------------------------------+
--
-- __Returns.__
--
-- @VK_SUCCESS@ and @*pContext == null@ if defragmentation finished within
-- this function call. @VK_NOT_READY@ and @*pContext != null@ if
-- defragmentation has been started and you need to call
-- 'defragmentationEnd' to finish it. Negative value in case of error.
--
-- Use this function instead of old, deprecated 'defragment'.
--
-- Warning! Between the call to 'defragmentationBegin' and
-- 'defragmentationEnd':
--
-- -   You should not use any of allocations passed as
--     @pInfo->pAllocations@ or any allocations that belong to pools passed
--     as @pInfo->pPools@, including calling 'getAllocationInfo',
--     'touchAllocation', or access their data.
--
-- -   Some mutexes protecting internal data structures may be locked, so
--     trying to make or free any allocations, bind buffers or images, map
--     memory, or launch another simultaneous defragmentation in between
--     may cause stall (when done on another thread) or deadlock (when done
--     on the same thread), unless you are 100% sure that defragmented
--     allocations are in different pools.
--
-- -   Information returned via @pStats@ and @pInfo->pAllocationsChanged@
--     are undefined. They become valid after call to 'defragmentationEnd'.
--
-- -   If @pInfo->commandBuffer@ is not null, you must submit that command
--     buffer and make sure it finished execution before calling
--     'defragmentationEnd'.
--
-- For more information and important limitations regarding
-- defragmentation, see documentation chapter: /Defragmentation/.
defragmentationBegin :: forall io
                      . (MonadIO io)
                     => -- No documentation found for Nested "vmaDefragmentationBegin" "allocator"
                        Allocator
                     -> -- No documentation found for Nested "vmaDefragmentationBegin" "pInfo"
                        DefragmentationInfo2
                     -> io (Result, DefragmentationStats, DefragmentationContext)
defragmentationBegin :: Allocator
-> DefragmentationInfo2
-> io (Result, DefragmentationStats, DefragmentationContext)
defragmentationBegin allocator :: Allocator
allocator info :: DefragmentationInfo2
info = IO (Result, DefragmentationStats, DefragmentationContext)
-> io (Result, DefragmentationStats, DefragmentationContext)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Result, DefragmentationStats, DefragmentationContext)
 -> io (Result, DefragmentationStats, DefragmentationContext))
-> (ContT
      (Result, DefragmentationStats, DefragmentationContext)
      IO
      (Result, DefragmentationStats, DefragmentationContext)
    -> IO (Result, DefragmentationStats, DefragmentationContext))
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     (Result, DefragmentationStats, DefragmentationContext)
-> io (Result, DefragmentationStats, DefragmentationContext)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  (Result, DefragmentationStats, DefragmentationContext)
  IO
  (Result, DefragmentationStats, DefragmentationContext)
-> IO (Result, DefragmentationStats, DefragmentationContext)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   (Result, DefragmentationStats, DefragmentationContext)
   IO
   (Result, DefragmentationStats, DefragmentationContext)
 -> io (Result, DefragmentationStats, DefragmentationContext))
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     (Result, DefragmentationStats, DefragmentationContext)
-> io (Result, DefragmentationStats, DefragmentationContext)
forall a b. (a -> b) -> a -> b
$ do
  Ptr DefragmentationInfo2
pInfo <- ((Ptr DefragmentationInfo2
  -> IO (Result, DefragmentationStats, DefragmentationContext))
 -> IO (Result, DefragmentationStats, DefragmentationContext))
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     (Ptr DefragmentationInfo2)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr DefragmentationInfo2
   -> IO (Result, DefragmentationStats, DefragmentationContext))
  -> IO (Result, DefragmentationStats, DefragmentationContext))
 -> ContT
      (Result, DefragmentationStats, DefragmentationContext)
      IO
      (Ptr DefragmentationInfo2))
-> ((Ptr DefragmentationInfo2
     -> IO (Result, DefragmentationStats, DefragmentationContext))
    -> IO (Result, DefragmentationStats, DefragmentationContext))
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     (Ptr DefragmentationInfo2)
forall a b. (a -> b) -> a -> b
$ DefragmentationInfo2
-> (Ptr DefragmentationInfo2
    -> IO (Result, DefragmentationStats, DefragmentationContext))
-> IO (Result, DefragmentationStats, DefragmentationContext)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (DefragmentationInfo2
info)
  Ptr DefragmentationStats
pPStats <- ((Ptr DefragmentationStats
  -> IO (Result, DefragmentationStats, DefragmentationContext))
 -> IO (Result, DefragmentationStats, DefragmentationContext))
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     (Ptr DefragmentationStats)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct DefragmentationStats =>
(Ptr DefragmentationStats -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @DefragmentationStats)
  Ptr DefragmentationContext
pPContext <- ((Ptr DefragmentationContext
  -> IO (Result, DefragmentationStats, DefragmentationContext))
 -> IO (Result, DefragmentationStats, DefragmentationContext))
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     (Ptr DefragmentationContext)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr DefragmentationContext
   -> IO (Result, DefragmentationStats, DefragmentationContext))
  -> IO (Result, DefragmentationStats, DefragmentationContext))
 -> ContT
      (Result, DefragmentationStats, DefragmentationContext)
      IO
      (Ptr DefragmentationContext))
-> ((Ptr DefragmentationContext
     -> IO (Result, DefragmentationStats, DefragmentationContext))
    -> IO (Result, DefragmentationStats, DefragmentationContext))
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     (Ptr DefragmentationContext)
forall a b. (a -> b) -> a -> b
$ IO (Ptr DefragmentationContext)
-> (Ptr DefragmentationContext -> IO ())
-> (Ptr DefragmentationContext
    -> IO (Result, DefragmentationStats, DefragmentationContext))
-> IO (Result, DefragmentationStats, DefragmentationContext)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr DefragmentationContext)
forall a. Int -> IO (Ptr a)
callocBytes @DefragmentationContext 8) Ptr DefragmentationContext -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result
-> ContT
     (Result, DefragmentationStats, DefragmentationContext) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result
 -> ContT
      (Result, DefragmentationStats, DefragmentationContext) IO Result)
-> IO Result
-> ContT
     (Result, DefragmentationStats, DefragmentationContext) IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> Ptr DefragmentationInfo2
-> Ptr DefragmentationStats
-> Ptr DefragmentationContext
-> IO Result
ffiVmaDefragmentationBegin) (Allocator
allocator) Ptr DefragmentationInfo2
pInfo (Ptr DefragmentationStats
pPStats) (Ptr DefragmentationContext
pPContext)
  IO ()
-> ContT
     (Result, DefragmentationStats, DefragmentationContext) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ()
 -> ContT
      (Result, DefragmentationStats, DefragmentationContext) IO ())
-> IO ()
-> ContT
     (Result, DefragmentationStats, DefragmentationContext) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  DefragmentationStats
pStats <- IO DefragmentationStats
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     DefragmentationStats
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO DefragmentationStats
 -> ContT
      (Result, DefragmentationStats, DefragmentationContext)
      IO
      DefragmentationStats)
-> IO DefragmentationStats
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     DefragmentationStats
forall a b. (a -> b) -> a -> b
$ Ptr DefragmentationStats -> IO DefragmentationStats
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @DefragmentationStats Ptr DefragmentationStats
pPStats
  DefragmentationContext
pContext <- IO DefragmentationContext
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     DefragmentationContext
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO DefragmentationContext
 -> ContT
      (Result, DefragmentationStats, DefragmentationContext)
      IO
      DefragmentationContext)
-> IO DefragmentationContext
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     DefragmentationContext
forall a b. (a -> b) -> a -> b
$ Ptr DefragmentationContext -> IO DefragmentationContext
forall a. Storable a => Ptr a -> IO a
peek @DefragmentationContext Ptr DefragmentationContext
pPContext
  (Result, DefragmentationStats, DefragmentationContext)
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     (Result, DefragmentationStats, DefragmentationContext)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Result, DefragmentationStats, DefragmentationContext)
 -> ContT
      (Result, DefragmentationStats, DefragmentationContext)
      IO
      (Result, DefragmentationStats, DefragmentationContext))
-> (Result, DefragmentationStats, DefragmentationContext)
-> ContT
     (Result, DefragmentationStats, DefragmentationContext)
     IO
     (Result, DefragmentationStats, DefragmentationContext)
forall a b. (a -> b) -> a -> b
$ (Result
r, DefragmentationStats
pStats, DefragmentationContext
pContext)

-- | A convenience wrapper to make a compatible pair of calls to
-- 'defragmentationBegin' and 'defragmentationEnd'
--
-- To ensure that 'defragmentationEnd' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the first argument.
-- To just extract the pair pass '(,)' as the first argument.
--
withDefragmentation :: forall io r . MonadIO io => Allocator -> DefragmentationInfo2 -> (io (Result, DefragmentationStats, DefragmentationContext) -> ((Result, DefragmentationStats, DefragmentationContext) -> io ()) -> r) -> r
withDefragmentation :: Allocator
-> DefragmentationInfo2
-> (io (Result, DefragmentationStats, DefragmentationContext)
    -> ((Result, DefragmentationStats, DefragmentationContext)
        -> io ())
    -> r)
-> r
withDefragmentation allocator :: Allocator
allocator pInfo :: DefragmentationInfo2
pInfo b :: io (Result, DefragmentationStats, DefragmentationContext)
-> ((Result, DefragmentationStats, DefragmentationContext)
    -> io ())
-> r
b =
  io (Result, DefragmentationStats, DefragmentationContext)
-> ((Result, DefragmentationStats, DefragmentationContext)
    -> io ())
-> r
b (Allocator
-> DefragmentationInfo2
-> io (Result, DefragmentationStats, DefragmentationContext)
forall (io :: * -> *).
MonadIO io =>
Allocator
-> DefragmentationInfo2
-> io (Result, DefragmentationStats, DefragmentationContext)
defragmentationBegin Allocator
allocator DefragmentationInfo2
pInfo)
    (\(_, _, o2 :: DefragmentationContext
o2) -> Allocator -> DefragmentationContext -> io ()
forall (io :: * -> *).
MonadIO io =>
Allocator -> DefragmentationContext -> io ()
defragmentationEnd Allocator
allocator DefragmentationContext
o2)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaDefragmentationEnd" ffiVmaDefragmentationEnd
  :: Allocator -> DefragmentationContext -> IO Result

-- | Ends defragmentation process.
--
-- Use this function to finish defragmentation started by
-- 'defragmentationBegin'. It is safe to pass @context == null@. The
-- function then does nothing.
defragmentationEnd :: forall io
                    . (MonadIO io)
                   => -- No documentation found for Nested "vmaDefragmentationEnd" "allocator"
                      Allocator
                   -> -- No documentation found for Nested "vmaDefragmentationEnd" "context"
                      DefragmentationContext
                   -> io ()
defragmentationEnd :: Allocator -> DefragmentationContext -> io ()
defragmentationEnd allocator :: Allocator
allocator context :: DefragmentationContext
context = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator -> DefragmentationContext -> IO Result
ffiVmaDefragmentationEnd) (Allocator
allocator) (DefragmentationContext
context)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaBeginDefragmentationPass" ffiVmaBeginDefragmentationPass
  :: Allocator -> DefragmentationContext -> Ptr DefragmentationPassInfo -> IO Result


beginDefragmentationPass :: forall io
                          . (MonadIO io)
                         => -- No documentation found for Nested "vmaBeginDefragmentationPass" "allocator"
                            Allocator
                         -> -- No documentation found for Nested "vmaBeginDefragmentationPass" "context"
                            DefragmentationContext
                         -> io (DefragmentationPassInfo)
beginDefragmentationPass :: Allocator -> DefragmentationContext -> io DefragmentationPassInfo
beginDefragmentationPass allocator :: Allocator
allocator context :: DefragmentationContext
context = IO DefragmentationPassInfo -> io DefragmentationPassInfo
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO DefragmentationPassInfo -> io DefragmentationPassInfo)
-> (ContT DefragmentationPassInfo IO DefragmentationPassInfo
    -> IO DefragmentationPassInfo)
-> ContT DefragmentationPassInfo IO DefragmentationPassInfo
-> io DefragmentationPassInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT DefragmentationPassInfo IO DefragmentationPassInfo
-> IO DefragmentationPassInfo
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT DefragmentationPassInfo IO DefragmentationPassInfo
 -> io DefragmentationPassInfo)
-> ContT DefragmentationPassInfo IO DefragmentationPassInfo
-> io DefragmentationPassInfo
forall a b. (a -> b) -> a -> b
$ do
  Ptr DefragmentationPassInfo
pPInfo <- ((Ptr DefragmentationPassInfo -> IO DefragmentationPassInfo)
 -> IO DefragmentationPassInfo)
-> ContT DefragmentationPassInfo IO (Ptr DefragmentationPassInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct DefragmentationPassInfo =>
(Ptr DefragmentationPassInfo -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @DefragmentationPassInfo)
  Result
r <- IO Result -> ContT DefragmentationPassInfo IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT DefragmentationPassInfo IO Result)
-> IO Result -> ContT DefragmentationPassInfo IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> DefragmentationContext
-> Ptr DefragmentationPassInfo
-> IO Result
ffiVmaBeginDefragmentationPass) (Allocator
allocator) (DefragmentationContext
context) (Ptr DefragmentationPassInfo
pPInfo)
  IO () -> ContT DefragmentationPassInfo IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT DefragmentationPassInfo IO ())
-> IO () -> ContT DefragmentationPassInfo IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  DefragmentationPassInfo
pInfo <- IO DefragmentationPassInfo
-> ContT DefragmentationPassInfo IO DefragmentationPassInfo
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO DefragmentationPassInfo
 -> ContT DefragmentationPassInfo IO DefragmentationPassInfo)
-> IO DefragmentationPassInfo
-> ContT DefragmentationPassInfo IO DefragmentationPassInfo
forall a b. (a -> b) -> a -> b
$ Ptr DefragmentationPassInfo -> IO DefragmentationPassInfo
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @DefragmentationPassInfo Ptr DefragmentationPassInfo
pPInfo
  DefragmentationPassInfo
-> ContT DefragmentationPassInfo IO DefragmentationPassInfo
forall (f :: * -> *) a. Applicative f => a -> f a
pure (DefragmentationPassInfo
 -> ContT DefragmentationPassInfo IO DefragmentationPassInfo)
-> DefragmentationPassInfo
-> ContT DefragmentationPassInfo IO DefragmentationPassInfo
forall a b. (a -> b) -> a -> b
$ (DefragmentationPassInfo
pInfo)

-- | This function will call the supplied action between calls to
-- 'beginDefragmentationPass' and 'endDefragmentationPass'
--
-- Note that 'endDefragmentationPass' is *not* called if an exception is
-- thrown by the inner action.
useDefragmentationPass :: forall io r . MonadIO io => Allocator -> DefragmentationContext -> ((DefragmentationPassInfo) -> io r) -> io r
useDefragmentationPass :: Allocator
-> DefragmentationContext
-> (DefragmentationPassInfo -> io r)
-> io r
useDefragmentationPass allocator :: Allocator
allocator context :: DefragmentationContext
context a :: DefragmentationPassInfo -> io r
a =
  do
    DefragmentationPassInfo
x <- Allocator -> DefragmentationContext -> io DefragmentationPassInfo
forall (io :: * -> *).
MonadIO io =>
Allocator -> DefragmentationContext -> io DefragmentationPassInfo
beginDefragmentationPass Allocator
allocator DefragmentationContext
context
    r
r <- DefragmentationPassInfo -> io r
a DefragmentationPassInfo
x
    (\(DefragmentationPassInfo
_) -> Allocator -> DefragmentationContext -> io ()
forall (io :: * -> *).
MonadIO io =>
Allocator -> DefragmentationContext -> io ()
endDefragmentationPass Allocator
allocator DefragmentationContext
context) DefragmentationPassInfo
x
    r -> io r
forall (f :: * -> *) a. Applicative f => a -> f a
pure r
r


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaEndDefragmentationPass" ffiVmaEndDefragmentationPass
  :: Allocator -> DefragmentationContext -> IO Result


endDefragmentationPass :: forall io
                        . (MonadIO io)
                       => -- No documentation found for Nested "vmaEndDefragmentationPass" "allocator"
                          Allocator
                       -> -- No documentation found for Nested "vmaEndDefragmentationPass" "context"
                          DefragmentationContext
                       -> io ()
endDefragmentationPass :: Allocator -> DefragmentationContext -> io ()
endDefragmentationPass allocator :: Allocator
allocator context :: DefragmentationContext
context = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator -> DefragmentationContext -> IO Result
ffiVmaEndDefragmentationPass) (Allocator
allocator) (DefragmentationContext
context)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaDefragment" ffiVmaDefragment
  :: Allocator -> Ptr Allocation -> CSize -> Ptr Bool32 -> Ptr DefragmentationInfo -> Ptr DefragmentationStats -> IO Result

-- | Deprecated. Compacts memory by moving allocations.
--
-- __Parameters.__
--
-- +-----------+-----------------------+-----------------------------------------------+
-- |           | pAllocations          | Array of allocations that can be moved during |
-- |           |                       | this compation.                               |
-- +-----------+-----------------------+-----------------------------------------------+
-- |           | allocationCount       | Number of elements in pAllocations and        |
-- |           |                       | pAllocationsChanged arrays.                   |
-- +-----------+-----------------------+-----------------------------------------------+
-- | out       | pAllocationsChanged   | Array of boolean values that will indicate    |
-- |           |                       | whether matching allocation in pAllocations   |
-- |           |                       | array has been moved. This parameter is       |
-- |           |                       | optional. Pass null if you don\'t need this   |
-- |           |                       | information.                                  |
-- +-----------+-----------------------+-----------------------------------------------+
-- |           | pDefragmentationInfo  | Configuration parameters. Optional - pass     |
-- |           |                       | null to use default values.                   |
-- +-----------+-----------------------+-----------------------------------------------+
-- | out       | pDefragmentationStats | Statistics returned by the function. Optional |
-- |           |                       | - pass null if you don\'t need this           |
-- |           |                       | information.                                  |
-- +-----------+-----------------------+-----------------------------------------------+
--
-- __Returns.__
--
-- @VK_SUCCESS@ if completed, negative error code in case of error.
--
-- /Deprecated/
--
-- This is a part of the old interface. It is recommended to use structure
-- 'DefragmentationInfo2' and function 'defragmentationBegin' instead.
--
-- This function works by moving allocations to different places (different
-- @VkDeviceMemory@ objects and\/or different offsets) in order to optimize
-- memory usage. Only allocations that are in @pAllocations@ array can be
-- moved. All other allocations are considered nonmovable in this call.
-- Basic rules:
--
-- -   Only allocations made in memory types that have
--     @VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT@ and
--     @VK_MEMORY_PROPERTY_HOST_COHERENT_BIT@ flags can be compacted. You
--     may pass other allocations but it makes no sense - these will never
--     be moved.
--
-- -   Custom pools created with 'POOL_CREATE_LINEAR_ALGORITHM_BIT' or
--     'POOL_CREATE_BUDDY_ALGORITHM_BIT' flag are not defragmented.
--     Allocations passed to this function that come from such pools are
--     ignored.
--
-- -   Allocations created with 'ALLOCATION_CREATE_DEDICATED_MEMORY_BIT' or
--     created as dedicated allocations for any other reason are also
--     ignored.
--
-- -   Both allocations made with or without 'ALLOCATION_CREATE_MAPPED_BIT'
--     flag can be compacted. If not persistently mapped, memory will be
--     mapped temporarily inside this function if needed.
--
-- -   You must not pass same 'Allocation' object multiple times in
--     @pAllocations@ array.
--
-- The function also frees empty @VkDeviceMemory@ blocks.
--
-- Warning: This function may be time-consuming, so you shouldn\'t call it
-- too often (like after every resource creation\/destruction). You can
-- call it on special occasions (like when reloading a game level or when
-- you just destroyed a lot of objects). Calling it every frame may be OK,
-- but you should measure that on your platform.
--
-- For more information, see /Defragmentation/ chapter.
defragment :: forall io
            . (MonadIO io)
           => -- No documentation found for Nested "vmaDefragment" "allocator"
              Allocator
           -> -- No documentation found for Nested "vmaDefragment" "pAllocations"
              ("allocations" ::: Vector Allocation)
           -> -- No documentation found for Nested "vmaDefragment" "pDefragmentationInfo"
              ("defragmentationInfo" ::: Maybe DefragmentationInfo)
           -> io (("allocationsChanged" ::: Vector Bool), DefragmentationStats)
defragment :: Allocator
-> ("allocations" ::: Vector Allocation)
-> ("defragmentationInfo" ::: Maybe DefragmentationInfo)
-> io ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
defragment allocator :: Allocator
allocator allocations :: "allocations" ::: Vector Allocation
allocations defragmentationInfo :: "defragmentationInfo" ::: Maybe DefragmentationInfo
defragmentationInfo = IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
-> io ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
 -> io ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> (ContT
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
      IO
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
    -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
-> io ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
  IO
  ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
-> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
   IO
   ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
 -> io ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
-> io ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
forall a b. (a -> b) -> a -> b
$ do
  Ptr Allocation
pPAllocations <- ((Ptr Allocation
  -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
 -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     (Ptr Allocation)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocation
   -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
  -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
 -> ContT
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
      IO
      (Ptr Allocation))
-> ((Ptr Allocation
     -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
    -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     (Ptr Allocation)
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> (Ptr Allocation
    -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned @Allocation ((("allocations" ::: Vector Allocation) -> Int
forall a. Vector a -> Int
Data.Vector.length ("allocations" ::: Vector Allocation
allocations)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8) 8
  IO ()
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ()
 -> ContT
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats) IO ())
-> IO ()
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats) IO ()
forall a b. (a -> b) -> a -> b
$ (Int -> Allocation -> IO ())
-> ("allocations" ::: Vector Allocation) -> IO ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\i :: Int
i e :: Allocation
e -> Ptr Allocation -> Allocation -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Allocation
pPAllocations Ptr Allocation -> Int -> Ptr Allocation
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Allocation) (Allocation
e)) ("allocations" ::: Vector Allocation
allocations)
  Ptr Bool32
pPAllocationsChanged <- ((Ptr Bool32
  -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
 -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     (Ptr Bool32)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Bool32
   -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
  -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
 -> ContT
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
      IO
      (Ptr Bool32))
-> ((Ptr Bool32
     -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
    -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     (Ptr Bool32)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Bool32)
-> (Ptr Bool32 -> IO ())
-> (Ptr Bool32
    -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Bool32)
forall a. Int -> IO (Ptr a)
callocBytes @Bool32 ((CSize -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral (("allocations" ::: Vector Allocation) -> Int
forall a. Vector a -> Int
Data.Vector.length (("allocations" ::: Vector Allocation) -> Int)
-> ("allocations" ::: Vector Allocation) -> Int
forall a b. (a -> b) -> a -> b
$ ("allocations" ::: Vector Allocation
allocations)) :: CSize))) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 4)) Ptr Bool32 -> IO ()
forall a. Ptr a -> IO ()
free
  Ptr DefragmentationInfo
pDefragmentationInfo <- case ("defragmentationInfo" ::: Maybe DefragmentationInfo
defragmentationInfo) of
    Nothing -> Ptr DefragmentationInfo
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     (Ptr DefragmentationInfo)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ptr DefragmentationInfo
forall a. Ptr a
nullPtr
    Just j :: DefragmentationInfo
j -> ((Ptr DefragmentationInfo
  -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
 -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     (Ptr DefragmentationInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr DefragmentationInfo
   -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
  -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
 -> ContT
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
      IO
      (Ptr DefragmentationInfo))
-> ((Ptr DefragmentationInfo
     -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
    -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     (Ptr DefragmentationInfo)
forall a b. (a -> b) -> a -> b
$ DefragmentationInfo
-> (Ptr DefragmentationInfo
    -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (DefragmentationInfo
j)
  Ptr DefragmentationStats
pPDefragmentationStats <- ((Ptr DefragmentationStats
  -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
 -> IO ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     (Ptr DefragmentationStats)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct DefragmentationStats =>
(Ptr DefragmentationStats -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @DefragmentationStats)
  Result
r <- IO Result
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result
 -> ContT
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
      IO
      Result)
-> IO Result
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> Ptr Allocation
-> CSize
-> Ptr Bool32
-> Ptr DefragmentationInfo
-> Ptr DefragmentationStats
-> IO Result
ffiVmaDefragment) (Allocator
allocator) (Ptr Allocation
pPAllocations) ((Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral (("allocations" ::: Vector Allocation) -> Int
forall a. Vector a -> Int
Data.Vector.length (("allocations" ::: Vector Allocation) -> Int)
-> ("allocations" ::: Vector Allocation) -> Int
forall a b. (a -> b) -> a -> b
$ ("allocations" ::: Vector Allocation
allocations)) :: CSize)) (Ptr Bool32
pPAllocationsChanged) Ptr DefragmentationInfo
pDefragmentationInfo (Ptr DefragmentationStats
pPDefragmentationStats)
  IO ()
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ()
 -> ContT
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats) IO ())
-> IO ()
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  "allocationsChanged" ::: Vector Bool
pAllocationsChanged <- IO ("allocationsChanged" ::: Vector Bool)
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     ("allocationsChanged" ::: Vector Bool)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO ("allocationsChanged" ::: Vector Bool)
 -> ContT
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
      IO
      ("allocationsChanged" ::: Vector Bool))
-> IO ("allocationsChanged" ::: Vector Bool)
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     ("allocationsChanged" ::: Vector Bool)
forall a b. (a -> b) -> a -> b
$ Int
-> (Int -> IO Bool) -> IO ("allocationsChanged" ::: Vector Bool)
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (CSize -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral (("allocations" ::: Vector Allocation) -> Int
forall a. Vector a -> Int
Data.Vector.length (("allocations" ::: Vector Allocation) -> Int)
-> ("allocations" ::: Vector Allocation) -> Int
forall a b. (a -> b) -> a -> b
$ ("allocations" ::: Vector Allocation
allocations)) :: CSize))) (\i :: Int
i -> do
    Bool32
pAllocationsChangedElem <- Ptr Bool32 -> IO Bool32
forall a. Storable a => Ptr a -> IO a
peek @Bool32 ((Ptr Bool32
pPAllocationsChanged Ptr Bool32 -> Int -> Ptr Bool32
forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (4 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr Bool32))
    Bool -> IO Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> IO Bool) -> Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ Bool32 -> Bool
bool32ToBool Bool32
pAllocationsChangedElem)
  DefragmentationStats
pDefragmentationStats <- IO DefragmentationStats
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     DefragmentationStats
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO DefragmentationStats
 -> ContT
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
      IO
      DefragmentationStats)
-> IO DefragmentationStats
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     DefragmentationStats
forall a b. (a -> b) -> a -> b
$ Ptr DefragmentationStats -> IO DefragmentationStats
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @DefragmentationStats Ptr DefragmentationStats
pPDefragmentationStats
  ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (("allocationsChanged" ::: Vector Bool, DefragmentationStats)
 -> ContT
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
      IO
      ("allocationsChanged" ::: Vector Bool, DefragmentationStats))
-> ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
-> ContT
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
     IO
     ("allocationsChanged" ::: Vector Bool, DefragmentationStats)
forall a b. (a -> b) -> a -> b
$ ("allocationsChanged" ::: Vector Bool
pAllocationsChanged, DefragmentationStats
pDefragmentationStats)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaBindBufferMemory" ffiVmaBindBufferMemory
  :: Allocator -> Allocation -> Buffer -> IO Result

-- | Binds buffer to allocation.
--
-- Binds specified buffer to region of memory represented by specified
-- allocation. Gets @VkDeviceMemory@ handle and offset from the allocation.
-- If you want to create a buffer, allocate memory for it and bind them
-- together separately, you should use this function for binding instead of
-- standard @vkBindBufferMemory()@, because it ensures proper
-- synchronization so that when a @VkDeviceMemory@ object is used by
-- multiple allocations, calls to @vkBind*Memory()@ or @vkMapMemory()@
-- won\'t happen from multiple threads simultaneously (which is illegal in
-- Vulkan).
--
-- It is recommended to use function 'createBuffer' instead of this one.
bindBufferMemory :: forall io
                  . (MonadIO io)
                 => -- No documentation found for Nested "vmaBindBufferMemory" "allocator"
                    Allocator
                 -> -- No documentation found for Nested "vmaBindBufferMemory" "allocation"
                    Allocation
                 -> -- No documentation found for Nested "vmaBindBufferMemory" "buffer"
                    Buffer
                 -> io ()
bindBufferMemory :: Allocator -> Allocation -> Buffer -> io ()
bindBufferMemory allocator :: Allocator
allocator allocation :: Allocation
allocation buffer :: Buffer
buffer = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator -> Allocation -> Buffer -> IO Result
ffiVmaBindBufferMemory) (Allocator
allocator) (Allocation
allocation) (Buffer
buffer)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaBindBufferMemory2" ffiVmaBindBufferMemory2
  :: Allocator -> Allocation -> DeviceSize -> Buffer -> Ptr () -> IO Result

-- | Binds buffer to allocation with additional parameters.
--
-- __Parameters.__
--
-- +-----------------------+--------------------------------------------------------+
-- | allocationLocalOffset | Additional offset to be added while binding, relative  |
-- |                       | to the beginnig of the @allocation@. Normally it       |
-- |                       | should be 0.                                           |
-- +-----------------------+--------------------------------------------------------+
-- | pNext                 | A chain of structures to be attached to                |
-- |                       | @VkBindBufferMemoryInfoKHR@ structure used internally. |
-- |                       | Normally it should be null.                            |
-- +-----------------------+--------------------------------------------------------+
--
-- This function is similar to 'bindBufferMemory', but it provides
-- additional parameters.
--
-- If @pNext@ is not null, 'Allocator' object must have been created with
-- 'ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT' flag or with
-- /VmaAllocatorCreateInfo::vulkanApiVersion/ @== VK_API_VERSION_1_1@.
-- Otherwise the call fails.
bindBufferMemory2 :: forall io
                   . (MonadIO io)
                  => -- No documentation found for Nested "vmaBindBufferMemory2" "allocator"
                     Allocator
                  -> -- No documentation found for Nested "vmaBindBufferMemory2" "allocation"
                     Allocation
                  -> -- No documentation found for Nested "vmaBindBufferMemory2" "allocationLocalOffset"
                     ("allocationLocalOffset" ::: DeviceSize)
                  -> -- No documentation found for Nested "vmaBindBufferMemory2" "buffer"
                     Buffer
                  -> -- No documentation found for Nested "vmaBindBufferMemory2" "pNext"
                     ("next" ::: Ptr ())
                  -> io ()
bindBufferMemory2 :: Allocator
-> Allocation
-> ("lostAllocationCount" ::: Word64)
-> Buffer
-> ("userData" ::: Ptr ())
-> io ()
bindBufferMemory2 allocator :: Allocator
allocator allocation :: Allocation
allocation allocationLocalOffset :: "lostAllocationCount" ::: Word64
allocationLocalOffset buffer :: Buffer
buffer next :: "userData" ::: Ptr ()
next = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator
-> Allocation
-> ("lostAllocationCount" ::: Word64)
-> Buffer
-> ("userData" ::: Ptr ())
-> IO Result
ffiVmaBindBufferMemory2) (Allocator
allocator) (Allocation
allocation) ("lostAllocationCount" ::: Word64
allocationLocalOffset) (Buffer
buffer) ("userData" ::: Ptr ()
next)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaBindImageMemory" ffiVmaBindImageMemory
  :: Allocator -> Allocation -> Image -> IO Result

-- | Binds image to allocation.
--
-- Binds specified image to region of memory represented by specified
-- allocation. Gets @VkDeviceMemory@ handle and offset from the allocation.
-- If you want to create an image, allocate memory for it and bind them
-- together separately, you should use this function for binding instead of
-- standard @vkBindImageMemory()@, because it ensures proper
-- synchronization so that when a @VkDeviceMemory@ object is used by
-- multiple allocations, calls to @vkBind*Memory()@ or @vkMapMemory()@
-- won\'t happen from multiple threads simultaneously (which is illegal in
-- Vulkan).
--
-- It is recommended to use function 'createImage' instead of this one.
bindImageMemory :: forall io
                 . (MonadIO io)
                => -- No documentation found for Nested "vmaBindImageMemory" "allocator"
                   Allocator
                -> -- No documentation found for Nested "vmaBindImageMemory" "allocation"
                   Allocation
                -> -- No documentation found for Nested "vmaBindImageMemory" "image"
                   Image
                -> io ()
bindImageMemory :: Allocator -> Allocation -> Image -> io ()
bindImageMemory allocator :: Allocator
allocator allocation :: Allocation
allocation image :: Image
image = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator -> Allocation -> Image -> IO Result
ffiVmaBindImageMemory) (Allocator
allocator) (Allocation
allocation) (Image
image)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaBindImageMemory2" ffiVmaBindImageMemory2
  :: Allocator -> Allocation -> DeviceSize -> Image -> Ptr () -> IO Result

-- | Binds image to allocation with additional parameters.
--
-- __Parameters.__
--
-- +-----------------------+--------------------------------------------------------+
-- | allocationLocalOffset | Additional offset to be added while binding, relative  |
-- |                       | to the beginnig of the @allocation@. Normally it       |
-- |                       | should be 0.                                           |
-- +-----------------------+--------------------------------------------------------+
-- | pNext                 | A chain of structures to be attached to                |
-- |                       | @VkBindImageMemoryInfoKHR@ structure used internally.  |
-- |                       | Normally it should be null.                            |
-- +-----------------------+--------------------------------------------------------+
--
-- This function is similar to 'bindImageMemory', but it provides
-- additional parameters.
--
-- If @pNext@ is not null, 'Allocator' object must have been created with
-- 'ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT' flag or with
-- /VmaAllocatorCreateInfo::vulkanApiVersion/ @== VK_API_VERSION_1_1@.
-- Otherwise the call fails.
bindImageMemory2 :: forall io
                  . (MonadIO io)
                 => -- No documentation found for Nested "vmaBindImageMemory2" "allocator"
                    Allocator
                 -> -- No documentation found for Nested "vmaBindImageMemory2" "allocation"
                    Allocation
                 -> -- No documentation found for Nested "vmaBindImageMemory2" "allocationLocalOffset"
                    ("allocationLocalOffset" ::: DeviceSize)
                 -> -- No documentation found for Nested "vmaBindImageMemory2" "image"
                    Image
                 -> -- No documentation found for Nested "vmaBindImageMemory2" "pNext"
                    ("next" ::: Ptr ())
                 -> io ()
bindImageMemory2 :: Allocator
-> Allocation
-> ("lostAllocationCount" ::: Word64)
-> Image
-> ("userData" ::: Ptr ())
-> io ()
bindImageMemory2 allocator :: Allocator
allocator allocation :: Allocation
allocation allocationLocalOffset :: "lostAllocationCount" ::: Word64
allocationLocalOffset image :: Image
image next :: "userData" ::: Ptr ()
next = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  Result
r <- (Allocator
-> Allocation
-> ("lostAllocationCount" ::: Word64)
-> Image
-> ("userData" ::: Ptr ())
-> IO Result
ffiVmaBindImageMemory2) (Allocator
allocator) (Allocation
allocation) ("lostAllocationCount" ::: Word64
allocationLocalOffset) (Image
image) ("userData" ::: Ptr ()
next)
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaCreateBuffer" ffiVmaCreateBuffer
  :: Allocator -> Ptr (SomeStruct BufferCreateInfo) -> Ptr AllocationCreateInfo -> Ptr Buffer -> Ptr Allocation -> Ptr AllocationInfo -> IO Result

-- | __Parameters.__
--
-- +-----------+-----------------+-----------------------------------------------+
-- | out       | pBuffer         | Buffer that was created.                      |
-- +-----------+-----------------+-----------------------------------------------+
-- | out       | pAllocation     | Allocation that was created.                  |
-- +-----------+-----------------+-----------------------------------------------+
-- | out       | pAllocationInfo | Optional. Information about allocated memory. |
-- |           |                 | It can be later fetched using function        |
-- |           |                 | 'getAllocationInfo'.                          |
-- +-----------+-----------------+-----------------------------------------------+
--
-- This function automatically:
--
-- 1.  Creates buffer.
--
-- 2.  Allocates appropriate memory for it.
--
-- 3.  Binds the buffer with the memory.
--
-- If any of these operations fail, buffer and allocation are not created,
-- returned value is negative error code, *pBuffer and *pAllocation are
-- null.
--
-- If the function succeeded, you must destroy both buffer and allocation
-- when you no longer need them using either convenience function
-- 'destroyBuffer' or separately, using @vkDestroyBuffer()@ and
-- 'freeMemory'.
--
-- If VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT flag was used,
-- VK_KHR_dedicated_allocation extension is used internally to query driver
-- whether it requires or prefers the new buffer to have dedicated
-- allocation. If yes, and if dedicated allocation is possible
-- (/VmaAllocationCreateInfo::pool/ is null and
-- VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT is not used), it creates
-- dedicated allocation for this buffer, just like when using
-- VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.
createBuffer :: forall a io
              . (Extendss BufferCreateInfo a, PokeChain a, MonadIO io)
             => -- No documentation found for Nested "vmaCreateBuffer" "allocator"
                Allocator
             -> -- No documentation found for Nested "vmaCreateBuffer" "pBufferCreateInfo"
                (BufferCreateInfo a)
             -> -- No documentation found for Nested "vmaCreateBuffer" "pAllocationCreateInfo"
                AllocationCreateInfo
             -> io (Buffer, Allocation, AllocationInfo)
createBuffer :: Allocator
-> BufferCreateInfo a
-> AllocationCreateInfo
-> io (Buffer, Allocation, AllocationInfo)
createBuffer allocator :: Allocator
allocator bufferCreateInfo :: BufferCreateInfo a
bufferCreateInfo allocationCreateInfo :: AllocationCreateInfo
allocationCreateInfo = IO (Buffer, Allocation, AllocationInfo)
-> io (Buffer, Allocation, AllocationInfo)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Buffer, Allocation, AllocationInfo)
 -> io (Buffer, Allocation, AllocationInfo))
-> (ContT
      (Buffer, Allocation, AllocationInfo)
      IO
      (Buffer, Allocation, AllocationInfo)
    -> IO (Buffer, Allocation, AllocationInfo))
-> ContT
     (Buffer, Allocation, AllocationInfo)
     IO
     (Buffer, Allocation, AllocationInfo)
-> io (Buffer, Allocation, AllocationInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  (Buffer, Allocation, AllocationInfo)
  IO
  (Buffer, Allocation, AllocationInfo)
-> IO (Buffer, Allocation, AllocationInfo)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   (Buffer, Allocation, AllocationInfo)
   IO
   (Buffer, Allocation, AllocationInfo)
 -> io (Buffer, Allocation, AllocationInfo))
-> ContT
     (Buffer, Allocation, AllocationInfo)
     IO
     (Buffer, Allocation, AllocationInfo)
-> io (Buffer, Allocation, AllocationInfo)
forall a b. (a -> b) -> a -> b
$ do
  Ptr (BufferCreateInfo a)
pBufferCreateInfo <- ((Ptr (BufferCreateInfo a)
  -> IO (Buffer, Allocation, AllocationInfo))
 -> IO (Buffer, Allocation, AllocationInfo))
-> ContT
     (Buffer, Allocation, AllocationInfo) IO (Ptr (BufferCreateInfo a))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr (BufferCreateInfo a)
   -> IO (Buffer, Allocation, AllocationInfo))
  -> IO (Buffer, Allocation, AllocationInfo))
 -> ContT
      (Buffer, Allocation, AllocationInfo) IO (Ptr (BufferCreateInfo a)))
-> ((Ptr (BufferCreateInfo a)
     -> IO (Buffer, Allocation, AllocationInfo))
    -> IO (Buffer, Allocation, AllocationInfo))
-> ContT
     (Buffer, Allocation, AllocationInfo) IO (Ptr (BufferCreateInfo a))
forall a b. (a -> b) -> a -> b
$ BufferCreateInfo a
-> (Ptr (BufferCreateInfo a)
    -> IO (Buffer, Allocation, AllocationInfo))
-> IO (Buffer, Allocation, AllocationInfo)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (BufferCreateInfo a
bufferCreateInfo)
  Ptr AllocationCreateInfo
pAllocationCreateInfo <- ((Ptr AllocationCreateInfo
  -> IO (Buffer, Allocation, AllocationInfo))
 -> IO (Buffer, Allocation, AllocationInfo))
-> ContT
     (Buffer, Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr AllocationCreateInfo
   -> IO (Buffer, Allocation, AllocationInfo))
  -> IO (Buffer, Allocation, AllocationInfo))
 -> ContT
      (Buffer, Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo))
-> ((Ptr AllocationCreateInfo
     -> IO (Buffer, Allocation, AllocationInfo))
    -> IO (Buffer, Allocation, AllocationInfo))
-> ContT
     (Buffer, Allocation, AllocationInfo) IO (Ptr AllocationCreateInfo)
forall a b. (a -> b) -> a -> b
$ AllocationCreateInfo
-> (Ptr AllocationCreateInfo
    -> IO (Buffer, Allocation, AllocationInfo))
-> IO (Buffer, Allocation, AllocationInfo)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (AllocationCreateInfo
allocationCreateInfo)
  Ptr Buffer
pPBuffer <- ((Ptr Buffer -> IO (Buffer, Allocation, AllocationInfo))
 -> IO (Buffer, Allocation, AllocationInfo))
-> ContT (Buffer, Allocation, AllocationInfo) IO (Ptr Buffer)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Buffer -> IO (Buffer, Allocation, AllocationInfo))
  -> IO (Buffer, Allocation, AllocationInfo))
 -> ContT (Buffer, Allocation, AllocationInfo) IO (Ptr Buffer))
-> ((Ptr Buffer -> IO (Buffer, Allocation, AllocationInfo))
    -> IO (Buffer, Allocation, AllocationInfo))
-> ContT (Buffer, Allocation, AllocationInfo) IO (Ptr Buffer)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Buffer)
-> (Ptr Buffer -> IO ())
-> (Ptr Buffer -> IO (Buffer, Allocation, AllocationInfo))
-> IO (Buffer, Allocation, AllocationInfo)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Buffer)
forall a. Int -> IO (Ptr a)
callocBytes @Buffer 8) Ptr Buffer -> IO ()
forall a. Ptr a -> IO ()
free
  Ptr Allocation
pPAllocation <- ((Ptr Allocation -> IO (Buffer, Allocation, AllocationInfo))
 -> IO (Buffer, Allocation, AllocationInfo))
-> ContT (Buffer, Allocation, AllocationInfo) IO (Ptr Allocation)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr Allocation -> IO (Buffer, Allocation, AllocationInfo))
  -> IO (Buffer, Allocation, AllocationInfo))
 -> ContT (Buffer, Allocation, AllocationInfo) IO (Ptr Allocation))
-> ((Ptr Allocation -> IO (Buffer, Allocation, AllocationInfo))
    -> IO (Buffer, Allocation, AllocationInfo))
-> ContT (Buffer, Allocation, AllocationInfo) IO (Ptr Allocation)
forall a b. (a -> b) -> a -> b
$ IO (Ptr Allocation)
-> (Ptr Allocation -> IO ())
-> (Ptr Allocation -> IO (Buffer, Allocation, AllocationInfo))
-> IO (Buffer, Allocation, AllocationInfo)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO (Ptr Allocation)
forall a. Int -> IO (Ptr a)
callocBytes @Allocation 8) Ptr Allocation -> IO ()
forall a. Ptr a -> IO ()
free
  Ptr AllocationInfo
pPAllocationInfo <- ((Ptr AllocationInfo -> IO (Buffer, Allocation, AllocationInfo))
 -> IO (Buffer, Allocation, AllocationInfo))
-> ContT
     (Buffer, Allocation, AllocationInfo) IO (Ptr AllocationInfo)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct AllocationInfo =>
(Ptr AllocationInfo -> IO b) -> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @AllocationInfo)
  Result
r <- IO Result -> ContT (Buffer, Allocation, AllocationInfo) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT (Buffer, Allocation, AllocationInfo) IO Result)
-> IO Result
-> ContT (Buffer, Allocation, AllocationInfo) IO Result
forall a b. (a -> b) -> a -> b
$ (Allocator
-> Ptr (SomeStruct BufferCreateInfo)
-> Ptr AllocationCreateInfo
-> Ptr Buffer
-> Ptr Allocation
-> Ptr AllocationInfo
-> IO Result
ffiVmaCreateBuffer) (Allocator
allocator) (Ptr (BufferCreateInfo a) -> Ptr (SomeStruct BufferCreateInfo)
forall (a :: [*] -> *) (es :: [*]).
Ptr (a es) -> Ptr (SomeStruct a)
forgetExtensions Ptr (BufferCreateInfo a)
pBufferCreateInfo) Ptr AllocationCreateInfo
pAllocationCreateInfo (Ptr Buffer
pPBuffer) (Ptr Allocation
pPAllocation) (Ptr AllocationInfo
pPAllocationInfo)
  IO () -> ContT (Buffer, Allocation, AllocationInfo) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT (Buffer, Allocation, AllocationInfo) IO ())
-> IO () -> ContT (Buffer, Allocation, AllocationInfo) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (VulkanException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  Buffer
pBuffer <- IO Buffer -> ContT (Buffer, Allocation, AllocationInfo) IO Buffer
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Buffer -> ContT (Buffer, Allocation, AllocationInfo) IO Buffer)
-> IO Buffer
-> ContT (Buffer, Allocation, AllocationInfo) IO Buffer
forall a b. (a -> b) -> a -> b
$ Ptr Buffer -> IO Buffer
forall a. Storable a => Ptr a -> IO a
peek @Buffer Ptr Buffer
pPBuffer
  Allocation
pAllocation <- IO Allocation
-> ContT (Buffer, Allocation, AllocationInfo) IO Allocation
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Allocation
 -> ContT (Buffer, Allocation, AllocationInfo) IO Allocation)
-> IO Allocation
-> ContT (Buffer, Allocation, AllocationInfo) IO Allocation
forall a b. (a -> b) -> a -> b
$ Ptr Allocation -> IO Allocation
forall a. Storable a => Ptr a -> IO a
peek @Allocation Ptr Allocation
pPAllocation
  AllocationInfo
pAllocationInfo <- IO AllocationInfo
-> ContT (Buffer, Allocation, AllocationInfo) IO AllocationInfo
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO AllocationInfo
 -> ContT (Buffer, Allocation, AllocationInfo) IO AllocationInfo)
-> IO AllocationInfo
-> ContT (Buffer, Allocation, AllocationInfo) IO AllocationInfo
forall a b. (a -> b) -> a -> b
$ Ptr AllocationInfo -> IO AllocationInfo
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @AllocationInfo Ptr AllocationInfo
pPAllocationInfo
  (Buffer, Allocation, AllocationInfo)
-> ContT
     (Buffer, Allocation, AllocationInfo)
     IO
     (Buffer, Allocation, AllocationInfo)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Buffer, Allocation, AllocationInfo)
 -> ContT
      (Buffer, Allocation, AllocationInfo)
      IO
      (Buffer, Allocation, AllocationInfo))
-> (Buffer, Allocation, AllocationInfo)
-> ContT
     (Buffer, Allocation, AllocationInfo)
     IO
     (Buffer, Allocation, AllocationInfo)
forall a b. (a -> b) -> a -> b
$ (Buffer
pBuffer, Allocation
pAllocation, AllocationInfo
pAllocationInfo)

-- | A convenience wrapper to make a compatible pair of calls to
-- 'createBuffer' and 'destroyBuffer'
--
-- To ensure that 'destroyBuffer' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the first argument.
-- To just extract the pair pass '(,)' as the first argument.
--
withBuffer :: forall a io r . (Extendss BufferCreateInfo a, PokeChain a, MonadIO io) => Allocator -> BufferCreateInfo a -> AllocationCreateInfo -> (io (Buffer, Allocation, AllocationInfo) -> ((Buffer, Allocation, AllocationInfo) -> io ()) -> r) -> r
withBuffer :: Allocator
-> BufferCreateInfo a
-> AllocationCreateInfo
-> (io (Buffer, Allocation, AllocationInfo)
    -> ((Buffer, Allocation, AllocationInfo) -> io ()) -> r)
-> r
withBuffer allocator :: Allocator
allocator pBufferCreateInfo :: BufferCreateInfo a
pBufferCreateInfo pAllocationCreateInfo :: AllocationCreateInfo
pAllocationCreateInfo b :: io (Buffer, Allocation, AllocationInfo)
-> ((Buffer, Allocation, AllocationInfo) -> io ()) -> r
b =
  io (Buffer, Allocation, AllocationInfo)
-> ((Buffer, Allocation, AllocationInfo) -> io ()) -> r
b (Allocator
-> BufferCreateInfo a
-> AllocationCreateInfo
-> io (Buffer, Allocation, AllocationInfo)
forall (a :: [*]) (io :: * -> *).
(Extendss BufferCreateInfo a, PokeChain a, MonadIO io) =>
Allocator
-> BufferCreateInfo a
-> AllocationCreateInfo
-> io (Buffer, Allocation, AllocationInfo)
createBuffer Allocator
allocator BufferCreateInfo a
pBufferCreateInfo AllocationCreateInfo
pAllocationCreateInfo)
    (\(o0 :: Buffer
o0, o1 :: Allocation
o1, _) -> Allocator -> Buffer -> Allocation -> io ()
forall (io :: * -> *).
MonadIO io =>
Allocator -> Buffer -> Allocation -> io ()
destroyBuffer Allocator
allocator Buffer
o0 Allocation
o1)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaDestroyBuffer" ffiVmaDestroyBuffer
  :: Allocator -> Buffer -> Allocation -> IO ()

-- | Destroys Vulkan buffer and frees allocated memory.
--
-- This is just a convenience function equivalent to:
--
-- @vkDestroyBuffer(device, buffer, allocationCallbacks);
-- vmaFreeMemory(allocator, allocation);
-- @
--
-- It it safe to pass null as buffer and\/or allocation.
destroyBuffer :: forall io
               . (MonadIO io)
              => -- No documentation found for Nested "vmaDestroyBuffer" "allocator"
                 Allocator
              -> -- No documentation found for Nested "vmaDestroyBuffer" "buffer"
                 Buffer
              -> -- No documentation found for Nested "vmaDestroyBuffer" "allocation"
                 Allocation
              -> io ()
destroyBuffer :: Allocator -> Buffer -> Allocation -> io ()
destroyBuffer allocator :: Allocator
allocator buffer :: Buffer
buffer allocation :: Allocation
allocation = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  (Allocator -> Buffer -> Allocation -> IO ()
ffiVmaDestroyBuffer) (Allocator
allocator) (Buffer
buffer) (Allocation
allocation)
  () -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> IO ()) -> () -> IO ()
forall a b. (a -> b) -> a -> b
$ ()


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "vmaCreateImage" ffiVmaCreateImage
  :: Allocator -> Ptr (SomeStruct ImageCreateInfo) -> Ptr AllocationCreateInfo -> Ptr Image -> Ptr Allocation -> Ptr AllocationInfo -> IO Result

-- | Function similar to 'createBuffer'.
createImage :: forall a io
             . (Extendss ImageCreateInfo a, PokeChain a, MonadIO io)
            => -- No documentation found for Nested "vmaCreateImage" "allocator"
               Allocator
            -> -- No documentation found for Nested "vmaCreateImage" "pImageCreateInfo"
               (ImageCreateInfo a)
            -> -- No documentation found for Nested "vmaCreateImage" "pAllocationCreateInfo"
               AllocationCreateInfo
            -> io (Image, Allocation, AllocationInfo)
createImage :: Allocator
-> ImageCreateInfo a
-> AllocationCreateInfo
-> io (Image, Allocation, AllocationInfo)
createImage allocator :: Allocator
allocator imageCreateInfo :: ImageCreateInfo a
imageCreateInfo allocationCreateInfo :: AllocationCreateInfo
allocationCreateInfo = IO (Image, Allocation, AllocationInfo)
-> io (Image, Allocation, AllocationInfo)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Image, Allocation, AllocationInfo)
 -> io (Image, Allocation, AllocationInfo))
-> (ContT
      (Image, Allocation, AllocationInfo)
      IO
      (Image, Allocation, AllocationInfo)
    -> IO (Image, Allocation, AllocationInfo))
-> ContT
     (Image, Allocation, AllocationInfo)
     IO
     (Image, Allocation, AllocationInfo)
-> io (Image, Allocation, AllocationInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT
  (Image, Allocation, AllocationInfo)
  IO
  (Image, Allocation, AllocationInfo)
-> IO (Image, Allocation, AllocationInfo)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT
   (Image, Allocation, AllocationInfo)
   IO
   (Image, Allocation, AllocationInfo)
 -> io (Image, Allocation, AllocationInfo))
-> ContT
     (Image, Allocation, AllocationInfo)
     IO
     (Image, Allocation, AllocationInfo)
-> io (Image, Allocation, AllocationInfo)
forall a b. (a -> b) -> a -> b
$ do
  Ptr (ImageCreateInfo a)
pImageCreateInfo <- ((Ptr (ImageCreateInfo a)
  -> IO (Image, Allocation, AllocationInfo))
 -> IO (Image, Allocation, AllocationInfo))
-> ContT
     (Image, Allocation, AllocationInfo) IO (Ptr (ImageCreateInfo a))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr (ImageCreateInfo a)
   -> IO (Image, Allocation, AllocationInfo))
  -> IO (Image, Allocation, AllocationInfo))
 -> ContT
      (Image, Allocation, AllocationInfo) IO (Ptr (ImageCreateInfo a)))
-> ((Ptr (ImageCreateInfo a)
     -> IO (Image, Allocation, AllocationInfo))
    -> IO (Image, Allocation, AllocationInfo))
-> ContT
     (Image, Allocation, AllocationInfo) IO (Ptr (ImageCreateInfo a))
forall a b. (a -> b) -> a -> b