Optimizing GPU Usage for Large Images in Qt Application
-
I'm developing an application and need to use an image of 20,000 by 20,000 with a total of 700 MB. Using Qt's QImage, I'm experiencing GPU usage of 1.5 GB. However, when using the same image resized to 10,000 by 10,000, the GPU usage drops to 500 MB. What would be the best way to reduce this GPU usage without resizing?
Note: Qt version 5.15 and the initial image is in PNG format.
Note2: I've generated a DDS image of 20,000 by 20,000 with a total of 500 MB, but I'm unable to display it. -
A QImage will never be in the GPU memory. Maybe a QPixmap.
But handling such big images is nothing where Qt can help you - you should handle this by yourself if you want it in gpu only memory (e.g. by using OpenGL or similar). -
@Christian-Ehrlicher said in Optimizing GPU Usage for Large Images in Qt Application:
A QImage will never be in the GPU memory. Maybe a QPixmap.
I'm sorry, but Image QML Type shouldn't be using my GPU memory, should be using my Ram instead?
-
@Alexandre-Henrique QImage <-> QML Image - you said QImage...
-
@Christian-Ehrlicher I'm sorry. So, Qml Image should use GPU memory? If so, can i manage to change to Ram?
-
Maybe you should consider creating a mechanism to tile your data.
So instead of working with a single 20k by 20k image you create an image abstraction that allows you to map only parts of the image into memory at any time in smaller chunks.
It all depends of course what you want to achieve exactly.
-
@Christian-Ehrlicher said in Optimizing GPU Usage for Large Images in Qt Application:
QPixmap
And thanks for this. I'm trying to open my image with QImage and use QQuickImageProvider Class to my Qml Application to see if my image consumes my ram instead my vram.
-
@Alexandre-Henrique said in Optimizing GPU Usage for Large Images in Qt Application:
20,000 by 20,000 with a total of 700 MB
A 20k square is 4e8 pixels. At one byte-per-pixel monochrome this is at least ~400MB, and two or more bytes-per-pixel would be bigger than 700MB. Are you sure of the memory measurement and that this is the image itself?
-
@ChrisW67 it's a compressed png, when it loads in my vram the image is descompressed i think, and that's why is consuming that much of my GPU. I am trying to change it to my ram instead of my vram. But still without success.
-
At some point the image needs to be decompressed. This most likely happens in RAM first and is then send over to the GPU. Have you thought, what the GPU might be doing with the image? It just resizes it to the viewport. The best you can do is to dynamically resize the image to the viewport size and have Qt copy that to the GPU instead. If you are zoomed in, just send that part of the image instead of the whole image.
Because QML is heavily using the GPU in the background (it is faster) the GPU needs to have access to the image it should display. On most computers the GPU cannot directly access the RAM.