wgpu-hs-0.1.0.0: WGPU
Safe HaskellNone
LanguageHaskell2010

WGPU.Internal.Memory

Description

This module contains type classes used to manage marshalling of objects into memory before calling C functions.

Motivation

In many locations in the API, we have:

A type (example only) which contains a nice Haskell representation of some data:

data ApiType = ApiType { things :: Vector Thing }

and a raw type which is required for a C function:

data WGPUApiType = WGPUApiType
  { thingsCount :: Word8,            -- this is an array length
    things      :: Ptr WGPUApiThing  -- this is a pointer to an array
  }

This type class constraint represents the ability to encode ApiType as WGPUApiType, performing any necessary memory allocation and freeing:

ToRaw ApiType WGPUApiType

ToRaw uses the ContT monad so that bracketing of the memory resources can be performed around some continuation that uses the memory.

In the example above, we could write a ToRaw instance as follows:

instance ToRaw ApiType WGPUApiType where
  raw ApiType{..} = do
    names_ptr <- rawArrayPtr names
    pure $ WGPUApiType
      { namesCount = fromIntegral . length $ names,
        names      = names_ptr
      }

The ToRawPtr type class represents similar functionality, except that it creates a pointer to a value. Thus it does both raw conversion and storing the raw value in allocated memory. It exists as a separate type class so that library types (eg. Text and ByteString) can be marshalled into pointers more easily.

Synopsis

Classes

class ToRaw a b | a -> b where Source #

Represents a value of type a that can be stored as type b in the ContT monad.

Implementations of this type class should bracket any resource management for creating the b value around the continuation. For example. memory to hold elements of b should be allocated and freed in a bracketed fashion.

Methods

raw :: a -> ContT c IO b Source #

Convert a value to a raw representation, bracketing any resource management.

Instances

Instances details
ToRaw Bool CBool Source # 
Instance details

Defined in WGPU.Internal.Memory

Methods

raw :: Bool -> ContT c IO CBool Source #

ToRaw Instance WGPUHsInstance Source # 
Instance details

Defined in WGPU.Internal.Instance

ToRaw CommandBuffer WGPUCommandBuffer Source # 
Instance details

Defined in WGPU.Internal.CommandBuffer

ToRaw Color WGPUColor Source # 
Instance details

Defined in WGPU.Internal.Color

Methods

raw :: Color -> ContT c IO WGPUColor Source #

ToRaw CompareFunction WGPUCompareFunction Source #

Convert a CompareFunction to its raw value.

Instance details

Defined in WGPU.Internal.Multipurpose

ToRaw Surface WGPUSurface Source # 
Instance details

Defined in WGPU.Internal.Surface

ToRaw Adapter WGPUAdapter Source # 
Instance details

Defined in WGPU.Internal.Adapter

ToRaw DeviceDescriptor WGPUDeviceExtras Source # 
Instance details

Defined in WGPU.Internal.Device

ToRaw Features WGPUNativeFeature Source # 
Instance details

Defined in WGPU.Internal.Device

ToRaw Device WGPUDevice Source # 
Instance details

Defined in WGPU.Internal.Device

ToRaw WGSL WGPUShaderModuleWGSLDescriptor Source # 
Instance details

Defined in WGPU.Internal.Shader

ToRaw SPIRV WGPUShaderModuleSPIRVDescriptor Source # 
Instance details

Defined in WGPU.Internal.Shader

ToRaw ShaderModuleDescriptor WGPUShaderModuleDescriptor Source # 
Instance details

Defined in WGPU.Internal.Shader

ToRaw ShaderModule WGPUShaderModule Source # 
Instance details

Defined in WGPU.Internal.Shader

ToRaw Queue WGPUQueue Source # 
Instance details

Defined in WGPU.Internal.Queue

Methods

raw :: Queue -> ContT c IO WGPUQueue Source #

ToRaw CommandEncoder WGPUCommandEncoder Source # 
Instance details

Defined in WGPU.Internal.CommandEncoder

ToRaw TextureFormat WGPUTextureFormat Source # 
Instance details

Defined in WGPU.Internal.Texture

ToRaw TextureUsage WGPUTextureUsage Source # 
Instance details

Defined in WGPU.Internal.Texture

ToRaw TextureViewDimension WGPUTextureViewDimension Source # 
Instance details

Defined in WGPU.Internal.Texture

ToRaw TextureView WGPUTextureView Source # 
Instance details

Defined in WGPU.Internal.Texture

ToRaw PresentMode WGPUPresentMode Source # 
Instance details

Defined in WGPU.Internal.SwapChain

ToRaw SwapChainDescriptor WGPUSwapChainDescriptor Source # 
Instance details

Defined in WGPU.Internal.SwapChain

ToRaw SwapChain WGPUSwapChain Source # 
Instance details

Defined in WGPU.Internal.SwapChain

ToRaw RenderPassDescriptor WGPURenderPassDescriptor Source # 
Instance details

Defined in WGPU.Internal.RenderPass

ToRaw RenderPassDepthStencilAttachment WGPURenderPassDepthStencilAttachment Source # 
Instance details

Defined in WGPU.Internal.RenderPass

ToRaw RenderPassColorAttachment WGPURenderPassColorAttachment Source # 
Instance details

Defined in WGPU.Internal.RenderPass

