Slang is a shader compiler framework that combines a modular shading language with automatic differentiation, multi-target code generation, and an intrinsic mapping and extension system. At its core, Slang provides a differentiable shader compiler that automatically generates forward and backward derivative propagation for functions with control flow, enabling gradient-based optimization in graphics. The framework also includes a fully featured shader language with modules, generics, interfaces, and separate compilation, all designed for building reusable shader libraries. From a single source, Slang compiles shader code to GPU APIs including Vulkan, Direct3D, Metal, and CUDA, as well as CPU targets.
Slang distinguishes itself with capabilities that go beyond standard shader compilation. Its automatic differentiation supports custom derivative implementations, higher-order derivatives, and explicit exclusion of non-differentiable parameters. The framework uses a descriptor heap binding model that accesses resources through indices rather than explicit slots, and it performs generic specialization at link time to adapt resource binding dynamically. Slang also provides an intrinsic-based targeting system that maps shader function calls to target-specific code snippets, with per-target switching and support for injecting custom code into generated output.
The shader language includes modern features such as type-parametric generics with interfaces, struct methods and operators, tuple and optional types, error handling with try-catch, and modular imports with namespace control. The compilation pipeline offers runtime shader inspection and specialization, precompilation into binary IR modules, parallel backend compilation for faster builds, and update rate parameter grouping to reduce CPU overhead. Compatibility checking verifies at compile time that each operation is available on the target API and shader stage, surfacing errors directly in the editor through a plugin.
Slang is available both through a programmatic API that gives full control over each compilation stage and through a command-line tool that supports multiple entry points and targets.