{-# language CPP #-}
module Vulkan.Core10.MemoryManagement ( getBufferMemoryRequirements
, bindBufferMemory
, getImageMemoryRequirements
, bindImageMemory
, MemoryRequirements(..)
, DeviceMemory(..)
) where
import Vulkan.Internal.Utils (traceAroundEvent)
import Control.Monad (unless)
import Control.Monad.IO.Class (liftIO)
import Foreign.Marshal.Alloc (allocaBytesAligned)
import GHC.Base (when)
import GHC.IO (throwIO)
import GHC.Ptr (nullFunPtr)
import Foreign.Ptr (plusPtr)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Cont (evalContT)
import Vulkan.CStruct (FromCStruct)
import Vulkan.CStruct (FromCStruct(..))
import Vulkan.CStruct (ToCStruct)
import Vulkan.CStruct (ToCStruct(..))
import Vulkan.Zero (Zero(..))
import Control.Monad.IO.Class (MonadIO)
import Data.Typeable (Typeable)
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 Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import Data.Word (Word32)
import Data.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import Vulkan.NamedType ((:::))
import Vulkan.Core10.Handles (Buffer)
import Vulkan.Core10.Handles (Buffer(..))
import Vulkan.Core10.Handles (Device)
import Vulkan.Core10.Handles (Device(..))
import Vulkan.Dynamic (DeviceCmds(pVkBindBufferMemory))
import Vulkan.Dynamic (DeviceCmds(pVkBindImageMemory))
import Vulkan.Dynamic (DeviceCmds(pVkGetBufferMemoryRequirements))
import Vulkan.Dynamic (DeviceCmds(pVkGetImageMemoryRequirements))
import Vulkan.Core10.Handles (DeviceMemory)
import Vulkan.Core10.Handles (DeviceMemory(..))
import Vulkan.Core10.FundamentalTypes (DeviceSize)
import Vulkan.Core10.Handles (Device_T)
import Vulkan.Core10.Handles (Image)
import Vulkan.Core10.Handles (Image(..))
import Vulkan.Core10.Enums.Result (Result)
import Vulkan.Core10.Enums.Result (Result(..))
import Vulkan.Exception (VulkanException(..))
import Vulkan.Core10.Enums.Result (Result(SUCCESS))
import Vulkan.Core10.Handles (DeviceMemory(..))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkGetBufferMemoryRequirements
:: FunPtr (Ptr Device_T -> Buffer -> Ptr MemoryRequirements -> IO ()) -> Ptr Device_T -> Buffer -> Ptr MemoryRequirements -> IO ()
getBufferMemoryRequirements :: forall io
. (MonadIO io)
=>
Device
->
Buffer
-> io (MemoryRequirements)
getBufferMemoryRequirements :: Device -> Buffer -> io MemoryRequirements
getBufferMemoryRequirements device :: Device
device buffer :: Buffer
buffer = IO MemoryRequirements -> io MemoryRequirements
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MemoryRequirements -> io MemoryRequirements)
-> (ContT MemoryRequirements IO MemoryRequirements
-> IO MemoryRequirements)
-> ContT MemoryRequirements IO MemoryRequirements
-> io MemoryRequirements
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT MemoryRequirements IO MemoryRequirements
-> IO MemoryRequirements
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT MemoryRequirements IO MemoryRequirements
-> io MemoryRequirements)
-> ContT MemoryRequirements IO MemoryRequirements
-> io MemoryRequirements
forall a b. (a -> b) -> a -> b
$ do
let vkGetBufferMemoryRequirementsPtr :: FunPtr
(Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
vkGetBufferMemoryRequirementsPtr = DeviceCmds
-> FunPtr
(Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
pVkGetBufferMemoryRequirements (Device -> DeviceCmds
deviceCmds (Device
device :: Device))
IO () -> ContT MemoryRequirements IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT MemoryRequirements IO ())
-> IO () -> ContT MemoryRequirements IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
(Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
vkGetBufferMemoryRequirementsPtr FunPtr
(Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
-> FunPtr
(Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
(Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for vkGetBufferMemoryRequirements is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
let vkGetBufferMemoryRequirements' :: Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ()
vkGetBufferMemoryRequirements' = FunPtr
(Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
-> Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ()
mkVkGetBufferMemoryRequirements FunPtr
(Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
vkGetBufferMemoryRequirementsPtr
"pMemoryRequirements" ::: Ptr MemoryRequirements
pPMemoryRequirements <- ((("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO MemoryRequirements)
-> IO MemoryRequirements)
-> ContT
MemoryRequirements
IO
("pMemoryRequirements" ::: Ptr MemoryRequirements)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct MemoryRequirements =>
(("pMemoryRequirements" ::: Ptr MemoryRequirements) -> IO b)
-> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @MemoryRequirements)
IO () -> ContT MemoryRequirements IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT MemoryRequirements IO ())
-> IO () -> ContT MemoryRequirements IO ()
forall a b. (a -> b) -> a -> b
$ String -> IO () -> IO ()
forall a. String -> IO a -> IO a
traceAroundEvent "vkGetBufferMemoryRequirements" (Ptr Device_T
-> Buffer
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ()
vkGetBufferMemoryRequirements' (Device -> Ptr Device_T
deviceHandle (Device
device)) (Buffer
buffer) ("pMemoryRequirements" ::: Ptr MemoryRequirements
pPMemoryRequirements))
MemoryRequirements
pMemoryRequirements <- IO MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements)
-> IO MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements
forall a b. (a -> b) -> a -> b
$ ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO MemoryRequirements
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @MemoryRequirements "pMemoryRequirements" ::: Ptr MemoryRequirements
pPMemoryRequirements
MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements)
-> MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements
forall a b. (a -> b) -> a -> b
$ (MemoryRequirements
pMemoryRequirements)
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkBindBufferMemory
:: FunPtr (Ptr Device_T -> Buffer -> DeviceMemory -> DeviceSize -> IO Result) -> Ptr Device_T -> Buffer -> DeviceMemory -> DeviceSize -> IO Result
bindBufferMemory :: forall io
. (MonadIO io)
=>
Device
->
Buffer
->
DeviceMemory
->
("memoryOffset" ::: DeviceSize)
-> io ()
bindBufferMemory :: Device
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> io ()
bindBufferMemory device :: Device
device buffer :: Buffer
buffer memory :: DeviceMemory
memory memoryOffset :: "memoryOffset" ::: DeviceSize
memoryOffset = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
let vkBindBufferMemoryPtr :: FunPtr
(Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
vkBindBufferMemoryPtr = DeviceCmds
-> FunPtr
(Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
pVkBindBufferMemory (Device -> DeviceCmds
deviceCmds (Device
device :: Device))
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
(Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
vkBindBufferMemoryPtr FunPtr
(Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
-> FunPtr
(Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
(Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for vkBindBufferMemory is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
let vkBindBufferMemory' :: Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result
vkBindBufferMemory' = FunPtr
(Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
-> Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result
mkVkBindBufferMemory FunPtr
(Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
vkBindBufferMemoryPtr
Result
r <- String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "vkBindBufferMemory" (Ptr Device_T
-> Buffer
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result
vkBindBufferMemory' (Device -> Ptr Device_T
deviceHandle (Device
device)) (Buffer
buffer) (DeviceMemory
memory) ("memoryOffset" ::: DeviceSize
memoryOffset))
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
"dynamic" mkVkGetImageMemoryRequirements
:: FunPtr (Ptr Device_T -> Image -> Ptr MemoryRequirements -> IO ()) -> Ptr Device_T -> Image -> Ptr MemoryRequirements -> IO ()
getImageMemoryRequirements :: forall io
. (MonadIO io)
=>
Device
->
Image
-> io (MemoryRequirements)
getImageMemoryRequirements :: Device -> Image -> io MemoryRequirements
getImageMemoryRequirements device :: Device
device image :: Image
image = IO MemoryRequirements -> io MemoryRequirements
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MemoryRequirements -> io MemoryRequirements)
-> (ContT MemoryRequirements IO MemoryRequirements
-> IO MemoryRequirements)
-> ContT MemoryRequirements IO MemoryRequirements
-> io MemoryRequirements
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT MemoryRequirements IO MemoryRequirements
-> IO MemoryRequirements
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT MemoryRequirements IO MemoryRequirements
-> io MemoryRequirements)
-> ContT MemoryRequirements IO MemoryRequirements
-> io MemoryRequirements
forall a b. (a -> b) -> a -> b
$ do
let vkGetImageMemoryRequirementsPtr :: FunPtr
(Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
vkGetImageMemoryRequirementsPtr = DeviceCmds
-> FunPtr
(Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
pVkGetImageMemoryRequirements (Device -> DeviceCmds
deviceCmds (Device
device :: Device))
IO () -> ContT MemoryRequirements IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT MemoryRequirements IO ())
-> IO () -> ContT MemoryRequirements IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
(Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
vkGetImageMemoryRequirementsPtr FunPtr
(Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
-> FunPtr
(Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
(Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for vkGetImageMemoryRequirements is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
let vkGetImageMemoryRequirements' :: Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ()
vkGetImageMemoryRequirements' = FunPtr
(Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
-> Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ()
mkVkGetImageMemoryRequirements FunPtr
(Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ())
vkGetImageMemoryRequirementsPtr
"pMemoryRequirements" ::: Ptr MemoryRequirements
pPMemoryRequirements <- ((("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO MemoryRequirements)
-> IO MemoryRequirements)
-> ContT
MemoryRequirements
IO
("pMemoryRequirements" ::: Ptr MemoryRequirements)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (forall b.
ToCStruct MemoryRequirements =>
(("pMemoryRequirements" ::: Ptr MemoryRequirements) -> IO b)
-> IO b
forall a b. ToCStruct a => (Ptr a -> IO b) -> IO b
withZeroCStruct @MemoryRequirements)
IO () -> ContT MemoryRequirements IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT MemoryRequirements IO ())
-> IO () -> ContT MemoryRequirements IO ()
forall a b. (a -> b) -> a -> b
$ String -> IO () -> IO ()
forall a. String -> IO a -> IO a
traceAroundEvent "vkGetImageMemoryRequirements" (Ptr Device_T
-> Image
-> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO ()
vkGetImageMemoryRequirements' (Device -> Ptr Device_T
deviceHandle (Device
device)) (Image
image) ("pMemoryRequirements" ::: Ptr MemoryRequirements
pPMemoryRequirements))
MemoryRequirements
pMemoryRequirements <- IO MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements)
-> IO MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements
forall a b. (a -> b) -> a -> b
$ ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO MemoryRequirements
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @MemoryRequirements "pMemoryRequirements" ::: Ptr MemoryRequirements
pPMemoryRequirements
MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements)
-> MemoryRequirements
-> ContT MemoryRequirements IO MemoryRequirements
forall a b. (a -> b) -> a -> b
$ (MemoryRequirements
pMemoryRequirements)
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkBindImageMemory
:: FunPtr (Ptr Device_T -> Image -> DeviceMemory -> DeviceSize -> IO Result) -> Ptr Device_T -> Image -> DeviceMemory -> DeviceSize -> IO Result
bindImageMemory :: forall io
. (MonadIO io)
=>
Device
->
Image
->
DeviceMemory
->
("memoryOffset" ::: DeviceSize)
-> io ()
bindImageMemory :: Device
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> io ()
bindImageMemory device :: Device
device image :: Image
image memory :: DeviceMemory
memory memoryOffset :: "memoryOffset" ::: DeviceSize
memoryOffset = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
let vkBindImageMemoryPtr :: FunPtr
(Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
vkBindImageMemoryPtr = DeviceCmds
-> FunPtr
(Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
pVkBindImageMemory (Device -> DeviceCmds
deviceCmds (Device
device :: Device))
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
(Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
vkBindImageMemoryPtr FunPtr
(Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
-> FunPtr
(Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
(Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for vkBindImageMemory is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
let vkBindImageMemory' :: Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result
vkBindImageMemory' = FunPtr
(Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
-> Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result
mkVkBindImageMemory FunPtr
(Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result)
vkBindImageMemoryPtr
Result
r <- String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "vkBindImageMemory" (Ptr Device_T
-> Image
-> DeviceMemory
-> ("memoryOffset" ::: DeviceSize)
-> IO Result
vkBindImageMemory' (Device -> Ptr Device_T
deviceHandle (Device
device)) (Image
image) (DeviceMemory
memory) ("memoryOffset" ::: DeviceSize
memoryOffset))
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))
data MemoryRequirements = MemoryRequirements
{
MemoryRequirements -> "memoryOffset" ::: DeviceSize
size :: DeviceSize
,
MemoryRequirements -> "memoryOffset" ::: DeviceSize
alignment :: DeviceSize
,
MemoryRequirements -> Word32
memoryTypeBits :: Word32
}
deriving (Typeable, MemoryRequirements -> MemoryRequirements -> Bool
(MemoryRequirements -> MemoryRequirements -> Bool)
-> (MemoryRequirements -> MemoryRequirements -> Bool)
-> Eq MemoryRequirements
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MemoryRequirements -> MemoryRequirements -> Bool
$c/= :: MemoryRequirements -> MemoryRequirements -> Bool
== :: MemoryRequirements -> MemoryRequirements -> Bool
$c== :: MemoryRequirements -> MemoryRequirements -> Bool
Eq)
#if defined(GENERIC_INSTANCES)
deriving instance Generic (MemoryRequirements)
#endif
deriving instance Show MemoryRequirements
instance ToCStruct MemoryRequirements where
withCStruct :: MemoryRequirements
-> (("pMemoryRequirements" ::: Ptr MemoryRequirements) -> IO b)
-> IO b
withCStruct x :: MemoryRequirements
x f :: ("pMemoryRequirements" ::: Ptr MemoryRequirements) -> IO b
f = Int
-> Int
-> (("pMemoryRequirements" ::: Ptr MemoryRequirements) -> IO b)
-> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned 24 8 ((("pMemoryRequirements" ::: Ptr MemoryRequirements) -> IO b)
-> IO b)
-> (("pMemoryRequirements" ::: Ptr MemoryRequirements) -> IO b)
-> IO b
forall a b. (a -> b) -> a -> b
$ \p :: "pMemoryRequirements" ::: Ptr MemoryRequirements
p -> ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> MemoryRequirements -> IO b -> IO b
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct "pMemoryRequirements" ::: Ptr MemoryRequirements
p MemoryRequirements
x (("pMemoryRequirements" ::: Ptr MemoryRequirements) -> IO b
f "pMemoryRequirements" ::: Ptr MemoryRequirements
p)
pokeCStruct :: ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> MemoryRequirements -> IO b -> IO b
pokeCStruct p :: "pMemoryRequirements" ::: Ptr MemoryRequirements
p MemoryRequirements{..} f :: IO b
f = do
Ptr ("memoryOffset" ::: DeviceSize)
-> ("memoryOffset" ::: DeviceSize) -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryRequirements" ::: Ptr MemoryRequirements
p ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> Int -> Ptr ("memoryOffset" ::: DeviceSize)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr DeviceSize)) ("memoryOffset" ::: DeviceSize
size)
Ptr ("memoryOffset" ::: DeviceSize)
-> ("memoryOffset" ::: DeviceSize) -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryRequirements" ::: Ptr MemoryRequirements
p ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> Int -> Ptr ("memoryOffset" ::: DeviceSize)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr DeviceSize)) ("memoryOffset" ::: DeviceSize
alignment)
Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryRequirements" ::: Ptr MemoryRequirements
p ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr Word32)) (Word32
memoryTypeBits)
IO b
f
cStructSize :: Int
cStructSize = 24
cStructAlignment :: Int
cStructAlignment = 8
pokeZeroCStruct :: ("pMemoryRequirements" ::: Ptr MemoryRequirements) -> IO b -> IO b
pokeZeroCStruct p :: "pMemoryRequirements" ::: Ptr MemoryRequirements
p f :: IO b
f = do
Ptr ("memoryOffset" ::: DeviceSize)
-> ("memoryOffset" ::: DeviceSize) -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryRequirements" ::: Ptr MemoryRequirements
p ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> Int -> Ptr ("memoryOffset" ::: DeviceSize)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr DeviceSize)) ("memoryOffset" ::: DeviceSize
forall a. Zero a => a
zero)
Ptr ("memoryOffset" ::: DeviceSize)
-> ("memoryOffset" ::: DeviceSize) -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryRequirements" ::: Ptr MemoryRequirements
p ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> Int -> Ptr ("memoryOffset" ::: DeviceSize)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr DeviceSize)) ("memoryOffset" ::: DeviceSize
forall a. Zero a => a
zero)
Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (("pMemoryRequirements" ::: Ptr MemoryRequirements
p ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr Word32)) (Word32
forall a. Zero a => a
zero)
IO b
f
instance FromCStruct MemoryRequirements where
peekCStruct :: ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO MemoryRequirements
peekCStruct p :: "pMemoryRequirements" ::: Ptr MemoryRequirements
p = do
"memoryOffset" ::: DeviceSize
size <- Ptr ("memoryOffset" ::: DeviceSize)
-> IO ("memoryOffset" ::: DeviceSize)
forall a. Storable a => Ptr a -> IO a
peek @DeviceSize (("pMemoryRequirements" ::: Ptr MemoryRequirements
p ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> Int -> Ptr ("memoryOffset" ::: DeviceSize)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr DeviceSize))
"memoryOffset" ::: DeviceSize
alignment <- Ptr ("memoryOffset" ::: DeviceSize)
-> IO ("memoryOffset" ::: DeviceSize)
forall a. Storable a => Ptr a -> IO a
peek @DeviceSize (("pMemoryRequirements" ::: Ptr MemoryRequirements
p ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> Int -> Ptr ("memoryOffset" ::: DeviceSize)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr DeviceSize))
Word32
memoryTypeBits <- Ptr Word32 -> IO Word32
forall a. Storable a => Ptr a -> IO a
peek @Word32 (("pMemoryRequirements" ::: Ptr MemoryRequirements
p ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr Word32))
MemoryRequirements -> IO MemoryRequirements
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MemoryRequirements -> IO MemoryRequirements)
-> MemoryRequirements -> IO MemoryRequirements
forall a b. (a -> b) -> a -> b
$ ("memoryOffset" ::: DeviceSize)
-> ("memoryOffset" ::: DeviceSize) -> Word32 -> MemoryRequirements
MemoryRequirements
"memoryOffset" ::: DeviceSize
size "memoryOffset" ::: DeviceSize
alignment Word32
memoryTypeBits
instance Storable MemoryRequirements where
sizeOf :: MemoryRequirements -> Int
sizeOf ~MemoryRequirements
_ = 24
alignment :: MemoryRequirements -> Int
alignment ~MemoryRequirements
_ = 8
peek :: ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO MemoryRequirements
peek = ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> IO MemoryRequirements
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
poke :: ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> MemoryRequirements -> IO ()
poke ptr :: "pMemoryRequirements" ::: Ptr MemoryRequirements
ptr poked :: MemoryRequirements
poked = ("pMemoryRequirements" ::: Ptr MemoryRequirements)
-> MemoryRequirements -> IO () -> IO ()
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct "pMemoryRequirements" ::: Ptr MemoryRequirements
ptr MemoryRequirements
poked (() -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
instance Zero MemoryRequirements where
zero :: MemoryRequirements
zero = ("memoryOffset" ::: DeviceSize)
-> ("memoryOffset" ::: DeviceSize) -> Word32 -> MemoryRequirements
MemoryRequirements
"memoryOffset" ::: DeviceSize
forall a. Zero a => a
zero
"memoryOffset" ::: DeviceSize
forall a. Zero a => a
zero
Word32
forall a. Zero a => a
zero