Overview of the slang-generate tool
masterslang-generate tool is a utility used to generate boilerplate code specifically for the Slang compiler implementation. It is located in the tools/slang-generate/ directory.repository·master·Indexed 26 days ago
https://github.com/shader-slang/slangA shader language and compiler featuring a reflection API and support for multiple targets including CPU, CUDA, DXIL, WGSL, and WebGPU. The project includes the slangc command-line tool, slang-coverage for HTML coverage reports, and a comprehensive build system for managing dependencies like glslang, spirv-tools, and DXC.
slang-generate tool is a utility used to generate boilerplate code specifically for the Slang compiler implementation. It is located in the tools/slang-generate/ directory.Generics in Slang allow you to parameterize various language constructs, enabling code reuse and abstraction. You can use generics with:
struct)interface)typealias)func or traditional syntax)__subscript)__init)Generic parameters can be:
When generic parameters are bound, the generic type or function is specialized into a concrete entity. Binding can occur via:
Note: Value-typed arguments used for binding must be link-time constants.
Slang's auto-diff processing follows a multi-step workflow managed by AutoDiffPass::processReferencedFunctions. The process is iterative to support nested differentiation (e.g., IRForwardDifferentiate(IRBackwardDifferentiate(...))):
IRForwardDifferentiate or IRBackwardDifferentiate. The subject can be an IRFunc, an IRSpecialize (for generic methods), or an IRLookupWitness (for interface methods).AutodiffTranscriberBase). The transcriber replaces the request with a generated derivative function or a call to an existing derivative function.The slang-coverage tools are two Python 3 utilities designed to generate static-HTML coverage reports from standard coverage data formats. They are project-neutral and do not require external dependencies like pip, Perl (genhtml), or .NET.
slang-coverage-html: Renders a single coverage input file into a directory of static HTML. It supports LCOV (.info, .lcov, or gzipped versions) and llvm-cov JSON exports (.json or gzipped versions). The format is automatically determined by the file extension.slang-coverage-merge: Combines multiple LCOV inputs (e.g., from different CI hosts) into a single merged LCOV file using max-aggregation. Note that this tool only supports LCOV; for JSON inputs, you should render each file individually to HTML instead of merging.Slang is a shading language and compiler system designed for real-time graphics. It extends HLSL with modern programming features while maintaining high GPU performance. Key features include:
The slang-coverage toolset provides utilities for rendering code coverage data into HTML reports and merging multiple coverage files. It consists of two primary CLI tools:
slang-coverage-html.py: A renderer that converts coverage data into an interactive HTML report.slang-coverage-merge.py: A utility to merge multiple LCOV files (e.g., from different operating systems) into a single report.The tools support both LCOV input (typically used for shader coverage on Windows) and llvm-cov export -format=json input (typically used for C++ coverage on Linux/macOS).
Slang program execution follows a hierarchy of workloads, entry point invocations, and threads.
Slang uses a capability system to handle cross-platform shader programming. A capability is a discrete feature that a compilation target either supports or does not support (e.g., fragment stage, vulkan API, or specific hardware features like implicit_gradient_texture_fetches).
Capabilities solve two primary problems:
#ifdef blocks.In multi-threaded Slang programs, a data race occurs when two threads access the same memory location, at least one access is a write, and they use non-atomic accesses without an established happens-before relationship.
To avoid data races, ensure that:
Warning: slangc currently emits incorrect code for Atomic<T> for multiple targets (see GitHub issue #10683).
The external/ directory contains all third-party dependencies required by Slang. It is organized into four types of content:
git submodule update --init --recursive. Examples include glslang, spirv-tools, vulkan, glm, and imgui.dxc/, stb/, spirv/).glslang-generated/ and spirv-tools-generated/ that are generated out-of-band by maintainer scripts and committed to avoid regeneration during normal builds.slang-tint, webgpu_dawn, slang-llvm, and DXC. Some have source-build fallbacks.Shader coverage in Slang is implemented through two distinct mechanisms to handle runtime instrumentation without polluting the public language surface:
Binding (Where the buffer is): Slang synthesizes a __slang_coverage buffer (either RWStructuredBuffer<uint64_t> or RWStructuredBuffer<uint> depending on the -trace-coverage-counter-width flag) during the IR-pass. This buffer is hidden from Slang's public reflection (e.g., IComponentType::getLayout()). To find and bind this buffer, hosts must consult ISyntheticResourceMetadata to determine the correct slot for their pipeline-layout, root-signature, or descriptor-set machinery.
Attribution (What the counters mean): To map runtime counter values back to source code locations (files, lines, functions), Slang uses ICoverageTracingMetadata and its on-disk sidecar format. This provides the semantic intent that standard reflection lacks.
A host requires both mechanisms: ISyntheticResourceMetadata to allocate and bind the buffer, and ICoverageTracingMetadata to interpret the data read back from the GPU.