diff --git a/doc/codingGuidelines.md b/doc/codingGuidelines.md index af70f3342e..373c8f0431 100644 --- a/doc/codingGuidelines.md +++ b/doc/codingGuidelines.md @@ -268,6 +268,21 @@ Our goal is to develop [maya-usd](https://github.com/autodesk/maya-usd) followin * `nullptr` keyword * … +## Diagnostic Facilities + +Developers are encouraged to use TF library diagnostic facilities in Maya USD. Please follow below guideline for picking the correct facility: https://graphics.pixar.com/usd/docs/api/page_tf__diagnostic.html + +In MayaUSD, `UsdMayaDiagnosticDelegate` converts TF diagnostics into native Maya infos, warnings, and errors. The environment flag `MAYAUSD_SHOW_FULL_DIAGNOSTICS`, controls the granularity of TF error/warning/status messages being displayed in Maya: + +e.g +``` +Error: Failed verification: ' image ' -- Unable to create an image from RetroTVBody_Albedo.png +``` +vs +``` +Error: Failed verification: ' image ' -- Unable to create an image from RetroTVBody_Albedo.png -- Coding Error in _LoadTexture at line 422 of C:\maya-usd\lib\mayaUsd\render\vp2RenderDelegate\material.cpp +``` + # Coding guidelines for Python We are adopting the [PEP-8](https://www.python.org/dev/peps/pep-0008) style for Python Code with the following modification: * Mixed-case for variable and function names are allowed diff --git a/lib/mayaUsd/render/vp2RenderDelegate/material.cpp b/lib/mayaUsd/render/vp2RenderDelegate/material.cpp index 2244084dff..aa6b54f02a 100644 --- a/lib/mayaUsd/render/vp2RenderDelegate/material.cpp +++ b/lib/mayaUsd/render/vp2RenderDelegate/material.cpp @@ -426,7 +426,8 @@ _LoadTexture(const std::string& path, bool& isColorSpaceSRGB, MFloatArray& uvSca #else GlfImageSharedPtr image = GlfImage::OpenForReading(path); #endif - if (!TF_VERIFY(image)) { + + if (!TF_VERIFY(image, "Unable to create an image from %s", path.c_str())) { return nullptr; } diff --git a/lib/mayaUsd/utils/diagnosticDelegate.cpp b/lib/mayaUsd/utils/diagnosticDelegate.cpp index 172b61945b..d017377376 100644 --- a/lib/mayaUsd/utils/diagnosticDelegate.cpp +++ b/lib/mayaUsd/utils/diagnosticDelegate.cpp @@ -23,7 +23,7 @@ #include -#include +#include PXR_NAMESPACE_OPEN_SCOPE @@ -34,6 +34,12 @@ TF_DEFINE_ENV_SETTING( "If batching is off, all secondary threads' diagnostics will be " "printed to stderr."); +TF_DEFINE_ENV_SETTING( + MAYAUSD_SHOW_FULL_DIAGNOSTICS, + false, + "This env flag controls the granularity of TF error/warning/status messages " + "being displayed in Maya."); + // Globally-shared delegate. Uses shared_ptr so we can have weak ptrs. static std::shared_ptr _sharedDelegate; @@ -61,14 +67,18 @@ class _WarningOnlyDelegate : public UsdUtilsCoalescingDiagnosticDelegate static MString _FormatDiagnostic(const TfDiagnosticBase& d) { - const std::string msg = TfStringPrintf( - "%s -- %s in %s at line %zu of %s", - d.GetCommentary().c_str(), - TfDiagnosticMgr::GetCodeName(d.GetDiagnosticCode()).c_str(), - d.GetContext().GetFunction(), - d.GetContext().GetLine(), - d.GetContext().GetFile()); - return msg.c_str(); + if (!TfGetEnvSetting(MAYAUSD_SHOW_FULL_DIAGNOSTICS)) { + return d.GetCommentary().c_str(); + } else { + const std::string msg = TfStringPrintf( + "%s -- %s in %s at line %zu of %s", + d.GetCommentary().c_str(), + TfDiagnosticMgr::GetCodeName(d.GetDiagnosticCode()).c_str(), + d.GetContext().GetFunction(), + d.GetContext().GetLine(), + ghc::filesystem::path(d.GetContext().GetFile()).relative_path().string().c_str()); + return msg.c_str(); + } } static MString _FormatCoalescedDiagnostic(const UsdUtilsCoalescingDiagnosticDelegateItem& item) @@ -104,12 +114,13 @@ void UsdMayaDiagnosticDelegate::IssueError(const TfError& err) { // Errors are never batched. They should be rare, and in those cases, we // want to see them separately. - // In addition, always display the full call site for errors by going - // through _FormatDiagnostic. + + const auto diagnosticMessage = _FormatDiagnostic(err); + if (ArchIsMainThread()) { - MGlobal::displayError(_FormatDiagnostic(err)); + MGlobal::displayError(diagnosticMessage); } else { - std::cerr << _FormatDiagnostic(err) << std::endl; + std::cerr << diagnosticMessage << std::endl; } } @@ -119,10 +130,12 @@ void UsdMayaDiagnosticDelegate::IssueStatus(const TfStatus& status) return; // Batched. } + const auto diagnosticMessage = _FormatDiagnostic(status); + if (ArchIsMainThread()) { - MGlobal::displayInfo(status.GetCommentary().c_str()); + MGlobal::displayInfo(diagnosticMessage); } else { - std::cerr << _FormatDiagnostic(status) << std::endl; + std::cerr << diagnosticMessage << std::endl; } } @@ -132,10 +145,12 @@ void UsdMayaDiagnosticDelegate::IssueWarning(const TfWarning& warning) return; // Batched. } + const auto diagnosticMessage = _FormatDiagnostic(warning); + if (ArchIsMainThread()) { - MGlobal::displayWarning(warning.GetCommentary().c_str()); + MGlobal::displayWarning(diagnosticMessage); } else { - std::cerr << _FormatDiagnostic(warning) << std::endl; + std::cerr << diagnosticMessage << std::endl; } } diff --git a/lib/mayaUsd/utils/stageCache.cpp b/lib/mayaUsd/utils/stageCache.cpp index 773013a530..1eb9a57788 100644 --- a/lib/mayaUsd/utils/stageCache.cpp +++ b/lib/mayaUsd/utils/stageCache.cpp @@ -50,7 +50,6 @@ struct _OnSceneResetListener : public TfWeakBase void OnSceneReset(const UsdMayaSceneResetNotice& notice) { - TF_STATUS("Clearing USD Stage Cache"); UsdMayaStageCache::Clear(); std::lock_guard lock(_sharedSessionLayersMutex); diff --git a/test/lib/mayaUsd/utils/testDiagnosticDelegate.py b/test/lib/mayaUsd/utils/testDiagnosticDelegate.py index 9c8871a3cb..41458c5916 100644 --- a/test/lib/mayaUsd/utils/testDiagnosticDelegate.py +++ b/test/lib/mayaUsd/utils/testDiagnosticDelegate.py @@ -118,9 +118,13 @@ def testError(self): # the module name will match the file name and be reported as # "testDiagnosticDelegate". We make the regex here recognize both # cases. - self.assertRegex(logText, - "^Python coding error: blah -- Coding Error in " - "(__main__|testDiagnosticDelegate)\.testError at line [0-9]+ of ") + if (Tf.GetEnvSetting('MAYAUSD_SHOW_FULL_DIAGNOSTICS')): + self.assertRegex(logText, + "^Python coding error: blah -- Coding Error in " + "(__main__|testDiagnosticDelegate)\.testError at line [0-9]+ of ") + else: + self.assertEqual(logText, "Python coding error: blah") + self.assertEqual(logCode, OM.MCommandMessage.kError) def testError_Python(self):