# shader-slang/slang

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/shader-slang-slang).**

5,039 stars · 416 forks · C++ · other

## Links

- GitHub: https://github.com/shader-slang/slang
- Homepage: http://shader-slang.com
- awesome-repositories: https://awesome-repositories.com/repository/shader-slang-slang.md

## Topics

`cuda` `d3d12` `glsl` `hlsl` `shaders` `vulkan`

## Description

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.

## Tags

### Graphics & Multimedia

- [Differentiable Shader Compilers](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/shaders/cross-platform-shader-compilers/differentiable-shader-compilers.md) — A compiler that automatically generates forward and backward derivative propagation for shader functions with control flow.
- [Descriptor Heap Indexing](https://awesome-repositories.com/f/graphics-multimedia/graphics-and-media/shape-drawing/draw-call-sorters/descriptor-binding-groupers/descriptor-set-managers/descriptor-heap-indexing.md) — Indexes into descriptor heaps to access textures, samplers, and buffers without explicit binding slots. ([source](https://shader-slang.com/slang/user-guide/convenience-features.html))
- [Cross-Platform Shader Compilers](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/shaders/cross-platform-shader-compilers.md) — Provides a compiler that translates a single shader source into platform-specific GPU binaries for multiple graphics APIs.
- [Multi-API Shader Compilations](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/shaders/cross-platform-shader-compilers/multi-api-shader-compilations.md) — Generates GPU kernel code for different graphics APIs from a single shader source in one compilation session. ([source](https://shader-slang.com/slang/user-guide/compiling.html))
- [Modular Shader Languages](https://awesome-repositories.com/f/graphics-multimedia/modular-shader-languages.md) — A shader language with modules, generics, interfaces, and separate compilation for building reusable shader libraries.
- [Module-Based Separate Compilation](https://awesome-repositories.com/f/graphics-multimedia/modular-shader-languages/module-based-separate-compilation.md) — Slang organizes shading code into modules with primary and included files, enforcing boundaries and enabling separate compilation. ([source](https://shader-slang.com/slang/user-guide/modules.html))
- [Shader Derivative Generators](https://awesome-repositories.com/f/graphics-multimedia/shader-derivative-generators.md) — Automatically derives forward and backward mode derivative functions for any differentiable function, supporting control flow and dynamic dispatch. ([source](https://shader-slang.com/slang/user-guide/autodiff.html))
- [Descriptor Heap Binding Models](https://awesome-repositories.com/f/graphics-multimedia/graphics-and-media/shape-drawing/draw-call-sorters/descriptor-binding-groupers/descriptor-set-managers/descriptor-heap-binding-models.md) — Accesses textures, samplers, and buffers through descriptor heap indices instead of explicit binding slots.
- [Resource Descriptor Definitions](https://awesome-repositories.com/f/graphics-multimedia/graphics-and-media/shape-drawing/draw-call-sorters/descriptor-binding-groupers/descriptor-set-managers/resource-descriptor-definitions.md) — Index into descriptor heaps to access textures, samplers, and buffers without explicit binding slots for modern graphics APIs.
- [Platform Capability Adaptations](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/shaders/cross-platform-shader-compilers/platform-capability-adaptations.md) — Checks GPU feature support at compile time and adapts shader code to ensure cross-platform compatibility. ([source](http://shader-slang.com/docs/llms.txt#slang))
- [Shader Operation Compatibility Checks](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/shaders/cross-platform-shader-compilers/shader-operation-compatibility-checks.md) — Checks that each operation used in shader code is available on the target graphics API and shader stage before code generation. ([source](https://shader-slang.com/slang/user-guide/capabilities.html))
- [Intrinsic Mapping Frameworks](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/shaders/shader-cross-compilation-pipelines/runtime-shader-compilers/intrinsic-mapping-frameworks.md) — Ships a framework for mapping shader functions to target-specific code snippets and injecting custom code per compilation target.
- [Runtime Shader Inspections](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/shaders/shader-cross-compilation-pipelines/runtime-shader-compilers/runtime-shader-inspections.md) — Provides runtime inspection of shader parameter layouts and generates specialized variants at link time. ([source](http://shader-slang.com/docs/llms.txt#slang))
- [Shader Compilation Orchestrations](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/shaders/shader-cross-compilation-pipelines/runtime-shader-compilers/shader-compilation-orchestrations.md) — Enables loading, composing, linking, and generating GPU kernel code from shader modules via a full-control API. ([source](https://shader-slang.com/slang/user-guide/compiling.html))
- [Shader Compilation Pipeline Controllers](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/shaders/shader-cross-compilation-pipelines/shader-compilation-pipeline-controllers.md) — Inspects shader parameter layouts, specializes variants, and links entry points through a fine-grained API or command line.
- [Modular Shader Development Environments](https://awesome-repositories.com/f/graphics-multimedia/modular-shader-development-environments.md) — Organizes shading code into independently compilable modules with imports, generics, and visibility control for type-safe reuse.

### Artificial Intelligence & ML

- [Compiler Differentiation Passes](https://awesome-repositories.com/f/artificial-intelligence-ml/automatic-differentiation-frameworks/compiler-differentiation-passes.md) — Generates forward and backward derivative code automatically for functions with control flow and dynamic dispatch.
- [Shader](https://awesome-repositories.com/f/artificial-intelligence-ml/automatic-differentiation/shader.md) — Generate forward and backward derivative code automatically for any shader function to support gradient-based optimization in graphics.
- [Custom Derivative Implementations](https://awesome-repositories.com/f/artificial-intelligence-ml/custom-derivative-implementations.md) — Overrides compiler-generated derivatives with custom forward, backward, or primal substitute functions for accuracy or intrinsic operations. ([source](https://shader-slang.com/slang/user-guide/autodiff.html))

### Programming Languages & Runtimes

- [Generic Types](https://awesome-repositories.com/f/programming-languages-runtimes/generic-types.md) — Writes reusable functions and types parameterized by types or compile-time values with constraints and variadic support. ([source](https://shader-slang.com/slang/user-guide/interfaces-generics.html))
- [Modular Generic Shader Code](https://awesome-repositories.com/f/programming-languages-runtimes/generic-types/modular-generic-shader-code.md) — Writes modular shader code that imports modules and uses generic interfaces for type-safe reuse. ([source](http://shader-slang.com/docs/llms.txt#slang))
- [Module Importing](https://awesome-repositories.com/f/programming-languages-runtimes/module-importing.md) — Provides a module import system that loads public symbols from external shader modules into scope. ([source](https://shader-slang.com/slang/user-guide/modules.html))
- [Multi-Target Compilers](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-compilers/multi-target-compilers.md) — Compiles shader source to multiple GPU APIs and intermediate representations from a single compilation session.
- [Code Definition Namespaces](https://awesome-repositories.com/f/programming-languages-runtimes/code-definition-namespaces.md) — Groups shader symbols into namespaces to prevent naming conflicts across large projects. ([source](https://shader-slang.com/slang/user-guide/convenience-features.html))
- [Compile-Time Attribute Parameterization](https://awesome-repositories.com/f/programming-languages-runtimes/generic-types/compile-time-attribute-parameterization.md) — Passes generic value parameters to shader entry-point attributes for host-controlled specialization. ([source](https://shader-slang.com/slang/user-guide/interfaces-generics.html))
- [Interface Contracts](https://awesome-repositories.com/f/programming-languages-runtimes/generic-types/interface-contracts.md) — Defines required methods and properties that concrete types must provide, with optional defaults and generic support. ([source](https://shader-slang.com/slang/user-guide/interfaces-generics.html))
- [Interface and Any Types](https://awesome-repositories.com/f/programming-languages-runtimes/interface-and-any-types.md) — Declares parameters and variables with interface types and casts them to concrete types using is and as. ([source](https://shader-slang.com/slang/user-guide/interfaces-generics.html))
- [Type Extensions](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/language-extensions/type-extensions.md) — Adds new interface conformances or methods to existing types and applies methods to all interface implementers. ([source](https://shader-slang.com/slang/user-guide/interfaces-generics.html))
- [Struct Methods and Operators](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/data-structure-type-helpers/data-structures/struct-generators/struct-property-accessors/struct-methods-and-operators.md) — Adds member functions, properties, constructors, and operator overloads to structs for encapsulated behavior. ([source](https://shader-slang.com/slang/user-guide/convenience-features.html))
- [Tuple and Optional Types](https://awesome-repositories.com/f/programming-languages-runtimes/runtime-execution-environments/runtime-environments/runtimes/type-definition-systems/conditional-types/tuple-and-optional-types.md) — Composes heterogeneous collections, nullable values, and conditionally compiled fields with built-in type constructors. ([source](https://shader-slang.com/slang/user-guide/convenience-features.html))
- [Per-Target Intrinsic Mappings](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-compilers/multi-target-compilers/per-target-intrinsic-mappings.md) — Provides per-target intrinsic mappings that switch based on the compilation target using case labels. ([source](https://shader-slang.com/slang/user-guide/a1-04-interop.html))
- [Type Visibility Controls](https://awesome-repositories.com/f/programming-languages-runtimes/type-visibility-controls.md) — Controls symbol visibility at type, module, and global levels with public, internal, and private modifiers. ([source](https://shader-slang.com/slang/user-guide/modules.html))
- [Target-Specific Type Mappings](https://awesome-repositories.com/f/programming-languages-runtimes/user-defined-types/target-specific-type-mappings.md) — Replaces declared structs or types with target-specific types in generated output for direct use of native library types. ([source](https://shader-slang.com/slang/user-guide/a1-04-interop.html))

### Software Engineering & Architecture

- [Shader](https://awesome-repositories.com/f/software-engineering-architecture/modular-extension-systems/codebase-modularization/shader.md) — Ships a modular shader codebase system with independent compilation and type-safe generic reuse. ([source](https://cdn.jsdelivr.net/gh/shader-slang/slang@master/README.md))

### Data & Databases

- [Compile-Time Capability Checks](https://awesome-repositories.com/f/data-databases/type-inspection-tools/compile-time-capability-checks.md) — Verifies at compile time that each operation is available on the target API and shader stage before code generation.

### Development Tools & Productivity

- [Shader Intrinsic Mappings](https://awesome-repositories.com/f/development-tools-productivity/custom-task-functions/compiler-functions/intrinsic-function-declarations/shader-intrinsic-mappings.md) — Implements a system for mapping shader function calls to target-specific code snippets using argument and type placeholders. ([source](https://shader-slang.com/slang/user-guide/a1-04-interop.html))
- [Target-Specific Intrinsic Mappings](https://awesome-repositories.com/f/development-tools-productivity/custom-task-functions/compiler-functions/intrinsic-function-declarations/target-specific-intrinsic-mappings.md) — Maps shader function calls to target-specific code snippets using argument and type placeholders for each platform.
- [Shader Module Compilation](https://awesome-repositories.com/f/development-tools-productivity/extension-compilers/extension-module-compilers/shader-module-compilation.md) — Organises shading code into independently compilable modules with explicit import and export symbols to avoid duplicate compilation.

### Testing & Quality Assurance

- [Shader](https://awesome-repositories.com/f/testing-quality-assurance/debugging-diagnostics/error-handling/shader.md) — Adds explicit error propagation via throw, try, and catch statements for robust shader code. ([source](https://shader-slang.com/slang/user-guide/convenience-features.html))

### Web Development

- [Target-Specific Code Injections](https://awesome-repositories.com/f/web-development/content-insertion-utilities/dynamic-content-insertion/marker-based-injection-utilities/source-code-injection/target-specific-code-injections.md) — Inserts target-specific code into generated shader output with automatic deduplication of identical prelude strings. ([source](https://shader-slang.com/slang/user-guide/a1-04-interop.html))
