Skip to content

Commit

Permalink
[hdPrman] Fix legacyGeomSubsetSceneIndex prim removal
Browse files Browse the repository at this point in the history
legacyGeomSubsetSceneIndex was not properly cleaning up its cache of subsets upon ancestor removal.

(Internal change: 2347373)
  • Loading branch information
tgvarik authored and pixar-oss committed Nov 8, 2024
1 parent b3303a2 commit 29a46f7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
46 changes: 19 additions & 27 deletions pxr/imaging/hd/legacyGeomSubsetSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,32 @@ class _HdDataSourceLegacyGeomSubset
{
public:
HD_DECLARE_DATASOURCE(_HdDataSourceLegacyGeomSubset);

TfTokenVector GetNames() override;
HdDataSourceBaseHandle Get(const TfToken& name) override;

private:
_HdDataSourceLegacyGeomSubset(
const SdfPath& id,
const SdfPath& parentId,
const TfToken& parentType,
HdSceneDelegate* sceneDelegate);

struct _Subset
{
TfToken type;
VtIntArray indices;
bool visibility = false;
SdfPath materialBinding;

operator bool() const {
return (!type.IsEmpty() && !indices.empty());
}
};

_Subset
_FindSubset() const;

SdfPath _parentId;
TfToken _parentType;
};
Expand Down Expand Up @@ -166,7 +166,7 @@ _HdDataSourceLegacyGeomSubset::Get(const TfToken& name)
.Build();
}
}

// We must intercept visibility and materialBindings because the
// base class does not know how to compute these for geom subsets.
if (name == HdVisibilitySchema::GetSchemaToken()) {
Expand Down Expand Up @@ -202,14 +202,14 @@ _HdDataSourceLegacyGeomSubset::Get(const TfToken& name)
HdPrimvarsSchema::BuildRetained(0, nullptr, nullptr);
return emptyPrimvarsDs;
}

// To block everything else, and so prevent calling something on the
// sceneDelegate for a geom subset path about which it knows nothing, we
// only defer to base class for sceneDelegate.
if (name == HdSceneIndexEmulationTokens->sceneDelegate) {
return HdDataSourceLegacyPrim::Get(name);
}

return nullptr;
}

Expand Down Expand Up @@ -313,7 +313,7 @@ void
HdLegacyGeomSubsetSceneIndex::_PrimsAdded(
const HdSceneIndexBase& /*sender*/,
const HdSceneIndexObserver::AddedPrimEntries& entries)
{
{
HdSceneIndexObserver::AddedPrimEntries newEntries;
for (const HdSceneIndexObserver::AddedPrimEntry& entry : entries) {
if (!HdPrimTypeSupportsGeomSubsets(entry.primType)) {
Expand All @@ -326,7 +326,7 @@ HdLegacyGeomSubsetSceneIndex::_PrimsAdded(
continue;
}
// Only add prims with subsets to _parentPrims to save on memory.
_parentPrims.insert({ entry.primPath, paths });
_parentPrims.insert({ entry.primPath, paths });
for (const SdfPath& path : paths) {
newEntries.push_back({ path, HdPrimTypeTokens->geomSubset });
}
Expand All @@ -343,21 +343,13 @@ HdLegacyGeomSubsetSceneIndex::_PrimsRemoved(
const HdSceneIndexBase& /*sender*/,
const HdSceneIndexObserver::RemovedPrimEntries& entries)
{
HdSceneIndexObserver::RemovedPrimEntries removedEntries;
for (const HdSceneIndexObserver::RemovedPrimEntry& entry : entries) {
auto it = _parentPrims.find(entry.primPath);
if (it != _parentPrims.end()) {
for (const SdfPath& path : it->second) {
removedEntries.push_back({ path });
}
_parentPrims.erase(it);
auto it = _parentPrims.lower_bound(entry.primPath);
while (it != _parentPrims.end() &&
it->first.HasPrefix(entry.primPath)) {
it = _parentPrims.erase(it);
}
}
if (!removedEntries.empty()) {
removedEntries.insert(
removedEntries.begin(), entries.cbegin(), entries.cend());
return _SendPrimsRemoved(removedEntries);
}
_SendPrimsRemoved(entries);
}

Expand All @@ -378,11 +370,11 @@ HdLegacyGeomSubsetSceneIndex::_PrimsDirtied(
HdMeshTopologySchema::GetDefaultLocator() };
static const HdDataSourceLocatorSet emptyLocatorSet {
HdDataSourceLocator::EmptyLocator() };

HdSceneIndexObserver::AddedPrimEntries addedEntries;
HdSceneIndexObserver::RemovedPrimEntries removedEntries;
HdSceneIndexObserver::DirtiedPrimEntries dirtiedEntries;

for (const HdSceneIndexObserver::DirtiedPrimEntry& entry : entries) {
if (!entry.dirtyLocators.Intersects(topologyLocators)) {
// If the change didn't affect topology, we can continue. This is
Expand Down Expand Up @@ -453,7 +445,7 @@ HdLegacyGeomSubsetSceneIndex::_PrimsDirtied(
SdfPathVector
HdLegacyGeomSubsetSceneIndex::_ListDelegateSubsets(
const SdfPath& parentPath,
const HdSceneIndexPrim& parentPrim)
const HdSceneIndexPrim& parentPrim)
{
SdfPathVector paths;
if (!parentPrim.dataSource ||
Expand Down Expand Up @@ -487,7 +479,7 @@ HdLegacyGeomSubsetSceneIndex::_ListDelegateSubsets(
paths.push_back(parentPath.AppendChild(
_tokens->invisiblePoints));
}

}
}
return paths;
Expand Down
20 changes: 10 additions & 10 deletions pxr/imaging/hd/legacyGeomSubsetSceneIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "pxr/pxr.h"

#include <unordered_map>
#include <map>

PXR_NAMESPACE_OPEN_SCOPE

Expand All @@ -45,42 +45,42 @@ class HdLegacyGeomSubsetSceneIndex
HD_API
static HdLegacyGeomSubsetSceneIndexRefPtr New(
const HdSceneIndexBaseRefPtr& inputSceneIndex);

HD_API
~HdLegacyGeomSubsetSceneIndex() override;

HD_API
HdSceneIndexPrim GetPrim(const SdfPath& primPath) const override;

HD_API
SdfPathVector GetChildPrimPaths(const SdfPath& primPath) const override;

protected:
HdLegacyGeomSubsetSceneIndex(
const HdSceneIndexBaseRefPtr& inputSceneIndex);

void _PrimsAdded(
const HdSceneIndexBase& sender,
const HdSceneIndexObserver::AddedPrimEntries& entries) override;

void _PrimsRemoved(
const HdSceneIndexBase& sender,
const HdSceneIndexObserver::RemovedPrimEntries& entries) override;

void _PrimsDirtied(
const HdSceneIndexBase& sender,
const HdSceneIndexObserver::DirtiedPrimEntries& entries) override;

private:
private:
static SdfPathVector
_ListDelegateSubsets(
const SdfPath& parentPath,
const HdSceneIndexPrim& parentPrim);

// Unordered map of parent path -> [subset paths...]
// XXX: Do not use SdfPathTable because we do not want it
// to implicitly include the extra ancestor paths.
std::unordered_map<SdfPath, SdfPathVector, SdfPath::Hash> _parentPrims;
std::map<SdfPath, SdfPathVector> _parentPrims;
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down

0 comments on commit 29a46f7

Please sign in to comment.