From 184ab41ba588c4ec1590eb6e715e8a4c61fcc870 Mon Sep 17 00:00:00 2001 From: David Lanier Date: Wed, 23 Aug 2023 10:37:11 +0200 Subject: [PATCH 1/3] HYDRA-472 : Fix the scene indices chain used for Maya Hydra, for USD 23.08 and 23.11+. Including the code changes from another PR : https://github.com/Autodesk/maya-usd/pull/3275. --- .../sceneIndex/proxyShapeSceneIndexPlugin.cpp | 158 +++++++++++++++--- 1 file changed, 131 insertions(+), 27 deletions(-) diff --git a/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp b/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp index ab39d673dc..451844bc7b 100644 --- a/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp +++ b/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp @@ -23,27 +23,35 @@ #include -#include -#if defined(HD_API_VERSION) && HD_API_VERSION >= 51 -#include -#else -#include -#endif #include -#include -#include -#include -#include -#if PXR_VERSION >= 2302 -#include //For USD 2302 and later -#include -#include + +#if USD_IMAGING_API_VERSION >= 20 //For USD 23.11+ + #include #else -#include -#include //For USD 2211 -#endif -#if defined(HD_API_VERSION) && HD_API_VERSION >= 54 -#include + #include + #if defined(HD_API_VERSION) && HD_API_VERSION >= 51 + #include + #else + #include + #endif + #include + #include + #include + #include + #include + #include + #if PXR_VERSION >= 2302 + #include //For USD 2302 and later + #include //For USD 2302 and later + #include + #include + #else + #include + #include //For USD 2211 + #endif + #if defined(HD_API_VERSION) && HD_API_VERSION >= 54 + #include + #endif #endif #include @@ -121,18 +129,26 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn auto proxyShape = dynamic_cast(dependNodeFn.userNode()); if (TF_VERIFY(proxyShape, "Error getting MayaUsdProxyShapeBase")) { +#if USD_IMAGING_API_VERSION >= 20 //For USD 23.11+ + UsdImagingCreateSceneIndicesInfo createInfo; + UsdImagingSceneIndices sceneIndices = UsdImagingCreateSceneIndices(createInfo); + + return MayaUsd::MayaUsdProxyShapeSceneIndex::New( + proxyShape, sceneIndices.finalSceneIndex, sceneIndices.stageSceneIndex); +#else + // We already have PXR_VERSION >= 2211 #if PXR_VERSION < 2302 // So for 2211 auto usdImagingStageSceneIndex = UsdImagingStageSceneIndex::New(); - HdSceneIndexBaseRefPtr _sceneIndex = UsdImagingGLDrawModeSceneIndex::New( + HdSceneIndexBaseRefPtr sceneIndex = UsdImagingGLDrawModeSceneIndex::New( HdFlatteningSceneIndex::New( HdInstancedBySceneIndex::New(usdImagingStageSceneIndex)), /* inputArgs = */ nullptr); #else + //For PXR_VERSION >= 2302 so for USD 22.11+ #if defined(HD_API_VERSION) && HD_API_VERSION >= 54 using namespace HdMakeDataSourceContainingFlattenedDataSourceProvider; #endif - // For PXR_VERSION >= 2302 // Used for the HdFlatteningSceneIndex to flatten material bindings static const HdContainerDataSourceHandle flatteningInputArgs = HdRetainedContainerDataSource::New( @@ -147,27 +163,115 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn HdRetainedTypedSampledDataSource::New(true)); #endif +#if PXR_VERSION < 2308 // Convert USD prims to rprims consumed by Hydra auto usdImagingStageSceneIndex = UsdImagingStageSceneIndex::New(); // Flatten transforms, visibility, purpose, model, and material // bindings over hierarchies. // Do it the same way as USDView does with a SceneIndices chain - HdSceneIndexBaseRefPtr _sceneIndex + HdSceneIndexBaseRefPtr sceneIndex = UsdImagingPiPrototypePropagatingSceneIndex::New(usdImagingStageSceneIndex); - _sceneIndex = UsdImagingNiPrototypePropagatingSceneIndex::New(_sceneIndex); + + sceneIndex = UsdImagingNiPrototypePropagatingSceneIndex::New(sceneIndex); // The native prototype propagating scene index does a lot of // the flattening before inserting copies of the the prototypes // into the scene index. However, the resolved material for a prim // coming from a USD prototype can depend on the prim ancestors of // a corresponding instance. So we need to do one final resolve here. - _sceneIndex = HdFlatteningSceneIndex::New(_sceneIndex, flatteningInputArgs); - _sceneIndex = UsdImagingDrawModeSceneIndex::New(_sceneIndex, /* inputArgs = */ nullptr); -#endif + sceneIndex = HdFlatteningSceneIndex::New(sceneIndex, flatteningInputArgs); + sceneIndex = UsdImagingDrawModeSceneIndex::New(sceneIndex, /* inputArgs = */ nullptr); +#else + //#For USD 23.08 and later, HD_API_VERSION=54 in USD 23.08 + static const bool _displayUnloadedPrimsWithBounds = true; + + HdContainerDataSourceHandle const stageInputArgs = + HdRetainedContainerDataSource::New( + UsdImagingStageSceneIndexTokens->includeUnloadedPrims, + HdRetainedTypedSampledDataSource::New( + _displayUnloadedPrimsWithBounds)); + + // Create the scene index graph. + sceneIndex = _stageSceneIndex = + UsdImagingStageSceneIndex::New(stageInputArgs); + + static HdContainerDataSourceHandle const materialPruningInputArgs = + HdRetainedContainerDataSource::New( + HdsiPrimTypePruningSceneIndexTokens->primTypes, + HdRetainedTypedSampledDataSource::New( + { HdPrimTypeTokens->material }), + HdsiPrimTypePruningSceneIndexTokens->bindingToken, + HdRetainedTypedSampledDataSource::New( + HdMaterialBindingsSchema::GetSchemaToken())); + + // Prune scene materials prior to flattening inherited + // materials bindings and resolving material bindings + sceneIndex = _materialPruningSceneIndex = + HdsiPrimTypePruningSceneIndex::New( + sceneIndex, materialPruningInputArgs); + + static HdContainerDataSourceHandle const lightPruningInputArgs = + HdRetainedContainerDataSource::New( + HdsiPrimTypePruningSceneIndexTokens->primTypes, + HdRetainedTypedSampledDataSource::New( + HdLightPrimTypeTokens()), + HdsiPrimTypePruningSceneIndexTokens->doNotPruneNonPrimPaths, + HdRetainedTypedSampledDataSource::New( + false)); + + sceneIndex = _lightPruningSceneIndex = + HdsiPrimTypePruningSceneIndex::New( + sceneIndex, lightPruningInputArgs); + + // Use extentsHint for default_/geometry purpose + HdContainerDataSourceHandle const extentInputArgs = + HdRetainedContainerDataSource::New( + UsdGeomTokens->purpose, + HdRetainedTypedSampledDataSource::New( + UsdGeomTokens->default_)); + + sceneIndex = + UsdImagingExtentResolvingSceneIndex::New( + sceneIndex, extentInputArgs); + + if (_displayUnloadedPrimsWithBounds) { + sceneIndex = + UsdImagingUnloadedDrawModeSceneIndex::New(sceneIndex); + } + + sceneIndex = _rootOverridesSceneIndex = + UsdImagingRootOverridesSceneIndex::New(sceneIndex); + + sceneIndex = + UsdImagingPiPrototypePropagatingSceneIndex::New(sceneIndex); + + sceneIndex = + UsdImagingNiPrototypePropagatingSceneIndex::New(sceneIndex); + + sceneIndex = _selectionSceneIndex = + UsdImagingSelectionSceneIndex::New(sceneIndex); + + sceneIndex = + UsdImagingRenderSettingsFlatteningSceneIndex::New(sceneIndex); + + sceneIndex = + HdFlatteningSceneIndex::New( + sceneIndex, UsdImagingFlattenedDataSourceProviders()); + + sceneIndex = + UsdImagingDrawModeSceneIndex::New(sceneIndex, + /* inputArgs = */ nullptr); + + sceneIndex = _displayStyleSceneIndex = + HdsiLegacyDisplayStyleOverrideSceneIndex::New(sceneIndex); + +#endif //End of #if PXR_VERSION < 2308 block +#endif //end of #if PXR_VERSION < 2302 block return MayaUsd::MayaUsdProxyShapeSceneIndex::New( - proxyShape, _sceneIndex, usdImagingStageSceneIndex); + proxyShape, sceneIndex, usdImagingStageSceneIndex); +#endif //End of #else clause of if USD_IMAGING_API_VERSION >= 20 block } } From caced77d057616e92f5ac0a0cf4a8dcbcb71181f Mon Sep 17 00:00:00 2001 From: David Lanier Date: Wed, 23 Aug 2023 15:53:09 +0200 Subject: [PATCH 2/3] Apply clang-format. --- .../sceneIndex/proxyShapeSceneIndexPlugin.cpp | 145 ++++++++---------- 1 file changed, 64 insertions(+), 81 deletions(-) diff --git a/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp b/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp index 451844bc7b..cd86e15336 100644 --- a/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp +++ b/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp @@ -25,33 +25,33 @@ #include -#if USD_IMAGING_API_VERSION >= 20 //For USD 23.11+ - #include +#if USD_IMAGING_API_VERSION >= 20 // For USD 23.11+ +#include #else - #include - #if defined(HD_API_VERSION) && HD_API_VERSION >= 51 - #include - #else - #include - #endif - #include - #include - #include - #include - #include - #include - #if PXR_VERSION >= 2302 - #include //For USD 2302 and later - #include //For USD 2302 and later - #include - #include - #else - #include - #include //For USD 2211 - #endif - #if defined(HD_API_VERSION) && HD_API_VERSION >= 54 - #include - #endif +#include +#if defined(HD_API_VERSION) && HD_API_VERSION >= 51 +#include +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#if PXR_VERSION >= 2302 +#include //For USD 2302 and later +#include //For USD 2302 and later +#include +#include +#else +#include +#include //For USD 2211 +#endif +#if defined(HD_API_VERSION) && HD_API_VERSION >= 54 +#include +#endif #endif #include @@ -129,10 +129,10 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn auto proxyShape = dynamic_cast(dependNodeFn.userNode()); if (TF_VERIFY(proxyShape, "Error getting MayaUsdProxyShapeBase")) { -#if USD_IMAGING_API_VERSION >= 20 //For USD 23.11+ +#if USD_IMAGING_API_VERSION >= 20 // For USD 23.11+ UsdImagingCreateSceneIndicesInfo createInfo; UsdImagingSceneIndices sceneIndices = UsdImagingCreateSceneIndices(createInfo); - + return MayaUsd::MayaUsdProxyShapeSceneIndex::New( proxyShape, sceneIndices.finalSceneIndex, sceneIndices.stageSceneIndex); #else @@ -145,7 +145,7 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn HdInstancedBySceneIndex::New(usdImagingStageSceneIndex)), /* inputArgs = */ nullptr); #else - //For PXR_VERSION >= 2302 so for USD 22.11+ + // For PXR_VERSION >= 2302 so for USD 22.11+ #if defined(HD_API_VERSION) && HD_API_VERSION >= 54 using namespace HdMakeDataSourceContainingFlattenedDataSourceProvider; #endif @@ -186,18 +186,15 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn //#For USD 23.08 and later, HD_API_VERSION=54 in USD 23.08 static const bool _displayUnloadedPrimsWithBounds = true; - HdContainerDataSourceHandle const stageInputArgs = - HdRetainedContainerDataSource::New( + HdContainerDataSourceHandle const stageInputArgs = HdRetainedContainerDataSource::New( UsdImagingStageSceneIndexTokens->includeUnloadedPrims, - HdRetainedTypedSampledDataSource::New( - _displayUnloadedPrimsWithBounds)); + HdRetainedTypedSampledDataSource::New(_displayUnloadedPrimsWithBounds)); // Create the scene index graph. - sceneIndex = _stageSceneIndex = - UsdImagingStageSceneIndex::New(stageInputArgs); + sceneIndex = _stageSceneIndex = UsdImagingStageSceneIndex::New(stageInputArgs); - static HdContainerDataSourceHandle const materialPruningInputArgs = - HdRetainedContainerDataSource::New( + static HdContainerDataSourceHandle const materialPruningInputArgs + = HdRetainedContainerDataSource::New( HdsiPrimTypePruningSceneIndexTokens->primTypes, HdRetainedTypedSampledDataSource::New( { HdPrimTypeTokens->material }), @@ -207,71 +204,57 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn // Prune scene materials prior to flattening inherited // materials bindings and resolving material bindings - sceneIndex = _materialPruningSceneIndex = - HdsiPrimTypePruningSceneIndex::New( - sceneIndex, materialPruningInputArgs); + sceneIndex = _materialPruningSceneIndex + = HdsiPrimTypePruningSceneIndex::New(sceneIndex, materialPruningInputArgs); - static HdContainerDataSourceHandle const lightPruningInputArgs = - HdRetainedContainerDataSource::New( + static HdContainerDataSourceHandle const lightPruningInputArgs + = HdRetainedContainerDataSource::New( HdsiPrimTypePruningSceneIndexTokens->primTypes, - HdRetainedTypedSampledDataSource::New( - HdLightPrimTypeTokens()), + HdRetainedTypedSampledDataSource::New(HdLightPrimTypeTokens()), HdsiPrimTypePruningSceneIndexTokens->doNotPruneNonPrimPaths, - HdRetainedTypedSampledDataSource::New( - false)); + HdRetainedTypedSampledDataSource::New(false)); - sceneIndex = _lightPruningSceneIndex = - HdsiPrimTypePruningSceneIndex::New( - sceneIndex, lightPruningInputArgs); + sceneIndex = _lightPruningSceneIndex + = HdsiPrimTypePruningSceneIndex::New(sceneIndex, lightPruningInputArgs); // Use extentsHint for default_/geometry purpose - HdContainerDataSourceHandle const extentInputArgs = - HdRetainedContainerDataSource::New( - UsdGeomTokens->purpose, - HdRetainedTypedSampledDataSource::New( - UsdGeomTokens->default_)); + HdContainerDataSourceHandle const extentInputArgs = HdRetainedContainerDataSource::New( + UsdGeomTokens->purpose, + HdRetainedTypedSampledDataSource::New(UsdGeomTokens->default_)); - sceneIndex = - UsdImagingExtentResolvingSceneIndex::New( - sceneIndex, extentInputArgs); + sceneIndex = UsdImagingExtentResolvingSceneIndex::New(sceneIndex, extentInputArgs); if (_displayUnloadedPrimsWithBounds) { - sceneIndex = - UsdImagingUnloadedDrawModeSceneIndex::New(sceneIndex); + sceneIndex = UsdImagingUnloadedDrawModeSceneIndex::New(sceneIndex); } - sceneIndex = _rootOverridesSceneIndex = - UsdImagingRootOverridesSceneIndex::New(sceneIndex); + sceneIndex = _rootOverridesSceneIndex + = UsdImagingRootOverridesSceneIndex::New(sceneIndex); - sceneIndex = - UsdImagingPiPrototypePropagatingSceneIndex::New(sceneIndex); - - sceneIndex = - UsdImagingNiPrototypePropagatingSceneIndex::New(sceneIndex); + sceneIndex = UsdImagingPiPrototypePropagatingSceneIndex::New(sceneIndex); - sceneIndex = _selectionSceneIndex = - UsdImagingSelectionSceneIndex::New(sceneIndex); + sceneIndex = UsdImagingNiPrototypePropagatingSceneIndex::New(sceneIndex); - sceneIndex = - UsdImagingRenderSettingsFlatteningSceneIndex::New(sceneIndex); + sceneIndex = _selectionSceneIndex = UsdImagingSelectionSceneIndex::New(sceneIndex); - sceneIndex = - HdFlatteningSceneIndex::New( - sceneIndex, UsdImagingFlattenedDataSourceProviders()); + sceneIndex = UsdImagingRenderSettingsFlatteningSceneIndex::New(sceneIndex); - sceneIndex = - UsdImagingDrawModeSceneIndex::New(sceneIndex, - /* inputArgs = */ nullptr); + sceneIndex + = HdFlatteningSceneIndex::New(sceneIndex, UsdImagingFlattenedDataSourceProviders()); + + sceneIndex = UsdImagingDrawModeSceneIndex::New( + sceneIndex, + /* inputArgs = */ nullptr); - sceneIndex = _displayStyleSceneIndex = - HdsiLegacyDisplayStyleOverrideSceneIndex::New(sceneIndex); + sceneIndex = _displayStyleSceneIndex + = HdsiLegacyDisplayStyleOverrideSceneIndex::New(sceneIndex); -#endif //End of #if PXR_VERSION < 2308 block -#endif //end of #if PXR_VERSION < 2302 block +#endif // End of #if PXR_VERSION < 2308 block +#endif // end of #if PXR_VERSION < 2302 block return MayaUsd::MayaUsdProxyShapeSceneIndex::New( proxyShape, sceneIndex, usdImagingStageSceneIndex); -#endif //End of #else clause of if USD_IMAGING_API_VERSION >= 20 block +#endif // End of #else clause of if USD_IMAGING_API_VERSION >= 20 block } } From 5776b39f2f718177ba646cf278b24583556d8948 Mon Sep 17 00:00:00 2001 From: David Lanier Date: Wed, 23 Aug 2023 18:28:19 +0200 Subject: [PATCH 3/3] Fix build errors for USD 23.08, also checked with USD 23.02. --- .../sceneIndex/proxyShapeSceneIndexPlugin.cpp | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp b/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp index cd86e15336..edfd17ae1b 100644 --- a/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp +++ b/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp @@ -42,7 +42,6 @@ #include #if PXR_VERSION >= 2302 #include //For USD 2302 and later -#include //For USD 2302 and later #include #include #else @@ -51,6 +50,14 @@ #endif #if defined(HD_API_VERSION) && HD_API_VERSION >= 54 #include +#include +#include +#include +#include +#include +#include +#include +#include #endif #endif @@ -146,7 +153,7 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn /* inputArgs = */ nullptr); #else // For PXR_VERSION >= 2302 so for USD 22.11+ -#if defined(HD_API_VERSION) && HD_API_VERSION >= 54 +#if defined(HD_API_VERSION) && HD_API_VERSION >= 54 // For USD 23.08+ using namespace HdMakeDataSourceContainingFlattenedDataSourceProvider; #endif // Used for the HdFlatteningSceneIndex to flatten material bindings @@ -157,7 +164,7 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn #else HdMaterialBindingSchemaTokens->materialBinding, #endif -#if defined(HD_API_VERSION) && HD_API_VERSION >= 54 +#if defined(HD_API_VERSION) && HD_API_VERSION >= 54 // For USD 23.08+ Make()); #else HdRetainedTypedSampledDataSource::New(true)); @@ -191,7 +198,8 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn HdRetainedTypedSampledDataSource::New(_displayUnloadedPrimsWithBounds)); // Create the scene index graph. - sceneIndex = _stageSceneIndex = UsdImagingStageSceneIndex::New(stageInputArgs); + auto usdImagingStageSceneIndex = UsdImagingStageSceneIndex::New(stageInputArgs); + HdSceneIndexBaseRefPtr sceneIndex = usdImagingStageSceneIndex; static HdContainerDataSourceHandle const materialPruningInputArgs = HdRetainedContainerDataSource::New( @@ -204,8 +212,7 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn // Prune scene materials prior to flattening inherited // materials bindings and resolving material bindings - sceneIndex = _materialPruningSceneIndex - = HdsiPrimTypePruningSceneIndex::New(sceneIndex, materialPruningInputArgs); + sceneIndex = HdsiPrimTypePruningSceneIndex::New(sceneIndex, materialPruningInputArgs); static HdContainerDataSourceHandle const lightPruningInputArgs = HdRetainedContainerDataSource::New( @@ -214,8 +221,7 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn HdsiPrimTypePruningSceneIndexTokens->doNotPruneNonPrimPaths, HdRetainedTypedSampledDataSource::New(false)); - sceneIndex = _lightPruningSceneIndex - = HdsiPrimTypePruningSceneIndex::New(sceneIndex, lightPruningInputArgs); + sceneIndex = HdsiPrimTypePruningSceneIndex::New(sceneIndex, lightPruningInputArgs); // Use extentsHint for default_/geometry purpose HdContainerDataSourceHandle const extentInputArgs = HdRetainedContainerDataSource::New( @@ -228,14 +234,13 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn sceneIndex = UsdImagingUnloadedDrawModeSceneIndex::New(sceneIndex); } - sceneIndex = _rootOverridesSceneIndex - = UsdImagingRootOverridesSceneIndex::New(sceneIndex); + sceneIndex = UsdImagingRootOverridesSceneIndex::New(sceneIndex); sceneIndex = UsdImagingPiPrototypePropagatingSceneIndex::New(sceneIndex); sceneIndex = UsdImagingNiPrototypePropagatingSceneIndex::New(sceneIndex); - sceneIndex = _selectionSceneIndex = UsdImagingSelectionSceneIndex::New(sceneIndex); + sceneIndex = UsdImagingSelectionSceneIndex::New(sceneIndex); sceneIndex = UsdImagingRenderSettingsFlatteningSceneIndex::New(sceneIndex); @@ -246,8 +251,7 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn sceneIndex, /* inputArgs = */ nullptr); - sceneIndex = _displayStyleSceneIndex - = HdsiLegacyDisplayStyleOverrideSceneIndex::New(sceneIndex); + sceneIndex = HdsiLegacyDisplayStyleOverrideSceneIndex::New(sceneIndex); #endif // End of #if PXR_VERSION < 2308 block #endif // end of #if PXR_VERSION < 2302 block