From 8ac460e80ebe9249bb8719e2bae7f7885645722b Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 4 Jun 2020 11:37:47 -0700 Subject: [PATCH 01/35] [px_vp20] add GetMFrameContextDisplayStyle() utility function for the legacy viewport This creates a public utility function out of the _ToMFrameContextDisplayStyle() private, static function in PxrMayaHdShapeAdapter. A subsequent commit will remove the old function and replace its usage with the new public function. --- lib/mayaUsd/render/px_vp20/utils_legacy.h | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lib/mayaUsd/render/px_vp20/utils_legacy.h b/lib/mayaUsd/render/px_vp20/utils_legacy.h index cc0148d3e9..08aa936e77 100644 --- a/lib/mayaUsd/render/px_vp20/utils_legacy.h +++ b/lib/mayaUsd/render/px_vp20/utils_legacy.h @@ -18,9 +18,24 @@ /// \file px_vp20/utils_legacy.h +// XXX: With Maya versions up through 2019 on Linux, M3dView.h ends up +// indirectly including an X11 header that #define's "Bool" as int: +// - includes +// - includes +// - includes +// - does: "#define Bool int" +// This can cause compilation issues if is included +// afterwards, so to fix this, we ensure that it gets included first. +// +// The X11 include appears to have been removed in Maya 2020+, so this should +// no longer be an issue with later versions. +#include + #include #include +#include +#include #include #include @@ -40,6 +55,40 @@ class px_LegacyViewportUtils GfMatrix4d& viewMatrix, GfMatrix4d& projectionMatrix); + /// Helper function that converts M3dView::DisplayStyle from the legacy + /// viewport into MHWRender::MFrameContext::DisplayStyle for Viewport + /// 2.0. + /// + /// In the legacy viewport, the M3dView can be in exactly one + /// displayStyle whereas Viewport 2.0's displayStyle is a bitmask of + /// potentially multiple styles. To translate from the legacy viewport + /// to Viewport 2.0, we simply bitwise-OR the single legacy viewport + /// displayStyle into an empty mask. + static unsigned int GetMFrameContextDisplayStyle( + M3dView::DisplayStyle legacyDisplayStyle) { + unsigned int displayStyle = 0u; + + switch (legacyDisplayStyle) { + case M3dView::kBoundingBox: + displayStyle |= MHWRender::MFrameContext::DisplayStyle::kBoundingBox; + break; + case M3dView::kFlatShaded: + displayStyle |= MHWRender::MFrameContext::DisplayStyle::kFlatShaded; + break; + case M3dView::kGouraudShaded: + displayStyle |= MHWRender::MFrameContext::DisplayStyle::kGouraudShaded; + break; + case M3dView::kWireFrame: + displayStyle |= MHWRender::MFrameContext::DisplayStyle::kWireFrame; + break; + case M3dView::kPoints: + // Not supported. + break; + } + + return displayStyle; + } + private: px_LegacyViewportUtils() = delete; ~px_LegacyViewportUtils() = delete; From 49705735385f5e978a19b7a8492212ef8779d602 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 4 Jun 2020 11:54:13 -0700 Subject: [PATCH 02/35] [pxrUsdMayaGL] use new utility function to convert legacy display status for VP 2.0 This change removes the private, static _ToMFrameContextDisplayStyle for PxrMayaHdShapeAdapter in favor of the newly added px_LegacyViewportUtils::GetMFrameContextDisplayStyle(). --- .../render/pxrUsdMayaGL/shapeAdapter.cpp | 38 ++----------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index b9345f26b7..c8e3c84138 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -43,6 +43,7 @@ #include #include +#include #include #include #include @@ -51,40 +52,6 @@ PXR_NAMESPACE_OPEN_SCOPE -// Helper function that converts M3dView::DisplayStyle (legacy viewport) into -// MHWRender::MFrameContext::DisplayStyle (Viewport 2.0). -// -// In the legacy viewport, the M3dView can be in exactly one displayStyle -// whereas Viewport 2.0's displayStyle is a bitmask of potentially multiple -// styles. To translate from the legacy viewport to Viewport 2.0, we simply -// bitwise-OR the single legacy viewport displayStyle into an empty mask. -static inline -unsigned int -_ToMFrameContextDisplayStyle(const M3dView::DisplayStyle legacyDisplayStyle) -{ - unsigned int displayStyle = 0u; - - switch (legacyDisplayStyle) { - case M3dView::kBoundingBox: - displayStyle |= MHWRender::MFrameContext::DisplayStyle::kBoundingBox; - break; - case M3dView::kFlatShaded: - displayStyle |= MHWRender::MFrameContext::DisplayStyle::kFlatShaded; - break; - case M3dView::kGouraudShaded: - displayStyle |= MHWRender::MFrameContext::DisplayStyle::kGouraudShaded; - break; - case M3dView::kWireFrame: - displayStyle |= MHWRender::MFrameContext::DisplayStyle::kWireFrame; - break; - case M3dView::kPoints: - // Not supported. - break; - } - - return displayStyle; -} - // Helper function that converts M3dView::DisplayStatus (legacy viewport) into // MHWRender::DisplayStatus (Viewport 2.0). static inline @@ -122,7 +89,8 @@ PxrMayaHdShapeAdapter::Sync( UsdMayaGLBatchRenderer::GetInstance().StartBatchingFrameDiagnostics(); const unsigned int displayStyle = - _ToMFrameContextDisplayStyle(legacyDisplayStyle); + px_LegacyViewportUtils::GetMFrameContextDisplayStyle( + legacyDisplayStyle); const MHWRender::DisplayStatus displayStatus = _ToMHWRenderDisplayStatus(legacyDisplayStatus); From 4f4106538f444464782868ad95d00ca4df412b2c Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 4 Jun 2020 12:03:15 -0700 Subject: [PATCH 03/35] [px_vp20] add functions for testing whether the display style indicates bounding box rendering --- lib/mayaUsd/render/px_vp20/utils.h | 9 +++++++++ lib/mayaUsd/render/px_vp20/utils_legacy.h | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/lib/mayaUsd/render/px_vp20/utils.h b/lib/mayaUsd/render/px_vp20/utils.h index c7ef3dc45b..23e5a51f9e 100644 --- a/lib/mayaUsd/render/px_vp20/utils.h +++ b/lib/mayaUsd/render/px_vp20/utils.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -64,6 +65,14 @@ class px_vp20Utils const MHWRender::MDrawContext& context, M3dView& view); + /// Returns true if the given Maya display style indicates that a + /// bounding box should be rendered. + static bool ShouldRenderBoundingBox(unsigned int displayStyle) { + const bool boundingBoxStyle = + displayStyle & MHWRender::MFrameContext::DisplayStyle::kBoundingBox; + return boundingBoxStyle; + } + /// Renders the given bounding box in the given \p color via OpenGL. MAYAUSD_CORE_PUBLIC static bool RenderBoundingBox( diff --git a/lib/mayaUsd/render/px_vp20/utils_legacy.h b/lib/mayaUsd/render/px_vp20/utils_legacy.h index 08aa936e77..1abeb8b392 100644 --- a/lib/mayaUsd/render/px_vp20/utils_legacy.h +++ b/lib/mayaUsd/render/px_vp20/utils_legacy.h @@ -89,6 +89,13 @@ class px_LegacyViewportUtils return displayStyle; } + /// Returns true if the given Maya display style indicates that a + /// bounding box should be rendered. + static bool ShouldRenderBoundingBox( + M3dView::DisplayStyle legacyDisplayStyle) { + return (legacyDisplayStyle == M3dView::kBoundingBox); + } + private: px_LegacyViewportUtils() = delete; ~px_LegacyViewportUtils() = delete; From 2db526e3fe7822f8b9bc3d1f5c734ae6c2ee9730 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 4 Jun 2020 12:21:14 -0700 Subject: [PATCH 04/35] [pxrUsdMayaGL] add batch renderer methods for drawing bounding boxes only The current batch renderer API offers Draw() functions that draw shapes, bounding boxes, or both depending on the user data. The usage, however, is that only the PxrHdImagingShape invokes a draw for all of the shapes, and then individual shapes only need to draw their bounding boxes. This change adds independent bounding box-only methods that the shapes can use when they need to draw their bounding boxes. Subsequent commits will update MPxDrawOverrides and MPxSurfaceShapeUIs to use the appropriate draw method. --- .../render/pxrUsdMayaGL/batchRenderer.cpp | 87 +++++++++++++++++++ .../render/pxrUsdMayaGL/batchRenderer.h | 10 +++ 2 files changed, 97 insertions(+) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp index b9b228ce07..1a986617c4 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp @@ -735,6 +735,93 @@ UsdMayaGLBatchRenderer::Draw( } } +void +UsdMayaGLBatchRenderer::DrawBoundingBox( + const MDrawRequest& request, + M3dView& view) +{ + // Legacy viewport implementation. + + TRACE_FUNCTION(); + + MProfilingScope profilingScope( + ProfilerCategory, + MProfiler::kColorC_L2, + "Batch Renderer DrawBoundingBox() (Legacy Viewport)"); + + MDrawData drawData = request.drawData(); + + const PxrMayaHdUserData* hdUserData = + static_cast(drawData.geometry()); + if (!hdUserData || !hdUserData->boundingBox) { + return; + } + + MMatrix modelViewMat; + view.modelViewMatrix(modelViewMat); + + MMatrix projectionMat; + view.projectionMatrix(projectionMat); + const GfMatrix4d projectionMatrix(projectionMat.matrix); + + // For the legacy viewport, apply a framebuffer gamma correction when + // drawing bounding boxes, just like we do when drawing geometry via Hydra. + glEnable(GL_FRAMEBUFFER_SRGB_EXT); + + px_vp20Utils::RenderBoundingBox( + *(hdUserData->boundingBox), + *(hdUserData->wireframeColor), + modelViewMat, + projectionMat); + + glDisable(GL_FRAMEBUFFER_SRGB_EXT); + + // Clean up the user data. + delete hdUserData; +} + +void +UsdMayaGLBatchRenderer::DrawBoundingBox( + const MHWRender::MDrawContext& context, + const MUserData* userData) +{ + // Viewport 2.0 implementation. + + TRACE_FUNCTION(); + + MProfilingScope profilingScope( + ProfilerCategory, + MProfiler::kColorC_L2, + "Batch Renderer DrawBoundingBox() (Viewport 2.0)"); + + const PxrMayaHdUserData* hdUserData = + dynamic_cast(userData); + if (!hdUserData || !hdUserData->boundingBox) { + return; + } + + const MHWRender::MRenderer* theRenderer = + MHWRender::MRenderer::theRenderer(); + if (!theRenderer || !theRenderer->drawAPIIsOpenGL()) { + return; + } + + MStatus status; + + const MMatrix worldViewMat = + context.getMatrix(MHWRender::MFrameContext::kWorldViewMtx, &status); + + const MMatrix projectionMat = + context.getMatrix(MHWRender::MFrameContext::kProjectionMtx, &status); + const GfMatrix4d projectionMatrix(projectionMat.matrix); + + px_vp20Utils::RenderBoundingBox( + *(hdUserData->boundingBox), + *(hdUserData->wireframeColor), + worldViewMat, + projectionMat); +} + GfVec2i UsdMayaGLBatchRenderer::GetSelectionResolution() const { diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h index 126aafffbe..717774b369 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h @@ -188,6 +188,16 @@ class UsdMayaGLBatchRenderer const MHWRender::MDrawContext& context, const MUserData* userData); + /// Render bounding box in the legacy viewport based on \p request + MAYAUSD_CORE_PUBLIC + void DrawBoundingBox(const MDrawRequest& request, M3dView& view); + + /// Render bounding box in Viewport 2.0 based on \p userData + MAYAUSD_CORE_PUBLIC + void DrawBoundingBox( + const MHWRender::MDrawContext& context, + const MUserData* userData); + /// Gets the resolution of the draw target used for computing selections. /// /// The resolution is specified as (width, height). From a5491201dc502010d491b2428b4b19abaa413cd7 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 4 Jun 2020 14:12:32 -0700 Subject: [PATCH 05/35] [pxrUsdMayaGL] always query the shape's bounding box when preparing for viewport draw This ensures that the bounding box is always available in case the viewport display style is changed and we don't end up executing another shape adapter Sync(). --- .../render/pxrUsdMayaGL/proxyDrawOverride.cpp | 19 ++----------------- .../render/pxrUsdMayaGL/proxyShapeUI.cpp | 19 ++----------------- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp index 5429ae97d6..30297ea418 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp @@ -208,24 +208,9 @@ UsdMayaProxyDrawOverride::prepareForDraw( UsdMayaGLBatchRenderer::GetInstance().AddShapeAdapter(&_shapeAdapter); - bool drawShape; - bool drawBoundingBox; - _shapeAdapter.GetRenderParams(&drawShape, &drawBoundingBox); + const MBoundingBox boundingBox = shape->boundingBox(); - if (!drawBoundingBox && !drawShape) { - // We weren't asked to do anything. - return nullptr; - } - - MBoundingBox boundingBox; - MBoundingBox* boundingBoxPtr = nullptr; - if (drawBoundingBox) { - // Only query for the bounding box if we're drawing it. - boundingBox = shape->boundingBox(); - boundingBoxPtr = &boundingBox; - } - - return _shapeAdapter.GetMayaUserData(oldData, boundingBoxPtr); + return _shapeAdapter.GetMayaUserData(oldData, &boundingBox); } /* virtual */ diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeUI.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeUI.cpp index 127668d8f9..2fec829760 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeUI.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeUI.cpp @@ -85,26 +85,11 @@ UsdMayaProxyShapeUI::getDrawRequests( UsdMayaGLBatchRenderer::GetInstance().AddShapeAdapter(&_shapeAdapter); - bool drawShape; - bool drawBoundingBox; - _shapeAdapter.GetRenderParams(&drawShape, &drawBoundingBox); - - if (!drawBoundingBox && !drawShape) { - // We weren't asked to do anything. - return; - } - - MBoundingBox boundingBox; - MBoundingBox* boundingBoxPtr = nullptr; - if (drawBoundingBox) { - // Only query for the bounding box if we're drawing it. - boundingBox = shape->boundingBox(); - boundingBoxPtr = &boundingBox; - } + const MBoundingBox boundingBox = shape->boundingBox(); MDrawRequest request = drawInfo.getPrototype(*this); - _shapeAdapter.GetMayaUserData(this, request, boundingBoxPtr); + _shapeAdapter.GetMayaUserData(this, request, &boundingBox); // Add the request to the queue. requests.add(request); From 1d2ad706230a612465192f233d91240ee6ae00a6 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 15:05:09 -0700 Subject: [PATCH 06/35] [pxrUsdMayaGL] remove early out in GetMayaUserData() Since practically we will now always have a bounding box in GetMayaUserData(), we remove the early return that used to check for it. --- lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index c8e3c84138..cceb3d6ab2 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -182,17 +182,10 @@ PxrMayaHdShapeAdapter::GetMayaUserData( // Viewport 2.0 implementation (also called by legacy viewport // implementation). // - // Our PxrMayaHdUserData can be used to signify whether we are requesting a - // shape to be rendered, a bounding box, both, or neither. - // // In the Viewport 2.0 prepareForDraw() usage, any MUserData object passed // into the function will be deleted by Maya. In the legacy viewport usage, // the object gets deleted at the end of a legacy viewport Draw() call. - if (!_drawShape && !boundingBox) { - return nullptr; - } - PxrMayaHdUserData* newData = dynamic_cast(oldData); if (!newData) { newData = new PxrMayaHdUserData(); From 1cecda707e17b3f6df15cad815f09a8cc29965ec Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 4 Jun 2020 14:22:40 -0700 Subject: [PATCH 07/35] [pxrUsdMayaGL] add private helper function for determining active status from displayStatus There are a handful of Maya displayStatus values that we consider "active", which means that Hydra should draw them including their wireframe. This reduces some duplicated code for determining whether the shape is active. --- .../render/pxrUsdMayaGL/shapeAdapter.cpp | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index cceb3d6ab2..9b25fe8b55 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -77,6 +77,18 @@ _ToMHWRenderDisplayStatus(const M3dView::DisplayStatus legacyDisplayStatus) return MHWRender::DisplayStatus((int)legacyDisplayStatus); } +static inline +bool +_IsActiveDisplayStatus(MHWRender::DisplayStatus displayStatus) +{ + return + (displayStatus == MHWRender::DisplayStatus::kActive) || + (displayStatus == MHWRender::DisplayStatus::kHilite) || + (displayStatus == MHWRender::DisplayStatus::kActiveTemplate) || + (displayStatus == MHWRender::DisplayStatus::kActiveComponent) || + (displayStatus == MHWRender::DisplayStatus::kLead); +} + /* virtual */ bool PxrMayaHdShapeAdapter::Sync( @@ -233,16 +245,11 @@ PxrMayaHdShapeAdapter::GetReprSelectorForDisplayState( return reprSelector; } + const bool isActive = _IsActiveDisplayStatus(displayStatus); + const bool shadeActiveOnlyStyle = displayStyle & MHWRender::MFrameContext::DisplayStyle::kShadeActiveOnly; - const bool isActive = - (displayStatus == MHWRender::DisplayStatus::kActive) || - (displayStatus == MHWRender::DisplayStatus::kHilite) || - (displayStatus == MHWRender::DisplayStatus::kActiveTemplate) || - (displayStatus == MHWRender::DisplayStatus::kActiveComponent) || - (displayStatus == MHWRender::DisplayStatus::kLead); - const bool wireframeStyle = displayStyle & MHWRender::MFrameContext::DisplayStyle::kWireFrame; @@ -403,12 +410,7 @@ PxrMayaHdShapeAdapter::_GetWireframeColor( const bool wireframeStyle = (displayStyle & wireframeDisplayStyles); - const bool isActive = - (displayStatus == MHWRender::DisplayStatus::kActive) || - (displayStatus == MHWRender::DisplayStatus::kHilite) || - (displayStatus == MHWRender::DisplayStatus::kActiveTemplate) || - (displayStatus == MHWRender::DisplayStatus::kActiveComponent) || - (displayStatus == MHWRender::DisplayStatus::kLead); + const bool isActive = _IsActiveDisplayStatus(displayStatus); if (wireframeStyle || isActive) { useWireframeColor = true; From e4a7ace81c24650a9d38e0583f1d3a1b365eaa7a Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 4 Jun 2020 14:46:17 -0700 Subject: [PATCH 08/35] [pxrUsdMayaGL] add useWireframe field to the render params This field will provide an easy way to re-use the state determined during Sync(). Subsequent changes will make it so that only the displayStatus (and not the viewport-specific displayStyle) determine whether or not to use the wireframe. --- lib/mayaUsd/render/pxrUsdMayaGL/renderParams.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/renderParams.h b/lib/mayaUsd/render/pxrUsdMayaGL/renderParams.h index c0093d01ac..a8e9a94632 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/renderParams.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/renderParams.h @@ -35,12 +35,14 @@ struct PxrMayaHdRenderParams // Color Params // + bool useWireframe = false; GfVec4f wireframeColor = GfVec4f(0.0f); /// Helper function to find a batch key for the render params size_t Hash() const { size_t hash = size_t(enableLighting); + boost::hash_combine(hash, useWireframe); boost::hash_combine(hash, wireframeColor); return hash; From 93a82ced84f6741781fb8de0fab3163b8a0c60cb Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 4 Jun 2020 16:13:11 -0700 Subject: [PATCH 09/35] [pxrUsdMayaGL] store whether or not to use the wireframe into the render params This boolean will soon be based on only the shape's display status and not any viewport's display style, so it can accurately be cached during calls to Sync() and re-used in between. --- lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp index 0ba420b78c..325ce5a82f 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp @@ -222,13 +222,13 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( unsigned int reprDisplayStyle = displayStyle; MColor mayaWireframeColor; - const bool useWireframeColor = + _renderParams.useWireframe = _GetWireframeColor( displayStyle, displayStatus, _shapeDagPath, &mayaWireframeColor); - if (useWireframeColor) { + if (_renderParams.useWireframe) { _renderParams.wireframeColor = GfVec4f(mayaWireframeColor.r, mayaWireframeColor.g, mayaWireframeColor.b, From 77465473589d8e6e9b6ced40fbb2c86a22ebe256 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 4 Jun 2020 16:26:46 -0700 Subject: [PATCH 10/35] [pxrUsdMayaGL] use render params useWireframe and query displayStatus when computing repr This change renames the shape adapter GetReprSelectorForDisplayState() function to GetReprSelectorForDisplayStyle(), makes it non-virtual, and only requires that the displayStyle be provided. It will query Maya for the shape's displayStatus itself. We also use the render params' useWireframe field to determine whether or not to use a repr that includes the wireframe, in addition to the displayStyle. Note that we are still erroneously using the displayStyle at Sync() time to decide whether or not to enable lighting. This can be addressed later but for now it only causes subtly incorrect visual results for wireframe display styles in certain cases. --- .../pxrUsdMayaGL/instancerShapeAdapter.cpp | 19 +++++++++------ .../render/pxrUsdMayaGL/shapeAdapter.cpp | 12 ++++++---- .../render/pxrUsdMayaGL/shapeAdapter.h | 19 +++++++-------- .../pxrUsdMayaGL/usdProxyShapeAdapter.cpp | 24 +++++++++---------- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp index c084a2779d..0b0a97ec0d 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp @@ -227,7 +227,7 @@ bool UsdMayaGL_InstancerShapeAdapter::_Sync( const MDagPath& shapeDagPath, const unsigned int displayStyle, - const MHWRender::DisplayStatus displayStatus) + const MHWRender::DisplayStatus /* displayStatus */) { MStatus status; UsdPrim usdPrim = _instancerStage->GetDefaultPrim(); @@ -262,10 +262,17 @@ UsdMayaGL_InstancerShapeAdapter::_Sync( // In contrast with the other shape adapters, this adapter ignores the // selection wireframe. The native instancer doesn't draw selection // wireframes, so we want to mimic that behavior for consistency. - HdReprSelector reprSelector = - GetReprSelectorForDisplayState( - displayStyle, - displayStatus); + + // XXX: This is not technically correct. Since the display style can vary + // per viewport, this decision of whether or not to enable lighting should + // be delayed until when the repr for each viewport is known during batched + // drawing. For now, the incorrectly shaded wireframe is not too offensive + // though. + // + // If the repr selector specifies a wireframe-only repr, then disable + // lighting. + const HdReprSelector reprSelector = + GetReprSelectorForDisplayStyle(displayStyle); _drawShape = reprSelector.AnyActiveRepr(); @@ -275,8 +282,6 @@ UsdMayaGL_InstancerShapeAdapter::_Sync( // geometry, though; is there any way to "teach" it about our bounds? _drawBoundingBox = false; - // If the repr selector specifies a wireframe-only repr, then disable - // lighting. if (reprSelector.Contains(HdReprTokens->wire) || reprSelector.Contains(HdReprTokens->refinedWire)) { _renderParams.enableLighting = false; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index 9b25fe8b55..1de1a9e766 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -223,11 +223,9 @@ PxrMayaHdShapeAdapter::GetMayaUserData( return newData; } -/* virtual */ HdReprSelector -PxrMayaHdShapeAdapter::GetReprSelectorForDisplayState( - const unsigned int displayStyle, - const MHWRender::DisplayStatus displayStatus) const +PxrMayaHdShapeAdapter::GetReprSelectorForDisplayStyle( + unsigned int displayStyle) const { HdReprSelector reprSelector; @@ -245,13 +243,17 @@ PxrMayaHdShapeAdapter::GetReprSelectorForDisplayState( return reprSelector; } + const MHWRender::DisplayStatus displayStatus = + MHWRender::MGeometryUtilities::displayStatus(_shapeDagPath); + const bool isActive = _IsActiveDisplayStatus(displayStatus); const bool shadeActiveOnlyStyle = displayStyle & MHWRender::MFrameContext::DisplayStyle::kShadeActiveOnly; const bool wireframeStyle = - displayStyle & MHWRender::MFrameContext::DisplayStyle::kWireFrame; + (displayStyle & MHWRender::MFrameContext::DisplayStyle::kWireFrame) || + _renderParams.useWireframe; const bool flatShadedStyle = displayStyle & MHWRender::MFrameContext::DisplayStyle::kFlatShaded; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index 698b7270f6..07db6d3a1a 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -143,7 +143,7 @@ class PxrMayaHdShapeAdapter const MBoundingBox* boundingBox = nullptr); /// Gets the HdReprSelector that corresponds to the given Maya display - /// state. + /// style. /// /// \p displayStyle should be a bitwise combination of /// MHWRender::MFrameContext::DisplayStyle values, typically either @@ -152,18 +152,17 @@ class PxrMayaHdShapeAdapter /// obtained using MHWRender::MFrameContext::getDisplayStyle() for /// Viewport 2.0. /// - /// \p displayStatus is typically either up-converted from - /// a M3dView::DisplayStatus value obtained using - /// MDrawInfo::displayStatus() for the legacy viewport, or obtained - /// using MHWRender::MGeometryUtilities::displayStatus() for Viewport - /// 2.0. + /// The HdReprSelector chosen is also dependent on the display status + /// (active/selected vs. inactive) which Maya is queried for, as well + /// as whether or not the render params specify that we are using the + /// shape's wireframe, which is influenced by both the display status + /// and whether or not the shape is involved in a soft selection. /// /// If there is no corresponding HdReprSelector for the given display - /// state, an empty HdReprSelector is returned. + /// style, an empty HdReprSelector is returned. MAYAUSD_CORE_PUBLIC - virtual HdReprSelector GetReprSelectorForDisplayState( - const unsigned int displayStyle, - const MHWRender::DisplayStatus displayStatus) const; + HdReprSelector GetReprSelectorForDisplayStyle( + unsigned int displayStyle) const; /// Get a set of render params from the shape adapter's current state. /// diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp index 325ce5a82f..65f3470cf7 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp @@ -219,8 +219,6 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( // Will only react if time actually changes. _delegate->SetTime(timeCode); - unsigned int reprDisplayStyle = displayStyle; - MColor mayaWireframeColor; _renderParams.useWireframe = _GetWireframeColor( @@ -233,24 +231,24 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( mayaWireframeColor.g, mayaWireframeColor.b, mayaWireframeColor.a); - - // Add in kWireFrame to the display style we'll use to determine the - // repr selector (e.g. so that we draw the wireframe over the shaded - // geometry for selected objects). - reprDisplayStyle |= MHWRender::MFrameContext::DisplayStyle::kWireFrame; } - HdReprSelector reprSelector = - GetReprSelectorForDisplayState( - reprDisplayStyle, - displayStatus); + // XXX: This is not technically correct. Since the display style can vary + // per viewport, this decision of whether or not to enable lighting should + // be delayed until when the repr for each viewport is known during batched + // drawing. For now, the incorrectly shaded wireframe is not too offensive + // though. + // + // If the repr selector specifies a wireframe-only repr, then disable + // lighting. The useWireframe property of the render params is used to + // determine the repr, so be sure to do this *after* that has been set. + const HdReprSelector reprSelector = + GetReprSelectorForDisplayStyle(displayStyle); _drawShape = reprSelector.AnyActiveRepr(); _drawBoundingBox = (displayStyle & MHWRender::MFrameContext::DisplayStyle::kBoundingBox); - // If the repr selector specifies a wireframe-only repr, then disable - // lighting. if (reprSelector.Contains(HdReprTokens->wire) || reprSelector.Contains(HdReprTokens->refinedWire)) { _renderParams.enableLighting = false; From ba208dfb96b11ecc15ad9578532bf22802097dd3 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 10:14:42 -0700 Subject: [PATCH 11/35] [pxrUsdMayaGL] remove drawShape and drawBoundingBox params from GetRenderParams() Draw overrides for individual shapes will call the batch renderer's DrawBoundingBox() and pxrHdImagingShape's draw override will call Draw(), so we don't need the shape adapters to track (unreliably) whether to draw its shape and/or bounding box, especially since those can also vary depending on each viewport's displayStyle. --- .../render/pxrUsdMayaGL/batchRenderer.cpp | 3 +-- .../render/pxrUsdMayaGL/shapeAdapter.cpp | 25 ------------------- .../render/pxrUsdMayaGL/shapeAdapter.h | 12 +++------ 3 files changed, 5 insertions(+), 35 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp index 1a986617c4..c6d4118e76 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp @@ -160,8 +160,7 @@ UsdMayaGLBatchRenderer::AddShapeAdapter(PxrMayaHdShapeAdapter* shapeAdapter) _shapeAdapterBuckets : _legacyShapeAdapterBuckets; - const PxrMayaHdRenderParams renderParams = - shapeAdapter->GetRenderParams(nullptr, nullptr); + const PxrMayaHdRenderParams& renderParams = shapeAdapter->GetRenderParams(); const size_t renderParamsHash = renderParams.Hash(); TF_DEBUG(PXRUSDMAYAGL_SHAPE_ADAPTER_BUCKETING).Msg( diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index 1de1a9e766..ef33c5681c 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -209,7 +209,6 @@ PxrMayaHdShapeAdapter::GetMayaUserData( // of batching up the drawing of all of the shapes, so we specify in the // Maya user data that the shape should *not* draw by default. The // pxrHdImagingShape bypasses this and sets drawShape to true. - // We handle this similarly in GetRenderParams() below. newData->drawShape = false; if (boundingBox) { @@ -296,30 +295,6 @@ PxrMayaHdShapeAdapter::GetReprSelectorForDisplayStyle( return reprSelector; } -/* virtual */ -PxrMayaHdRenderParams -PxrMayaHdShapeAdapter::GetRenderParams( - bool* drawShape, - bool* drawBoundingBox) const -{ - if (drawShape) { - // Internally, the shape adapter keeps track of whether its shape is - // being drawn for managing visibility, but otherwise most Hydra-imaged - // shapes should not be drawing themselves. The pxrHdImagingShape will - // take care of batching up the drawing of all of the shapes, so for - // the purposes of render params, we set drawShape to false by default. - // The pxrHdImagingShape bypasses this and sets drawShape to true. - // We handle this similarly in GetMayaUserData() above. - *drawShape = false; - } - - if (drawBoundingBox) { - *drawBoundingBox = _drawBoundingBox; - } - - return _renderParams; -} - /* virtual */ const HdRprimCollection& PxrMayaHdShapeAdapter::GetRprimCollection() const diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index 07db6d3a1a..0b65ec1a4f 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -164,14 +164,10 @@ class PxrMayaHdShapeAdapter HdReprSelector GetReprSelectorForDisplayStyle( unsigned int displayStyle) const; - /// Get a set of render params from the shape adapter's current state. - /// - /// Sets \p drawShape and \p drawBoundingBox depending on whether shape - /// and/or bounding box rendering is indicated from the state. - MAYAUSD_CORE_PUBLIC - virtual PxrMayaHdRenderParams GetRenderParams( - bool* drawShape, - bool* drawBoundingBox) const; + /// Get the render params for the shape adapter's current state. + const PxrMayaHdRenderParams& GetRenderParams() const { + return _renderParams; + } MAYAUSD_CORE_PUBLIC virtual const HdRprimCollection& GetRprimCollection() const; From 6ba5129ccd2c118bf7ef3aec7516e5bdfa1ea0ae Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 10:27:32 -0700 Subject: [PATCH 12/35] [pxrUsdMayaGL] remove now unused _drawBoundingBox field on shape adapters --- lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp | 6 ------ lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h | 1 - lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp | 2 -- 3 files changed, 9 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp index 0b0a97ec0d..4bd4d3dcb3 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp @@ -276,12 +276,6 @@ UsdMayaGL_InstancerShapeAdapter::_Sync( _drawShape = reprSelector.AnyActiveRepr(); - // We won't ever draw the bounding box here because the native Maya - // instancer already draws a bounding box, and we don't want to draw two. - // XXX: The native Maya instancer's bounding box will only cover the native - // geometry, though; is there any way to "teach" it about our bounds? - _drawBoundingBox = false; - if (reprSelector.Contains(HdReprTokens->wire) || reprSelector.Contains(HdReprTokens->refinedWire)) { _renderParams.enableLighting = false; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index 0b65ec1a4f..9d036f5b49 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -282,7 +282,6 @@ class PxrMayaHdShapeAdapter PxrMayaHdRenderParams _renderParams; bool _drawShape; - bool _drawBoundingBox; HdRprimCollection _rprimCollection; TfTokenVector _renderTags; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp index 65f3470cf7..8fc0ed393f 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp @@ -246,8 +246,6 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( GetReprSelectorForDisplayStyle(displayStyle); _drawShape = reprSelector.AnyActiveRepr(); - _drawBoundingBox = - (displayStyle & MHWRender::MFrameContext::DisplayStyle::kBoundingBox); if (reprSelector.Contains(HdReprTokens->wire) || reprSelector.Contains(HdReprTokens->refinedWire)) { From 90aeee46360967847f12c8baf5080de8fad2de0e Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 10:37:03 -0700 Subject: [PATCH 13/35] [pxrUsdMayaGL] call batch renderer DrawBoundingBox() from USD proxy shape draw callbacks Only the pxrHdImagingShape will actually invoke a Hydra draw to render shapes, so the only reason that individual shape draw callbacks will do any drawing is if they need to draw the bounding box for their shape. --- lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h | 6 ++++-- .../render/pxrUsdMayaGL/proxyDrawOverride.cpp | 11 ++++++----- lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeUI.cpp | 12 +++++++----- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h index 717774b369..5b0595fdd5 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h @@ -93,8 +93,10 @@ using HgiUniquePtr = std::unique_ptr; /// A user data object should also be created/obtained for the shape by calling /// the shape adapter's GetMayaUserData() method. /// -/// In the draw stage, Draw() must be called for each draw request to complete -/// the render. +/// Typically, all Hydra-imaged shapes will be drawn automatically as a single +/// batch by the pxrHdImagingShape. However, bounding boxes are not drawn by +/// Hydra, so each draw override should invoke DrawBoundingBox() to do that if +/// necessary. /// /// Draw/selection management objects should be sure to call /// RemoveShapeAdapter() (usually in the destructor) when they no longer wish diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp index 30297ea418..0897509c77 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp @@ -299,11 +299,12 @@ UsdMayaProxyDrawOverride::draw( MProfiler::kColorC_L1, "USD Proxy Shape draw() (Viewport 2.0)"); - // Note that this Draw() call is only necessary when we're drawing the - // bounding box, since that is not yet handled by Hydra and is instead done - // internally by the batch renderer on a per-shape basis. Otherwise, the - // pxrHdImagingShape is what will invoke Hydra to draw the shape. - UsdMayaGLBatchRenderer::GetInstance().Draw(context, data); + const unsigned int displayStyle = context.getDisplayStyle(); + if (!px_vp20Utils::ShouldRenderBoundingBox(displayStyle)) { + return; + } + + UsdMayaGLBatchRenderer::GetInstance().DrawBoundingBox(context, data); } diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeUI.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeUI.cpp index 2fec829760..9aa901b15e 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeUI.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeUI.cpp @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -106,17 +107,18 @@ UsdMayaProxyShapeUI::draw(const MDrawRequest& request, M3dView& view) const MProfiler::kColorC_L1, "USD Proxy Shape draw() (Legacy Viewport)"); + const M3dView::DisplayStyle legacyDisplayStyle = view.displayStyle(); + if (!px_LegacyViewportUtils::ShouldRenderBoundingBox(legacyDisplayStyle)) { + return; + } + if (!view.pluginObjectDisplay(MayaUsdProxyShapeBase::displayFilterName)) { return; } - // Note that this Draw() call is only necessary when we're drawing the - // bounding box, since that is not yet handled by Hydra and is instead done - // internally by the batch renderer on a per-shape basis. Otherwise, the - // pxrHdImagingShape is what will invoke Hydra to draw the shape. view.beginGL(); - UsdMayaGLBatchRenderer::GetInstance().Draw(request, view); + UsdMayaGLBatchRenderer::GetInstance().DrawBoundingBox(request, view); view.endGL(); } From 5fff18735223fcbd59e2be070b440741a1281d31 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 10:43:20 -0700 Subject: [PATCH 14/35] [pxrUsdMayaGL] make batch renderer Draw() only handle Hydra drawing With the pxrHdImagingShape draw override now the only one that calls Draw(), we don't need any bounding-box related drawing code in those methods anymore, since individual shape draw overrides are instead expected to call DrawBoundingBox() as necessary from their own draw callbacks. --- .../render/pxrUsdMayaGL/batchRenderer.cpp | 125 +++++++----------- .../render/pxrUsdMayaGL/batchRenderer.h | 4 +- 2 files changed, 48 insertions(+), 81 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp index c6d4118e76..8bd1bed36c 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp @@ -607,46 +607,26 @@ UsdMayaGLBatchRenderer::Draw(const MDrawRequest& request, M3dView& view) const PxrMayaHdUserData* hdUserData = static_cast(drawData.geometry()); - if (!hdUserData || (!hdUserData->drawShape && !hdUserData->boundingBox)) { - // Bail out as soon as possible if there's nothing to be drawn. + if (!hdUserData) { return; } + GfMatrix4d worldToViewMatrix; + _GetWorldToViewMatrix(view, &worldToViewMatrix); + MMatrix projectionMat; view.projectionMatrix(projectionMat); const GfMatrix4d projectionMatrix(projectionMat.matrix); - if (hdUserData->boundingBox) { - MMatrix modelViewMat; - view.modelViewMatrix(modelViewMat); - - // For the legacy viewport, apply a framebuffer gamma correction when - // drawing bounding boxes, just like we do when drawing geometry via - // Hydra. - glEnable(GL_FRAMEBUFFER_SRGB_EXT); - - px_vp20Utils::RenderBoundingBox(*(hdUserData->boundingBox), - *(hdUserData->wireframeColor), - modelViewMat, - projectionMat); - - glDisable(GL_FRAMEBUFFER_SRGB_EXT); - } - - if (hdUserData->drawShape) { - GfMatrix4d worldToViewMatrix; - _GetWorldToViewMatrix(view, &worldToViewMatrix); + GfVec4d viewport; + _GetViewport(view, &viewport); - GfVec4d viewport; - _GetViewport(view, &viewport); - - _RenderBatches( - /* vp2Context */ nullptr, - &view, - worldToViewMatrix, - projectionMatrix, - viewport); - } + _RenderBatches( + /* vp2Context */ nullptr, + &view, + worldToViewMatrix, + projectionMatrix, + viewport); // Clean up the user data. delete hdUserData; @@ -668,8 +648,7 @@ UsdMayaGLBatchRenderer::Draw( const PxrMayaHdUserData* hdUserData = dynamic_cast(userData); - if (!hdUserData || (!hdUserData->drawShape && !hdUserData->boundingBox)) { - // Bail out as soon as possible if there's nothing to be drawn. + if (!hdUserData) { return; } @@ -679,59 +658,47 @@ UsdMayaGLBatchRenderer::Draw( return; } + // Check whether this draw call is for a selection pass. If it is, we do + // *not* actually perform any drawing, but instead just mark a selection as + // pending so we know to re-compute selection when the next pick attempt is + // made. + // Note that Draw() calls for contexts with the "selectionPass" semantic + // are only made from draw overrides that do *not* implement user selection + // (i.e. those that do not override, or return false from, + // wantUserSelection()). The draw override for pxrHdImagingShape will + // likely be the only one of these where that is the case. + const MHWRender::MPassContext& passContext = context.getPassContext(); + const MStringArray& passSemantics = passContext.passSemantics(); + + for (unsigned int i = 0u; i < passSemantics.length(); ++i) { + if (passSemantics[i] == MHWRender::MPassContext::kSelectionPassSemantic) { + _UpdateIsSelectionPending(true); + return; + } + } + + GfMatrix4d worldToViewMatrix; + _GetWorldToViewMatrix(context, &worldToViewMatrix); + MStatus status; const MMatrix projectionMat = context.getMatrix(MHWRender::MFrameContext::kProjectionMtx, &status); const GfMatrix4d projectionMatrix(projectionMat.matrix); - if (hdUserData->boundingBox) { - const MMatrix worldViewMat = - context.getMatrix(MHWRender::MFrameContext::kWorldViewMtx, &status); - - px_vp20Utils::RenderBoundingBox(*(hdUserData->boundingBox), - *(hdUserData->wireframeColor), - worldViewMat, - projectionMat); - } + GfVec4d viewport; + _GetViewport(context, &viewport); - if (hdUserData->drawShape) { - // Check whether this draw call is for a selection pass. If it is, we - // do *not* actually perform any drawing, but instead just mark a - // selection as pending so we know to re-compute selection when the - // next pick attempt is made. - // Note that Draw() calls for contexts with the "selectionPass" - // semantic are only made from draw overrides that do *not* implement - // user selection (i.e. those that do not override, or return false - // from, wantUserSelection()). The draw override for pxrHdImagingShape - // will likely be the only one of these where that is the case. - const MHWRender::MPassContext& passContext = context.getPassContext(); - const MStringArray& passSemantics = passContext.passSemantics(); - - for (unsigned int i = 0u; i < passSemantics.length(); ++i) { - if (passSemantics[i] == MHWRender::MPassContext::kSelectionPassSemantic) { - _UpdateIsSelectionPending(true); - return; - } - } + M3dView view; + const bool hasView = + px_vp20Utils::GetViewFromDrawContext(context, view); - GfMatrix4d worldToViewMatrix; - _GetWorldToViewMatrix(context, &worldToViewMatrix); - - GfVec4d viewport; - _GetViewport(context, &viewport); - - M3dView view; - const bool hasView = - px_vp20Utils::GetViewFromDrawContext(context, view); - - _RenderBatches( - &context, - hasView ? &view : nullptr, - worldToViewMatrix, - projectionMatrix, - viewport); - } + _RenderBatches( + &context, + hasView ? &view : nullptr, + worldToViewMatrix, + projectionMatrix, + viewport); } void diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h index 5b0595fdd5..77ca9503bb 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h @@ -180,11 +180,11 @@ class UsdMayaGLBatchRenderer const MDagPath& dagPath, PxrMayaHdPrimFilter& primFilter); - /// Render batch or bounding box in the legacy viewport based on \p request + /// Render batch in the legacy viewport based on \p request MAYAUSD_CORE_PUBLIC void Draw(const MDrawRequest& request, M3dView& view); - /// Render batch or bounding box in Viewport 2.0 based on \p userData + /// Render batch in Viewport 2.0 based on \p userData MAYAUSD_CORE_PUBLIC void Draw( const MHWRender::MDrawContext& context, From 7aa7034249e1037341929652f4b4593ba0f60864 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 10:47:52 -0700 Subject: [PATCH 15/35] [pxrUsdMayaGL] remove now unused drawShape field on PxrMayaHdUserData --- .../render/pxrUsdMayaGL/hdImagingShapeDrawOverride.cpp | 2 -- lib/mayaUsd/render/pxrUsdMayaGL/hdImagingShapeUI.cpp | 1 - lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp | 8 -------- lib/mayaUsd/render/pxrUsdMayaGL/userData.cpp | 6 +----- lib/mayaUsd/render/pxrUsdMayaGL/userData.h | 1 - 5 files changed, 1 insertion(+), 17 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/hdImagingShapeDrawOverride.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/hdImagingShapeDrawOverride.cpp index 657d3fe140..2885d38c45 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/hdImagingShapeDrawOverride.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/hdImagingShapeDrawOverride.cpp @@ -193,8 +193,6 @@ PxrMayaHdImagingShapeDrawOverride::prepareForDraw( newData = new PxrMayaHdUserData(); } - newData->drawShape = true; - return newData; } diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/hdImagingShapeUI.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/hdImagingShapeUI.cpp index 0dad3aa007..81b85f8b62 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/hdImagingShapeUI.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/hdImagingShapeUI.cpp @@ -116,7 +116,6 @@ PxrMayaHdImagingShapeUI::getDrawRequests( // renderer deletes the MUserData object at the end of a legacy viewport // Draw() call. PxrMayaHdUserData* userData = new PxrMayaHdUserData(); - userData->drawShape = true; MDrawData drawData; getDrawData(userData, drawData); diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index ef33c5681c..83cc27bcaf 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -203,14 +203,6 @@ PxrMayaHdShapeAdapter::GetMayaUserData( newData = new PxrMayaHdUserData(); } - // Internally, the shape adapter keeps track of whether its shape is being - // drawn for managing visibility, but otherwise most Hydra-imaged shapes - // should not be drawing themselves. The pxrHdImagingShape will take care - // of batching up the drawing of all of the shapes, so we specify in the - // Maya user data that the shape should *not* draw by default. The - // pxrHdImagingShape bypasses this and sets drawShape to true. - newData->drawShape = false; - if (boundingBox) { newData->boundingBox.reset(new MBoundingBox(*boundingBox)); newData->wireframeColor.reset(new GfVec4f(_renderParams.wireframeColor)); diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/userData.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/userData.cpp index 740410d767..fd63f76e44 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/userData.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/userData.cpp @@ -24,12 +24,8 @@ PXR_NAMESPACE_OPEN_SCOPE /// Note that we set deleteAfterUse=false when calling the MUserData /// constructor. This ensures that the draw data survives across multiple draw /// passes in Viewport 2.0 (e.g. a shadow pass and a color pass). -/// -/// drawShape is initialized to false, since we expect that the -/// pxrHdImagingShape will be the only one to set it to true. PxrMayaHdUserData::PxrMayaHdUserData() : - MUserData(/* deleteAfterUse = */ false), - drawShape(false) + MUserData(/* deleteAfterUse = */ false) { } diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/userData.h b/lib/mayaUsd/render/pxrUsdMayaGL/userData.h index d2b05f42cb..db20d58d05 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/userData.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/userData.h @@ -41,7 +41,6 @@ class PxrMayaHdUserData : public MUserData { public: - bool drawShape; std::unique_ptr boundingBox; std::unique_ptr wireframeColor; From 4189220d43800b364b1a4e6e56524eeafdda888d Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 11:14:49 -0700 Subject: [PATCH 16/35] [pxrUsdMayaGL] always store the wireframe color in the render params Since we may not get another Sync() callback if the viewport display style is changed, we need to make sure that the wireframe color is always available from the render params. This may lead to slightly different shape adapter bucketing behavior, since the render params for shapes will pretty much always have a non-zero wireframe color now, but it shouldn't practically impact performance significantly. This also modifies the _GetWireframeColor() function to handle the MColor to GfVec4f conversion so that clients don't have to, and so that they can pass a pointer to the render params' wireframeColor directly. --- .../render/pxrUsdMayaGL/shapeAdapter.cpp | 41 ++++++++++--------- .../render/pxrUsdMayaGL/shapeAdapter.h | 28 ++++++++----- .../pxrUsdMayaGL/usdProxyShapeAdapter.cpp | 12 +----- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index 83cc27bcaf..8a1586ee7b 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -348,40 +348,43 @@ PxrMayaHdShapeAdapter::_GetRprimCollectionName() const /* static */ bool PxrMayaHdShapeAdapter::_GetWireframeColor( - const unsigned int displayStyle, - const MHWRender::DisplayStatus displayStatus, + MHWRender::DisplayStatus displayStatus, const MDagPath& shapeDagPath, - MColor* mayaWireColor) + GfVec4f* wireframeColor) { bool useWireframeColor = false; + MColor mayaWireframeColor; + // Dormant objects may be included in a soft selection. if (displayStatus == MHWRender::kDormant) { auto& batchRenderer = UsdMayaGLBatchRenderer::GetInstance(); if (batchRenderer.GetObjectSoftSelectEnabled()) { const UsdMayaGLSoftSelectHelper& softSelectHelper = UsdMayaGLBatchRenderer::GetInstance().GetSoftSelectHelper(); - useWireframeColor = softSelectHelper.GetFalloffColor(shapeDagPath, - mayaWireColor); + useWireframeColor = + softSelectHelper.GetFalloffColor( + shapeDagPath, + &mayaWireframeColor); } } - // If the object isn't included in a soft selection, just ask Maya for the - // wireframe color. - if (!useWireframeColor && mayaWireColor != nullptr) { - *mayaWireColor = - MHWRender::MGeometryUtilities::wireframeColor(shapeDagPath); - } - - constexpr unsigned int wireframeDisplayStyles = ( - MHWRender::MFrameContext::DisplayStyle::kWireFrame | - MHWRender::MFrameContext::DisplayStyle::kBoundingBox); - - const bool wireframeStyle = (displayStyle & wireframeDisplayStyles); + if (wireframeColor != nullptr) { + // The caller wants a color returned. If the object isn't included in a + // soft selection, just ask Maya for the wireframe color. + if (!useWireframeColor) { + mayaWireframeColor = + MHWRender::MGeometryUtilities::wireframeColor(shapeDagPath); + } - const bool isActive = _IsActiveDisplayStatus(displayStatus); + *wireframeColor = GfVec4f( + mayaWireframeColor.r, + mayaWireframeColor.g, + mayaWireframeColor.b, + mayaWireframeColor.a); + } - if (wireframeStyle || isActive) { + if (_IsActiveDisplayStatus(displayStatus)) { useWireframeColor = true; } diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index 9d036f5b49..e8d6d11989 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -43,7 +44,6 @@ #include #undef Always // Defined in /usr/lib/X11/X.h (eventually included by M3dView.h) - breaks pxr/usd/lib/usdUtils/registeredVariantSet.h #include -#include #include #include #include @@ -244,18 +244,26 @@ class PxrMayaHdShapeAdapter /// access the soft selection info. /// /// Returns true if the wireframe color should be used, that is if the - /// object and/or its component(s) are involved in a selection, or if - /// the displayStyle indicates that a wireframe style is being drawn - /// (either kWireFrame or kBoundingBox). Otherwise returns false. + /// object and/or its component(s) are involved in a selection. + /// Otherwise returns false. /// - /// The wireframe color will always be returned in \p mayaWireColor (if - /// it is not nullptr) in case the caller wants to use other criteria - /// for determining whether to use it. + /// Note that we do not factor in the viewport's displayStyle, which + /// may indicate that a wireframe style is being drawn (either + /// kWireFrame or kBoundingBox). The displayStyle can be changed + /// without triggering a re-Sync(), so we want to make sure that shape + /// adapters don't inadvertently "bake in" whether to use the wireframe + /// into their render params based on it. We only want to know whether + /// we need to use the wireframe for a reason *other* than the + /// displayStyle. + /// + /// The wireframe color will always be returned in \p wireframeColor + /// (if it is not nullptr) in case the caller wants to use other + /// criteria for determining whether to use it (e.g. for bounding + /// boxes). static bool _GetWireframeColor( - const unsigned int displayStyle, - const MHWRender::DisplayStatus displayStatus, + MHWRender::DisplayStatus displayStatus, const MDagPath& shapeDagPath, - MColor* mayaWireColor); + GfVec4f* wireframeColor); /// Helper for computing the viewport visibility of the shape. /// diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp index 8fc0ed393f..3b7972ab13 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -34,7 +33,6 @@ #include #include -#include #include #include #include @@ -219,19 +217,11 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( // Will only react if time actually changes. _delegate->SetTime(timeCode); - MColor mayaWireframeColor; _renderParams.useWireframe = _GetWireframeColor( - displayStyle, displayStatus, _shapeDagPath, - &mayaWireframeColor); - if (_renderParams.useWireframe) { - _renderParams.wireframeColor = GfVec4f(mayaWireframeColor.r, - mayaWireframeColor.g, - mayaWireframeColor.b, - mayaWireframeColor.a); - } + &_renderParams.wireframeColor); // XXX: This is not technically correct. Since the display style can vary // per viewport, this decision of whether or not to enable lighting should From 4fdc11cab7bd28c8cac870d6d53ca81efeaf4cd0 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 11:46:08 -0700 Subject: [PATCH 17/35] [pxrUsdMayaGL] remove virtual dispatch for shape adapter methods and/or define them inline --- .../render/pxrUsdMayaGL/shapeAdapter.cpp | 36 ---------------- .../render/pxrUsdMayaGL/shapeAdapter.h | 42 +++++++++++-------- 2 files changed, 25 insertions(+), 53 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index 8a1586ee7b..f84e408fcb 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -287,35 +287,6 @@ PxrMayaHdShapeAdapter::GetReprSelectorForDisplayStyle( return reprSelector; } -/* virtual */ -const HdRprimCollection& -PxrMayaHdShapeAdapter::GetRprimCollection() const -{ - return _rprimCollection; -} - -/* virtual */ -const TfTokenVector& -PxrMayaHdShapeAdapter::GetRenderTags() const -{ - return _renderTags; -} - - -/* virtual */ -const GfMatrix4d& -PxrMayaHdShapeAdapter::GetRootXform() const -{ - return _rootXform; -} - -/* virtual */ -void -PxrMayaHdShapeAdapter::SetRootXform(const GfMatrix4d& transform) -{ - _rootXform = transform; -} - /* virtual */ const SdfPath& PxrMayaHdShapeAdapter::GetDelegateID() const @@ -323,13 +294,6 @@ PxrMayaHdShapeAdapter::GetDelegateID() const return SdfPath::EmptyPath(); } -/* virtual */ -const MDagPath& -PxrMayaHdShapeAdapter::GetDagPath() const -{ - return _shapeDagPath; -} - /* virtual */ TfToken PxrMayaHdShapeAdapter::_GetRprimCollectionName() const diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index e8d6d11989..8637ee9a55 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -169,30 +169,38 @@ class PxrMayaHdShapeAdapter return _renderParams; } - MAYAUSD_CORE_PUBLIC - virtual const HdRprimCollection& GetRprimCollection() const; - - /// Retrieves the render tags for this shape. I.e. which - /// prim purposes should be drawn (such as geomerty, proxy, guides - /// and/or render). - /// This function just returns the _renderTags attribute and it - /// is expected each subclass update the attribute in _Sync() or - /// overrides this function if it needs special processing. - MAYAUSD_CORE_PUBLIC - virtual const TfTokenVector& GetRenderTags() const; + const HdRprimCollection& GetRprimCollection() const { + return _rprimCollection; + } + /// Retrieves the render tags for this shape (i.e. which prim purposes + /// should be drawn, such as geometry, proxy, guide and/or render). + /// + /// This function just returns the _renderTags attribute and it is + /// expected that subclasses update the attribute in _Sync(). + const TfTokenVector& GetRenderTags() const { + return _renderTags; + } - MAYAUSD_CORE_PUBLIC - virtual const GfMatrix4d& GetRootXform() const; + const GfMatrix4d& GetRootXform() const { + return _rootXform; + } - MAYAUSD_CORE_PUBLIC - virtual void SetRootXform(const GfMatrix4d& transform); + /// Sets the root transform for the shape adapter. + /// + /// This function is virtual in case the shape adapter needs to update + /// other state in response to a change in the root transform (e.g. + /// updating an HdSceneDelegate). + virtual void SetRootXform(const GfMatrix4d& transform) { + _rootXform = transform; + } MAYAUSD_CORE_PUBLIC virtual const SdfPath& GetDelegateID() const; - MAYAUSD_CORE_PUBLIC - virtual const MDagPath& GetDagPath() const; + const MDagPath& GetDagPath() const { + return _shapeDagPath; + } /// Get whether this shape adapter is for use with Viewport 2.0. /// From 78465797e444f364d5899d5241e7ee225dae3aab Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 14:11:55 -0700 Subject: [PATCH 18/35] [pxrUsdMayaGL] remove virtual dispatch of shape adapter Sync() Derived classes can control their own behaviors in the protected _Sync(). --- lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp | 2 -- lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index f84e408fcb..7314b7c665 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -89,7 +89,6 @@ _IsActiveDisplayStatus(MHWRender::DisplayStatus displayStatus) (displayStatus == MHWRender::DisplayStatus::kLead); } -/* virtual */ bool PxrMayaHdShapeAdapter::Sync( const MDagPath& shapeDagPath, @@ -132,7 +131,6 @@ PxrMayaHdShapeAdapter::Sync( return success; } -/* virtual */ bool PxrMayaHdShapeAdapter::Sync( const MDagPath& shapeDagPath, diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index 8637ee9a55..d92e1c1b62 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -66,7 +66,7 @@ class PxrMayaHdShapeAdapter /// Update the shape adapter's state from the shape with the given /// \p shapeDagPath and the legacy viewport display state. MAYAUSD_CORE_PUBLIC - virtual bool Sync( + bool Sync( const MDagPath& shapeDagPath, const M3dView::DisplayStyle legacyDisplayStyle, const M3dView::DisplayStatus legacyDisplayStatus); @@ -74,7 +74,7 @@ class PxrMayaHdShapeAdapter /// Update the shape adapter's state from the shape with the given /// \p shapeDagPath and the Viewport 2.0 display state. MAYAUSD_CORE_PUBLIC - virtual bool Sync( + bool Sync( const MDagPath& shapeDagPath, const unsigned int displayStyle, const MHWRender::DisplayStatus displayStatus); From d62fb649e150ccd5d5ce56d2e0e9d9bf8a805d91 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 13:52:06 -0700 Subject: [PATCH 19/35] [pxrUsdMayaGL] make shape adapter base class responsible for identifiers This moves all computation of a unique identifier for the shape into the shape adapter base class and removes it from derived classes. Instead of a fixed string and a hash of the Maya object, we instead query Maya for the node's UUID and use that directly as the shape's "identifier", which we also use both as the name of its rprim collection, and to construct the delegate ID. We use the node's UUID since MPxDrawOverrides may be constructed and destructed over the course of a node's lifetime (e.g. by doing 'ogs -reset'). Since the draw override owns the shape adapter, we therefore need an identifier tied to the node's lifetime rather than to the shape adapter's lifetime. With the delegate ID now stored in the base class, its accessor no longer needs to be virtual, and also gets defined inline. --- .../pxrUsdMayaGL/instancerShapeAdapter.cpp | 72 +++--------------- .../pxrUsdMayaGL/instancerShapeAdapter.h | 3 - .../render/pxrUsdMayaGL/shapeAdapter.cpp | 63 +++++++++++----- .../render/pxrUsdMayaGL/shapeAdapter.h | 21 ++++-- .../pxrUsdMayaGL/usdProxyShapeAdapter.cpp | 74 +++---------------- .../pxrUsdMayaGL/usdProxyShapeAdapter.h | 3 - 6 files changed, 78 insertions(+), 158 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp index 4bd4d3dcb3..5fd2736a10 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp @@ -17,8 +17,6 @@ #include -#include - #include #include #include @@ -28,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -105,17 +102,6 @@ UsdMayaGL_InstancerShapeAdapter::SetRootXform(const GfMatrix4d& transform) } } -/* virtual */ -const SdfPath& -UsdMayaGL_InstancerShapeAdapter::GetDelegateID() const -{ - if (_delegate) { - return _delegate->GetDelegateID(); - } - - return SdfPath::EmptyPath(); -} - static void _ClearInstancer(const UsdGeomPointInstancer& usdInstancer) { @@ -241,7 +227,7 @@ UsdMayaGL_InstancerShapeAdapter::_Sync( if (!(shapeDagPath == _shapeDagPath) || !_delegate || renderIndex != &_delegate->GetRenderIndex()) { - _shapeDagPath = shapeDagPath; + _SetDagPath(shapeDagPath); if (!_Init(renderIndex)) { return false; @@ -311,61 +297,23 @@ UsdMayaGL_InstancerShapeAdapter::_Sync( bool UsdMayaGL_InstancerShapeAdapter::_Init(HdRenderIndex* renderIndex) { - if (!TF_VERIFY(renderIndex, - "Cannot initialize shape adapter with invalid HdRenderIndex")) { + if (!TF_VERIFY( + renderIndex, + "Cannot initialize shape adapter with invalid HdRenderIndex")) { return false; } - const SdfPath delegatePrefix = - UsdMayaGLBatchRenderer::GetInstance().GetDelegatePrefix(_isViewport2); - - // Create a simple "name" for this shape adapter to insert into the batch - // renderer's SdfPath hierarchy. - // - // XXX: For as long as we're using the MAYA_VP2_USE_VP1_SELECTION - // environment variable, we need to be able to pass responsibility back and - // forth between the MPxDrawOverride's shape adapter for drawing and the - // MPxSurfaceShapeUI's shape adapter for selection. This requires both - // shape adapters to have the same "name", which forces us to build it - // from data on the shape that will be common to both classes, as we do - // below. When we remove MAYA_VP2_USE_VP1_SELECTION and can trust that a - // single shape adapter handles both drawing and selection, we can do - // something even simpler instead like using the shape adapter's memory - // address as the "name". - size_t shapeHash(MObjectHandle(_shapeDagPath.transform()).hashCode()); - boost::hash_combine(shapeHash, _instancerStage->GetDefaultPrim()); - - // We prepend the Maya type name to the beginning of the delegate name to - // ensure that there are no name collisions between shape adapters of - // shapes with different Maya types. - const TfToken delegateName( - TfStringPrintf("%s_%zx", - _tokens->NativeInstancerType.GetText(), - shapeHash)); - - const SdfPath delegateId = delegatePrefix.AppendChild(delegateName); - - if (_delegate && - delegateId == GetDelegateID() && - renderIndex == &_delegate->GetRenderIndex()) { - // The delegate's current ID matches the delegate ID we computed and - // the render index matches, so it must be up to date already. - return true; - } - - const TfToken collectionName = _GetRprimCollectionName(); - TF_DEBUG(PXRUSDMAYAGL_SHAPE_ADAPTER_LIFECYCLE).Msg( "Initializing UsdMayaGL_InstancerShapeAdapter: %p\n" - " shape DAG path : %s\n" - " collection name: %s\n" - " delegateId : %s\n", + " shape DAG path : %s\n" + " shape identifier: %s\n" + " delegateId : %s\n", this, _shapeDagPath.fullPathName().asChar(), - collectionName.GetText(), - delegateId.GetText()); + _shapeIdentifier.GetText(), + _delegateId.GetText()); - _delegate.reset(new UsdImagingDelegate(renderIndex, delegateId)); + _delegate.reset(new UsdImagingDelegate(renderIndex, _delegateId)); if (!TF_VERIFY(_delegate, "Failed to create shape adapter delegate for shape %s", _shapeDagPath.fullPathName().asChar())) { diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h index 84669075d0..0715fcc8e9 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h @@ -82,9 +82,6 @@ class UsdMayaGL_InstancerShapeAdapter : public PxrMayaHdShapeAdapter MAYAUSD_CORE_PUBLIC void SetRootXform(const GfMatrix4d& transform) override; - MAYAUSD_CORE_PUBLIC - const SdfPath& GetDelegateID() const override; - MAYAUSD_CORE_PUBLIC ~UsdMayaGL_InstancerShapeAdapter() override; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index 7314b7c665..d41869020a 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -15,13 +15,15 @@ // #include "shapeAdapter.h" +#include + #include #include #include #include #include #include -#include +#include #include #include #include @@ -285,26 +287,51 @@ PxrMayaHdShapeAdapter::GetReprSelectorForDisplayStyle( return reprSelector; } -/* virtual */ -const SdfPath& -PxrMayaHdShapeAdapter::GetDelegateID() const +MStatus +PxrMayaHdShapeAdapter::_SetDagPath(const MDagPath& dagPath) { - return SdfPath::EmptyPath(); -} + if (_shapeDagPath == dagPath) { + return MS::kSuccess; + } + + _shapeDagPath = dagPath; + + _shapeIdentifier = TfToken(); + _delegateId = SdfPath(); -/* virtual */ -TfToken -PxrMayaHdShapeAdapter::_GetRprimCollectionName() const -{ MStatus status; - const MObject shapeObj = _shapeDagPath.node(&status); - CHECK_MSTATUS_AND_RETURN(status, TfToken()); - const MFnDependencyNode depNodeFn(shapeObj, &status); - CHECK_MSTATUS_AND_RETURN(status, TfToken()); - const MUuid shapeUuid = depNodeFn.uuid(&status); - CHECK_MSTATUS_AND_RETURN(status, TfToken()); - - return TfToken(TfMakeValidIdentifier(shapeUuid.asString().asChar())); + const bool dagPathIsValid = _shapeDagPath.isValid(&status); + if (status != MS::kSuccess || !dagPathIsValid) { + return status; + } + + const MFnDagNode dagNodeFn(_shapeDagPath, &status); + CHECK_MSTATUS_AND_RETURN_IT(status); + + // We use the shape's UUID as a unique identifier for this shape adapter in + // the batch renderer's SdfPath hierarchy. Since MPxDrawOverrides may be + // constructed and destructed over the course of a node's lifetime (e.g. by + // doing 'ogs -reset'), we need an identifier tied to the node's lifetime + // rather than to the shape adapter's lifetime. + const MUuid shapeUuid = dagNodeFn.uuid(&status); + CHECK_MSTATUS_AND_RETURN_IT(status); + + const std::string uuidString( + shapeUuid.asString().asChar(), + shapeUuid.asString().length()); + + _shapeIdentifier = TfToken(TfMakeValidIdentifier(uuidString)); + + const UsdMayaGLBatchRenderer& batchRenderer = + UsdMayaGLBatchRenderer::GetInstance(); + HdRenderIndex* renderIndex = batchRenderer.GetRenderIndex(); + + const SdfPath delegatePrefix = + batchRenderer.GetDelegatePrefix(_isViewport2); + + _delegateId = delegatePrefix.AppendChild(_shapeIdentifier); + + return status; } /* static */ diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index d92e1c1b62..7e5ec99900 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -195,8 +195,9 @@ class PxrMayaHdShapeAdapter _rootXform = transform; } - MAYAUSD_CORE_PUBLIC - virtual const SdfPath& GetDelegateID() const; + const SdfPath& GetDelegateID() const { + return _delegateId; + } const MDagPath& GetDagPath() const { return _shapeDagPath; @@ -230,19 +231,21 @@ class PxrMayaHdShapeAdapter const unsigned int displayStyle, const MHWRender::DisplayStatus displayStatus) = 0; - /// Helper for computing the name of the shape's HdRprimCollection. + /// Sets the shape adapter's DAG path. /// - /// The batch renderer currently creates a render task for each shape's + /// This re-computes the "identifier" for the shape, which is used to + /// compute the name of the shape's HdRprimCollection. The batch + /// renderer currently creates a render task for each shape's /// HdRprimCollection, and those render tasks are identified by an /// SdfPath constructed using the collection's name. We therefore need /// the collection to have a name that is unique to the shape it /// represents and also sanitized for use in SdfPaths. /// - /// Returns a TfToken collection name that is unique to the shape and - /// is a valid SdfPath identifier, or an empty TfToken is there is an - /// error. + /// The identifier will be a TfToken that is unique to the shape and is + /// a valid SdfPath identifier, or an empty TfToken if there is an + /// error, which can be detected from the returned MStatus. MAYAUSD_CORE_PUBLIC - virtual TfToken _GetRprimCollectionName() const; + MStatus _SetDagPath(const MDagPath& dagPath); /// Helper for getting the wireframe color of the shape. /// @@ -295,6 +298,8 @@ class PxrMayaHdShapeAdapter virtual ~PxrMayaHdShapeAdapter(); MDagPath _shapeDagPath; + TfToken _shapeIdentifier; + SdfPath _delegateId; PxrMayaHdRenderParams _renderParams; bool _drawShape; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp index 3b7972ab13..ce8971b9f8 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp @@ -17,15 +17,11 @@ #include -#include - #include #include -#include #include #include #include -#include #include #include #include @@ -103,17 +99,6 @@ PxrMayaHdUsdProxyShapeAdapter::SetRootXform(const GfMatrix4d& transform) } } -/* virtual */ -const SdfPath& -PxrMayaHdUsdProxyShapeAdapter::GetDelegateID() const -{ - if (_delegate) { - return _delegate->GetDelegateID(); - } - - return SdfPath::EmptyPath(); -} - /* virtual */ bool PxrMayaHdUsdProxyShapeAdapter::_Sync( @@ -166,7 +151,7 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( excludedPrimPaths != _excludedPrimPaths || !_delegate || renderIndex != &_delegate->GetRenderIndex()) { - _shapeDagPath = shapeDagPath; + _SetDagPath(shapeDagPath); _rootPrim = usdPrim; _excludedPrimPaths = excludedPrimPaths; @@ -279,62 +264,23 @@ PxrMayaHdUsdProxyShapeAdapter::_Init(HdRenderIndex* renderIndex) MProfiler::kColorE_L2, "USD Proxy Shape Initializing Shape Adapter"); - if (!TF_VERIFY(renderIndex, - "Cannot initialize shape adapter with invalid HdRenderIndex")) { + if (!TF_VERIFY( + renderIndex, + "Cannot initialize shape adapter with invalid HdRenderIndex")) { return false; } - const SdfPath delegatePrefix = - UsdMayaGLBatchRenderer::GetInstance().GetDelegatePrefix(_isViewport2); - - // Create a simple "name" for this shape adapter to insert into the batch - // renderer's SdfPath hierarchy. - // - // XXX: For as long as we're using the MAYA_VP2_USE_VP1_SELECTION - // environment variable, we need to be able to pass responsibility back and - // forth between the MPxDrawOverride's shape adapter for drawing and the - // MPxSurfaceShapeUI's shape adapter for selection. This requires both - // shape adapters to have the same "name", which forces us to build it - // from data on the shape that will be common to both classes, as we do - // below. When we remove MAYA_VP2_USE_VP1_SELECTION and can trust that a - // single shape adapter handles both drawing and selection, we can do - // something even simpler instead like using the shape adapter's memory - // address as the "name". - size_t shapeHash(MObjectHandle(_shapeDagPath.transform()).hashCode()); - boost::hash_combine(shapeHash, _rootPrim); - boost::hash_combine(shapeHash, _excludedPrimPaths); - - // We prepend the Maya type name to the beginning of the delegate name to - // ensure that there are no name collisions between shape adapters of - // shapes with different Maya types. - const TfToken delegateName( - TfStringPrintf("%s_%zx", - MayaUsdProxyShapeBaseTokens->MayaTypeName.GetText(), - shapeHash)); - - const SdfPath delegateId = delegatePrefix.AppendChild(delegateName); - - if (_delegate && - delegateId == GetDelegateID() && - renderIndex == &_delegate->GetRenderIndex()) { - // The delegate's current ID matches the delegate ID we computed and - // the render index matches, so it must be up to date already. - return true; - } - - const TfToken collectionName = _GetRprimCollectionName(); - TF_DEBUG(PXRUSDMAYAGL_SHAPE_ADAPTER_LIFECYCLE).Msg( "Initializing PxrMayaHdUsdProxyShapeAdapter: %p\n" - " shape DAG path : %s\n" - " collection name: %s\n" - " delegateId : %s\n", + " shape DAG path : %s\n" + " shape identifier: %s\n" + " delegateId : %s\n", this, _shapeDagPath.fullPathName().asChar(), - collectionName.GetText(), - delegateId.GetText()); + _shapeIdentifier.GetText(), + _delegateId.GetText()); - _delegate.reset(new UsdImagingDelegate(renderIndex, delegateId)); + _delegate.reset(new UsdImagingDelegate(renderIndex, _delegateId)); if (!TF_VERIFY(_delegate, "Failed to create shape adapter delegate for shape %s", _shapeDagPath.fullPathName().asChar())) { diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h index 70cb70f643..433d4cf288 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h @@ -87,9 +87,6 @@ class PxrMayaHdUsdProxyShapeAdapter : public PxrMayaHdShapeAdapter MAYAUSD_CORE_PUBLIC void SetRootXform(const GfMatrix4d& transform) override; - MAYAUSD_CORE_PUBLIC - const SdfPath& GetDelegateID() const override; - protected: /// Update the shape adapter's state from the shape with the given From d3bbd4643c59461e84e87a4d21d19453808a5943 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Mon, 8 Jun 2020 12:09:49 -0700 Subject: [PATCH 20/35] [pxrUsdMayaGL] update doc strings on shape adapter _Init() functions --- lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h | 7 ++++--- lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h index 0715fcc8e9..c3093a226a 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h @@ -123,9 +123,10 @@ class UsdMayaGL_InstancerShapeAdapter : public PxrMayaHdShapeAdapter /// Initialize the shape adapter using the given \p renderIndex. /// /// This method is called automatically during Sync() when the shape - /// adapter's "identity" changes. This happens when the delegateId or - /// the rprim collection name computed from the shape adapter's shape - /// is different than what is currently stored in the shape adapter. + /// adapter's "identity" changes. This can happen when the shape + /// managed by this adapter is changed by setting a new DAG path, or + /// otherwise when there is some other fundamental change to the shape + /// or to the delegate or render index. /// The shape adapter will then query the batch renderer for its render /// index and use that to re-create its delegate and re-add its rprim /// collection, if necessary. diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h index 433d4cf288..0831d1ee94 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h @@ -118,9 +118,10 @@ class PxrMayaHdUsdProxyShapeAdapter : public PxrMayaHdShapeAdapter /// Initialize the shape adapter using the given \p renderIndex. /// /// This method is called automatically during Sync() when the shape - /// adapter's "identity" changes. This happens when the delegateId or - /// the rprim collection name computed from the shape adapter's shape - /// is different than what is currently stored in the shape adapter. + /// adapter's "identity" changes. This can happen when the shape + /// managed by this adapter is changed by setting a new DAG path, or + /// otherwise when there is some other fundamental change to the shape + /// or to the delegate or render index. /// The shape adapter will then query the batch renderer for its render /// index and use that to re-create its delegate and re-add its rprim /// collection, if necessary. From aa65162952e2eef2cef237f2b1c0fa0124f3ef29 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 14:03:30 -0700 Subject: [PATCH 21/35] [pxrUsdMayaGL] make shape adapter's _shapeDagPath a private field Now that a bunch of other shape adapter data is recomputed whenever _SetDagPath() is called, we want to make sure that _shapeDagPath is not changed any other way, so this change makes it private instead of protected. Existing usage of the field now uses the public accessor instead. --- .../render/pxrUsdMayaGL/instancerShapeAdapter.cpp | 10 +++++----- .../render/pxrUsdMayaGL/proxyDrawOverride.cpp | 4 ++-- lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h | 5 ++++- .../render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp | 12 ++++++------ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp index 5fd2736a10..a1e9b9ac86 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp @@ -72,7 +72,7 @@ bool UsdMayaGL_InstancerShapeAdapter::UpdateVisibility(const M3dView* view) { bool isVisible; - if (!_GetVisibility(_shapeDagPath, view, &isVisible)) { + if (!_GetVisibility(GetDagPath(), view, &isVisible)) { return false; } @@ -224,7 +224,7 @@ UsdMayaGL_InstancerShapeAdapter::_Sync( // require us to re-initialize the shape adapter. HdRenderIndex* renderIndex = UsdMayaGLBatchRenderer::GetInstance().GetRenderIndex(); - if (!(shapeDagPath == _shapeDagPath) || + if (!(shapeDagPath == GetDagPath()) || !_delegate || renderIndex != &_delegate->GetRenderIndex()) { _SetDagPath(shapeDagPath); @@ -237,7 +237,7 @@ UsdMayaGL_InstancerShapeAdapter::_Sync( // Reset _renderParams to the defaults. _renderParams = PxrMayaHdRenderParams(); - const MMatrix transform = _shapeDagPath.inclusiveMatrix(&status); + const MMatrix transform = GetDagPath().inclusiveMatrix(&status); if (status == MS::kSuccess) { _rootXform = GfMatrix4d(transform.matrix); _delegate->SetRootTransform(_rootXform); @@ -309,14 +309,14 @@ UsdMayaGL_InstancerShapeAdapter::_Init(HdRenderIndex* renderIndex) " shape identifier: %s\n" " delegateId : %s\n", this, - _shapeDagPath.fullPathName().asChar(), + GetDagPath().fullPathName().asChar(), _shapeIdentifier.GetText(), _delegateId.GetText()); _delegate.reset(new UsdImagingDelegate(renderIndex, _delegateId)); if (!TF_VERIFY(_delegate, "Failed to create shape adapter delegate for shape %s", - _shapeDagPath.fullPathName().asChar())) { + GetDagPath().fullPathName().asChar())) { return false; } diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp index 0897509c77..a52dc0f248 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/proxyDrawOverride.cpp @@ -254,7 +254,7 @@ UsdMayaProxyDrawOverride::userSelect( const unsigned int displayStyle = context.getDisplayStyle(); const MHWRender::DisplayStatus displayStatus = - MHWRender::MGeometryUtilities::displayStatus(_shapeAdapter._shapeDagPath); + MHWRender::MGeometryUtilities::displayStatus(_shapeAdapter.GetDagPath()); // At this point, we expect the shape to have already been drawn and our // shape adapter to have been added to the batch renderer, but just in @@ -263,7 +263,7 @@ UsdMayaProxyDrawOverride::userSelect( // must have already been done to have caused the shape to be drawn and // become eligible for selection. if (!_shapeAdapter.Sync( - _shapeAdapter._shapeDagPath, displayStyle, displayStatus)) { + _shapeAdapter.GetDagPath(), displayStyle, displayStatus)) { return false; } diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index 7e5ec99900..e0802561cf 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -297,7 +297,6 @@ class PxrMayaHdShapeAdapter MAYAUSD_CORE_PUBLIC virtual ~PxrMayaHdShapeAdapter(); - MDagPath _shapeDagPath; TfToken _shapeIdentifier; SdfPath _delegateId; @@ -310,6 +309,10 @@ class PxrMayaHdShapeAdapter GfMatrix4d _rootXform; const bool _isViewport2; + + private: + + MDagPath _shapeDagPath; }; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp index ce8971b9f8..66948f2757 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp @@ -69,7 +69,7 @@ PxrMayaHdUsdProxyShapeAdapter::UpdateVisibility(const M3dView* view) // USD proxy shapes are being filtered from this view, so don't bother // checking any other visibility state. isVisible = false; - } else if (!_GetVisibility(_shapeDagPath, view, &isVisible)) { + } else if (!_GetVisibility(GetDagPath(), view, &isVisible)) { return false; } @@ -146,7 +146,7 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( // require us to re-initialize the shape adapter. HdRenderIndex* renderIndex = UsdMayaGLBatchRenderer::GetInstance().GetRenderIndex(); - if (!(shapeDagPath == _shapeDagPath) || + if (!(shapeDagPath == GetDagPath()) || usdPrim != _rootPrim || excludedPrimPaths != _excludedPrimPaths || !_delegate || @@ -191,7 +191,7 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( #endif MStatus status; - const MMatrix transform = _shapeDagPath.inclusiveMatrix(&status); + const MMatrix transform = GetDagPath().inclusiveMatrix(&status); if (status == MS::kSuccess) { _rootXform = GfMatrix4d(transform.matrix); _delegate->SetRootTransform(_rootXform); @@ -205,7 +205,7 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( _renderParams.useWireframe = _GetWireframeColor( displayStatus, - _shapeDagPath, + GetDagPath(), &_renderParams.wireframeColor); // XXX: This is not technically correct. Since the display style can vary @@ -276,14 +276,14 @@ PxrMayaHdUsdProxyShapeAdapter::_Init(HdRenderIndex* renderIndex) " shape identifier: %s\n" " delegateId : %s\n", this, - _shapeDagPath.fullPathName().asChar(), + GetDagPath().fullPathName().asChar(), _shapeIdentifier.GetText(), _delegateId.GetText()); _delegate.reset(new UsdImagingDelegate(renderIndex, _delegateId)); if (!TF_VERIFY(_delegate, "Failed to create shape adapter delegate for shape %s", - _shapeDagPath.fullPathName().asChar())) { + GetDagPath().fullPathName().asChar())) { return false; } From 5f0d234bf8252288bd8d0fc022a8f1c942c020fc Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 15:10:06 -0700 Subject: [PATCH 22/35] [pxrUsdMayaGL] use renderTags token from HdTokens instead of private one in scene delegate --- .../render/pxrUsdMayaGL/sceneDelegate.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp index 6d4c9baecf..bdbf84e89f 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp @@ -62,7 +62,6 @@ TF_DEFINE_PRIVATE_TOKENS( _tokens, (selectionTask) - (renderTags) ); @@ -163,7 +162,7 @@ PxrMayaHdSceneDelegate::PxrMayaHdSceneDelegate( taskParams.camera = _cameraId; taskParams.viewport = _viewport; cache[HdTokens->params] = VtValue(taskParams); - cache[_tokens->renderTags] = VtValue(defaultShadowRenderTags); + cache[HdTokens->renderTags] = VtValue(defaultShadowRenderTags); } // Picking task. @@ -178,7 +177,7 @@ PxrMayaHdSceneDelegate::PxrMayaHdSceneDelegate( // on first use, but this ensures we don't need // to special case first time vs others for comparing // to current render tags - cache[_tokens->renderTags] = VtValue(TfTokenVector()); + cache[HdTokens->renderTags] = VtValue(TfTokenVector()); } } @@ -211,7 +210,7 @@ PxrMayaHdSceneDelegate::GetCameraParamValue( TfTokenVector PxrMayaHdSceneDelegate::GetTaskRenderTags(SdfPath const& taskId) { - VtValue value = Get(taskId, _tokens->renderTags); + VtValue value = Get(taskId, HdTokens->renderTags); return value.Get(); } @@ -441,10 +440,10 @@ PxrMayaHdSceneDelegate::GetPickingTasks( { // Update tasks render tags to match those specified in the parameter. const TfTokenVector ¤tRenderTags = - _GetValue(_pickingTaskId, _tokens->renderTags); + _GetValue(_pickingTaskId, HdTokens->renderTags); if (currentRenderTags != renderTags) { - _SetValue(_pickingTaskId, _tokens->renderTags, renderTags); + _SetValue(_pickingTaskId, HdTokens->renderTags, renderTags); GetRenderIndex().GetChangeTracker().MarkTaskDirty( _pickingTaskId, HdChangeTracker::DirtyRenderTags); @@ -532,16 +531,16 @@ PxrMayaHdSceneDelegate::GetRenderTasks( _ValueCache& cache = _valueCacheMap[renderTaskId]; cache[HdTokens->params] = VtValue(); cache[HdTokens->collection] = VtValue(primFilter.collection); - cache[_tokens->renderTags] = VtValue(primFilter.renderTags); + cache[HdTokens->renderTags] = VtValue(primFilter.renderTags); _renderTaskIdMap[key] = renderTaskId; } else { // Update task's render tags const TfTokenVector ¤tRenderTags = - _GetValue(renderTaskId, _tokens->renderTags); + _GetValue(renderTaskId, HdTokens->renderTags); if (currentRenderTags != primFilter.renderTags) { - _SetValue(renderTaskId, _tokens->renderTags, primFilter.renderTags); + _SetValue(renderTaskId, HdTokens->renderTags, primFilter.renderTags); GetRenderIndex().GetChangeTracker().MarkTaskDirty( renderTaskId, HdChangeTracker::DirtyRenderTags); From 2d0b160dd8ff3acb5162cabff9e963b2d0ba74c1 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 15:11:22 -0700 Subject: [PATCH 23/35] [pxrUsdMayaGL] move GetPickingTasks() after GetRenderTasks() This makes the ordering in the cpp file consistent with the declaration order in the header. --- .../render/pxrUsdMayaGL/sceneDelegate.cpp | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp index bdbf84e89f..3c64b1c28b 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp @@ -434,28 +434,6 @@ PxrMayaHdSceneDelegate::GetSetupTasks() return tasks; } -HdTaskSharedPtrVector -PxrMayaHdSceneDelegate::GetPickingTasks( - const TfTokenVector& renderTags) -{ - // Update tasks render tags to match those specified in the parameter. - const TfTokenVector ¤tRenderTags = - _GetValue(_pickingTaskId, HdTokens->renderTags); - - if (currentRenderTags != renderTags) { - _SetValue(_pickingTaskId, HdTokens->renderTags, renderTags); - GetRenderIndex().GetChangeTracker().MarkTaskDirty( - _pickingTaskId, - HdChangeTracker::DirtyRenderTags); - } - - HdTaskSharedPtrVector tasks; - - tasks.push_back(GetRenderIndex().GetTask(_pickingTaskId)); - - return tasks; -} - HdTaskSharedPtrVector PxrMayaHdSceneDelegate::GetRenderTasks( const size_t hash, @@ -642,6 +620,28 @@ PxrMayaHdSceneDelegate::GetRenderTasks( return taskList; } +HdTaskSharedPtrVector +PxrMayaHdSceneDelegate::GetPickingTasks( + const TfTokenVector& renderTags) +{ + // Update tasks render tags to match those specified in the parameter. + const TfTokenVector ¤tRenderTags = + _GetValue(_pickingTaskId, HdTokens->renderTags); + + if (currentRenderTags != renderTags) { + _SetValue(_pickingTaskId, HdTokens->renderTags, renderTags); + GetRenderIndex().GetChangeTracker().MarkTaskDirty( + _pickingTaskId, + HdChangeTracker::DirtyRenderTags); + } + + HdTaskSharedPtrVector tasks; + + tasks.push_back(GetRenderIndex().GetTask(_pickingTaskId)); + + return tasks; +} + size_t PxrMayaHdSceneDelegate::_RenderTaskIdMapKey::HashFunctor::operator ()( From 04ab04b5ce6764ae2c305673fdb7735591684ae3 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 15:15:50 -0700 Subject: [PATCH 24/35] [pxrUsdMayaGL] reuse already fetched renderIndex in scene delegate GetRenderTasks() --- lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp index 3c64b1c28b..e47a481fa8 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp @@ -441,7 +441,7 @@ PxrMayaHdSceneDelegate::GetRenderTasks( const PxrMayaHdPrimFilterVector& primFilters) { HdTaskSharedPtrVector taskList; - HdRenderIndex &renderIndex = GetRenderIndex(); + HdRenderIndex& renderIndex = GetRenderIndex(); // Task List Consist of: // Render Setup Task @@ -502,7 +502,7 @@ PxrMayaHdSceneDelegate::GetRenderTasks( key.hash, key.collectionName.GetText()))); - GetRenderIndex().InsertTask(this, renderTaskId); + renderIndex.InsertTask(this, renderTaskId); // Note that the render task has no params of its own. All of the // render params are on the render setup task instead. @@ -519,8 +519,8 @@ PxrMayaHdSceneDelegate::GetRenderTasks( if (currentRenderTags != primFilter.renderTags) { _SetValue(renderTaskId, HdTokens->renderTags, primFilter.renderTags); - GetRenderIndex().GetChangeTracker().MarkTaskDirty( - renderTaskId, + renderIndex.GetChangeTracker().MarkTaskDirty( + renderTaskId, HdChangeTracker::DirtyRenderTags); } } @@ -530,7 +530,7 @@ PxrMayaHdSceneDelegate::GetRenderTasks( // Update the collections on the render task and mark them dirty. // XXX: Should only mark collection dirty if collection has changed _SetValue(renderTaskId, HdTokens->collection, primFilter.collection); - GetRenderIndex().GetChangeTracker().MarkTaskDirty( + renderIndex.GetChangeTracker().MarkTaskDirty( renderTaskId, HdChangeTracker::DirtyCollection); } @@ -543,7 +543,7 @@ PxrMayaHdSceneDelegate::GetRenderTasks( _tokens->selectionTask.GetText(), hash))); - GetRenderIndex().InsertTask(this, selectionTaskId); + renderIndex.InsertTask(this, selectionTaskId); HdxSelectionTaskParams selectionTaskParams; selectionTaskParams.enableSelection = true; @@ -612,7 +612,7 @@ PxrMayaHdSceneDelegate::GetRenderTasks( // Store the updated render setup task params back in the cache and // mark them dirty. _SetValue(renderSetupTaskId, HdTokens->params, renderSetupTaskParams); - GetRenderIndex().GetChangeTracker().MarkTaskDirty( + renderIndex.GetChangeTracker().MarkTaskDirty( renderSetupTaskId, HdChangeTracker::DirtyParams); } From d4fdf26daf67601d9cfb9ff8d2dfce14ff27e3d2 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 15:24:38 -0700 Subject: [PATCH 25/35] [pxrUsdMayaGL] get viewport displayStyle in _RenderBatches() and plumb it down to GetRenderTasks() displayStatus may vary per viewport, so we need to select the repr for each shape at draw time rather than at Sync() time. Subsequent commits will make use of the displayStyle by querying each shape adapter for the repr that should be used. --- .../render/pxrUsdMayaGL/batchRenderer.cpp | 24 ++++++++++++++++++- .../render/pxrUsdMayaGL/batchRenderer.h | 1 + .../render/pxrUsdMayaGL/sceneDelegate.cpp | 1 + .../render/pxrUsdMayaGL/sceneDelegate.h | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp index 8bd1bed36c..1852dc06ad 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp @@ -1294,6 +1294,7 @@ UsdMayaGLBatchRenderer::_Render( const GfMatrix4d& worldToViewMatrix, const GfMatrix4d& projectionMatrix, const GfVec4d& viewport, + unsigned int displayStyle, const std::vector<_RenderItem>& items) { TRACE_FUNCTION(); @@ -1353,7 +1354,11 @@ UsdMayaGLBatchRenderer::_Render( primFilters.size()); HdTaskSharedPtrVector renderTasks = - _taskDelegate->GetRenderTasks(paramsHash, params, primFilters); + _taskDelegate->GetRenderTasks( + paramsHash, + params, + displayStyle, + primFilters); tasks.insert(tasks.end(), renderTasks.begin(), renderTasks.end()); } @@ -1433,6 +1438,22 @@ UsdMayaGLBatchRenderer::_RenderBatches( // re-populate it. _softSelectHelper.Reset(); + // Assume shaded displayStyle, but we *should* be able to pull it from + // either the vp2Context for Viewport 2.0 or the M3dView for the legacy + // viewport. + unsigned int displayStyle = + MHWRender::MFrameContext::DisplayStyle::kGouraudShaded; + + if (vp2Context) { + displayStyle = vp2Context->getDisplayStyle(); + } else if (view3d) { + const M3dView::DisplayStyle legacyDisplayStyle = + view3d->displayStyle(); + displayStyle = + px_LegacyViewportUtils::GetMFrameContextDisplayStyle( + legacyDisplayStyle); + } + bool itemsVisible = false; std::vector<_RenderItem> items; for (const auto& iter : bucketsMap) { @@ -1491,6 +1512,7 @@ UsdMayaGLBatchRenderer::_RenderBatches( _Render(worldToViewMatrix, projectionMatrix, viewport, + displayStyle, items); // Viewport 2 may be rendering in multiple passes, and we want to make sure diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h index 77ca9503bb..daaa5c84b9 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h @@ -318,6 +318,7 @@ class UsdMayaGLBatchRenderer const GfMatrix4d& worldToViewMatrix, const GfMatrix4d& projectionMatrix, const GfVec4d& viewport, + unsigned int displayStyle, const std::vector<_RenderItem>& items); /// Call to render all queued batches. May be called safely without diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp index e47a481fa8..c2e3e6da92 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp @@ -438,6 +438,7 @@ HdTaskSharedPtrVector PxrMayaHdSceneDelegate::GetRenderTasks( const size_t hash, const PxrMayaHdRenderParams& renderParams, + unsigned int /* displayStyle */, const PxrMayaHdPrimFilterVector& primFilters) { HdTaskSharedPtrVector taskList; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h index c71a5358a7..d5008117cf 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h @@ -94,6 +94,7 @@ class PxrMayaHdSceneDelegate : public HdSceneDelegate HdTaskSharedPtrVector GetRenderTasks( const size_t hash, const PxrMayaHdRenderParams& renderParams, + unsigned int displayStyle, const PxrMayaHdPrimFilterVector& primFilters); MAYAUSD_CORE_PUBLIC From fd0860c43f892b5a011f9d850459839f1b89345e Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 16:39:15 -0700 Subject: [PATCH 26/35] [pxrUsdMayaGL] remove old, and now inaccurate, refactoring comments in GetRenderTasks() --- lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp index c2e3e6da92..08f3ee4eba 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp @@ -579,20 +579,10 @@ PxrMayaHdSceneDelegate::GetRenderTasks( // With Hydra, changing the contents of a collection can be // an expensive operation as it causes draw batches to be rebuilt. // - // The Maya-Hydra Plugin is currently reusing the same collection - // name for all collections within a frame. - // (This stems from a time when collection name had a significant meaning - // rather than id'ing a collection). - // // The plugin should also track deltas to the contents of a collection // and set Hydra's dirty state when prims get added and removed from // the collection. // - // Another possible change that can be made to this code is HdxRenderTask - // now takes an array of collections, so it is possible to support different - // reprs using the same task. Therefore, this code should be modified to - // only add one task that is provided with the active set of collections. - // // However, a further improvement to the code could be made using // UsdDelegate's fallback repr feature instead of using multiple // collections as it would avoid modifying the collection as a Maya shape From d1232ad39168bb394d6b1e865adc723810891f6f Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 16:55:08 -0700 Subject: [PATCH 27/35] [pxrUsdMayaGL] use a single selection task instead of one per render params hash Since the parameters to the selection task do not vary based on anything shape related and in fact never change at all, there's no reason that we need one per set of unique render params. We can just always use the same one for all shapes. --- .../render/pxrUsdMayaGL/sceneDelegate.cpp | 43 ++++++++----------- .../render/pxrUsdMayaGL/sceneDelegate.h | 2 +- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp index 08f3ee4eba..7499d3ee46 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp @@ -119,6 +119,7 @@ PxrMayaHdSceneDelegate::PxrMayaHdSceneDelegate( _simpleLightTaskId = _rootId.AppendChild(HdxPrimitiveTokens->simpleLightTask); _shadowTaskId = _rootId.AppendChild(HdxPrimitiveTokens->shadowTask); _pickingTaskId = _rootId.AppendChild(HdxPrimitiveTokens->pickTask); + _selectionTaskId = _rootId.AppendChild(_tokens->selectionTask); _cameraId = _rootId.AppendChild(HdPrimTypeTokens->camera); // camera @@ -179,6 +180,22 @@ PxrMayaHdSceneDelegate::PxrMayaHdSceneDelegate( // to current render tags cache[HdTokens->renderTags] = VtValue(TfTokenVector()); } + + // Selection task. + { + renderIndex->InsertTask(this, _selectionTaskId); + _ValueCache& cache = _valueCacheMap[_selectionTaskId]; + HdxSelectionTaskParams taskParams; + taskParams.enableSelection = true; + + // Note that the selection color is a constant zero value. This is to + // mimic selection behavior in Maya where the wireframe color is what + // changes to indicate selection and not the object color. + taskParams.selectionColor = GfVec4f(0.0f); + + cache[HdTokens->params] = VtValue(taskParams); + cache[HdTokens->collection] = VtValue(); + } } /*virtual*/ @@ -536,31 +553,7 @@ PxrMayaHdSceneDelegate::GetRenderTasks( HdChangeTracker::DirtyCollection); } - SdfPath selectionTaskId; - if (!TfMapLookup(_selectionTaskIdMap, hash, &selectionTaskId)) { - // Create a new selection task if one does not exist for this hash. - selectionTaskId = _rootId.AppendChild( - TfToken(TfStringPrintf("%s_%zx", - _tokens->selectionTask.GetText(), - hash))); - - renderIndex.InsertTask(this, selectionTaskId); - HdxSelectionTaskParams selectionTaskParams; - selectionTaskParams.enableSelection = true; - - // Note that the selection color is a constant zero value. This is to - // mimic selection behavior in Maya where the wireframe color is what - // changes to indicate selection and not the object color. As a result, - // we don't need to dirty the selectionTaskParams below. - selectionTaskParams.selectionColor = GfVec4f(0.0f); - - _ValueCache& cache = _valueCacheMap[selectionTaskId]; - cache[HdTokens->params] = VtValue(selectionTaskParams); - cache[HdTokens->collection] = VtValue(); - - _selectionTaskIdMap[hash] = selectionTaskId; - } - taskList.emplace_back(renderIndex.GetTask(selectionTaskId)); + taskList.emplace_back(renderIndex.GetTask(_selectionTaskId)); // // (meta-XXX): The notes below are actively being addressed with an diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h index d5008117cf..e502ce2085 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h @@ -162,9 +162,9 @@ class PxrMayaHdSceneDelegate : public HdSceneDelegate _RenderParamTaskIdMap _renderSetupTaskIdMap; _RenderTaskIdMap _renderTaskIdMap; - _RenderParamTaskIdMap _selectionTaskIdMap; SdfPath _pickingTaskId; + SdfPath _selectionTaskId; typedef TfHashMap _ValueCache; typedef TfHashMap _ValueCacheMap; From d7926c4dca01537fdda446c924d77b69500a0f94 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 17:27:45 -0700 Subject: [PATCH 28/35] [pxrUsdMayaGL] map collection names to render tasks and render params hashes to render setup tasks This change simplifies the mapping of HdRprimCollection names to render task IDs and hashes of render params to render setup task IDs, respectively. Since the batch renderer now never changes the collection of a render task itself, it no longer needs to mark them dirty on every draw. Note that this commit would actually cause somewhat of a performance regression on its own, since the single render task per collection would get thrashed a bit more as its repr is changed. Subsequent commits will make the shape adapters manage a collection and a render task ID *per* repr. This also allows the shape adapter to notify the change tracker when its collections or tasks need to be dirtied. --- .../render/pxrUsdMayaGL/sceneDelegate.cpp | 84 ++++++++----------- .../render/pxrUsdMayaGL/sceneDelegate.h | 36 +++----- 2 files changed, 46 insertions(+), 74 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp index 7499d3ee46..2e1781b827 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp @@ -498,59 +498,63 @@ PxrMayaHdSceneDelegate::GetRenderTasks( } taskList.emplace_back(renderIndex.GetTask(renderSetupTaskId)); - size_t numPrimFilters = primFilters.size(); - for (size_t primFilterNum = 0; - primFilterNum < numPrimFilters; - ++primFilterNum) - - { - const PxrMayaHdPrimFilter &primFilter = primFilters[primFilterNum]; + for (const PxrMayaHdPrimFilter& primFilter : primFilters) { + SdfPath renderTaskId; + const HdRprimCollection& rprimCollection = primFilter.collection; + const TfTokenVector& renderTags = primFilter.renderTags; - _RenderTaskIdMapKey key = {hash, primFilter.collection.GetName()}; + // The batch renderer manages the render task ID for this collection, + // so look up its ID by name. + const TfToken& collectionName = rprimCollection.GetName(); - SdfPath renderTaskId; - if (!TfMapLookup(_renderTaskIdMap, key, &renderTaskId)) { - // Create a new render task if one does not exist for this key. + if (!TfMapLookup(_renderTaskIdMap, collectionName, &renderTaskId)) { + // Create a new render task ID if one does not exist for this + // collection. // Note that we expect the collection name to have already been // sanitized for use in SdfPaths. - TF_VERIFY(TfIsValidIdentifier(key.collectionName.GetString())); + TF_VERIFY(TfIsValidIdentifier(collectionName.GetString())); renderTaskId = _rootId.AppendChild( - TfToken(TfStringPrintf("%s_%zx_%s", - HdxPrimitiveTokens->renderTask.GetText(), - key.hash, - key.collectionName.GetText()))); + TfToken( + TfStringPrintf( + "%s_%s", + HdxPrimitiveTokens->renderTask.GetText(), + collectionName.GetText()))); + + _renderTaskIdMap[collectionName] = renderTaskId; + } + HdTaskSharedPtr renderTask = renderIndex.GetTask(renderTaskId); + if (!renderTask) { renderIndex.InsertTask(this, renderTaskId); + renderTask = renderIndex.GetTask(renderTaskId); + + _ValueCache& cache = _valueCacheMap[renderTaskId]; // Note that the render task has no params of its own. All of the // render params are on the render setup task instead. - _ValueCache& cache = _valueCacheMap[renderTaskId]; cache[HdTokens->params] = VtValue(); - cache[HdTokens->collection] = VtValue(primFilter.collection); - cache[HdTokens->renderTags] = VtValue(primFilter.renderTags); - _renderTaskIdMap[key] = renderTaskId; + // Once the task is created, the batch renderer itself will not + // change the task's collection. + cache[HdTokens->collection] = VtValue(rprimCollection); + + cache[HdTokens->renderTags] = VtValue(renderTags); } else { // Update task's render tags - const TfTokenVector ¤tRenderTags = + const TfTokenVector& currentRenderTags = _GetValue(renderTaskId, HdTokens->renderTags); - if (currentRenderTags != primFilter.renderTags) { - _SetValue(renderTaskId, HdTokens->renderTags, primFilter.renderTags); + if (currentRenderTags != renderTags) { + _SetValue(renderTaskId, HdTokens->renderTags, renderTags); renderIndex.GetChangeTracker().MarkTaskDirty( renderTaskId, HdChangeTracker::DirtyRenderTags); } } - taskList.emplace_back(renderIndex.GetTask(renderTaskId)); - - // Update the collections on the render task and mark them dirty. - // XXX: Should only mark collection dirty if collection has changed - _SetValue(renderTaskId, HdTokens->collection, primFilter.collection); - renderIndex.GetChangeTracker().MarkTaskDirty( - renderTaskId, - HdChangeTracker::DirtyCollection); + if (renderTask) { + taskList.emplace_back(renderTask); + } } taskList.emplace_back(renderIndex.GetTask(_selectionTaskId)); @@ -627,22 +631,4 @@ PxrMayaHdSceneDelegate::GetPickingTasks( } -size_t -PxrMayaHdSceneDelegate::_RenderTaskIdMapKey::HashFunctor::operator ()( - const _RenderTaskIdMapKey& value) const -{ - size_t hash = value.hash; - boost::hash_combine(hash, value.collectionName); - - return hash; -} - -bool -PxrMayaHdSceneDelegate::_RenderTaskIdMapKey::operator ==( - const _RenderTaskIdMapKey& other) const -{ - return ((this->hash == other.hash) && - (this->collectionName == other.collectionName)); -} - PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h index e502ce2085..64c65faad6 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h @@ -134,32 +134,18 @@ class PxrMayaHdSceneDelegate : public HdSceneDelegate SdfPath _shadowTaskId; - // XXX: While this is correct, that we are using - // hash in forming the task id, so the map is valid. - // It is possible for the hash to collide, so the id - // formed from the combination of hash and collection name is not - // necessarily unique. - struct _RenderTaskIdMapKey - { - size_t hash; - TfToken collectionName; + // Currently, there is a one-to-one mapping between rprim collections + // managed by shape adapters and Hydra render tasks. The shape adapters + // ensure that their collections have a unique name, so we index into + // the map of Hydra render tasks using that name to find the render + // task for that collection. + using _RenderTaskIdMap = + std::unordered_map; + + // For render setup tasks, there is one task per unique set of render + // params, which are hashed to generate a key. + using _RenderParamTaskIdMap = std::unordered_map; - struct HashFunctor { - size_t operator()(const _RenderTaskIdMapKey& value) const; - }; - - bool operator==(const _RenderTaskIdMapKey& other) const; - }; - - typedef std::unordered_map< - _RenderTaskIdMapKey, - SdfPath, - _RenderTaskIdMapKey::HashFunctor> _RenderTaskIdMap; - - typedef std::unordered_map _RenderParamTaskIdMap; - - - _RenderParamTaskIdMap _renderSetupTaskIdMap; _RenderTaskIdMap _renderTaskIdMap; From b59b187bd5609ff0ca9d285a9cc9a34891a5d7a0 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 17:44:29 -0700 Subject: [PATCH 29/35] [pxrUsdMayaGL] add a way to plumb shape adapters into GetRenderTasks() using prim filters This will allow us to delay computing which repr to use until draw time and to query the necessary data from the shape adapters directly. The original mechanism will be supported by specifying the shape adapter as nullptr in the prim filter. This commit adds the plumbing and a subsequent commit will take advantage of it when the shape adapters manage a collection per repr. --- .../render/pxrUsdMayaGL/batchRenderer.cpp | 3 +++ .../pxrUsdMayaGL/proxyShapeDelegate.cpp | 1 + .../render/pxrUsdMayaGL/sceneDelegate.h | 24 +++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp index 1852dc06ad..a7221e44f4 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp @@ -1090,6 +1090,7 @@ UsdMayaGLBatchRenderer::_GetIntersectionPrimFilters( primFilters.push_back( PxrMayaHdPrimFilter { + nullptr, rprimCollection, renderTags }); @@ -1104,6 +1105,7 @@ UsdMayaGLBatchRenderer::_GetIntersectionPrimFilters( primFilters.push_back( PxrMayaHdPrimFilter { + nullptr, collection, TfTokenVector{ #if USD_VERSION_NUM >= 1911 @@ -1466,6 +1468,7 @@ UsdMayaGLBatchRenderer::_RenderBatches( itemsVisible |= shapeAdapter->IsVisible(); primFilters.push_back(PxrMayaHdPrimFilter { + nullptr, shapeAdapter->GetRprimCollection(), shapeAdapter->GetRenderTags() }); diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeDelegate.cpp index c44d275515..6ffdd715cc 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeDelegate.cpp @@ -33,6 +33,7 @@ PXR_NAMESPACE_OPEN_SCOPE static PxrMayaHdPrimFilter _sharedPrimFilter = { + nullptr, HdRprimCollection( TfToken("UsdMayaGL_ClosestPointOnProxyShape"), HdReprSelector(HdReprTokens->refined) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h index 64c65faad6..2e9b702382 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h @@ -40,10 +40,21 @@ #include #include +#include PXR_NAMESPACE_OPEN_SCOPE +/// Prim filters can be specified in one of two ways: +/// +/// 1. If a shape adapter is being used, it can be specified in the +/// shapeAdapter field and all necessary data will be obtained by +/// querying the shape adapter for it. +/// 2. If no shape adapter is being used, the shapeAdapter field should be +/// set to nullptr, and a collection and set of render tags *must* be +/// provided. +/// struct PxrMayaHdPrimFilter { + PxrMayaHdShapeAdapter* shapeAdapter; HdRprimCollection collection; TfTokenVector renderTags; }; @@ -134,11 +145,14 @@ class PxrMayaHdSceneDelegate : public HdSceneDelegate SdfPath _shadowTaskId; - // Currently, there is a one-to-one mapping between rprim collections - // managed by shape adapters and Hydra render tasks. The shape adapters - // ensure that their collections have a unique name, so we index into - // the map of Hydra render tasks using that name to find the render - // task for that collection. + // When prim filters are populated including a shape adapter, the + // adapter is responsible for providing the appropriate render task ID + // for a given repr. When no shape adapter is given, the batch renderer + // manages the render task ID and constructs it using the rprim + // collection name. The batch renderer will ultimately instantiate the + // render task itself for both cases. + // This type maps collection names to render task IDs for tasks in the + // latter case where the task ID is managed by the batch renderer. using _RenderTaskIdMap = std::unordered_map; From 9d27bf8e6f2e930e18454384bedfcaa461255f21 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 18:04:43 -0700 Subject: [PATCH 30/35] [pxrUsdMayaGL] make shape adapters manage a collection and a render task ID per repr This change provides a consistent one-to-one mapping between reprs, collections, and render tasks in the shape adapter. This results in minimal draw batch thrashing within hydra when the repr changes due to a change in Maya viewport displayStyle, since the repr on the collection never needs to change and the collection on the render task never needs to change. The shape adapter must be queried for which collection and render task ID to use based on a particular repr, so that handling has been added where necessary in the batch renderer and scene/task delegate. When rendering, the shape adapters are plumbed through to GetRenderTasks() where we determine what repr to use based on the displayStyle, and then use that repr to get the appropriate collection and render task ID for each shape we're drawing. --- .../render/pxrUsdMayaGL/batchRenderer.cpp | 25 +++++-- .../pxrUsdMayaGL/instancerShapeAdapter.cpp | 23 ------ .../render/pxrUsdMayaGL/sceneDelegate.cpp | 60 +++++++++------ .../render/pxrUsdMayaGL/shapeAdapter.cpp | 45 +++++++++++ .../render/pxrUsdMayaGL/shapeAdapter.h | 75 ++++++++++++++++--- .../pxrUsdMayaGL/usdProxyShapeAdapter.cpp | 22 ------ 6 files changed, 167 insertions(+), 83 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp index a7221e44f4..2776ef1286 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp @@ -362,7 +362,8 @@ UsdMayaGLBatchRenderer::PopulateCustomPrimFilter( // Only update the collection and mark it dirty if the root paths have // actually changed. This greatly affects performance. PxrMayaHdShapeAdapter* adapter = iter->second; - const SdfPathVector& roots = adapter->GetRprimCollection().GetRootPaths(); + const HdReprSelector repr = collection.GetReprSelector(); + const SdfPathVector& roots = adapter->GetRprimCollection(repr).GetRootPaths(); if (collection.GetRootPaths() != roots) { collection.SetRootPaths(roots); changeTracker.MarkCollectionDirty(collection.GetName()); @@ -1083,14 +1084,20 @@ UsdMayaGLBatchRenderer::_GetIntersectionPrimFilters( continue; } + // XXX: The full viewport-based collections use the "refined" repr, + // so we use the same repr here if we're doing adapter-by-adapter + // depth selection. Ideally though, this would be whatever repr was + // most recently drawn for the viewport in which the selection is + // taking place. + const HdReprSelector repr(HdReprTokens->refined); const HdRprimCollection &rprimCollection = - shapeAdapter->GetRprimCollection(); + shapeAdapter->GetRprimCollection(repr); const TfTokenVector &renderTags = shapeAdapter->GetRenderTags(); primFilters.push_back( PxrMayaHdPrimFilter { - nullptr, + shapeAdapter, rprimCollection, renderTags }); @@ -1456,6 +1463,12 @@ UsdMayaGLBatchRenderer::_RenderBatches( legacyDisplayStyle); } + // Since we'll be populating the prim filters with shape adapters, we don't + // need to specify collections or render tags on them, so just use empty + // ones. + static const HdRprimCollection emptyCollection; + static const TfTokenVector emptyRenderTags; + bool itemsVisible = false; std::vector<_RenderItem> items; for (const auto& iter : bucketsMap) { @@ -1468,9 +1481,9 @@ UsdMayaGLBatchRenderer::_RenderBatches( itemsVisible |= shapeAdapter->IsVisible(); primFilters.push_back(PxrMayaHdPrimFilter { - nullptr, - shapeAdapter->GetRprimCollection(), - shapeAdapter->GetRenderTags() + shapeAdapter, + emptyCollection, + emptyRenderTags }); } diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp index a1e9b9ac86..0696dbce95 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -271,19 +270,6 @@ UsdMayaGL_InstancerShapeAdapter::_Sync( _delegate->SetRootVisibility(_drawShape); } - if (_rprimCollection.GetReprSelector() != reprSelector) { - _rprimCollection.SetReprSelector(reprSelector); - - TF_DEBUG(PXRUSDMAYAGL_SHAPE_ADAPTER_LIFECYCLE).Msg( - " Repr selector changed: %s\n" - " Marking collection dirty: %s\n", - reprSelector.GetText(), - _rprimCollection.GetName().GetText()); - - _delegate->GetRenderIndex().GetChangeTracker().MarkCollectionDirty( - _rprimCollection.GetName()); - } - HdCullStyle cullStyle = HdCullStyleNothing; if (displayStyle & MHWRender::MFrameContext::DisplayStyle::kBackfaceCulling) { cullStyle = HdCullStyleBackUnlessDoubleSided; @@ -323,15 +309,6 @@ UsdMayaGL_InstancerShapeAdapter::_Init(HdRenderIndex* renderIndex) UsdPrim usdPrim = _instancerStage->GetDefaultPrim(); _delegate->Populate(usdPrim, SdfPathVector()); - if (collectionName != _rprimCollection.GetName()) { - _rprimCollection.SetName(collectionName); - renderIndex->GetChangeTracker().AddCollection( - _rprimCollection.GetName()); - } - - _rprimCollection.SetReprSelector(HdReprSelector(HdReprTokens->refined)); - _rprimCollection.SetRootPath(delegateId); - return true; } diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp index 2e1781b827..0f112748cd 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp @@ -55,6 +55,7 @@ #include #include #include +#include PXR_NAMESPACE_OPEN_SCOPE @@ -455,7 +456,7 @@ HdTaskSharedPtrVector PxrMayaHdSceneDelegate::GetRenderTasks( const size_t hash, const PxrMayaHdRenderParams& renderParams, - unsigned int /* displayStyle */, + unsigned int displayStyle, const PxrMayaHdPrimFilterVector& primFilters) { HdTaskSharedPtrVector taskList; @@ -463,7 +464,7 @@ PxrMayaHdSceneDelegate::GetRenderTasks( // Task List Consist of: // Render Setup Task - // Render Task Per Collection + // Render Task Per Shape Adapter/Collection // Selection Task taskList.reserve(2 + primFilters.size()); @@ -500,27 +501,40 @@ PxrMayaHdSceneDelegate::GetRenderTasks( for (const PxrMayaHdPrimFilter& primFilter : primFilters) { SdfPath renderTaskId; - const HdRprimCollection& rprimCollection = primFilter.collection; - const TfTokenVector& renderTags = primFilter.renderTags; - - // The batch renderer manages the render task ID for this collection, - // so look up its ID by name. - const TfToken& collectionName = rprimCollection.GetName(); - - if (!TfMapLookup(_renderTaskIdMap, collectionName, &renderTaskId)) { - // Create a new render task ID if one does not exist for this - // collection. - // Note that we expect the collection name to have already been - // sanitized for use in SdfPaths. - TF_VERIFY(TfIsValidIdentifier(collectionName.GetString())); - renderTaskId = _rootId.AppendChild( - TfToken( - TfStringPrintf( - "%s_%s", - HdxPrimitiveTokens->renderTask.GetText(), - collectionName.GetText()))); - - _renderTaskIdMap[collectionName] = renderTaskId; + HdRprimCollection rprimCollection; + TfTokenVector renderTags; + + if (primFilter.shapeAdapter != nullptr) { + const HdReprSelector repr = + primFilter.shapeAdapter->GetReprSelectorForDisplayStyle( + displayStyle); + + renderTaskId = primFilter.shapeAdapter->GetRenderTaskId(repr); + rprimCollection = primFilter.shapeAdapter->GetRprimCollection(repr); + renderTags = primFilter.shapeAdapter->GetRenderTags(); + } else { + rprimCollection = primFilter.collection; + renderTags = primFilter.renderTags; + + // The batch renderer manages the render task ID for this + // collection, so look up its ID by name. + const TfToken& collectionName = rprimCollection.GetName(); + + if (!TfMapLookup(_renderTaskIdMap, collectionName, &renderTaskId)) { + // Create a new render task ID if one does not exist for this + // collection. + // Note that we expect the collection name to have already been + // sanitized for use in SdfPaths. + TF_VERIFY(TfIsValidIdentifier(collectionName.GetString())); + renderTaskId = _rootId.AppendChild( + TfToken( + TfStringPrintf( + "%s_%s", + HdxPrimitiveTokens->renderTask.GetText(), + collectionName.GetText()))); + + _renderTaskIdMap[collectionName] = renderTaskId; + } } HdTaskSharedPtr renderTask = renderIndex.GetTask(renderTaskId); diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index d41869020a..224e50f9cb 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -16,6 +16,7 @@ #include "shapeAdapter.h" #include +#include #include #include @@ -42,6 +43,8 @@ #include #include #include +#include +#include #include #include @@ -299,6 +302,9 @@ PxrMayaHdShapeAdapter::_SetDagPath(const MDagPath& dagPath) _shapeIdentifier = TfToken(); _delegateId = SdfPath(); + _rprimCollectionMap.clear(); + _renderTaskIdMap.clear(); + MStatus status; const bool dagPathIsValid = _shapeDagPath.isValid(&status); if (status != MS::kSuccess || !dagPathIsValid) { @@ -331,6 +337,45 @@ PxrMayaHdShapeAdapter::_SetDagPath(const MDagPath& dagPath) _delegateId = delegatePrefix.AppendChild(_shapeIdentifier); + // Create entries in the collection and render task ID maps for each repr + // we might use. + static const std::vector allMayaReprs({ + HdReprSelector(HdReprTokens->hull), + HdReprSelector(HdReprTokens->refined), + HdReprSelector(HdReprTokens->refinedWire), + HdReprSelector(HdReprTokens->refinedWireOnSurf), + HdReprSelector(HdReprTokens->wire), + HdReprSelector(HdReprTokens->wireOnSurf) + }); + + for (const HdReprSelector& reprSelector : allMayaReprs) { + const TfToken rprimCollectionName = TfToken( + TfStringPrintf("%s_%s", + _shapeIdentifier.GetText(), + reprSelector.GetText())); + _rprimCollectionMap.emplace( + std::make_pair( + reprSelector, + HdRprimCollection( + rprimCollectionName, + reprSelector, + _delegateId))); + + renderIndex->GetChangeTracker().AddCollection(rprimCollectionName); + + // We only generate the render task ID here. We'll leave it to the + // batch renderer to lazily create the task in the render index when + // it is first needed. + const TfToken renderTaskName = TfToken( + TfStringPrintf("%s_%s", + HdxPrimitiveTokens->renderTask.GetText(), + rprimCollectionName.GetText())); + _renderTaskIdMap.emplace( + std::make_pair( + reprSelector, + _delegateId.AppendChild(renderTaskName))); + } + return status; } diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index e0802561cf..e6ff43fe38 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -19,6 +19,7 @@ /// \file pxrUsdMayaGL/shapeAdapter.h #include +#include #include #include @@ -169,8 +170,39 @@ class PxrMayaHdShapeAdapter return _renderParams; } - const HdRprimCollection& GetRprimCollection() const { - return _rprimCollection; + /// Get the rprim collection for the given repr. + /// + /// These collections are created when the shape adapter's MDagPath is + /// set to a valid Maya shape. + /// + /// Returns an empty collection if there is no collection for the given + /// repr. + const HdRprimCollection& GetRprimCollection( + const HdReprSelector& repr) const { + const auto& iter = _rprimCollectionMap.find(repr); + if (iter != _rprimCollectionMap.cend()) { + return iter->second; + } + + static const HdRprimCollection emptyCollection; + return emptyCollection; + } + + /// Get the ID of the render task for the collection of the given repr. + /// + /// These render task IDs are created when the shape adapter's MDagPath + /// is set to a valid Maya shape. + /// + /// Returns an empty SdfPath if there is no render task ID for the + /// given repr. + const SdfPath& GetRenderTaskId(const HdReprSelector& repr) const { + const auto& iter = _renderTaskIdMap.find(repr); + if (iter != _renderTaskIdMap.cend()) { + return iter->second; + } + + static const SdfPath emptyTaskId; + return emptyTaskId; } /// Retrieves the render tags for this shape (i.e. which prim purposes @@ -234,12 +266,12 @@ class PxrMayaHdShapeAdapter /// Sets the shape adapter's DAG path. /// /// This re-computes the "identifier" for the shape, which is used to - /// compute the name of the shape's HdRprimCollection. The batch - /// renderer currently creates a render task for each shape's - /// HdRprimCollection, and those render tasks are identified by an + /// compute the names of the shape's HdRprimCollections. The batch + /// renderer will create a render task for each of the shape's + /// HdRprimCollections, and those render tasks are identified by an /// SdfPath constructed using the collection's name. We therefore need - /// the collection to have a name that is unique to the shape it - /// represents and also sanitized for use in SdfPaths. + /// the collections to have names that are unique to the shape they + /// represent and also sanitized for use in SdfPaths. /// /// The identifier will be a TfToken that is unique to the shape and is /// a valid SdfPath identifier, or an empty TfToken if there is an @@ -303,8 +335,33 @@ class PxrMayaHdShapeAdapter PxrMayaHdRenderParams _renderParams; bool _drawShape; - HdRprimCollection _rprimCollection; - TfTokenVector _renderTags; + struct _ReprHashFunctor { + size_t operator()(const HdReprSelector& repr) const { + // Since we currently only use the refinedToken of + // HdReprSelector, we only need to consider that one token when + // hashing. + return repr[0u].Hash(); + } + }; + + // Mapping of HdReprSelector to the rprim collection for that selector. + using _RprimCollectionMap = + std::unordered_map< + const HdReprSelector, + const HdRprimCollection, + _ReprHashFunctor>; + _RprimCollectionMap _rprimCollectionMap; + + // Mapping of HdReprSelector to the ID of the render task for the + // collection for that selector. + using _RenderTaskIdMap = + std::unordered_map< + const HdReprSelector, + const SdfPath, + _ReprHashFunctor>; + _RenderTaskIdMap _renderTaskIdMap; + + TfTokenVector _renderTags; GfMatrix4d _rootXform; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp index 66948f2757..082f336fec 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -231,19 +230,6 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( _delegate->SetRootVisibility(_drawShape); } - if (_rprimCollection.GetReprSelector() != reprSelector) { - _rprimCollection.SetReprSelector(reprSelector); - - TF_DEBUG(PXRUSDMAYAGL_SHAPE_ADAPTER_LIFECYCLE).Msg( - " Repr selector changed: %s\n" - " Marking collection dirty: %s\n", - reprSelector.GetText(), - _rprimCollection.GetName().GetText()); - - _delegate->GetRenderIndex().GetChangeTracker().MarkCollectionDirty( - _rprimCollection.GetName()); - } - HdCullStyle cullStyle = HdCullStyleNothing; if (displayStyle & MHWRender::MFrameContext::DisplayStyle::kBackfaceCulling) { cullStyle = HdCullStyleBackUnlessDoubleSided; @@ -303,14 +289,6 @@ PxrMayaHdUsdProxyShapeAdapter::_Init(HdRenderIndex* renderIndex) _delegate->Populate(_rootPrim, _excludedPrimPaths, SdfPathVector()); - if (collectionName != _rprimCollection.GetName()) { - _rprimCollection.SetName(collectionName); - renderIndex->GetChangeTracker().AddCollection(_rprimCollection.GetName()); - } - - _rprimCollection.SetReprSelector(HdReprSelector(HdReprTokens->refined)); - _rprimCollection.SetRootPath(delegateId); - return true; } From ece942958d85f007757310e6474e6234fff239f4 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 18:18:39 -0700 Subject: [PATCH 31/35] [pxrUsdMayaGL] push "drawShape" out of shape adapter Sync() and into GetRenderTasks() Storing whether or not to draw the shape during Sync() is not correct since we may be drawing for multiple viewports with differing displayStyles, or we may change displayStyles on a particular viewport and not get another prepareForDraw() callback. To fix this, instead of setting the delegate's root visibility during sync, we check during GetRenderTasks() to see whether there's an active render for the given displayStatus, and simply skip adding the render task if there isn't one. --- lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp | 7 ------- lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp | 4 ++++ lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h | 1 - lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp | 7 ------- 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp index 0696dbce95..86348fb68c 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp @@ -258,18 +258,11 @@ UsdMayaGL_InstancerShapeAdapter::_Sync( // lighting. const HdReprSelector reprSelector = GetReprSelectorForDisplayStyle(displayStyle); - - _drawShape = reprSelector.AnyActiveRepr(); - if (reprSelector.Contains(HdReprTokens->wire) || reprSelector.Contains(HdReprTokens->refinedWire)) { _renderParams.enableLighting = false; } - if (_delegate->GetRootVisibility() != _drawShape) { - _delegate->SetRootVisibility(_drawShape); - } - HdCullStyle cullStyle = HdCullStyleNothing; if (displayStyle & MHWRender::MFrameContext::DisplayStyle::kBackfaceCulling) { cullStyle = HdCullStyleBackUnlessDoubleSided; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp index 0f112748cd..fbc11a49ee 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp @@ -509,6 +509,10 @@ PxrMayaHdSceneDelegate::GetRenderTasks( primFilter.shapeAdapter->GetReprSelectorForDisplayStyle( displayStyle); + if (!repr.AnyActiveRepr()) { + continue; + } + renderTaskId = primFilter.shapeAdapter->GetRenderTaskId(repr); rprimCollection = primFilter.shapeAdapter->GetRprimCollection(repr); renderTags = primFilter.shapeAdapter->GetRenderTags(); diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index e6ff43fe38..fdaac782e4 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -333,7 +333,6 @@ class PxrMayaHdShapeAdapter SdfPath _delegateId; PxrMayaHdRenderParams _renderParams; - bool _drawShape; struct _ReprHashFunctor { size_t operator()(const HdReprSelector& repr) const { diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp index 082f336fec..dc57041b66 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp @@ -218,18 +218,11 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( // determine the repr, so be sure to do this *after* that has been set. const HdReprSelector reprSelector = GetReprSelectorForDisplayStyle(displayStyle); - - _drawShape = reprSelector.AnyActiveRepr(); - if (reprSelector.Contains(HdReprTokens->wire) || reprSelector.Contains(HdReprTokens->refinedWire)) { _renderParams.enableLighting = false; } - if (_delegate->GetRootVisibility() != _drawShape) { - _delegate->SetRootVisibility(_drawShape); - } - HdCullStyle cullStyle = HdCullStyleNothing; if (displayStyle & MHWRender::MFrameContext::DisplayStyle::kBackfaceCulling) { cullStyle = HdCullStyleBackUnlessDoubleSided; From 7acc081c2b80c4aa5bfead19bf26da1eb58123d4 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 18:21:39 -0700 Subject: [PATCH 32/35] [pxrUsdMayaGL] add a shape adapter function for dirtying its render tasks Though this is not yet being used, this function can be used to notify the change tracker when the shape adapter detects a change in the shape that requires regenerating draw batches. --- .../render/pxrUsdMayaGL/shapeAdapter.cpp | 18 ++++++++++++++++++ lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp index 224e50f9cb..f9599f9396 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -379,6 +380,23 @@ PxrMayaHdShapeAdapter::_SetDagPath(const MDagPath& dagPath) return status; } +void +PxrMayaHdShapeAdapter::_MarkRenderTasksDirty(HdDirtyBits dirtyBits) +{ + HdRenderIndex* renderIndex = + UsdMayaGLBatchRenderer::GetInstance().GetRenderIndex(); + + for (const auto& iter : _renderTaskIdMap) { + // The render tasks represented by the IDs in this map are instantiated + // lazily, so check that the task exists before attempting to dirty it. + if (renderIndex->HasTask(iter.second)) { + renderIndex->GetChangeTracker().MarkTaskDirty( + iter.second, + dirtyBits); + } + } +} + /* static */ bool PxrMayaHdShapeAdapter::_GetWireframeColor( diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h index fdaac782e4..ba35b21f7c 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/shapeAdapter.h @@ -25,8 +25,10 @@ #include #include #include +#include #include #include +#include #include // XXX: With Maya versions up through 2019 on Linux, M3dView.h ends up @@ -279,6 +281,16 @@ class PxrMayaHdShapeAdapter MAYAUSD_CORE_PUBLIC MStatus _SetDagPath(const MDagPath& dagPath); + /// Mark the render tasks for this shape dirty. + /// + /// The batch renderer currently creates a render task for each shape's + /// HdRprimCollection, but it has no knowledge of when the collection + /// is changed, for example. This method should be called to notify the + /// batch renderer when such a change is made. + MAYAUSD_CORE_PUBLIC + void _MarkRenderTasksDirty( + HdDirtyBits dirtyBits = HdChangeTracker::AllDirty); + /// Helper for getting the wireframe color of the shape. /// /// Determining the wireframe color may involve inspecting the soft From f3f0405e82ae5c800d56b1ba005a25efdb8179bf Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Thu, 4 Jun 2020 12:13:25 -0700 Subject: [PATCH 33/35] [pxrUsdMayaGL] add missing header includes in batch renderer .h and .cpp files Symbols from these headers are used, but the headers were not being included. --- lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp | 1 + lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp index 2776ef1286..fd02106dff 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h index daaa5c84b9..478d0d7bd8 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.h @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include From 4fbe00e7e41f47ea1cda2ab4cc7e5267e787679d Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 17:17:52 -0700 Subject: [PATCH 34/35] [pxrUsdMayaGL] add missing include of hd/changeTracker.h in sceneDelegate.cpp --- lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp index fbc11a49ee..8f1101219d 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include From 24031f0c5881c7921b830300e03079f96557f79e Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Jun 2020 10:22:10 -0700 Subject: [PATCH 35/35] [px_vp20, pxrUsdMayaGL] whitespace clean-up --- lib/mayaUsd/render/px_vp20/utils.cpp | 10 +++++----- lib/mayaUsd/render/px_vp20/utils.h | 2 +- lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp | 10 +++++----- lib/mayaUsd/render/pxrUsdMayaGL/instancerImager.cpp | 2 +- .../render/pxrUsdMayaGL/instancerShapeAdapter.cpp | 2 +- .../render/pxrUsdMayaGL/instancerShapeAdapter.h | 4 ++-- lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeDelegate.cpp | 4 ++-- lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h | 2 +- lib/mayaUsd/render/pxrUsdMayaGL/softSelectHelper.cpp | 2 +- lib/mayaUsd/render/pxrUsdMayaGL/softSelectHelper.h | 4 ++-- .../render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp | 2 +- lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h | 2 +- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/mayaUsd/render/px_vp20/utils.cpp b/lib/mayaUsd/render/px_vp20/utils.cpp index 8a18f28bab..c90136da97 100644 --- a/lib/mayaUsd/render/px_vp20/utils.cpp +++ b/lib/mayaUsd/render/px_vp20/utils.cpp @@ -763,8 +763,8 @@ px_vp20Utils::RenderBoundingBox( bboxTransformMatrix.setScale(scales, MSpace::kTransform); return RenderWireCubes( { GfMatrix4f(bboxTransformMatrix.asMatrix().matrix) }, - color, - GfMatrix4d(worldViewMat.matrix), + color, + GfMatrix4d(worldViewMat.matrix), GfMatrix4d(projectionMat.matrix)); } @@ -875,7 +875,7 @@ void main() // Populate the shader variables. GfMatrix4f vpMatrix(worldViewMat * projectionMat); GLuint vpMatrixLoc = glGetUniformLocation(renderBoundsProgramId, "vpMatrix"); - glUniformMatrix4fv(vpMatrixLoc, 1, + glUniformMatrix4fv(vpMatrixLoc, 1, GL_TRUE, // transpose vpMatrix.data()); @@ -891,12 +891,12 @@ void main() // since we're copying these directly from GfMatrix4f, we need to // transpose() them in the shader. const GLuint cubeXformLoc = glGetAttribLocation(renderBoundsProgramId, "cubeXformT"); - glBufferData(GL_ARRAY_BUFFER, + glBufferData(GL_ARRAY_BUFFER, sizeof(GfMatrix4f) * numCubes, cubeXforms.data(), GL_DYNAMIC_DRAW); for (size_t r = 0; r < 4; r++) { GLuint loc = cubeXformLoc + r; glEnableVertexAttribArray(loc); - glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, sizeof(GfMatrix4f), + glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, sizeof(GfMatrix4f), (char*)(sizeof(float)*4*r)); glVertexAttribDivisor(loc, 1); } diff --git a/lib/mayaUsd/render/px_vp20/utils.h b/lib/mayaUsd/render/px_vp20/utils.h index 23e5a51f9e..8204c583eb 100644 --- a/lib/mayaUsd/render/px_vp20/utils.h +++ b/lib/mayaUsd/render/px_vp20/utils.h @@ -83,7 +83,7 @@ class px_vp20Utils /// Helper to draw multiple wireframe boxes, where \p cubeXforms is a /// list of transforms to apply to the unit cube centered around the - /// origin. Those transforms will all be concatenated with the + /// origin. Those transforms will all be concatenated with the /// \p worldViewMat and \p projectionMat. MAYAUSD_CORE_PUBLIC static bool RenderWireCubes( diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp index fd02106dff..14775ce569 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/batchRenderer.cpp @@ -1097,11 +1097,11 @@ UsdMayaGLBatchRenderer::_GetIntersectionPrimFilters( const TfTokenVector &renderTags = shapeAdapter->GetRenderTags(); primFilters.push_back( - PxrMayaHdPrimFilter { - shapeAdapter, - rprimCollection, - renderTags - }); + PxrMayaHdPrimFilter { + shapeAdapter, + rprimCollection, + renderTags + }); } } diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerImager.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/instancerImager.cpp index 7efc28d422..d7224570b6 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerImager.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerImager.cpp @@ -92,7 +92,7 @@ UsdMayaGL_InstancerImager::_SyncShapeAdapters( const MDagPath firstInstancePath = MDagPath::getAPathTo(handle.object()); - + // Create the adapter if it doesn't exist yet. _InstancerEntry& entry = iter->second; if (vp2) { diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp index 86348fb68c..6323d926cd 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.cpp @@ -309,7 +309,7 @@ UsdMayaGL_InstancerShapeAdapter::_Init(HdRenderIndex* renderIndex) void UsdMayaGL_InstancerShapeAdapter::SyncInstancerPerPrototypePostHook( const MPlug& , UsdPrim& prototypePrim, - std::vector& + std::vector& ) { UsdReferences prototypeRefs = prototypePrim.GetReferences(); diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h index c3093a226a..fceba3dd33 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/instancerShapeAdapter.h @@ -75,7 +75,7 @@ class UsdMayaGL_InstancerShapeAdapter : public PxrMayaHdShapeAdapter /// Gets whether the shape adapter's shape is visible. /// /// This should be called after a call to UpdateVisibility() to ensure - /// that the returned value is correct. + /// that the returned value is correct. MAYAUSD_CORE_PUBLIC bool IsVisible() const override; @@ -83,7 +83,7 @@ class UsdMayaGL_InstancerShapeAdapter : public PxrMayaHdShapeAdapter void SetRootXform(const GfMatrix4d& transform) override; MAYAUSD_CORE_PUBLIC - ~UsdMayaGL_InstancerShapeAdapter() override; + ~UsdMayaGL_InstancerShapeAdapter() override; protected: diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeDelegate.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeDelegate.cpp index 6ffdd715cc..d11f4406e3 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeDelegate.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/proxyShapeDelegate.cpp @@ -35,8 +35,8 @@ PXR_NAMESPACE_OPEN_SCOPE static PxrMayaHdPrimFilter _sharedPrimFilter = { nullptr, HdRprimCollection( - TfToken("UsdMayaGL_ClosestPointOnProxyShape"), - HdReprSelector(HdReprTokens->refined) + TfToken("UsdMayaGL_ClosestPointOnProxyShape"), + HdReprSelector(HdReprTokens->refined) ), TfTokenVector() // Render Tags }; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h index 2e9b702382..08b950104a 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/sceneDelegate.h @@ -163,7 +163,7 @@ class PxrMayaHdSceneDelegate : public HdSceneDelegate _RenderParamTaskIdMap _renderSetupTaskIdMap; _RenderTaskIdMap _renderTaskIdMap; - SdfPath _pickingTaskId; + SdfPath _pickingTaskId; SdfPath _selectionTaskId; typedef TfHashMap _ValueCache; diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/softSelectHelper.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/softSelectHelper.cpp index 2b6d1f29e5..a951761cb8 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/softSelectHelper.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/softSelectHelper.cpp @@ -53,7 +53,7 @@ UsdMayaGLSoftSelectHelper::Populate() _populated = true; } -void +void UsdMayaGLSoftSelectHelper::_PopulateWeights() { // we don't want to fallback to the active selection if there is no sot diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/softSelectHelper.h b/lib/mayaUsd/render/pxrUsdMayaGL/softSelectHelper.h index 2d90f14987..930eb1ef9e 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/softSelectHelper.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/softSelectHelper.h @@ -44,7 +44,7 @@ PXR_NAMESPACE_OPEN_SCOPE /// While this class doesn't have anything particular to rendering, it is only /// used by the render and is therefore here. We can move this to usdMaya if /// we'd like to use it outside of the rendering. -class UsdMayaGLSoftSelectHelper +class UsdMayaGLSoftSelectHelper { public: MAYAUSD_CORE_PUBLIC @@ -59,7 +59,7 @@ class UsdMayaGLSoftSelectHelper void Populate(); /// \brief Returns true if \p dagPath is in the softSelection. Also returns - /// the \p weight. + /// the \p weight. /// /// NOTE: until MAYA-73448 (and MAYA-73513) is fixed, the \p weight value is /// arbitrary. diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp index dc57041b66..dde5db18f2 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp @@ -112,7 +112,7 @@ PxrMayaHdUsdProxyShapeAdapter::_Sync( MProfiler::kColorE_L2, "USD Proxy Shape Syncing Shape Adapter"); - MayaUsdProxyShapeBase* usdProxyShape = + MayaUsdProxyShapeBase* usdProxyShape = MayaUsdProxyShapeBase::GetShapeAtDagPath(shapeDagPath); if (!usdProxyShape) { TF_DEBUG(PXRUSDMAYAGL_SHAPE_ADAPTER_LIFECYCLE).Msg( diff --git a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h index 0831d1ee94..58f5395138 100644 --- a/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h +++ b/lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.h @@ -80,7 +80,7 @@ class PxrMayaHdUsdProxyShapeAdapter : public PxrMayaHdShapeAdapter /// Gets whether the shape adapter's shape is visible. /// /// This should be called after a call to UpdateVisibility() to ensure - /// that the returned value is correct. + /// that the returned value is correct. MAYAUSD_CORE_PUBLIC bool IsVisible() const override;