Skip to content

Commit

Permalink
hd: emulate non-hierarchical removal in render index
Browse files Browse the repository at this point in the history
Originally, when HdSceneDelegate removed a prim from the render index
via RemoveRprim, RemoveSprim or RemoveBprim, it did not remove any
children.  HdRenderIndex::RemoveSprim was updated in a previous commit
to reproduce the flat behavior but other prim types were left
unchanged.  This change moves the RemoveSprim behavior into
HdLegacyPrimSceneIndex so that removing Sprims, Rprims and Bprims are
handled uniformly in scene index emulation.

(Internal change: 2262307)
  • Loading branch information
jloy authored and pixar-oss committed Feb 8, 2023
1 parent d9a0463 commit 6b3afc2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
11 changes: 11 additions & 0 deletions pxr/imaging/hd/legacyPrimSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ HdLegacyPrimSceneIndex::AddLegacyPrim(SdfPath const &id, TfToken const &type,
HdDataSourceLegacyPrim::New(id, type, sceneDelegate)}});
}

void
HdLegacyPrimSceneIndex::RemovePrim(SdfPath const &id)
{
if (!GetChildPrimPaths(id).empty()) {
AddPrims({{id, TfToken(), nullptr}});
}
else {
RemovePrims({id});
}
}

void
HdLegacyPrimSceneIndex::DirtyPrims(
const HdSceneIndexObserver::DirtiedPrimEntries &entries)
Expand Down
12 changes: 12 additions & 0 deletions pxr/imaging/hd/legacyPrimSceneIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class HdLegacyPrimSceneIndex : public HdRetainedSceneIndex
void AddLegacyPrim(SdfPath const &id, TfToken const &type,
HdSceneDelegate *sceneDelegate);

/// Remove only the prim at \p id without affecting children.
///
/// If \p id has children, it is replaced by an entry with no type
/// and no data source. If \p id does not have children, it is
/// removed from the retained scene index.
///
/// This is called by HdRenderIndex on behalf of legacy
/// HdSceneDelegates to emulate the original behavior of
/// Remove{B,R,S}Prim, which did not remove children.
///
void RemovePrim(SdfPath const &id);

/// extends to also call DirtyPrim on HdDataSourceLegacyPrim
void DirtyPrims(
const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
Expand Down
17 changes: 3 additions & 14 deletions pxr/imaging/hd/renderIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ HdRenderIndex::RemoveRprim(SdfPath const& id)
// If we are emulating let's remove from the scene index
// which will trigger render index removals later.
if (_IsEnabledSceneIndexEmulation()) {
_emulationSceneIndex->RemovePrims({id});
_emulationSceneIndex->RemovePrim(id);
return;
}

Expand Down Expand Up @@ -643,18 +643,7 @@ void
HdRenderIndex::RemoveSprim(TfToken const& typeId, SdfPath const& id)
{
if (_IsEnabledSceneIndexEmulation()) {

// Removing an sprim doesn't remove any descendant prims from the
// renderIndex. Removing a prim from the scene index does remove
// all descendant prims. Special case removal of an sprim which has
// children to instead be replaced with an empty type.
if (!_emulationSceneIndex->GetChildPrimPaths(id).empty()) {
_emulationSceneIndex->AddPrims({{id, TfToken(), nullptr}});
return;
}

_emulationSceneIndex->RemovePrims({id});

_emulationSceneIndex->RemovePrim(id);
return;
}

Expand Down Expand Up @@ -727,7 +716,7 @@ void
HdRenderIndex::RemoveBprim(TfToken const& typeId, SdfPath const& id)
{
if (_IsEnabledSceneIndexEmulation()) {
_emulationSceneIndex->RemovePrims({id});
_emulationSceneIndex->RemovePrim(id);
return;
}

Expand Down

0 comments on commit 6b3afc2

Please sign in to comment.