Skip to content
Making it easier to work with shaders
Branch: master
Clone or download
jsmall-nvidia Hotfix/dx12 cubemap lookup (#921)
* Disable Dx12 half tests. The half-calc test runs, but is not actually doing any half maths. If the code is changed such that it is, the device fails when the shader is used. This can be seen by looking at dxil-asm.

* Fix using software driver for dx12 even when hardware is requested.

* * Refactor Dx12 _createAdapter such that it doesn't have side effects and stores desc information
* Disable half on dx12 software renderer because it crashes

* * Disable erroneous warnings from dx12
* Test for adapter creation
* Identify warp specifically

* Structured buffer test now works on dx12.

* Fix intemittent crash on dx12.
Due to if a resource was initialized with data, the actual resource constructed might be larger, for alignment issues. This led to a memcpy potentially copying from after the allocated source data and therefore a crash. Now only copies the non aligned amount of data.

* * Rename the test to use - style
* Disable TextureCube lookup in tests, as does not produce the correct result in dx12 (will fix in future PR)

* Updated hlsl.meta.slang.h that has rcp for glsl.

* * Fix bug where the SRV description was incorrect for cubemaps on dx12
* Re-enable cube map access in dx12 tests
* Slightly re-organize texture upload on dx12 to not repeatidly create and destroy upload resource for array/cube scenarios
Latest commit 5bdc3ef Mar 21, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Add options to control optimization and debug information (#897) Mar 12, 2019
examples Improve support for interfaces as shader parameters (#886) Mar 9, 2019
external Upgraded vulkan headers to v1.1.103 (#909) Mar 15, 2019
source Hotfix/dx12 tests use hardware (#920) Mar 21, 2019
tests Hotfix/dx12 cubemap lookup (#921) Mar 21, 2019
tools Hotfix/dx12 cubemap lookup (#921) Mar 21, 2019
.editorconfig Add an EditorConfig file (#474) Apr 4, 2018
.travis.yml Create Jul 26, 2017
Makefile Update Sep 28, 2018
slang-com-helper.h Feature/shared library refactor (#712) Nov 6, 2018
slang.h * Added ToolReturnCode to be more rigerous about how a return code is… Mar 18, 2019
test.bat Running tests in slang-test process (#740) Dec 12, 2018


AppVeyor build status Travis build status

Slang is a shading language that extends HLSL with new capabilities for building modular, extensible, and high-performance real-time shading systems. This repository provides a command-line compiler and a C/C++ API for loading, compiling, and reflecting shader code in Slang or plain HLSL.

The extensions provided by the Slang language make it easier for you to write high-performance shader codebases with a maintainable and modular structure. For example:

  • Parameter blocks (exposed as ParameterBlock<T>) let you group together related shader parameters -- both simple uniform values and resources like samplers/textures - in ordinary struct types, and then specify that they should be passed to the GPU as a single coherent block. Your application code can easily map a parameter block to abstractions like descriptor tables/sets on D3D12/Vulkan, or to the facilities provided by other APIs.

  • Generics and interfaces can be used to perform static specialization of your shader code without resort to preprocessor techniques or string-pasting. Unlike C++ templates, Slang's generics can be 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.

The Slang implementation in this repository provides a library and a stand-alone compiler for Slang that can be used to:

  • Compile your HLSL or Slang code to DX bytecode, DXIL, SPIR-V, or plain source code in HLSL or GLSL.

  • Get full reflection information about the parameters of your shader code, with a consistent interface no matter the target graphics API. Slang doesn't silently drop unused or "dead" shader parameters from the reflection data, so you can always see the full picture.

  • Take ordinary HLSL code that neglects to include all those tedious register and layout bindings, and transform it into code that includes explicit bindings on every shader parameter. This frees you to write simple and clean code, while still getting completely deterministic binding locations.

Getting Started

The fastest way to get started with Slang 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. A 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 instructions here.


For users getting started with Slang, it may help to start by looking at our example programs:

  • The hello-world example shows the basics for integrating the Slang API into an application as a more-or-less drop-in replacement for D3DCompile.

  • The model-viewer example shows a more involved rendering application that uses Slang's new language features to perform efficient shader specialization and parameter binding while maintaining clear and modular shader code.

A paper on the Slang system was accepted into SIGGRAPH 2018, and it provides an overview of the language and the compiler implementation. See also Yong He's dissertation for the detailed thinking behind the design of the Slang system.

The Slang language guide provides information on extended language features that Slang provides for user code.

The API user's guide gives information on how to drive Slang programmatically from an application.

If you want to try out the slangc command-line tool, then you will want to read its documentation. Be warned, however, that the command-line tool is primarily intended for experimenting, testing, and debugging; serious applications will likely want to use the API interface.


The Slang project is in an early state, so there are many rough edges to be aware of. Slang is not currently recommended for production use. The project is intentionally on a pre-1.0.0 version to reflect the fact that interfaces and features may change at any time (though we try not to break user code without good reason).

Major limitations to be aware of (beyond everything files in the issue tracker):

  • Slang only officially supports outputting GLSL/SPIR-V for Vulkan, not OpenGL

  • Slang's current approach to automatically assigning registers is appropriate to D3D12, and is not ideal for D3D11

  • Slang-to-GLSL cross-compilation only supports vertex, fragment, and compute shaders. Geometry and tessellation shader cross-compilation is not yet implemented.

  • The Slang front-end does best-effort checking of HLSL input, but it is challenging to achieve 100% compatibility. Bug reports and pull requests related to HLSL feature support are welcome.

  • Translations from Slang/HLSL constructs to GLSL equivalents has been done on as as-needed basis, so it is likely that new users will run into unimplemented cases.


If you'd like to contribute to the project, we are excited to have your input. We don't currently have a formal set of guidelines for contributors, but here's the long/short of it:

  • 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


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

The Slang projet can be compiled to use the glslang project as a submodule (under external/glslang), and glslang is under a BSD license.

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 Slang examples and tests use the stb_image and stb_image_write libraries (under external/stb) which have been placed in the public domain by their author(s).

You can’t perform that action at this time.