Crosstl
Universal Programming Language & Translator
Install / Use
/learn @CrossGL/CrosstlREADME
<div style="display: block;" align="center"> <img class="dark-light" width="5%" > <a href="https://crossgl.net/"> <img class="dark-light" height="5%" width="5%" src="https://github.com/CrossGL/crossgl-docs/blob/main/docs/assets/web_icon.png"> </a> <img class="dark-light" width="5%" > <a href="https://crossgl.github.io/crossgl-docs/pages/graphica/language"> <img class="dark-light" height="5%" width="5%" src="https://github.com/CrossGL/crossgl-docs/blob/main/docs/assets/docs.png"> </a> <img class="dark-light" width="5%" > <a href="https://github.com/CrossGL/demos"> <img class="dark-light" height="5%" width="5%" src="https://github.com/CrossGL/crossgl-docs/blob/main/docs/assets/written.png"> </a> <img class="dark-light" width="5%" > <a href="https://crossgl.github.io/crossgl-docs/pages/graphica/design"> <img class="dark-light" height="5%" width="5%" src="https://github.com/CrossGL/crossgl-docs/blob/main/docs/assets/strategic-plan.png"> </a> </div> <br> <div style="margin-top: 10px; margin-bottom: 10px; display: block;" align="center"> <a href="https://github.com/CrossGL/crosstl/issues"> <img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://img.shields.io/github/issues/CrossGL/crosstl"> </a> <a href="https://github.com/CrossGL/crosstl/network/members"> <img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://img.shields.io/github/forks/CrossGL/crosstl"> </a> <a href="https://github.com/CrossGL/crosstl/stargazers"> <img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://img.shields.io/github/stars/CrossGL/crosstl"> </a> <a href="https://github.com/CrossGL/crosstl/pulls"> <img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"> </a> <a href="https://pypi.org/project/crosstl/"> <img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://badge.fury.io/py/crosstl.svg"> </a> <a href="https://discord.com/invite/uyRQKXhcyW"> <img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://img.shields.io/discord/1240998239206113330?color=blue&label=%20&logo=discord&logoColor=white"> </a> <a href="https://doi.org/10.5281/zenodo.15826974"> <img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://zenodo.org/badge/DOI/10.5281/zenodo.15826974.svg"> </a> </div> <br clear="all" />
CrossTL - Universal Programming Language & Translator
CrossTL is a revolutionary universal programming language translator built around CrossGL - a powerful intermediate representation (IR) language that serves as the bridge between diverse programming languages, platforms, and computing paradigms. More than just a translation tool, CrossGL represents a complete programming language designed for universal code portability and cross-platform development.
🌍 CrossGL: The Universal Programming Language
Beyond Shader Translation - A Complete Programming Ecosystem
CrossGL has evolved far beyond its origins as a shader language into a comprehensive programming language with full support for:
- Advanced Control Flow: Complex conditionals, loops, switch statements, and pattern matching
- Rich Data Structures: Arrays, structs, enums, and custom types
- Memory Management: Buffer handling, pointer operations, and memory layout control
- Function Systems: First-class functions, generics, and polymorphism
- Compute Paradigms: Parallel processing, GPU computing, and heterogeneous execution
- Modern Language Features: Type inference, pattern matching, and algebraic data types
🚀 Write Once, Deploy Everywhere
CrossGL enables you to write sophisticated programs once and deploy across:
- Graphics APIs: Metal, DirectX (HLSL), OpenGL (GLSL), Vulkan (SPIRV)
- Systems Languages: Rust, Mojo
- GPU Computing: CUDA, HIP
- Specialized Domains: Slang (real-time graphics), compute shaders
🎯 Supported Translation Targets
CrossTL provides comprehensive bidirectional translation between CrossGL and major programming ecosystems:
Graphics & Compute APIs
- Metal - Apple's unified graphics and compute API
- DirectX (HLSL) - Microsoft's graphics framework
- OpenGL (GLSL) - Cross-platform graphics standard
- Vulkan (SPIRV) - High-performance graphics and compute
Systems Programming Languages
- Rust - Memory-safe systems programming with GPU support
- Mojo - AI-first systems language with Python compatibility
Parallel Computing Platforms
- CUDA - NVIDIA's parallel computing platform
- HIP - AMD's GPU computing interface
Specialized Languages
- Slang - Real-time shading and compute language
Universal Intermediate Representation
- CrossGL (.cgl) - Our universal programming language and IR
✅ Backend Readiness: DirectX / Metal / OpenGL
We maintain first-class, bidirectional support for the three cornerstone graphics APIs. Each backend is implemented as both a source (parse/import) and codegen (export) target, so you can round‑trip between native shaders and CrossGL without lossy hops.
- DirectX / HLSL
- Pipeline coverage: vertex, fragment/pixel, compute, geometry, hull/domain (tessellation), mesh/task, full ray‑tracing stages.
- Resource model: cbuffers, register/space bindings, UAV/RW textures & buffers, structured buffers, Interlocked atomics, wave ops, texture/buffer dimension queries.
- Semantics map to
SV_*and user semantics, preserved through CrossGL attributes.
- Metal
- Stages: vertex, fragment, compute, mesh/object, and ray‑tracing qualifiers.
- Resource/binding support: argument buffers,
[[buffer]],[[texture]],[[sampler]], function constants, packed/simd types, indirect command buffers, payload/hit attributes. - Texture methods (sample/load/store/gather/compare) and threadgroup builtins are translated to CrossGL intrinsics.
- OpenGL / GLSL
- Stages: vertex, fragment, compute with version inference (defaults to
#version 450 corewhen absent). - Handles interface blocks, layouts/bindings, sampler & image operations, control flow, structs/arrays, discard, builtins (
gl_*) and preprocessor directives.
- Stages: vertex, fragment, compute with version inference (defaults to
- Round‑trips verified via converters in
crosstl.backend.{DirectX,Metal,GLSL}and registered intranslator.source_registryandtranslator.codegen.registry.
How we validate backend parity
- Targeted unit suites exercise the full feature surface for these three backends (shader stages, bindings, intrinsics, control‑flow, resources, and preprocessor handling).
- Quick check: run
pytest tests/test_backend/test_directx tests/test_backend/test_metal tests/test_backend/test_GLSL -q(currently 321 passing tests). - End‑to‑end translation: translate native HLSL/Metal/GLSL → CrossGL → HLSL/Metal/GLSL/Vulkan to ensure attributes, layouts, and semantics survive round‑trips.
💡 Revolutionary Advantages
- 🔄 Universal Portability: Write complex algorithms once, run on any platform
- ⚡ Performance Preservation: Maintain optimization opportunities across translations
- 🧠 Simplified Development: Master one language instead of platform-specific variants
- 🔍 Advanced Debugging: Universal tooling for analysis and optimization
- 🔮 Future-Proof Architecture: Easily adapt to emerging programming paradigms
- 🌐 Bidirectional Translation: Migrate existing codebases to CrossGL or translate to any target
- 📈 Scalable Complexity: From simple shaders to complex distributed algorithms
- 🎯 Domain Flexibility: Graphics, AI, HPC, systems programming, and beyond
⚙️ Translation Architecture
CrossTL employs a sophisticated multi-stage translation pipeline:
- Lexical Analysis: Advanced tokenization with context-aware parsing
- Syntax Analysis: Robust AST generation with error recovery
- Semantic Analysis: Type checking, scope resolution, and semantic validation
- IR Generation: Conversion to CrossGL intermediate representation
- Optimization Passes: Platform-agnostic code optimization and analysis
- Target Generation: Backend-specific code generation with optimization
- Post-Processing: Platform-specific optimizations and formatting
🔄 Bidirectional Translation Capabilities
CrossGL supports seamless translation in both directions - import existing code from any supported language or export CrossGL to any target platform.
🌈 CrossGL Programming Language Examples
Complex Algorithm Implementation
// Advanced pattern matching and algebraic data types
enum Result<T, E> {
Ok(T),
Error(E)
}
struct Matrix<T> {
data: T[],
rows: u32,
cols: u32
}
function matrixMultiply<T>(a: Matrix<T>, b: Matrix<T>) -> Result<Matrix<T>, String> {
if (a.cols != b.rows) {
return Result::Error("Matrix dimensions incompatible");
}
let result = Matrix<T> {
data: new T[a.rows * b.cols],
rows: a.rows,
cols: b.cols
};
parallel for i in 0..a.rows {
for j in 0..b.cols {
let mut sum = T::default();
for k in 0..a.cols {
sum += a.data[i * a.cols + k] * b.data[k * b.cols + j];
}
result.data[i * result.cols + j] = sum;
}
}
return Result::Ok(result);
}
// GPU compute shader with advanced memory management
compute spawn matrixCompute {
buffer float* matrix_A;
buffer float* matrix_B;
buffer float* result;
local float shared_m
