{-# LINE 1 "src/Gpu/Vulkan/Semaphore/Middle/Internal.hsc" #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts, FlexibleInstances, UndecidableInstances #-}
{-# LANGUAGE PatternSynonyms, ViewPatterns #-}
{-# LANGUAGE StandaloneDeriving, GeneralizedNewtypeDeriving #-}
{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}
module Gpu.Vulkan.Semaphore.Middle.Internal (
create, destroy, S(..), CreateInfo(..), CreateFlags,
) where
import Foreign.Ptr
import Foreign.Marshal.Alloc
import Foreign.Storable
import Foreign.Storable.PeekPoke
import Foreign.C.Enum
import Data.TypeLevel.Maybe qualified as TMaybe
import Data.TypeLevel.ParMaybe qualified as TPMaybe
import Data.Default
import Data.Bits
import Data.Word
import Gpu.Vulkan.Exception.Middle.Internal
import Gpu.Vulkan.Exception.Enum
import qualified Gpu.Vulkan.AllocationCallbacks.Middle.Internal as AllocationCallbacks
import qualified Gpu.Vulkan.Semaphore.Core as C
import qualified Gpu.Vulkan.Device.Middle.Types as Device
enum "CreateFlags" ''Word32
{-# LINE 41 "src/Gpu/Vulkan/Semaphore/Middle/Internal.hsc" #-}
[''Show, ''Eq, ''Storable, ''Bits] [("CreateFlagsZero", 0)]
data CreateInfo mn = CreateInfo {
forall (mn :: Maybe (*)). CreateInfo mn -> M mn
createInfoNext :: TMaybe.M mn, forall (mn :: Maybe (*)). CreateInfo mn -> CreateFlags
createInfoFlags :: CreateFlags }
deriving instance Show (TMaybe.M mn) => Show (CreateInfo mn)
instance Default (CreateInfo 'Nothing) where
def :: CreateInfo 'Nothing
def = CreateInfo {
createInfoNext :: M 'Nothing
createInfoNext = M 'Nothing
TMaybe.N, createInfoFlags :: CreateFlags
createInfoFlags = CreateFlags
forall a. Bits a => a
zeroBits }
createInfoToCore :: WithPoked (TMaybe.M mn) =>
CreateInfo mn -> (Ptr C.CreateInfo -> IO r) -> IO ()
createInfoToCore :: forall (mn :: Maybe (*)) r.
WithPoked (M mn) =>
CreateInfo mn -> (Ptr CreateInfo -> IO r) -> IO ()
createInfoToCore CreateInfo {
createInfoNext :: forall (mn :: Maybe (*)). CreateInfo mn -> M mn
createInfoNext = M mn
mnxt,
createInfoFlags :: forall (mn :: Maybe (*)). CreateInfo mn -> CreateFlags
createInfoFlags = CreateFlags Word32
flgs } Ptr CreateInfo -> IO r
f =
M mn -> (forall s. PtrS s (M mn) -> IO ()) -> IO ()
forall a b.
WithPoked a =>
a -> (forall s. PtrS s a -> IO b) -> IO b
forall b. M mn -> (forall s. PtrS s (M mn) -> IO b) -> IO b
withPoked' M mn
mnxt \PtrS s (M mn)
pnxt -> PtrS s (M mn) -> (Ptr (M mn) -> IO r) -> IO ()
forall s a b. PtrS s a -> (Ptr a -> IO b) -> IO ()
withPtrS PtrS s (M mn)
pnxt \(Ptr (M mn) -> Ptr ()
forall a b. Ptr a -> Ptr b
castPtr -> Ptr ()
pnxt') ->
let ci :: CreateInfo
ci = C.CreateInfo {
createInfoSType :: ()
C.createInfoSType = (),
createInfoPNext :: Ptr ()
C.createInfoPNext = Ptr ()
pnxt',
createInfoFlags :: Word32
C.createInfoFlags = Word32
flgs } in CreateInfo -> (Ptr CreateInfo -> IO r) -> IO r
forall a b. Pokable a => a -> (Ptr a -> IO b) -> IO b
withPoked CreateInfo
ci Ptr CreateInfo -> IO r
f
newtype S = S { S -> S
unS :: C.S } deriving Int -> S -> ShowS
[S] -> ShowS
S -> String
(Int -> S -> ShowS) -> (S -> String) -> ([S] -> ShowS) -> Show S
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> S -> ShowS
showsPrec :: Int -> S -> ShowS
$cshow :: S -> String
show :: S -> String
$cshowList :: [S] -> ShowS
showList :: [S] -> ShowS
Show
create :: WithPoked (TMaybe.M mn) =>
Device.D -> CreateInfo mn -> TPMaybe.M AllocationCallbacks.A mc -> IO S
create :: forall (mn :: Maybe (*)) (mc :: Maybe (*)).
WithPoked (M mn) =>
D -> CreateInfo mn -> M A mc -> IO S
create (Device.D D
dvc) CreateInfo mn
ci M A mc
mac = S -> S
S (S -> S) -> IO S -> IO S
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr S -> IO S) -> IO S
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca \Ptr S
ps -> do
CreateInfo mn -> (Ptr CreateInfo -> IO ()) -> IO ()
forall (mn :: Maybe (*)) r.
WithPoked (M mn) =>
CreateInfo mn -> (Ptr CreateInfo -> IO r) -> IO ()
createInfoToCore CreateInfo mn
ci \Ptr CreateInfo
pci -> M A mc -> (Ptr A -> IO ()) -> IO ()
forall (ma :: Maybe (*)) b. M A ma -> (Ptr A -> IO b) -> IO ()
AllocationCallbacks.mToCore M A mc
mac \Ptr A
pac ->
Result -> IO ()
throwUnlessSuccess (Result -> IO ()) -> (Int32 -> Result) -> Int32 -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Result
Result (Int32 -> IO ()) -> IO Int32 -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< D -> Ptr CreateInfo -> Ptr A -> Ptr S -> IO Int32
C.create D
dvc Ptr CreateInfo
pci Ptr A
pac Ptr S
ps
Ptr S -> IO S
forall a. Storable a => Ptr a -> IO a
peek Ptr S
ps
destroy :: Device.D -> S -> TPMaybe.M AllocationCallbacks.A md -> IO ()
destroy :: forall (md :: Maybe (*)). D -> S -> M A md -> IO ()
destroy (Device.D D
dvc) (S S
s) M A md
mac =
M A md -> (Ptr A -> IO ()) -> IO ()
forall (ma :: Maybe (*)) b. M A ma -> (Ptr A -> IO b) -> IO ()
AllocationCallbacks.mToCore M A md
mac ((Ptr A -> IO ()) -> IO ()) -> (Ptr A -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ D -> S -> Ptr A -> IO ()
C.destroy D
dvc S
s