{-# language CPP #-}
-- No documentation found for Chapter "ExtensionDiscovery"
module Vulkan.Core10.ExtensionDiscovery  ( enumerateInstanceExtensionProperties
                                         , enumerateDeviceExtensionProperties
                                         , ExtensionProperties(..)
                                         ) where

import Vulkan.CStruct.Utils (FixedArray)
import Vulkan.Internal.Utils (traceAroundEvent)
import Control.Exception.Base (bracket)
import Control.Monad (unless)
import Control.Monad.IO.Class (liftIO)
import Foreign.Marshal.Alloc (allocaBytes)
import Foreign.Marshal.Alloc (callocBytes)
import Foreign.Marshal.Alloc (free)
import GHC.Base (when)
import GHC.IO (throwIO)
import Foreign.Ptr (castFunPtr)
import GHC.Ptr (nullFunPtr)
import Foreign.Ptr (nullPtr)
import Foreign.Ptr (plusPtr)
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 Foreign.C.Types (CChar(..))
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.C.Types (CChar)
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 GHC.Ptr (Ptr(Ptr))
import Data.Word (Word32)
import Data.ByteString (ByteString)
import Data.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import Data.Vector (Vector)
import Vulkan.CStruct.Utils (advancePtrBytes)
import Vulkan.Dynamic (getInstanceProcAddr')
import Vulkan.CStruct.Utils (lowerArrayPtr)
import Vulkan.CStruct.Utils (pokeFixedLengthNullTerminatedByteString)
import Vulkan.NamedType ((:::))
import Vulkan.Dynamic (InstanceCmds(pVkEnumerateDeviceExtensionProperties))
import Vulkan.Core10.APIConstants (MAX_EXTENSION_NAME_SIZE)
import Vulkan.Core10.Handles (PhysicalDevice)
import Vulkan.Core10.Handles (PhysicalDevice(..))
import Vulkan.Core10.Handles (PhysicalDevice(PhysicalDevice))
import Vulkan.Core10.Handles (PhysicalDevice_T)
import Vulkan.Core10.Enums.Result (Result)
import Vulkan.Core10.Enums.Result (Result(..))
import Vulkan.Exception (VulkanException(..))
import Vulkan.Core10.Enums.Result (Result(SUCCESS))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkVkEnumerateInstanceExtensionProperties
  :: FunPtr (Ptr CChar -> Ptr Word32 -> Ptr ExtensionProperties -> IO Result) -> Ptr CChar -> Ptr Word32 -> Ptr ExtensionProperties -> IO Result

-- | vkEnumerateInstanceExtensionProperties - Returns up to requested number
-- of global extension properties
--
-- = Description
--
-- When @pLayerName@ parameter is @NULL@, only extensions provided by the
-- Vulkan implementation or by implicitly enabled layers are returned. When
-- @pLayerName@ is the name of a layer, the instance extensions provided by
-- that layer are returned.
--
-- If @pProperties@ is @NULL@, then the number of extensions properties
-- available is returned in @pPropertyCount@. Otherwise, @pPropertyCount@
-- /must/ point to a variable set by the user to the number of elements in
-- the @pProperties@ array, and on return the variable is overwritten with
-- the number of structures actually written to @pProperties@. If
-- @pPropertyCount@ is less than the number of extension properties
-- available, at most @pPropertyCount@ structures will be written, and
-- 'Vulkan.Core10.Enums.Result.INCOMPLETE' will be returned instead of
-- 'Vulkan.Core10.Enums.Result.SUCCESS', to indicate that not all the
-- available properties were returned.
--
-- Because the list of available layers may change externally between calls
-- to 'enumerateInstanceExtensionProperties', two calls may retrieve
-- different results if a @pLayerName@ is available in one call but not in
-- another. The extensions supported by a layer may also change between two
-- calls, e.g. if the layer implementation is replaced by a different
-- version between those calls.
--
-- Implementations /must/ not advertise any pair of extensions that cannot
-- be enabled together due to behavioral differences, or any extension that
-- cannot be enabled against the advertised version.
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-vkEnumerateInstanceExtensionProperties-pLayerName-parameter#
--     If @pLayerName@ is not @NULL@, @pLayerName@ /must/ be a
--     null-terminated UTF-8 string
--
-- -   #VUID-vkEnumerateInstanceExtensionProperties-pPropertyCount-parameter#
--     @pPropertyCount@ /must/ be a valid pointer to a @uint32_t@ value
--
-- -   #VUID-vkEnumerateInstanceExtensionProperties-pProperties-parameter#
--     If the value referenced by @pPropertyCount@ is not @0@, and
--     @pProperties@ is not @NULL@, @pProperties@ /must/ be a valid pointer
--     to an array of @pPropertyCount@ 'ExtensionProperties' structures
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-successcodes Success>]
--
--     -   'Vulkan.Core10.Enums.Result.SUCCESS'
--
--     -   'Vulkan.Core10.Enums.Result.INCOMPLETE'
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-errorcodes Failure>]
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_OUT_OF_HOST_MEMORY'
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_OUT_OF_DEVICE_MEMORY'
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_LAYER_NOT_PRESENT'
--
-- = See Also
--
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_VERSION_1_0 VK_VERSION_1_0>,
-- 'ExtensionProperties'
enumerateInstanceExtensionProperties :: forall io
                                      . (MonadIO io)
                                     => -- | @pLayerName@ is either @NULL@ or a pointer to a null-terminated UTF-8
                                        -- string naming the layer to retrieve extensions from.
                                        ("layerName" ::: Maybe ByteString)
                                     -> io (Result, ("properties" ::: Vector ExtensionProperties))
