Qt3DCore - High CPU Usage
-
I've got a weird issue when trying to display a 3D model in my
QWidgets
app on Windows whereby the CPU usage creeps up past 30% when absolutely nothing is going on.Steps to recreate:
- Create a new
Qt Widgets Application
- Target
Qt 5.11.3 for MSVC 2015 32bit
- Append the following to the
QT +=
section .pro file3dcore 3drender 3dextras
- Paste the following code into
MainWindow.cpp
(underui->setupUi(this);
):
QColor bg = this->palette().background().color(); // Create the view Qt3DExtras::Qt3DWindow* view = new Qt3DExtras::Qt3DWindow(); view->defaultFrameGraph()->setClearColor(bg); // Create the container widget QWidget* container = QWidget::createWindowContainer(view); this->setCentralWidget(container); // Create a root entity Qt3DCore::QEntity* root = new Qt3DCore::QEntity; // Create a scene camera Qt3DRender::QCamera* camera = view->camera(); camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f); camera->setPosition(QVector3D(0, 0, 8.0f)); camera->setUpVector(QVector3D(0, 1, 0)); camera->setViewCenter(QVector3D(0, 0, 0)); // Set up the scene lighting Qt3DCore::QEntity* light = new Qt3DCore::QEntity(root); Qt3DRender::QPointLight* point = new Qt3DRender::QPointLight(light); point->setColor("silver"); point->setIntensity(1); light->addComponent(point); Qt3DCore::QTransform* lightTransform = new Qt3DCore::QTransform(light); lightTransform->setTranslation(camera->position()); light->addComponent(lightTransform); Qt3DCore::QEntity* model = new Qt3DCore::QEntity(root); Qt3DRender::QMesh* mesh = new Qt3DRender::QMesh(); mesh->setSource(QUrl::fromLocalFile("my_model.obj")); Qt3DExtras::QPhongMaterial* material = new Qt3DExtras::QPhongMaterial; material->setDiffuse(QColor(Qt::darkGray)); Qt3DCore::QTransform* transform = new Qt3DCore::QTransform; transform->setScale(1.0); transform->setRotation(QQuaternion::fromEulerAngles(0.0, 0.0, 0.0)); model->addComponent(mesh); model->addComponent(transform); model->addComponent(material); view->setRootEntity(root); transform->setRotation(QQuaternion::fromEulerAngles(0, 0, 0));
My understand (from various forum posts) was that the performance on the
Qt3DCore
side had been improved with recent releases of Qt however this definitely does not seem to be the case. - Create a new
-
@JohanSolo Unfortunately switching to 5.12 made no difference.
Even with the simple example above, with 5.12.5 I'm seeing > 40%.
-
@webzoid said in Qt3DCore - High CPU Usage:
Steps to recreate:
I tried to follow your steps on Qt 5.13.0 for MSVC 2017 32-bit, but the window was blank.
So I ran the Basic Shapes Example on Qt 5.13.0 for MSVC 2017 32-bit. Sitting idly, the CPU did not exceed 4%.
I have a Intel Core i7 4710HQ @ 2.50GHz + 2048MB ATI AMD Radeon R9 M265X. What hardware are you using? What happens when you run the Basic Shapes example?
-
@JKSH I'm assuming that you replaced "my_model.obj" with an alternative?
I've just run the
Basic Shapes
example and my current CPU usage is at 52.1%!!! Yikes!My machine is an Intel Core i5-2500 @ 3.30GHz + dual AMD Radeon HD 7500 graphics cards + 16GB RAM.
Maybe I need a driver update but I have also seen this on many customers machines.
** UPDATE **
Ok, so one thing I didn't highlight is that I'm running 3 displays from those dual graphics cards. Interestingly, if I have the Qt example application running on the primary display, the CPU usage is high. If I move the Qt window to one of the other displays then the CPU usage drops by about 30% to around the 24% region.
Weirdness!
-
@webzoid said in Qt3DCore - High CPU Usage:
@JKSH I'm assuming that you replaced "my_model.obj" with an alternative?
Ah, no I didn't notice that your code needs my_model.obj. (Suggestion: When you want others to reproduce a problem that you're seeing, it's best to use examples that don't require others to create their own resource files)
I've just run the
Basic Shapes
example and my current CPU usage is at 52.1%!!! Yikes!OK, since you can reproduce your problem on an official example, let's stick to this. Use this example when you submit a bug report.
My machine is an Intel Core i5-2500 @ 3.30GHz + dual AMD Radeon HD 7500 graphics cards + 16GB RAM.
That should certainly be enough to run the Basic Shapes example comfortably.
Ok, so one thing I didn't highlight is that I'm running 3 displays from those dual graphics cards. Interestingly, if I have the Qt example application running on the primary display, the CPU usage is high. If I move the Qt window to one of the other displays then the CPU usage drops by about 30% to around the 24% region.
Weirdness!
24% still seems quite high. What happens if you only have a single display connected to your GPU?
I just noticed this on a different machine:
Specs:
- Intel i7-7770 3.6 GHz
- 16 GB DDR4 RAM
- 3071MB NVIDIA GeForce GTX 1080 Ti
- 1920 x 1080 display
- Qt 5.13.1 for MSVC 2017 32-bit
Behaviour for the Basic Shapes example when idle:
Mode CPU Usage Debug mode 4% Release mode 17% Would you be happy to open a report at https://bugreports.qt.io/ ? (Provide as much details as you can, using an official example)
EDIT: I left the Basic Shapes example running in Release mode while I did other things. I noticed that the CPU activity dropped to 2% after a while and stayed at 2%, even when I move the camera around rapidly.