High CPU usage
-
I just recently started to play around with Qt3d. And i'm surprised how fast you get something that looks pretty decent (at least in my opinion).
But i still have an issue with rendering speed and CPU usage. I've written a small test program to showcase this (see below).
Tested this on 2 different Setups.
- Ubuntu 18.04, i7-4790, GeForce 745 GTX
- Windows 10, i7-3770, GeForce 960 GTX
And had the same results:
- CPU usage is very high - 100% on one Core all the time.
- GPU usage shows no real difference if the application is running or not.
Didn't find anything about this and already asked on stackoverflow with no real answer.
The example just draws 2000 Cuboids with random sizes on random positions with a light source above.
This is quite simple and should be no problem at all, right? Or am i missing something?
Thanks in advance!#include <QGuiApplication> #include <QRandomGenerator> #include <QHBoxLayout> #include <Qt3DRender/QCamera> #include <Qt3DCore/QEntity> #include <QtWidgets/QApplication> #include <QtWidgets/QWidget> #include <QtGui/QScreen> #include <Qt3DCore/QTransform> #include <Qt3DCore/QAspectEngine> #include <Qt3DExtras/QForwardRenderer> #include <Qt3DRender/QPointLight> #include <Qt3DExtras/QCuboidMesh> #include <Qt3DExtras/QDiffuseSpecularMaterial> #include <Qt3DExtras/Qt3DWindow> #include <Qt3DExtras/QOrbitCameraController> int main(int argc, char **argv) { //basic window/widget stuff QApplication app(argc, argv); Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow(); view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f))); QWidget *container = QWidget::createWindowContainer(view); QSize screenSize = view->screen()->size(); container->setMinimumSize(QSize(200, 100)); container->setMaximumSize(screenSize); QWidget *widget = new QWidget; QHBoxLayout *hLayout = new QHBoxLayout(widget); hLayout->addWidget(container, 1); //root entity Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); view->setRootEntity(rootEntity); //setup camera view->camera()->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 10.0f, 5000.0f); view->camera()->setPosition(QVector3D(0, 0, 3000)); view->camera()->setUpVector(QVector3D(0, 1, 0)); view->camera()->setViewCenter(QVector3D(0, 0, 0)); //orbit camera controller Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(rootEntity); camController->setCamera(view->camera()); camController->setLookSpeed(500); //add light Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity); Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity); light->setColor("white"); light->setIntensity(1); lightEntity->addComponent(light); Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity); lightTransform->setTranslation(QVector3D(0, 5000, 0)); lightEntity->addComponent(lightTransform); //add objects QRandomGenerator rng(1234); for(int i = 0; i <= 2000; i++) { Qt3DCore::QEntity* shapeEntity = new Qt3DCore::QEntity(rootEntity); Qt3DExtras::QCuboidMesh* mesh = new Qt3DExtras::QCuboidMesh(); mesh->setXExtent(int(rng.generate() % 30)+20); mesh->setYExtent(int(rng.generate() % 30)+20); mesh->setZExtent(int(rng.generate() % 30)+20); shapeEntity->addComponent(mesh); Qt3DExtras::QDiffuseSpecularMaterial *material = new Qt3DExtras::QDiffuseSpecularMaterial(); material->setAmbient(QColor(Qt::red).darker(150)); material->setDiffuse(QColor(Qt::red)); shapeEntity->addComponent(material); Qt3DCore::QTransform* pTrans = new Qt3DCore::QTransform(); pTrans->setTranslation(QVector3D(int(rng.generate() % 2000)-1000, int(rng.generate() % 2000)-1000, int(rng.generate() % 2000)-1000)); shapeEntity->addComponent(pTrans); } //show widget->show(); widget->resize(1200, 800); return app.exec(); }
-
@Darksorrow Maybe you could check if your system is using the correct drivers, check this blog https://www.qt.io/blog/2017/01/18/opengl-implementation-qt-quick-app-using-today . Its about qml, but maybe you could use a small qml example just to check if your drivers are good.
Edit: I just tested your program in my windows machine, core-I7 8750H, with nvidia gtx 1050TI, it's using more less 23% cpu and 25% gpu. -
Hi!
@johngodSorry for the late reply. Had other other things to do and put this to the side in the meanwhile.
So i did a Qt-Quick example with the environment variable QSG_INFO set.
But this looks fine to me:qt.scenegraph.general: threaded render loop qt.scenegraph.general: Using sg animation driver qt.scenegraph.general: Animation Driver: using vsync: 16.67 ms qt.scenegraph.general: Using sg animation driver qt.scenegraph.general: Animation Driver: using vsync: 16.67 ms qt.scenegraph.general: opengl texture atlas dimensions: 1024x512 qt.scenegraph.general: R/G/B/A Buffers: 8 8 8 0 qt.scenegraph.general: Depth Buffer: 24 qt.scenegraph.general: Stencil Buffer: 8 qt.scenegraph.general: Samples: -1 qt.scenegraph.general: GL_VENDOR: NVIDIA Corporation qt.scenegraph.general: GL_RENDERER: GeForce GTX 745/PCIe/SSE2 qt.scenegraph.general: GL_VERSION: 4.6.0 NVIDIA 390.138 qt.scenegraph.general: GL_EXTENSIONS: ... (a lot of stuff^^) qt.scenegraph.general: Max Texture Size: 16384 qt.scenegraph.general: Debug context: false
You said you tested it on your machine. What do you think? Isn't 23% CPU for a still image on a CPU like this not way to high?
Edit:
I downloaded Qt5.15 which has more debug-options for Qt3d as i read in this article:
https://www.kdab.com/debugging-profiling-qt-3d-apps/
But didn't really learn anything helpful :-/Also used the newly introduced class "Qt3DRender::QRenderCapabilities"
qDebug() << cap.api(); //"Qt3DRender::QRenderCapabilities::OpenGL" qDebug() << cap.driverVersion(); //"4.3.0 NVIDIA 390.138" qDebug() << cap.glslVersion(); //"4.30 NVIDIA via Cg compiler" qDebug() << cap.renderer(); //"GeForce GTX 745/PCIe/SSE2" qDebug() << cap.profile(); //"Qt3DRender::QRenderCapabilities::CoreProfile"
Which also looks good to me.
I really don't understand whats causing this...
If i can't figure this out i think i'll go back to use OpenGL directly >.< -
@Darksorrow said in High CPU usage:
If i can't figure this out i think i'll go back to use OpenGL directly >.<
I have the same problem>.<!
Any good results?