Summary
This issue outlines the roadmap for enabling Slang render validation within our pytest-based rendering framework (contrib/tests) in metashade/MaterialX.
The primary objective is to achieve cross-backend rendering parity (GLSL vs. Slang) to prove that Metashade generates functional Slang shaders that render identically to GLSL baselines on actual GPU hardware.
Background & Current State
-
Shader Generation (MaterialXGenSlang):
- The Slang code generator is fully supported and enabled by default (MATERIALX_BUILD_GEN_SLANG=ON).
- Python bindings (PyMaterialXGenSlang) and JS bindings exist.
- Syntax and node implementation tests exist in Catch under [genslang].
-
Slang Renderer (MaterialXRenderSlang):
- Implements ShaderRenderer using slang-rhi (supporting D3D12 on Windows, Vulkan on Linux, and Metal on macOS).
- MaterialXTest contains a [renderslang] test case in source/MaterialXTest/MaterialXRenderSlang/RenderSlang.cpp.
- Currently requires manually supplying -DMATERIALX_SLANG_RHI_SOURCE_DIR at CMake configure time.
- Omitted from upstream CI because slang-rhi is not pre-packaged on runner images.
-
Python Render Bindings Missing:
- While PyMaterialXRenderGlsl, PyMaterialXRenderMsl, and PyMaterialXRenderOsl exist, there is currently no PyMaterialXRenderSlang module.
- As a result, Python-based test harnesses (including our pytest framework) cannot currently instantiate a native Slang renderer.
Implementation Roadmap
Phase 1: Zero-Friction slang-rhi Integration (Upstream Candidate)
- CMake FetchContent with local fallback:
- Introduce MATERIALX_BUILD_RENDER_SLANG option.
- If MATERIALX_SLANG_RHI_SOURCE_DIR is not provided, automatically fetch and build a pinned version of shader-slang/slang-rhi via CMake FetchContent.
- Retain full support for MATERIALX_SLANG_RHI_SOURCE_DIR so developers hacking on / debugging local slang-rhi checkouts can point to their local directory.
- Developer Experience:
- Add a windows-slang configure/build preset in CMakePresets.json.
- Add VS Code task and debug configuration for running MaterialXTest [renderslang].
- Upstream Benefit: Makes MaterialXTest [renderslang] completely reproducible on any developer machine and CI runner with a single flag.
Phase 2: Python Bindings for Slang Renderer (PyMaterialXRenderSlang) (Upstream Candidate)
- Add source/PyMaterialX/PyMaterialXRenderSlang/PySlangRenderer.cpp (~30 lines of pybind11 code matching PyGlslRenderer.cpp / PyMslRenderer.mm).
- Bind SlangRenderer::create, initialize, createProgram, �alidateInputs,
ender,
enderTextureSpace, captureImage, and getProgram.
- Configure the PyMaterialXRenderSlang CMake module.
Phase 3: pytest Framework Integration (metashade/MaterialX)
- Shader Generator Registry:
- Register mx_gen_slang.SlangShaderGenerator.create() under target genslang in mtlxutils/mxshadergen.py.
- Slang Render Environment:
- Implement SlangRenderer in mtlxutils/mxrenderer.py wrapping PyMaterialXRenderSlang.
- Add --renderer slang CLI option and fixtures in contrib/tests/conftest.py.
- Cross-Backend Validation:
- Run contrib/tests/test_render.py with Slang backend and compare rendered outputs directly against GLSL references using perceptual FLIP gating (--flip-threshold 0.05).
- Add VS Code launch configuration and task: pytest: Metashade Render Slang.
Phase 4: CI & Automation
- Add a GitHub Actions CI matrix job on Windows / Linux runners to execute both MaterialXTest [renderslang] and pytest contrib/tests/test_render.py --renderer slang.
- Include Slang runs in scheduled builds to catch compiler and driver regressions early.
Summary
This issue outlines the roadmap for enabling Slang render validation within our pytest-based rendering framework (contrib/tests) in metashade/MaterialX.
The primary objective is to achieve cross-backend rendering parity (GLSL vs. Slang) to prove that Metashade generates functional Slang shaders that render identically to GLSL baselines on actual GPU hardware.
Background & Current State
Shader Generation (MaterialXGenSlang):
Slang Renderer (MaterialXRenderSlang):
Python Render Bindings Missing:
Implementation Roadmap
Phase 1: Zero-Friction slang-rhi Integration (Upstream Candidate)
Phase 2: Python Bindings for Slang Renderer (PyMaterialXRenderSlang) (Upstream Candidate)
ender,
enderTextureSpace, captureImage, and getProgram.
Phase 3: pytest Framework Integration (metashade/MaterialX)
Phase 4: CI & Automation