enumerateInstanceExtensionProperties :: forall (io :: * -> *).
MonadIO io =>
("layerName" ::: Maybe ByteString)
-> io (Result, "properties" ::: Vector ExtensionProperties)
enumerateInstanceExtensionProperties "layerName" ::: Maybe ByteString
layerName = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT forall a b. (a -> b) -> a -> b
$ do
  FunPtr
  (("pLayerName" ::: Ptr CChar)
   -> ("pPropertyCount" ::: Ptr Word32)
   -> ("pProperties" ::: Ptr ExtensionProperties)
   -> IO Result)
vkEnumerateInstanceExtensionPropertiesPtr <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a b. FunPtr a -> FunPtr b
castFunPtr @_ @(("pLayerName" ::: Ptr CChar) -> ("pPropertyCount" ::: Ptr Word32) -> ("pProperties" ::: Ptr ExtensionProperties) -> IO Result) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Instance_T
-> ("pLayerName" ::: Ptr CChar) -> IO PFN_vkVoidFunction
getInstanceProcAddr' forall a. Ptr a
nullPtr (forall a. Addr# -> Ptr a
Ptr Addr#
"vkEnumerateInstanceExtensionProperties"#)
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (("pLayerName" ::: Ptr CChar)
   -> ("pPropertyCount" ::: Ptr Word32)
   -> ("pProperties" ::: Ptr ExtensionProperties)
   -> IO Result)
vkEnumerateInstanceExtensionPropertiesPtr forall a. Eq a => a -> a -> Bool
/= forall a. FunPtr a
nullFunPtr) forall a b. (a -> b) -> a -> b
$
    forall e a. Exception e => e -> IO a
throwIO forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError forall a. Maybe a
Nothing IOErrorType
InvalidArgument String
"" String
"The function pointer for vkEnumerateInstanceExtensionProperties is null" forall a. Maybe a
Nothing forall a. Maybe a
Nothing
  let vkEnumerateInstanceExtensionProperties' :: ("pLayerName" ::: Ptr CChar)
-> ("pPropertyCount" ::: Ptr Word32)
-> ("pProperties" ::: Ptr ExtensionProperties)
-> IO Result
vkEnumerateInstanceExtensionProperties' = FunPtr
  (("pLayerName" ::: Ptr CChar)
   -> ("pPropertyCount" ::: Ptr Word32)
   -> ("pProperties" ::: Ptr ExtensionProperties)
   -> IO Result)
