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-691 : Move mayaUsd code for managing stages inside mayaHydra #38

Merged
merged 26 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ab5fa06
HYDRA-691 : Move mayaUsd code for manging stages inside mayHydra
lanierd-adsk Jan 12, 2024
40facc0
Fixes from Sean code review.
lanierd-adsk Jan 16, 2024
cdec922
HYDRA-691 : Modifications from code review
lanierd-adsk Jan 19, 2024
652bc7a
Rename find MAYAUSD module
lanierd-adsk Jan 19, 2024
3a8af36
Use MayaUsd name instead of MAYAUSD
lanierd-adsk Jan 22, 2024
8139e6d
Fix config problem.
lanierd-adsk Jan 22, 2024
7e072cc
Fix location passed from python to cmake removing backslashes
lanierd-adsk Jan 22, 2024
b378b2e
Try to fix build cmake
lanierd-adsk Jan 23, 2024
a5832e0
Attempt in fixing compilation problem.
lanierd-adsk Jan 23, 2024
fb0d37e
Revert "Attempt in fixing compilation problem."
lanierd-adsk Jan 23, 2024
bd26758
Try to fix compilation when using mayaUsd.
lanierd-adsk Jan 23, 2024
9a6df1c
Attempt in fixing compilation.
lanierd-adsk Jan 24, 2024
4ba3a09
Fix OSX compile
lanierd-adsk Jan 24, 2024
168d09f
fix a bug found by flowviewportAPI tests.
lanierd-adsk Jan 24, 2024
8071d12
Increase image diff threshold.
lanierd-adsk Jan 24, 2024
fd44b97
Test for mayausdAPI is required only if it was found during compile t…
lanierd-adsk Jan 25, 2024
73d8280
Add testMayaUsdAPIUsage only if the lib is found during compile time.
lanierd-adsk Jan 25, 2024
904d9dc
Revert "fix a bug found by flowviewportAPI tests."
lanierd-adsk Jan 25, 2024
27b9a7a
Fix a problem when switching back and forth from Hydra to VP2.
lanierd-adsk Jan 26, 2024
7a7afb1
Fixes from code review from Sean.
lanierd-adsk Jan 26, 2024
547153b
Fix MayaUsd_FOUND not being written correctly.
lanierd-adsk Jan 26, 2024
9daac45
Fixed MayaUsd wrongly written.
lanierd-adsk Jan 26, 2024
695a97b
Update from code review.
lanierd-adsk Jan 29, 2024
f84fa74
Escape ; for Windows.
lanierd-adsk Jan 29, 2024
e784335
Changes from code review.
lanierd-adsk Feb 2, 2024
f041028
Merge branch 'dev' into lanierd/HYDRA-691
lanierd-adsk Feb 2, 2024
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ else()
message(STATUS "UFE not found.")
endif()

find_package(MayaUsd OPTIONAL_COMPONENTS)
find_package(MayaUsd)
if(MayaUsd_FOUND)
message(STATUS "Building with MayaUsd.")
else()
Expand Down
43 changes: 7 additions & 36 deletions cmake/modules/FindMayaUsd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# It searches for MayaUsd's libraries and include header files.
#
# Variables that will be defined:
# MAYAUSD_FOUND Defined if a MayaUsd installation has been detected
# MAYAUSD_LIBRARY_DIR Path to MayaUsd libraries directory
# MayaUsd_FOUND Defined if a MayaUsd installation has been detected
# MAYAUSD_INCLUDE_DIR Path to the MayaUsd include directory
# MAYAUSDAPI_LIBRARY Path to MayaUsdAPI library
# MAYAUSD_MOD_PATH Path to mayaUSD.mod file
Expand All @@ -22,23 +21,11 @@ find_path(MAYAUSD_INCLUDE_DIR
"MayaUsd header path"
)

find_path(MAYAUSD_LIBRARY_DIR
mayaUsd.lib
HINTS
${MAYAUSD_LOCATION}
PATH_SUFFIXES
lib/
DOC
"MayaUsd libraries path"
)

