<p>What you are talking about is transform feedback. With transform feedback you can capture primitives (vertices, triangles, lines) in a buffer such they can be used in subsequent draw calls. You don't have to grab the data from the GPU to the CPU and back again as you can directly use the GPU buffer you have just rendered to.</p>
<p>I'm not exactly sure what your use-case exactly is, but you mention simulation and timesteps. Imagine a particle system where each particle has a position and a velocity at each time step of the simulation. We have two buffers A and B. A will be rendered from on even numbered frames and will be written to on odd-numbered frames and B that we write to on even numbered frames and render from on odd-numbered frames. We also have a simple vertex shader that updates the positions of vertices using the aforementioned position and velocity attributes.</p>
<p>Then using some initial position and velocity for each particle we can start rendering from buffer A into buffer B. After having finished this process all particles will have an update position and we can render from buffer B into buffer A.</p>
<p>With this you also have the option to not render to the at all screen by using the GL_RASTERIZER_DISCARD functionality.</p>
<p>Take a look at the examples listed on <a href="http://webglsamples.org/WebGL2Samples/#transform_feedback_instanced" rel="nofollow noreferrer">this</a> page under 'Transform Feedback'. Or at <a href="https://prideout.net/blog/old/blog/index.html@tag=opengl-transform-feedback.html" rel="nofollow noreferrer">this</a> example.</p>

CC BY-SA 4.0
2020-07-28T14:49:32.067Z
2020-07-28T14:49:32.067Z
Reynolds
<p>As someone who is trying to dive into WebGL for parallelizing simulations, or Machine Learning, or typical IIR filters I've come to realize that for everything that I want to do requires the GPU to update itself and send &quot;gossip&quot; signals to the screen.</p>
<p>Sending data to the screen is fairly straight forward, however having the GPU write to itself in order to step into the next time step for a simulation and then send that information to the screen is something I have no clue about doing. I don't know what it's called or if it's even possible.</p>
<p>I hate asking a &quot;<em>is it possible to do X?</em>&quot; question, but sadly this is one of those because my knowledge regarding WebGL is so bad, and studying WebGL for a few months just to realize that it's not possible is not time I can afford right now. I have no one else to ask.</p>
<p>However, to give this question some more meat to the bones I'll say that I assume that it is possible and it is just a matter of setting up two buffers and linking them together in some <em>special way</em>.</p>
<p><strong>Here's the actual question:</strong> I'm familiar with the fact that you set up pipelines in WebGL, does WebGL support pipelines to itself that never goes to the screen so it can modify its internal buffers?</p>

<webgl>
Let GPU write to itself
Harry Svensson
# Let GPU write to itself

(Asked by: username_0 on 2020-07-28)

As someone who is trying to dive into WebGL for parallelizing simulations, or Machine Learning, or typical IIR filters I've come to realize that for everything that I want to do requires the GPU to update itself and send "gossip" signals to the screen.

Sending data to the screen is fairly straight forward, however having the GPU write to itself in order to step into the next time step for a simulation and then send that information to the screen is something I have no clue about doing. I don't know what it's called or if it's even possible.

I hate asking a "*is it possible to do X?*" question, but sadly this is one of those because my knowledge regarding WebGL is so bad, and studying WebGL for a few months just to realize that it's not possible is not time I can afford right now. I have no one else to ask.

However, to give this question some more meat to the bones I'll say that I assume that it is possible and it is just a matter of setting up two buffers and linking them together in some *special way*.

**Here's the actual question:** I'm familiar with the fact that you set up pipelines in WebGL, does WebGL support pipelines to itself that never goes to the screen so it can modify its internal buffers?

**Tags:** webgl


---

## 1 answers

### Answer by username_1 on 2020-07-28. Score: 2 | Accepted answer

What you are talking about is transform feedback. With transform feedback you can capture primitives (vertices, triangles, lines) in a buffer such they can be used in subsequent draw calls. You don't have to grab the data from the GPU to the CPU and back again as you can directly use the GPU buffer you have just rendered to.

I'm not exactly sure what your use-case exactly is, but you mention simulation and timesteps. Imagine a particle system where each particle has a position and a velocity at each time step of the simulation. We have two buffers A and B. A will be rendered from on even numbered frames and will be written to on odd-numbered frames and B that we write to on even numbered frames and render from on odd-numbered frames. We also have a simple vertex shader that updates the positions of vertices using the aforementioned position and velocity attributes.

Then using some initial position and velocity for each particle we can start rendering from buffer A into buffer B. After having finished this process all particles will have an update position and we can render from buffer B into buffer A.

With this you also have the option to not render to the at all screen by using the GL\_RASTERIZER\_DISCARD functionality.

Take a look at the examples listed on [this](http://webglsamples.org/WebGL2Samples/#transform_feedback_instanced) page under 'Transform Feedback'. Or at [this](https://prideout.net/blog/old/blog/index.html@tag=opengl-transform-feedback.html) example.


---