-> ("pLayerName" ::: Ptr CChar)
-> ("pPropertyCount" ::: Ptr Word32)
-> ("pProperties" ::: Ptr ExtensionProperties)
-> IO Result
mkVkEnumerateInstanceExtensionProperties FunPtr
  (("pLayerName" ::: Ptr CChar)
   -> ("pPropertyCount" ::: Ptr Word32)
   -> ("pProperties" ::: Ptr ExtensionProperties)
   -> IO Result)
vkEnumerateInstanceExtensionPropertiesPtr
  "pLayerName" ::: Ptr CChar
pLayerName <- case ("layerName" ::: Maybe ByteString
layerName) of
    "layerName" ::: Maybe ByteString
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Ptr a
nullPtr
    Just ByteString
j -> forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a.
ByteString -> (("pLayerName" ::: Ptr CChar) -> IO a) -> IO a
useAsCString (ByteString
j)
  "pPropertyCount" ::: Ptr Word32
pPPropertyCount <- forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (forall a. Int -> IO (Ptr a)
callocBytes @Word32 Int
4) forall a. Ptr a -> IO ()
free
  Result
r <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. String -> IO a -> IO a
traceAroundEvent String
"vkEnumerateInstanceExtensionProperties" (("pLayerName" ::: Ptr CChar)
-> ("pPropertyCount" ::: Ptr Word32)
-> ("pProperties" ::: Ptr ExtensionProperties)
-> IO Result
vkEnumerateInstanceExtensionProperties'
                                                                           "pLayerName" ::: Ptr CChar
pLayerName
                                                                           ("pPropertyCount" ::: Ptr Word32
pPPropertyCount)
                                                                           (forall a. Ptr a
nullPtr))
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  Word32
pPropertyCount <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> IO a
peek @Word32 "pPropertyCount" ::: Ptr Word32
pPPropertyCount
  "pProperties" ::: Ptr ExtensionProperties
pPProperties <- forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (forall a. Int -> IO (Ptr a)
callocBytes @ExtensionProperties ((forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
pPropertyCount)) forall a. Num a => a -> a -> a
* Int
260)) forall a. Ptr a -> IO ()
free
  [()]
_ <- forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (\Int
i -> forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b. ToCStruct a => Ptr a -> IO b -> IO b
pokeZeroCStruct ("pProperties" ::: Ptr ExtensionProperties
pPProperties forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
i forall a. Num a => a -> a -> a
* Int
260) :: Ptr ExtensionProperties) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. (a -> b) -> a -> b
$ ())) [Int
0..(forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
pPropertyCount)) forall a. Num a => a -> a -> a
- Int
1]
  Result
r' <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. String -> IO a -> IO a
traceAroundEvent String
"vkEnumerateInstanceExtensionProperties" (("pLayerName" ::: Ptr CChar)
-> ("pPropertyCount" ::: Ptr Word32)
-> ("pProperties" ::: Ptr ExtensionProperties)
-> IO Result
vkEnumerateInstanceExtensionProperties'
                                                                            "pLayerName" ::: Ptr CChar
pLayerName
                                                                            ("pPropertyCount" ::: Ptr Word32
pPPropertyCount)
                                                                            (("pProperties" ::: Ptr ExtensionProperties
pPProperties)))
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r' forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r'))
  Word32
pPropertyCount' <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> IO a
peek @Word32 "pPropertyCount" ::: Ptr Word32
pPPropertyCount
  "properties" ::: Vector ExtensionProperties
