# Sequential execution for compute shaders

**URL:** <https://openrndr.discourse.group/t/sequential-execution-for-compute-shaders/441>\
**Category:** GLSL Shaders\
**Created:** [October 22, 2022, 9:38am UTC](https://openrndr.discourse.group/t/sequential-execution-for-compute-shaders/441 "2022-10-22T09:38:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alessandro](https://yyz2.discourse-cdn.com/free1/user_avatar/openrndr.discourse.group/alessandro/32/412_2.png) [@Alessandro](https://openrndr.discourse.group/u/Alessandro)\
**Post date:** [October 22, 2022, 9:38am UTC](https://openrndr.discourse.group/t/sequential-execution-for-compute-shaders/441/1 "2022-10-22T09:38:56Z")

</div>

I was trying to understand sequential execution of compute shaders. Suppose I have compute shaders computeA and computeB: computeA writes on an SSBO and computeB reads from it. In OpenGL one usually issues a

```auto
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT)

```

after the dispatch call of computeA (i.e. the execute call in openrndr), since one is not guaranteed syncronicity. As far as I can see from the source code, the .execute call does not incorporate such a barrier, and it makes sense. My experiments seem also to confirm that. Is there a way to invoke such a command without directly passing from a low-level OpenGL library?

---

<div class="post-metadata">

**Author:** ![abe](https://yyz2.discourse-cdn.com/free1/user_avatar/openrndr.discourse.group/abe/32/700_2.png) [@abe](https://openrndr.discourse.group/u/abe)\
**Post date:** [October 22, 2022, 10:02am UTC](https://openrndr.discourse.group/t/sequential-execution-for-compute-shaders/441/2 "2022-10-22T10:02:09Z")

</div>

Interesting! I have been using 8 or 9 compute shaders sequentially in a program. Some are reading, writing or doing both from SSBOs. Do you think they may be misbehaving? I haven’t noticed… maybe that’s what makes the result interesting? XD I’ll ask in Slack.

---

<div class="post-metadata">

**Author:** ![Alessandro](https://yyz2.discourse-cdn.com/free1/user_avatar/openrndr.discourse.group/alessandro/32/412_2.png) [@Alessandro](https://openrndr.discourse.group/u/Alessandro)\
**Post date:** [October 22, 2022, 10:17am UTC](https://openrndr.discourse.group/t/sequential-execution-for-compute-shaders/441/3 "2022-10-22T10:17:58Z")

</div>

Technically different dispatch call are not assured to be synchronous. A nice example is [here](https://learnopengl.com/Guest-Articles/2022/Compute-Shaders/Introduction), in particular

> Before accessing the image data after the compute shader execution we need to define a barrier to make sure the data writing is completly finished. The glMemoryBarrier defines such a barrier which orders memory transactions. The GLbitfield parameter barriers specifies the barriers to insert. They must be a bit wise combination of any GL barrier\_bit constants (see: [glMemoryBarrier - Khronos](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glMemoryBarrier.xhtml)). In this case, we only need the GL\_SHADER\_IMAGE\_ACCESS\_BARRIER\_BIT which assures access using the image functions will reflect data written by shaders prior to the barrier.

This is for images, but you have barrier for all types.  
As for providing interesting effects, I am all up for it! Actually I’ll probably show one of these artifacts tomorrow at the meeting 🙂
