Laszlo Agocs

Boosting performance with shader binary caching in Qt 5.9

Published Thursday March 23rd, 2017
3 Comments on Boosting performance with shader binary caching in Qt 5.9
Posted in Dev Loop, Graphics, OpenGL, Painting, Qt Quick

Now that Qt 5.9 is getting closer, let’s take a look at a minor but immensely useful improvement to the basic OpenGL enablers that form the foundation of Qt Quick and the optional OpenGL-based rendering path of QPainter.

Those looking at the documentation snapshots for 5.9 may have already come across some new functions in the venerable QOpenGLShaderProgram. What is more, most internal usages in Qt have been switched over to the new API. What does this mean in practice?

As explained here, such shader programs will attempt to cache the program binaries on disk using GL_ARB_get_program_binary or the standard equivalents in OpenGL ES 3.0. When no support is provided by the driver, the behavior is equivalent to the non-cached case. The files are stored in the global or per-process cache location, whichever is writable. The result is a nice boost in performance when a program is created with the same shader sources next time.

How big is the improvement? It varies. Some drivers have already been doing some sort of caching for the past couple of years, while some others have similar features in the pipeline. However, the gains turn out to be quite significant in practice on devices that are out in the field right now:

image2016-11-21-152420

Do not read too much into the actual numbers. What is important is the difference between Qt 5.8 and 5.9. Also, a simple Qt Quick or GL-backed QPainter scene will definitely not use 10 programs, but as complexity grows, with Qt Graphical Effects and custom ShaderEffect items entering the picture, getting similar improvements does not look far fetched anymore.

In fact we gain something even on systems that employ shader caching already. Therefore every application’s startup and view switching times are expected to benefit with Qt 5.9 – without having to change anything.

Applications that use QOpenGLShaderProgram on their own can usually switch to the cacheable function variants by just changing the name in the function call. The change have to be a conscious decision, though, since some of the APIs change semantics when program binaries are used. Most notably, QOpenGLShader, addShader(), and removeShader() are incompatible with the program-level caching since they rely on individual shader compilation.

That’s it for now, stay tuned for more posts about exciting upcoming Qt 5.9 and 5.10 features.

Do you like this? Share it
Share on LinkedInGoogle+Share on FacebookTweet about this on Twitter

Posted in Dev Loop, Graphics, OpenGL, Painting, Qt Quick

3 comments

David B says:

Speaking of performance, I see Qt 5.9 is using Chrome 55 in its webengine. Is there any chance that will be bumped up to version 56 which uses WebGL2.0

Thanks,
David

Tom says:

Will you drop support for msvc2013 32bit compiler? (As its not contained in the beta snapshot)

And when do you plan to add support for msvc2017?

Commenting closed.

Get started today with Qt Download now