Qt World Summit: Submit your Presentation

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();
        QWidget *container = QWidget::createWindowContainer(view);
        QSize screenSize = view->screen()->size();
        container->setMinimumSize(QSize(200, 100));
        QWidget *widget = new QWidget;
        QHBoxLayout *hLayout = new QHBoxLayout(widget);
        hLayout->addWidget(container, 1);
        //root entity
        Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();
        //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);
        //add light
        Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
        Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
        Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
        lightTransform->setTranslation(QVector3D(0, 5000, 0));
        //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);
            Qt3DExtras::QDiffuseSpecularMaterial *material = new Qt3DExtras::QDiffuseSpecularMaterial();
            Qt3DCore::QTransform* pTrans = new Qt3DCore::QTransform();
            pTrans->setTranslation(QVector3D(int(rng.generate() % 2000)-1000, int(rng.generate() % 2000)-1000, int(rng.generate() % 2000)-1000));
        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!

    Sorry 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?

    I downloaded Qt5.15 which has more debug-options for Qt3d as i read in this article:
    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´╝č

Log in to reply