Skip to content

CrossGL/compiler

Repository files navigation




CrossGL Compiler

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).

Supported Targets

Target Output Status
Metal MSL source / .metallib Active
Vulkan SPIR-V assembly / binary Active
DirectX HLSL source / DXIL Active
OpenGL GLSL source Active

Pipeline

.cgl source
  → Lexer (tokenization)
  → Parser (AST)
  → HIR construction (typed, resource-annotated)
  → Optimization passes (constant folding, algebraic simplification)
  → Target legalization
  → Backend code generation
  → Package (.cglb)

Building

Requires C++20, CMake 3.20+, and Ninja.

cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build

CLI Usage

# 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 doctor

Example

shader 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;
        }
    }
}

Testing

cmake --build build --target test

Tests cover the full pipeline: lexer, parser, HIR semantics, backend code generation, native build validation (Metal/Vulkan), package integrity, and JSON schema conformance.

Project Structure

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

Related Projects

Community

License

CrossGL Compiler is open-source and licensed under the Apache License 2.0.


The CrossGL Team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors