packages feed

fir-0.1.0.0: src/SPIRV/Layout.hs

{-# LANGUAGE DerivingStrategies #-}

{-|
Module: SPIRV.Layout

This module describes how types are laid out in memory.

Values have logical types, which carry no layout information.
Memory can impose a layout on the types it contains: for instance,
a structure in a storage buffer must specify the offsets of its members.
In SPIR-V, the same logical type with different layouts gives different types,
which are declared with different decorations.

-}

module SPIRV.Layout
  ( LayoutRules(..)
  , BlockKind(..)
  , Layout(..), logical
  ) where

--------------------------------------------------

-- | Rules for explicitly laying out types in memory.
data LayoutRules
  = BaseAlignment     -- ^ Used for storage buffers, push constants and shader record buffers.
  | ExtendedAlignment -- ^ Used for uniform buffers.
  deriving stock ( Show, Eq, Ord )

-- | The kind of an interface block.
data BlockKind
  = UserBlock    -- ^ A block declared by the user.
  | BuiltinBlock -- ^ A block of built-in variables, such as @gl_PerVertex@.
  deriving stock ( Show, Eq, Ord )

-- | How a type is laid out in memory.
data Layout
  = Layout
  { layoutRules :: Maybe LayoutRules
    -- ^ Rules for explicit offsets and strides, if any.
  , blockKind   :: Maybe BlockKind
    -- ^ Whether the type is an interface block (or an array of interface blocks).
  }
  deriving stock ( Show, Eq, Ord )

-- | The layout of values: no explicit offsets or strides, and not an interface block.
logical :: Layout
logical = Layout { layoutRules = Nothing, blockKind = Nothing }