-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds python bindings for Metal Shading Language generator
- Loading branch information
Showing
5 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
file(GLOB pymaterialxgenmsl_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") | ||
file(GLOB pymaterialxgenmsl_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h") | ||
|
||
pybind11_add_module(PyMaterialXGenMsl SHARED ${PYBIND11_MODULE_FLAGS} ${pymaterialxgenmsl_source} ${pymaterialxgenmsl_headers}) | ||
|
||
if(APPLE) | ||
set_target_properties(PyMaterialXGenMsl PROPERTIES CXX_VISIBILITY_PRESET "default") | ||
endif() | ||
|
||
set_target_properties( | ||
PyMaterialXGenMsl | ||
PROPERTIES | ||
OUTPUT_NAME PyMaterialXGenMsl | ||
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}" | ||
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}" | ||
INSTALL_RPATH "${MATERIALX_UP_TWO_RPATH}" | ||
VERSION "${MATERIALX_LIBRARY_VERSION}" | ||
SOVERSION "${MATERIALX_MAJOR_VERSION}" | ||
DEBUG_POSTFIX "${MATERIALX_PYTHON_DEBUG_POSTFIX}") | ||
|
||
target_link_libraries( | ||
PyMaterialXGenMsl | ||
PUBLIC PyMaterialXGenShader | ||
MaterialXGenMsl | ||
PRIVATE ${CMAKE_DL_LIBS}) | ||
|
||
install(TARGETS PyMaterialXGenMsl | ||
DESTINATION "python/MaterialX") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Copyright Contributors to the MaterialX Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <PyMaterialX/PyMaterialX.h> | ||
|
||
namespace py = pybind11; | ||
|
||
void bindPyMslShaderGenerator(py::module& mod); | ||
void bindPyMslResourceBindingContext(py::module &mod); | ||
|
||
PYBIND11_MODULE(PyMaterialXGenMsl, mod) | ||
{ | ||
mod.doc() = "Module containing Python bindings for the MaterialXGenMsl library"; | ||
|
||
bindPyMslShaderGenerator(mod); | ||
bindPyMslResourceBindingContext(mod); | ||
} |
37 changes: 37 additions & 0 deletions
37
source/PyMaterialX/PyMaterialXGenMsl/PyMslShaderGenerator.cpp
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Copyright Contributors to the MaterialX Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <PyMaterialX/PyMaterialX.h> | ||
|
||
#include <MaterialXGenMsl/MslShaderGenerator.h> | ||
#include <MaterialXGenMsl/MslResourceBindingContext.h> | ||
#include <MaterialXGenShader/Shader.h> | ||
#include <MaterialXGenShader/ShaderGenerator.h> | ||
|
||
#include <string> | ||
|
||
namespace py = pybind11; | ||
namespace mx = MaterialX; | ||
|
||
// MSL shader generator bindings | ||
|
||
void bindPyMslShaderGenerator(py::module& mod) | ||
{ | ||
py::class_<mx::MslShaderGenerator, mx::HwShaderGenerator, mx::MslShaderGeneratorPtr>(mod, "MslShaderGenerator") | ||
.def_static("create", &mx::MslShaderGenerator::create) | ||
.def(py::init<>()) | ||
.def("generate", &mx::MslShaderGenerator::generate) | ||
.def("getTarget", &mx::MslShaderGenerator::getTarget) | ||
.def("getVersion", &mx::MslShaderGenerator::getVersion); | ||
} | ||
|
||
void bindPyMslResourceBindingContext(py::module &mod) | ||
{ | ||
py::class_<mx::MslResourceBindingContext, mx::HwResourceBindingContext, mx::MslResourceBindingContextPtr>(mod, "MslResourceBindingContext") | ||
.def_static("create", &mx::MslResourceBindingContext::create) | ||
.def(py::init<size_t, size_t>()) | ||
.def("emitDirectives", &mx::MslResourceBindingContext::emitDirectives) | ||
.def("emitResourceBindings", &mx::MslResourceBindingContext::emitResourceBindings); | ||
} |