Skip to content

Commit d24b4f1

Browse files
authored
Merge branch 'AcademySoftwareFoundation:main' into functional_nodedefs
2 parents aa3ca63 + ef1d56c commit d24b4f1

File tree

9 files changed

+126
-2
lines changed

9 files changed

+126
-2
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ jobs:
230230
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --target osl
231231
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --target mdl
232232
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --target msl
233+
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --target slang
233234
working-directory: python
234235

235236
- name: Shader Validation Tests (Windows)

javascript/MaterialXTest/browser/shaderGenerator.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ describe('Generate Shaders', function ()
5151
generators.push(mx.WgslShaderGenerator.create());
5252
if (typeof mx.MdlShaderGenerator != 'undefined')
5353
generators.push(mx.MdlShaderGenerator.create());
54+
if (typeof mx.SlangShaderGenerator != 'undefined')
55+
generators.push(mx.SlangShaderGenerator.create());
5456

5557
const elem = mx.findRenderableElement(doc);
5658
for (let gen of generators)

python/Scripts/generateshader.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import MaterialX.PyMaterialXGenMdl as mx_gen_mdl
1212
import MaterialX.PyMaterialXGenMsl as mx_gen_msl
1313
import MaterialX.PyMaterialXGenOsl as mx_gen_osl
14+
import MaterialX.PyMaterialXGenSlang as mx_gen_slang
1415
import MaterialX.PyMaterialXGenShader as mx_gen_shader
1516

1617
def validateCode(sourceCodeFile, codevalidator, codevalidatorArgs):
@@ -102,6 +103,8 @@ def main():
102103
shadergen = mx_gen_glsl.WgslShaderGenerator.create()
103104
elif gentarget == 'msl':
104105
shadergen = mx_gen_msl.MslShaderGenerator.create()
106+
elif gentarget == 'slang':
107+
shadergen = mx_gen_slang.SlangShaderGenerator.create()
105108
else:
106109
shadergen = mx_gen_glsl.GlslShaderGenerator.create()
107110

source/JsMaterialX/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(GENMSL ${CMAKE_CURRENT_SOURCE_DIR}/JsMaterialXGenMsl/)
88
set(GENVK ${CMAKE_CURRENT_SOURCE_DIR}/JsMaterialXGenVk/)
99
set(GENMDL ${CMAKE_CURRENT_SOURCE_DIR}/JsMaterialXGenMdl/)
1010
set(GENWGSL ${CMAKE_CURRENT_SOURCE_DIR}/JsMaterialXGenWgsl/)
11+
set(GENSLANG ${CMAKE_CURRENT_SOURCE_DIR}/JsMaterialXGenSlang/)
1112

1213
set(SOURCE_FOLDER ${PROJECT_SOURCE_DIR}/source)
1314

@@ -50,6 +51,7 @@ set(GENMSL_DEPS ${GENMSL}JsMslShaderGenerator.cpp)
5051
set(GENVK_DEPS ${GENVK}JsVkShaderGenerator.cpp)
5152
set(GENWGSL_DEPS ${GENWGSL}JsWgslShaderGenerator.cpp)
5253
set(GENMDL_DEPS ${GENMDL}JsMdlShaderGenerator.cpp)
54+
set(GENSLANG_DEPS ${GENSLANG}JsSlangShaderGenerator.cpp)
5355

5456
# Linker flags
5557
set(JS_LINK_FLAGS_CORE "")
@@ -114,6 +116,10 @@ if (MATERIALX_BUILD_GEN_MSL)
114116
message("JS: Building JsMaterialXGenShader with MSL support")
115117
target_sources(JsMaterialXGenShader PRIVATE ${GENMSL_DEPS})
116118
endif()
119+
if (MATERIALX_BUILD_GEN_SLANG)
120+
message("JS: Building JsMaterialXGenShader with Slang support")
121+
target_sources(JsMaterialXGenShader PRIVATE ${GENSLANG_DEPS})
122+
endif()
117123

118124
set_target_properties(JsMaterialXCore
119125
PROPERTIES
@@ -152,7 +158,10 @@ if (MATERIALX_BUILD_GEN_MDL)
152158
endif()
153159
if (MATERIALX_BUILD_GEN_MSL)
154160
target_link_libraries(JsMaterialXGenShader PUBLIC MaterialXGenMsl)
155-
endif()
161+
endif()
162+
if (MATERIALX_BUILD_GEN_SLANG)
163+
target_link_libraries(JsMaterialXGenShader PUBLIC MaterialXGenSlang)
164+
endif()
156165

157166
# Install the JavaScript output
158167
install(TARGETS JsMaterialXCore DESTINATION "JavaScript/MaterialX")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Copyright Contributors to the MaterialX Project
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
6+
#include <MaterialXGenSlang/SlangShaderGenerator.h>
7+
#include <MaterialXGenShader/Util.h>
8+
9+
#include <emscripten/bind.h>
10+
11+
namespace ems = emscripten;
12+
namespace mx = MaterialX;
13+
14+
namespace
15+
{
16+
// Creator wrapper to avoid having to expose the TypeSystem class in JavaScript
17+
mx::ShaderGeneratorPtr SlangShaderGenerator_create()
18+
{
19+
return mx::SlangShaderGenerator::create();
20+
}
21+
}
22+
23+
EMSCRIPTEN_BINDINGS(SlangShaderGenerator)
24+
{
25+
ems::class_<mx::SlangShaderGenerator, ems::base<mx::HwShaderGenerator>>("SlangShaderGenerator")
26+
.class_function("create", &SlangShaderGenerator_create);
27+
}

source/PyMaterialX/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ endif()
3737

3838
add_subdirectory(PyMaterialXCore)
3939
add_subdirectory(PyMaterialXFormat)
40-
if (MATERIALX_BUILD_GEN_GLSL OR MATERIALX_BUILD_GEN_OSL OR MATERIALX_BUILD_GEN_MDL OR MATERIALX_BUILD_GEN_MSL)
40+
if (MATERIALX_BUILD_GEN_GLSL OR MATERIALX_BUILD_GEN_OSL OR MATERIALX_BUILD_GEN_MDL OR MATERIALX_BUILD_GEN_MSL OR MATERIALX_BUILD_GEN_SLANG)
4141
add_subdirectory(PyMaterialXGenShader)
4242
if (MATERIALX_BUILD_GEN_GLSL)
4343
add_subdirectory(PyMaterialXGenGlsl)
@@ -51,6 +51,9 @@ if (MATERIALX_BUILD_GEN_GLSL OR MATERIALX_BUILD_GEN_OSL OR MATERIALX_BUILD_GEN_M
5151
if (MATERIALX_BUILD_GEN_MDL)
5252
add_subdirectory(PyMaterialXGenMdl)
5353
endif()
54+
if (MATERIALX_BUILD_GEN_SLANG)
55+
add_subdirectory(PyMaterialXGenSlang)
56+
endif()
5457
endif()
5558
if (MATERIALX_BUILD_RENDER)
5659
add_subdirectory(PyMaterialXRender)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
file(GLOB pymaterialxgenslang_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
2+
file(GLOB pymaterialxgenslang_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
3+
4+
pybind11_add_module(PyMaterialXGenSlang SHARED ${PYBIND11_MODULE_FLAGS} ${pymaterialxgenslang_source} ${pymaterialxgenslang_headers})
5+
6+
if(APPLE)
7+
set_target_properties(PyMaterialXGenSlang PROPERTIES CXX_VISIBILITY_PRESET "default")
8+
endif()
9+
10+
set_target_properties(
11+
PyMaterialXGenSlang
12+
PROPERTIES
13+
OUTPUT_NAME PyMaterialXGenSlang
14+
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
15+
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
16+
INSTALL_RPATH "${MATERIALX_UP_TWO_RPATH}"
17+
DEBUG_POSTFIX "${MATERIALX_PYTHON_DEBUG_POSTFIX}")
18+
19+
target_link_libraries(
20+
PyMaterialXGenSlang
21+
PUBLIC PyMaterialXGenShader
22+
MaterialXGenSlang
23+
PRIVATE ${CMAKE_DL_LIBS})
24+
25+
install(TARGETS PyMaterialXGenSlang
26+
DESTINATION "${MATERIALX_PYTHON_FOLDER_NAME}")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright Contributors to the MaterialX Project
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
6+
#include <PyMaterialX/PyMaterialX.h>
7+
8+
namespace py = pybind11;
9+
10+
void bindPySlangShaderGenerator(py::module& mod);
11+
12+
PYBIND11_MODULE(PyMaterialXGenSlang, mod)
13+
{
14+
mod.doc() = "Shader generation using the Slang shading language.";
15+
16+
// PyMaterialXGenSlang depends on types defined in PyMaterialXGenShader
17+
PYMATERIALX_IMPORT_MODULE(PyMaterialXGenShader);
18+
19+
bindPySlangShaderGenerator(mod);
20+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Copyright Contributors to the MaterialX Project
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
6+
#include <PyMaterialX/PyMaterialX.h>
7+
8+
#include <MaterialXGenSlang/SlangShaderGenerator.h>
9+
#include <MaterialXGenShader/Shader.h>
10+
#include <MaterialXGenShader/ShaderGenerator.h>
11+
12+
namespace py = pybind11;
13+
namespace mx = MaterialX;
14+
15+
// Slang shader generator bindings
16+
17+
namespace
18+
{
19+
// Creator wrapper to avoid having to expose the TypeSystem class in python
20+
mx::ShaderGeneratorPtr SlangShaderGenerator_create()
21+
{
22+
return mx::SlangShaderGenerator::create();
23+
}
24+
}
25+
26+
void bindPySlangShaderGenerator(py::module& mod)
27+
{
28+
py::class_<mx::SlangShaderGenerator, mx::HwShaderGenerator, mx::SlangShaderGeneratorPtr>(mod, "SlangShaderGenerator")
29+
.def_static("create", &SlangShaderGenerator_create)
30+
.def("generate", &mx::SlangShaderGenerator::generate)
31+
.def("getTarget", &mx::SlangShaderGenerator::getTarget)
32+
.def("getVersion", &mx::SlangShaderGenerator::getVersion);
33+
}

0 commit comments

Comments
 (0)