{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeSynonymInstances #-}
module WGPU.Internal.Binding
(
BindGroup (..),
BindGroupDescriptor (..),
BindGroupEntry (..),
BindGroupLayout (..),
BindGroupLayoutDescriptor (..),
BindGroupLayoutEntry (..),
Binding (..),
ShaderStage (..),
BindingType (..),
BufferBindingLayout (..),
SamplerBindingLayout (..),
TextureBindingLayout (..),
StorageTextureBindingLayout (..),
StorageTextureAccess (..),
TextureSampleType (..),
BufferBindingType (..),
BindingResource (..),
BufferBinding (..),
createBindGroup,
createBindGroupLayout,
)
where
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Bits ((.|.))
import Data.Default (Default, def)
import Data.Text (Text)
import Data.Vector (Vector)
import qualified Data.Vector as Vector
import Data.Word (Word32, Word64)
import Foreign (nullPtr)
import Foreign.C (CBool (CBool))
import WGPU.Internal.Buffer (Buffer, wgpuBuffer)
import WGPU.Internal.Device (Device, deviceInst, wgpuDevice)
import WGPU.Internal.Instance (wgpuHsInstance)
import WGPU.Internal.Memory
( ToRaw,
evalContT,
raw,
rawArrayPtr,
rawPtr,
showWithPtr,
)
import WGPU.Internal.SMaybe (SMaybe, fromSMaybe)
import WGPU.Internal.Sampler (Sampler, wgpuSampler)
import WGPU.Internal.Texture (TextureFormat, TextureView, TextureViewDimension, wgpuTextureView)
import WGPU.Raw.Generated.Enum.WGPUBufferBindingType (WGPUBufferBindingType)
import qualified WGPU.Raw.Generated.Enum.WGPUBufferBindingType as WGPUBufferBindingType
import qualified WGPU.Raw.Generated.Enum.WGPUSamplerBindingType as WGPUSamplerBindingType
import qualified WGPU.Raw.Generated.Enum.WGPUShaderStage as WGPUShaderStage
import WGPU.Raw.Generated.Enum.WGPUStorageTextureAccess (WGPUStorageTextureAccess)
import qualified WGPU.Raw.Generated.Enum.WGPUStorageTextureAccess as WGPUStorageTextureAccess
import qualified WGPU.Raw.Generated.Enum.WGPUTextureFormat as WGPUTextureFormat
import WGPU.Raw.Generated.Enum.WGPUTextureSampleType (WGPUTextureSampleType)
import qualified WGPU.Raw.Generated.Enum.WGPUTextureSampleType as WGPUTextureSampleType
import qualified WGPU.Raw.Generated.Enum.WGPUTextureViewDimension as WGPUTextureViewDimension
import qualified WGPU.Raw.Generated.Fun as RawFun
import WGPU.Raw.Generated.Struct.WGPUBindGroupDescriptor (WGPUBindGroupDescriptor)
import qualified WGPU.Raw.Generated.Struct.WGPUBindGroupDescriptor as WGPUBindGroupDescriptor
import WGPU.Raw.Generated.Struct.WGPUBindGroupEntry (WGPUBindGroupEntry)
import qualified WGPU.Raw.Generated.Struct.WGPUBindGroupEntry as WGPUBindGroupEntry
import WGPU.Raw.Generated.Struct.WGPUBindGroupLayoutDescriptor (WGPUBindGroupLayoutDescriptor)
import qualified WGPU.Raw.Generated.Struct.WGPUBindGroupLayoutDescriptor as WGPUBindGroupLayoutDescriptor
import WGPU.Raw.Generated.Struct.WGPUBindGroupLayoutEntry (WGPUBindGroupLayoutEntry)
import qualified WGPU.Raw.Generated.Struct.WGPUBindGroupLayoutEntry as WGPUBindGroupLayoutEntry
import WGPU.Raw.Generated.Struct.WGPUBufferBindingLayout (WGPUBufferBindingLayout)
import qualified WGPU.Raw.Generated.Struct.WGPUBufferBindingLayout as WGPUBufferBindingLayout
import WGPU.Raw.Generated.Struct.WGPUSamplerBindingLayout (WGPUSamplerBindingLayout)
import qualified WGPU.Raw.Generated.Struct.WGPUSamplerBindingLayout as WGPUSamplerBindingLayout
import WGPU.Raw.Generated.Struct.WGPUStorageTextureBindingLayout (WGPUStorageTextureBindingLayout)
import qualified WGPU.Raw.Generated.Struct.WGPUStorageTextureBindingLayout as WGPUStorageTextureBindingLayout
import WGPU.Raw.Generated.Struct.WGPUTextureBindingLayout (WGPUTextureBindingLayout)
import qualified WGPU.Raw.Generated.Struct.WGPUTextureBindingLayout as WGPUTextureBindingLayout
import WGPU.Raw.Types
( WGPUBindGroup (WGPUBindGroup),
WGPUBindGroupLayout (WGPUBindGroupLayout),
WGPUBuffer (WGPUBuffer),
WGPUSampler (WGPUSampler),
WGPUShaderStageFlags,
WGPUTextureView (WGPUTextureView),
)
newtype BindGroup = BindGroup {BindGroup -> WGPUBindGroup
wgpuBindGroup :: WGPUBindGroup}
instance Show BindGroup where
show :: BindGroup -> String
show BindGroup
b =
let BindGroup (WGPUBindGroup Ptr ()
ptr) = BindGroup
b
in String -> Ptr () -> String
forall a. String -> Ptr a -> String
showWithPtr String
"BindGroup" Ptr ()
ptr
instance Eq BindGroup where
== :: BindGroup -> BindGroup -> Bool
(==) BindGroup
b1 BindGroup
b2 =
let BindGroup (WGPUBindGroup Ptr ()
b1_ptr) = BindGroup
b1
BindGroup (WGPUBindGroup Ptr ()
b2_ptr) = BindGroup
b2
in Ptr ()
b1_ptr Ptr () -> Ptr () -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr ()
b2_ptr
instance ToRaw BindGroup WGPUBindGroup where
raw :: BindGroup -> ContT r IO WGPUBindGroup
raw = WGPUBindGroup -> ContT r IO WGPUBindGroup
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUBindGroup -> ContT r IO WGPUBindGroup)
-> (BindGroup -> WGPUBindGroup)
-> BindGroup
-> ContT r IO WGPUBindGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BindGroup -> WGPUBindGroup
wgpuBindGroup
newtype BindGroupLayout = BindGroupLayout {BindGroupLayout -> WGPUBindGroupLayout
wgpuBindGroupLayout :: WGPUBindGroupLayout}
instance Show BindGroupLayout where
show :: BindGroupLayout -> String
show BindGroupLayout
b =
let BindGroupLayout (WGPUBindGroupLayout Ptr ()
ptr) = BindGroupLayout
b
in String -> Ptr () -> String
forall a. String -> Ptr a -> String
showWithPtr String
"BindGroupLayout" Ptr ()
ptr
instance Eq BindGroupLayout where
== :: BindGroupLayout -> BindGroupLayout -> Bool
(==) BindGroupLayout
b1 BindGroupLayout
b2 =
let BindGroupLayout (WGPUBindGroupLayout Ptr ()
b1_ptr) = BindGroupLayout
b1
BindGroupLayout (WGPUBindGroupLayout Ptr ()
b2_ptr) = BindGroupLayout
b2
in Ptr ()
b1_ptr Ptr () -> Ptr () -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr ()
b2_ptr
instance ToRaw BindGroupLayout WGPUBindGroupLayout where
raw :: BindGroupLayout -> ContT r IO WGPUBindGroupLayout
raw = WGPUBindGroupLayout -> ContT r IO WGPUBindGroupLayout
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUBindGroupLayout -> ContT r IO WGPUBindGroupLayout)
-> (BindGroupLayout -> WGPUBindGroupLayout)
-> BindGroupLayout
-> ContT r IO WGPUBindGroupLayout
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BindGroupLayout -> WGPUBindGroupLayout
wgpuBindGroupLayout
data BindGroupDescriptor = BindGroupDescriptor
{ BindGroupDescriptor -> Text
bindGroupLabel :: !Text,
BindGroupDescriptor -> BindGroupLayout
bindGroupLayout :: !BindGroupLayout,
BindGroupDescriptor -> Vector BindGroupEntry
bindGroupEntries :: !(Vector BindGroupEntry)
}
deriving (BindGroupDescriptor -> BindGroupDescriptor -> Bool
(BindGroupDescriptor -> BindGroupDescriptor -> Bool)
-> (BindGroupDescriptor -> BindGroupDescriptor -> Bool)
-> Eq BindGroupDescriptor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BindGroupDescriptor -> BindGroupDescriptor -> Bool
$c/= :: BindGroupDescriptor -> BindGroupDescriptor -> Bool
== :: BindGroupDescriptor -> BindGroupDescriptor -> Bool
$c== :: BindGroupDescriptor -> BindGroupDescriptor -> Bool
Eq, Int -> BindGroupDescriptor -> ShowS
[BindGroupDescriptor] -> ShowS
BindGroupDescriptor -> String
(Int -> BindGroupDescriptor -> ShowS)
-> (BindGroupDescriptor -> String)
-> ([BindGroupDescriptor] -> ShowS)
-> Show BindGroupDescriptor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BindGroupDescriptor] -> ShowS
$cshowList :: [BindGroupDescriptor] -> ShowS
show :: BindGroupDescriptor -> String
$cshow :: BindGroupDescriptor -> String
showsPrec :: Int -> BindGroupDescriptor -> ShowS
$cshowsPrec :: Int -> BindGroupDescriptor -> ShowS
Show)
instance ToRaw BindGroupDescriptor WGPUBindGroupDescriptor where
raw :: BindGroupDescriptor -> ContT r IO WGPUBindGroupDescriptor
raw BindGroupDescriptor {Text
Vector BindGroupEntry
BindGroupLayout
bindGroupEntries :: Vector BindGroupEntry
bindGroupLayout :: BindGroupLayout
bindGroupLabel :: Text
bindGroupEntries :: BindGroupDescriptor -> Vector BindGroupEntry
bindGroupLayout :: BindGroupDescriptor -> BindGroupLayout
bindGroupLabel :: BindGroupDescriptor -> Text
..} = do
Ptr CChar
label_ptr <- Text -> ContT r IO (Ptr CChar)
forall a b r. ToRawPtr a b => a -> ContT r IO (Ptr b)
rawPtr Text
bindGroupLabel
WGPUBindGroupLayout
n_layout <- BindGroupLayout -> ContT r IO WGPUBindGroupLayout
forall a b r. ToRaw a b => a -> ContT r IO b
raw BindGroupLayout
bindGroupLayout
let n_entryCount :: Word32
n_entryCount = Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word32)
-> (Vector BindGroupEntry -> Int)
-> Vector BindGroupEntry
-> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector BindGroupEntry -> Int
forall a. Vector a -> Int
Vector.length (Vector BindGroupEntry -> Word32)
-> Vector BindGroupEntry -> Word32
forall a b. (a -> b) -> a -> b
$ Vector BindGroupEntry
bindGroupEntries
Ptr WGPUBindGroupEntry
entries_ptr <- Vector BindGroupEntry -> ContT r IO (Ptr WGPUBindGroupEntry)
forall (v :: * -> *) r a b.
(ToRaw a b, Storable b, Vector v a) =>
v a -> ContT r IO (Ptr b)
rawArrayPtr Vector BindGroupEntry
bindGroupEntries
WGPUBindGroupDescriptor -> ContT r IO WGPUBindGroupDescriptor
forall (f :: * -> *) a. Applicative f => a -> f a
pure
WGPUBindGroupDescriptor :: Ptr WGPUChainedStruct
-> Ptr CChar
-> WGPUBindGroupLayout
-> Word32
-> Ptr WGPUBindGroupEntry
-> WGPUBindGroupDescriptor
WGPUBindGroupDescriptor.WGPUBindGroupDescriptor
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
label :: Ptr CChar
label = Ptr CChar
label_ptr,
layout :: WGPUBindGroupLayout
layout = WGPUBindGroupLayout
n_layout,
entryCount :: Word32
entryCount = Word32
n_entryCount,
entries :: Ptr WGPUBindGroupEntry
entries = Ptr WGPUBindGroupEntry
entries_ptr
}
data BindGroupEntry = BindGroupEntry
{ BindGroupEntry -> Binding
binding :: !Binding,
BindGroupEntry -> BindingResource
resource :: !BindingResource
}
deriving (BindGroupEntry -> BindGroupEntry -> Bool
(BindGroupEntry -> BindGroupEntry -> Bool)
-> (BindGroupEntry -> BindGroupEntry -> Bool) -> Eq BindGroupEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BindGroupEntry -> BindGroupEntry -> Bool
$c/= :: BindGroupEntry -> BindGroupEntry -> Bool
== :: BindGroupEntry -> BindGroupEntry -> Bool
$c== :: BindGroupEntry -> BindGroupEntry -> Bool
Eq, Int -> BindGroupEntry -> ShowS
[BindGroupEntry] -> ShowS
BindGroupEntry -> String
(Int -> BindGroupEntry -> ShowS)
-> (BindGroupEntry -> String)
-> ([BindGroupEntry] -> ShowS)
-> Show BindGroupEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BindGroupEntry] -> ShowS
$cshowList :: [BindGroupEntry] -> ShowS
show :: BindGroupEntry -> String
$cshow :: BindGroupEntry -> String
showsPrec :: Int -> BindGroupEntry -> ShowS
$cshowsPrec :: Int -> BindGroupEntry -> ShowS
Show)
instance ToRaw BindGroupEntry WGPUBindGroupEntry where
raw :: BindGroupEntry -> ContT r IO WGPUBindGroupEntry
raw BindGroupEntry {Binding
BindingResource
resource :: BindingResource
binding :: Binding
resource :: BindGroupEntry -> BindingResource
binding :: BindGroupEntry -> Binding
..} = WGPUBindGroupEntry -> ContT r IO WGPUBindGroupEntry
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUBindGroupEntry -> ContT r IO WGPUBindGroupEntry)
-> WGPUBindGroupEntry -> ContT r IO WGPUBindGroupEntry
forall a b. (a -> b) -> a -> b
$
case BindingResource
resource of
BindingResourceBuffer BufferBinding
bufferBinding ->
Binding -> BufferBinding -> WGPUBindGroupEntry
bufferBindingToRaw Binding
binding BufferBinding
bufferBinding
BindingResourceSampler Sampler
sampler ->
Binding -> Sampler -> WGPUBindGroupEntry
samplerBindingToRaw Binding
binding Sampler
sampler
BindingResourceTextureView TextureView
textureView ->
Binding -> TextureView -> WGPUBindGroupEntry
textureViewBindingToRaw Binding
binding TextureView
textureView
where
bufferBindingToRaw :: Binding -> BufferBinding -> WGPUBindGroupEntry
bufferBindingToRaw :: Binding -> BufferBinding -> WGPUBindGroupEntry
bufferBindingToRaw Binding
bnding BufferBinding {Word64
Buffer
bindingBufferSize :: BufferBinding -> Word64
bindingBufferOffset :: BufferBinding -> Word64
bindingBuffer :: BufferBinding -> Buffer
bindingBufferSize :: Word64
bindingBufferOffset :: Word64
bindingBuffer :: Buffer
..} =
WGPUBindGroupEntry :: Word32
-> WGPUBuffer
-> Word64
-> Word64
-> WGPUSampler
-> WGPUTextureView
-> WGPUBindGroupEntry
WGPUBindGroupEntry.WGPUBindGroupEntry
{ binding :: Word32
binding = Binding -> Word32
unBinding Binding
bnding,
buffer :: WGPUBuffer
buffer = Buffer -> WGPUBuffer
wgpuBuffer Buffer
bindingBuffer,
offset :: Word64
offset = Word64
bindingBufferOffset,
size :: Word64
size = Word64
bindingBufferSize,
sampler :: WGPUSampler
sampler = Ptr () -> WGPUSampler
WGPUSampler Ptr ()
forall a. Ptr a
nullPtr,
textureView :: WGPUTextureView
textureView = Ptr () -> WGPUTextureView
WGPUTextureView Ptr ()
forall a. Ptr a
nullPtr
}
samplerBindingToRaw :: Binding -> Sampler -> WGPUBindGroupEntry
samplerBindingToRaw :: Binding -> Sampler -> WGPUBindGroupEntry
samplerBindingToRaw Binding
bnding Sampler
sampler =
WGPUBindGroupEntry :: Word32
-> WGPUBuffer
-> Word64
-> Word64
-> WGPUSampler
-> WGPUTextureView
-> WGPUBindGroupEntry
WGPUBindGroupEntry.WGPUBindGroupEntry
{ binding :: Word32
binding = Binding -> Word32
unBinding Binding
bnding,
buffer :: WGPUBuffer
buffer = Ptr () -> WGPUBuffer
WGPUBuffer Ptr ()
forall a. Ptr a
nullPtr,
offset :: Word64
offset = Word64
0,
size :: Word64
size = Word64
0,
sampler :: WGPUSampler
sampler = Sampler -> WGPUSampler
wgpuSampler Sampler
sampler,
textureView :: WGPUTextureView
textureView = Ptr () -> WGPUTextureView
WGPUTextureView Ptr ()
forall a. Ptr a
nullPtr
}
textureViewBindingToRaw :: Binding -> TextureView -> WGPUBindGroupEntry
textureViewBindingToRaw :: Binding -> TextureView -> WGPUBindGroupEntry
textureViewBindingToRaw Binding
bnding TextureView
textureView =
WGPUBindGroupEntry :: Word32
-> WGPUBuffer
-> Word64
-> Word64
-> WGPUSampler
-> WGPUTextureView
-> WGPUBindGroupEntry
WGPUBindGroupEntry.WGPUBindGroupEntry
{ binding :: Word32
binding = Binding -> Word32
unBinding Binding
bnding,
buffer :: WGPUBuffer
buffer = Ptr () -> WGPUBuffer
WGPUBuffer Ptr ()
forall a. Ptr a
nullPtr,
offset :: Word64
offset = Word64
0,
size :: Word64
size = Word64
0,
sampler :: WGPUSampler
sampler = Ptr () -> WGPUSampler
WGPUSampler Ptr ()
forall a. Ptr a
nullPtr,
textureView :: WGPUTextureView
textureView = TextureView -> WGPUTextureView
wgpuTextureView TextureView
textureView
}
data BindingResource
= BindingResourceBuffer !BufferBinding
| BindingResourceSampler !Sampler
| BindingResourceTextureView !TextureView
deriving (BindingResource -> BindingResource -> Bool
(BindingResource -> BindingResource -> Bool)
-> (BindingResource -> BindingResource -> Bool)
-> Eq BindingResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BindingResource -> BindingResource -> Bool
$c/= :: BindingResource -> BindingResource -> Bool
== :: BindingResource -> BindingResource -> Bool
$c== :: BindingResource -> BindingResource -> Bool
Eq, Int -> BindingResource -> ShowS
[BindingResource] -> ShowS
BindingResource -> String
(Int -> BindingResource -> ShowS)
-> (BindingResource -> String)
-> ([BindingResource] -> ShowS)
-> Show BindingResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BindingResource] -> ShowS
$cshowList :: [BindingResource] -> ShowS
show :: BindingResource -> String
$cshow :: BindingResource -> String
showsPrec :: Int -> BindingResource -> ShowS
$cshowsPrec :: Int -> BindingResource -> ShowS
Show)
data BufferBinding = BufferBinding
{ BufferBinding -> Buffer
bindingBuffer :: !Buffer,
BufferBinding -> Word64
bindingBufferOffset :: !Word64,
BufferBinding -> Word64
bindingBufferSize :: !Word64
}
deriving (BufferBinding -> BufferBinding -> Bool
(BufferBinding -> BufferBinding -> Bool)
-> (BufferBinding -> BufferBinding -> Bool) -> Eq BufferBinding
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BufferBinding -> BufferBinding -> Bool
$c/= :: BufferBinding -> BufferBinding -> Bool
== :: BufferBinding -> BufferBinding -> Bool
$c== :: BufferBinding -> BufferBinding -> Bool
Eq, Int -> BufferBinding -> ShowS
[BufferBinding] -> ShowS
BufferBinding -> String
(Int -> BufferBinding -> ShowS)
-> (BufferBinding -> String)
-> ([BufferBinding] -> ShowS)
-> Show BufferBinding
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BufferBinding] -> ShowS
$cshowList :: [BufferBinding] -> ShowS
show :: BufferBinding -> String
$cshow :: BufferBinding -> String
showsPrec :: Int -> BufferBinding -> ShowS
$cshowsPrec :: Int -> BufferBinding -> ShowS
Show)
data BindGroupLayoutDescriptor = BindGroupLayoutDescriptor
{
BindGroupLayoutDescriptor -> Text
bindGroupLayoutLabel :: !Text,
BindGroupLayoutDescriptor -> Vector BindGroupLayoutEntry
layoutEntries :: !(Vector BindGroupLayoutEntry)
}
deriving (BindGroupLayoutDescriptor -> BindGroupLayoutDescriptor -> Bool
(BindGroupLayoutDescriptor -> BindGroupLayoutDescriptor -> Bool)
-> (BindGroupLayoutDescriptor -> BindGroupLayoutDescriptor -> Bool)
-> Eq BindGroupLayoutDescriptor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BindGroupLayoutDescriptor -> BindGroupLayoutDescriptor -> Bool
$c/= :: BindGroupLayoutDescriptor -> BindGroupLayoutDescriptor -> Bool
== :: BindGroupLayoutDescriptor -> BindGroupLayoutDescriptor -> Bool
$c== :: BindGroupLayoutDescriptor -> BindGroupLayoutDescriptor -> Bool
Eq, Int -> BindGroupLayoutDescriptor -> ShowS
[BindGroupLayoutDescriptor] -> ShowS
BindGroupLayoutDescriptor -> String
(Int -> BindGroupLayoutDescriptor -> ShowS)
-> (BindGroupLayoutDescriptor -> String)
-> ([BindGroupLayoutDescriptor] -> ShowS)
-> Show BindGroupLayoutDescriptor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BindGroupLayoutDescriptor] -> ShowS
$cshowList :: [BindGroupLayoutDescriptor] -> ShowS
show :: BindGroupLayoutDescriptor -> String
$cshow :: BindGroupLayoutDescriptor -> String
showsPrec :: Int -> BindGroupLayoutDescriptor -> ShowS
$cshowsPrec :: Int -> BindGroupLayoutDescriptor -> ShowS
Show)
instance ToRaw BindGroupLayoutDescriptor WGPUBindGroupLayoutDescriptor where
raw :: BindGroupLayoutDescriptor
-> ContT r IO WGPUBindGroupLayoutDescriptor
raw BindGroupLayoutDescriptor {Text
Vector BindGroupLayoutEntry
layoutEntries :: Vector BindGroupLayoutEntry
bindGroupLayoutLabel :: Text
layoutEntries :: BindGroupLayoutDescriptor -> Vector BindGroupLayoutEntry
bindGroupLayoutLabel :: BindGroupLayoutDescriptor -> Text
..} = do
Ptr CChar
label_ptr <- Text -> ContT r IO (Ptr CChar)
forall a b r. ToRawPtr a b => a -> ContT r IO (Ptr b)
rawPtr Text
bindGroupLayoutLabel
let n_entryCount :: Word32
n_entryCount = Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word32)
-> (Vector BindGroupLayoutEntry -> Int)
-> Vector BindGroupLayoutEntry
-> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector BindGroupLayoutEntry -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (Vector BindGroupLayoutEntry -> Word32)
-> Vector BindGroupLayoutEntry -> Word32
forall a b. (a -> b) -> a -> b
$ Vector BindGroupLayoutEntry
layoutEntries
Ptr WGPUBindGroupLayoutEntry
entries_ptr <- Vector BindGroupLayoutEntry
-> ContT r IO (Ptr WGPUBindGroupLayoutEntry)
forall (v :: * -> *) r a b.
(ToRaw a b, Storable b, Vector v a) =>
v a -> ContT r IO (Ptr b)
rawArrayPtr Vector BindGroupLayoutEntry
layoutEntries
WGPUBindGroupLayoutDescriptor
-> ContT r IO WGPUBindGroupLayoutDescriptor
forall (f :: * -> *) a. Applicative f => a -> f a
pure
WGPUBindGroupLayoutDescriptor :: Ptr WGPUChainedStruct
-> Ptr CChar
-> Word32
-> Ptr WGPUBindGroupLayoutEntry
-> WGPUBindGroupLayoutDescriptor
WGPUBindGroupLayoutDescriptor.WGPUBindGroupLayoutDescriptor
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
label :: Ptr CChar
label = Ptr CChar
label_ptr,
entryCount :: Word32
entryCount = Word32
n_entryCount,
entries :: Ptr WGPUBindGroupLayoutEntry
entries = Ptr WGPUBindGroupLayoutEntry
entries_ptr
}
data BindGroupLayoutEntry = BindGroupLayoutEntry
{
BindGroupLayoutEntry -> Binding
layoutBinding :: !Binding,
BindGroupLayoutEntry -> ShaderStage
visibility :: !ShaderStage,
BindGroupLayoutEntry -> BindingType
bindGroupLayoutEntryType :: !BindingType
}
deriving (BindGroupLayoutEntry -> BindGroupLayoutEntry -> Bool
(BindGroupLayoutEntry -> BindGroupLayoutEntry -> Bool)
-> (BindGroupLayoutEntry -> BindGroupLayoutEntry -> Bool)
-> Eq BindGroupLayoutEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BindGroupLayoutEntry -> BindGroupLayoutEntry -> Bool
$c/= :: BindGroupLayoutEntry -> BindGroupLayoutEntry -> Bool
== :: BindGroupLayoutEntry -> BindGroupLayoutEntry -> Bool
$c== :: BindGroupLayoutEntry -> BindGroupLayoutEntry -> Bool
Eq, Int -> BindGroupLayoutEntry -> ShowS
[BindGroupLayoutEntry] -> ShowS
BindGroupLayoutEntry -> String
(Int -> BindGroupLayoutEntry -> ShowS)
-> (BindGroupLayoutEntry -> String)
-> ([BindGroupLayoutEntry] -> ShowS)
-> Show BindGroupLayoutEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BindGroupLayoutEntry] -> ShowS
$cshowList :: [BindGroupLayoutEntry] -> ShowS
show :: BindGroupLayoutEntry -> String
$cshow :: BindGroupLayoutEntry -> String
showsPrec :: Int -> BindGroupLayoutEntry -> ShowS
$cshowsPrec :: Int -> BindGroupLayoutEntry -> ShowS
Show)
instance ToRaw BindGroupLayoutEntry WGPUBindGroupLayoutEntry where
raw :: BindGroupLayoutEntry -> ContT r IO WGPUBindGroupLayoutEntry
raw BindGroupLayoutEntry {BindingType
ShaderStage
Binding
bindGroupLayoutEntryType :: BindingType
visibility :: ShaderStage
layoutBinding :: Binding
bindGroupLayoutEntryType :: BindGroupLayoutEntry -> BindingType
visibility :: BindGroupLayoutEntry -> ShaderStage
layoutBinding :: BindGroupLayoutEntry -> Binding
..} = do
Word32
n_binding <- Binding -> ContT r IO Word32
forall a b r. ToRaw a b => a -> ContT r IO b
raw Binding
layoutBinding
Word32
n_visibility <- ShaderStage -> ContT r IO Word32
forall a b r. ToRaw a b => a -> ContT r IO b
raw ShaderStage
visibility
(WGPUBufferBindingLayout
n_buffer, WGPUSamplerBindingLayout
n_sampler, WGPUTextureBindingLayout
n_texture, WGPUStorageTextureBindingLayout
n_storageTexture) <-
case BindingType
bindGroupLayoutEntryType of
BindingTypeBuffer BufferBindingLayout
bbl -> do
WGPUBufferBindingLayout
nn_buffer <- BufferBindingLayout -> ContT r IO WGPUBufferBindingLayout
forall a b r. ToRaw a b => a -> ContT r IO b
raw BufferBindingLayout
bbl
(WGPUBufferBindingLayout, WGPUSamplerBindingLayout,
WGPUTextureBindingLayout, WGPUStorageTextureBindingLayout)
-> ContT
r
IO
(WGPUBufferBindingLayout, WGPUSamplerBindingLayout,
WGPUTextureBindingLayout, WGPUStorageTextureBindingLayout)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUBufferBindingLayout
nn_buffer, WGPUSamplerBindingLayout
noSampler, WGPUTextureBindingLayout
noTexture, WGPUStorageTextureBindingLayout
noStorageTexture)
BindingTypeSampler SamplerBindingLayout
sbl -> do
WGPUSamplerBindingLayout
nn_sampler <- SamplerBindingLayout -> ContT r IO WGPUSamplerBindingLayout
forall a b r. ToRaw a b => a -> ContT r IO b
raw SamplerBindingLayout
sbl
(WGPUBufferBindingLayout, WGPUSamplerBindingLayout,
WGPUTextureBindingLayout, WGPUStorageTextureBindingLayout)
-> ContT
r
IO
(WGPUBufferBindingLayout, WGPUSamplerBindingLayout,
WGPUTextureBindingLayout, WGPUStorageTextureBindingLayout)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUBufferBindingLayout
noBuffer, WGPUSamplerBindingLayout
nn_sampler, WGPUTextureBindingLayout
noTexture, WGPUStorageTextureBindingLayout
noStorageTexture)
BindingTypeTexture TextureBindingLayout
tbl -> do
WGPUTextureBindingLayout
nn_texture <- TextureBindingLayout -> ContT r IO WGPUTextureBindingLayout
forall a b r. ToRaw a b => a -> ContT r IO b
raw TextureBindingLayout
tbl
(WGPUBufferBindingLayout, WGPUSamplerBindingLayout,
WGPUTextureBindingLayout, WGPUStorageTextureBindingLayout)
-> ContT
r
IO
(WGPUBufferBindingLayout, WGPUSamplerBindingLayout,
WGPUTextureBindingLayout, WGPUStorageTextureBindingLayout)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUBufferBindingLayout
noBuffer, WGPUSamplerBindingLayout
noSampler, WGPUTextureBindingLayout
nn_texture, WGPUStorageTextureBindingLayout
noStorageTexture)
BindingTypeStorageTexture StorageTextureBindingLayout
stbl -> do
WGPUStorageTextureBindingLayout
nn_storageTexture <- StorageTextureBindingLayout
-> ContT r IO WGPUStorageTextureBindingLayout
forall a b r. ToRaw a b => a -> ContT r IO b
raw StorageTextureBindingLayout
stbl
(WGPUBufferBindingLayout, WGPUSamplerBindingLayout,
WGPUTextureBindingLayout, WGPUStorageTextureBindingLayout)
-> ContT
r
IO
(WGPUBufferBindingLayout, WGPUSamplerBindingLayout,
WGPUTextureBindingLayout, WGPUStorageTextureBindingLayout)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUBufferBindingLayout
noBuffer, WGPUSamplerBindingLayout
noSampler, WGPUTextureBindingLayout
noTexture, WGPUStorageTextureBindingLayout
nn_storageTexture)
WGPUBindGroupLayoutEntry -> ContT r IO WGPUBindGroupLayoutEntry
forall (f :: * -> *) a. Applicative f => a -> f a
pure
WGPUBindGroupLayoutEntry :: Ptr WGPUChainedStruct
-> Word32
-> Word32
-> WGPUBufferBindingLayout
-> WGPUSamplerBindingLayout
-> WGPUTextureBindingLayout
-> WGPUStorageTextureBindingLayout
-> WGPUBindGroupLayoutEntry
WGPUBindGroupLayoutEntry.WGPUBindGroupLayoutEntry
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
binding :: Word32
binding = Word32
n_binding,
visibility :: Word32
visibility = Word32
n_visibility,
buffer :: WGPUBufferBindingLayout
buffer = WGPUBufferBindingLayout
n_buffer,
sampler :: WGPUSamplerBindingLayout
sampler = WGPUSamplerBindingLayout
n_sampler,
texture :: WGPUTextureBindingLayout
texture = WGPUTextureBindingLayout
n_texture,
storageTexture :: WGPUStorageTextureBindingLayout
storageTexture = WGPUStorageTextureBindingLayout
n_storageTexture
}
where
noBuffer :: WGPUBufferBindingLayout
noBuffer :: WGPUBufferBindingLayout
noBuffer =
WGPUBufferBindingLayout :: Ptr WGPUChainedStruct
-> WGPUBufferBindingType
-> CBool
-> Word64
-> WGPUBufferBindingLayout
WGPUBufferBindingLayout.WGPUBufferBindingLayout
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
typ :: WGPUBufferBindingType
typ = WGPUBufferBindingType
forall a. (Eq a, Num a) => a
WGPUBufferBindingType.Undefined,
hasDynamicOffset :: CBool
hasDynamicOffset = Word8 -> CBool
CBool Word8
0,
minBindingSize :: Word64
minBindingSize = Word64
0
}
noSampler :: WGPUSamplerBindingLayout
noSampler :: WGPUSamplerBindingLayout
noSampler =
WGPUSamplerBindingLayout :: Ptr WGPUChainedStruct
-> WGPUSamplerBindingType -> WGPUSamplerBindingLayout
WGPUSamplerBindingLayout.WGPUSamplerBindingLayout
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
typ :: WGPUSamplerBindingType
typ = WGPUSamplerBindingType
forall a. (Eq a, Num a) => a
WGPUSamplerBindingType.Undefined
}
noTexture :: WGPUTextureBindingLayout
noTexture :: WGPUTextureBindingLayout
noTexture =
WGPUTextureBindingLayout :: Ptr WGPUChainedStruct
-> WGPUTextureSampleType
-> WGPUTextureViewDimension
-> CBool
-> WGPUTextureBindingLayout
WGPUTextureBindingLayout.WGPUTextureBindingLayout
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
sampleType :: WGPUTextureSampleType
sampleType = WGPUTextureSampleType
forall a. (Eq a, Num a) => a
WGPUTextureSampleType.Undefined,
viewDimension :: WGPUTextureViewDimension
viewDimension = WGPUTextureViewDimension
forall a. (Eq a, Num a) => a
WGPUTextureViewDimension.Undefined,
multisampled :: CBool
multisampled = Word8 -> CBool
CBool Word8
0
}
noStorageTexture :: WGPUStorageTextureBindingLayout
noStorageTexture :: WGPUStorageTextureBindingLayout
noStorageTexture =
WGPUStorageTextureBindingLayout :: Ptr WGPUChainedStruct
-> WGPUStorageTextureAccess
-> WGPUTextureFormat
-> WGPUTextureViewDimension
-> WGPUStorageTextureBindingLayout
WGPUStorageTextureBindingLayout.WGPUStorageTextureBindingLayout
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
access :: WGPUStorageTextureAccess
access = WGPUStorageTextureAccess
forall a. (Eq a, Num a) => a
WGPUStorageTextureAccess.Undefined,
format :: WGPUTextureFormat
format = WGPUTextureFormat
forall a. (Eq a, Num a) => a
WGPUTextureFormat.Undefined,
viewDimension :: WGPUTextureViewDimension
viewDimension = WGPUTextureViewDimension
forall a. (Eq a, Num a) => a
WGPUTextureViewDimension.Undefined
}
newtype Binding = Binding {Binding -> Word32
unBinding :: Word32} deriving (Binding -> Binding -> Bool
(Binding -> Binding -> Bool)
-> (Binding -> Binding -> Bool) -> Eq Binding
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Binding -> Binding -> Bool
$c/= :: Binding -> Binding -> Bool
== :: Binding -> Binding -> Bool
$c== :: Binding -> Binding -> Bool
Eq, Integer -> Binding
Binding -> Binding
Binding -> Binding -> Binding
(Binding -> Binding -> Binding)
-> (Binding -> Binding -> Binding)
-> (Binding -> Binding -> Binding)
-> (Binding -> Binding)
-> (Binding -> Binding)
-> (Binding -> Binding)
-> (Integer -> Binding)
-> Num Binding
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> Binding
$cfromInteger :: Integer -> Binding
signum :: Binding -> Binding
$csignum :: Binding -> Binding
abs :: Binding -> Binding
$cabs :: Binding -> Binding
negate :: Binding -> Binding
$cnegate :: Binding -> Binding
* :: Binding -> Binding -> Binding
$c* :: Binding -> Binding -> Binding
- :: Binding -> Binding -> Binding
$c- :: Binding -> Binding -> Binding
+ :: Binding -> Binding -> Binding
$c+ :: Binding -> Binding -> Binding
Num, Int -> Binding -> ShowS
[Binding] -> ShowS
Binding -> String
(Int -> Binding -> ShowS)
-> (Binding -> String) -> ([Binding] -> ShowS) -> Show Binding
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Binding] -> ShowS
$cshowList :: [Binding] -> ShowS
show :: Binding -> String
$cshow :: Binding -> String
showsPrec :: Int -> Binding -> ShowS
$cshowsPrec :: Int -> Binding -> ShowS
Show)
instance ToRaw Binding Word32 where
raw :: Binding -> ContT r IO Word32
raw = Word32 -> ContT r IO Word32
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Word32 -> ContT r IO Word32)
-> (Binding -> Word32) -> Binding -> ContT r IO Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Binding -> Word32
unBinding
data ShaderStage = ShaderStage
{
ShaderStage -> Bool
stageVertex :: !Bool,
ShaderStage -> Bool
stageFragment :: !Bool,
ShaderStage -> Bool
stageCompute :: !Bool
}
deriving (ShaderStage -> ShaderStage -> Bool
(ShaderStage -> ShaderStage -> Bool)
-> (ShaderStage -> ShaderStage -> Bool) -> Eq ShaderStage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ShaderStage -> ShaderStage -> Bool
$c/= :: ShaderStage -> ShaderStage -> Bool
== :: ShaderStage -> ShaderStage -> Bool
$c== :: ShaderStage -> ShaderStage -> Bool
Eq, Int -> ShaderStage -> ShowS
[ShaderStage] -> ShowS
ShaderStage -> String
(Int -> ShaderStage -> ShowS)
-> (ShaderStage -> String)
-> ([ShaderStage] -> ShowS)
-> Show ShaderStage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShaderStage] -> ShowS
$cshowList :: [ShaderStage] -> ShowS
show :: ShaderStage -> String
$cshow :: ShaderStage -> String
showsPrec :: Int -> ShaderStage -> ShowS
$cshowsPrec :: Int -> ShaderStage -> ShowS
Show)
instance ToRaw ShaderStage WGPUShaderStageFlags where
raw :: ShaderStage -> ContT r IO Word32
raw ShaderStage {Bool
stageCompute :: Bool
stageFragment :: Bool
stageVertex :: Bool
stageCompute :: ShaderStage -> Bool
stageFragment :: ShaderStage -> Bool
stageVertex :: ShaderStage -> Bool
..} =
Word32 -> ContT r IO Word32
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Word32 -> ContT r IO Word32) -> Word32 -> ContT r IO Word32
forall a b. (a -> b) -> a -> b
$
(if Bool
stageVertex then Word32
forall a. (Eq a, Num a) => a
WGPUShaderStage.Vertex else Word32
0)
Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|. (if Bool
stageFragment then Word32
forall a. (Eq a, Num a) => a
WGPUShaderStage.Fragment else Word32
0)
Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|. (if Bool
stageCompute then Word32
forall a. (Eq a, Num a) => a
WGPUShaderStage.Compute else Word32
0)
instance Default ShaderStage where
def :: ShaderStage
def =
ShaderStage :: Bool -> Bool -> Bool -> ShaderStage
ShaderStage
{ stageVertex :: Bool
stageVertex = Bool
False,
stageFragment :: Bool
stageFragment = Bool
False,
stageCompute :: Bool
stageCompute = Bool
False
}
data BindingType
=
BindingTypeBuffer !BufferBindingLayout
|
BindingTypeSampler !SamplerBindingLayout
|
BindingTypeTexture !TextureBindingLayout
|
BindingTypeStorageTexture !StorageTextureBindingLayout
deriving (BindingType -> BindingType -> Bool
(BindingType -> BindingType -> Bool)
-> (BindingType -> BindingType -> Bool) -> Eq BindingType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BindingType -> BindingType -> Bool
$c/= :: BindingType -> BindingType -> Bool
== :: BindingType -> BindingType -> Bool
$c== :: BindingType -> BindingType -> Bool
Eq, Int -> BindingType -> ShowS
[BindingType] -> ShowS
BindingType -> String
(Int -> BindingType -> ShowS)
-> (BindingType -> String)
-> ([BindingType] -> ShowS)
-> Show BindingType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BindingType] -> ShowS
$cshowList :: [BindingType] -> ShowS
show :: BindingType -> String
$cshow :: BindingType -> String
showsPrec :: Int -> BindingType -> ShowS
$cshowsPrec :: Int -> BindingType -> ShowS
Show)
data BufferBindingLayout = BufferBindingLayout
{
BufferBindingLayout -> BufferBindingType
bindingBufferLayoutType :: !BufferBindingType,
BufferBindingLayout -> Bool
hasDynamicOffset :: !Bool,
BufferBindingLayout -> SMaybe Word64
minBindingSize :: !(SMaybe Word64)
}
deriving (BufferBindingLayout -> BufferBindingLayout -> Bool
(BufferBindingLayout -> BufferBindingLayout -> Bool)
-> (BufferBindingLayout -> BufferBindingLayout -> Bool)
-> Eq BufferBindingLayout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BufferBindingLayout -> BufferBindingLayout -> Bool
$c/= :: BufferBindingLayout -> BufferBindingLayout -> Bool
== :: BufferBindingLayout -> BufferBindingLayout -> Bool
$c== :: BufferBindingLayout -> BufferBindingLayout -> Bool
Eq, Int -> BufferBindingLayout -> ShowS
[BufferBindingLayout] -> ShowS
BufferBindingLayout -> String
(Int -> BufferBindingLayout -> ShowS)
-> (BufferBindingLayout -> String)
-> ([BufferBindingLayout] -> ShowS)
-> Show BufferBindingLayout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BufferBindingLayout] -> ShowS
$cshowList :: [BufferBindingLayout] -> ShowS
show :: BufferBindingLayout -> String
$cshow :: BufferBindingLayout -> String
showsPrec :: Int -> BufferBindingLayout -> ShowS
$cshowsPrec :: Int -> BufferBindingLayout -> ShowS
Show)
instance ToRaw BufferBindingLayout WGPUBufferBindingLayout where
raw :: BufferBindingLayout -> ContT r IO WGPUBufferBindingLayout
raw BufferBindingLayout {Bool
SMaybe Word64
BufferBindingType
minBindingSize :: SMaybe Word64
hasDynamicOffset :: Bool
bindingBufferLayoutType :: BufferBindingType
minBindingSize :: BufferBindingLayout -> SMaybe Word64
hasDynamicOffset :: BufferBindingLayout -> Bool
bindingBufferLayoutType :: BufferBindingLayout -> BufferBindingType
..} = do
WGPUBufferBindingType
n_typ <- BufferBindingType -> ContT r IO WGPUBufferBindingType
forall a b r. ToRaw a b => a -> ContT r IO b
raw BufferBindingType
bindingBufferLayoutType
CBool
n_hasDynamicOffset <- Bool -> ContT r IO CBool
forall a b r. ToRaw a b => a -> ContT r IO b
raw Bool
hasDynamicOffset
WGPUBufferBindingLayout -> ContT r IO WGPUBufferBindingLayout
forall (f :: * -> *) a. Applicative f => a -> f a
pure
WGPUBufferBindingLayout :: Ptr WGPUChainedStruct
-> WGPUBufferBindingType
-> CBool
-> Word64
-> WGPUBufferBindingLayout
WGPUBufferBindingLayout.WGPUBufferBindingLayout
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
typ :: WGPUBufferBindingType
typ = WGPUBufferBindingType
n_typ,
hasDynamicOffset :: CBool
hasDynamicOffset = CBool
n_hasDynamicOffset,
minBindingSize :: Word64
minBindingSize = Word64 -> SMaybe Word64 -> Word64
forall a. a -> SMaybe a -> a
fromSMaybe Word64
0 SMaybe Word64
minBindingSize
}
data SamplerBindingLayout
= SamplerBindingLayoutFiltering
| SamplerBindingLayoutNonFiltering
| SamplerBindingLayoutComparison
deriving (SamplerBindingLayout -> SamplerBindingLayout -> Bool
(SamplerBindingLayout -> SamplerBindingLayout -> Bool)
-> (SamplerBindingLayout -> SamplerBindingLayout -> Bool)
-> Eq SamplerBindingLayout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SamplerBindingLayout -> SamplerBindingLayout -> Bool
$c/= :: SamplerBindingLayout -> SamplerBindingLayout -> Bool
== :: SamplerBindingLayout -> SamplerBindingLayout -> Bool
$c== :: SamplerBindingLayout -> SamplerBindingLayout -> Bool
Eq, Int -> SamplerBindingLayout -> ShowS
[SamplerBindingLayout] -> ShowS
SamplerBindingLayout -> String
(Int -> SamplerBindingLayout -> ShowS)
-> (SamplerBindingLayout -> String)
-> ([SamplerBindingLayout] -> ShowS)
-> Show SamplerBindingLayout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SamplerBindingLayout] -> ShowS
$cshowList :: [SamplerBindingLayout] -> ShowS
show :: SamplerBindingLayout -> String
$cshow :: SamplerBindingLayout -> String
showsPrec :: Int -> SamplerBindingLayout -> ShowS
$cshowsPrec :: Int -> SamplerBindingLayout -> ShowS
Show)
instance ToRaw SamplerBindingLayout WGPUSamplerBindingLayout where
raw :: SamplerBindingLayout -> ContT r IO WGPUSamplerBindingLayout
raw SamplerBindingLayout
sbl =
WGPUSamplerBindingLayout -> ContT r IO WGPUSamplerBindingLayout
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUSamplerBindingLayout -> ContT r IO WGPUSamplerBindingLayout)
-> WGPUSamplerBindingLayout -> ContT r IO WGPUSamplerBindingLayout
forall a b. (a -> b) -> a -> b
$
WGPUSamplerBindingLayout :: Ptr WGPUChainedStruct
-> WGPUSamplerBindingType -> WGPUSamplerBindingLayout
WGPUSamplerBindingLayout.WGPUSamplerBindingLayout
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
typ :: WGPUSamplerBindingType
typ =
case SamplerBindingLayout
sbl of
SamplerBindingLayout
SamplerBindingLayoutFiltering ->
WGPUSamplerBindingType
forall a. (Eq a, Num a) => a
WGPUSamplerBindingType.Filtering
SamplerBindingLayout
SamplerBindingLayoutNonFiltering ->
WGPUSamplerBindingType
forall a. (Eq a, Num a) => a
WGPUSamplerBindingType.NonFiltering
SamplerBindingLayout
SamplerBindingLayoutComparison ->
WGPUSamplerBindingType
forall a. (Eq a, Num a) => a
WGPUSamplerBindingType.Comparison
}
data TextureBindingLayout = TextureBindingLayout
{
TextureBindingLayout -> TextureSampleType
sampleType :: !TextureSampleType,
TextureBindingLayout -> TextureViewDimension
textureBindingViewDimension :: !TextureViewDimension,
TextureBindingLayout -> Bool
multiSampled :: !Bool
}
deriving (TextureBindingLayout -> TextureBindingLayout -> Bool
(TextureBindingLayout -> TextureBindingLayout -> Bool)
-> (TextureBindingLayout -> TextureBindingLayout -> Bool)
-> Eq TextureBindingLayout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TextureBindingLayout -> TextureBindingLayout -> Bool
$c/= :: TextureBindingLayout -> TextureBindingLayout -> Bool
== :: TextureBindingLayout -> TextureBindingLayout -> Bool
$c== :: TextureBindingLayout -> TextureBindingLayout -> Bool
Eq, Int -> TextureBindingLayout -> ShowS
[TextureBindingLayout] -> ShowS
TextureBindingLayout -> String
(Int -> TextureBindingLayout -> ShowS)
-> (TextureBindingLayout -> String)
-> ([TextureBindingLayout] -> ShowS)
-> Show TextureBindingLayout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TextureBindingLayout] -> ShowS
$cshowList :: [TextureBindingLayout] -> ShowS
show :: TextureBindingLayout -> String
$cshow :: TextureBindingLayout -> String
showsPrec :: Int -> TextureBindingLayout -> ShowS
$cshowsPrec :: Int -> TextureBindingLayout -> ShowS
Show)
instance ToRaw TextureBindingLayout WGPUTextureBindingLayout where
raw :: TextureBindingLayout -> ContT r IO WGPUTextureBindingLayout
raw TextureBindingLayout {Bool
TextureViewDimension
TextureSampleType
multiSampled :: Bool
textureBindingViewDimension :: TextureViewDimension
sampleType :: TextureSampleType
multiSampled :: TextureBindingLayout -> Bool
textureBindingViewDimension :: TextureBindingLayout -> TextureViewDimension
sampleType :: TextureBindingLayout -> TextureSampleType
..} = do
WGPUTextureSampleType
n_sampleType <- TextureSampleType -> ContT r IO WGPUTextureSampleType
forall a b r. ToRaw a b => a -> ContT r IO b
raw TextureSampleType
sampleType
WGPUTextureViewDimension
n_viewDimension <- TextureViewDimension -> ContT r IO WGPUTextureViewDimension
forall a b r. ToRaw a b => a -> ContT r IO b
raw TextureViewDimension
textureBindingViewDimension
CBool
n_multisampled <- Bool -> ContT r IO CBool
forall a b r. ToRaw a b => a -> ContT r IO b
raw Bool
multiSampled
WGPUTextureBindingLayout -> ContT r IO WGPUTextureBindingLayout
forall (f :: * -> *) a. Applicative f => a -> f a
pure
WGPUTextureBindingLayout :: Ptr WGPUChainedStruct
-> WGPUTextureSampleType
-> WGPUTextureViewDimension
-> CBool
-> WGPUTextureBindingLayout
WGPUTextureBindingLayout.WGPUTextureBindingLayout
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
sampleType :: WGPUTextureSampleType
sampleType = WGPUTextureSampleType
n_sampleType,
viewDimension :: WGPUTextureViewDimension
viewDimension = WGPUTextureViewDimension
n_viewDimension,
multisampled :: CBool
multisampled = CBool
n_multisampled
}
data StorageTextureBindingLayout = StorageTextureBindingLayout
{
StorageTextureBindingLayout -> StorageTextureAccess
access :: !StorageTextureAccess,
StorageTextureBindingLayout -> TextureFormat
storageTextureFormat :: !TextureFormat,
StorageTextureBindingLayout -> TextureViewDimension
storageTextureViewDimension :: !TextureViewDimension
}
deriving (StorageTextureBindingLayout -> StorageTextureBindingLayout -> Bool
(StorageTextureBindingLayout
-> StorageTextureBindingLayout -> Bool)
-> (StorageTextureBindingLayout
-> StorageTextureBindingLayout -> Bool)
-> Eq StorageTextureBindingLayout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StorageTextureBindingLayout -> StorageTextureBindingLayout -> Bool
$c/= :: StorageTextureBindingLayout -> StorageTextureBindingLayout -> Bool
== :: StorageTextureBindingLayout -> StorageTextureBindingLayout -> Bool
$c== :: StorageTextureBindingLayout -> StorageTextureBindingLayout -> Bool
Eq, Int -> StorageTextureBindingLayout -> ShowS
[StorageTextureBindingLayout] -> ShowS
StorageTextureBindingLayout -> String
(Int -> StorageTextureBindingLayout -> ShowS)
-> (StorageTextureBindingLayout -> String)
-> ([StorageTextureBindingLayout] -> ShowS)
-> Show StorageTextureBindingLayout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StorageTextureBindingLayout] -> ShowS
$cshowList :: [StorageTextureBindingLayout] -> ShowS
show :: StorageTextureBindingLayout -> String
$cshow :: StorageTextureBindingLayout -> String
showsPrec :: Int -> StorageTextureBindingLayout -> ShowS
$cshowsPrec :: Int -> StorageTextureBindingLayout -> ShowS
Show)
instance ToRaw StorageTextureBindingLayout WGPUStorageTextureBindingLayout where
raw :: StorageTextureBindingLayout
-> ContT r IO WGPUStorageTextureBindingLayout
raw StorageTextureBindingLayout {TextureFormat
TextureViewDimension
StorageTextureAccess
storageTextureViewDimension :: TextureViewDimension
storageTextureFormat :: TextureFormat
access :: StorageTextureAccess
storageTextureViewDimension :: StorageTextureBindingLayout -> TextureViewDimension
storageTextureFormat :: StorageTextureBindingLayout -> TextureFormat
access :: StorageTextureBindingLayout -> StorageTextureAccess
..} = do
WGPUStorageTextureAccess
n_access <- StorageTextureAccess -> ContT r IO WGPUStorageTextureAccess
forall a b r. ToRaw a b => a -> ContT r IO b
raw StorageTextureAccess
access
WGPUTextureFormat
n_format <- TextureFormat -> ContT r IO WGPUTextureFormat
forall a b r. ToRaw a b => a -> ContT r IO b
raw TextureFormat
storageTextureFormat
WGPUTextureViewDimension
n_viewDimension <- TextureViewDimension -> ContT r IO WGPUTextureViewDimension
forall a b r. ToRaw a b => a -> ContT r IO b
raw TextureViewDimension
storageTextureViewDimension
WGPUStorageTextureBindingLayout
-> ContT r IO WGPUStorageTextureBindingLayout
forall (f :: * -> *) a. Applicative f => a -> f a
pure
WGPUStorageTextureBindingLayout :: Ptr WGPUChainedStruct
-> WGPUStorageTextureAccess
-> WGPUTextureFormat
-> WGPUTextureViewDimension
-> WGPUStorageTextureBindingLayout
WGPUStorageTextureBindingLayout.WGPUStorageTextureBindingLayout
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
access :: WGPUStorageTextureAccess
access = WGPUStorageTextureAccess
n_access,
format :: WGPUTextureFormat
format = WGPUTextureFormat
n_format,
viewDimension :: WGPUTextureViewDimension
viewDimension = WGPUTextureViewDimension
n_viewDimension
}
data StorageTextureAccess
= StorageTextureAccessReadOnly
| StorageTextureAccessWriteOnly
| StorageTextureAccessReadWrite
deriving (StorageTextureAccess -> StorageTextureAccess -> Bool
(StorageTextureAccess -> StorageTextureAccess -> Bool)
-> (StorageTextureAccess -> StorageTextureAccess -> Bool)
-> Eq StorageTextureAccess
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StorageTextureAccess -> StorageTextureAccess -> Bool
$c/= :: StorageTextureAccess -> StorageTextureAccess -> Bool
== :: StorageTextureAccess -> StorageTextureAccess -> Bool
$c== :: StorageTextureAccess -> StorageTextureAccess -> Bool
Eq, Int -> StorageTextureAccess -> ShowS
[StorageTextureAccess] -> ShowS
StorageTextureAccess -> String
(Int -> StorageTextureAccess -> ShowS)
-> (StorageTextureAccess -> String)
-> ([StorageTextureAccess] -> ShowS)
-> Show StorageTextureAccess
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StorageTextureAccess] -> ShowS
$cshowList :: [StorageTextureAccess] -> ShowS
show :: StorageTextureAccess -> String
$cshow :: StorageTextureAccess -> String
showsPrec :: Int -> StorageTextureAccess -> ShowS
$cshowsPrec :: Int -> StorageTextureAccess -> ShowS
Show)
instance ToRaw StorageTextureAccess WGPUStorageTextureAccess where
raw :: StorageTextureAccess -> ContT r IO WGPUStorageTextureAccess
raw StorageTextureAccess
sta =
WGPUStorageTextureAccess -> ContT r IO WGPUStorageTextureAccess
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUStorageTextureAccess -> ContT r IO WGPUStorageTextureAccess)
-> WGPUStorageTextureAccess -> ContT r IO WGPUStorageTextureAccess
forall a b. (a -> b) -> a -> b
$
case StorageTextureAccess
sta of
StorageTextureAccess
StorageTextureAccessReadOnly -> WGPUStorageTextureAccess
forall a. (Eq a, Num a) => a
WGPUStorageTextureAccess.ReadOnly
StorageTextureAccess
StorageTextureAccessWriteOnly -> WGPUStorageTextureAccess
forall a. (Eq a, Num a) => a
WGPUStorageTextureAccess.WriteOnly
StorageTextureAccess
StorageTextureAccessReadWrite -> WGPUStorageTextureAccess
forall a. (Eq a, Num a) => a
WGPUStorageTextureAccess.Undefined
data TextureSampleType
= TextureSampleTypeFloat {TextureSampleType -> Bool
filterable :: !Bool}
| TextureSampleTypeDepth
| TextureSampleTypeSignedInt
| TextureSampleTypeUnsignedInt
deriving (TextureSampleType -> TextureSampleType -> Bool
(TextureSampleType -> TextureSampleType -> Bool)
-> (TextureSampleType -> TextureSampleType -> Bool)
-> Eq TextureSampleType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TextureSampleType -> TextureSampleType -> Bool
$c/= :: TextureSampleType -> TextureSampleType -> Bool
== :: TextureSampleType -> TextureSampleType -> Bool
$c== :: TextureSampleType -> TextureSampleType -> Bool
Eq, Int -> TextureSampleType -> ShowS
[TextureSampleType] -> ShowS
TextureSampleType -> String
(Int -> TextureSampleType -> ShowS)
-> (TextureSampleType -> String)
-> ([TextureSampleType] -> ShowS)
-> Show TextureSampleType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TextureSampleType] -> ShowS
$cshowList :: [TextureSampleType] -> ShowS
show :: TextureSampleType -> String
$cshow :: TextureSampleType -> String
showsPrec :: Int -> TextureSampleType -> ShowS
$cshowsPrec :: Int -> TextureSampleType -> ShowS
Show)
instance ToRaw TextureSampleType WGPUTextureSampleType where
raw :: TextureSampleType -> ContT r IO WGPUTextureSampleType
raw TextureSampleType
tt =
WGPUTextureSampleType -> ContT r IO WGPUTextureSampleType
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUTextureSampleType -> ContT r IO WGPUTextureSampleType)
-> WGPUTextureSampleType -> ContT r IO WGPUTextureSampleType
forall a b. (a -> b) -> a -> b
$
case TextureSampleType
tt of
TextureSampleTypeFloat Bool
False -> WGPUTextureSampleType
forall a. (Eq a, Num a) => a
WGPUTextureSampleType.UnfilterableFloat
TextureSampleTypeFloat Bool
True -> WGPUTextureSampleType
forall a. (Eq a, Num a) => a
WGPUTextureSampleType.Float
TextureSampleType
TextureSampleTypeDepth -> WGPUTextureSampleType
forall a. (Eq a, Num a) => a
WGPUTextureSampleType.Depth
TextureSampleType
TextureSampleTypeSignedInt -> WGPUTextureSampleType
forall a. (Eq a, Num a) => a
WGPUTextureSampleType.Sint
TextureSampleType
TextureSampleTypeUnsignedInt -> WGPUTextureSampleType
forall a. (Eq a, Num a) => a
WGPUTextureSampleType.Uint
data BufferBindingType
= Uniform
| Storage {BufferBindingType -> Bool
readOnly :: !Bool}
deriving (BufferBindingType -> BufferBindingType -> Bool
(BufferBindingType -> BufferBindingType -> Bool)
-> (BufferBindingType -> BufferBindingType -> Bool)
-> Eq BufferBindingType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BufferBindingType -> BufferBindingType -> Bool
$c/= :: BufferBindingType -> BufferBindingType -> Bool
== :: BufferBindingType -> BufferBindingType -> Bool
$c== :: BufferBindingType -> BufferBindingType -> Bool
Eq, Int -> BufferBindingType -> ShowS
[BufferBindingType] -> ShowS
BufferBindingType -> String
(Int -> BufferBindingType -> ShowS)
-> (BufferBindingType -> String)
-> ([BufferBindingType] -> ShowS)
-> Show BufferBindingType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BufferBindingType] -> ShowS
$cshowList :: [BufferBindingType] -> ShowS
show :: BufferBindingType -> String
$cshow :: BufferBindingType -> String
showsPrec :: Int -> BufferBindingType -> ShowS
$cshowsPrec :: Int -> BufferBindingType -> ShowS
Show)
instance ToRaw BufferBindingType WGPUBufferBindingType where
raw :: BufferBindingType -> ContT r IO WGPUBufferBindingType
raw BufferBindingType
bt =
WGPUBufferBindingType -> ContT r IO WGPUBufferBindingType
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUBufferBindingType -> ContT r IO WGPUBufferBindingType)
-> WGPUBufferBindingType -> ContT r IO WGPUBufferBindingType
forall a b. (a -> b) -> a -> b
$
case BufferBindingType
bt of
BufferBindingType
Uniform -> WGPUBufferBindingType
forall a. (Eq a, Num a) => a
WGPUBufferBindingType.Uniform
Storage Bool
False -> WGPUBufferBindingType
forall a. (Eq a, Num a) => a
WGPUBufferBindingType.Storage
Storage Bool
True -> WGPUBufferBindingType
forall a. (Eq a, Num a) => a
WGPUBufferBindingType.ReadOnlyStorage
createBindGroup ::
MonadIO m =>
Device ->
BindGroupDescriptor ->
m BindGroup
createBindGroup :: Device -> BindGroupDescriptor -> m BindGroup
createBindGroup Device
device BindGroupDescriptor
bindGroupDescriptor = IO BindGroup -> m BindGroup
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO BindGroup -> m BindGroup)
-> (ContT BindGroup IO BindGroup -> IO BindGroup)
-> ContT BindGroup IO BindGroup
-> m BindGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT BindGroup IO BindGroup -> IO BindGroup
forall (m :: * -> *) a. Monad m => ContT a m a -> m a
evalContT (ContT BindGroup IO BindGroup -> m BindGroup)
-> ContT BindGroup IO BindGroup -> m BindGroup
forall a b. (a -> b) -> a -> b
$ do
let inst :: Instance
inst = Device -> Instance
deviceInst Device
device
Ptr WGPUBindGroupDescriptor
bindGroupDescriptor_ptr <- BindGroupDescriptor
-> ContT BindGroup IO (Ptr WGPUBindGroupDescriptor)
forall a b r. ToRawPtr a b => a -> ContT r IO (Ptr b)
rawPtr BindGroupDescriptor
bindGroupDescriptor
WGPUBindGroup -> BindGroup
BindGroup
(WGPUBindGroup -> BindGroup)
-> ContT BindGroup IO WGPUBindGroup -> ContT BindGroup IO BindGroup
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WGPUHsInstance
-> WGPUDevice
-> Ptr WGPUBindGroupDescriptor
-> ContT BindGroup IO WGPUBindGroup
forall (m :: * -> *).
MonadIO m =>
WGPUHsInstance
-> WGPUDevice -> Ptr WGPUBindGroupDescriptor -> m WGPUBindGroup
RawFun.wgpuDeviceCreateBindGroup
(Instance -> WGPUHsInstance
wgpuHsInstance Instance
inst)
(Device -> WGPUDevice
wgpuDevice Device
device)
Ptr WGPUBindGroupDescriptor
bindGroupDescriptor_ptr
createBindGroupLayout ::
MonadIO m =>
Device ->
BindGroupLayoutDescriptor ->
m BindGroupLayout
createBindGroupLayout :: Device -> BindGroupLayoutDescriptor -> m BindGroupLayout
createBindGroupLayout Device
device BindGroupLayoutDescriptor
ld = IO BindGroupLayout -> m BindGroupLayout
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO BindGroupLayout -> m BindGroupLayout)
-> (ContT BindGroupLayout IO BindGroupLayout -> IO BindGroupLayout)
-> ContT BindGroupLayout IO BindGroupLayout
-> m BindGroupLayout
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT BindGroupLayout IO BindGroupLayout -> IO BindGroupLayout
forall (m :: * -> *) a. Monad m => ContT a m a -> m a
evalContT (ContT BindGroupLayout IO BindGroupLayout -> m BindGroupLayout)
-> ContT BindGroupLayout IO BindGroupLayout -> m BindGroupLayout
forall a b. (a -> b) -> a -> b
$ do
let inst :: Instance
inst = Device -> Instance
deviceInst Device
device
Ptr WGPUBindGroupLayoutDescriptor
bindGroupLayoutDescriptor_ptr <- BindGroupLayoutDescriptor
-> ContT BindGroupLayout IO (Ptr WGPUBindGroupLayoutDescriptor)
forall a b r. ToRawPtr a b => a -> ContT r IO (Ptr b)
rawPtr BindGroupLayoutDescriptor
ld
WGPUBindGroupLayout
rawBindGroupLayout <-
WGPUHsInstance
-> WGPUDevice
-> Ptr WGPUBindGroupLayoutDescriptor
-> ContT BindGroupLayout IO WGPUBindGroupLayout
forall (m :: * -> *).
MonadIO m =>
WGPUHsInstance
-> WGPUDevice
-> Ptr WGPUBindGroupLayoutDescriptor
-> m WGPUBindGroupLayout
RawFun.wgpuDeviceCreateBindGroupLayout
(Instance -> WGPUHsInstance
wgpuHsInstance Instance
inst)
(Device -> WGPUDevice
wgpuDevice Device
device)
Ptr WGPUBindGroupLayoutDescriptor
bindGroupLayoutDescriptor_ptr
BindGroupLayout -> ContT BindGroupLayout IO BindGroupLayout
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUBindGroupLayout -> BindGroupLayout
BindGroupLayout WGPUBindGroupLayout
rawBindGroupLayout)