Skip to content
Gustav Sterbrant edited this page Oct 11, 2024 · 2 revisions

Base types

The built in types in GPULang are the following:

  • i32 - 32 bit integer
  • u32 - 32 bit unsigned integer
  • f32 - 32 bit floating point
  • b8 - boolean

Vectors

The above types can be in vector form, in which case they are expressed by adding xN to the type, where N is the size of the vector. A vector can maximally have 4 components. Example: f32x4

Matrices are expressed by adding another xM to the type to declare the amount of columns. Once again, M can maximally be 4. Matrices can only be of floating point type. Example: f32x4x3

All vector types can be swizzled as expected. Matrices have a builtin [] operator to get its columns.

Pointers

A handle to an externally provided resource, such as a texture of buffer, is expressed as a pointer. Example:

*texture2D

A type can also be expressed as an array as such:

[512]*texture2D

GPULang supports multiple dimensions of arrays, as long as they are not bound as external resources.

User defined types

A user may also define their own types. These can be either a struct or an enum. They both follow the same requirements you would expect, with some minor differences.

Struct

Structs are defined as

struct X 
{ 
    name : type
    , ... 
};

Example:

struct Camera
{
    viewProjection : f32x4x4;
    position : f32x4;
};

Structs can not be instantiated upon declaration.

Enum

Enums are defined as

enum X <: type>
{ 
    label <= expression>
    , ... 
};

Example:

enum Framebuffer : i32
{
    Color
};

The type is optional, and if omitted will take on the type of the type of the first value. If the first value isn't defined by an expression, as is optional, then the underlying type of the enum is i32. If the second value is of a different type than the first, the compiler will emit an error. If the enum is explicitly typed and a label evaluates to another type, the compiler will emit an error.

Clone this wiki locally