<p>I am trying to solve a problem with compute shaders.
I have several shaders that are executed one after the other in a loop.</p>
<p>At an unpredictable time, the memory is full and the shaders should be stopped to transfer the memory to the CPU side.
There is an integer in an SSBO that atomically counts the objects that are generated.
If it reaches a certain number, the memory is full and the shader should be stopped.</p>
<p>At the moment, I transfer the SSBO integer to the CPU after each shader and decide whether to continue or not. The GPU &lt;-&gt; CPU communication seems to be a bottleneck to me.</p>
<p>What options do I have to interrupt the command buffer regarding the integer?</p>
<p>An interrupt instruction within the shader would be my favorite to halt, if possible.</p>

CC BY-SA 4.0
2024-12-23T11:27:12.003Z
There is no direct way to interrupt a shader, compute or otherwise.  A flag (such as setting an atomic flag when memory is full)  can be used to tell compute shaders to stop, or just to skip execution all together. Using finer grained dispatch, resetting command buffers before execution starts. All the stuff I'm sure you already thought of and or tried.
pmw1234
CC BY-SA 4.0
2024-12-24T10:32:49.827Z
@pmw1234 Yes, I have tried to optimise memory usage by minimising the byte size of an object. I also try to load finished objects (that do not need further computation) to the CPU to keep the number of objects small. Each object can create a maximum of 4 children within a shader call, so I try to estimate how many shaders can be executed before I have to check memory again.
Thomas
<glsl><vulkan><compute-shader>
How do you interrupt from a compute shader?
Thomas
# How do you interrupt from a compute shader?

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

I am trying to solve a problem with compute shaders.
I have several shaders that are executed one after the other in a loop.

At an unpredictable time, the memory is full and the shaders should be stopped to transfer the memory to the CPU side.
There is an integer in an SSBO that atomically counts the objects that are generated.
If it reaches a certain number, the memory is full and the shader should be stopped.

At the moment, I transfer the SSBO integer to the CPU after each shader and decide whether to continue or not. The GPU <-> CPU communication seems to be a bottleneck to me.

What options do I have to interrupt the command buffer regarding the integer?

An interrupt instruction within the shader would be my favorite to halt, if possible.

**Tags:** glsl, vulkan, compute-shader

> **Comments:**
> **username_1**: There is no direct way to interrupt a shader, compute or otherwise.  A flag (such as setting an atomic flag when memory is full)  can be used to tell compute shaders to stop, or just to skip execution all together. Using finer grained dispatch, resetting command buffers before execution starts. All the stuff I'm sure you already thought of and or tried.  
> **username_0**: @username_1 Yes, I have tried to optimise memory usage by minimising the byte size of an object. I also try to load finished objects (that do not need further computation) to the CPU to keep the number of objects small. Each object can create a maximum of 4 children within a shader call, so I try to estimate how many shaders can be executed before I have to check memory again.  

---

## 0 answers

