Skip to content
Gustav Sterbrant edited this page Oct 25, 2024 · 17 revisions

Welcome to GPULang!

GPULang is a programming language designed specifically for GPUs. This Wiki contains a bunch of useful information, such as motivation, syntax, target language limitations, etc.

If you're looking for a syntax highlighting plugin, one is provided for VSCode: https://marketplace.visualstudio.com/items?itemName=GustavSterbrant.gpulang

To get started, review the menu on the right, or jump to the different topics here:

Annotations and Attributes

Types

Variables

Binding Interface

Programs

Built‐ins

Intrinsics

Here are some examples:

//------------------------------------------------------------------------------
//  @file basicgraphics.gpul
//  @copyright (C) 2024 Individual contributors, see AUTHORS file
//------------------------------------------------------------------------------

uniform Albedo : *texture2D;
uniform Material: *sampled texture2D;
uniform Sampler : *sampler;
struct Camera
{
    viewProjection : f32x4x4;
    position : f32x4;
};

uniform camera : *Camera;

struct Object
{
    model : f32x4x4;
};

uniform object : *Object;

entry_point
BasicVertex(
    in Position : f32x3
    , in UV : f32x2
    , out OutUV : f32x2
) void
{
    const worldPos = object.model * f32x4(Position, 1.0f);
    const clipPos = camera.viewProjection * worldPos;

    gplExportVertexCoordinates(clipPos);
    OutUV = UV;
}

enum Framebuffer : i32
{
    Color
};

entry_point
BasicPixel(
    in UV : f32x2
) void
{
    var color = textureSample(Albedo, Sampler, UV);
    gplExportColor(color, Framebuffer.Color);
}

program TestProgram
{
    VertexShader = BasicVertex;
    PixelShader = BasicPixel;
};
Clone this wiki locally