From 35919326b4c1b7803cd68a38c4d7d3c8d710a04a Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Tue, 7 Jan 2020 17:14:28 +0000 Subject: Add commands to dump frame graph and scene graph prints to the console, also dump the list of paths in the frame graph to help understand render views. Change-Id: Ic4756e09545971b224a239fafc6667b0ca3d4572 Reviewed-by: Paul Lemire --- src/core/nodes/qentity.cpp | 50 +++++++++++++++++++++ src/core/nodes/qentity_p.h | 1 + src/core/services/qsysteminformationservice.cpp | 2 +- src/render/framegraph/qframegraphnode.cpp | 59 +++++++++++++++++++++++++ src/render/framegraph/qframegraphnode_p.h | 3 ++ src/render/frontend/qrenderaspect.cpp | 18 ++++++++ 6 files changed, 132 insertions(+), 1 deletion(-) diff --git a/src/core/nodes/qentity.cpp b/src/core/nodes/qentity.cpp index 93601901f..1199dfc4b 100644 --- a/src/core/nodes/qentity.cpp +++ b/src/core/nodes/qentity.cpp @@ -53,6 +53,50 @@ QT_BEGIN_NAMESPACE +namespace { + +QString dumpNode(const Qt3DCore::QEntity *n) { + auto formatNode = [](const Qt3DCore::QNode *n) { + QString res = QString(QLatin1String("%1{%2}")) + .arg(QLatin1String(n->metaObject()->className())) + .arg(n->id().id()); + if (!n->objectName().isEmpty()) + res += QString(QLatin1String(" (%1)")).arg(n->objectName()); + if (!n->isEnabled()) + res += QLatin1String(" [D]"); + return res; + }; + + QString res = formatNode(n); + const auto &components = n->components(); + if (components.size()) { + QStringList componentNames; + for (const auto &c : components) + componentNames += formatNode(c); + res += QString(QLatin1String(" [ %1 ]")).arg(componentNames.join(QLatin1String(", "))); + } + + return res; +} + +QStringList dumpSG(const Qt3DCore::QEntity *n, int level = 0) +{ + QStringList reply; + QString res = dumpNode(n); + reply += res.rightJustified(res.length() + level * 2, ' '); + + const auto children = n->childNodes(); + for (auto *child: children) { + auto *childFGNode = qobject_cast(child); + if (childFGNode != nullptr) + reply += dumpSG(childFGNode, level + 1); + } + + return reply; +} + +} + namespace Qt3DCore { /*! @@ -244,6 +288,12 @@ QNodeId QEntityPrivate::parentEntityId() const return m_parentEntityId; } +QString QEntityPrivate::dumpSceneGraph() const +{ + Q_Q(const QEntity); + return dumpSG(q).join('\n'); +} + QNodeCreatedChangeBasePtr QEntity::createNodeCreationChange() const { auto creationChange = QNodeCreatedChangePtr::create(this); diff --git a/src/core/nodes/qentity_p.h b/src/core/nodes/qentity_p.h index 803754c87..992f81931 100644 --- a/src/core/nodes/qentity_p.h +++ b/src/core/nodes/qentity_p.h @@ -82,6 +82,7 @@ public : return typedComponents; } + QString dumpSceneGraph() const; void removeDestroyedComponent(QComponent *comp); QComponentVector m_components; diff --git a/src/core/services/qsysteminformationservice.cpp b/src/core/services/qsysteminformationservice.cpp index 212038eea..87cc08e59 100644 --- a/src/core/services/qsysteminformationservice.cpp +++ b/src/core/services/qsysteminformationservice.cpp @@ -430,7 +430,7 @@ void QSystemInformationService::dumpCommand(const QString &command) return; } } - qWarning() << res; + qWarning() << qPrintable(res.toString()); } } diff --git a/src/render/framegraph/qframegraphnode.cpp b/src/render/framegraph/qframegraphnode.cpp index 2390cb1c9..f49f6433a 100644 --- a/src/render/framegraph/qframegraphnode.cpp +++ b/src/render/framegraph/qframegraphnode.cpp @@ -49,6 +49,51 @@ using namespace Qt3DCore; QT_BEGIN_NAMESPACE +namespace { + +QString dumpNode(const Qt3DRender::QFrameGraphNode *n) { + QString res = QLatin1String(n->metaObject()->className()); + if (!n->objectName().isEmpty()) + res += QString(QLatin1String(" (%1)")).arg(n->objectName()); + if (!n->isEnabled()) + res += QLatin1String(" [D]"); + return res; +} + +QStringList dumpFG(const Qt3DRender::QFrameGraphNode *n, int level = 0) +{ + QStringList reply; + QString res = dumpNode(n); + reply += res.rightJustified(res.length() + level * 2, ' '); + + const auto children = n->childNodes(); + for (auto *child: children) { + auto *childFGNode = qobject_cast(child); + if (childFGNode != nullptr) + reply += dumpFG(childFGNode, level + 1); + } + + return reply; +} + +void dumpFGPaths(const Qt3DRender::QFrameGraphNode *n, QStringList &result, QStringList parents = {}) +{ + parents += dumpNode(n); + + const auto children = n->childNodes(); + if (children.length()) { + for (auto *child: children) { + auto *childFGNode = qobject_cast(child); + if (childFGNode != nullptr) + dumpFGPaths(childFGNode, result, parents); + } + } else { + result << QLatin1String("[ ") + parents.join(QLatin1String(", ")) + QLatin1String(" ]"); + } +} + +} + namespace Qt3DRender { QFrameGraphNodePrivate::QFrameGraphNodePrivate() @@ -240,6 +285,20 @@ QVector QFrameGraphNodePrivate::childFrameGraphNodes() const return result; } +QString QFrameGraphNodePrivate::dumpFrameGraph() const +{ + Q_Q(const QFrameGraphNode); + return dumpFG(q).join('\n'); +} + +QStringList QFrameGraphNodePrivate::dumpFrameGraphPaths() const +{ + Q_Q(const QFrameGraphNode); + QStringList result; + dumpFGPaths(q, result); + return result; +} + /*! \internal */ QFrameGraphNode::QFrameGraphNode(QFrameGraphNodePrivate &dd, QNode *parent) : QNode(dd, parent) diff --git a/src/render/framegraph/qframegraphnode_p.h b/src/render/framegraph/qframegraphnode_p.h index c03017638..4d9516b88 100644 --- a/src/render/framegraph/qframegraphnode_p.h +++ b/src/render/framegraph/qframegraphnode_p.h @@ -70,6 +70,9 @@ public: static QFrameGraphNodePrivate *get(QFrameGraphNode *node) { return node->d_func(); } static const QFrameGraphNodePrivate *get(const QFrameGraphNode *node) { return node->d_func(); } + QString dumpFrameGraph() const; + QStringList dumpFrameGraphPaths() const; + Q_DECLARE_PUBLIC(QFrameGraphNode) }; diff --git a/src/render/frontend/qrenderaspect.cpp b/src/render/frontend/qrenderaspect.cpp index 7a51fa0e7..d48eb4dd3 100644 --- a/src/render/frontend/qrenderaspect.cpp +++ b/src/render/frontend/qrenderaspect.cpp @@ -169,6 +169,8 @@ #include #include #include +#include +#include #include #include @@ -550,6 +552,22 @@ QVector QRenderAspect::jobsToExecute(qint64 time) QVariant QRenderAspect::executeCommand(const QStringList &args) { Q_D(QRenderAspect); + + if (args.size() == 1) { + Render::RenderSettings *settings = d->m_renderer->settings(); + auto *droot = static_cast(Qt3DCore::QNodePrivate::get(d->m_root)); + auto *fg = qobject_cast(droot->m_scene->lookupNode(settings->activeFrameGraphID())); + if (fg) { + if (args.front() == QLatin1String("framegraph")) + return Qt3DRender::QFrameGraphNodePrivate::get(fg)->dumpFrameGraph(); + if (args.front() == QLatin1String("framepaths")) + return Qt3DRender::QFrameGraphNodePrivate::get(fg)->dumpFrameGraphPaths().join(QLatin1String("\n")); + } + if (args.front() == QLatin1String("scenegraph")) + return droot->dumpSceneGraph(); + return {}; + } + return d->m_renderer->executeCommand(args); } -- cgit v1.2.3