Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,15 @@ HdMeshTopology MayaHydraSceneIndex::GetMeshTopology(const SdfPath& id)
_renderItemsAdapters);
}

HdBasisCurvesTopology MayaHydraSceneIndex::GetBasisCurvesTopology(const SdfPath& id)
{
return _GetValue<MayaHydraAdapter, HdBasisCurvesTopology>(
id,
[](MayaHydraAdapter* a) -> HdBasisCurvesTopology { return a->GetBasisCurvesTopology(); },
_shapeAdapters,
_renderItemsAdapters);
}

void MayaHydraSceneIndex::RemoveAdapter(const SdfPath& id)
{
if (!_RemoveAdapter<MayaHydraAdapter>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex

HdMeshTopology GetMeshTopology(const SdfPath& id);

HdBasisCurvesTopology GetBasisCurvesTopology(const SdfPath& id);

SdfPath GetPrimPath(const MDagPath& dg, bool isSprim) const;

SdfPath GetRprimPath() const { return _rprimPath; }
Expand Down
75 changes: 75 additions & 0 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
#include <pxr/imaging/hd/rendererPluginRegistry.h>
#include <pxr/imaging/hd/rprim.h>
#include <pxr/imaging/hd/sceneIndexPluginRegistry.h>
#include <pxr/imaging/hd/dataSource.h>
#include <pxr/imaging/hd/basisCurvesTopology.h>
#include <pxr/imaging/hd/meshTopology.h>
#include <pxr/imaging/hd/sceneIndexPrimView.h>
#include <pxr/imaging/hdx/selectionTask.h>
#include <pxr/imaging/hdx/colorizeSelectionTask.h>
#include <pxr/imaging/hdx/pickTask.h>
Expand Down Expand Up @@ -440,6 +444,77 @@ int MtohRenderOverride::GetUsedGPUMemory()
return totalGPUMemory / (1024*1024);
}

std::map<std::string, int> MtohRenderOverride::GetSceneStatistics()
{
std::map<std::string, int> stats = {
Comment thread
huangi-adsk marked this conversation as resolved.
{"primitives", 0},
{"mesh", 0},
{"mesh.points", 0},
{"mesh.faces", 0},
{"curve", 0},
{"curve.points", 0},
{"point", 0},
};

MtohRenderOverride* instance = nullptr;
{
std::lock_guard<std::mutex> lock(_allInstancesMutex);
for (auto* inst : _allInstances) {
if (inst->_initializationSucceeded && inst->_renderIndex) {
instance = inst;
break;
}
}
}

if (!instance || !instance->_renderIndex) {
return stats;
}

auto* renderIndex = instance->_renderIndex;
auto primIds = renderIndex->GetRprimIds();

for (const auto& primId : primIds) {
auto* rprim = renderIndex->GetRprim(primId);
if (!rprim) {
continue;
}

stats["primitives"]++;

HdSceneIndexPrim prim;
TfToken primType;
if (instance->_mayaHydraSceneIndex) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Need to find a common way to query the primtype, it could come from any SceneIndex

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One way might be check the type of auto* rprim = renderIndex->GetRprim(primId);, if it could be dynamically casted to HdMesh, we will assume it's a mesh prim.

prim = instance->_mayaHydraSceneIndex->GetPrim(primId);
primType = prim.primType;
}

if (primType.IsEmpty()) {
continue;
}

if (primType == HdPrimTypeTokens->mesh) {
stats["mesh"]++;
if (instance->_mayaHydraSceneIndex && prim.dataSource) {
HdMeshTopology meshTopology = instance->_mayaHydraSceneIndex->GetMeshTopology(primId);
stats["mesh.points"] += meshTopology.GetNumPoints();
stats["mesh.faces"] += meshTopology.GetNumFaces();
}
}
else if (primType == HdPrimTypeTokens->basisCurves) {
stats["curve"]++;
if (instance->_mayaHydraSceneIndex && prim.dataSource) {
HdBasisCurvesTopology curvesTopology = instance->_mayaHydraSceneIndex->GetBasisCurvesTopology(primId);
stats["curve.points"] += curvesTopology.GetNumPoints();
}
}
else if (primType == HdPrimTypeTokens->points) {
stats["point"]++;
}
}
return stats;
}

std::vector<MString> MtohRenderOverride::AllActiveRendererNames()
{
std::vector<MString> renderers;
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 @@ -151,6 +151,9 @@ class MtohRenderOverride : public MHWRender::MRenderOverride,
// Utility function to get GPU memory usage stats
static int GetUsedGPUMemory();

// Returns scene statistics as a map for the currently active render delegate from Hydra primitives
static std::map<std::string, int> GetSceneStatistics();

bool startOperationIterator() override;
MHWRender::MRenderOperation* renderOperation() override;
bool nextRenderOperation() override;
Expand Down
13 changes: 12 additions & 1 deletion lib/mayaHydra/mayaPlugin/viewCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ constexpr auto _rendererIdLong = "-renderer";
constexpr auto _userDefaultsId = "-u";
constexpr auto _userDefaultsIdLong = "-userDefaults";

constexpr auto _sceneStats = "-ss";
constexpr auto _sceneStatsLong = "-sceneStats";

constexpr auto _helpText = R"HELP(For details on args usage please see
https://github.com/Autodesk/maya-hydra/tree/dev/doc/mayaHydraCommads.md
)HELP";
Expand Down Expand Up @@ -151,6 +154,8 @@ MSyntax MtohViewCmd::createSyntax()

syntax.addFlag(_usdVersion, _usdVersionLong);

syntax.addFlag(_sceneStats, _sceneStatsLong);

return syntax;
}

Expand All @@ -176,8 +181,14 @@ MStatus MtohViewCmd::doIt(const MArgList& args)

if (db.isFlagSet(_hdGPUMem)) {
appendToResult(MtohRenderOverride::GetUsedGPUMemory());
} if (db.isFlagSet(_currentProcessMemory)) {
} else if (db.isFlagSet(_currentProcessMemory)) {
appendToResult(getProcessMemory());
} else if (db.isFlagSet(_sceneStats)) {
auto stats = MtohRenderOverride::GetSceneStatistics();
for (const auto& pair : stats) {
appendToResult(pair.first.c_str());
appendToResult(std::to_string(pair.second).c_str());
}
} else if (db.isFlagSet(_listRenderers)) {
for (auto& plugin : MtohGetRendererDescriptions())
appendToResult(plugin.rendererName.GetText());
Expand Down