Why Slang?

The Slang system is designed to provide developers of real-time graphics applications with the services they need when working with large-scale and high-performance shader code.

Write Cross Platform Shaders

The Slang compiler can generate code for a wide variety of targets and APIs: D3D12, Vulkan, Metal, D3D11, OpenGL, CUDA, and CPU. Slang code can be broadly portable, but still take advantage of the unique features of each platform. For textual targets such as Metal Shading Language(MSL) and CUDA, Slang generates readable code that preserves the original identifier names and the type + call structure for ease of debugging.

Access Latest GPU Feature

Being cross-platform doesn’t mean reducing accessible GPU feature set to the least common denominator of all platforms. Slang exposes latest features in Direct3D and Vulkan. For example, you can use pointers when generating SPIRV. To help applications managing feature set differences across platforms, Slang’s capability system can ensure your code is only using available features on a target platform during the type-checking step, before generating the final code.

In addition, Slang provides flexible interop features to allow you to directly embed target code or SPIRV in your shaders.

Automatic Differentiation

Slang can automatically generate both forward and backward derivative propagation code for complex functions that involve arbitrary control flow and dynamic dispatch. This allows users to easily make existing rendering codebases differentiable, or to use Slang as the kernel language in a PyTorch driven machine learning framework via slangtorch.

Module System

Slang provides a module system that can be used to logically organize code and benefit from separate compilation. Slang modules can be compiled offline to a custom IR (with optional obfuscation) and then linked at runtime to generate DXIL, SPIR-V etc.

Code Specialization that Works with Modules

Slang supports generics and interfaces (a.k.a. type traits/protocols) to allow clear expression of shader specialization without resorting to preprocessor techniques or string-pasting. Unlike C++ templates, Slang’s generics are checked ahead of time and don’t produce cascading error messages that are difficult to diagnose. The same generic shader can be specialized for a variety of different types to produce specialized code ahead of time, or on the fly, completely under application control.

Easy On-ramp from HLSL and GLSL

Slang’s syntax is similar to HLSL and most existing HLSL code can be compiled with the Slang compiler out-of-the-box, or with minor modifications. It is possible to start taking advantage of Slang’s benefits without rewriting or porting your shader codebase.

In addition, Slang offers a compatbility module that allows you to use most GLSL intrinsic functions and parameter binding syntax.

Comprehensive Tooling Support

Slang has full intellisense features in Visual Studio Code and Visual Studio through the Language Server Protocol. Full debugging experience is also available with SPIRV and RenderDoc.