From 5454a9e5853d34cdd2e2e47e133c999c3bc8eb4b Mon Sep 17 00:00:00 2001 From: cpichard Date: Thu, 25 Jan 2024 14:03:41 +0000 Subject: [PATCH] Merge branch fix-7.2.5 20240125 (#1831) * Update tests after arnold changes on curves (#1766) (cherry picked from commit 2fcc262f3e52deb35685937847171b6dd104973c) * Fix the incorrect orientation of the PointInstancer instances in the render delegate (#1777) * add test for #1776 * Initialize the rotation matrix with the quad directly * update changelog for #1776 * Fix changelog for 7.2.5 release (#1788) * More changelog fixes * handle vertex interpolated uvs on bspline curves (#1792) * FIx the error "Cannot load _htoa_pygeo library required for volume rendering in Solaris" (#1811) * Improve material network creation times by caching the nodes returned by Arnold (#1813) * Improve material network creation by caching the nodes returned by arnold * optimize further by first checking if the shader is an arnold shader * move shader node entry and osl code cache in the render delegate and use lock/mutex * cache materialx nodes only * Fix build with older versions of arnold (#1820) * fix build with older versions of arnold * fix compatibility with older versions of arnold * convert AtString to string * allow materialx for versions > 7.1.4 * fix ifdef versions for materialx * compatibility with older arnold versions * update changelog for fix-7.2.5.0 (#1827) * Fix crash happening in maya aiStandin when scrolling the timeline (#1830) * make the UsdArnoldReaderRegistry non static * register readers before reading --------- Co-authored-by: Sebastien Blaineau-Ortega --- CHANGELOG.md | 1 + libs/translator/reader/reader.cpp | 47 +++++++++++++------------------ libs/translator/reader/reader.h | 24 ++++------------ 3 files changed, 26 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 534d227ae6..2d738cf9ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - [usd#1808](https://github.com/Autodesk/arnold-usd/issues/1808) - Fix the error "Cannot load _htoa_pygeo library required for volume rendering in Solaris" in Houdini 19.5+. - [usd#1812](https://github.com/Autodesk/arnold-usd/issues/1812) - Improve Material network creation by caching the node entries and the osl code. +- [usd#1781](https://github.com/Autodesk/arnold-usd/issues/1781) - Fix a crash happening in a aiStandin usd when scrolling the timeline in maya. ## [7.2.5.1] - 2024-01-18 diff --git a/libs/translator/reader/reader.cpp b/libs/translator/reader/reader.cpp index 3d6ccf80c6..3bc0b1932c 100644 --- a/libs/translator/reader/reader.cpp +++ b/libs/translator/reader/reader.cpp @@ -83,22 +83,27 @@ namespace { WorkDispatcher *dispatcher; }; }; -// global reader registry, will be used in the default case -static UsdArnoldReaderRegistry *s_readerRegistry = nullptr; -static int s_mustDeleteRegistry = 0; + static AtMutex s_globalReaderMutex; static std::unordered_map s_cacheRefCount; - +UsdArnoldReader::UsdArnoldReader() + : _procParent(nullptr), + _universe(nullptr), + _convert(true), + _debug(false), + _threadCount(1), + _mask(AI_NODE_ALL), + _defaultShader(nullptr), + _hasRootPrim(false), + _readStep(READ_NOT_STARTED), + _purpose(UsdGeomTokens->render), + _dispatcher(nullptr), + _readerRegistry(new UsdArnoldReaderRegistry()) + {} UsdArnoldReader::~UsdArnoldReader() { - if (s_mustDeleteRegistry && _registry) { - delete _registry; - s_mustDeleteRegistry = false; - _registry = s_readerRegistry; - } - // What do we want to do at destruction here ? - // Should we delete the created nodes in case there was no procParent ? + delete _readerRegistry; } void UsdArnoldReader::TraverseStage(UsdPrim *rootPrim, UsdArnoldReaderContext &context, @@ -291,19 +296,7 @@ void UsdArnoldReader::ReadStage(UsdStageRefPtr stage, const std::string &path) // and the eventual procedural mask set above _mask = _mask & procMask; - // eventually use a dedicated registry - if (_registry == nullptr) { - // No registry was set (default), let's use the global one - { - std::lock_guard guard(s_globalReaderMutex); - if (s_readerRegistry == nullptr) { - s_readerRegistry = new UsdArnoldReaderRegistry(); // initialize the global registry - s_readerRegistry->RegisterPrimitiveReaders(); - } - } - _registry = s_readerRegistry; - } else - _registry->RegisterPrimitiveReaders(); + _readerRegistry->RegisterPrimitiveReaders(); UsdPrim *rootPrimPtr = nullptr; @@ -609,7 +602,7 @@ void UsdArnoldReader::ReadPrimitive(const UsdPrim &prim, UsdArnoldReaderContext _renderSettings = objName; } - UsdArnoldPrimReader *primReader = _registry->GetPrimReader(objType); + UsdArnoldPrimReader *primReader = _readerRegistry->GetPrimReader(objType); if (primReader && (_mask & primReader->GetType())) { if (_debug) { std::string txt; @@ -706,8 +699,8 @@ void UsdArnoldReader::SetProceduralParent(AtNode *node) } void UsdArnoldReader::CreateViewportRegistry(AtProcViewportMode mode, const AtParamValueMap* params) { - s_mustDeleteRegistry = true; - _registry = new UsdArnoldViewportReaderRegistry(mode, params); + delete _readerRegistry; + _readerRegistry = new UsdArnoldViewportReaderRegistry(mode, params); } void UsdArnoldReader::SetUniverse(AtUniverse *universe) diff --git a/libs/translator/reader/reader.h b/libs/translator/reader/reader.h index cefd3bd84e..ce9971b91f 100644 --- a/libs/translator/reader/reader.h +++ b/libs/translator/reader/reader.h @@ -47,21 +47,7 @@ class UsdArnoldReaderRegistry; class UsdArnoldReader : public ProceduralReader { public: - UsdArnoldReader() - : _procParent(nullptr), - _universe(nullptr), - _registry(nullptr), - _convert(true), - _debug(false), - _threadCount(1), - _mask(AI_NODE_ALL), - _defaultShader(nullptr), - _hasRootPrim(false), - _readStep(READ_NOT_STARTED), - _purpose(UsdGeomTokens->render), - _dispatcher(nullptr) - { - } + UsdArnoldReader(); ~UsdArnoldReader(); void ReadStage(UsdStageRefPtr stage, @@ -74,7 +60,7 @@ class UsdArnoldReader : public ProceduralReader { void SetProceduralParent(AtNode *node) override; void SetUniverse(AtUniverse *universe) override; - // void SetRegistry(UsdArnoldReaderRegistry *registry); + void CreateViewportRegistry(AtProcViewportMode mode, const AtParamValueMap* params) override; void SetFrame(float frame) override; void SetMotionBlur(bool motionBlur, float motionStart = 0.f, float motionEnd = 0.f) override; @@ -89,7 +75,7 @@ class UsdArnoldReader : public ProceduralReader { const UsdStageRefPtr &GetStage() const { return _stage; } const std::vector &GetNodes() const override { return _nodes; } float GetFrame() const { return _time.frame; } - UsdArnoldReaderRegistry *GetRegistry() { return _registry; } + UsdArnoldReaderRegistry *GetRegistry() { return _readerRegistry; } AtUniverse *GetUniverse() { return _universe; } const AtNode *GetProceduralParent() const { return _procParent; } bool GetDebug() const { return _debug; } @@ -206,8 +192,6 @@ class UsdArnoldReader : public ProceduralReader { private: const AtNode *_procParent; // the created nodes are children of a procedural parent AtUniverse *_universe; // only set if a specific universe is being used - UsdArnoldReaderRegistry *_registry; // custom registry used for this reader. If null, a global - // registry will be used. TimeSettings _time; bool _convert; // do we want to convert the primitives attributes bool _debug; @@ -235,6 +219,8 @@ class UsdArnoldReader : public ProceduralReader { AtString _pxrMtlxPath; // environment variable PXR_MTLX_STDLIB_SEARCH_PATHS unsigned int _id = 0; ///< Arnold shape ID for the procedural. + // Reader registry, will be used in the default case + UsdArnoldReaderRegistry *_readerRegistry = nullptr; }; class UsdArnoldReaderThreadContext : public ArnoldAPIAdapter {