/qtcomputeshader

Implementing compute shader computation without graphics

Primary LanguageC++

qtcomputeshader

It's example of using compute shader in Qt without graphical rendering.

The compute shader processes array of 23 floats and writes it to another array. Qt reads both input and output arrays back to CPU and prints to console.

When running, the example should print the 23 input and output elements to console:

Buffers: 
   0   0
   1   1.5
   2   3
   3   4.5
   4   6
   5   7.5
   6   9
   7   10.5
...

Example contains ShaderBuffer, ComputeShader and GlContext helper classes to simplify working with compute shaders.

Note on data aligning

As you see in the example, we use array of 23 floats, together with std430 layout specifier in shader's buffer declaration. Such array works and we are not required to align data to 4*float. But nevertheless you shouldn't use vec3 anyway in shader buffer, because it's aligned itself to 16 floats anyway! See details here: https://stackoverflow.com/questions/38172696/should-i-ever-use-a-vec3-inside-of-a-uniform-buffer-or-shader-storage-buffer-o

Requirements

  • OpenGL >= 4.3.
  • Tested on Qt = 5.15, Windows, but contains no platform-specific code.

Further development

I created this example to test working compute shaders in Qt. Then I use it in compute shaders support for Xclu project, https://github.com/XcluDev/Xclu

  • See sdk/compshaders/xcomputeshader.h,.cpp (may be renamed in future).

Credits

The code is made using ideas from the following codes:

Useful links: