Skip to content

Commit 193b815

Browse files
Add support for df_vulkan as MDL test renderer (#2743)
Wrapper code based on that for the OSL test renderer and intermediate code from #2254. The new CMake variable MATERIALX_MDL_BINARY_TESTRENDER contains the path of the df_vulkan binary, and is derived from MATERIALX_MDL_SDK_DIR. Use x64-windows-release triplet for the MDL SDK to save disk space on the runners (and build time).
1 parent 7c98bbe commit 193b815

8 files changed

Lines changed: 327 additions & 12 deletions

File tree

.github/workflows/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ jobs:
174174
- name: Install MDL SDK
175175
if: env.IS_EXTENDED_BUILD == 'true' && matrix.extended_build_mdl_sdk == 'ON' && runner.os == 'Windows'
176176
run: |
177-
C:/vcpkg/vcpkg install mdl-sdk --triplet=x64-windows
178-
Add-Content $env:GITHUB_PATH "C:/vcpkg/installed/x64-windows/bin"
177+
C:/vcpkg/vcpkg install mdl-sdk[dds,df-vulkan,openimageio] --triplet=x64-windows-release
178+
Add-Content $env:GITHUB_PATH "C:/vcpkg/installed/x64-windows-release/bin"
179179
180180
- name: Install Python ${{ matrix.python }}
181181
if: matrix.python != 'None'
@@ -198,13 +198,13 @@ jobs:
198198
EXTENDED_BUILD_CONFIG=""
199199
if [ "${{ env.IS_EXTENDED_BUILD }}" == "true" ]; then
200200
if [ "${{ runner.os }}" == "Windows" ]; then
201-
EXTENDED_BUILD_CONFIG="-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows"
201+
EXTENDED_BUILD_CONFIG="-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
202202
fi
203203
if [ "${{ matrix.extended_build_oiio }}" == "ON" ]; then
204-
EXTENDED_BUILD_CONFIG="$EXTENDED_BUILD_CONFIG -DMATERIALX_BUILD_OIIO=ON"
204+
EXTENDED_BUILD_CONFIG="$EXTENDED_BUILD_CONFIG -DVCPKG_TARGET_TRIPLET=x64-windows -DMATERIALX_BUILD_OIIO=ON"
205205
fi
206206
if [ "${{ matrix.extended_build_mdl_sdk }}" == "ON" -a "${{ runner.os }}" == "Windows" ]; then
207-
EXTENDED_BUILD_CONFIG="$EXTENDED_BUILD_CONFIG -DMATERIALX_MDL_SDK_DIR=C:/vcpkg/installed/x64-windows"
207+
EXTENDED_BUILD_CONFIG="$EXTENDED_BUILD_CONFIG -DVCPKG_TARGET_TRIPLET=x64-windows-release -DMATERIALX_MDL_SDK_DIR=C:/vcpkg/installed/x64-windows-release"
208208
fi
209209
fi
210210
TEST_RENDER_CONFIG="-DMATERIALX_TEST_RENDER=OFF"

CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ mark_as_advanced(MATERIALX_EMSDK_PATH)
224224
mark_as_advanced(MATERIALX_BUILD_IOS)
225225
mark_as_advanced(MATERIALX_BUILD_APPLE_FRAMEWORK)
226226
mark_as_advanced(MATERIALX_MDL_BINARY_MDLC)
227+
mark_as_advanced(MATERIALX_MDL_BINARY_TESTRENDER)
227228
mark_as_advanced(MATERIALX_MDL_MODULE_PATHS)
228229
mark_as_advanced(MATERIALX_MDL_SDK_DIR)
229230
mark_as_advanced(MATERIALX_SLANG_RHI_SOURCE_DIR)
@@ -264,11 +265,23 @@ if (MATERIALX_BUILD_BENCHMARK_TESTS)
264265
add_definitions(-DMATERIALX_BUILD_BENCHMARK_TESTS)
265266
endif()
266267

267-
# GEN MDL does not have any additional dependencies. For loading and compiling MDL, e.g., in the test renderer, the MDL SDK is needed.
268+
# MaterialXGenMdl does not have any additional dependencies.
269+
# MaterialXTest/MaterialXGenMdl performs a syntax check if the mdlc binary is available.
270+
# MaterialXTest/MaterialXRenderMdl needs the df_vulkan example, SDK library, and image plugins.
268271
if(MATERIALX_MDL_SDK_DIR)
269272
find_package(mdl QUIET CONFIG REQUIRED PATHS ${MATERIALX_MDL_SDK_DIR})
270273
get_target_property(MATERIALX_MDL_BINARY_MDLC mdl::mdlc LOCATION)
271274
set(MATERIALX_MDL_BINARY_MDLC ${MATERIALX_MDL_BINARY_MDLC} CACHE FILEPATH "Full path to the mdlc binary." FORCE)
275+
if((${mdl_VERSION} VERSION_GREATER_EQUAL "2025.0.3") OR (${mdl_VERSION} STREQUAL "trunk"))
276+
find_program(MATERIALX_MDL_BINARY_TESTRENDER
277+
NAMES df_vulkan
278+
HINTS
279+
${MATERIALX_MDL_SDK_DIR}/examples/mdl_sdk/df_vulkan # regular install layout
280+
${MATERIALX_MDL_SDK_DIR}/tools/mdl-sdk) # vcpkg layout
281+
else()
282+
message(WARNING "The MDL df_vulkan test renderer requires an MDL SDK >= 2025.0.3 (found ${mdl_VERSION}).")
283+
set(MATERIALX_MDL_BINARY_TESTRENDER "" CACHE FILEPATH "Full path to the MDL df_vulkan test renderer.")
284+
endif()
272285
endif()
273286

274287
# Adjust the default installation path

python/MaterialXTest/tests_to_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def main(args=None):
106106
langFiles1 = []
107107
langPaths1 = []
108108
for subdir, _, files in os.walk(args.inputdir1):
109-
for curFile in files:
109+
for curFile in sorted(files):
110110
if curFile.endswith(args.lang1 + ".png"):
111111
langFiles1.append(curFile)
112112
langPaths1.append(subdir)

source/MaterialXGenMdl/MdlShaderGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ ShaderPtr MdlShaderGenerator::generate(const string& name, ElementPtr element, G
220220
inputSocket->getType().getSemantic() == TypeDesc::SEMANTIC_CLOSURE ||
221221
inputSocket->getType().getSemantic() == TypeDesc::SEMANTIC_MATERIAL))
222222
{
223-
const string& qualifier = inputSocket->isUniform() || inputSocket->getType() == Type::FILENAME
224-
? uniformPrefix
223+
const string& qualifier = inputSocket->isUniform() || inputSocket->getType() == Type::FILENAME
224+
? uniformPrefix
225225
: EMPTY_STRING;
226226
const string& type = _syntax->getTypeName(inputSocket->getType());
227227

source/MaterialXTest/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ if(MATERIALX_BUILD_RENDER)
8181
add_subdirectory(MaterialXRenderOsl)
8282
target_link_libraries(MaterialXTest MaterialXRenderOsl)
8383
endif()
84+
if(MATERIALX_BUILD_GEN_MDL)
85+
add_subdirectory(MaterialXRenderMdl)
86+
endif()
8487
if(APPLE AND MATERIALX_BUILD_GEN_MSL)
8588
add_subdirectory(MaterialXRenderMsl)
8689
target_link_libraries(MaterialXTest MaterialXRenderMsl)

source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,20 @@ void MdlStringResolver::initialize(
5858
paths.append(addSp);
5959
}
6060

61+
// use a set to remove duplicates while keeping the order
62+
auto less = [](const mx::FilePath& lhs, const mx::FilePath& rhs)
63+
{ return lhs.asString() < rhs.asString(); };
64+
std::set<mx::FilePath, decltype(less)> unique_paths(less);
65+
6166
_mdl_searchPaths.clear();
6267
for (const auto& path : paths)
6368
{
6469
// normalize all search paths, as we need this later in `resolve`
6570
auto normalizedPath = path.getNormalized();
66-
if (normalizedPath.exists())
71+
if (normalizedPath.exists() && unique_paths.insert(normalizedPath).second)
72+
{
6773
_mdl_searchPaths.append(normalizedPath);
74+
}
6875
}
6976

7077
_logFile = logFile;
@@ -105,7 +112,7 @@ std::string MdlStringResolver::resolve(const std::string& str, const std::string
105112
}
106113
if (_logFile)
107114
{
108-
*_logFile << "MaterialX resource can not be accessed through an MDL search path. "
115+
*_logFile << "Failed to resolve a MaterialX resource via the given search paths. "
109116
<< "Dropping the resource from the Material. Resource Path: "
110117
<< normalizedPath.asString().c_str() << std::endl;
111118
}
@@ -244,7 +251,7 @@ void MdlShaderGeneratorTester::compileSource(const std::vector<mx::FilePath>& so
244251
mdlcCommand += " ::" + moduleToTest;
245252

246253
// redirect output
247-
mx::FilePath errorFile = moduleToTestPath / (moduleToTest + ".mdl_compile_errors.txt");
254+
mx::FilePath errorFile = moduleToTestPath / (moduleToTest + "_log.txt");
248255
mdlcCommand += " > " + errorFile.asString() + " 2>&1";
249256

250257
// execute the compiler and evaluate return code and the output stream
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
file(GLOB_RECURSE source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
2+
file(GLOB_RECURSE headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
3+
4+
target_sources(MaterialXTest PUBLIC ${source} ${headers})
5+
6+
if (NOT MATERIALX_BUILD_MONOLITHIC)
7+
get_target_property(MaterialXGenMdl_SOURCE_DIR MaterialXGenMdl SOURCE_DIR)
8+
else()
9+
get_target_property(PROJECT_SOURCE_DIR ${MATERIALX_MONOLITHIC_TARGET} SOURCE_DIR)
10+
set(MaterialXGenMdl_SOURCE_DIR "{PROJECT_SOURCE_DIR}/MaterialXGenMdl")
11+
endif()
12+
13+
target_compile_definitions(MaterialXTest PRIVATE
14+
MATERIALX_MDL_BINARY_TESTRENDER=\"${MATERIALX_MDL_BINARY_TESTRENDER}\"
15+
MATERIALX_MDL_IMPL_MODULE_PATH=\"${MaterialXGenMdl_SOURCE_DIR}/mdl\"
16+
MATERIALX_INSTALL_MDL_MODULE_PATH=\"${MATERIALX_INSTALL_STDLIB_PATH}\"
17+
MATERIALX_MDL_MODULE_PATHS=\"${MATERIALX_MDL_MODULE_PATHS}\"
18+
)
19+
20+
add_tests("${source}")
21+
22+
assign_source_group("Source Files" ${source})
23+
assign_source_group("Header Files" ${headers})

0 commit comments

Comments
 (0)