<blockquote>
  <p>The Opengl deals this problem automatically? </p>
</blockquote>

<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2017-12-21T15:28:16.737Z
2017-12-21T15:28:16.737Z
Nicol Bolas
<p>I'am curious about compute shader in OpenGL.</p>

<p>Let's assume the number of points (vec4) is 900</p>

<p>and  the work group size(= the number of work items) is 256</p>

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

<p>The code is as follows:</p>

<pre><code>glDispatchCompute(4, 1, 1);
</code></pre>

<p>and shader is as follows:</p>

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

<p>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.</p>

<p>Do we need to deal exceptional case(overflow)?</p>

<p>For example, if idex > total num, then 'pass'</p>

<p>Or</p>

<p>The Opengl deals this problem automatically? </p>

<p>(ex, There is no problem situation.)</p>

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

CC BY-SA 3.0
2017-12-21T02:55:36.183Z
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
<opengl><shader><gpu><compute-shader><gpgpu>
Process of compute shader in OpenGL
shashack
# Process of compute shader in OpenGL

(Asked by: username_0 on 2017-12-21)

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.

**Tags:** opengl, shader, gpu, compute-shader, gpgpu

> **Comments:**
> **username_1**: 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.  

---

## 1 answers

### Answer by username_2 on 2017-12-21. Score: 3 | Accepted answer

> 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.


---

