Qt

OpenGL Qt5 Application on Linux using Bumblebee and VirtualGL

Fabrice

Jan. 20, 2015

Bumblebee OpenGL VirtualGL Qt

Qt5 switched from the Xlib to XCB library which implements the client-side of the X11 display server protocol. But VirtualGL prior to 2.4 doesn't support XCB which leads to window resizing bugs on Qt5 application using OpenGL.

Peoples which want to use their laptop's NVidia discrete GPU through the Optimus technology on Linux have to deal with the Bumblebee folks. There is now others alternatives, but Bumblebee is still useful on some situations. Bumblebee is a hack that run an OpenGL application on a dedicated X server using the discrete GPU and that copy back the frame-buffer to the Intel GPU several times per second. Bumblebee uses internally VirtualGL as a bridge. It worked fine until Qt4, but Qt5 switched from the Xlib to XCB library which implements the client-side of the X11 display server protocol. But VirtualGL prior to 2.4 doesn't support XCB which leads to window resizing bugs on Qt5 application using OpenGL.

This issue was reported on the Qt Jira on august 2013 and in the VirtualGL forum.

The SVN trunk of VirtualGL (version 2.4) has now an implementation of XCB which solved this issue:

VirtualGL can now interpose enough of the XCB API to make Qt 5 work properly. Qt 5 does not use XCB to perform 3D rendering (there is no suitable XCB replacement for GLX yet), but it does use XCB to detect whether the GLX extension is available and to handle the application's event queue(s). Thus, when attempting to run Qt 5 applications in VirtualGL, previously the OpenGL portion of the window would fail to resize when the window was resized, or the application would complain that OpenGL was not available and fail to start, or the application would fall back to non-OpenGL rendering.

Currently, enabling XCB support in VirtualGL requires building VirtualGL from source and adding -DVGL_FAKEXCB=1 to the CMake command line. The XCB interposer is also disabled by default at run time. It must be enabled by setting the VGL_FAKEXCB environment variable to 1 or passing +xcb to vglrun.

To install the upstream version of VirtualGL, you have to basically do these steps:

svn co svn://svn.code.sf.net/p/virtualgl/code/trunk vgl
cmake -DVGL_FAKEXCB=1 CMakeLists.txt
make install

and to run an application:

export VGL_FAKEXCB=1
optirun my_application