Skip to content

Language Syntax

File Structure

An .axsl file has the following top-level structure:

axsl
@version <number>;
@include "path/to/file.axsl";   // zero or more, must appear before globals

// Global declarations (structs, consts, uniforms, interfaces, functions)

@stage vertex   { ... }
@stage fragment { ... }
@stage geometry { ... }
@stage compute  { ... }

Comments

C-style line and block comments:

axsl
// line comment
/* block comment */

Types

All GLSL primitive and sampler types are first-class keywords in AXSL:

Scalar Types

bool, int, uint, float

Vector Types

vec2, vec3, vec4, ivec2, ivec3, ivec4, uvec2, uvec3, uvec4

Matrix Types

mat2, mat3, mat4

Sampler Types

sampler2D, samplerCube, sampler2DShadow, isampler2D, usampler2D

User-Defined Types

Any identifier token is accepted as a type name (struct names, etc.).

Built-in Variables

The following GLSL built-in variables are recognized:

Vertex Stage:

  • gl_Position
  • gl_PointSize
  • gl_ClipDistance
  • gl_VertexID
  • gl_InstanceID
  • gl_DrawID

Fragment Stage:

  • gl_FragCoord
  • gl_FrontFacing
  • gl_PointCoord
  • gl_FragDepth
  • gl_SampleID
  • gl_SamplePosition
  • gl_SampleMaskIn
  • gl_SampleMask

Compute Stage:

  • gl_NumWorkGroups
  • gl_WorkGroupSize
  • gl_WorkGroupID
  • gl_LocalInvocationID
  • gl_GlobalInvocationID
  • gl_LocalInvocationIndex

Expressions

Literals

Integer:

axsl
42
0xFF      // hexadecimal

Float:

axsl
3.14
0.        // trailing dot (abbreviation for 0.0)
1.        // abbreviation for 1.0

Boolean:

axsl
true
false

Operators

Binary:

  • Arithmetic: +, -, *, /, %
  • Comparison: ==, !=, <, >, <=, >=
  • Logical: &&, ||
  • Bitwise: &, |, ^, <<, >>

Unary Prefix:

  • ! (logical not)
  • ~ (bitwise not)
  • - (negation)
  • + (unary plus)
  • ++, -- (increment/decrement)

Unary Postfix:

  • ++, -- (increment/decrement)

Assignment:

  • Simple: =
  • Compound: +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=

Ternary:

axsl
condition ? then_expr : else_expr

Type Constructors

axsl
vec3(1.0, 0.0, 0.0)
vec4(vec3(1.0), 1.0)
mat4(1.0)  // identity matrix

Function Calls

axsl
sin(angle)
texture(sampler, uv)
normalize(vec)

Field Access

axsl
material.albedo
position.xyz
color.rgb

Array Subscript

axsl
array[index]
matrix[row][col]

Statements

Variable Declaration

axsl
float x = 0.0;
vec3 position;
int count = 10;

If Statement

axsl
if (condition) {
    // ...
} else if (other_condition) {
    // ...
} else {
    // ...
}

For Loop

axsl
for (int i = 0; i < 10; i++) {
    // ...
}

While Loop

axsl
while (condition) {
    // ...
}

Do-While Loop

WARNING

Do-while loops are currently emitted as regular while loops, losing the guarantee that the body executes at least once. This is a known limitation.

axsl
do {
    // ...
} while (condition);

Return Statement

axsl
return;
return value;

Control Flow

axsl
break;      // exit loop
continue;   // next iteration
discard;    // fragment shader only

Expression Statement

axsl
x = x + 1;
function_call();
x++;

Array Syntax

Fixed-Size Arrays

axsl
uniform PointLight lights[4];
float values[16];

Runtime-Sized Arrays

Inside buffer/uniform blocks, unbounded arrays are declared with empty brackets:

axsl
@std430 @binding(0) buffer InstanceBuffer {
    mat4 models[];
} instance;

This is emitted as [] in GLSL, indicating a runtime-sized array (SSBO feature).

Qualifiers

Parameter Qualifiers

Used on function parameters:

AXSL keywordGLSL outputMeaning
ininInput parameter (default)
outoutOutput parameter
inoutinoutInput/output parameter
constconstConstant parameter

Example:

axsl
void transform(in vec3 pos, out vec4 result) {
    result = vec4(pos, 1.0);
}