From dd1064eee23fc99bcdfe4f869510018c8e2b3110 Mon Sep 17 00:00:00 2001 From: Juan Jose Casafranca Date: Tue, 19 Nov 2019 11:41:32 +0100 Subject: [PATCH] Add geometry memory usage in gltfEditor Change-Id: I1ea1244f4af57b61cd2c8b632545ec08b79d0737 Reviewed-on: https://kuesa-codereview.kdab.com/c/kuesa/kuesa/+/336 Reviewed-by: Paul Lemire --- tools/gltfEditor/gltfEditor.pro | 9 ++- tools/gltfEditor/mainwindow.cpp | 8 +++ tools/gltfEditor/mainwindow.h | 2 + tools/gltfEditor/mainwindow.ui | 11 ++- tools/gltfEditor/memoryusagewidget.cpp | 99 ++++++++++++++++++++++++++ tools/gltfEditor/memoryusagewidget.h | 62 ++++++++++++++++ tools/gltfEditor/memoryusagewidget.ui | 86 ++++++++++++++++++++++ 7 files changed, 273 insertions(+), 4 deletions(-) create mode 100644 tools/gltfEditor/memoryusagewidget.cpp create mode 100644 tools/gltfEditor/memoryusagewidget.h create mode 100644 tools/gltfEditor/memoryusagewidget.ui diff --git a/tools/gltfEditor/gltfEditor.pro b/tools/gltfEditor/gltfEditor.pro index f607f98d7..5b8046f19 100644 --- a/tools/gltfEditor/gltfEditor.pro +++ b/tools/gltfEditor/gltfEditor.pro @@ -55,7 +55,8 @@ SOURCES += \ texturepreviewmaterial.cpp \ settingsdialog.cpp \ orbitcameracontroller.cpp \ - exportdialog.cpp + exportdialog.cpp \ + memoryusagewidget.cpp HEADERS += \ mainwindow.h \ @@ -78,7 +79,8 @@ HEADERS += \ texturepreviewmaterial.h \ settingsdialog.h \ orbitcameracontroller.h \ - exportdialog.h + exportdialog.h \ + memoryusagewidget.h FORMS += \ animationwidget.ui \ @@ -90,7 +92,8 @@ FORMS += \ meshwidget.ui \ texturewidget.ui \ settingsdialog.ui \ - exportdialog.ui + exportdialog.ui \ + memoryusagewidget.ui RESOURCES += \ qml.qrc \ diff --git a/tools/gltfEditor/mainwindow.cpp b/tools/gltfEditor/mainwindow.cpp index c28f7adc5..c91fd4fdf 100644 --- a/tools/gltfEditor/mainwindow.cpp +++ b/tools/gltfEditor/mainwindow.cpp @@ -37,6 +37,7 @@ #include "meshinspector.h" #include "animationwidget.h" #include "camerawidget.h" +#include "memoryusagewidget.h" #include "orbitcameracontroller.h" #include "exportdialog.h" @@ -152,6 +153,10 @@ MainWindow::MainWindow(QWidget *parent) m_ui->cameraDockWidget->setWidget(m_cameraWidget); m_ui->cameraDockWidget->setVisible(false); + m_memoryUsageWidget = new MemoryUsageWidget; + m_ui->memoryUsageWidget->setWidget(m_memoryUsageWidget); + m_ui->memoryUsageWidget->setVisible(false); + qmlRegisterType("GltfEditor", 1, 0, "TexturePreviewMaterial"); qmlRegisterType("GltfEditor", 1, 0, "OrbitCameraController"); @@ -174,6 +179,7 @@ MainWindow::MainWindow(QWidget *parent) m_ui->menuView->addAction(m_ui->assetInspectorDockWidget->toggleViewAction()); m_ui->menuView->addAction(m_ui->animationDockWidget->toggleViewAction()); m_ui->menuView->addAction(m_ui->cameraDockWidget->toggleViewAction()); + m_ui->menuView->addAction(m_ui->memoryUsageWidget->toggleViewAction()); m_ui->collectionBrowser->setModel(new CollectionModel(this)); @@ -262,6 +268,8 @@ void MainWindow::updateScene(Kuesa::SceneEntity *entity) m_sceneSelector->setEnabled(m_sceneSelector->count() > 1); m_sceneSelector->setCurrentIndex(selectorIndex); m_sceneSelector->blockSignals(false); + + m_memoryUsageWidget->setSceneEntity(entity); } void MainWindow::assetSelected(const QString &assetName, Kuesa::AbstractAssetCollection *collection) diff --git a/tools/gltfEditor/mainwindow.h b/tools/gltfEditor/mainwindow.h index 9b603e81f..6a45aadcd 100644 --- a/tools/gltfEditor/mainwindow.h +++ b/tools/gltfEditor/mainwindow.h @@ -40,6 +40,7 @@ class AnimationWidget; class AssetInspectorWidget; class AssetInspector; class CameraWidget; +class MemoryUsageWidget; namespace Ui { class MainWindow; @@ -133,6 +134,7 @@ private slots: QString m_selectedAssetName; QColor m_clearColor; CameraWidget *m_cameraWidget; + MemoryUsageWidget *m_memoryUsageWidget; QSize m_renderAreaSize; bool m_generateTangents; bool m_generateNormals; diff --git a/tools/gltfEditor/mainwindow.ui b/tools/gltfEditor/mainwindow.ui index c2e8a2534..581576ef4 100644 --- a/tools/gltfEditor/mainwindow.ui +++ b/tools/gltfEditor/mainwindow.ui @@ -24,7 +24,7 @@ 0 0 1400 - 22 + 23 @@ -151,6 +151,15 @@ + + + GPU memory usage + + + 2 + + + &Open... diff --git a/tools/gltfEditor/memoryusagewidget.cpp b/tools/gltfEditor/memoryusagewidget.cpp new file mode 100644 index 000000000..e110ac6be --- /dev/null +++ b/tools/gltfEditor/memoryusagewidget.cpp @@ -0,0 +1,99 @@ +/* + memoryusage.cpp + + This file is part of Kuesa. + + Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Juan Casafranca + + Licensees holding valid proprietary KDAB Kuesa licenses may use this file in + accordance with the Kuesa Enterprise License Agreement provided with the Software in the + LICENSE.KUESA.ENTERPRISE file. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#include "memoryusagewidget.h" +#include "ui_memoryusagewidget.h" + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +namespace { + const QLatin1String LASTPATHSETTING("mainwindow/lastPath"); + +QString totalSizeString(int sizeInBytes) +{ + auto size = sizeInBytes / 1024.0; + QString suffix(QStringLiteral(" KB")); + if (size > 1024.) { + size = size / 1024.; + suffix = QStringLiteral(" MB"); + } + return QString::number(size, 'f', 2) + suffix; +} +} + +MemoryUsageWidget::MemoryUsageWidget(QWidget *parent) + : QWidget(parent) + , m_ui(new Ui::MemoryUsageWidget) + , m_sceneEntity(nullptr) +{ + m_ui->setupUi(this); +} + +MemoryUsageWidget::~MemoryUsageWidget() +{ +} + +void MemoryUsageWidget::setSceneEntity(Kuesa::SceneEntity *sceneEntity) +{ + m_sceneEntity = sceneEntity; + updateWidgetValues(); +} + +void MemoryUsageWidget::updateWidgetValues() +{ + Kuesa::MeshCollection *meshesCollection = m_sceneEntity->meshes(); + const auto &names = meshesCollection->names(); + + int geometrySize = 0; + QVector visitedBuffer; + for (const auto &name: names) { + Qt3DRender::QGeometryRenderer *mesh = meshesCollection->find(name); + + const auto &attributes = mesh->geometry()->attributes(); + for (Qt3DRender::QAttribute *attribute : attributes) { + if (!visitedBuffer.contains(attribute->buffer())) { + geometrySize += attribute->buffer()->data().size(); + visitedBuffer.push_back(attribute->buffer()); + } + } + } + + m_ui->geometryUsage->setText(totalSizeString(geometrySize)); +} diff --git a/tools/gltfEditor/memoryusagewidget.h b/tools/gltfEditor/memoryusagewidget.h new file mode 100644 index 000000000..3d8b2497d --- /dev/null +++ b/tools/gltfEditor/memoryusagewidget.h @@ -0,0 +1,62 @@ +/* + MemoryUsageWidget.h + + This file is part of Kuesa. + + Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Juan Casafranca + + Licensees holding valid proprietary KDAB Kuesa licenses may use this file in + accordance with the Kuesa Enterprise License Agreement provided with the Software in the + LICENSE.KUESA.ENTERPRISE file. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#ifndef MEMORYUSAGEWIDGET_H +#define MEMORYUSAGEWIDGET_H + +#include +#include +#include + +namespace Ui { +class MemoryUsageWidget; +} // namespace Ui + +namespace Kuesa +{ +class SceneEntity; +} + +class MemoryUsageWidget : public QWidget +{ + Q_OBJECT + +public: + MemoryUsageWidget(QWidget *parent = nullptr); + virtual ~MemoryUsageWidget(); + + void setSceneEntity(Kuesa::SceneEntity *sceneEntity); + +private: + void updateWidgetValues(); + + QScopedPointer m_ui; + Kuesa::SceneEntity *m_sceneEntity; +}; + +#endif // MEMORYUSAGEWIDGET_H diff --git a/tools/gltfEditor/memoryusagewidget.ui b/tools/gltfEditor/memoryusagewidget.ui new file mode 100644 index 000000000..95b16c1c7 --- /dev/null +++ b/tools/gltfEditor/memoryusagewidget.ui @@ -0,0 +1,86 @@ + + + MemoryUsageWidget + + + + 0 + 0 + 571 + 147 + + + + Form + + + + + + + + + + Geometry: + + + + + + + Texture: + + + + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 0 + + + + + + + + +