IN THIS ARTICLE
Shader Build Pipeline
Shaders in Atom are written in the Amazon Shading Language (AZSL), coupled with specialized configuration files that add various metadata.
Shaders are made up of several files:
*.azsl: The main AZSL source file that contains the shader program.
*.shader: References the .azsl file and attaches metadata to configure the shader for compiling.
*.azsli: (Optional) Contains reusable AZSL code, which is intended to be included in .azsl files.
*.srgi: (Optional) Contains AZSL code, which combines partial SRGs.
.shadervariantlist: (Optional) Describes what shader variants must be compiled for a given .shader file.
AZSL is a variation of HLSL, with a few extensions that make it easier to author and maintain shaders. Most programming rules that apply to AZSL are the same for HLSL. You can refer to the AZSL and Compiler section and the Microsoft DirectX HLSL documentation for more details.
There are a few key extensions of AZSL, which affect the shader build pipeline:
Shader Resource Groups (SRGs): A container for application visible variables, which are defined in code with the class
ShaderResourceGroup. SRGs can be defined in
.azslfiles as partial SRGs, which define only a portion of an SRG. You can combine the partial SRGs in a single
.srgifile. Learn more about SRGs in the AZSL section.
Shader variant options: Application visible variables, which the developer can choose to compile as static constants or as regular global variables. The compiled shader code results in shader variants, or variations of the shader code, which minimize branching in runtime. You can specify the variants you want to pre-build in a
.shadervariantlistfile. Learn more about shader variant options .
.azsl file is the main source file that contains AZSL code and shader programs. Atom currently supports vertex, pixel (or fragment), compute, and raytracing shaders. The
.azsl file might also include other files with reusable AZSL code, like
.shader files are written in JSON. They reference the main AZSL source file (
*.azsl) and add a variety of metadata for configuring AZSLc and indicating how the render pipeline should use this shader.
.azsli files contain AZSL code that is meant to be reused and shared among multiple
.azsl files. The
.azsli extension is simply a naming convention to indicate that the file contains reusable AZSL code and should be included by
.azsl files; otherwise,
.azsli files are virtually identical to the
.srgi files are specialized AZSL files that are used to merge multiple partial SRG definitions into a single SRG asset. This allows multiple Gems to contribute their own resources to a common SRG, like the SceneSrg or ViewSrg.
The Asset Processer has several builders that work together to process shader files and produce all of the assets that are needed in runtime. These shader assets and shader variant assets are most often used by the pass system or by the material system.
The shader build pipeline consists of the following processes:
- The Shader Asset Builder converts the
.shaderfile into a
.azshaderfile, known as a shader asset. It also produces a shader variant asset (
*.azshadervariant) for the root shader variant, which is the main variant of the shader and is the default bytecode that’s used for rendering.
- The Amazon Shading Language Compiler (AZSLc) and platform compilers compile the
.azslfile by transpiling AZSL to HLSL (Shader Model 6.3).
- The target platform’s shader compiler compiles the HLSL code.
The Shader System uses the following shader compilers for supported platforms:
- D3D12: DirectX shader compiler with DXT emission.
- Vulkan: DirectX shader compiler with SpirV emission.
- Metal: DirectX shader compiler and SPIRV-Cross to generate metalSL emission.
Copyright © 2022 Open 3D Engine Contributors
Documentation Distributed under CC BY 4.0.
The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our Trademark Policy page.