# Process of 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);


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.

• 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. – PaulHK Dec 21 '17 at 2:55