pProperties' <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
pPropertyCount')) (\Int
i -> forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @ExtensionProperties ((("pProperties" ::: Ptr ExtensionProperties
pPProperties) forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
260 forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr ExtensionProperties)))
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ ((Result
r'), "properties" ::: Vector ExtensionProperties
pProperties')


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkVkEnumerateDeviceExtensionProperties
  :: FunPtr (Ptr PhysicalDevice_T -> Ptr CChar -> Ptr Word32 -> Ptr ExtensionProperties -> IO Result) -> Ptr PhysicalDevice_T -> Ptr CChar -> Ptr Word32 -> Ptr ExtensionProperties -> IO Result

-- | vkEnumerateDeviceExtensionProperties - Returns properties of available
-- physical device extensions
--
-- = Description
--
-- When @pLayerName@ parameter is @NULL@, only extensions provided by the
-- Vulkan implementation or by implicitly enabled layers are returned. When
-- @pLayerName@ is the name of a layer, the device extensions provided by
-- that layer are returned.
--
-- Implementations /must/ not advertise any pair of extensions that cannot
-- be enabled together due to behavioral differences, or any extension that
-- cannot be enabled against the advertised version.
--
-- Implementations claiming support for the
-- <https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#roadmap-2022 Roadmap 2022>
-- profile /must/ advertise the @VK_KHR_global_priority@ extension in
-- @pProperties@.
--
-- Note
--
-- Due to platform details on Android, 'enumerateDeviceExtensionProperties'
-- may be called with @physicalDevice@ equal to @NULL@ during layer
-- discovery. This behaviour will only be observed by layer
-- implementations, and not the underlying Vulkan driver.
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-vkEnumerateDeviceExtensionProperties-physicalDevice-parameter#
--     @physicalDevice@ /must/ be a valid
--     'Vulkan.Core10.Handles.PhysicalDevice' handle
--
-- -   #VUID-vkEnumerateDeviceExtensionProperties-pLayerName-parameter# If
--     @pLayerName@ is not @NULL@, @pLayerName@ /must/ be a null-terminated
--     UTF-8 string
--
-- -   #VUID-vkEnumerateDeviceExtensionProperties-pPropertyCount-parameter#
--     @pPropertyCount@ /must/ be a valid pointer to a @uint32_t@ value
--
-- -   #VUID-vkEnumerateDeviceExtensionProperties-pProperties-parameter# If
--     the value referenced by @pPropertyCount@ is not @0@, and
--     @pProperties@ is not @NULL@, @pProperties@ /must/ be a valid pointer
--     to an array of @pPropertyCount@ 'ExtensionProperties' structures
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-successcodes Success>]
--
--     -   'Vulkan.Core10.Enums.Result.SUCCESS'
--
--     -   'Vulkan.Core10.Enums.Result.INCOMPLETE'
--
-- [<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#fundamentals-errorcodes Failure>]
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_OUT_OF_HOST_MEMORY'
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_OUT_OF_DEVICE_MEMORY'
--
--     -   'Vulkan.Core10.Enums.Result.ERROR_LAYER_NOT_PRESENT'
--
-- = See Also
--
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_VERSION_1_0 VK_VERSION_1_0>,
-- 'ExtensionProperties', 'Vulkan.Core10.Handles.PhysicalDevice'
enumerateDeviceExtensionProperties :: forall io
                                    . (MonadIO io)
                                   => -- | @physicalDevice@ is the physical device that will be queried.
                                      PhysicalDevice
                                   -> -- | @pLayerName@ is either @NULL@ or a pointer to a null-terminated UTF-8
                                      -- string naming the layer to retrieve extensions from.
                                      ("layerName" ::: Maybe ByteString)
                                   -> io (Result, ("properties" ::: Vector ExtensionProperties))
enumerateDeviceExtensionProperties :: forall (io :: * -> *).
MonadIO io =>
PhysicalDevice
-> ("layerName" ::: Maybe ByteString)
-> io (Result, "properties" ::: Vector ExtensionProperties)
enumerateDeviceExtensionProperties PhysicalDevice
physicalDevice
                                     "layerName" ::: Maybe ByteString
layerName = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT forall a b. (a -> b) -> a -> b
$ do
  let vkEnumerateDeviceExtensionPropertiesPtr :: FunPtr
  (Ptr PhysicalDevice_T
   -> ("pLayerName" ::: Ptr CChar)
   -> ("pPropertyCount" ::: Ptr Word32)
   -> ("pProperties" ::: Ptr ExtensionProperties)
   -> IO Result)
vkEnumerateDeviceExtensionPropertiesPtr = InstanceCmds
-> FunPtr
     (Ptr PhysicalDevice_T
      -> ("pLayerName" ::: Ptr CChar)
      -> ("pPropertyCount" ::: Ptr Word32)
      -> ("pProperties" ::: Ptr ExtensionProperties)
      -> IO Result)
pVkEnumerateDeviceExtensionProperties (case PhysicalDevice
physicalDevice of PhysicalDevice{InstanceCmds
$sel:instanceCmds:PhysicalDevice :: PhysicalDevice -> InstanceCmds
instanceCmds :: InstanceCmds
instanceCmds} -> InstanceCmds
instanceCmds)
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr PhysicalDevice_T
   -> ("pLayerName" ::: Ptr CChar)
   -> ("pPropertyCount" ::: Ptr Word32)
   -> ("pProperties" ::: Ptr ExtensionProperties)
   -> IO Result)
vkEnumerateDeviceExtensionPropertiesPtr forall a. Eq a => a -> a -> Bool
/= forall a. FunPtr a
nullFunPtr) forall a b. (a -> b) -> a -> b
$
    forall e a. Exception e => e -> IO a
