Introduction
A .slang file holds shader code written in
Slang, a shading language that builds on
HLSL and adds modules, interfaces and generics, and
automatic differentiation. One Slang source can be compiled for many targets, among
them SPIR-V, DXIL, HLSL, GLSL,
CUDA, Metal and
WGSL. The project is open source, under the Apache 2.0
licence with an LLVM exception.
The compiler, slangc, takes a .slang file and a target and
writes the result. Slang can also compile a file into a binary module, a
.slang-module file, that other code imports without compiling the source
again.
Structure
A Slang file is plain text, and its syntax extends that of HLSL. A shader is an entry-point function marked with an
attribute such as [shader("compute")], and attributes like
[numthreads(1,1,1)] are used as in HLSL. Buffers are declared as in HLSL,
for example StructuredBuffer<float> and
RWStructuredBuffer<float>. One file pulls in another module with
import my_library;.
StructuredBuffer<float> buffer0;
RWStructuredBuffer<float> result;
[shader("compute")]
[numthreads(1, 1, 1)]
void computeMain(uint3 threadId : SV_DispatchThreadID)
{
uint i = threadId.x;
result[i] = buffer0[i] * 2.0;
}
slangc scale.slang -target spirv -o scale.spv.Not described
Known, not yet covered
- Reference: this overview is the only page. The language has no reference pages: the types and generics, interfaces and associated types, modules and the
importand__includerules, automatic differentiation ([Differentiable]), the parameter and resource binding rules, the attributes, and the differences from HLSL. The Slang user guide describes them. - Reference: the
slangccommand-line options, the list of targets and profiles, the.slang-modulebinary module format and the compilation API are not described. - Viewer: there is no viewer for this format yet, and nothing is compiled or checked.
Links
Software
- Slang – the
slangccompiler and the Slang libraries, open source (Windows, macOS, Linux)
Developers
- Slang – the project’s site
Reference
- Slang user guide: introduction – what the language adds to HLSL and its targets
- Slang user guide: compiling code –
slangc, modules and file names