fir-0.0.1.0: An EDSL that compiles to SPIR-V for graphics programming on the GPU in Haskell.
FIR is an EDSL for writing GPU shader code in Haskell, compiled to SPIR-V. Requires GHC >= 8.8.
With this library, shader programs can be written using do notation. Such programs are then transformed into abstract syntax trees (ASTs), before being compiled to SPIR-V assembly.
In effect, this replaces GLSL as a shader language. This means the Haskell type-system and type-checker are put to use in verifying programs at compile-time. Functional idioms, such as functor and applicative operations, are also supported.
See the fir-examples project subdirectory for fleshed out examples, including using the vulkan-api package for rendering.
The exposed modules are:
- FIR
- Re-exports the main functionality of the library: writing and compiling programs.
- FIR.Syntax.Labels
- Optional imperative-like syntax using OverloadedLabels.
- Math.Linear
- Vectors, matrices, and operations on them, as used by this library.
- Math.Quaternion
- Quaternions and their action by conjugation in 3 dimensions, useful for 3D cameras.
Important types used by this library:
Code aCode for a pure value of type
a, represented internally as an abstract syntax tree. See FIR.AST.Overloaded functions are provided that automatically create and combine terms of this type. For instance,
3 + 5 :: Code Floatgets desugared toPrimOp FAdd ( Lit 3.0 ) ( Lit 5.0 ).Program i j aA monadic expression, starting in state
iand ending in statej. This state is used to keep track of information at the type level, allowing for type errors to be thrown on invalid operations (e.g. writing to a read-only variable, image sampling outside a fragment shader, etc).A value of type
Program i j (Code a)can be thought of as stateful GPU code producing a value of typea.Internally represented using the codensity transformation of McBride-style indexed monads, see Control.Monad.Indexed.
Module defsCode for a program that can be compiled to a
SPIR-Vmodule.defsis a type-level list of shader inputs/ouputs (uniforms, varyings, etc), top-level functions, and entry points.See FIR.Module for the definition, and the example shaders for common usage patterns.
Values of all three of these types can be displayed graphically as trees using showAST/drawAST, which can be useful for debugging.
See the project readme for further information, as well as the "getting started" guide, which includes instructions concerning installation and usage of the library, and of useful tools such as the SPIR-V tools provided by the Vulkan SDK.
Signatures
Modules
- CodeGen
- Control
- Data
- Binary
- Constraint
- Containers
- Finite
- Function
- Data.Product
- Type
- Deriving
- FIR
---Main module, re-exports what's needed to write programs and compile to SPIR-V.- FIR.AST
- FIR.Binding
- FIR.Builtin
- FIR.Definition
- FIR.Layout
- FIR.Module
- FIR.Pipeline
- Prim
- FIR.ProgramState
- Syntax
- FIR.Syntax.AST
- FIR.Syntax.IfThenElse
- FIR.Syntax.Images
- FIR.Syntax.Labels
---Optional imperative-style syntax using overloaded labels. - FIR.Syntax.Optics
- FIR.Syntax.Option
- FIR.Syntax.Program
- FIR.Syntax.Swizzle
- FIR.Syntax.Synonyms
- FIR.Temp
- Validation
- Instances
- Math
- Algebra
- Math.Linear
---Vectors & matrices, as used by this library. Import required to use vectors & matrices. - Logic
- Math.Quaternion
- SPIRV