throwIO forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError forall a. Maybe a
Nothing IOErrorType
InvalidArgument String
"" String
"The function pointer for vkEnumerateDeviceExtensionProperties is null" forall a. Maybe a
Nothing forall a. Maybe a
Nothing
  let vkEnumerateDeviceExtensionProperties' :: Ptr PhysicalDevice_T
-> ("pLayerName" ::: Ptr CChar)
-> ("pPropertyCount" ::: Ptr Word32)
-> ("pProperties" ::: Ptr ExtensionProperties)
-> IO Result
vkEnumerateDeviceExtensionProperties' = FunPtr
  (Ptr PhysicalDevice_T
   -> ("pLayerName" ::: Ptr CChar)
   -> ("pPropertyCount" ::: Ptr Word32)
   -> ("pProperties" ::: Ptr ExtensionProperties)
   -> IO Result)
-> Ptr PhysicalDevice_T
-> ("pLayerName" ::: Ptr CChar)
-> ("pPropertyCount" ::: Ptr Word32)
-> ("pProperties" ::: Ptr ExtensionProperties)
-> IO Result
mkVkEnumerateDeviceExtensionProperties FunPtr
  (Ptr PhysicalDevice_T
   -> ("pLayerName" ::: Ptr CChar)
   -> ("pPropertyCount" ::: Ptr Word32)
   -> ("pProperties" ::: Ptr ExtensionProperties)
   -> IO Result)
vkEnumerateDeviceExtensionPropertiesPtr
  let physicalDevice' :: Ptr PhysicalDevice_T
physicalDevice' = PhysicalDevice -> Ptr PhysicalDevice_T
physicalDeviceHandle (PhysicalDevice
physicalDevice)
  "pLayerName" ::: Ptr CChar
pLayerName <- case ("layerName" ::: Maybe ByteString
layerName) of
    "layerName" ::: Maybe ByteString
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Ptr a
nullPtr
    Just ByteString
j -> forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a.
ByteString -> (("pLayerName" ::: Ptr CChar) -> IO a) -> IO a
useAsCString (ByteString
j)
  "pPropertyCount" ::: Ptr Word32
pPPropertyCount <- forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (forall a. Int -> IO (Ptr a)
callocBytes @Word32 Int
4) forall a. Ptr a -> IO ()
free
  Result
r <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. String -> IO a -> IO a
traceAroundEvent String
"vkEnumerateDeviceExtensionProperties" (Ptr PhysicalDevice_T
-> ("pLayerName" ::: Ptr CChar)
-> ("pPropertyCount" ::: Ptr Word32)
-> ("pProperties" ::: Ptr ExtensionProperties)
-> IO Result
vkEnumerateDeviceExtensionProperties'
                                                                         Ptr PhysicalDevice_T
physicalDevice'
                                                                         "pLayerName" ::: Ptr CChar
pLayerName
                                                                         ("pPropertyCount" ::: Ptr Word32
pPPropertyCount)
                                                                         (forall a. Ptr a
nullPtr))
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r))
  Word32
