Global MDL file search path not compatible with parallel material loading

Suppose I want to load two MDL files from two different locations in parallel using the IMdl_impexp_api::load_module function.

The function takes a material module name as an argument and resolves it using the search path added with IMdl_configuration::add_mdl_path().

The problem I see is that the search path state is global - modifying it in parallel leads to wrong results.

Is there an alternative way to achieve the same or would it be possible to adjust the API to allow this use case?

Thank you!

Why do you need a different search path for your second module? Is it clear that the search path is a list of paths that are searched in order and that directories below form packages in the mdl namespace?

in general, modifying the search path between module loads is dangerous because a module in the mdl namespace might map to a different file.

Why do you need a different search path for your second module?

As a real-world example, I get the search paths on a material/shader basis from OpenUSD’s MDL info:mdl:sourceAsset parameter. The path is used to resolve modules that are shipped with the asset, as it is the case for OpenUSD files from TurboSquid and the NV samples. Since such a path is relative to the USD layer, and a USD scene can be composed of multiple layers, the paths can differ within an asset.

Is it clear that the search path is a list of paths that are searched in order […]

Yes, and exactly this order can cause ambiguities when two independent “sibling” MDL modules are processed in parallel – that is, if they have the same name or reference another MDL file that has the same name as another. A hardcoded global search path would lead them to load the exact same file due to the path order, which is not desired. Hence, the path must be changed between module loads, which prevents parallel processing.