From 43985cc3d65fb60cf8045c5ae10d50e66c3a507c Mon Sep 17 00:00:00 2001 From: Krishna Date: Fri, 12 Jun 2026 18:00:36 -0700 Subject: [PATCH 1/4] Add CI coverage for Slang shader validation Slang shaders were generated in CI (--target slang) but never compiled, unlike GLSL (Windows) and MSL (macOS) which run a real validator. Add a Slang validation step that downloads the prebuilt slangc release and runs generateshader.py with slangc as the --validator, gated behind a new test_slang matrix flag on a Linux runner. Also update generateshader.py docs to list all currently supported targets (incl. Slang). Refs: AcademySoftwareFoundation/MaterialX#2668 Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/main.yml | 13 +++++++++++++ python/Scripts/generateshader.py | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 90c096f336..cff22a3260 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -297,6 +298,18 @@ 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 + SLANGC="$PWD/slang-release/bin/slangc" + "$SLANGC" -v || true + 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: | diff --git a/python/Scripts/generateshader.py b/python/Scripts/generateshader.py index 46ff359043..4a9c64cadf 100644 --- a/python/Scripts/generateshader.py +++ b/python/Scripts/generateshader.py @@ -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 @@ -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.') From 01e24e61a3ccfb64ac64700a5e7b3846e16f9667 Mon Sep 17 00:00:00 2001 From: Krishna <1148983+krishnamanchikalapudi@users.noreply.github.com> Date: Tue, 30 Jun 2026 20:36:14 -0700 Subject: [PATCH 2/4] Fix Slang stage handling in generateshader.py; harden slangc download step - generateshader.py: include 'slang' in the target list that writes and validates both the vertex and pixel stage sources. SlangShaderGenerator derives from HwShaderGenerator (same as GLSL/ESSL/Vulkan/WGSL/MSL) and emits separate VERTEX_STAGE and PIXEL_STAGE sources, so without this the new Slang CI step only validated the pixel stage and silently skipped the vertex stage. - main.yml: chmod +x the extracted slangc binary before invoking it, since correct executable permissions from the release tarball shouldn't be assumed. --- .github/workflows/main.yml | 1 + python/Scripts/generateshader.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cff22a3260..bd44e635e3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -306,6 +306,7 @@ jobs: mkdir -p slang-release tar -xzf slang.tar.gz -C slang-release SLANGC="$PWD/slang-release/bin/slangc" + chmod +x "$SLANGC" "$SLANGC" -v || true 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" diff --git a/python/Scripts/generateshader.py b/python/Scripts/generateshader.py index 4a9c64cadf..b574563224 100644 --- a/python/Scripts/generateshader.py +++ b/python/Scripts/generateshader.py @@ -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) From 95827ee35c901319a4a7aaaf6c7680018ce7fa59 Mon Sep 17 00:00:00 2001 From: Krishna <1148983+krishnamanchikalapudi@users.noreply.github.com> Date: Wed, 8 Jul 2026 18:36:09 -0700 Subject: [PATCH 3/4] Fix Slang validation: add missing semicolons after struct definitions --- libraries/stdlib/genslang/lib/mx_texture.slang | 2 +- source/MaterialXGenSlang/SlangShaderGenerator.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/stdlib/genslang/lib/mx_texture.slang b/libraries/stdlib/genslang/lib/mx_texture.slang index 80e3a4ce1f..2f4420d019 100644 --- a/libraries/stdlib/genslang/lib/mx_texture.slang +++ b/libraries/stdlib/genslang/lib/mx_texture.slang @@ -24,7 +24,7 @@ struct SamplerTexture2D tex.GetDimensions(0, width, height, numberOfLevels); return numberOfLevels; } -} +}; float4 textureLod(SamplerTexture2D tex, float2 uv, float lod) { diff --git a/source/MaterialXGenSlang/SlangShaderGenerator.cpp b/source/MaterialXGenSlang/SlangShaderGenerator.cpp index 2e093b32d8..9a088cae9b 100644 --- a/source/MaterialXGenSlang/SlangShaderGenerator.cpp +++ b/source/MaterialXGenSlang/SlangShaderGenerator.cpp @@ -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) @@ -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); } @@ -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); } From ecc19388f093b95458ad59f930b94c3ef87157e9 Mon Sep 17 00:00:00 2001 From: Krishna <1148983+krishnamanchikalapudi@users.noreply.github.com> Date: Wed, 15 Jul 2026 17:50:26 -0700 Subject: [PATCH 4/4] Fix Slang validation: export LD_LIBRARY_PATH for slangc dynamic libraries --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 274627b79e..fcf1f2d2b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -306,9 +306,10 @@ jobs: 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 || true + "$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"