Skip to content
Open
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
compiler: gcc
compiler_version: "14"
python: 3.13
test_slang: ON
extended_build_perfetto: ON
extended_cmake_config: -DMATERIALX_BUILD_PERFETTO_TRACING=ON

Expand Down Expand Up @@ -298,6 +299,20 @@ jobs:
python python/Scripts/generateshader.py resources/Materials/Examples --target msl --validator "xcrun metal --language=metal" --validatorArgs="-w"
python python/Scripts/generateshader.py resources/Materials/TestSuite/stdlib --target msl --validator "xcrun metal --language=metal" --validatorArgs="-w"

- name: Shader Validation Tests (Slang)
if: matrix.test_slang == 'ON' && runner.os == 'Linux'
run: |
SLANG_VERSION=2026.10.2
curl -fsSL -o slang.tar.gz "https://github.com/shader-slang/slang/releases/download/v${SLANG_VERSION}/slang-${SLANG_VERSION}-linux-x86_64.tar.gz"
mkdir -p slang-release
tar -xzf slang.tar.gz -C slang-release
export LD_LIBRARY_PATH="$PWD/slang-release/lib:$PWD/slang-release/bin:$LD_LIBRARY_PATH"
SLANGC="$PWD/slang-release/bin/slangc"
chmod +x "$SLANGC"
"$SLANGC" -v
python python/Scripts/generateshader.py resources/Materials/Examples/StandardSurface --target slang --validator "$SLANGC"
python python/Scripts/generateshader.py resources/Materials/TestSuite/stdlib --target slang --validator "$SLANGC"

- name: Coverage Analysis Tests
if: matrix.coverage_analysis == 'ON'
run: |
Expand Down
2 changes: 1 addition & 1 deletion libraries/stdlib/genslang/lib/mx_texture.slang
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct SamplerTexture2D
tex.GetDimensions(0, width, height, numberOfLevels);
return numberOfLevels;
}
}
};

float4 textureLod(SamplerTexture2D tex, float2 uv, float lod)
{
Expand Down
6 changes: 3 additions & 3 deletions python/Scripts/generateshader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
'''
Generate shader code for each renderable element in a MaterialX document or folder.
The currently supported target languages are GLSL, ESSL, MSL, OSL, and MDL.
The currently supported target languages are GLSL, ESSL, Vulkan, WGSL, MSL, Slang, OSL, and MDL.
'''

import sys, os, argparse, subprocess
Expand Down Expand Up @@ -47,7 +47,7 @@ def main():
parser = argparse.ArgumentParser(description='Generate shader code for each renderable element in a MaterialX document or folder.')
parser.add_argument('--path', dest='paths', action='append', nargs='+', help='An additional absolute search path location (e.g. "/projects/MaterialX")')
parser.add_argument('--library', dest='libraries', action='append', nargs='+', help='An additional relative path to a custom data library folder (e.g. "libraries/custom")')
parser.add_argument('--target', dest='target', default='glsl', help='Target shader generator to use (e.g. "glsl, osl, mdl, essl, vulkan, wgsl"). Default is glsl.')
parser.add_argument('--target', dest='target', default='glsl', help='Target shader generator to use (e.g. "glsl, essl, vulkan, wgsl, msl, slang, osl, mdl"). Default is glsl.')
parser.add_argument('--outputPath', dest='outputPath', help='File path to output shaders to. If not specified, is the location of the input document is used.')
parser.add_argument('--validator', dest='validator', nargs='?', const=' ', type=str, help='Name of executable to perform source code validation.')
parser.add_argument('--validatorArgs', dest='validatorArgs', nargs='?', const=' ', type=str, help='Optional arguments for code validator.')
Expand Down Expand Up @@ -158,7 +158,7 @@ def main():
if shader:
# Use extension of .vert and .frag as it's type is
# recognized by glslangValidator
if gentarget in ['glsl', 'essl', 'vulkan', 'msl', 'wgsl']:
if gentarget in ['glsl', 'essl', 'vulkan', 'msl', 'wgsl', 'slang']:
pixelSource = shader.getSourceCode(mx_gen_shader.PIXEL_STAGE)
filename = pathPrefix + "/" + shader.getName() + "." + gentarget + ".frag"
print('--- Wrote pixel shader to: ' + filename)
Expand Down
6 changes: 3 additions & 3 deletions source/MaterialXGenSlang/SlangShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void SlangShaderGenerator::emitInputs(GenContext& context, ShaderStage& stage) c
emitLine("struct " + vertexInputs.getName(), stage, false);
emitScopeBegin(stage);
emitVariableDeclarations(vertexInputs, _syntax->getInputQualifier(), Syntax::SEMICOLON, context, stage, false);
emitScopeEnd(stage);
emitScopeEnd(stage, true);
emitLineBreak(stage);

for (size_t i = 0; i < vertexInputs.size(); ++i)
Expand All @@ -398,7 +398,7 @@ void SlangShaderGenerator::emitInputs(GenContext& context, ShaderStage& stage) c
{
emitVariableDeclarations(vertexData, EMPTY_STRING, Syntax::SEMICOLON, context, stage, false);
}
emitScopeEnd(stage, false, false);
emitScopeEnd(stage, true);
emitLineBreak(stage);
emitLine("static " + vertexData.getName() + " vd", stage);
}
Expand All @@ -416,7 +416,7 @@ void SlangShaderGenerator::emitOutputs(GenContext& context, ShaderStage& stage)
{
emitVariableDeclarations(vertexData, EMPTY_STRING, Syntax::SEMICOLON, context, stage, false);
}
emitScopeEnd(stage);
emitScopeEnd(stage, true);
emitLineBreak(stage);
emitLineBreak(stage);
}
Expand Down
Loading