{-# language CPP #-}
module Vulkan.Extensions.VK_EXT_memory_budget ( PhysicalDeviceMemoryBudgetPropertiesEXT(..)
, EXT_MEMORY_BUDGET_SPEC_VERSION
, pattern EXT_MEMORY_BUDGET_SPEC_VERSION
, EXT_MEMORY_BUDGET_EXTENSION_NAME
, pattern EXT_MEMORY_BUDGET_EXTENSION_NAME
) where
import Vulkan.CStruct.Utils (FixedArray)
import Control.Monad (unless)
import Foreign.Marshal.Alloc (allocaBytes)
import GHC.IO (throwIO)
import Foreign.Ptr (nullPtr)
import Foreign.Ptr (plusPtr)
import Data.Vector (generateM)
import qualified Data.Vector (imapM_)
import qualified Data.Vector (length)
import Vulkan.CStruct (FromCStruct)
import Vulkan.CStruct (FromCStruct(..))
import Vulkan.CStruct (ToCStruct)
import Vulkan.CStruct (ToCStruct(..))
import Vulkan.Zero (Zero(..))
import Data.String (IsString)
import Data.Typeable (Typeable)
import Foreign.Storable (Storable)
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 (Ptr)
import Data.Kind (Type)
import Data.Vector (Vector)
import Vulkan.CStruct.Utils (advancePtrBytes)
import Vulkan.CStruct.Utils (lowerArrayPtr)
import Vulkan.Core10.FundamentalTypes (DeviceSize)
import Vulkan.Core10.APIConstants (MAX_MEMORY_HEAPS)
import Vulkan.Core10.Enums.StructureType (StructureType)
import Vulkan.Core10.APIConstants (pattern MAX_MEMORY_HEAPS)
import Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT))
data PhysicalDeviceMemoryBudgetPropertiesEXT = PhysicalDeviceMemoryBudgetPropertiesEXT
{
PhysicalDeviceMemoryBudgetPropertiesEXT -> Vector DeviceSize
heapBudget :: Vector DeviceSize
,
PhysicalDeviceMemoryBudgetPropertiesEXT -> Vector DeviceSize
heapUsage :: Vector DeviceSize
}
deriving (Typeable)
#if defined(GENERIC_INSTANCES)
deriving instance Generic (PhysicalDeviceMemoryBudgetPropertiesEXT)
#endif
deriving instance Show PhysicalDeviceMemoryBudgetPropertiesEXT
instance ToCStruct PhysicalDeviceMemoryBudgetPropertiesEXT where
withCStruct :: forall b.
PhysicalDeviceMemoryBudgetPropertiesEXT
-> (Ptr PhysicalDeviceMemoryBudgetPropertiesEXT -> IO b) -> IO b
withCStruct PhysicalDeviceMemoryBudgetPropertiesEXT
x Ptr PhysicalDeviceMemoryBudgetPropertiesEXT -> IO b
f = forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes Int
272 forall a b. (a -> b) -> a -> b
$ \Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p -> forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p PhysicalDeviceMemoryBudgetPropertiesEXT
x (Ptr PhysicalDeviceMemoryBudgetPropertiesEXT -> IO b
f Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p)
pokeCStruct :: forall b.
Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
-> PhysicalDeviceMemoryBudgetPropertiesEXT -> IO b -> IO b
pokeCStruct Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p PhysicalDeviceMemoryBudgetPropertiesEXT{Vector DeviceSize
heapUsage :: Vector DeviceSize
heapBudget :: Vector DeviceSize
$sel:heapUsage:PhysicalDeviceMemoryBudgetPropertiesEXT :: PhysicalDeviceMemoryBudgetPropertiesEXT -> Vector DeviceSize
$sel:heapBudget:PhysicalDeviceMemoryBudgetPropertiesEXT :: PhysicalDeviceMemoryBudgetPropertiesEXT -> Vector DeviceSize
..} IO b
f = do
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT)
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8 :: Ptr (Ptr ()))) (forall a. Ptr a
nullPtr)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ((forall a. Vector a -> Int
Data.Vector.length forall a b. (a -> b) -> a -> b
$ (Vector DeviceSize
heapBudget)) forall a. Ord a => a -> a -> Bool
<= forall a. Integral a => a
MAX_MEMORY_HEAPS) forall a b. (a -> b) -> a -> b
$
forall e a. Exception e => e -> IO a
throwIO forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError forall a. Maybe a
Nothing IOErrorType
InvalidArgument String
"" String
"heapBudget is too long, a maximum of MAX_MEMORY_HEAPS elements are allowed" forall a. Maybe a
Nothing forall a. Maybe a
Nothing
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\Int
i DeviceSize
e -> forall a. Storable a => Ptr a -> a -> IO ()
poke ((forall a (n :: Nat). Ptr (FixedArray n a) -> Ptr a
lowerArrayPtr ((Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16 :: Ptr (FixedArray MAX_MEMORY_HEAPS DeviceSize)))) forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
8 forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceSize) (DeviceSize
e)) (Vector DeviceSize
heapBudget)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ((forall a. Vector a -> Int
Data.Vector.length forall a b. (a -> b) -> a -> b
$ (Vector DeviceSize
heapUsage)) forall a. Ord a => a -> a -> Bool
<= forall a. Integral a => a
MAX_MEMORY_HEAPS) forall a b. (a -> b) -> a -> b
$
forall e a. Exception e => e -> IO a
throwIO forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError forall a. Maybe a
Nothing IOErrorType
InvalidArgument String
"" String
"heapUsage is too long, a maximum of MAX_MEMORY_HEAPS elements are allowed" forall a. Maybe a
Nothing forall a. Maybe a
Nothing
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> Vector a -> m ()
Data.Vector.imapM_ (\Int
i DeviceSize
e -> forall a. Storable a => Ptr a -> a -> IO ()
poke ((forall a (n :: Nat). Ptr (FixedArray n a) -> Ptr a
lowerArrayPtr ((Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
144 :: Ptr (FixedArray MAX_MEMORY_HEAPS DeviceSize)))) forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
8 forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceSize) (DeviceSize
e)) (Vector DeviceSize
heapUsage)
IO b
f
cStructSize :: Int
cStructSize = Int
272
cStructAlignment :: Int
cStructAlignment = Int
8
pokeZeroCStruct :: forall b.
Ptr PhysicalDeviceMemoryBudgetPropertiesEXT -> IO b -> IO b
pokeZeroCStruct Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p IO b
f = do
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr StructureType)) (StructureType
STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT)
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8 :: Ptr (Ptr ()))) (forall a. Ptr a
nullPtr)
IO b
f
instance FromCStruct PhysicalDeviceMemoryBudgetPropertiesEXT where
peekCStruct :: Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
-> IO PhysicalDeviceMemoryBudgetPropertiesEXT
peekCStruct Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p = do
Vector DeviceSize
heapBudget <- forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (forall a. Integral a => a
MAX_MEMORY_HEAPS) (\Int
i -> forall a. Storable a => Ptr a -> IO a
peek @DeviceSize (((forall a (n :: Nat). Ptr (FixedArray n a) -> Ptr a
lowerArrayPtr @DeviceSize ((Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16 :: Ptr (FixedArray MAX_MEMORY_HEAPS DeviceSize)))) forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
8 forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceSize)))
Vector DeviceSize
heapUsage <- forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (forall a. Integral a => a
MAX_MEMORY_HEAPS) (\Int
i -> forall a. Storable a => Ptr a -> IO a
peek @DeviceSize (((forall a (n :: Nat). Ptr (FixedArray n a) -> Ptr a
lowerArrayPtr @DeviceSize ((Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
144 :: Ptr (FixedArray MAX_MEMORY_HEAPS DeviceSize)))) forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
8 forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr DeviceSize)))
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Vector DeviceSize
-> Vector DeviceSize -> PhysicalDeviceMemoryBudgetPropertiesEXT
PhysicalDeviceMemoryBudgetPropertiesEXT
Vector DeviceSize
heapBudget Vector DeviceSize
heapUsage
instance Storable PhysicalDeviceMemoryBudgetPropertiesEXT where
sizeOf :: PhysicalDeviceMemoryBudgetPropertiesEXT -> Int
sizeOf ~PhysicalDeviceMemoryBudgetPropertiesEXT
_ = Int
272
alignment :: PhysicalDeviceMemoryBudgetPropertiesEXT -> Int
alignment ~PhysicalDeviceMemoryBudgetPropertiesEXT
_ = Int
8
peek :: Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
-> IO PhysicalDeviceMemoryBudgetPropertiesEXT
peek = forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
poke :: Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
-> PhysicalDeviceMemoryBudgetPropertiesEXT -> IO ()
poke Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
ptr PhysicalDeviceMemoryBudgetPropertiesEXT
poked = forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr PhysicalDeviceMemoryBudgetPropertiesEXT
ptr PhysicalDeviceMemoryBudgetPropertiesEXT
poked (forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
instance Zero PhysicalDeviceMemoryBudgetPropertiesEXT where
zero :: PhysicalDeviceMemoryBudgetPropertiesEXT
zero = Vector DeviceSize
-> Vector DeviceSize -> PhysicalDeviceMemoryBudgetPropertiesEXT
PhysicalDeviceMemoryBudgetPropertiesEXT
forall a. Monoid a => a
mempty
forall a. Monoid a => a
mempty
type EXT_MEMORY_BUDGET_SPEC_VERSION = 1
pattern EXT_MEMORY_BUDGET_SPEC_VERSION :: forall a . Integral a => a
pattern $bEXT_MEMORY_BUDGET_SPEC_VERSION :: forall a. Integral a => a
$mEXT_MEMORY_BUDGET_SPEC_VERSION :: forall {r} {a}.
Integral a =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
EXT_MEMORY_BUDGET_SPEC_VERSION = 1
type EXT_MEMORY_BUDGET_EXTENSION_NAME = "VK_EXT_memory_budget"
pattern EXT_MEMORY_BUDGET_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern $bEXT_MEMORY_BUDGET_EXTENSION_NAME :: forall a. (Eq a, IsString a) => a
$mEXT_MEMORY_BUDGET_EXTENSION_NAME :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
EXT_MEMORY_BUDGET_EXTENSION_NAME = "VK_EXT_memory_budget"