diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0c0a301cf2..b1694d324b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -193,6 +193,7 @@ jobs: - name: CMake Generate shell: bash run: | + EXTENDED_BUILD_CONFIG="" if [ "${{ env.IS_EXTENDED_BUILD }}" == "true" ]; then if [ "${{ runner.os }}" == "Windows" ]; then EXTENDED_BUILD_CONFIG="-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows" @@ -204,7 +205,14 @@ jobs: EXTENDED_BUILD_CONFIG="$EXTENDED_BUILD_CONFIG -DMATERIALX_MDL_SDK_DIR=C:/vcpkg/installed/x64-windows" fi fi - cmake -S . -B build -DMATERIALX_BUILD_PYTHON=ON -DMATERIALX_BUILD_VIEWER=ON -DMATERIALX_BUILD_GRAPH_EDITOR=ON -DMATERIALX_BUILD_TESTS=ON -DMATERIALX_TEST_RENDER=OFF -DMATERIALX_WARNINGS_AS_ERRORS=ON $EXTENDED_BUILD_CONFIG ${{matrix.cmake_config}} + TEST_RENDER_CONFIG="-DMATERIALX_TEST_RENDER=OFF" + if [ "${{ matrix.test_render }}" == "ON" ]; then + if [ "${{ runner.os }}" == "macOS" ]; then + TEST_RENDER_CONFIG="-DMATERIALX_TEST_RENDER=ON -DMATERIALX_RENDER_MSL_ONLY=ON" + fi + fi + EXTENDED_BUILD_CONFIG="$EXTENDED_BUILD_CONFIG $TEST_RENDER_CONFIG" + cmake -S . -B build -DMATERIALX_BUILD_PYTHON=ON -DMATERIALX_BUILD_VIEWER=ON -DMATERIALX_BUILD_GRAPH_EDITOR=ON -DMATERIALX_BUILD_TESTS=ON -DMATERIALX_WARNINGS_AS_ERRORS=ON $EXTENDED_BUILD_CONFIG ${{matrix.cmake_config}} - name: CMake Build run: cmake --build build --target install --config Release --parallel 2 @@ -332,6 +340,13 @@ jobs: name: Renders_${{ matrix.name }} path: build/render/*.png + - name: Upload Resources (MacOS) + uses: actions/upload-artifact@v4 + if: matrix.test_render == 'ON' && runner.os == 'macOS' + with: + name: Resources_${{ matrix.name }} + path: build/bin/resources + - name: Upload Coverage Report uses: actions/upload-artifact@v4 if: matrix.coverage_analysis == 'ON' diff --git a/CMakeLists.txt b/CMakeLists.txt index a4bba653b7..357270cc89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ option(MATERIALX_BUILD_GEN_MSL "Build the MSL shader generator back-end." ON) option(MATERIALX_BUILD_GEN_SLANG "Build the Slang shader generator back-end." ON) option(MATERIALX_BUILD_RENDER "Build the MaterialX Render modules." ON) option(MATERIALX_BUILD_RENDER_PLATFORMS "Build platform-specific render modules for each shader generator." ON) +option(MATERIALX_RENDER_MSL_ONLY "On macOS, use Metal Shading Language only for tests and viewer (skips GLSL render tests)." OFF) option(MATERIALX_BUILD_OIIO "Build OpenImageIO support for MaterialXRender." OFF) option(MATERIALX_BUILD_OCIO "Build OpenColorIO support for shader generators." OFF) option(MATERIALX_BUILD_TESTS "Build unit tests." OFF) @@ -112,6 +113,17 @@ if (MATERIALX_BUILD_JS) set(MATERIALX_BUILD_TESTS OFF) endif() +# Validate MSL-only rendering option +if(MATERIALX_RENDER_MSL_ONLY) + if(NOT APPLE) + message(FATAL_ERROR "MATERIALX_RENDER_MSL_ONLY can only be enabled on Apple platforms") + endif() + if(NOT MATERIALX_BUILD_GEN_MSL) + message(FATAL_ERROR "MATERIALX_RENDER_MSL_ONLY requires MATERIALX_BUILD_GEN_MSL to be enabled") + endif() + message(STATUS "MSL-only testing mode enabled - MaterialXTest will not link MaterialXRenderGlsl") +endif() + # All hardware shading languages currently depend on the GLSL shader generator. if(MATERIALX_BUILD_GEN_MSL) set(MATERIALX_BUILD_GEN_GLSL ON) @@ -178,6 +190,7 @@ mark_as_advanced(MATERIALX_BUILD_GEN_MSL) mark_as_advanced(MATERIALX_BUILD_OSOS) mark_as_advanced(MATERIALX_BUILD_RENDER) mark_as_advanced(MATERIALX_BUILD_RENDER_PLATFORMS) +mark_as_advanced(MATERIALX_RENDER_MSL_ONLY) mark_as_advanced(MATERIALX_BUILD_OIIO) mark_as_advanced(MATERIALX_BUILD_OCIO) mark_as_advanced(MATERIALX_BUILD_BENCHMARK_TESTS) diff --git a/source/MaterialXTest/CMakeLists.txt b/source/MaterialXTest/CMakeLists.txt index 1825420d51..1da03b9060 100644 --- a/source/MaterialXTest/CMakeLists.txt +++ b/source/MaterialXTest/CMakeLists.txt @@ -69,7 +69,7 @@ endif() if(MATERIALX_BUILD_RENDER) add_subdirectory(MaterialXRender) target_link_libraries(MaterialXTest MaterialXRender) - if(MATERIALX_BUILD_GEN_GLSL) + if(MATERIALX_BUILD_GEN_GLSL AND NOT MATERIALX_RENDER_MSL_ONLY) add_subdirectory(MaterialXRenderGlsl) target_link_libraries(MaterialXTest MaterialXRenderGlsl) endif() diff --git a/source/MaterialXView/CMakeLists.txt b/source/MaterialXView/CMakeLists.txt index f9f9eb256c..0bbad1ebef 100644 --- a/source/MaterialXView/CMakeLists.txt +++ b/source/MaterialXView/CMakeLists.txt @@ -11,7 +11,12 @@ if(APPLE) set(USE_OPENGL_BACKEND_ON_APPLE_PLATFORM ON) endif() - if(USE_OPENGL_BACKEND_ON_APPLE_PLATFORM) + # Force Metal backend if MSL-only rendering is enabled + if(MATERIALX_RENDER_MSL_ONLY) + set(USE_OPENGL_BACKEND_ON_APPLE_PLATFORM OFF) + set(NANOGUI_PREFERRED_BACKEND Metal) + set(MATERIALXVIEW_RENDER_BACKEND_DEFINITIONS "-DMATERIALXVIEW_METAL_BACKEND=1") + elseif(USE_OPENGL_BACKEND_ON_APPLE_PLATFORM) set(NANOGUI_PREFERRED_BACKEND OpenGL) set(MATERIALXVIEW_RENDER_BACKEND_DEFINITIONS "-DMATERIALXVIEW_OPENGL_BACKEND=1") else()