Slang

使得使用着色器更容易。Slang 是一种着色语言,它使人们更容易以模块化和可扩展的方式建立和维护大型着色器代码库,同时还能在现代 GPU 和图形 API 上保持尽可能高的性能。「Making it easier to work with shaders. Slang is a shading language that makes it easier to build and maintain large shader codebases in a modular and extensible fashion, while also maintaining the highest possible performance on modern GPUs and graphics APIs.」

Github星跟踪图

Slang

AppVeyor build status Travis build status

Slang is a shading language that makes it easier to build and maintain large shader codebases in a modular and extensible fashion, while also maintaining the highest possible performance on modern GPUs and graphics APIs.
Slang is based on years of collaboration between researchers at NVIDIA, Carnegie Mellon University, and Stanford.

Key Features

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

  • Slang is backwards-compatible with most existing HLSL code. It is possible to start taking advantage of Slang's benefits without rewriting or porting your shader codebase.

  • The Slang compiler can generate code for a wide variety of targets and APIs: D3D12, Vulkan, D3D11, OpenGL, CUDA, and CPU. Slang code can be broadly portable, but still take advantage of the unique features of each platform.

  • Parameter blocks (exposed as ParameterBlock<T>) provide a first-class language feature for grouping related shader parameters and specifying that they should be passed to the GPU as a coherent block. Parameter blocks make it easy for applications to use the most efficient parameter-binding model of each API, such as descriptor tables/sets in D3D12/Vulkan.

  • Generics and interfaces allow shader specialization to be expressed cleanly without resort 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.

  • 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.

  • Rather than require tedious explicit register and layout specifications on each shader parameter, Slang supports completely automate and deterministic assignment of binding locations to parameter. You can write simple and clean code and still get the deterministic layout your application wants.

  • For applications that want it, Slang provides full reflection information about the parameters of your shader code, with a consistent API across all target platforms and graphics APIs. Unlike some other compilers, Slang does not reorder or drop shader parameters based on how they are used, so you can always see the full picture.

Getting Started

If you want to try out the Slang language without installing anything, you may want to use the Shader Playground website.
We have written up some tips on how to use Slang from within Shader Playground.

The fastest way to get started using Slang in your own development is to use a pre-built binary package, available through GitHub releases.
There are packages built for 32- and 64-bit Windows, as well as 64-bit Ubuntu.
Each binary release includes the command-line slangc compiler, a shared library for the compiler, and the slang.h header.

If you would like to build Slang from source, please consult the build instructions.

Documentation

The Slang project provides a variety of different documentation, but most users would be well served starting with the User's Guide.

We also provide a few examples of how to integrate Slang into a rendering application.

Contributing

If you'd like to contribute to the project, we are excited to have your input.
The following guidelines should be observed by contributors:

  • Please follow the contributor Code of Conduct.
  • Bugs reports and feature requests should go through the GitHub issue tracker
  • Changes should ideally come in as small pull requests on top of master, coming from your own personal fork of the project
  • Large features that will involve multiple contributors or a long development time should be discussed in issues, and broken down into smaller pieces that can be implemented and checked in in stages

Limitations

The Slang project has been used for production applications and large shader codebases, but it is still under active development.
Support is currently focused on the platforms (Windows, Linux) and target APIs (Direct3D 12, Vulkan) where Slang is used most heavily.
Users who are looking for support on other platforms or APIs should coordinate with the development team via the issue tracker to make sure that their use case(s) can be supported.

License

The Slang code itself is under the MIT license (see LICENSE).

Builds of the core Slang tools depend on the following projects, either automatically or optionally, which may have their own licenses:

The Slang tests (which are not distributed with source/binary releases) include example HLSL shaders extracted from the Microsoft DirectX SDK, which has its own license

Some of the tests and example programs that build with Slang use the following projets, which may have their own licenses:

  • glm (MIT)
  • stb_image and stb_image_write from the stb collection of single-file libraries (Public Domain)
  • tinyobjloader (MIT)

主要指标

概览
名称与所有者shader-slang/slang
主编程语言C++
编程语言C++ (语言数: 12)
平台
许可证Other
所有者活动
创建于2017-06-09 17:42:49
推送于2025-04-26 19:04:01
最后一次提交2025-04-26 21:04:01
发布数551
最新版本名称v2025.7.1 (发布于 )
第一版名称v0.1.0 (发布于 2017-06-27 09:37:01)
用户参与
星数3.9k
关注者数55
派生数279
提交数4.5k
已启用问题?
问题数2516
打开的问题数372
拉请求数4023
打开的拉请求数45
关闭的拉请求数266
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?