Implement PyMaterialXRenderSlang Python bindings - #59
Open
ppenenko wants to merge 2 commits into
Open
Conversation
ppenenko
force-pushed
the
metashade/slang-python-bindings
branch
from
August 22, 2026 16:57
6715f38 to
97264e6
Compare
There was a problem hiding this comment.
Pull request overview
Adds Python bindings for the Slang renderer and supporting build/runtime integration.
Changes:
- Adds renderer, texture-handler, and texture-baker bindings.
- Integrates the module into CMake and documentation targets.
- Updates renderer dependencies and Windows DLL search paths.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
CMakeLists.txt |
Enables hardware-renderer support for Slang builds. |
python/MaterialX/__init__.py |
Configures Windows DLL search paths. |
source/MaterialXRenderSlang/CMakeLists.txt |
Adds the hardware-rendering dependency. |
source/MaterialXRenderSlang/TextureBaker.h |
Includes the complete framebuffer type. |
source/PyMaterialX/CMakeLists.txt |
Registers the new Python module. |
source/PyMaterialX/PyMaterialXRenderSlang/CMakeLists.txt |
Builds and installs the extension. |
source/PyMaterialX/PyMaterialXRenderSlang/PyModule.cpp |
Defines module initialization. |
source/PyMaterialX/PyMaterialXRenderSlang/PySlangRenderer.cpp |
Binds SlangRenderer. |
source/PyMaterialX/PyMaterialXRenderSlang/PySlangTextureHandler.cpp |
Binds SlangTextureHandler. |
source/PyMaterialX/PyMaterialXRenderSlang/PyTextureBaker.cpp |
Binds the Slang texture baker. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| .def("render", &mx::SlangRenderer::render) | ||
| .def("renderTextureSpace", &mx::SlangRenderer::renderTextureSpace) | ||
| .def("captureImage", &mx::SlangRenderer::captureImage) | ||
| .def("getProgram", &mx::SlangRenderer::getProgram); |
| void bindPySlangTextureHandler(py::module& mod) | ||
| { | ||
| py::class_<mx::SlangTextureHandler, mx::ImageHandler, mx::SlangTextureHandlerPtr>(mod, "SlangTextureHandler") | ||
| .def_static("create", &mx::SlangTextureHandler::create) |
Comment on lines
+12
to
+13
| os.add_dll_directory(mxdir) | ||
| except (AttributeError, OSError): |
Comment on lines
+31
to
+33
| if(WIN32) | ||
| # Install slang-rhi runtime DLL dependencies to python package directory | ||
| install(FILES |
- Add PySlangProgram binding and register in PyModule - Remove unusable SlangTextureHandler::create static method - Retain DLL directory handles in module list to prevent GC cleanup - Add multi-platform runtime installation for macOS and Linux - Add default arguments for createImageHandler, captureImage, renderTextureSpace - Fix constant buffer reflection in SlangProgram to account for trailing u_lightData
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Suppressed comments (1)
source/PyMaterialX/PyMaterialXRenderSlang/CMakeLists.txt:42
- The pinned slang-rhi project only copies these compiler libraries into
SLANG_RHI_BINARY_DIRon Windows; on Linux and macOS the importedslangtarget points to the downloaded library in its package directory. Consequently both non-Windows paths here are absent,OPTIONALsilently skips them, and the installed extension cannot load its Slang compiler dependency. Install$<TARGET_FILE:slang>for both non-Windows branches instead of guessing output filenames.
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libslang.dylib
| .def("hasUniform", &mx::SlangProgram::hasUniform) | ||
| .def("bindUniform", &mx::SlangProgram::bindUniform, | ||
| py::arg("name"), py::arg("value"), py::arg("errorIfMissing") = true) | ||
| .def("bindMesh", static_cast<void (mx::SlangProgram::*)(mx::MeshPtr)>(&mx::SlangProgram::bindMesh)) |
| target_link_libraries( | ||
| PyMaterialXRenderSlang | ||
| PUBLIC PyMaterialXRender | ||
| MaterialXRenderSlang |
|
|
||
| void bindPySlangProgram(py::module& mod) | ||
| { | ||
| py::class_<mx::SlangProgram, mx::SlangProgramPtr>(mod, "SlangProgram") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses Phase 2 of #57.
This PR implements the
PyMaterialXRenderSlangPython C++ extension module, exposing the native Slang hardware renderer (MaterialXRenderSlang) to Python:source/PyMaterialX/PyMaterialXRenderSlang/Module:PyModule.cpp: DefinesPYBIND11_MODULE(PyMaterialXRenderSlang, mod).PySlangRenderer.cpp: ExposesSlangRenderer(create,initialize,createProgram,validateInputs,render,renderTextureSpace,captureImage,getProgram).PySlangTextureHandler.cpp: ExposesSlangTextureHandler(create,bindImage,unbindImage,createRenderResources,releaseRenderResources).PyTextureBaker.cpp: ExposesTextureBakerSlang.CMakeLists.txt: Configures module build and installs dependent runtime DLLs.MaterialXRenderHwtoMaterialXRenderSlangmodules to resolveSimpleWindowsymbol dependencies.SlangFramebuffer.hinTextureBaker.hfor complete type definition when instantiated.add_subdirectory(source/MaterialXRenderHw)inCMakeLists.txtso it is compiled whenever Slang rendering is active.python/MaterialX/__init__.pyto ensureos.add_dll_directoryis called for both the package directory and the installationbin/directory on Windows, allowingPyMaterialXRenderSlangto findslang.dllautomatically.Verification
PyMaterialXRenderSlangand installed into environment viacmake --install build --config Debug.