The native ahead-of-time compiler for CrossGL. It takes .cgl shader sources through lexing, parsing, type-checked HIR construction, optimization, and target-specific code generation to produce GPU-ready artifacts for Metal, Vulkan (SPIR-V), DirectX (HLSL/DXIL), and OpenGL (GLSL).
| Target | Output | Status |
|---|---|---|
| Metal | MSL source / .metallib |
Active |
| Vulkan | SPIR-V assembly / binary | Active |
| DirectX | HLSL source / DXIL | Active |
| OpenGL | GLSL source | Active |
.cgl source
→ Lexer (tokenization)
→ Parser (AST)
→ HIR construction (typed, resource-annotated)
→ Optimization passes (constant folding, algebraic simplification)
→ Target legalization
→ Backend code generation
→ Package (.cglb)
Requires C++20, CMake 3.20+, and Ninja.
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build# Check a shader for diagnostics
cglc check shader.cgl
# Compile to a target
cglc build shader.cgl --target metal
cglc build shader.cgl --target vulkan
cglc build shader.cgl --target directx
cglc build shader.cgl --target opengl
# Dump typed HIR
cglc dump-ir shader.cgl
# List available targets and their capabilities
cglc targets
# Explain target selection for a shader
cglc explain-targets shader.cgl
# Inspect a compiled package
cglc inspect shader.cglb
# Run environment diagnostics
cglc doctorshader SimpleShader {
struct VertexInput {
vec3 position;
vec2 texCoord;
}
struct VertexOutput {
vec2 uv;
vec4 position;
}
struct FragmentInput {
vec2 uv;
}
struct FragmentOutput {
vec4 color;
}
vertex {
VertexOutput main(VertexInput input) {
VertexOutput output;
output.uv = input.texCoord;
output.position = vec4(input.position, 1.0);
return output;
}
}
fragment {
FragmentOutput main(FragmentInput input) {
FragmentOutput output;
float r = input.uv.x;
float g = input.uv.y;
float b = 0.5;
output.color = vec4(r, g, b, 1.0);
return output;
}
}
}
cmake --build build --target testTests cover the full pipeline: lexer, parser, HIR semantics, backend code generation, native build validation (Metal/Vulkan), package integrity, and JSON schema conformance.
src/
Frontend/ Lexer and parser
HIR/ Typed high-level IR, constant folding, type semantics
Optimizer/ HIR pass manager
Backend/ Metal, Vulkan, DirectX, OpenGL code generators
IR/ IR printer
Driver/ CLI driver, package tooling, reflection
include/ Public headers
runtime/ Package reader prototype (Python)
tests/ Unit tests, fixtures, schema validation
tools/ CI and schema validation scripts
cmake/ Build system modules
- CrossGL Translator — Python-based bidirectional shader translator
- CrossGL Documentation — Language reference and guides
CrossGL Compiler is open-source and licensed under the Apache License 2.0.
The CrossGL Team
