Language Syntax
File Structure
An .axsl file has the following top-level structure:
@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:
// 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_Positiongl_PointSizegl_ClipDistancegl_VertexIDgl_InstanceIDgl_DrawID
Fragment Stage:
gl_FragCoordgl_FrontFacinggl_PointCoordgl_FragDepthgl_SampleIDgl_SamplePositiongl_SampleMaskIngl_SampleMask
Compute Stage:
gl_NumWorkGroupsgl_WorkGroupSizegl_WorkGroupIDgl_LocalInvocationIDgl_GlobalInvocationIDgl_LocalInvocationIndex
Expressions
Literals
Integer:
42
0xFF // hexadecimalFloat:
3.14
0. // trailing dot (abbreviation for 0.0)
1. // abbreviation for 1.0Boolean:
true
falseOperators
Binary:
- Arithmetic:
+,-,*,/,% - Comparison:
==,!=,<,>,<=,>= - Logical:
&&,|| - Bitwise:
&,|,^,<<,>>
Unary Prefix:
!(logical not)~(bitwise not)-(negation)+(unary plus)++,--(increment/decrement)
Unary Postfix:
++,--(increment/decrement)
Assignment:
- Simple:
= - Compound:
+=,-=,*=,/=,%=,&=,|=,^=,<<=,>>=
Ternary:
condition ? then_expr : else_exprType Constructors
vec3(1.0, 0.0, 0.0)
vec4(vec3(1.0), 1.0)
mat4(1.0) // identity matrixFunction Calls
sin(angle)
texture(sampler, uv)
normalize(vec)Field Access
material.albedo
position.xyz
color.rgbArray Subscript
array[index]
matrix[row][col]Statements
Variable Declaration
float x = 0.0;
vec3 position;
int count = 10;If Statement
if (condition) {
// ...
} else if (other_condition) {
// ...
} else {
// ...
}For Loop
for (int i = 0; i < 10; i++) {
// ...
}While Loop
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.
do {
// ...
} while (condition);Return Statement
return;
return value;Control Flow
break; // exit loop
continue; // next iteration
discard; // fragment shader onlyExpression Statement
x = x + 1;
function_call();
x++;Array Syntax
Fixed-Size Arrays
uniform PointLight lights[4];
float values[16];Runtime-Sized Arrays
Inside buffer/uniform blocks, unbounded arrays are declared with empty brackets:
@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 keyword | GLSL output | Meaning |
|---|---|---|
in | in | Input parameter (default) |
out | out | Output parameter |
inout | inout | Input/output parameter |
const | const | Constant parameter |
Example:
void transform(in vec3 pos, out vec4 result) {
result = vec4(pos, 1.0);
}