From c1749600cd3f900876f87add0a71ca47e84296a7 Mon Sep 17 00:00:00 2001 From: JGamache-autodesk <56274617+JGamache-autodesk@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:17:43 -0500 Subject: [PATCH 1/4] Adjust Windows DLL search path for Python 3.8+ (#1440) Fixes #1439 Required by python/cpython#80266 --- python/MaterialX/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/python/MaterialX/__init__.py b/python/MaterialX/__init__.py index bd3999fe36..609e42eae6 100644 --- a/python/MaterialX/__init__.py +++ b/python/MaterialX/__init__.py @@ -1,3 +1,24 @@ +# Python 3.8+ on Windows: DLL search paths for dependent +# shared libraries +# Refs.: +# - https://github.com/python/cpython/issues/80266 +# - https://docs.python.org/3.8/library/os.html#os.add_dll_directory +import os +import sys +if sys.platform == "win32" and sys.version_info >= (3, 8): + import importlib.metadata + try: + importlib.metadata.version('MaterialX') + except importlib.metadata.PackageNotFoundError: + # On a non-pip installation, this file is in %INSTALLDIR%\python\MaterialX + # We need to add %INSTALLDIR%\bin to the DLL path. + mxdir = os.path.dirname(__file__) + pydir = os.path.split(mxdir)[0] + installdir = os.path.split(pydir)[0] + bindir = os.path.join(installdir, "bin") + if os.path.exists(bindir): + os.add_dll_directory(bindir) + from .main import * from .colorspace import * From e6e3ef550367bf05addcd0d7d3009a7b3337d73a Mon Sep 17 00:00:00 2001 From: Lee Kerley <154285602+ld-kerley@users.noreply.github.com> Date: Fri, 13 Dec 2024 18:04:21 -0800 Subject: [PATCH 2/4] Additional cleanup from OSL legacy closure removal (#2142) #2121 removed the OSL legacy closures - but we can simplify the data library installation a little more now they are gone. --- libraries/CMakeLists.txt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index 6852090932..2b2097e203 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -1,10 +1,7 @@ if(NOT SKBUILD) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}" - PATTERN "CMakeLists.txt" EXCLUDE - PATTERN "pbrlib_genosl_impl.*" EXCLUDE) - install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pbrlib/genosl/pbrlib_genosl_impl.mtlx" - DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}/pbrlib/genosl/" RENAME pbrlib_genosl_impl.mtlx) + PATTERN "CMakeLists.txt" EXCLUDE) endif() set(MATERIALX_PYTHON_LIBRARIES_PATH "${MATERIALX_PYTHON_FOLDER_NAME}/${MATERIALX_INSTALL_STDLIB_PATH}") @@ -15,8 +12,5 @@ endif() if(MATERIALX_BUILD_PYTHON) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION "${MATERIALX_PYTHON_LIBRARIES_PATH}" - PATTERN "CMakeLists.txt" EXCLUDE - PATTERN "pbrlib_genosl_impl.*" EXCLUDE) - install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pbrlib/genosl/pbrlib_genosl_impl.mtlx" - DESTINATION "${MATERIALX_PYTHON_LIBRARIES_PATH}/pbrlib/genosl/" RENAME pbrlib_genosl_impl.mtlx) + PATTERN "CMakeLists.txt" EXCLUDE) endif() From b1b94b658e88a90637fe65321818fb21bbc75670 Mon Sep 17 00:00:00 2001 From: Jonathan Stone Date: Fri, 13 Dec 2024 18:30:40 -0800 Subject: [PATCH 3/4] Extend fuzz testing to Examples folder (#2143) This changelist extends fuzz testing from Examples/StandardSurface to the full Examples folder, providing a broader set of input materials. --- .../MaterialXTest/MaterialXFormat/XmlIo.cpp | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/source/MaterialXTest/MaterialXFormat/XmlIo.cpp b/source/MaterialXTest/MaterialXFormat/XmlIo.cpp index 6d3bb7868f..fb6f824c6c 100644 --- a/source/MaterialXTest/MaterialXFormat/XmlIo.cpp +++ b/source/MaterialXTest/MaterialXFormat/XmlIo.cpp @@ -265,42 +265,45 @@ TEST_CASE("Comments and newlines", "[xmlio]") TEST_CASE("Fuzz testing", "[xmlio]") { mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath(); - mx::FilePath examplesPath = searchPath.find("resources/Materials/Examples/StandardSurface"); + mx::FilePath examplesPath = searchPath.find("resources/Materials/Examples"); std::mt19937 rng(0); std::uniform_int_distribution randChar(0, 255); - for (const mx::FilePath& filename : examplesPath.getFilesInDirectory(mx::MTLX_EXTENSION)) + for (const mx::FilePath& path : examplesPath.getSubDirectories()) { - // Read the example file into an XML string buffer. - const std::string origString = mx::readFile(examplesPath / filename); - REQUIRE(origString.size() > 0); - std::uniform_int_distribution randPos(0, origString.size() - 1); - - // Iterate over test runs. - for (size_t testRun = 0; testRun < 256; testRun++) + for (const mx::FilePath& filename : path.getFilesInDirectory(mx::MTLX_EXTENSION)) { - std::string editString = origString; + // Read the example file into an XML string buffer. + const std::string origString = mx::readFile(path / filename); + REQUIRE(origString.size() > 0); + std::uniform_int_distribution randPos(0, origString.size() - 1); - // Iterate over string edits. - for (size_t editIndex = 0; editIndex < 32; editIndex++) + // Iterate over test runs. + for (size_t testRun = 0; testRun < 256; testRun++) { - // Randomly alter one character in the document. - size_t charIndex = randPos(rng); - size_t newChar = randChar(rng); - editString[charIndex] = (char) newChar; - - // Attempt to interpret the edited string as a document, allowing only MaterialX exceptions. - mx::DocumentPtr doc = mx::createDocument(); - try - { - mx::readFromXmlString(doc, editString, searchPath); - doc->validate(); - } - catch (const mx::Exception&) + std::string editString = origString; + + // Iterate over string edits. + for (size_t editIndex = 0; editIndex < 32; editIndex++) { - // On a MaterialX exception, proceed to the next test run. - break; + // Randomly alter one character in the document. + size_t charIndex = randPos(rng); + size_t newChar = randChar(rng); + editString[charIndex] = (char) newChar; + + // Attempt to interpret the edited string as a document, allowing only MaterialX exceptions. + mx::DocumentPtr doc = mx::createDocument(); + try + { + mx::readFromXmlString(doc, editString, searchPath); + doc->validate(); + } + catch (const mx::Exception&) + { + // On a MaterialX exception, proceed to the next test run. + break; + } } } } From 81ed31d43026cc0e475bbdf9b040ccbc17ba60bc Mon Sep 17 00:00:00 2001 From: Chris Rydalch Date: Fri, 13 Dec 2024 21:52:58 -0600 Subject: [PATCH 4/4] Add support for geompropvalueuniform node (#2092) Adds a string-/filename-friendly primvar/geompropvalue node, as was proposed for 1.39. --- .../Specification/MaterialX.Proposals.md | 6 ----- .../Specification/MaterialX.Specification.md | 6 +++++ libraries/bxdf/usd_preview_surface.mtlx | 22 ++++++++++++++----- .../stdlib/genglsl/stdlib_genglsl_impl.mtlx | 5 ++++- .../stdlib/genmdl/stdlib_genmdl_impl.mtlx | 5 ++++- .../stdlib/genmsl/stdlib_genmsl_impl.mtlx | 5 ++++- .../stdlib/genosl/stdlib_genosl_impl.mtlx | 5 ++++- libraries/stdlib/stdlib_defs.mtlx | 21 +++++++++++++----- .../stdlib/geometric/geompropvalue.mtlx | 8 +++---- .../MaterialXGenGlsl/GlslShaderGenerator.cpp | 1 + source/MaterialXGenMsl/MslShaderGenerator.cpp | 2 ++ .../MaterialXTest/MaterialXGenGlsl/GenGlsl.h | 2 +- source/MaterialXTest/MaterialXGenMsl/GenMsl.h | 2 +- source/MaterialXTest/MaterialXGenOsl/GenOsl.h | 2 +- 14 files changed, 65 insertions(+), 27 deletions(-) diff --git a/documents/Specification/MaterialX.Proposals.md b/documents/Specification/MaterialX.Proposals.md index d387d28718..1aaa930923 100644 --- a/documents/Specification/MaterialX.Proposals.md +++ b/documents/Specification/MaterialX.Proposals.md @@ -219,12 +219,6 @@ In #1201 it was decided that separate periodic versions of all of the noises is * **`bump`**: Existing node, proposal to add a vector3 `bitangent` input - - -* **`geompropvalueuniform`**: the value of the specified uniform geometric property (defined using <geompropdef>) of the currently-bound geometry. This node's type must match that of the referenced geomprop. - * `geomprop` (uniform string): the geometric property to be referenced. - * `default` (same type as the geomprop's value): a value to return if the specified `geomprop` is not defined on the current geometry. - Note: when <geompropvalueuniform> is added, the text in the first paragraph of the Specification about Node Inputs should be revised to include "<geompropvalueuniform>" as an example of "or any other node whose output is explicitly declared to be uniform". diff --git a/documents/Specification/MaterialX.Specification.md b/documents/Specification/MaterialX.Specification.md index 65027694d8..4ad29dc963 100644 --- a/documents/Specification/MaterialX.Specification.md +++ b/documents/Specification/MaterialX.Specification.md @@ -1091,6 +1091,12 @@ Standard Geometric nodes: * `geomprop` (uniform string): the geometric property to be referenced. * `default` (same type as the geomprop's value): a value to return if the specified `geomprop` is not defined on the current geometry. + + +* **`geompropvalueuniform`**: the value of the specified uniform geometric property (defined using <geompropdef>) of the currently-bound geometry. This node's type must match that of the referenced geomprop. + * `geomprop` (uniform string): the geometric property to be referenced. + * `default` (same type as the geomprop's value): a value to return if the specified `geomprop` is not defined on the current geometry. + Additionally, the `geomcolor` and `geompropvalue` nodes for color3/color4-type properties can take a `colorspace` attribute to declare what colorspace the color property value is in; the default is "none" for no colorspace declaration (and hence no colorspace conversion). diff --git a/libraries/bxdf/usd_preview_surface.mtlx b/libraries/bxdf/usd_preview_surface.mtlx index 4abdb91d9f..afc6954af9 100644 --- a/libraries/bxdf/usd_preview_surface.mtlx +++ b/libraries/bxdf/usd_preview_surface.mtlx @@ -62,8 +62,13 @@ - - + + + + + + + @@ -359,11 +364,18 @@ - + - - + + + + + + + + + diff --git a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx index ad3a21e9cf..0625d17a25 100644 --- a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx +++ b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx @@ -157,7 +157,6 @@ - @@ -165,6 +164,10 @@ + + + + diff --git a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx index 6ac2b862dd..05dbc995d6 100644 --- a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx +++ b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx @@ -159,7 +159,6 @@ - @@ -167,6 +166,10 @@ + + + + diff --git a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx index 3cb99052cf..ea09880543 100644 --- a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx +++ b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx @@ -73,7 +73,6 @@ - @@ -81,6 +80,10 @@ + + + + diff --git a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx index db318976c5..bd2e2540b5 100644 --- a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx +++ b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx @@ -159,7 +159,6 @@ - @@ -167,6 +166,10 @@ + + + + diff --git a/libraries/stdlib/stdlib_defs.mtlx b/libraries/stdlib/stdlib_defs.mtlx index 8f86a03b44..7e6be9b050 100644 --- a/libraries/stdlib/stdlib_defs.mtlx +++ b/libraries/stdlib/stdlib_defs.mtlx @@ -1355,11 +1355,6 @@ - - - - - @@ -1391,6 +1386,22 @@ + + + + + + + + + + + + + registerImplementation("IM_frame_float_" + GlslShaderGenerator::TARGET, HwFrameNode::create); diff --git a/source/MaterialXGenMsl/MslShaderGenerator.cpp b/source/MaterialXGenMsl/MslShaderGenerator.cpp index 9511fac7ba..d886d43e96 100644 --- a/source/MaterialXGenMsl/MslShaderGenerator.cpp +++ b/source/MaterialXGenMsl/MslShaderGenerator.cpp @@ -86,6 +86,8 @@ MslShaderGenerator::MslShaderGenerator() : registerImplementation(elementNames, GeomPropValueNodeMsl::create); registerImplementation("IM_geompropvalue_boolean_" + MslShaderGenerator::TARGET, GeomPropValueNodeMslAsUniform::create); registerImplementation("IM_geompropvalue_string_" + MslShaderGenerator::TARGET, GeomPropValueNodeMslAsUniform::create); + registerImplementation("IM_geompropvalue_filename_" + MslShaderGenerator::TARGET, GeomPropValueNodeMslAsUniform::create); + // registerImplementation("IM_frame_float_" + MslShaderGenerator::TARGET, HwFrameNode::create); diff --git a/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.h b/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.h index 8d3e8c8720..9db87197f1 100644 --- a/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.h +++ b/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.h @@ -52,7 +52,7 @@ class GlslShaderGeneratorTester : public GenShaderUtil::ShaderGeneratorTester whiteList = { "volumeshader", "volumematerial", - "IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue_boolean", "IM_geompropvalue_string", + "IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue_boolean", "IM_geompropvalue_string", "IM_geompropvalue_filename", "IM_light_", "IM_point_light_", "IM_spot_light_", "IM_directional_light_" }; ShaderGeneratorTester::getImplementationWhiteList(whiteList); diff --git a/source/MaterialXTest/MaterialXGenMsl/GenMsl.h b/source/MaterialXTest/MaterialXGenMsl/GenMsl.h index eea7b86acb..c159919773 100644 --- a/source/MaterialXTest/MaterialXGenMsl/GenMsl.h +++ b/source/MaterialXTest/MaterialXGenMsl/GenMsl.h @@ -71,7 +71,7 @@ class MslShaderGeneratorTester : public GenShaderUtil::ShaderGeneratorTester whiteList = { "displacementshader", "volumeshader", "surfacematerial", "volumematerial", - "IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue_boolean", "IM_geompropvalue_string", + "IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue_boolean", "IM_geompropvalue_string", "IM_geompropvalue_filename", "IM_light_", "IM_point_light_", "IM_spot_light_", "IM_directional_light_", "ND_surfacematerial", "ND_volumematerial" }; diff --git a/source/MaterialXTest/MaterialXGenOsl/GenOsl.h b/source/MaterialXTest/MaterialXGenOsl/GenOsl.h index aa84a62218..d36c571a82 100644 --- a/source/MaterialXTest/MaterialXGenOsl/GenOsl.h +++ b/source/MaterialXTest/MaterialXGenOsl/GenOsl.h @@ -64,7 +64,7 @@ class OslShaderGeneratorTester : public GenShaderUtil::ShaderGeneratorTester whiteList = { "displacementshader", "volumeshader", - "IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue" + "IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue", "IM_geompropvalueuniform" }; ShaderGeneratorTester::getImplementationWhiteList(whiteList); }