find_library(MAYAUSDAPI_LIBRARY
NAMES
mayaUsdAPI
HINTS
${MAYAUSD_LOCATION}
PATHS
${MAYAUSD_LIBRARY_DIR}
PATH_SUFFIXES
lib/
DOC
Expand All @@ -55,36 +42,20 @@ find_path(MAYAUSD_MOD_PATH
)


# Handle the QUIETLY and REQUIRED arguments and set MAYAUSD_FOUND to TRUE if
# Handle the QUIETLY and REQUIRED arguments and set MayaUsd_FOUND to TRUE if
# all listed variables are TRUE.
include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(MAYAUSD
find_package_handle_standard_args(MayaUsd
REQUIRED_VARS
MAYAUSD_INCLUDE_DIR
MAYAUSD_LIBRARY_DIR
MAYAUSDAPI_LIBRARY
MAYAUSD_MOD_PATH
)

if(MAYAUSD_FOUND)
message(STATUS "MayaUsd found : ${MAYAUSD_LOCATION}")
if(MayaUsd_FOUND)
message(STATUS "MayaUsd include dir: ${MAYAUSD_INCLUDE_DIR}")
message(STATUS "MayaUsd libraries dir: ${MAYAUSD_LIBRARY_DIR}")
message(STATUS "MayaUsdAPI.lib fullpath : ${MAYAUSDAPI_LIBRARY}")
message(STATUS "MayaUsdAPI library fullpath : ${MAYAUSDAPI_LIBRARY}")
message(STATUS "MAYAUSD_MOD_PATH : ${MAYAUSD_MOD_PATH}")

#Add MAYAUSD_MOD_PATH (the path where maya USD .mod file is) to the MAYA_MODULE_PATH

# Get the current value of the environment variable
set(CURRENT_MAYA_MODULE_PATH $ENV{MAYA_MODULE_PATH})

# Append the new path to the current value
set(MAYA_MODULE_PATH "${CURRENT_MAYA_MODULE_PATH}:${MAYAUSD_MOD_PATH}")

# Export the new value to the environment
set(ENV{MAYA_MODULE_PATH} ${MAYA_MODULE_PATH})
else()
if(DEFINED MAYAUSD_LOCATION)
message(WARNING "Could not find MayaUsd library and include directories in the folder provided : ${MAYAUSD_LOCATION}")
endif()
endif()

17 changes: 17 additions & 0 deletions cmake/test.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
set(MAYA_USD_DIR ${CMAKE_CURRENT_SOURCE_DIR})

if(MayaUsd_FOUND)
#Add MAYAUSD_MOD_PATH (the path where maya USD .mod file is) to the MAYA_MODULE_PATH
# Get the current value of the environment variable
set(CURRENT_MAYA_MODULE_PATH $ENV{MAYA_MODULE_PATH})
# Append the new path to the current value
if(IS_MACOSX OR IS_LINUX)
#Linux and OSX
set(MAYA_MODULE_PATH "${CURRENT_MAYA_MODULE_PATH}:${MAYAUSD_MOD_PATH}")
else()
#Windows
set(MAYA_MODULE_PATH "${CURRENT_MAYA_MODULE_PATH}\;${MAYAUSD_MOD_PATH}")
endif()
# Export the new value to the environment
set(ENV{MAYA_MODULE_PATH} ${MAYA_MODULE_PATH})
message(STATUS "MAYA_MODULE_PATH is now : ${MAYA_MODULE_PATH}")
endif()

function(mayaUsd_get_unittest_target unittest_target unittest_basename)
get_filename_component(unittest_name ${unittest_basename} NAME_WE)
set(${unittest_target} "${unittest_name}" PARENT_SCOPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,10 @@ void DataProducerSceneIndexInterfaceImp::setSceneIndexDataFactory(DataProducerSc
sceneIndexDataFactory = &factory;
}

void DataProducerSceneIndexInterfaceImp::ClearDataProducerSceneIndicesThatApplyToAllViewports()
{
std::lock_guard<std::mutex> lockDataProducerSceneIndicesDataPerViewport(dataProducerSceneIndicesThatApplyToAllViewports_mutex);
dataProducerSceneIndicesThatApplyToAllViewports.clear();
}

} //End of namespace FVP_NS_DEF
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class DataProducerSceneIndexInterfaceImp : public DataProducerSceneIndexInterfac
const std::string& hydraViewportId = PXR_NS::FvpViewportAPITokens->allViewports)override;


FVP_API void ClearDataProducerSceneIndicesThatApplyToAllViewports();

//Called by flow viewport
///hydraViewportSceneIndexAdded is called when a new hydra viewport is created by the ViewportInformationAndSceneIndicesPerViewportDataManager, it's not a callback.
void hydraViewportSceneIndexAdded(const InformationInterface::ViewportInformation& viewportInfo);
Expand Down
6 changes: 3 additions & 3 deletions lib/mayaHydra/hydraExtensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ set(HEADERS
target_compile_definitions(${TARGET_NAME}
PRIVATE
MAYAHYDRALIB_EXPORT
$<$<BOOL:${MAYAUSDAPI_LIBRARY}>:MAYAHYDRALIB_MAYAUSDAPI_ENABLED>
$<$<BOOL:${MayaUsd_FOUND}>:MAYAHYDRALIB_MAYAUSDAPI_ENABLED>
$<$<BOOL:${IS_MACOSX}>:OSMac_>
# Copy-pasted from lib/mayaUsd/CMakeLists.txt
)
Expand All @@ -52,7 +52,7 @@ target_include_directories(${TARGET_NAME}
${CMAKE_BINARY_DIR}/include
PRIVATE
$<$<BOOL:${UFE_FOUND}>:${UFE_INCLUDE_DIR}>
$<$<BOOL:${MAYAUSDAPI_LIBRARY}>:${MAYAUSD_INCLUDE_DIR}>
$<$<BOOL:${MayaUsd_FOUND}>:${MAYAUSD_INCLUDE_DIR}>
)

target_compile_definitions(${TARGET_NAME}
Expand Down Expand Up @@ -123,7 +123,7 @@ target_link_libraries(${TARGET_NAME}
$<$<BOOL:${USD_001905_BUILD}>:hio>
${PYTHON_LIBRARIES}
$<$<BOOL:${UFE_FOUND}>:${UFE_LIBRARY}>
$<$<BOOL:${MAYAUSDAPI_LIBRARY}>:${MAYAUSDAPI_LIBRARY}>
$<$<BOOL:${MayaUsd_FOUND}>:${MAYAUSDAPI_LIBRARY}>
)

# -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ MayaUsdProxyShapeSceneIndex::MayaUsdProxyShapeSceneIndex(const MAYAUSDAPI_NS::Pr
, _dagNodeHandle(dagNodeHandle)
{
TfWeakPtr<MayaUsdProxyShapeSceneIndex> ptr(this);
TfNotice::Register(ptr, &MayaUsdProxyShapeSceneIndex::_StageSet);
TfNotice::Register(ptr, &MayaUsdProxyShapeSceneIndex::_ObjectsChanged);
_stageSetNoticeKey = TfNotice::Register(ptr, &MayaUsdProxyShapeSceneIndex::_StageSet);
_objectsChangedNoticeKey = TfNotice::Register(ptr, &MayaUsdProxyShapeSceneIndex::_ObjectsChanged);

_timeChangeCallbackId = MEventMessage::addEventCallback("timeChanged", onTimeChanged, this);
}

MayaUsdProxyShapeSceneIndex::~MayaUsdProxyShapeSceneIndex()
{
MMessage::removeCallback(_timeChangeCallbackId);
TfNotice::Revoke(_stageSetNoticeKey);
TfNotice::Revoke(_objectsChangedNoticeKey);
}

MayaUsdProxyShapeSceneIndexRefPtr MayaUsdProxyShapeSceneIndex::New(const MAYAUSDAPI_NS::ProxyStage& proxyStage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class MayaUsdProxyShapeSceneIndex : public HdSingleInputFilteringSceneIndexBase
std::atomic<bool> _populated { false };
MCallbackId _timeChangeCallbackId = 0;
MObjectHandle _dagNodeHandle;
TfNotice::Key _stageSetNoticeKey;
TfNotice::Key _objectsChangedNoticeKey;
};

} // namespace MAYAHYDRA_NS_DEF
Expand Down
23 changes: 16 additions & 7 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ MtohRenderOverride::~MtohRenderOverride()
if (_timerCallback)
MMessage::removeCallback(_timerCallback);

ClearHydraResources();
static const bool fullReset = true;
ClearHydraResources(fullReset);

for (auto operation : _operations) {
delete operation;
Expand Down Expand Up @@ -549,7 +550,8 @@ MStatus MtohRenderOverride::Render(

_DetectMayaDefaultLighting(drawContext);
if (_needsClear.exchange(false)) {
ClearHydraResources();
static const bool fullReset = false;
ClearHydraResources(fullReset);
}

if (!_initializationAttempted) {
Expand Down Expand Up @@ -808,7 +810,7 @@ void MtohRenderOverride::_InitHydraResources(const MHWRender::MDrawContext& draw
_initializationSucceeded = true;
}

void MtohRenderOverride::ClearHydraResources()
void MtohRenderOverride::ClearHydraResources(bool fullReset)
{
if (!_initializationAttempted) {
return;
Expand All @@ -820,6 +822,13 @@ void MtohRenderOverride::ClearHydraResources()
//We don't have any viewport using Hydra any more
Fvp::ViewportInformationAndSceneIndicesPerViewportDataManager::Get().RemoveAllViewportsInformation();

if (fullReset){
//Remove the data producer scene indices that apply to all viewports
Fvp::DataProducerSceneIndexInterfaceImp::get().ClearDataProducerSceneIndicesThatApplyToAllViewports();
//Remove the scene index registry
_sceneIndexRegistry.reset();
}

_mayaHydraSceneProducer.reset();
_selectionSceneIndex.Reset();
_selection.reset();
Expand All @@ -845,8 +854,6 @@ void MtohRenderOverride::ClearHydraResources()
_rendererPlugin = nullptr;
}

_sceneIndexRegistry.reset();

//Decrease ref count on the render index proxy which owns the merging scene index at the end of this function as some previous calls may likely use it to remove some scene indices
_renderIndexProxy.reset();

Expand Down Expand Up @@ -894,7 +901,8 @@ void MtohRenderOverride::_RemovePanel(MString panelName)
}

if (_renderPanelCallbacks.empty()) {
ClearHydraResources();
static const bool fullReset = false;
ClearHydraResources(fullReset);
}
}

Expand Down Expand Up @@ -1265,7 +1273,8 @@ void MtohRenderOverride::_ClearHydraCallback(void* data)
if (!TF_VERIFY(instance)) {
return;
}
instance->ClearHydraResources();
static const bool fullReset = true;
instance->ClearHydraResources(fullReset);
}

void MtohRenderOverride::_PlayblastingChanged(bool playBlasting, void* userData)
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaHydra/mayaPlugin/renderOverride.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class MtohRenderOverride : public MHWRender::MRenderOverride
const MHWRender::MDrawContext& drawContext,
const MHWRender::MDataServerOperation::MViewportScene& scene);

void ClearHydraResources();
void ClearHydraResources(bool fullReset);
void SelectionChanged(const Ufe::SelectionChanged& notification);
void SetRenderPurposeTags(const MayaHydraParams& delegateParams) { _SetRenderPurposeTags(delegateParams); };
MString uiName() const override { return MString(_rendererDesc.displayName.GetText()); }
Expand Down
6 changes: 3 additions & 3 deletions test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ set(TEST_SCRIPT_FILES
cpp/testFlowViewportAPIFilterPrims.py
)

#Add this test only if the MAYAUSDAPI_LIBRARY has been found during compile time.
if(MAYAUSDAPI_LIBRARY)
#Add this test only if the MayaUsd_FOUND (so also MAYAUSDAPI_LIBRARY) has been found during compile time.
if(MayaUsd_FOUND)
list(APPEND TEST_SCRIPT_FILES testMayaUsdAPIUsage.py)
endif(MAYAUSDAPI_LIBRARY)
endif(MayaUsd_FOUND)

# Test use of mesh adapter code for mesh support, using environment variable.
# As of 13-Jun-2023, if a test in this list is identical to a test in
Expand Down
Loading