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-125728 - Implement display layer's hide-on-playback flag for instanced geometry #2780

Merged
merged 4 commits into from
Dec 16, 2022
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
36 changes: 28 additions & 8 deletions lib/mayaUsd/render/vp2RenderDelegate/draw_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ class HdVP2DrawItem final : public HdDrawItem
*/
const MString& GetDrawItemName() const { return _drawItemName; }

/*! \brief Get render item name
*/
const MString& GetRenderItemName() const { return GetRenderItemData()._renderItemName; }

/*! \brief Get pointer of the associated render item
*/
MHWRender::MRenderItem* GetRenderItem() const { return GetRenderItemData()._renderItem; }
Expand All @@ -185,10 +181,6 @@ class HdVP2DrawItem final : public HdDrawItem
*/
bool MatchesUsage(RenderItemUsage usage) const { return _renderItemUsage == usage; }

/*! \brief Bitwise OR with the input dirty bits.
*/
void SetDirtyBits(HdDirtyBits bits) { GetRenderItemData().SetDirtyBits(bits); }

/*! \brief Reset the dirty bits to clean.
*/
void ResetDirtyBits() { GetRenderItemData().ResetDirtyBits(); }
Expand All @@ -199,6 +191,25 @@ class HdVP2DrawItem final : public HdDrawItem

static SdfPath RenderItemToPrimPath(const MHWRender::MRenderItem& item);

/*! Mods are used in instanced primitives to represent particular instances which visual
properties were modified by a display layer. Example: instances with hide-on-playback
flag enabled will have their own mod. A mod associated with the main draw item may have
another mod attached to it and so on, thus forming a linked list of mods.
*/
void SetMod(std::unique_ptr<HdVP2DrawItem>&& mod) { _mod = std::move(mod); }

/*! \brief Get the mod assotiated with the given draw item.
*/
HdVP2DrawItem* GetMod() { return _mod.get(); }

/*! \brief Mark this draw item as being a mod for instances with hide-on-playback enabled.
*/
void SetModFlagHideOnPlayback(bool prop) { _modFlagHideOnPlayback = prop; }

/*! \brief Verify if this draw item is a mod for instances with hide-on-playback enabled.
*/
bool GetModFlagHideOnPlayback() const { return _modFlagHideOnPlayback; }

private:
/*
Data stored directly on the HdVP2DrawItem can be shared across all the MRenderItems
Expand All @@ -216,6 +227,15 @@ class HdVP2DrawItem final : public HdDrawItem
The list of MRenderItems used to represent *this in VP2.
*/
RenderItemDataVector _renderItems; //!< VP2 render item data

/*
Mod associated with the given draw item.
This mod may have another one attached to it, thus forming a linked list
*/
std::unique_ptr<HdVP2DrawItem> _mod;

//! flag marking the given draw item as a mod for instances with hide-on-playback enabled.
bool _modFlagHideOnPlayback = false;
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
121 changes: 46 additions & 75 deletions lib/mayaUsd/render/vp2RenderDelegate/mayaPrimCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,16 @@ void MayaUsdRPrim::_FirstInitRepr(HdDirtyBits* dirtyBits, SdfPath const& id)

