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-121408 Trigger the populate selection when a new instancer is added #2038

Merged
Merged
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
46 changes: 17 additions & 29 deletions lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,7 @@ void ProxyRenderDelegate::_ClearRenderDelegate()

// reset any version ids or dirty information that doesn't make sense if we clear
// the render index.
_renderTagVersion = 0;
#ifdef ENABLE_RENDERTAG_VISIBILITY_WORKAROUND
_visibilityVersion = 0;
#endif
_changeVersions.reset();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored how these "versions" of things from USD are tracked into a single struct to keep it simpler.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much nicer, thx!

_taskRenderTagsValid = false;
_isPopulated = false;
}
Expand Down Expand Up @@ -558,13 +555,9 @@ void ProxyRenderDelegate::_InitRenderDelegate()
HdVP2RenderDelegate::sProfilerCategory, MProfiler::kColorD_L1, "Allocate RenderIndex");
_renderIndex.reset(HdRenderIndex::New(_renderDelegate.get(), HdDriverVector()));

// Set the _renderTagVersion and _visibilityVersion so that we don't trigger a
// needlessly large update them on the first frame.
HdChangeTracker& changeTracker = _renderIndex->GetChangeTracker();
_renderTagVersion = changeTracker.GetRenderTagVersion();
#ifdef ENABLE_RENDERTAG_VISIBILITY_WORKAROUND
_visibilityVersion = changeTracker.GetVisibilityChangeCount();
#endif
// Sync the _changeVersions so that we don't trigger a needlessly large update them on the
// first frame.
_changeVersions.sync(_renderIndex->GetChangeTracker());

// Add additional configurations after render index creation.
static std::once_flag reprsOnce;
Expand Down Expand Up @@ -776,21 +769,22 @@ void ProxyRenderDelegate::_Execute(const MHWRender::MFrameContext& frameContext)
= MHWRender::MGeometryUtilities::wireframeColor(_proxyShapeData->ProxyDagPath());
}

// To work around USD issue #1516 set instanceIndexChange to true. By default leave the value
// false. There is a significant performance overhead caused by populating selection every
// frame, and the workflows that trigger it are much more common then changing instancing.
// See MayaUSD issue #1991 for the performance problem.
// We don't know if any instanced object has had it's instance index change, so re-populate
// selection every update to ensure correct selection highlighting of instanced objects.
bool instanceIndexChanged = false;
// Work around USD issue #1516. There is a significant performance overhead caused by populating
// selection, so only force the populate selection to occur when we detect a change which
// impacts the instance indexing.
HdChangeTracker& changeTracker = _renderIndex->GetChangeTracker();
bool forcePopulateSelection = !_changeVersions.instanceIndexValid(changeTracker);
_changeVersions.sync(changeTracker);

#ifdef MAYA_NEW_POINT_SNAPPING_SUPPORT
if (_selectionModeChanged || (_selectionChanged && !inSelectionPass) || instanceIndexChanged) {
if (_selectionModeChanged || (_selectionChanged && !inSelectionPass)
|| forcePopulateSelection) {
_UpdateSelectionStates();
_selectionChanged = false;
_selectionModeChanged = false;
}
#else
if ((_selectionChanged && !inSelectionPass) || instanceIndexChanged) {
if ((_selectionChanged && !inSelectionPass) || forcePopulateSelection) {
_UpdateSelectionStates();
_selectionChanged = false;
}
Expand Down Expand Up @@ -842,8 +836,7 @@ void ProxyRenderDelegate::_Execute(const MHWRender::MFrameContext& frameContext)
// Mark everything "dirty" so that sync is called on everything
// If there are multiple views up with different viewport modes then
// this is slow.
auto& rprims = _renderIndex->GetRprimIds();
HdChangeTracker& changeTracker = _renderIndex->GetChangeTracker();
auto& rprims = _renderIndex->GetRprimIds();
for (auto path : rprims) {
changeTracker.MarkRprimDirty(path, MayaPrimCommon::DirtyDisplayMode);
}
Expand Down Expand Up @@ -1324,10 +1317,10 @@ void ProxyRenderDelegate::_UpdateRenderTags()
// or when the global render tags are set. Check to see if the render tags version has
// changed since the last time we set the render tags so we know if there is a change
// to an individual rprim or not.
bool rprimRenderTagChanged = (_renderTagVersion != changeTracker.GetRenderTagVersion());
bool rprimRenderTagChanged = !_changeVersions.renderTagValid(changeTracker);
#ifdef ENABLE_RENDERTAG_VISIBILITY_WORKAROUND
rprimRenderTagChanged
= rprimRenderTagChanged || (_visibilityVersion != changeTracker.GetVisibilityChangeCount());
= rprimRenderTagChanged || !_changeVersions.visibilityValid(changeTracker);
#endif

bool renderPurposeChanged = false;
Expand Down Expand Up @@ -1412,11 +1405,6 @@ void ProxyRenderDelegate::_UpdateRenderTags()
// UsdImagingDelegate::GetRenderTag(). So far I don't see an advantage of
// using this feature for MayaUSD, but it may be useful at some point in
// the future.

_renderTagVersion = changeTracker.GetRenderTagVersion();
#ifdef ENABLE_RENDERTAG_VISIBILITY_WORKAROUND
_visibilityVersion = changeTracker.GetVisibilityChangeCount();
#endif
}

//! \brief List the rprims in collection that match renderTags
Expand Down
50 changes: 43 additions & 7 deletions lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,49 @@ class ProxyRenderDelegate : public MHWRender::MPxSubSceneOverride
//! A collection of Rprims to prepare render data for specified reprs
std::unique_ptr<HdRprimCollection> _defaultCollection;

//! The render tag version used the last time render tags were updated
unsigned int _renderTagVersion { 0 }; // initialized to 1 in HdChangeTracker, so we'll always
// have an invalid version the first update.
#ifdef ENABLE_RENDERTAG_VISIBILITY_WORKAROUND
unsigned int _visibilityVersion { 0 }; // initialized to 1 in HdChangeTracker.
#endif
bool _taskRenderTagsValid {
// Version Id values saved from the last time we queried the HdChangeTracker.
// These values are initialized to 1 in HdChangeTracker
struct HdChangeTrackerVersions
{
//! The render tag version the last time _Execute was called
unsigned int _renderTag { 0 };
//! The visibility change count the last time _Execute was called
unsigned int _visibility { 0 };
//! The combined instancer index version and instance index change count the last time
//! _Execute was called
unsigned int _instanceIndex { 0 };

void sync(const HdChangeTracker& tracker)
{
_renderTag = tracker.GetRenderTagVersion();
_visibility = tracker.GetVisibilityChangeCount();
_instanceIndex = tracker.GetInstancerIndexVersion();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetInstanceIndexVersion doesn't capture all the workflows we care about, but it captures some of them. So at least some things work correctly with this updated version of the code.

}

bool renderTagValid(const HdChangeTracker& tracker)
{
return _renderTag == tracker.GetRenderTagVersion();
}

bool visibilityValid(const HdChangeTracker& tracker)
{
return _visibility == tracker.GetVisibilityChangeCount();
}

bool instanceIndexValid(const HdChangeTracker& tracker)
{
return _instanceIndex == tracker.GetInstancerIndexVersion();
}

void reset()
{
_renderTag = 0;
_visibility = 0;
_instanceIndex = 0;
}
};
HdChangeTrackerVersions _changeVersions;
bool _taskRenderTagsValid {
false
}; //!< If false the render tags on the dummy render task are not the minimum set of tags.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.