The Slang shading language and compiler is a proven open-source technology empowering real-time graphics developers with flexible, innovative features that complement existing shading languages, including neural computation inside graphics shaders. Slang’s support for modular code significantly simplifies the development and maintenance of large codebases, while its compiler enables smooth migration paths for existing HLSL and GLSL shaders. The Slang compiler also supports multiple backend targets for portable code deployment across diverse APIs and platforms.
View the Slang Launch DeckDiscover the continuously evolving benefits of Slang.
The Slang compiler can generate code for a wide variety of targets: D3D12, Vulkan, Metal, D3D11, OpenGL, CUDA, WebGPU and even generate code to run on a CPU. For textual targets, such as Metal Shading Language (MSL) and CUDA, Slang produces readable code that preserves original identifier names, as well as the type and call structure, making it easier to debug.
Slang code is highly portable, but can still leverage unique platform capabilities, including the latest features in Direct3D and Vulkan. For example, developers can make full use of pointers when generating SPIR-V. Slang's capability system helps applications manage feature set differences across target platforms by ensuring code only uses available features during the type-checking step, before generating final code. Additionally, Slang provides flexible interop features to enable directly embedding target code or SPIR-V into generated shaders.
Slang can automatically generate both forward and backward derivative propagation code for complex functions that involve arbitrary control flow and dynamic dispatch. This allows existing rendering codebases to easily become differentiable, enabling adoption of neural components, or integration into a training process.
Automatic DifferentiationSlang code can be integrated directly into your Python/PyTorch training loop with SlangPy. You can implement complex control-divergent algorithms, sparse data structures, make use of advanced GPU features in Slang, and call your Slang code from Python without any boilerplate with the SlangPy package.
SlangPySlang provides a module system that enables logical organization of code for separate compilation. Slang modules can be independently compiled offline to a custom IR (with optional obfuscation) and then linked at runtime to generate code in formats such as DXIL or SPIR-V.
Module systemSlang supports generics and interfaces (a.k.a. type traits/protocols), allowing for clear expression of shader specialization without the need for preprocessor techniques or string-pasting. Unlike C++ templates, Slang’s generics are pre-checked 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, entirely under application control.
Generics and InterfacesSlang’s syntax is similar to HLSL, and most existing HLSL code can be compiled with the Slang compiler out-of-the-box, or with just minor modifications. This allows existing shader codebases to immediately benefit from Slang without requiring a complete rewrite or port. Slang provides a compatibility module that enables the use of most GLSL intrinsic functions and GLSL’s parameter binding syntax.
Port from HLSLSlang comes with full support of IntelliSense editing features in Visual Studio Code and Visual Studio through the Language Server Protocol. Full debugging capabilities are also available through RenderDoc and SPIR-V based tools.
ToolsSlang is now hosted as a Khronos Group open-source project, fostering industry-wide collaboration to propel its ongoing growth and evolution. While Slang has been available as open source for a while, establishing multi-company governance is essential to build industry trust by ensuring that Slang remains independent and not controlled by, or dependent on, single entity. This trust empowers the graphics industry to collaboratively invest in and depend on Slang for business-critical applications.