ToRaw StoreOp WGPUStoreOp Source # 
Instance details

Defined in WGPU.Internal.RenderPass

ToRaw RenderPassEncoder WGPURenderPassEncoder Source # 
Instance details

Defined in WGPU.Internal.RenderPass

ToRaw RenderPipeline WGPURenderPipeline Source # 
Instance details

Defined in WGPU.Internal.RenderPass

ToRaw BufferBindingType WGPUBufferBindingType Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw TextureSampleType WGPUTextureSampleType Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw StorageTextureAccess WGPUStorageTextureAccess Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw StorageTextureBindingLayout WGPUStorageTextureBindingLayout Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw TextureBindingLayout WGPUTextureBindingLayout Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw SamplerBindingLayout WGPUSamplerBindingLayout Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw BufferBindingLayout WGPUBufferBindingLayout Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw ShaderStage WGPUShaderStageFlags Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw Binding Word32 Source # 
Instance details

Defined in WGPU.Internal.Binding

Methods

raw :: Binding -> ContT c IO Word32 Source #

ToRaw BindGroupLayoutEntry WGPUBindGroupLayoutEntry Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw BindGroupLayoutDescriptor WGPUBindGroupLayoutDescriptor Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw BindGroupLayout WGPUBindGroupLayout Source # 
Instance details

Defined in WGPU.Internal.Binding

ToRaw RenderPipelineDescriptor WGPURenderPipelineDescriptor Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw FragmentState WGPUFragmentState Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw ColorTargetState WGPUColorTargetState Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw ColorWriteMask WGPUColorWriteMask Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw BlendState WGPUBlendState Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw BlendComponent WGPUBlendComponent Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw BlendOperation WGPUBlendOperation Source #

Convert a BlendOperation to its raw value.

Instance details

Defined in WGPU.Internal.Pipeline

ToRaw BlendFactor WGPUBlendFactor Source #

Convert a BlendFactor to its raw value.

Instance details

Defined in WGPU.Internal.Pipeline

ToRaw MultisampleState WGPUMultisampleState Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw DepthStencilState WGPUDepthStencilState Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw StencilFaceState WGPUStencilFaceState Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw StencilOperation WGPUStencilOperation Source #

Convert a StencilOperation to its raw value.

Instance details

Defined in WGPU.Internal.Pipeline

ToRaw PrimitiveState WGPUPrimitiveState Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw CullMode WGPUCullMode Source #

Convert a CullMode to its raw value.

Instance details

Defined in WGPU.Internal.Pipeline

ToRaw FrontFace WGPUFrontFace Source #

Convert a FrontFace to its raw value.

Instance details

Defined in WGPU.Internal.Pipeline

ToRaw IndexFormat WGPUIndexFormat Source #

Convert an IndexFormat to its raw value.

Instance details

Defined in WGPU.Internal.Pipeline

ToRaw PrimitiveTopology WGPUPrimitiveTopology Source #

Convert a PrimitiveTopology to its raw value.

Instance details

Defined in WGPU.Internal.Pipeline

ToRaw VertexState WGPUVertexState Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw VertexBufferLayout WGPUVertexBufferLayout Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw InputStepMode WGPUInputStepMode Source #

Convert an InputStepMode to its raw value.

Instance details

Defined in WGPU.Internal.Pipeline

ToRaw VertexAttribute WGPUVertexAttribute Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw VertexFormat WGPUVertexFormat Source #

Convert a VertexFormat to its raw representation.

Instance details

Defined in WGPU.Internal.Pipeline

ToRaw PipelineLayoutDescriptor WGPUPipelineLayoutDescriptor Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw PipelineLayout WGPUPipelineLayout Source # 
Instance details

Defined in WGPU.Internal.Pipeline

ToRaw (ChainedStruct a) WGPUChainedStruct Source # 
Instance details

Defined in WGPU.Internal.ChainedStruct

class ToRawPtr a b where Source #

Represents a value of type a that can be stored as type (Ptr b) in the ContT monad.

Implementations of this type class should bracket resource management for creating (Ptr b) around the continuation. In particular, the memory allocated for (Ptr b) must be allocated before the continuation is called, and freed afterward.

Methods

rawPtr :: a -> ContT c IO (Ptr b) Source #

Instances

Instances details
(Storable b, ToRaw a b) => ToRawPtr a b Source # 
Instance details

Defined in WGPU.Internal.Memory

Methods

rawPtr :: a -> ContT c IO (Ptr b) Source #

ToRawPtr ByteString Word8 Source # 
Instance details

Defined in WGPU.Internal.Memory

ToRawPtr Text CChar Source # 
Instance details

Defined in WGPU.Internal.Memory

Methods

rawPtr :: Text -> ContT c IO (Ptr CChar) Source #

ToRawPtr ShaderEntryPoint CChar Source # 
Instance details

Defined in WGPU.Internal.Shader

Functions

rawArrayPtr Source #

Arguments

:: forall v a b c. (ToRaw a b, Storable b, Vector v a) 
=> v a

Vector of values to store in a C array.

-> ContT c IO (Ptr b)

Pointer to the array with raw values stored in it.

Return a pointer to an allocated array, populated with raw values from a vector.

showWithPtr Source #

Arguments

:: String

Name of the type.

-> Ptr a

Opaque pointer that the type contains.

-> String

Final show string.

Formatter for Show instances for opaque pointers.

Displays a name and a corresponding opaque pointer.