slayout is a domain-specific language (DSL) and compiler designed to simplify and unify shader layout definitions across multiple shading languages and graphics backends.
It allows you to reuse parts of shader code and define macros to only write one shader instead of one for each format. After defining only one layout and one shader, you can use this CLI tool to generate other shader formats.
Writing shaders for multiple backends like GLSL, HLSL, MSL, or SPIR-V often requires duplicating layout declarations, adapting syntax, and maintaining parallel versions.
slayout solves this by allowing you to define reusable macros and backend-specific layout mappings in a simple scripting language. It replaces layout macros inside your shader files with the appropriate backend-specific code automatically during preprocessing.
It is very useful for renderers that support many backends, such as Ogre
- Define reusable macros using custom layout identifiers.
- Assign backend-specific code for:
GLSLHLSLMSLSPIR-V
- Fallback to a default layout when backend-specific one is not defined.
- Lazy mode for passthrough macros.
- Boolean variables and conditional execution (
ifstatements). - Print debug information at runtime.
- File includes via
read_*()functions. stringvariable support with automatic concatenation.
- C++17 or newer compiler (e.g.
clang++,g++) - CMake version 3.15 or higher
git clone https://github.com/sssarana/slayout.git
cd slayout
mkdir build && cd build
cmake ..
cmake --build .This will build the CLI tool slayoutc inside build/bin.
Want to learn how to use the language? Check out USAGE.md for syntax guide. You can also find examples of typical use cases in examples/ folder.
Slayout Tools extension enables syntax highlighting for .slayout files and macro highlighting for shaders.
When hovering on the macro, it will display all backend-specific code associated with it, like this:
To find this extension you can search for Slayout Tools or follow the link provided above.
Enjoy!