void MayaUsdRPrim::_SetDirtyRepr(const HdReprSharedPtr& repr)
{
const auto& items = repr->GetDrawItems();
#if HD_API_VERSION < 35
for (HdDrawItem* item : items) {
HdVP2DrawItem* drawItem = static_cast<HdVP2DrawItem*>(item);
#else
for (const HdRepr::DrawItemUniquePtr& item : items) {
HdVP2DrawItem* const drawItem = static_cast<HdVP2DrawItem*>(item.get());
#endif
if (drawItem) {
for (auto& renderItemData : drawItem->GetRenderItems()) {
if (renderItemData.GetDirtyBits() & HdChangeTracker::AllDirty) {
// About to be drawn, but the Repr is dirty. Add DirtyRepr so we know in
// _PropagateDirtyBits that we need to propagate the dirty bits of this draw
// items to ensure proper Sync
renderItemData.SetDirtyBits(HdChangeTracker::DirtyRepr);
}
}
RenderItemFunc setDirtyRepr = [](HdVP2DrawItem::RenderItemData& renderItemData) {
if (renderItemData.GetDirtyBits() & HdChangeTracker::AllDirty) {
// About to be drawn, but the Repr is dirty. Add DirtyRepr so we know in
// _PropagateDirtyBits that we need to propagate the dirty bits of this draw
// items to ensure proper Sync
renderItemData.SetDirtyBits(HdChangeTracker::DirtyRepr);
}
}
};

_ForEachRenderItemInRepr(repr, setDirtyRepr);
}

void DisableRenderItem(HdVP2DrawItem::RenderItemData& renderItemData, HdVP2RenderDelegate* delegate)
Expand Down Expand Up @@ -390,43 +381,21 @@ void MayaUsdRPrim::_PropagateDirtyBitsCommon(HdDirtyBits& bits, const ReprVector
{
if (bits & HdChangeTracker::AllDirty) {
// RPrim is dirty, propagate dirty bits to all draw items.
for (const std::pair<TfToken, HdReprSharedPtr>& pair : reprs) {
const HdReprSharedPtr& repr = pair.second;
const auto& items = repr->GetDrawItems();
#if HD_API_VERSION < 35
for (HdDrawItem* item : items) {
if (HdVP2DrawItem* drawItem = static_cast<HdVP2DrawItem*>(item)) {
#else
for (const HdRepr::DrawItemUniquePtr& item : items) {
if (HdVP2DrawItem* const drawItem = static_cast<HdVP2DrawItem*>(item.get())) {
#endif
for (auto& renderItemData : drawItem->GetRenderItems()) {
renderItemData.SetDirtyBits(bits);
}
}
}
}
RenderItemFunc setDirtyBitsToItem = [bits](HdVP2DrawItem::RenderItemData& renderItemData) {
renderItemData.SetDirtyBits(bits);
};

_ForEachRenderItem(reprs, setDirtyBitsToItem);
} else {
// RPrim is clean, find out if any drawItem about to be shown is dirty:
for (const std::pair<TfToken, HdReprSharedPtr>& pair : reprs) {
const HdReprSharedPtr& repr = pair.second;
const auto& items = repr->GetDrawItems();
#if HD_API_VERSION < 35
for (const HdDrawItem* item : items) {
if (const HdVP2DrawItem* drawItem = static_cast<const HdVP2DrawItem*>(item)) {
#else
for (const HdRepr::DrawItemUniquePtr& item : items) {
if (const HdVP2DrawItem* const drawItem = static_cast<HdVP2DrawItem*>(item.get())) {
#endif
// Is this Repr dirty and in need of a Sync?
for (auto& renderItemData : drawItem->GetRenderItems()) {
if (renderItemData.GetDirtyBits() & HdChangeTracker::DirtyRepr) {
bits |= (renderItemData.GetDirtyBits() & ~HdChangeTracker::DirtyRepr);
}
}
}
}
}
RenderItemFunc setDirtyBitsFromItem
= [&bits](HdVP2DrawItem::RenderItemData& renderItemData) {
if (renderItemData.GetDirtyBits() & HdChangeTracker::DirtyRepr) {
bits |= (renderItemData.GetDirtyBits() & ~HdChangeTracker::DirtyRepr);
}
};

_ForEachRenderItem(reprs, setDirtyBitsFromItem);
}
}

Expand Down Expand Up @@ -576,27 +545,16 @@ void MayaUsdRPrim::_MakeOtherReprRenderItemsInvisible(
const TfToken& reprToken,
const ReprVector& reprs)
{
RenderItemFunc disableRenderItem = [this](HdVP2DrawItem::RenderItemData& renderItemData) {
_delegate->GetVP2ResourceRegistry().EnqueueCommit([&renderItemData]() {
renderItemData._enabled = false;
renderItemData._renderItem->enable(false);
});
};

for (const std::pair<TfToken, HdReprSharedPtr>& pair : reprs) {
if (pair.first != reprToken) {
// For each relevant draw item, update dirty buffer sources.
const HdReprSharedPtr& repr = pair.second;
const auto& items = repr->GetDrawItems();

#if HD_API_VERSION < 35
for (HdDrawItem* item : items) {
if (HdVP2DrawItem* drawItem = static_cast<HdVP2DrawItem*>(item)) {
#else
for (const HdRepr::DrawItemUniquePtr& item : items) {
if (HdVP2DrawItem* const drawItem = static_cast<HdVP2DrawItem*>(item.get())) {
#endif
for (auto& renderItemData : drawItem->GetRenderItems()) {
_delegate->GetVP2ResourceRegistry().EnqueueCommit([&renderItemData]() {
renderItemData._enabled = false;
renderItemData._renderItem->enable(false);
});
}
}
}
_ForEachRenderItemInRepr(pair.second, disableRenderItem);
}
}
}
Expand All @@ -622,11 +580,12 @@ void MayaUsdRPrim::_ForEachRenderItemInRepr(const HdReprSharedPtr& curRepr, Rend

#if HD_API_VERSION < 35
for (HdDrawItem* item : items) {
if (HdVP2DrawItem* drawItem = static_cast<HdVP2DrawItem*>(item)) {
HdVP2DrawItem* drawItem = static_cast<HdVP2DrawItem*>(item);
#else
for (const HdRepr::DrawItemUniquePtr& item : items) {
if (HdVP2DrawItem* const drawItem = static_cast<HdVP2DrawItem*>(item.get())) {
HdVP2DrawItem* drawItem = static_cast<HdVP2DrawItem*>(item.get());
#endif
for (; drawItem; drawItem = drawItem->GetMod()) {
for (auto& renderItemData : drawItem->GetRenderItems()) {
func(renderItemData);
}
Expand Down Expand Up @@ -811,6 +770,7 @@ void MayaUsdRPrim::_SyncDisplayLayerModesInstanced(SdfPath const& id, unsigned i
_displayLayerModesInstancedFrame = drawScene.GetFrameCounter();

_needForcedBBox = false;
_needHideOnPlaybackMod = false;
if (drawScene.SupportPerInstanceDisplayLayers(id)) {
_displayLayerModesInstanced.resize(instanceCount);
for (unsigned int usdInstanceId = 0; usdInstanceId < instanceCount; usdInstanceId++) {
Expand All @@ -821,6 +781,10 @@ void MayaUsdRPrim::_SyncDisplayLayerModesInstanced(SdfPath const& id, unsigned i
if (displayLayerModes._reprOverride == kBBox) {
_needForcedBBox = true;
}

if (displayLayerModes._hideOnPlayback) {
_needHideOnPlaybackMod = true;
}
}
} else {
_displayLayerModesInstanced.clear();
Expand Down Expand Up @@ -1047,7 +1011,10 @@ bool MayaUsdRPrim::_GetMaterialPrimvars(
return true;
}

bool MayaUsdRPrim::_ShouldSkipInstance(unsigned int usdInstanceId, const TfToken& reprToken) const
bool MayaUsdRPrim::_ShouldSkipInstance(
unsigned int usdInstanceId,
const TfToken& reprToken,
bool hideOnPlaybackItem) const
{
if (_displayLayerModesInstanced.size() <= usdInstanceId) {
return false;
Expand All @@ -1068,6 +1035,10 @@ bool MayaUsdRPrim::_ShouldSkipInstance(unsigned int usdInstanceId, const TfToken
}
}

if (displayLayerModes._hideOnPlayback != hideOnPlaybackItem) {
return true;
}

return false;
}

Expand Down
12 changes: 9 additions & 3 deletions lib/mayaUsd/render/vp2RenderDelegate/mayaPrimCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ class MayaUsdRPrim
void _SyncDisplayLayerModes(SdfPath const& id);
void _SyncDisplayLayerModesInstanced(SdfPath const& id, unsigned int instanceCount);

bool _ShouldSkipInstance(unsigned int usdInstanceId, const TfToken& reprToken) const;
bool _ShouldSkipInstance(
unsigned int usdInstanceId,
const TfToken& reprToken,
bool hideOnPlaybackItem) const;

void _SyncForcedReprs(
HdRprim& refThis,
Expand All @@ -295,8 +298,8 @@ class MayaUsdRPrim

void _HideAllDrawItems(HdReprSharedPtr const& curRepr);

void _ForEachRenderItemInRepr(const HdReprSharedPtr& curRepr, RenderItemFunc& func);
void _ForEachRenderItem(const ReprVector& reprs, RenderItemFunc& func);
static void _ForEachRenderItemInRepr(const HdReprSharedPtr& curRepr, RenderItemFunc& func);
static void _ForEachRenderItem(const ReprVector& reprs, RenderItemFunc& func);

//! Helper utility function to adapt Maya API changes.
static void _SetWantConsolidation(MHWRender::MRenderItem& renderItem, bool state);
Expand Down Expand Up @@ -346,6 +349,9 @@ class MayaUsdRPrim
uint64_t _displayLayerModesFrame { 0 };
uint64_t _displayLayerModesInstancedFrame { 0 };

// For instanced primitives, specifies if at least one istance has to be hidden on playback
bool _needHideOnPlaybackMod = false;

// forced representations runtime state
bool _needForcedBBox = false;
uint64_t _forcedReprsFrame { 0 };
Expand Down
Loading