Slang compiles one shader library into DXIL, SPIR-V, MSL and CUDA
Making it easier to work with shaders
At a glance
- What is it?
- Slang is a shading language, written in C++, built for large shader codebases. Its compiler emits six backends from one source, its modules precompile to optional obfuscated IR linked at run time, and its bundled examples still sit on a graphics layer the project is retiring.
- Who is it for?
- Slang fits teams that already maintain a large shader library across several graphics APIs and want one compile step for all of them, and it fits differentiable rendering work through autodiff and slangtorch. Before committing, check two things: whether GFX, the layer the shipped examples use, matters for your port, and whether your build process can pin a compiler version, since v2026.18.3, v2026.19 and v2026.20 arrived within a month.
- Can I use it commercially?
- Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
- Is it still maintained?
- Yes. The repository last received commits 2 days ago.
- What is it written in?
- Mainly C++, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 13, 2026, and from our analysis. They are not legal advice.
Star history
- shader-slang/slang5,813 ★ · +145
| Repository | 2026-09-23 | 2026-11-13 |
|---|---|---|
| shader-slang/slang | 5.7k | 5.8k |
145 Stars in the last 51 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Six codegen targets, and text output that keeps your names
Write a shader once and let the compiler pick the backend: the Slang compiler generates code for D3D12, Vulkan, Metal, D3D11, CUDA, and it can also generate code that runs on the CPU. What you get back is not the same on every target, and the difference matters when something goes wrong. Metal Shading Language and CUDA are textual targets, and there Slang produces readable code that preserves the identifier names you wrote, along with the type and call structure. That is a debugging decision rather than a formatting one: when a captured frame lands in the Metal backend and you need to know which function ran, the generated source carries your names into the file your tools can look through.
That single compile step is the reason the language exists as a separate tool rather than as a dialect of HLSL. A team with a D3D12 renderer on Windows, a Vulkan path on Linux, and a Metal path for Apple hardware ends up maintaining one shader library instead of three copies that drift apart. Compute sits next to graphics in the same language, since CUDA and CPU targets are compiled from the same source as the graphics backends, so a training kernel and a rendering pass can share types and helpers.
The capability system rejects unavailable features at type-check time
Portability has a price, and Slang makes the price explicit. Its capability system exists so an application can manage the feature set differences between target platforms, and it does that by checking during the type-checking step that the code only uses features that are actually available, before final code generation runs. Nothing is deferred and discovered later. When a feature is missing on a target, the compile fails at type-check rather than producing code that takes a slow path or quietly drops the effect. For a large codebase this is the arrangement you want, because portability problems surface in one place, in the build, where they can be reported and fixed instead of showing up as visual differences between platforms.
Portability does not mean featureless. Slang code can still use capabilities specific to a platform, including the newest features in Direct3D and Vulkan, and pointers can be used when generating SPIR-V, where the reference page documents pointers as a limited feature. Interop features let you embed target code or SPIR-V directly into generated shaders, which is how hand written code gets mixed with generated code.
Modules become optional obfuscated IR that links at run time
Large shader libraries rarely build as a single translation unit, so the module system is about separate compilation. A module gives you a logical unit of organization, and modules can be compiled independently and offline into a custom IR. That IR is a project specific intermediate form, neither DXIL nor SPIR-V, and it can be obfuscated before it is written out. Those stored modules are then linked at run time to generate the final code in formats such as DXIL or SPIR-V. Shipping obfuscated IR instead of readable source changes what you hand to a studio: the shader library stops being text that anyone on the team can skim.
The cost shows up in versioning. The release cadence makes this a live problem: v2026.18.3 shipped on 2026-09-25, v2026.19 on 2026-09-29, and v2026.20 on 2026-10-17, so several compiler versions can be in service inside one month. If you precompile modules offline, you need your own rule for which compiler wrote a given IR file and for what happens when that pairing is wrong.
The build files at the top of the tree show where that offline work lives:
CMakeLists.txt
CMakePresets.json
include/
prelude/
source/
tools/
tests/Generics fail at the call site instead of cascading like C++ templates
Specialization in Slang is written with generics and interfaces, described in the documentation as type traits and protocols, and the reason to use them instead of the preprocessor is precision. Shader specialization usually arrives as macro definitions and string pasting, where the code that reaches the compiler is text nobody can point at in a debugger. Slang states the same intent directly. The check that matters is the error message: generics are pre-checked, and unlike C++ templates they do not produce cascading errors that are hard to diagnose. A mistake is reported where the specialization is written.
Timing stays under application control. One generic shader can be specialized for several different types, and that specialization can happen ahead of time or on the fly. An engine that wants a specialized variant for one surface type does not need a second shader file, and it decides when the variant is produced. The syntax itself is not in the README: for the actual spellings of generic declarations and interface conformance, the pointers are the User's Guide and the Slang Core Module Reference, which covers built-in types and functions.
Autodiff crosses control flow and dynamic dispatch
Slang can generate derivative propagation code for you. Both the forward pass and the backward pass are produced automatically, and the case that matters is complexity: the functions it handles can involve arbitrary control flow and dynamic dispatch. That is the part that sets it apart from hand written gradients. Differentiable rendering usually breaks where a shader branches or dispatches through a function table, because every path needs its own derivative chain. Because Slang generates the propagation itself, an existing rendering codebase can become differentiable without a manual rewrite, and Slang can serve as the kernel language for a PyTorch driven machine learning framework through slangtorch.
The tree carries examples aimed at that audience, including mlp-training, mlp-training-coopvec, and autodiff-texture, next to cpu-com-example and cpu-hello-world for the CPU backend and ray-tracing for the ray tracing intrinsics. The honest limit is where those examples stop. They are integration samples that link the compiler into an application and run the compiled code, and they are wired to the graphics layer described next, which the project is retiring. Read them for the structure of an autodiff setup, not as a template to copy unchanged into a codebase of your own.
GFX is being deprecated while the shipped examples still sit on it
The bundled examples show how to integrate Slang into a rendering application, and all of them sit on GFX. GFX is a graphics abstraction bundled with Slang that covers several APIs at once, listed in the README as D3D11, D2D12, OpenGL, Vulkan, CUDA, and the CPU, so a single application can use GPU graphics and compute across platforms. The project states that GFX is being deprecated in favor of slang-rhi, which lives in its own repository. The sample code in the tree is therefore written against a layer with an end date:
D3D11
D2D12
OpenGL
Vulkan
CUDA
CPUThat is the main thing Slang cannot currently hand you: a stable, supported application layer to build a product on. Copying examples/hello-world or examples/ray-tracing into a codebase means either starting on GFX and planning the move, or skipping the samples and writing the integration against slang-rhi from the start, and the second path gives up the worked examples. For language features on Vulkan, the README points outward to the Vulkan Mini Examples in nvpro-samples for pointers and the ray tracing intrinsics, which is a separate codebase to read rather than a dependency to take.
A binary release ships slangc, a shared library and slang.h
You do not have to build Slang to use it. Pre-built binary packages are published on the repository's releases page, and the same binaries are included in the Vulkan SDK from version 1.3.296.0 onward, so a project that already depends on the SDK can pick the compiler up there. Packages are built for x86_64 and aarch64 on Windows, Linux, and macOS. Each one contains the command-line slangc compiler, a shared library for the compiler, and the slang.h header, which is the set of artifacts your build system has to work with:
slangc
slang.h
share/slang/agent-skillsTwo other routes exist. The Slang Playground needs no install at all: it loads the compiler into the browser, compiles Slang to a variety of targets locally, and sends no data to any server, and can even run some simple shaders directly within the browser. Building from source is handled by docs/building.md, which the README points to instead of repeating. Packages also carry a tested snapshot of the Slang user skills under share/slang/agent-skills for assistants that support Agent Skills, offered for optional, explicit installation instead of installed by default.
The gaps sit in the operational details. No slangc invocation appears in the README, so the flags live in the user guide's command-line compilation page. Licensing also needs a look: the tree carries a LICENSE file, a LICENSES directory, and REUSE.toml, while the repository's license field reports NOASSERTION. The project is moving, with the last push landing on 2026-11-02 and the newest tag v2026.20 published on 2026-10-17.
Editorial conclusion
Slang fits teams that already maintain a large shader library across several graphics APIs and want one compile step for all of them, and it fits differentiable rendering work through autodiff and slangtorch. Before committing, check two things: whether GFX, the layer the shipped examples use, matters for your port, and whether your build process can pin a compiler version, since v2026.18.3, v2026.19 and v2026.20 arrived within a month. A single target with no ML plans gains little from the extra toolchain.
Frequently asked questions
What is Slang, the shader language?
Slang is a shading language for building and maintaining large shader codebases, created through years of collaboration between researchers at NVIDIA, Carnegie Mellon University, Stanford, MIT, UCSD and the University of Washington. Its compiler targets D3D12, Vulkan, Metal, D3D11, CUDA and the CPU.
How do I install the Slang compiler?
Take a pre-built binary package from the repository's releases page, or use the copy bundled with the Vulkan SDK since version 1.3.296.0. Packages exist for x86_64 and aarch64 on Windows, Linux and macOS, and each contains the slangc command, a shared compiler library and the slang.h header.
How does Slang handle features a target does not support?
Its capability system checks availability during the type-checking step, before final code generation, so code using a missing feature fails the compile instead of degrading at run time. Interop features also let target code or SPIR-V be embedded directly into generated shaders.
What replaces GFX in the Slang examples?
GFX is the bundled graphics abstraction over D3D11, D2D12, OpenGL, Vulkan, CUDA and the CPU, and it is being deprecated in favor of slang-rhi. The examples in the tree still use GFX, so new integration work has to plan that swap.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/shader-slang-slang)Star history chart for your README
[](https://hysenlabs.com/projects/shader-slang-slang)Was this useful?