WebEngine refuses to use GPU
-
I'm just running a minimal example:
#include <QApplication> #include <QWebEngineView> #include <QWebEngineSettings> #include <QSurfaceFormat> int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); QSurfaceFormat format; format.setRenderableType(QSurfaceFormat::OpenGL); QSurfaceFormat::setDefaultFormat(format); qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--enable-gpu-rasterization --enable-zero-copy --ignore-gpu-blacklist"); QWebEngineView *view = new QWebEngineView(); view->settings()->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, true); view->settings()->setAttribute(QWebEngineSettings::WebGLEnabled, true); view->setUrl(QUrl("https://maps.google.com")); view->show(); return app.exec(); }
And noticed the rendering lags badly. As you can see I already tried setting a bunch of flags to force it to use GPU. Checking chrome://gpu (replace the gooogle maps url with it) shows that hardware acceleration is enabled:
But when I check the task manager, the WebEngineProcess shows no gpu loading, and the cpu load is very high.
Perplexingly, I wrote a python script on the same machine that runs fine and smooth:
from PyQt5.QtWidgets import QApplication from PyQt5.QtWebEngineWidgets import QWebEngineView import sys from PyQt5.QtCore import QUrl import os app = QApplication(sys.argv) view = QWebEngineView() print(os.environ.get("QTWEBENGINE_CHROMIUM_FLAGS")) view.setUrl(QUrl("https://maps.google.com")) view.show() sys.exit(app.exec_())
What could be the issue here? Any help would be greatly appreciated.
-
Very embarassing but I found out I have to to build in RELEASE mode to have the full GPU acceleration.
In practice that means doing
cmake -DCMAKE_BUILD_TYPE=Release ..
Then run windeployqt again. There should be QWebEngineProcess.exe - if there is QWebEngineProcessd.exe (the d for "debug") that means it is still in debug mode and will be slow.