{-# language CPP #-}
module Graphics.Vulkan.Extensions.VK_EXT_calibrated_timestamps ( getPhysicalDeviceCalibrateableTimeDomainsEXT
, getCalibratedTimestampsEXT
, CalibratedTimestampInfoEXT(..)
, TimeDomainEXT( TIME_DOMAIN_DEVICE_EXT
, TIME_DOMAIN_CLOCK_MONOTONIC_EXT
, TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
, TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT
, ..
)
, EXT_CALIBRATED_TIMESTAMPS_SPEC_VERSION
, pattern EXT_CALIBRATED_TIMESTAMPS_SPEC_VERSION
, EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME
, pattern EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME
) where
import Control.Exception.Base (bracket)
import Control.Monad.IO.Class (liftIO)
import Foreign.Marshal.Alloc (allocaBytesAligned)
import Foreign.Marshal.Alloc (callocBytes)
import Foreign.Marshal.Alloc (free)
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 Text.ParserCombinators.ReadPrec ((+++))
import Text.ParserCombinators.ReadPrec (prec)
import Text.ParserCombinators.ReadPrec (step)
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 Control.Monad.IO.Class (MonadIO)
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 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.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import Data.Vector (Vector)
import Graphics.Vulkan.CStruct.Utils (advancePtrBytes)
import Graphics.Vulkan.NamedType ((:::))
import Graphics.Vulkan.Core10.Handles (Device)
import Graphics.Vulkan.Core10.Handles (Device(..))
import Graphics.Vulkan.Dynamic (DeviceCmds(pVkGetCalibratedTimestampsEXT))
import Graphics.Vulkan.Core10.Handles (Device_T)
import Graphics.Vulkan.CStruct (FromCStruct)
import Graphics.Vulkan.CStruct (FromCStruct(..))
import Graphics.Vulkan.Dynamic (InstanceCmds(pVkGetPhysicalDeviceCalibrateableTimeDomainsEXT))
import Graphics.Vulkan.Core10.Handles (PhysicalDevice)
import Graphics.Vulkan.Core10.Handles (PhysicalDevice(..))
import Graphics.Vulkan.Core10.Handles (PhysicalDevice_T)
import Graphics.Vulkan.Core10.Enums.Result (Result)
import Graphics.Vulkan.Core10.Enums.Result (Result(..))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType)
import Graphics.Vulkan.CStruct (ToCStruct)
import Graphics.Vulkan.CStruct (ToCStruct(..))
import Graphics.Vulkan.Exception (VulkanException(..))
import Graphics.Vulkan.Zero (Zero)
import Graphics.Vulkan.Zero (Zero(..))
import Graphics.Vulkan.Core10.Enums.StructureType (StructureType(STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT))
import Graphics.Vulkan.Core10.Enums.Result (Result(SUCCESS))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkGetPhysicalDeviceCalibrateableTimeDomainsEXT
:: FunPtr (Ptr PhysicalDevice_T -> Ptr Word32 -> Ptr TimeDomainEXT -> IO Result) -> Ptr PhysicalDevice_T -> Ptr Word32 -> Ptr TimeDomainEXT -> IO Result
getPhysicalDeviceCalibrateableTimeDomainsEXT :: forall io . MonadIO io => PhysicalDevice -> io (Result, ("timeDomains" ::: Vector TimeDomainEXT))
getPhysicalDeviceCalibrateableTimeDomainsEXT physicalDevice = liftIO . evalContT $ do
let vkGetPhysicalDeviceCalibrateableTimeDomainsEXT' = mkVkGetPhysicalDeviceCalibrateableTimeDomainsEXT (pVkGetPhysicalDeviceCalibrateableTimeDomainsEXT (instanceCmds (physicalDevice :: PhysicalDevice)))
let physicalDevice' = physicalDeviceHandle (physicalDevice)
pPTimeDomainCount <- ContT $ bracket (callocBytes @Word32 4) free
r <- lift $ vkGetPhysicalDeviceCalibrateableTimeDomainsEXT' physicalDevice' (pPTimeDomainCount) (nullPtr)
lift $ when (r < SUCCESS) (throwIO (VulkanException r))
pTimeDomainCount <- lift $ peek @Word32 pPTimeDomainCount
pPTimeDomains <- ContT $ bracket (callocBytes @TimeDomainEXT ((fromIntegral (pTimeDomainCount)) * 4)) free
r' <- lift $ vkGetPhysicalDeviceCalibrateableTimeDomainsEXT' physicalDevice' (pPTimeDomainCount) (pPTimeDomains)
lift $ when (r' < SUCCESS) (throwIO (VulkanException r'))
pTimeDomainCount' <- lift $ peek @Word32 pPTimeDomainCount
pTimeDomains' <- lift $ generateM (fromIntegral (pTimeDomainCount')) (\i -> peek @TimeDomainEXT ((pPTimeDomains `advancePtrBytes` (4 * (i)) :: Ptr TimeDomainEXT)))
pure $ ((r'), pTimeDomains')
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkVkGetCalibratedTimestampsEXT
:: FunPtr (Ptr Device_T -> Word32 -> Ptr CalibratedTimestampInfoEXT -> Ptr Word64 -> Ptr Word64 -> IO Result) -> Ptr Device_T -> Word32 -> Ptr CalibratedTimestampInfoEXT -> Ptr Word64 -> Ptr Word64 -> IO Result
getCalibratedTimestampsEXT :: forall io . MonadIO io => Device -> ("timestampInfos" ::: Vector CalibratedTimestampInfoEXT) -> io (("timestamps" ::: Vector Word64), ("maxDeviation" ::: Word64))
getCalibratedTimestampsEXT device timestampInfos = liftIO . evalContT $ do
let vkGetCalibratedTimestampsEXT' = mkVkGetCalibratedTimestampsEXT (pVkGetCalibratedTimestampsEXT (deviceCmds (device :: Device)))
pPTimestampInfos <- ContT $ allocaBytesAligned @CalibratedTimestampInfoEXT ((Data.Vector.length (timestampInfos)) * 24) 8
Data.Vector.imapM_ (\i e -> ContT $ pokeCStruct (pPTimestampInfos `plusPtr` (24 * (i)) :: Ptr CalibratedTimestampInfoEXT) (e) . ($ ())) (timestampInfos)
pPTimestamps <- ContT $ bracket (callocBytes @Word64 ((fromIntegral ((fromIntegral (Data.Vector.length $ (timestampInfos)) :: Word32))) * 8)) free
pPMaxDeviation <- ContT $ bracket (callocBytes @Word64 8) free
r <- lift $ vkGetCalibratedTimestampsEXT' (deviceHandle (device)) ((fromIntegral (Data.Vector.length $ (timestampInfos)) :: Word32)) (pPTimestampInfos) (pPTimestamps) (pPMaxDeviation)
lift $ when (r < SUCCESS) (throwIO (VulkanException r))
pTimestamps <- lift $ generateM (fromIntegral ((fromIntegral (Data.Vector.length $ (timestampInfos)) :: Word32))) (\i -> peek @Word64 ((pPTimestamps `advancePtrBytes` (8 * (i)) :: Ptr Word64)))
pMaxDeviation <- lift $ peek @Word64 pPMaxDeviation
pure $ (pTimestamps, pMaxDeviation)
data CalibratedTimestampInfoEXT = CalibratedTimestampInfoEXT
{
timeDomain :: TimeDomainEXT }
deriving (Typeable)
deriving instance Show CalibratedTimestampInfoEXT
instance ToCStruct CalibratedTimestampInfoEXT where
withCStruct x f = allocaBytesAligned 24 8 $ \p -> pokeCStruct p x (f p)
pokeCStruct p CalibratedTimestampInfoEXT{..} f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr TimeDomainEXT)) (timeDomain)
f
cStructSize = 24
cStructAlignment = 8
pokeZeroCStruct p f = do
poke ((p `plusPtr` 0 :: Ptr StructureType)) (STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT)
poke ((p `plusPtr` 8 :: Ptr (Ptr ()))) (nullPtr)
poke ((p `plusPtr` 16 :: Ptr TimeDomainEXT)) (zero)
f
instance FromCStruct CalibratedTimestampInfoEXT where
peekCStruct p = do
timeDomain <- peek @TimeDomainEXT ((p `plusPtr` 16 :: Ptr TimeDomainEXT))
pure $ CalibratedTimestampInfoEXT
timeDomain
instance Storable CalibratedTimestampInfoEXT where
sizeOf ~_ = 24
alignment ~_ = 8
peek = peekCStruct
poke ptr poked = pokeCStruct ptr poked (pure ())
instance Zero CalibratedTimestampInfoEXT where
zero = CalibratedTimestampInfoEXT
zero
newtype TimeDomainEXT = TimeDomainEXT Int32
deriving newtype (Eq, Ord, Storable, Zero)
pattern TIME_DOMAIN_DEVICE_EXT = TimeDomainEXT 0
pattern TIME_DOMAIN_CLOCK_MONOTONIC_EXT = TimeDomainEXT 1
pattern TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT = TimeDomainEXT 2
pattern TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT = TimeDomainEXT 3
{-# complete TIME_DOMAIN_DEVICE_EXT,
TIME_DOMAIN_CLOCK_MONOTONIC_EXT,
TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT,
TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT :: TimeDomainEXT #-}
instance Show TimeDomainEXT where
showsPrec p = \case
TIME_DOMAIN_DEVICE_EXT -> showString "TIME_DOMAIN_DEVICE_EXT"
TIME_DOMAIN_CLOCK_MONOTONIC_EXT -> showString "TIME_DOMAIN_CLOCK_MONOTONIC_EXT"
TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT -> showString "TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT"
TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT -> showString "TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT"
TimeDomainEXT x -> showParen (p >= 11) (showString "TimeDomainEXT " . showsPrec 11 x)
instance Read TimeDomainEXT where
readPrec = parens (choose [("TIME_DOMAIN_DEVICE_EXT", pure TIME_DOMAIN_DEVICE_EXT)
, ("TIME_DOMAIN_CLOCK_MONOTONIC_EXT", pure TIME_DOMAIN_CLOCK_MONOTONIC_EXT)
, ("TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT", pure TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT)
, ("TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT", pure TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT)]
+++
prec 10 (do
expectP (Ident "TimeDomainEXT")
v <- step readPrec
pure (TimeDomainEXT v)))
type EXT_CALIBRATED_TIMESTAMPS_SPEC_VERSION = 1
pattern EXT_CALIBRATED_TIMESTAMPS_SPEC_VERSION :: forall a . Integral a => a
pattern EXT_CALIBRATED_TIMESTAMPS_SPEC_VERSION = 1
type EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME = "VK_EXT_calibrated_timestamps"
pattern EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME = "VK_EXT_calibrated_timestamps"