pPropertyCount <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> IO a
peek @Word32 "pPropertyCount" ::: Ptr Word32
pPPropertyCount
  "pProperties" ::: Ptr ExtensionProperties
pPProperties <- forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (forall a. Int -> IO (Ptr a)
callocBytes @ExtensionProperties ((forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
pPropertyCount)) forall a. Num a => a -> a -> a
* Int
260)) forall a. Ptr a -> IO ()
free
  [()]
_ <- forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (\Int
i -> forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT forall a b. (a -> b) -> a -> b
$ forall a b. ToCStruct a => Ptr a -> IO b -> IO b
pokeZeroCStruct ("pProperties" ::: Ptr ExtensionProperties
pPProperties forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
i forall a. Num a => a -> a -> a
* Int
260) :: Ptr ExtensionProperties) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. (a -> b) -> a -> b
$ ())) [Int
0..(forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
pPropertyCount)) forall a. Num a => a -> a -> a
- Int
1]
  Result
r' <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. String -> IO a -> IO a
traceAroundEvent String
"vkEnumerateDeviceExtensionProperties" (Ptr PhysicalDevice_T
-> ("pLayerName" ::: Ptr CChar)
-> ("pPropertyCount" ::: Ptr Word32)
-> ("pProperties" ::: Ptr ExtensionProperties)
-> IO Result
vkEnumerateDeviceExtensionProperties'
                                                                          Ptr PhysicalDevice_T
physicalDevice'
                                                                          "pLayerName" ::: Ptr CChar
pLayerName
                                                                          ("pPropertyCount" ::: Ptr Word32
pPPropertyCount)
                                                                          (("pProperties" ::: Ptr ExtensionProperties
pPProperties)))
  forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r' forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (forall e a. Exception e => e -> IO a
