diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c842d3b530..0a71a31011 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,18 +25,20 @@ jobs: python: 3.7 cmake_config: -DMATERIALX_BUILD_SHARED_LIBS=ON - - name: Linux_GCC_11_Python39 - os: ubuntu-20.04 - compiler: gcc - compiler_version: "11" - python: 3.9 - build_javascript: ON - - name: Linux_GCC_12_Python311 os: ubuntu-22.04 compiler: gcc compiler_version: "12" python: 3.11 + build_javascript: ON + + - name: Linux_GCC_13_Python312 + os: ubuntu-22.04 + compiler: gcc + compiler_version: "13" + python: 3.12 + static_analysis: ON + cmake_config: -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - name: Linux_GCC_CoverageAnalysis os: ubuntu-22.04 @@ -52,20 +54,19 @@ jobs: compiler_version: "10" python: 3.7 cmake_config: -DMATERIALX_BUILD_SHARED_LIBS=ON - static_analysis: ON - - name: Linux_Clang_14_Python311 + - name: Linux_Clang_15_Python312 os: ubuntu-22.04 compiler: clang - compiler_version: "14" - python: 3.11 + compiler_version: "15" + python: 3.12 test_render: ON clang_format: ON - - name: Linux_Clang_14_DynamicAnalysis + - name: Linux_Clang_DynamicAnalysis os: ubuntu-22.04 compiler: clang - compiler_version: "14" + compiler_version: "15" python: None cmake_config: -DMATERIALX_DYNAMIC_ANALYSIS=ON dynamic_analysis: ON @@ -197,10 +198,7 @@ jobs: run: find source \( -name *.h -o -name *.cpp -o -name *.mm \) ! -path "*/External/*" ! -path "*/NanoGUI/*" | xargs clang-format -i --verbose - name: CMake Generate - run: | - mkdir build - cd build - cmake -DMATERIALX_BUILD_PYTHON=ON -DMATERIALX_BUILD_VIEWER=ON -DMATERIALX_BUILD_GRAPH_EDITOR=ON -DMATERIALX_TEST_RENDER=OFF -DMATERIALX_WARNINGS_AS_ERRORS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ${{matrix.cmake_config}} .. + run: cmake -S . -B build -DMATERIALX_BUILD_PYTHON=ON -DMATERIALX_BUILD_VIEWER=ON -DMATERIALX_BUILD_GRAPH_EDITOR=ON -DMATERIALX_TEST_RENDER=OFF -DMATERIALX_WARNINGS_AS_ERRORS=ON ${{matrix.cmake_config}} - name: CMake Build run: cmake --build . --target install --config Release --parallel 2 @@ -312,10 +310,7 @@ jobs: - name: JavaScript CMake Generate if: matrix.build_javascript == 'ON' - run: | - mkdir javascript/build - cd javascript/build - cmake -DMATERIALX_BUILD_JS=ON -DMATERIALX_EMSDK_PATH=${{ env.EMSDK }} -DMATERIALX_BUILD_RENDER=OFF -DMATERIALX_BUILD_TESTS=OFF -DMATERIALX_BUILD_GEN_OSL=OFF -DMATERIALX_BUILD_GEN_MDL=OFF ../.. + run: cmake -S . -B javascript/build -DMATERIALX_BUILD_JS=ON -DMATERIALX_EMSDK_PATH=${{ env.EMSDK }} - name: JavaScript CMake Build if: matrix.build_javascript == 'ON' diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d6a64d6b1..c29565a7ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ set(MATERIALX_BUILD_VERSION 9) set(MATERIALX_LIBRARY_VERSION ${MATERIALX_MAJOR_VERSION}.${MATERIALX_MINOR_VERSION}.${MATERIALX_BUILD_VERSION}) # Cmake setup -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.16) set(CMAKE_CXX_STANDARD 14) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) set(CMAKE_MACOSX_RPATH ON) @@ -61,13 +61,21 @@ option(MATERIALX_BUILD_IOS "Build MaterialX for iOS." OFF) if (MATERIALX_BUILD_IOS) set(CMAKE_SYSTEM_NAME iOS) add_definitions(-DTARGET_OS_IOS=1) - set(MATERIALX_BUILD_PYTHON OFF) - set(MATERIALX_BUILD_VIEWER OFF) - set(MATERIALX_BUILD_GRAPH_EDITOR OFF) - set(MATERIALX_BUILD_GEN_GLSL OFF) - set(MATERIALX_BUILD_GEN_OSL OFF) - set(MATERIALX_BUILD_GEN_MDL OFF) - set(MATERIALX_BUILD_TESTS OFF) + set(MATERIALX_BUILD_PYTHON OFF) + set(MATERIALX_BUILD_VIEWER OFF) + set(MATERIALX_BUILD_GRAPH_EDITOR OFF) + set(MATERIALX_BUILD_GEN_GLSL OFF) + set(MATERIALX_BUILD_GEN_OSL OFF) + set(MATERIALX_BUILD_GEN_MDL OFF) + set(MATERIALX_BUILD_TESTS OFF) +endif() + +if (MATERIALX_BUILD_JS) + set(MATERIALX_BUILD_GEN_OSL OFF) + set(MATERIALX_BUILD_GEN_MSL OFF) + set(MATERIALX_BUILD_GEN_MDL OFF) + set(MATERIALX_BUILD_RENDER OFF) + set(MATERIALX_BUILD_TESTS OFF) endif() set(MATERIALX_PYTHON_VERSION "" CACHE STRING @@ -81,10 +89,6 @@ set(MATERIALX_PYTHON_PYBIND11_DIR "" CACHE PATH set(MATERIALX_OIIO_DIR "" CACHE PATH "Path to the root folder of the OpenImageIO installation.") -if (MATERIALX_BUILD_JS) - set(MATERIALX_BUILD_GEN_GLSL ON) -endif() - # Settings to define installation layout set(MATERIALX_INSTALL_INCLUDE_PATH "include" CACHE STRING "Install header include path (e.g. 'inc', 'include').") set(MATERIALX_INSTALL_LIB_PATH "lib" CACHE STRING "Install lib path (e.g. 'libs', 'lib').") @@ -339,14 +343,12 @@ if(MATERIALX_BUILD_JS) add_subdirectory(source/JsMaterialX) endif() -if(${CMAKE_VERSION} VERSION_GREATER "3.6.2") - if(MATERIALX_BUILD_VIEWER) - set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT MaterialXView) - elseif(MATERIALX_BUILD_GRAPH_EDITOR) - set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT MaterialXGraphEditor) - elseif(MATERIALX_BUILD_TESTS) - set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT MaterialXTest) - endif() +if(MATERIALX_BUILD_VIEWER) + set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT MaterialXView) +elseif(MATERIALX_BUILD_GRAPH_EDITOR) + set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT MaterialXGraphEditor) +elseif(MATERIALX_BUILD_TESTS) + set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT MaterialXTest) endif() # Install root-level documents diff --git a/javascript/build_javascript_win.bat b/javascript/build_javascript_win.bat index 43d8b8b562..8b08c26600 100644 --- a/javascript/build_javascript_win.bat +++ b/javascript/build_javascript_win.bat @@ -8,14 +8,12 @@ if NOT ["%errorlevel%"]==["0"] pause @echo --------------------- Build MaterialX With JavaScript --------------------- @echo on cd %MATERIALX_LOCATION% -mkdir javascript\build -cd javascript\build -cmake -DMATERIALX_BUILD_JS=ON -DMATERIALX_EMSDK_PATH=%EMSDK_LOCATION% -G Ninja -DMATERIALX_BUILD_RENDER=OFF -DMATERIALX_BUILD_TESTS=OFF -DMATERIALX_BUILD_GEN_OSL=OFF -DMATERIALX_BUILD_GEN_MDL=OFF ..\.. -cmake --build . --target install --config RelWithDebInfo --parallel 2 +cmake -S . -B javascript/build -DMATERIALX_BUILD_JS=ON -DMATERIALX_EMSDK_PATH=%EMSDK_LOCATION% -G Ninja +cmake --build javascript/build --target install --config RelWithDebInfo --parallel 2 if NOT ["%errorlevel%"]==["0"] pause @echo --------------------- Run JavaScript Tests --------------------- @echo on -cd ../MaterialXTest +cd javascript/MaterialXTest call npm install call npm run test call npm run test:browser diff --git a/python/Scripts/baketextures.py b/python/Scripts/baketextures.py index caf2aaed3e..ce132036a6 100644 --- a/python/Scripts/baketextures.py +++ b/python/Scripts/baketextures.py @@ -5,9 +5,8 @@ import sys, os, argparse from sys import platform + import MaterialX as mx -from MaterialX import PyMaterialXGenShader -from MaterialX import PyMaterialXGenGlsl from MaterialX import PyMaterialXRender as mx_render from MaterialX import PyMaterialXRenderGlsl as mx_render_glsl if platform == "darwin": diff --git a/python/Scripts/generateshader.py b/python/Scripts/generateshader.py index 8329f7231e..f6158d270a 100644 --- a/python/Scripts/generateshader.py +++ b/python/Scripts/generateshader.py @@ -5,12 +5,13 @@ ''' import sys, os, argparse, subprocess + import MaterialX as mx -import MaterialX.PyMaterialXGenShader as mx_gen_shader import MaterialX.PyMaterialXGenGlsl as mx_gen_glsl -import MaterialX.PyMaterialXGenOsl as mx_gen_osl import MaterialX.PyMaterialXGenMdl as mx_gen_mdl import MaterialX.PyMaterialXGenMsl as mx_gen_msl +import MaterialX.PyMaterialXGenOsl as mx_gen_osl +import MaterialX.PyMaterialXGenShader as mx_gen_shader def validateCode(sourceCodeFile, codevalidator, codevalidatorArgs): if codevalidator: @@ -24,7 +25,7 @@ def validateCode(sourceCodeFile, codevalidator, codevalidatorArgs): print(cmd_flatten) try: output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) - result = output.decode(encoding='utf-8') + return output.decode(encoding='utf-8') except subprocess.CalledProcessError as out: return (out.output.decode(encoding='utf-8')) return "" @@ -82,7 +83,7 @@ def main(): try: mx.loadLibraries(libraryFolders, searchPath, stdlib) doc.importLibrary(stdlib) - except err: + except Exception as err: print('Generation failed: "', err, '"') sys.exit(-1) diff --git a/python/Scripts/genmdl.py b/python/Scripts/genmdl.py index f42add0425..ded1021554 100644 --- a/python/Scripts/genmdl.py +++ b/python/Scripts/genmdl.py @@ -3,9 +3,11 @@ Generate MDL implementation directory based on MaterialX nodedefs ''' -import sys import os -import string; os.environ['PYTHONIOENCODING'] = 'utf-8' +import sys + +os.environ['PYTHONIOENCODING'] = 'utf-8' + import MaterialX as mx def usage(): @@ -345,7 +347,7 @@ def main(): doc = mx.createDocument() searchPath = os.path.join(_startPath, 'libraries') - libraryPath = os.path.join(searchPath, 'stdlib') + libraryPath = os.path.join(searchPath, LIBRARY) _loadLibraries(doc, searchPath, libraryPath) DEFINITION_PREFIX = 'ND_' @@ -522,7 +524,7 @@ def main(): if isinstance(elem, mx.Output): outputValue = elem.getAttribute('default') if outputValue == '[]': - outputvalue = '' + outputValue = '' if not outputValue: outputValue = elem.getAttribute('defaultinput') if outputValue: diff --git a/python/Scripts/mxdoc.py b/python/Scripts/mxdoc.py index 7ee21eb8e5..7c9ba09a07 100644 --- a/python/Scripts/mxdoc.py +++ b/python/Scripts/mxdoc.py @@ -3,7 +3,9 @@ Print markdown documentation for each nodedef in the given document. ''' -import sys, os, argparse +import argparse +import sys + import MaterialX as mx HEADERS = ('Name', 'Type', 'Default Value', diff --git a/python/Scripts/mxformat.py b/python/Scripts/mxformat.py index 8f6ad731e1..0b327883bd 100644 --- a/python/Scripts/mxformat.py +++ b/python/Scripts/mxformat.py @@ -4,7 +4,9 @@ the documents to the latest version of the standard. ''' -import sys, os, argparse +import argparse +import os + import MaterialX as mx def main(): diff --git a/python/Scripts/mxvalidate.py b/python/Scripts/mxvalidate.py index e251b4599b..8b5271e9ed 100755 --- a/python/Scripts/mxvalidate.py +++ b/python/Scripts/mxvalidate.py @@ -3,7 +3,9 @@ Verify that the given file is a valid MaterialX document. ''' -import sys, os, argparse +import argparse +import sys + import MaterialX as mx def main(): @@ -25,7 +27,7 @@ def main(): stdlib = mx.createDocument() try: mx.loadLibraries(mx.getDefaultDataLibraryFolders(), mx.getDefaultDataSearchPath(), stdlib) - except err: + except Exception as err: print(err) sys.exit(0) doc.importLibrary(stdlib) diff --git a/python/Scripts/translateshader.py b/python/Scripts/translateshader.py index 71d7a480b5..f7c5686211 100644 --- a/python/Scripts/translateshader.py +++ b/python/Scripts/translateshader.py @@ -5,15 +5,13 @@ ''' import sys, os, argparse -import MaterialX as mx - from sys import platform + +import MaterialX as mx from MaterialX import PyMaterialXGenShader as mx_gen_shader -from MaterialX import PyMaterialXGenGlsl as ms_gen_glsl from MaterialX import PyMaterialXRender as mx_render from MaterialX import PyMaterialXRenderGlsl as mx_render_glsl if platform == "darwin": - from MaterialX import PyMaterialXGenMsl as ms_gen_msl from MaterialX import PyMaterialXRenderMsl as mx_render_msl def main(): diff --git a/source/MaterialXCore/Util.cpp b/source/MaterialXCore/Util.cpp index 9bb75a19b5..639b8f343c 100644 --- a/source/MaterialXCore/Util.cpp +++ b/source/MaterialXCore/Util.cpp @@ -24,7 +24,7 @@ const std::tuple LIBRARY_VERSION_TUPLE(MATERIALX_MAJOR_VERSION, bool invalidNameChar(char c) { - return !isalnum(c) && c != '_' && c != ':'; + return !isalnum((unsigned char) c) && c != '_' && c != ':'; } } // anonymous namespace diff --git a/source/MaterialXFormat/File.cpp b/source/MaterialXFormat/File.cpp index bb40ba54d1..62b7ec39a8 100644 --- a/source/MaterialXFormat/File.cpp +++ b/source/MaterialXFormat/File.cpp @@ -51,7 +51,7 @@ const string MATERIALX_SEARCH_PATH_ENV_VAR = "MATERIALX_SEARCH_PATH"; inline bool hasWindowsDriveSpecifier(const string& val) { - return (val.length() > 1 && std::isalpha(val[0]) && (val[1] == ':')); + return (val.length() > 1 && std::isalpha((unsigned char) val[0]) && (val[1] == ':')); } // diff --git a/source/MaterialXGraphEditor/CMakeLists.txt b/source/MaterialXGraphEditor/CMakeLists.txt index 1785540bd8..f5f22be2c5 100644 --- a/source/MaterialXGraphEditor/CMakeLists.txt +++ b/source/MaterialXGraphEditor/CMakeLists.txt @@ -9,7 +9,7 @@ if (NOT IS_DIRECTORY "${DEAR_IMGUI_PREFIX}/backends") endif() if(MSVC) - add_compile_options(-wd4100) + add_compile_options(-wd4100 -wd4152 -wd4201 -wd4244 -wd4456) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wno-unused -Wno-deprecated -Wno-comment -Wno-unused-variable) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") diff --git a/source/MaterialXGraphEditor/Graph.cpp b/source/MaterialXGraphEditor/Graph.cpp index 93bb4bde95..fb049ee62c 100644 --- a/source/MaterialXGraphEditor/Graph.cpp +++ b/source/MaterialXGraphEditor/Graph.cpp @@ -241,7 +241,7 @@ mx::DocumentPtr Graph::loadDocument(mx::FilePath filename) std::cerr << "*** Validation warnings for " << filename.asString() << " ***" << std::endl; std::cerr << message << std::endl; } - + // Cache the currently loaded file _materialFilename = filename; } @@ -2124,11 +2124,11 @@ mx::InputPtr Graph::findInput(mx::InputPtr nodeInput, const std::string& name) { if (_isNodeGraph) { - for (UiNodePtr node : _graphNodes) + for (UiNodePtr uiNode : _graphNodes) { - if (node->getNode()) + if (uiNode->getNode()) { - for (mx::InputPtr input : node->getNode()->getActiveInputs()) + for (mx::InputPtr input : uiNode->getNode()->getActiveInputs()) { if (input->getInterfaceInput()) { @@ -2569,7 +2569,7 @@ void Graph::addLink(ed::PinId startPinId, ed::PinId endPinId) return; } - // Perform type check + // Perform type check bool typesMatch = (outputPin->_type == inputPin->_type); if (!typesMatch) { @@ -3115,7 +3115,7 @@ void Graph::loadGraphFromFile(bool prompt) _fileDialog.open(); } else - { + { _graphDoc = loadDocument(_materialFilename); // Rebuild the UI @@ -3126,7 +3126,7 @@ void Graph::loadGraphFromFile(bool prompt) _renderer->setDocument(_graphDoc); _renderer->updateMaterials(nullptr); - } + } } void Graph::saveGraphToFile() @@ -3263,7 +3263,7 @@ void Graph::graphButtons() // Create two windows using splitter float paneWidth = (leftPaneWidth - 2.0f); - + float aspectRatio = _renderer->getPixelRatio(); ImVec2 screenSize = ImVec2(paneWidth, paneWidth / aspectRatio); @@ -3271,14 +3271,14 @@ void Graph::graphButtons() ImVec2 tempWindowPos = ImGui::GetCursorPos(); bool cursorInRenderView = mousePos.x > tempWindowPos.x && mousePos.x < (tempWindowPos.x + screenSize.x) && mousePos.y > tempWindowPos.y && mousePos.y < (tempWindowPos.y + screenSize.y); - + ImGuiWindowFlags windowFlags = 0; if (cursorInRenderView) { windowFlags |= ImGuiWindowFlags_NoScrollWithMouse; } - + ImGui::BeginChild("Selection", ImVec2(paneWidth, 0), false, windowFlags); ImVec2 windowPos = ImGui::GetWindowPos(); @@ -3328,16 +3328,16 @@ void Graph::propertyEditor() std::string name = _currUiNode->getNode()->getParent()->createValidChildName(temp); std::vector downstreamNodes = _currUiNode->getOutputConnections(); - for (UiNodePtr nodes : downstreamNodes) + for (UiNodePtr uiNode : downstreamNodes) { - if (nodes->getInput() == nullptr) + if (!uiNode->getInput() && uiNode->getNode()) { - for (mx::InputPtr input : nodes->getNode()->getActiveInputs()) + for (mx::InputPtr input : uiNode->getNode()->getActiveInputs()) { if (input->getConnectedNode() == _currUiNode->getNode()) { _currUiNode->getNode()->setName(name); - nodes->getNode()->setConnectedNode(input->getName(), _currUiNode->getNode()); + uiNode->getNode()->setConnectedNode(input->getName(), _currUiNode->getNode()); } } } @@ -3352,13 +3352,13 @@ void Graph::propertyEditor() { std::string name = _currUiNode->getInput()->getParent()->createValidChildName(temp); std::vector downstreamNodes = _currUiNode->getOutputConnections(); - for (UiNodePtr nodes : downstreamNodes) + for (UiNodePtr uiNode : downstreamNodes) { - if (nodes->getInput() == nullptr) + if (uiNode->getInput() == nullptr) { - if (nodes->getNode()) + if (uiNode->getNode()) { - for (mx::InputPtr input : nodes->getNode()->getActiveInputs()) + for (mx::InputPtr input : uiNode->getNode()->getActiveInputs()) { if (input->getInterfaceInput() == _currUiNode->getInput()) { @@ -3371,7 +3371,7 @@ void Graph::propertyEditor() } else { - nodes->getOutput()->setConnectedNode(_currUiNode->getNode()); + uiNode->getOutput()->setConnectedNode(_currUiNode->getNode()); } } } @@ -3973,7 +3973,6 @@ void Graph::handleRenderViewInputs() { _renderer->setScrollEvent(scrollAmt); } - } void Graph::drawGraph(ImVec2 mousePos) diff --git a/source/MaterialXRenderGlsl/CMakeLists.txt b/source/MaterialXRenderGlsl/CMakeLists.txt index cb2f3c27c2..067cc5d016 100644 --- a/source/MaterialXRenderGlsl/CMakeLists.txt +++ b/source/MaterialXRenderGlsl/CMakeLists.txt @@ -50,7 +50,8 @@ if(MATERIALX_BUILD_SHARED_LIBS) target_compile_definitions(${MATERIALX_MODULE_NAME} PUBLIC GLAD_GLAPI_EXPORT PRIVATE GLAD_GLAPI_EXPORT_BUILD) endif() -set(COMMON_LIBRARIES +target_link_libraries( + ${MATERIALX_MODULE_NAME} MaterialXRenderHw MaterialXGenGlsl ${CMAKE_DL_LIBS}) @@ -59,30 +60,26 @@ if(WIN32) if(MSVC) target_link_libraries( ${MATERIALX_MODULE_NAME} - ${COMMON_LIBRARIES} Opengl32) elseif(MINGW) target_link_libraries( ${MATERIALX_MODULE_NAME} - ${COMMON_LIBRARIES} Opengl32 gdi32) endif() elseif(APPLE) target_link_libraries( ${MATERIALX_MODULE_NAME} - ${COMMON_LIBRARIES} - ${OPENGL_LIBRARIES} + OpenGL::GL "-framework Foundation" "-framework Cocoa" "-framework Metal") elseif(UNIX) target_link_libraries( ${MATERIALX_MODULE_NAME} - ${COMMON_LIBRARIES} - ${OPENGL_LIBRARIES} - ${X11_LIBRARIES} - ${X11_Xt_LIB}) + OpenGL::GL + X11::X11 + X11::Xt) endif() set_target_properties( diff --git a/source/MaterialXRenderHw/CMakeLists.txt b/source/MaterialXRenderHw/CMakeLists.txt index dfd262a3ae..9efc26017c 100644 --- a/source/MaterialXRenderHw/CMakeLists.txt +++ b/source/MaterialXRenderHw/CMakeLists.txt @@ -57,8 +57,8 @@ elseif(UNIX) ${MATERIALX_MODULE_NAME} MaterialXRender ${CMAKE_DL_LIBS} - ${X11_LIBRARIES} - ${X11_Xt_LIB}) + X11::X11 + X11::Xt) endif() set_target_properties( diff --git a/source/MaterialXRenderMsl/CMakeLists.txt b/source/MaterialXRenderMsl/CMakeLists.txt index 4d5e286463..41e00d4b9f 100644 --- a/source/MaterialXRenderMsl/CMakeLists.txt +++ b/source/MaterialXRenderMsl/CMakeLists.txt @@ -42,36 +42,33 @@ add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers}) add_definitions(-DMATERIALX_RENDERMSL_EXPORTS) -set(COMMON_LIBRARIES +target_link_libraries( + ${MATERIALX_MODULE_NAME} MaterialXRenderHw MaterialXGenMsl ${CMAKE_DL_LIBS}) - -if(APPLE AND NOT MATERIALX_BUILD_IOS) -set(COMMON_LIBRARIES - ${COMMON_LIBRARIES} - "-framework Cocoa") -endif() if(MSVC) target_link_libraries( ${MATERIALX_MODULE_NAME} - ${COMMON_LIBRARIES} Opengl32) elseif(APPLE) + if(NOT MATERIALX_BUILD_IOS) + target_link_libraries( + ${MATERIALX_MODULE_NAME} + "-framework Cocoa" + OpenGL::GL) + endif() target_link_libraries( ${MATERIALX_MODULE_NAME} - ${COMMON_LIBRARIES} - ${OPENGL_LIBRARIES} "-framework Foundation" "-framework Metal") elseif(UNIX) target_link_libraries( ${MATERIALX_MODULE_NAME} - ${COMMON_LIBRARIES} - ${OPENGL_LIBRARIES} - ${X11_LIBRARIES} - ${X11_Xt_LIB}) + OpenGL::GL + X11::X11 + X11::Xt) endif() set_target_properties( diff --git a/source/MaterialXTest/MaterialXFormat/XmlIo.cpp b/source/MaterialXTest/MaterialXFormat/XmlIo.cpp index 1336a080c4..495712381e 100644 --- a/source/MaterialXTest/MaterialXFormat/XmlIo.cpp +++ b/source/MaterialXTest/MaterialXFormat/XmlIo.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -262,6 +261,51 @@ TEST_CASE("Comments and newlines", "[xmlio]") REQUIRE(origXml == newXml); } +TEST_CASE("Fuzz testing", "[xmlio]") +{ + mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath(); + mx::FilePath examplesPath = searchPath.find("resources/Materials/Examples/StandardSurface"); + + std::mt19937 rng(0); + std::uniform_int_distribution randChar(0, 255); + + for (const mx::FilePath& filename : examplesPath.getFilesInDirectory(mx::MTLX_EXTENSION)) + { + // 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++) + { + std::string editString = origString; + + // Iterate over string edits. + for (size_t editIndex = 0; editIndex < 32; editIndex++) + { + // 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; + } + } + } + } +} + TEST_CASE("Locale region testing", "[xmlio]") { // In the United States, the thousands separator is a comma, while in Germany it is a period. diff --git a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp index 2ca8afa86c..1280ff390d 100644 --- a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp +++ b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp @@ -370,9 +370,8 @@ void shaderGenPerformanceTest(mx::GenContext& context) REQUIRE(loadedDocuments.size() == documentsPaths.size()); // Shuffle the order of documents and perform document library import validatation and shadergen - std::random_device random_dev; - std::mt19937 generator(random_dev()); - std::shuffle(loadedDocuments.begin(), loadedDocuments.end(), generator); + std::mt19937 rng(0); + std::shuffle(loadedDocuments.begin(), loadedDocuments.end(), rng); for (const auto& doc : loadedDocuments) { doc->importLibrary(nodeLibrary); diff --git a/source/PyMaterialX/PyMaterialX.h b/source/PyMaterialX/PyMaterialX.h index 7af67ac4bd..1e7bc7ff87 100644 --- a/source/PyMaterialX/PyMaterialX.h +++ b/source/PyMaterialX/PyMaterialX.h @@ -16,4 +16,16 @@ #include #include +// Define a macro to import a PyMaterialX module, e.g. `PyMaterialXCore`, +// either within the `MaterialX` Python package, e.g. in `installed/python/`, +// or as a standalone module, e.g. in `lib/` +#define PYMATERIALX_IMPORT_MODULE(MODULE_NAME) \ + try \ + { \ + pybind11::module::import("MaterialX." #MODULE_NAME); \ + } \ + catch (const py::error_already_set&) \ + { \ + pybind11::module::import(#MODULE_NAME); \ + } #endif diff --git a/source/PyMaterialX/PyMaterialXFormat/PyModule.cpp b/source/PyMaterialX/PyMaterialXFormat/PyModule.cpp index 842087d24f..3965f48753 100644 --- a/source/PyMaterialX/PyMaterialXFormat/PyModule.cpp +++ b/source/PyMaterialX/PyMaterialXFormat/PyModule.cpp @@ -15,6 +15,9 @@ PYBIND11_MODULE(PyMaterialXFormat, mod) { mod.doc() = "Module containing Python bindings for the MaterialXFormat library"; + // PyMaterialXFormat depends on types defined in PyMaterialXCore + PYMATERIALX_IMPORT_MODULE(PyMaterialXCore); + bindPyFile(mod); bindPyXmlIo(mod); bindPyUtil(mod); diff --git a/source/PyMaterialX/PyMaterialXGenGlsl/PyModule.cpp b/source/PyMaterialX/PyMaterialXGenGlsl/PyModule.cpp index a36b815d32..9ab46e514d 100644 --- a/source/PyMaterialX/PyMaterialXGenGlsl/PyModule.cpp +++ b/source/PyMaterialX/PyMaterialXGenGlsl/PyModule.cpp @@ -16,6 +16,9 @@ PYBIND11_MODULE(PyMaterialXGenGlsl, mod) { mod.doc() = "Module containing Python bindings for the MaterialXGenGlsl library"; + // PyMaterialXGenGlsl depends on types defined in PyMaterialXGenShader + PYMATERIALX_IMPORT_MODULE(PyMaterialXGenShader); + bindPyGlslShaderGenerator(mod); bindPyGlslResourceBindingContext(mod); diff --git a/source/PyMaterialX/PyMaterialXGenMdl/PyModule.cpp b/source/PyMaterialX/PyMaterialXGenMdl/PyModule.cpp index 020c944e63..a34b28a729 100644 --- a/source/PyMaterialX/PyMaterialXGenMdl/PyModule.cpp +++ b/source/PyMaterialX/PyMaterialXGenMdl/PyModule.cpp @@ -13,5 +13,8 @@ PYBIND11_MODULE(PyMaterialXGenMdl, mod) { mod.doc() = "Module containing Python bindings for the MaterialXGenMdl library"; + // PyMaterialXGenMdl depends on types defined in PyMaterialXGenShader + PYMATERIALX_IMPORT_MODULE(PyMaterialXGenShader); + bindPyMdlShaderGenerator(mod); }; diff --git a/source/PyMaterialX/PyMaterialXGenMsl/PyModule.cpp b/source/PyMaterialX/PyMaterialXGenMsl/PyModule.cpp index 6eda44871b..b3dcdb10a8 100644 --- a/source/PyMaterialX/PyMaterialXGenMsl/PyModule.cpp +++ b/source/PyMaterialX/PyMaterialXGenMsl/PyModule.cpp @@ -14,6 +14,9 @@ PYBIND11_MODULE(PyMaterialXGenMsl, mod) { mod.doc() = "Module containing Python bindings for the MaterialXGenMsl library"; + // PyMaterialXGenMsl depends on types defined in PyMaterialXGenShader + PYMATERIALX_IMPORT_MODULE(PyMaterialXGenShader); + bindPyMslShaderGenerator(mod); bindPyMslResourceBindingContext(mod); } diff --git a/source/PyMaterialX/PyMaterialXGenOsl/PyModule.cpp b/source/PyMaterialX/PyMaterialXGenOsl/PyModule.cpp index d772d18b6a..54d7d2439a 100644 --- a/source/PyMaterialX/PyMaterialXGenOsl/PyModule.cpp +++ b/source/PyMaterialX/PyMaterialXGenOsl/PyModule.cpp @@ -13,5 +13,8 @@ PYBIND11_MODULE(PyMaterialXGenOsl, mod) { mod.doc() = "Module containing Python bindings for the MaterialXGenOsl library"; + // PyMaterialXGenOsl depends on types defined in PyMaterialXGenShader + PYMATERIALX_IMPORT_MODULE(PyMaterialXGenShader); + bindPyOslShaderGenerator(mod); } diff --git a/source/PyMaterialX/PyMaterialXRender/PyModule.cpp b/source/PyMaterialX/PyMaterialXRender/PyModule.cpp index 1c60142346..bbf9688403 100644 --- a/source/PyMaterialX/PyMaterialXRender/PyModule.cpp +++ b/source/PyMaterialX/PyMaterialXRender/PyModule.cpp @@ -25,6 +25,9 @@ PYBIND11_MODULE(PyMaterialXRender, mod) { mod.doc() = "Module containing Python bindings for the MaterialXRender library"; + // PyMaterialXRender depends on types defined in PyMaterialXCore + PYMATERIALX_IMPORT_MODULE(PyMaterialXCore); + bindPyMesh(mod); bindPyGeometryHandler(mod); bindPyLightHandler(mod); diff --git a/source/PyMaterialX/PyMaterialXRenderGlsl/PyModule.cpp b/source/PyMaterialX/PyMaterialXRenderGlsl/PyModule.cpp index 32fb79239d..d0ef04158d 100644 --- a/source/PyMaterialX/PyMaterialXRenderGlsl/PyModule.cpp +++ b/source/PyMaterialX/PyMaterialXRenderGlsl/PyModule.cpp @@ -16,6 +16,9 @@ PYBIND11_MODULE(PyMaterialXRenderGlsl, mod) { mod.doc() = "Module containing Python bindings for the MaterialXRenderGlsl library"; + // PyMaterialXRenderGlsl depends on types defined in PyMaterialXRender + PYMATERIALX_IMPORT_MODULE(PyMaterialXRender); + bindPyGlslProgram(mod); bindPyGlslRenderer(mod); bindPyGLTextureHandler(mod); diff --git a/source/PyMaterialX/PyMaterialXRenderMsl/PyModule.mm b/source/PyMaterialX/PyMaterialXRenderMsl/PyModule.mm index 10b440d21c..f4d0dbeaeb 100644 --- a/source/PyMaterialX/PyMaterialXRenderMsl/PyModule.mm +++ b/source/PyMaterialX/PyMaterialXRenderMsl/PyModule.mm @@ -16,6 +16,9 @@ { mod.doc() = "Module containing Python bindings for the MaterialXRenderMsl library"; + // PyMaterialXRenderMsl depends on types defined in PyMaterialXRender + PYMATERIALX_IMPORT_MODULE(PyMaterialXRender); + bindPyMslProgram(mod); bindPyMslRenderer(mod); bindPyMetalTextureHandler(mod); diff --git a/source/PyMaterialX/PyMaterialXRenderOsl/PyModule.cpp b/source/PyMaterialX/PyMaterialXRenderOsl/PyModule.cpp index 15610066f3..4019d364ab 100644 --- a/source/PyMaterialX/PyMaterialXRenderOsl/PyModule.cpp +++ b/source/PyMaterialX/PyMaterialXRenderOsl/PyModule.cpp @@ -13,5 +13,8 @@ PYBIND11_MODULE(PyMaterialXRenderOsl, mod) { mod.doc() = "Module containing Python bindings for the MaterialXRenderOsl library"; + // PyMaterialXRenderOsl depends on types defined in PyMaterialXRender + PYMATERIALX_IMPORT_MODULE(PyMaterialXRender); + bindPyOslRenderer(mod); }