fir: An EDSL that compiles to SPIR-V for graphics programming on the GPU in Haskell.

[ bsd3, graphics, library ] [ Propose Tags ] [ Report a vulnerability ]

FIR is an EDSL for writing GPU shader code in Haskell, compiled to SPIR-V. Requires GHC >= 8.10.

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 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 a

Code 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 Float gets desugared to PrimOp FAdd ( Lit 3.0 ) ( Lit 5.0 ).

Program i j a

A monadic expression, starting in state i and ending in state j. 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 type a.

Internally represented using the codensity transformation of McBride-style indexed monads, see Control.Monad.Indexed.

Module defs

Code for a program that can be compiled to a SPIR-V module.

defs is 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.

Modules

  • CodeGen
    • CodeGen.Application
    • CodeGen.Applicative
    • CodeGen.Array
    • CodeGen.Atomics
    • CodeGen.Binary
    • CodeGen.CFG
    • CodeGen.CodeGen
    • CodeGen.Composite
    • CodeGen.Debug
    • CodeGen.Functions
    • CodeGen.IDs
    • CodeGen.Images
    • CodeGen.Instruction
    • CodeGen.Monad
    • CodeGen.Optics
    • CodeGen.Phi
    • CodeGen.Pointers
    • CodeGen.PrimOps
    • CodeGen.RayTracing
    • CodeGen.State
  • Control
    • Arrow
      • Control.Arrow.Strength
    • Monad
      • Control.Monad.Indexed
    • Type
      • Control.Type.Optic
  • Data
    • Binary
      • Class
        • Data.Binary.Class.Put
    • Constraint
      • Data.Constraint.All
    • Containers
      • Data.Containers.Traversals
    • Finite
      • Data.Finite.With
    • Function
      • Data.Function.Variadic
    • Data.Product
    • Type
      • Data.Type.Error
      • Data.Type.Known
      • Data.Type.LazyEquality
      • Data.Type.List
      • Data.Type.Map
      • Data.Type.Maybe
      • Data.Type.Nat
      • Data.Type.POrd
      • Data.Type.Snoc
      • Data.Type.String
  • Deriving
    • Deriving.Base
  • FIR
    • FIR.AST
      • FIR.AST.ControlFlow
      • FIR.AST.Display
      • FIR.AST.Effs
      • FIR.AST.Exts
      • FIR.AST.Images
      • FIR.AST.Optics
      • FIR.AST.Prim
      • FIR.AST.Type
    • FIR.Binding
    • FIR.Builtin
    • FIR.Definition
    • FIR.Generics
    • FIR.Layout
    • FIR.Module
    • FIR.Pipeline
    • FIR.Prelude
    • Prim
      • FIR.Prim.Array
      • FIR.Prim.Atomic
      • FIR.Prim.Image
      • FIR.Prim.Op
      • FIR.Prim.RayTracing
      • FIR.Prim.Struct
      • FIR.Prim.Types
    • FIR.ProgramState
    • Syntax
      • FIR.Syntax.AST
      • FIR.Syntax.Complex
      • FIR.Syntax.DebugPrintf
      • FIR.Syntax.IfThenElse
      • FIR.Syntax.Images
      • FIR.Syntax.Labels
      • FIR.Syntax.Optics
      • FIR.Syntax.Option
      • FIR.Syntax.Program
      • FIR.Syntax.RayTracing
      • FIR.Syntax.Swizzle
      • FIR.Syntax.Synonyms
    • FIR.Temp
    • Validation
      • FIR.Validation.Ambiguity
      • FIR.Validation.Arrayness
      • FIR.Validation.Bindings
      • FIR.Validation.Bounds
      • FIR.Validation.CFG
      • FIR.Validation.Definitions
      • FIR.Validation.ExecutionModes
      • FIR.Validation.Formats
      • FIR.Validation.Images
      • FIR.Validation.Interface
      • FIR.Validation.Layout
      • FIR.Validation.Pipeline
      • FIR.Validation.RayTracing
  • Instances
    • TH
      • Instances.TH.Lift
  • Math
    • Algebra
      • Math.Algebra.Class
      • Math.Algebra.GradedSemigroup
    • Math.Linear
    • Logic
      • Math.Logic.Bits
      • Math.Logic.Class
    • Math.Quaternion
  • SPIRV
    • SPIRV.Builtin
    • SPIRV.Capability
    • SPIRV.Control
    • SPIRV.Decoration
    • SPIRV.ExecutionMode
    • SPIRV.Extension
    • SPIRV.Groups
    • SPIRV.Image
    • SPIRV.Layout
    • SPIRV.Operation
    • SPIRV.PrimOp
    • SPIRV.PrimTy
    • SPIRV.Requirements
    • SPIRV.ScalarTy
    • SPIRV.Stage
    • SPIRV.Storage
    • SPIRV.Synchronisation
    • SPIRV.Version

Flags

Manual Flags

NameDescriptionDefault
internals

This flag exposes all internal modules that by default are inaccessible. It's mostly only useful for library developers to use the internals of FIR rather than end users writing shader programs.

Disabled
sop

This flag exposes a module with Syntactic instances for generics-sop.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies atomic-file-ops (>=0.3.0.0 && <0.4), base (>=4.14 && <4.23), binary (>=0.8.7.0 && <0.11), bytestring (>=0.10.9.0 && <0.13), containers (>=0.6.2.1 && <0.9), directory (>=1.3.3.0 && <1.4), distributive (>=0.6 && <0.7), finite-typelits (>=0.1.4.2 && <0.3), generic-monoid (>=0.1.0.0 && <0.2), ghc-typelits-knownnat (>=0.8.2 && <0.9), ghc-typelits-natnormalise (>=0.9.0 && <0.10), half (>=0.3 && <0.4), lens (>=4.18 && <5.4), mtl (>=2.2.2 && <2.4), split (>=0.2.3.3 && <0.3), template-haskell (>=2.15 && <2.25), text-short (>=0.1.4 && <0.2), transformers (>=0.5.6.2 && <0.7), tree-view (>=0.5 && <0.6), typelits-witnesses (>=0.2.3 && <0.5), variant (>=1.0.1 && <1.1), vector (>=0.12.0.3 && <0.14), vector-sized (>=1.4.0.0 && <1.7) [details]
Tested with ghc ==9.14.1
License BSD-3-Clause
Author Sam Derbyshire
Maintainer sam.derbyshire@gmail.com
Uploaded by sheaf at 2026-11-06T09:42:23Z
Revised Revision 1 made by sheaf at 2026-11-06T09:44:18Z
Category Graphics
Home page https://gitlab.com/sheaf/fir
Bug tracker https://gitlab.com/sheaf/fir/-/issues
Source repo head: git clone https://gitlab.com/sheaf/fir.git -b 0.1
Distributions
Downloads 0 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2026-11-06 [all 2 reports]