throwIO (Result -> VulkanException
VulkanException Result
r'))
  Word32
pPropertyCount' <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> IO a
peek @Word32 "pPropertyCount" ::: Ptr Word32
pPPropertyCount
  "properties" ::: Vector ExtensionProperties
pProperties' <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
generateM (forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
pPropertyCount')) (\Int
i -> forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @ExtensionProperties ((("pProperties" ::: Ptr ExtensionProperties
pPProperties) forall a. Ptr a -> Int -> Ptr a
`advancePtrBytes` (Int
260 forall a. Num a => a -> a -> a
* (Int
i)) :: Ptr ExtensionProperties)))
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ ((Result
r'), "properties" ::: Vector ExtensionProperties
pProperties')


-- | VkExtensionProperties - Structure specifying an extension properties
--
-- = See Also
--
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_VERSION_1_0 VK_VERSION_1_0>,
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkVideoCapabilitiesKHR VkVideoCapabilitiesKHR>,
-- <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VkVideoSessionCreateInfoKHR VkVideoSessionCreateInfoKHR>,
-- 'enumerateDeviceExtensionProperties',
-- 'enumerateInstanceExtensionProperties'
data ExtensionProperties = ExtensionProperties
  { -- | @extensionName@ is an array of
    -- 'Vulkan.Core10.APIConstants.MAX_EXTENSION_NAME_SIZE' @char@ containing a
    -- null-terminated UTF-8 string which is the name of the extension.
    ExtensionProperties -> ByteString
extensionName :: ByteString
  , -- | @specVersion@ is the version of this extension. It is an integer,
    -- incremented with backward compatible changes.
    ExtensionProperties -> Word32
specVersion :: Word32
  }
  deriving (Typeable)
#if defined(GENERIC_INSTANCES)
deriving instance Generic (ExtensionProperties)
#endif
deriving instance Show ExtensionProperties

instance ToCStruct ExtensionProperties where
  withCStruct :: forall b.
ExtensionProperties
-> (("pProperties" ::: Ptr ExtensionProperties) -> IO b) -> IO b
withCStruct ExtensionProperties
x ("pProperties" ::: Ptr ExtensionProperties) -> IO b
f = forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes Int
260 forall a b. (a -> b) -> a -> b
$ \"pProperties" ::: Ptr ExtensionProperties
p -> forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct "pProperties" ::: Ptr ExtensionProperties
p ExtensionProperties
x (("pProperties" ::: Ptr ExtensionProperties) -> IO b
f "pProperties" ::: Ptr ExtensionProperties
p)
  pokeCStruct :: forall b.
("pProperties" ::: Ptr ExtensionProperties)
-> ExtensionProperties -> IO b -> IO b
pokeCStruct "pProperties" ::: Ptr ExtensionProperties
p ExtensionProperties{Word32
ByteString
specVersion :: Word32
extensionName :: ByteString
$sel:specVersion:ExtensionProperties :: ExtensionProperties -> Word32
$sel:extensionName:ExtensionProperties :: ExtensionProperties -> ByteString
..} IO b
f = do
    forall (n :: Nat).
KnownNat n =>
Ptr (FixedArray n CChar) -> ByteString -> IO ()
pokeFixedLengthNullTerminatedByteString (("pProperties" ::: Ptr ExtensionProperties
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr (FixedArray MAX_EXTENSION_NAME_SIZE CChar))) (ByteString
extensionName)
    forall a. Storable a => Ptr a -> a -> IO ()
poke (("pProperties" ::: Ptr ExtensionProperties
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
256 :: Ptr Word32)) (Word32
specVersion)
    IO b
f
  cStructSize :: Int
cStructSize = Int
260
  cStructAlignment :: Int
cStructAlignment = Int
4
  pokeZeroCStruct :: forall b.
("pProperties" ::: Ptr ExtensionProperties) -> IO b -> IO b
pokeZeroCStruct "pProperties" ::: Ptr ExtensionProperties
p IO b
f = do
    forall (n :: Nat).
KnownNat n =>
Ptr (FixedArray n CChar) -> ByteString -> IO ()
pokeFixedLengthNullTerminatedByteString (("pProperties" ::: Ptr ExtensionProperties
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr (FixedArray MAX_EXTENSION_NAME_SIZE CChar))) (forall a. Monoid a => a
mempty)
    forall a. Storable a => Ptr a -> a -> IO ()
poke (("pProperties" ::: Ptr ExtensionProperties
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
256 :: Ptr Word32)) (forall a. Zero a => a
zero)
    IO b
f

instance FromCStruct ExtensionProperties where
  peekCStruct :: ("pProperties" ::: Ptr ExtensionProperties)
-> IO ExtensionProperties
peekCStruct "pProperties" ::: Ptr ExtensionProperties
p = do
    ByteString
extensionName <- ("pLayerName" ::: Ptr CChar) -> IO ByteString
packCString (forall a (n :: Nat). Ptr (FixedArray n a) -> Ptr a
lowerArrayPtr (("pProperties" ::: Ptr ExtensionProperties
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr (FixedArray MAX_EXTENSION_NAME_SIZE CChar))))
    Word32
specVersion <- forall a. Storable a => Ptr a -> IO a
peek @Word32 (("pProperties" ::: Ptr ExtensionProperties
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
256 :: Ptr Word32))
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ ByteString -> Word32 -> ExtensionProperties
ExtensionProperties
             ByteString
extensionName Word32
specVersion

instance Storable ExtensionProperties where
  sizeOf :: ExtensionProperties -> Int
sizeOf ~ExtensionProperties
_ = Int
260
  alignment :: ExtensionProperties -> Int
alignment ~ExtensionProperties
_ = Int
4
  peek :: ("pProperties" ::: Ptr ExtensionProperties)
-> IO ExtensionProperties
peek = forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
  poke :: ("pProperties" ::: Ptr ExtensionProperties)
-> ExtensionProperties -> IO ()
poke "pProperties" ::: Ptr ExtensionProperties
ptr ExtensionProperties
poked = forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct "pProperties" ::: Ptr ExtensionProperties
ptr ExtensionProperties
poked (forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

instance Zero ExtensionProperties where
  zero :: ExtensionProperties
zero = ByteString -> Word32 -> ExtensionProperties
ExtensionProperties
           forall a. Monoid a => a
mempty
           forall a. Zero a => a
zero