Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAYA-136105 - Optimize MaterialX 1.38.5 #4063

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions lib/mayaUsd/render/vp2RenderDelegate/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@

#ifdef WANT_MATERIALX_BUILD
#include <mayaUsd/render/MaterialXGenOgsXml/CombinedMaterialXVersion.h>
#include <mayaUsd/render/MaterialXGenOgsXml/LobePruner.h>
#include <mayaUsd/render/MaterialXGenOgsXml/OgsFragment.h>
#include <mayaUsd/render/MaterialXGenOgsXml/OgsXmlGenerator.h>
#include <mayaUsd/render/MaterialXGenOgsXml/ShaderGenUtil.h>
#if MX_COMBINED_VERSION >= 13808
#include <mayaUsd/render/MaterialXGenOgsXml/LobePruner.h>
#endif

#include <MaterialXCore/Document.h>
#include <MaterialXFormat/File.h>
Expand Down Expand Up @@ -356,7 +354,6 @@ struct _MaterialXData
static const std::string env = TfGetenv("USDMTLX_PRIMARY_UV_NAME");
_mainUvSetName = env.empty() ? UsdUtilsGetPrimaryUVSetName().GetString() : env;

#if MX_COMBINED_VERSION >= 13808
_lobePruner = MaterialXMaya::ShaderGenUtil::LobePruner::create();
_lobePruner->setLibrary(_mtlxLibrary);
_lobePruner->optimizeLibrary(_mtlxLibrary);
Expand All @@ -370,7 +367,6 @@ struct _MaterialXData
// NodeGraph boundary, then no optimization will be found. This would require a change
// in the LobePruner to detect transitive weights. Doable, but complex. We will wait
// until there is sufficient demand.
#endif
} catch (mx::Exception& e) {
TF_RUNTIME_ERROR(
"Caught exception '%s' while initializing MaterialX library", e.what());
Expand All @@ -379,9 +375,7 @@ struct _MaterialXData
MaterialX::FileSearchPath _mtlxSearchPath; //!< MaterialX library search path
MaterialX::DocumentPtr _mtlxLibrary; //!< MaterialX library
std::string _mainUvSetName; //!< Main UV set name
#if MX_COMBINED_VERSION >= 13808
MaterialXMaya::ShaderGenUtil::LobePruner::Ptr _lobePruner;
#endif

private:
void _FixLibraryTangentInputs(MaterialX::DocumentPtr& mtlxLibrary);
Expand Down Expand Up @@ -483,16 +477,12 @@ size_t _GenerateNetwork2TopoHash(const HdMaterialNetwork2& materialNetwork)
MayaUsd::hash_combine(topoHash, hash_value(nodePair.first));

const auto& node = nodePair.second;
#if MX_COMBINED_VERSION >= 13808
TfToken optimizedNodeId = _GetMaterialXData()._lobePruner->getOptimizedNodeId(node);
TfToken optimizedNodeId = _GetMaterialXData()._lobePruner->getOptimizedNodeId(node);
if (optimizedNodeId.IsEmpty()) {
MayaUsd::hash_combine(topoHash, hash_value(node.nodeTypeId));
} else {
MayaUsd::hash_combine(topoHash, hash_value(optimizedNodeId));
}
#else
MayaUsd::hash_combine(topoHash, hash_value(node.nodeTypeId));
#endif
if (_IsTopologicalNode(node)) {
// We need to capture values that affect topology:
for (auto const& p : node.parameters) {
Expand Down Expand Up @@ -2912,16 +2902,12 @@ void HdVP2Material::CompiledNetwork::_ApplyMtlxVP2Fixes(
for (const auto& nodePair : inNet.nodes) {
const HdMaterialNode2& inNode = nodePair.second;
HdMaterialNode2 outNode;
#if MX_COMBINED_VERSION >= 13808
TfToken optimizedNodeId = _GetMaterialXData()._lobePruner->getOptimizedNodeId(inNode);
if (optimizedNodeId.IsEmpty()) {
outNode.nodeTypeId = inNode.nodeTypeId;
} else {
outNode.nodeTypeId = optimizedNodeId;
}
#else
outNode.nodeTypeId = inNode.nodeTypeId;
#endif
if (_IsTopologicalNode(inNode)) {
// These parameters affect topology:
outNode.parameters = inNode.parameters;
Expand Down
Loading