Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HYDRA-927 - Expose complexity settings in globalRenderSettings #106

Merged
merged 7 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/mayaHydra/hydraExtensions/mayaHydraParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct MayaHydraParams
float motionSampleStart = 0;
float motionSampleEnd = 0;
bool displaySmoothMeshes = true;
int refineLevel = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about the refineLevel which is adapters, MayaHydraAdapter::GetDisplayStyle().refineLevel > 0)
Is what you do replaces this ? Or is this something else ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume the added one is the global refine level, while the one in DisplayStyle is per-primitive, but it's not enabled yet due to MRenderItem was already refined. HdsiLegacyDisplayStyleOverrideSceneIndex can be used to override the per-primitive one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As far as I understand MayaHydraAdapter is used only for Maya native prims. The new scene index is supposed to be used only for USD prims. I will add "addExcludedSceneRoot" to it in my next commit to exclude Maya prims


bool motionSamplesEnabled() const { return motionSampleStart != 0 || motionSampleEnd != 0; }
};
Expand Down
33 changes: 33 additions & 0 deletions lib/mayaHydra/mayaPlugin/renderGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,15 @@ void MtohRenderGlobals::BuildOptionsMenu(
<< ", $fromAE);\n";
}

{
ss << "\tmtohRenderOverride_AddAttribute(" << quote(rendererDesc.rendererName.GetString())
<< ',' << quote("Refine level") << ',' // Description
<< quote(_MangleName(MtohTokens->mtohRefinementLevel).GetString())
<< ',' // Attribute name
<< quote(MtohTokens->mtohRefinementLevel.GetText()) // Label
<< ", $fromAE);\n";
}

// Temp solution to store global settings for USD Purpose tags
{
ss << "\tframeLayout -label \"Display Purpose\" -collapsable true;";
Expand Down Expand Up @@ -916,6 +925,20 @@ MObject MtohRenderGlobals::CreateAttributes(const GlobalParams& params)
return mayaObject;
}
}
if (filter(MtohTokens->mtohRefinementLevel)) {
_CreateIntAttribute(
node,
filter.mayaString(),
defGlobals.delegateParams.refineLevel,
userDefaults,
[](MFnNumericAttribute& nAttr) {
nAttr.setMin(0);
nAttr.setMax(8);
});
if (filter.attributeFilter()) {
return mayaObject;
}
}

for (const auto& rit : MtohGetRendererSettings()) {
const auto rendererName = rit.first;
Expand Down Expand Up @@ -1103,6 +1126,16 @@ MtohRenderGlobals::GetInstance(const GlobalParams& params, bool storeUserSetting
return globals;
}
}
if (filter(MtohTokens->mtohRefinementLevel)) {
_GetAttribute(
node,
filter.mayaString(),
globals.delegateParams.refineLevel,
storeUserSetting);
if (filter.attributeFilter()) {
return globals;
}
}

for (const auto& rit : MtohGetRendererSettings()) {
const auto rendererName = rit.first;
Expand Down
24 changes: 16 additions & 8 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ MStatus MtohRenderOverride::Render(
_mayaHydraSceneIndex->PreFrame(drawContext);
}

if (_displayStyleSceneIndex) {
vlasovi marked this conversation as resolved.
Show resolved Hide resolved
_displayStyleSceneIndex->SetRefineLevel({true, delegateParams.refineLevel});
}

HdxRenderTaskParams params;
params.enableLighting = true;
params.enableSceneMaterials = true;
Expand Down Expand Up @@ -742,7 +746,7 @@ MStatus MtohRenderOverride::Render(
if (_mayaHydraSceneIndex) {
_mayaHydraSceneIndex->PostFrame();
}

return MStatus::kSuccess;
}

Expand Down Expand Up @@ -831,7 +835,7 @@ void MtohRenderOverride::_InitHydraResources(const MHWRender::MDrawContext& draw

_mayaHydraSceneIndex = MayaHydraSceneIndex::New(mhInitData, !_hasDefaultLighting);
TF_VERIFY(_mayaHydraSceneIndex, "Maya Hydra scene index not found, check mayaHydra plugin installation.");

VtValue fvpSelectionTrackerValue(_fvpSelectionTracker);
_engine.SetTaskContextData(FvpTokens->fvpSelectionState, fvpSelectionTrackerValue);

Expand Down Expand Up @@ -884,15 +888,15 @@ void MtohRenderOverride::ClearHydraResources(bool fullReset)
_sceneIndexRegistry.reset();
}

#ifdef CODE_COVERAGE_WORKAROUND
// Leak the Maya scene index, as its base class HdRetainedSceneIndex
// destructor crashes under Windows clang code coverage build.
#ifdef CODE_COVERAGE_WORKAROUND
// Leak the Maya scene index, as its base class HdRetainedSceneIndex
// destructor crashes under Windows clang code coverage build.
_mayaHydraSceneIndex->RemoveCallbacksAndDeleteAdapters();
_mayaHydraSceneIndex.Reset();
#else
#else
_ClearMayaHydraSceneIndex();
#endif

#endif
_displayStyleSceneIndex = nullptr;
_selectionSceneIndex.Reset();
_selection.reset();

Expand Down Expand Up @@ -945,6 +949,10 @@ void MtohRenderOverride::_CreateSceneIndicesChainAfterMergingSceneIndex()
_sceneIndexRegistry.reset(new MayaHydraSceneIndexRegistry(_renderIndexProxy));
}

