LambdaCube 3D DSL

Overview

Hardware background

Work migrated from CPU to GPU

Software background

GPU API

Main motivation
have a common interface for lots of different GPUs
How it works
missing features on a specific GPU are emulated on CPU

OpenGL

Currently OpenGL is the only cross-language, multi-platform API for GPU graphics.

Scope:

OpenGL (2)

OpenGL architecture and usage

OpenGL is a state-machine whose state is called pipeline.

The pipeline is an abstract model of the configured GPU
(the data is loaded into the GPU memory but the computation did not begin)

Two different group of OpenGL operations:

Typical sequence of operations of an application:

  1. initial pipeline setup
  2. pipeline execution
  3. put the result onto the screen (not part of OpenGL)
  4. wait for user input (not part of OpenGL)
  5. pipeline modification
  6. go back to 2.

OpenGL pipeline

OpenGL 3.3 simplified pipeline

OpenGL 3.3 simplified pipeline

OpenGL pipeline (2)

OpenGL 3.3 simplified pipeline

OpenGL 3.3 simplified pipeline

Shaders

GLSL: the language specified for shaders in OpenGL

Steps for processing GLSL source code:

  1. the application provides GLSL code as a string (usually hand written)
  2. the driver compiles it to GPU machine code (usually at runtime)
  3. the code is uploaded to the GPU with specific OpenGL commands (at runtime)

LambdaCube 3D

Motivations

Main goal: cross-platform GPU graphics in a statically typed functional language

LambdaCube 3D layers

Layers and design decisions:

State machine vs. ADT expressions

A state machine is fed by a sequence of state modification operations

An ADT expression is built up by constructors

Use strong static typing

Result: all OpenGL specification constraints are expressed in the type system
i.e. if the type checking succeeds at compile time, we have a valid pipeline at runtime

Development history of LambdaCube 3D

2009 begin to work on an Ogre3D compatible engine in Haskell
2011 public API of the engine as a Haskell EDSL
2012 redesigned, more functional EDSL which was ispired by GPipe
2013 LambdaCube Intermediate Representation (IR) was introduced for platform independence
2015 March begin to work on a separate DSL with a compiler
2015 May begin to work on a web-based editor
2015 end of May begin LambdaCube 3D Europe Tour

Integration into applications

integration

integration

LambdaCube 3D language

Scope:

Main abstractions used: GADTs, functions, type classes

Language specification

Haskell98 (with some diversions) + various extensions

Main diversion: different Prelude

more

LambdaCube 3D Prelude

data FrontFace
    = CW
    | CCW

data CullMode
    = CullFront FrontFace
    | CullBack FrontFace
    | CullNone

data RasterContext (a :: PrimitiveType) where
  TriangleCtx         :: CullMode -> PolygonMode -> PolygonOffset -> ProvokingVertex -> RasterContext Triangle
  PointCtx            :: PointSize -> Float -> PointSpriteCoordOrigin                -> RasterContext Point
  LineCtx             :: Float -> ProvokingVertex                                    -> RasterContext Line

builtins
  PrimAnd, PrimOr, PrimXor  :: Bool -> Bool -> Bool
  PrimAdd, PrimSub, PrimMul :: (t ~ MatVecElem a, Num t) => a -> a -> a

Compiler

Web-based editor

figure

figure

Plans

Plans for the second half of 2015