Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions pxr/usd/usdShade/connectableAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,14 @@ struct UsdShadeConnectionSourceInfo {
bool operator!=(const UsdShadeConnectionSourceInfo &other) const {
return !(*this == other);
}

template <typename HashState>
friend void TfHashAppend(HashState& h, const UsdShadeConnectionSourceInfo& info) {
// Using the same criteria as operator==(...)
h.Append(info.sourceName);
h.Append(info.sourceType);
h.Append(info.source.GetPrim());
}
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
25 changes: 20 additions & 5 deletions pxr/usdImaging/usdImaging/materialAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,17 @@ _IsConnectionDirty(
const UsdPrim& dirtyPrim,
const TfTokenVector& dirtyProperties,
const UsdShadeMaterial& material,
const UsdShadeConnectionSourceInfo& connection)
const UsdShadeConnectionSourceInfo& connection,
TfHashMap<UsdShadeConnectionSourceInfo, bool, TfHash>& seenConnections)
{
if (bool seen; TfMapLookup(seenConnections, connection, &seen))
return seen;

if (!connection.IsValid())
{
seenConnections.insert({connection, false});
return false;
}

// If we reach the root material only dirty if we are connected to the
// specific property which is dirty and don't recurse further.
Expand All @@ -141,15 +148,18 @@ _IsConnectionDirty(
&& dirtyProperty
== connection.source.GetInput(connection.sourceName)
.GetFullName())) {
seenConnections.insert({connection, true});
return true;
}
}
}
seenConnections.insert({connection, false});
return false;
}

// We are connected to the dirty prim
if (connection.source.GetPrim() == dirtyPrim) {
seenConnections.insert({connection, true});
return true;
}

Expand All @@ -162,7 +172,8 @@ _IsConnectionDirty(
output.GetConnectedSources()) {
if (_IsConnectionDirty(
dirtyPrim, dirtyProperties, material,
outputConnection)) {
outputConnection, seenConnections)) {
seenConnections.insert({connection, true});
return true;
}
}
Expand All @@ -174,12 +185,14 @@ _IsConnectionDirty(
for (UsdShadeConnectionSourceInfo& inputConnection :
input.GetConnectedSources()) {
if (_IsConnectionDirty(
dirtyPrim, dirtyProperties, material, inputConnection)) {
dirtyPrim, dirtyProperties, material, inputConnection, seenConnections)) {
seenConnections.insert({connection, true});
return true;
}
}
}

seenConnections.insert({connection, false});
return false;
}

Expand All @@ -201,7 +214,8 @@ UsdImagingMaterialAdapter::InvalidateImagingSubprim(
for (UsdShadeOutput& output : material.GetOutputs()) {
for (UsdShadeConnectionSourceInfo& connection :
output.GetConnectedSources()) {
if (_IsConnectionDirty(prim, properties, material, connection)) {
TfHashMap<UsdShadeConnectionSourceInfo, bool, TfHash> seenConnections;
if (_IsConnectionDirty(prim, properties, material, connection, seenConnections)) {
result.insert(_CreateTerminalLocator(output.GetBaseName()));
}
}
Expand Down Expand Up @@ -235,8 +249,9 @@ UsdImagingMaterialAdapter::InvalidateImagingSubprimFromDescendent(
for (UsdShadeOutput& output : material.GetOutputs()) {
for (UsdShadeConnectionSourceInfo& connection :
output.GetConnectedSources()) {
TfHashMap<UsdShadeConnectionSourceInfo, bool, TfHash> seenConnections;
if (_IsConnectionDirty(
descendentPrim, properties, material, connection)) {
descendentPrim, properties, material, connection, seenConnections)) {
result.insert(_CreateTerminalLocator(output.GetBaseName()));
}
}
Expand Down
Loading