Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module is not part of auto-generated code based on vk.xml. Instead, it is hand-written to provide common types and classes.
DANGER! This is an internal module; it can change a lot between package versions; it provides low-level functions, most of which have user-friendly analogues.
Synopsis
- data VkStruct a = VkStruct {}
- unsafeFromByteArrayOffset :: Int# -> ByteArray# -> VkStruct a
- class (VulkanStruct (StructRep a), IsVkStruct a) => VulkanMarshal a where
- type StructRep a :: StructMeta
- newVkData :: forall a. VulkanMarshal a => (Ptr a -> IO ()) -> IO a
- mallocVkData :: forall a. VulkanMarshal a => IO a
- mallocVkDataArray :: forall a. VulkanMarshal a => Int -> IO (Ptr a, [a])
- unsafePtr :: IsVkStruct a => a -> Ptr a
- fromForeignPtr :: forall a. VulkanMarshal a => ForeignPtr a -> IO a
- toForeignPtr :: IsVkStruct a => a -> IO (ForeignPtr a)
- toPlainForeignPtr :: IsVkStruct a => a -> IO (ForeignPtr a)
- touchVkData :: IsVkStruct a => a -> IO ()
- type StructFields a = SFields (StructRep a)
- type CUnionType a = SIsUnion (StructRep a)
- type ReturnedOnly a = SIsReturnedOnly (StructRep a)
- type StructExtends a = SStructExtends (StructRep a)
- type StructFieldNames (a :: Type) = FieldNames (StructFields a)
- type HasField (fname :: Symbol) (a :: Type) = (VulkanMarshal a, VulkanField (FieldRep fname a))
- type FieldRep (fname :: Symbol) (a :: Type) = GetFieldMeta (ErrorNoSuchField fname a) fname (StructFields a)
- type FieldType (fname :: Symbol) (a :: Type) = FType (FieldRep fname a)
- type FieldOptional (fname :: Symbol) (a :: Type) = FOptional (FieldRep fname a)
- type FieldOffset (fname :: Symbol) (a :: Type) = FByteOffset (FieldRep fname a)
- type FieldIsArray (fname :: Symbol) (a :: Type) = IsArrayLen (FLength (FieldRep fname a))
- type FieldArrayLength (fname :: Symbol) (a :: Type) = FLength (FieldRep fname a)
- type CanReadField (fname :: Symbol) (a :: Type) = (HasField fname a, IsTrue (ErrorNotReadableField fname a) (FCanRead (FieldRep fname a)), Storable (FieldType fname a))
- type CanWriteField (fname :: Symbol) (a :: Type) = (HasField fname a, IsTrue (ErrorNotWritableField fname a) (FCanWrite (FieldRep fname a)), Storable (FieldType fname a))
- type CanReadFieldArray (fname :: Symbol) (a :: Type) = CanReadField fname a
- type CanWriteFieldArray (fname :: Symbol) (a :: Type) = CanWriteField fname a
- fieldOptional :: forall (fname :: Symbol) (a :: Type). HasField fname a => Bool
- fieldOffset :: forall (fname :: Symbol) (a :: Type). HasField fname a => Int
- fieldArrayLength :: forall (fname :: Symbol) (a :: Type). HasField fname a => Int
- getField :: forall (fname :: Symbol) (a :: Type). CanReadField fname a => a -> FieldType fname a
- readField :: forall (fname :: Symbol) (a :: Type). CanReadField fname a => Ptr a -> IO (FieldType fname a)
- writeField :: forall (fname :: Symbol) (a :: Type). CanWriteField fname a => Ptr a -> FieldType fname a -> IO ()
- getFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanReadFieldArray fname a => Int -> a -> FieldType fname a
- readFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanReadFieldArray fname a => Int -> Ptr a -> IO (FieldType fname a)
- writeFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanWriteFieldArray fname a => Int -> Ptr a -> FieldType fname a -> IO ()
- getFieldArray :: forall fname idx a. (CanReadFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => a -> FieldType fname a
- readFieldArray :: forall fname idx a. (CanReadFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => Ptr a -> IO (FieldType fname a)
- writeFieldArray :: forall fname idx a. (CanWriteFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => Ptr a -> FieldType fname a -> IO ()
- type IndexInBounds (s :: Symbol) (i :: Nat) (a :: Type) = IndexInBounds' s i a (CmpNat i (FieldArrayLength s a))
- class VulkanFields (SFields m) => VulkanStruct (m :: StructMeta) where
- class (Show (FType m), Storable (FType m)) => VulkanField (m :: FieldMeta) where
- class VulkanFields (ms :: [FieldMeta]) where
- withField :: forall (fname :: Symbol) (r :: Type) (errMsg :: ErrorMessage). KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname ms) => r) -> r
- enumerateFields :: forall (a :: Type). (forall (m :: FieldMeta). VulkanField m => Proxy# m -> a -> a) -> a -> a
- class KnownBool (b :: Bool) where
- data FieldMeta = FieldMeta Symbol Type Bool Nat Nat Bool Bool
- data StructMeta = StructMeta Symbol Type Nat Nat [FieldMeta] Bool Bool [Type]
- withCStringField :: forall fname a b. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> (CString -> IO b) -> IO b
- unsafeCStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> CString
- getStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> String
- readStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => Ptr a -> IO String
- writeStringField :: forall fname a. (CanWriteFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => Ptr a -> String -> IO ()
- cmpCStrings :: CString -> CString -> Ordering
- cmpCStringsN :: CString -> CString -> Int -> Ordering
Documentation
Internal representation of all Vulkan structures: a pinned byte array and an address pointing to an area in this array.
VkStruct | |
|
Instances
unsafeFromByteArrayOffset :: Int# -> ByteArray# -> VkStruct a Source #
Combine a vulkan structure from ByteArray and an offset in this array.
class (VulkanStruct (StructRep a), IsVkStruct a) => VulkanMarshal a Source #
All Vulkan structures are stored as-is in byte arrays to avoid any overheads for wrapping and unwrapping haskell values. VulkanMarshal provides an interfaces to write and read these structures in an imperative way.
type StructRep a :: StructMeta Source #
Instances
newVkData :: forall a. VulkanMarshal a => (Ptr a -> IO ()) -> IO a Source #
Allocate a pinned aligned byte array to keep vulkan data structure and fill it using a foreign function.
Note, the function is supposed to use newAlignedPinnedByteArray#
and does not guarantee to fill memory with zeroes.
Use clearStorable
to make sure all bytes are set to zero.
Note, the memory is managed by GHC, thus no need for freeing it manually.
mallocVkData :: forall a. VulkanMarshal a => IO a Source #
Allocate a pinned aligned byte array to keep vulkan data structure.
Note, the function is supposed to use newAlignedPinnedByteArray#
and does not guarantee to fill memory with zeroes.
Use clearStorable
to make sure all bytes are set to zero.
Note, the memory is managed by GHC, thus no need for freeing it manually.
mallocVkDataArray :: forall a. VulkanMarshal a => Int -> IO (Ptr a, [a]) Source #
Allocate a pinned aligned byte array to keep vulkan data structures. Returned `Ptr a` points to the first element in the contiguous array of returned structures. Returned list elements point to the same memory area. This function is unsafe in two ways:
- Several structures are stored next to each other, with no gaps; it would break its alignment if the size is not multiple of alignment.
- Returned pointer is not tracked by GHC as a reference to the managed memory. Thus, the array can be GCed if all references to the returned list are lost.
Note, the function is supposed to use newAlignedPinnedByteArray#
and does not guarantee to fill memory with zeroes.
Use clearStorable
to make sure all bytes are set to zero.
Note, the memory is managed by GHC, thus no need for freeing it manually.
unsafePtr :: IsVkStruct a => a -> Ptr a Source #
Get pointer to vulkan structure. Note, the address is only valid as long as a given vulkan structure exists. Structures created with newVkData are stored in pinned byte arrays, so their memory is maintained by Haskell GC.
fromForeignPtr :: forall a. VulkanMarshal a => ForeignPtr a -> IO a Source #
Get vulkan structure referenced by a ForeignPtr
trying to avoid copying data.
This function does copy data if called on an unmanaged ForeignPtr
(i.e. one created from ordinary Ptr
using something like newForeignPtr
.).
This function does not copy data if called on a managed ForeignPtr
(i.e. one created using mallocForeignPtr
, or toForeignPtr
, or toPlainForeignPtr
).
Note, fromForeignPtr
does not copy finalizers of ForeignPtr
.
Thus, if all references to original ForeignPtr
are lost,
its attached finalizers may run even if the created structure is alive.
toForeignPtr :: IsVkStruct a => a -> IO (ForeignPtr a) Source #
Create a ForeignPtr
referencing the structure without copying data.
toPlainForeignPtr :: IsVkStruct a => a -> IO (ForeignPtr a) Source #
Create a ForeignPtr
referencing the structure without copying data.
This version of a pointer carries no finalizers.
It is not possible to add a finalizer to a ForeignPtr created with
toPlainForeignPtr
.
Attempts to add a finalizer to a ForeignPtr created this way, or to
finalize such a pointer, will throw an exception.
touchVkData :: IsVkStruct a => a -> IO () Source #
Make sure this data is alive at a given point in a sequence of IO actions.
Type-indexed access to struct members
type StructFields a = SFields (StructRep a) Source #
Descriptions of all fields of a vulkan struct
type CUnionType a = SIsUnion (StructRep a) Source #
Whether this type is a C union. Otherwise this is a C structure.
type ReturnedOnly a = SIsReturnedOnly (StructRep a) Source #
Notes that this struct or union is going to be filled in by the API, rather than an application filling it out and passing it to the API.
type StructExtends a = SStructExtends (StructRep a) Source #
Comma-separated list of structures whose "pNext" can include this type.
type StructFieldNames (a :: Type) = FieldNames (StructFields a) Source #
type HasField (fname :: Symbol) (a :: Type) = (VulkanMarshal a, VulkanField (FieldRep fname a)) Source #
A Constraint: a vulkan struct must have a field with a given name.
type FieldRep (fname :: Symbol) (a :: Type) = GetFieldMeta (ErrorNoSuchField fname a) fname (StructFields a) Source #
Type-level description of a Vulkan structure field.
type FieldType (fname :: Symbol) (a :: Type) = FType (FieldRep fname a) Source #
Type of a field in a vulkan structure or union.
type FieldOptional (fname :: Symbol) (a :: Type) = FOptional (FieldRep fname a) Source #
Whether this field marked optional in vulkan specification.
Usually, this means that VK_NULL
can be written in place
of this field.
type FieldOffset (fname :: Symbol) (a :: Type) = FByteOffset (FieldRep fname a) Source #
Offset of a field in bytes.
type FieldIsArray (fname :: Symbol) (a :: Type) = IsArrayLen (FLength (FieldRep fname a)) Source #
Whether this field is a fixed-length array stored directly in a struct.
type FieldArrayLength (fname :: Symbol) (a :: Type) = FLength (FieldRep fname a) Source #
Length of an array that is a field of a structure or union
type CanReadField (fname :: Symbol) (a :: Type) = (HasField fname a, IsTrue (ErrorNotReadableField fname a) (FCanRead (FieldRep fname a)), Storable (FieldType fname a)) Source #
type CanWriteField (fname :: Symbol) (a :: Type) = (HasField fname a, IsTrue (ErrorNotWritableField fname a) (FCanWrite (FieldRep fname a)), Storable (FieldType fname a)) Source #
type CanReadFieldArray (fname :: Symbol) (a :: Type) = CanReadField fname a Source #
type CanWriteFieldArray (fname :: Symbol) (a :: Type) = CanWriteField fname a Source #
fieldOptional :: forall (fname :: Symbol) (a :: Type). HasField fname a => Bool Source #
Whether this field marked optional in vulkan specification.
Usually, this means that VK_NULL
can be written in place
of this field.
fieldOffset :: forall (fname :: Symbol) (a :: Type). HasField fname a => Int Source #
Offset of a field in bytes.
fieldArrayLength :: forall (fname :: Symbol) (a :: Type). HasField fname a => Int Source #
Length of an array that is a field of a structure or union.
Returns 1
if this field is not an array.
getField :: forall (fname :: Symbol) (a :: Type). CanReadField fname a => a -> FieldType fname a Source #
readField :: forall (fname :: Symbol) (a :: Type). CanReadField fname a => Ptr a -> IO (FieldType fname a) Source #
writeField :: forall (fname :: Symbol) (a :: Type). CanWriteField fname a => Ptr a -> FieldType fname a -> IO () Source #
getFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanReadFieldArray fname a => Int -> a -> FieldType fname a Source #
Index an array-type field. No bound checks.
readFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanReadFieldArray fname a => Int -> Ptr a -> IO (FieldType fname a) Source #
Read from an array-type field. No bound checks.
writeFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanWriteFieldArray fname a => Int -> Ptr a -> FieldType fname a -> IO () Source #
Write to an array-type field. No bound checks.
getFieldArray :: forall fname idx a. (CanReadFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => a -> FieldType fname a Source #
readFieldArray :: forall fname idx a. (CanReadFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => Ptr a -> IO (FieldType fname a) Source #
writeFieldArray :: forall fname idx a. (CanWriteFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => Ptr a -> FieldType fname a -> IO () Source #
type IndexInBounds (s :: Symbol) (i :: Nat) (a :: Type) = IndexInBounds' s i a (CmpNat i (FieldArrayLength s a)) Source #
Type-level info about Structs
class VulkanFields (SFields m) => VulkanStruct (m :: StructMeta) where Source #
type SName m :: Symbol Source #
type SFields m :: [FieldMeta] Source #
type SIsUnion m :: Bool Source #
type SIsReturnedOnly m :: Bool Source #
type SStructExtends m :: [Type] Source #
Instances
(KnownSymbol structName, KnownNat size, KnownNat alignment, VulkanFields fields, KnownBool isUnion, KnownBool isReturnedOnly) => VulkanStruct (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal type SName (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Symbol Source # type SType (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Type Source # type SSize (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Nat Source # type SAlign (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Nat Source # type SFields (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: [FieldMeta] Source # type SIsUnion (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Bool Source # type SIsReturnedOnly (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Bool Source # type SStructExtends (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: [Type] Source # |
class (Show (FType m), Storable (FType m)) => VulkanField (m :: FieldMeta) where Source #
type FName m :: Symbol Source #
type FOptional m :: Bool Source #
type FByteOffset m :: Nat Source #
type FLength m :: Nat Source #
fByteOffset :: Int Source #
Instances
(KnownSymbol fieldName, Show t, Storable t, KnownBool optional, KnownNat byteOffset, KnownNat length, KnownBool canRead, KnownBool canWrite) => VulkanField (FieldMeta fieldName t optional byteOffset length canRead canWrite) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal type FName (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Symbol Source # type FType (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Type Source # type FOptional (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Bool Source # type FByteOffset (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Nat Source # type FLength (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Nat Source # type FCanRead (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Bool Source # type FCanWrite (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Bool Source # |
class VulkanFields (ms :: [FieldMeta]) where Source #
withField :: forall (fname :: Symbol) (r :: Type) (errMsg :: ErrorMessage). KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname ms) => r) -> r Source #
enumerateFields :: forall (a :: Type). (forall (m :: FieldMeta). VulkanField m => Proxy# m -> a -> a) -> a -> a Source #
Instances
VulkanFields ([] :: [FieldMeta]) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal withField :: KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname []) -> r) -> r Source # enumerateFields :: (forall (m :: FieldMeta). VulkanField m => Proxy# m -> a -> a) -> a -> a Source # | |
(VulkanField m, VulkanFields ms) => VulkanFields (m ': ms) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal withField :: KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname (m ': ms)) -> r) -> r Source # enumerateFields :: (forall (m0 :: FieldMeta). VulkanField m0 => Proxy# m0 -> a -> a) -> a -> a Source # |
class KnownBool (b :: Bool) where Source #
This class give a term-level boolean associated with a type-level boolean.
The same as KnownNat
for integers.
FieldMeta fieldName fieldType optional byteOffset length canRead canWrite
represents a Vulkan structure field at the type level.
Instances
VulkanFields ([] :: [FieldMeta]) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal withField :: KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname []) -> r) -> r Source # enumerateFields :: (forall (m :: FieldMeta). VulkanField m => Proxy# m -> a -> a) -> a -> a Source # | |
(VulkanField m, VulkanFields ms) => VulkanFields (m ': ms) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal withField :: KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname (m ': ms)) -> r) -> r Source # enumerateFields :: (forall (m0 :: FieldMeta). VulkanField m0 => Proxy# m0 -> a -> a) -> a -> a Source # |
data StructMeta Source #
StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends
represents a Vulkan structure at the type level.
Utilities for string types
withCStringField :: forall fname a b. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> (CString -> IO b) -> IO b Source #
Perform an action on a C string field. The string pointers should not be used outside the callback. It will point to a correct location only as long as the struct is alive.
unsafeCStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> CString Source #
Get pointer to a memory location of the C string field in a structure.
getStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> String Source #
readStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => Ptr a -> IO String Source #
writeStringField :: forall fname a. (CanWriteFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => Ptr a -> String -> IO () Source #