High GPU usage when animating
-
Hello,
I've been developing a Qt application in my company. Lately I've received reports of significantly high GPU usage in Windows 10 in the application during animations. While pinpointing the cause, I noticed that even the basic Qt examples can exhibit this problem.
Steps to reproduce:
- Open Qt Creator, select "OpenGL Window Example" in Examples and run the application
- Open Task Manager and observe GPU usage
- If nothing happens, try maximizing and minimizing the application window, and activating and moving other windows around
- Sometimes it takes up to 20 seconds before the GPU usage increases
What is also notable, is that it's not only the application that consumes the GPU, but Desktop Window Manager participates always as well:
This is a desktop computer with one GPU, NVIDIA GeForce GTX 1070Ti, which should not budge from such a simple 3D task. What is peculiar in this case is that the GPU load varies intensely. The following is a snapshot of ~60 seconds of runtime, without any other particular activity:
The lowest values around ~5% is something that could be expected when running the example in fullscreen in WQHD. But GPU load around 30-40% should not happen.
Other observations:
- This problem is very inconsistent. Sometimes the GPU load is within acceptable levels, but it can ramp up unexpectedly. Sometimes it remains high throughout the whole run time.
- Tweaking
QSurfaceFormat
settings seems to have no impact. - Desktop Window Manager (
dwm.exe
) seems to always contribute roughly the same amount of GPU usage as the Qt app. - Other 3D software does not produce unreasonably high GPU usage, nor do they make DWM consume resources more than a couple of percents at max. This seems to be particular to apps developed in Qt.
- Window size or state do not affect the results consistently, i.e. a tiny window can still consume GPU. Likewise, a maximized window does not always consume large amounts of GPU resources. Desktop scaling doesn't seem to have an effect.
- Tested different Qt-versions (up from 5.12) and compilers (MSVC, MinGW), no effect.
- This issue is not particular to any specific Qt application; Any application (that I've tested) with openGL content, including QML applications, running constant animations/updates have this issue.
- Switching to D3D12 (
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Direct3D12)
) seems to set the application to minimal GPU usage, but then DWM GPU usage doubles. - The problem has been reported to occur also on other Windows 10 computers.
Any idea what could be the cause?
-
@jpsjanne I've got no solution for you but wanted to add that we experience very high GPU usage on iOS with animation and QML. In fact any kind of on screen change eats up GPU. Battery-life is significantly hit and iPads get very hot, I'll be watching this thread with interest. We've used Qt on this particular project since 5.9 and the high GPU issue has persisted all along.
-
two things...first, you need to meter your performance outside of the Creator, not running the app from within creator. an IDE could be doing implicit profiling that interferes with getting real numbers from the OS.
Second, compare sample program load by running instances compiled optimized and then with full debugging enabled.
and as a final note, why do you care about GPU utilization? as long as it's not starved you shouldn't care because that utilization is generally only reflecting the rendering pipeline...real CPU utilization is where I would worry.
-
I've tested both debug and release versions in Qt Creator and standalone release versions. All tests show far have exhibited the same behavior.
There are a lot of reasons to care about GPU utilization:
- We are deploying our software on industrial low-end computers, which do not have powerful GPUs
- They may also in some cases rely only on battery
- They may also be running other critical applications requiring GPU resources, which our software should attempt to preserve
- The GPU load is unreasonable
- For comparison, I can view an animated high-poly 3D model on Sketchfab with the same GPU load as viewing a spinning triangle in a Qt app
- This kind of thing can negatively impact the company image. Our software runs on a small window but still manages to clog the GPU, which would not be viewed positively by our customer base. Conserving computation resources is definitely a key point in our field of business
- This could be a bug
- The 3D chart that I posted depicts that the GPU load varies drastically, albeit the rendering task doesn't
- If the same issue is affecting other developers and other platforms, I think it's worth investigating further
- We are deploying our software on industrial low-end computers, which do not have powerful GPUs
-
This post is deleted!
-
Okay, the issue got resolved after a myriad of various tests. The root cause proved to be quite simple: GPU power save.
Since Qt programs use VSync by default, and the rendering task is small, this triggered the GPU to reduce its clock frequency to save power. Counter-intuitively, Task Manager displays an increase in GPU utilization, as it only displays the utilization of the current resources, not the total available resources of the GPU. The power save decision process is unpredictable, which causes the sporadic increase & decrease in GPU utilization.
Also, DWM is consuming a constant amount of GPU, but it appears to increase consumption only because the total amount of resources decreases.
Therefore, when evaluating Qt performance GPU-wise, looking only at the GPU utilization makes sense only if the application is configured to use the maximum performance when the application is running:
The actual clock frequency can be seen for example with GPU-Z:
As an additional side note to GPU performance evaluation, what should be also considered is dual-GPU laptops. Many laptops have a more powerful dedicated GPU in addition to the low-end integrated GPU. Qt applications seem to be running on the integrated GPU by default. While it's possible to manually set the active GPU for applications, it is also possible to force the use of the dedicated GPU programmatically:
https://stackoverflow.com/a/39047129I'm withdrawing the bug report since there's nothing to fix. Hopefully these discoveries will be useful for other developers who are scratching their heads on the same issue.
-
Thanks for the detailed feedback !