1
$\begingroup$

I'am curious about compute shader in OpenGL.

Let's assume the number of points (vec4) is 900

and the work group size(= the number of work items) is 256

Then, We would have four work groups because 900/256 = 3.xx, so need to plus 1.

The code is as follows:

glDispatchCompute(4, 1, 1);

and shader is as follows:

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;
layout(std430, binding = 0) buffer Particles {
    vec4 partices[];
};

In this case, I wonder how to work fourth work group. In my thought, the fourth work group have overflow problem because the total number of points is 900.

Do we need to deal exceptional case(overflow)?

For example, if idex > total num, then 'pass'

Or

The Opengl deals this problem automatically?

(ex, There is no problem situation.)

I tried to check by myself. Even though I make overflow situation, there was no warning.

$\endgroup$
  • 1
    $\begingroup$ 30x30x1 will cover 900 points. It is up to the shader what to do with the global invocation ID, in your case it would be an index into the particles[] array. If you have a case were the ID is greater than the size of the particles array you can just skip doing any work. $\endgroup$ – PaulHK Dec 21 '17 at 2:55
3
$\begingroup$

The Opengl deals this problem automatically?

How could it? At no point do you inform OpenGL that you only want 900 invocations. You have exactly 2 mechanisms to control the number of invocations: the work group size in the shader, and the work group count in the dispatch call. That determines how many invocations there are.

If you want a variable number of invocations with a fixed work group size, then your shader has to be given the actual maximum number of operations, and you have to explicitly not do anything for invocations beyond that size.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.