// Add display style scene index
vlasovi marked this conversation as resolved.
Show resolved Hide resolved
_lastFilteringSceneIndexBeforeCustomFiltering = _displayStyleSceneIndex =
HdsiLegacyDisplayStyleOverrideSceneIndex::New(_lastFilteringSceneIndexBeforeCustomFiltering);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe worth checking the perf impact (switch to Hydra/First Frame) after introducing this SceneIndex. We expect, by default, with refine level is 0, the overhead should be trivial

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lilike-adsk With refine level set to 0, I haven't noticed any performance impact of this change. The FPS maybe degraded with refine levels more than 0, but this is expected.


auto wfSi = TfDynamic_cast<Fvp::WireframeSelectionHighlightSceneIndexRefPtr>(Fvp::WireframeSelectionHighlightSceneIndex::New(_lastFilteringSceneIndexBeforeCustomFiltering, _selection));
wfSi->SetDisplayName("Flow Viewport Wireframe Selection Highlight Scene Index");

Expand Down
3 changes: 3 additions & 0 deletions lib/mayaHydra/mayaPlugin/renderOverride.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <pxr/imaging/hd/rendererPlugin.h>
#include <pxr/imaging/hd/rprimCollection.h>
#include <pxr/imaging/hd/pluginRenderDelegateUniqueHandle.h>
#include <pxr/imaging/hdsi/legacyDisplayStyleOverrideSceneIndex.h>
#include <pxr/imaging/hdSt/renderDelegate.h>
#include <pxr/imaging/hdx/taskController.h>
#include <pxr/pxr.h>
Expand Down Expand Up @@ -240,6 +241,8 @@ class MtohRenderOverride : public MHWRender::MRenderOverride
HdReprSelector(HdReprTokens->refined),
SdfPath::AbsoluteRootPath() };

HdsiLegacyDisplayStyleOverrideSceneIndexRefPtr _displayStyleSceneIndex;

HdRprimCollection _pointSnappingCollection {
HdTokens->geometry,
HdReprSelector(HdReprTokens->refined, TfToken(), HdReprTokens->points),
Expand Down
3 changes: 2 additions & 1 deletion lib/mayaHydra/mayaPlugin/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ PXR_NAMESPACE_OPEN_SCOPE
// clang-format off
#define MTOH_TOKENS \
(HdStormRendererPlugin) \
(mtohMaximumShadowMapResolution)
(mtohMaximumShadowMapResolution) \
(mtohRefinementLevel)
// clang-format on

// This is not an exported API.
Expand Down
1 change: 1 addition & 0 deletions test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(INTERACTIVE_TEST_SCRIPT_FILES
testSceneBrowser.py
testStageAddPrim.py
testTransforms.py
testRefinement.py
testMaterialXOnNative.py
testNewSceneWithStage.py
testMayaDisplayModes.py
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/testRefinement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2024 Autodesk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import maya.cmds as cmds

import fixturesUtils
import mtohUtils
import unittest
import testUtils

class TestRefinement(mtohUtils.MtohTestCase):
_file = __file__

IMAGEDIFF_FAIL_THRESHOLD = 0.01
IMAGEDIFF_FAIL_PERCENT = 0.1

def verifySnapshot(self, imageName):
cmds.refresh()
self.assertSnapshotClose(imageName,
self.IMAGEDIFF_FAIL_THRESHOLD,
self.IMAGEDIFF_FAIL_PERCENT)

@unittest.skipUnless(mtohUtils.checkForMayaUsdPlugin(), "Requires Maya USD Plugin.")
def test_usdPrim(self):
import usdUtils
usdScenePath = testUtils.getTestScene('testStagePayloadsReferences', 'cube.usda')
usdUtils.createStageFromFile(usdScenePath)

self.setBasicCam(1)
self.setHdStormRenderer()
cmds.mayaHydra(createRenderGlobals=1)

cmds.setAttr("defaultRenderGlobals.mtohRefinementLevel", 0)
cmds.mayaHydra(updateRenderGlobals="mtohRefinementLevel")
self.verifySnapshot("usd_cube_refined_0.png")

cmds.setAttr("defaultRenderGlobals.mtohRefinementLevel", 2)
cmds.mayaHydra(updateRenderGlobals="mtohRefinementLevel")
self.verifySnapshot("usd_cube_refined_2.png")

cmds.setAttr("defaultRenderGlobals.mtohRefinementLevel", 4)
cmds.mayaHydra(updateRenderGlobals="mtohRefinementLevel")
self.verifySnapshot("usd_cube_refined_4.png")

#restore the default
cmds.setAttr("defaultRenderGlobals.mtohRefinementLevel", 0)
cmds.mayaHydra(updateRenderGlobals="mtohRefinementLevel")

if __name__ == '__main__':
fixturesUtils.runTests(globals())