Why use Transform feedback?

Hi

I'm studying the Transform feedback.

I understand how to use the transform feedback buffer.
But I still don't know why we use it.

Is there any good performance effect on transform feedback buffer?
(I guess it is concept of threading. For example, first vertex shader is only updating position and velocity, and second vertex shader is used on drawing vertex.)

And I also have another question that it can be done one pass vertex shader pipeline. why should be used transform feedback buffer? Is it like such a "pipelining" on Computer Architecture?

Off the top of my head, these are some possible uses:
- Say you do animations with a bones and skin system (vertex skinning) on the GPU, but need the transformed mesh for some physics or logic calculation on the CPU. TF essentially allows you to transform the mesh once, write to a buffer (optionally download that buffer to the CPU) and render the transformed mesh. This saves doing (the potentially expensive) vertex skinning twice.
- You use some form of dynamic LOD, where models are tesselated based on distance from the camera. Since that distance usually changes slowly you only perform the tesselation when a change in LOD requires it, store the result in a TF buffer and for the frames where there is no change just re-use the TF buffer for rendering.

A more generic way of looking at uses for TF is whenever you have expensive vertex/geometry processing steps where the output can be used for multiple draw operations it can save you repeating the expensive steps for each draw.

Transform feedback is primarily used to retrieve values from vertex-transforming stages of the pipeline.
There are a lot of use cases. The reason in the case you mentioned is performance - using vertex shader to parallelize calculation (instead a single thread calculation on the CPU use tens or hundreds of threads on the GPU).
The second question is not clear. Can you reformulate it?

Another very common case are stateful particle systems where you don't want to recalculate the attributes of particles in a buffer object on the CPU. Using TF spares you the round-trip entirely and additionally let's you calculate new particle values in parallel without any hassle. I've seen code that did this using textures and FBOs instead and TF makes this so much nicer and easier.

BTW, another interesting addition of the TF extension is the ability to discard rasterization entirely. Essentially, when enabling that option, you use the GPU as sort of a compute devices and not as a rasterizer spitting out an image when it's done. EDIT: Note that since GL4 this is only true for stream zero. There can now be multiple streams into which you can commit vertex attribs, but you'll need a geometry shader for that. Otherwise you'll implicitly use stream zero and everything on that stream is implicitly rasterized - unless rasterizer discard is enabled. Streaming to any other stream does not forward attributes to subsequent stages and thus rasterizer discard is essentially only necessary if you don't want to redirect vertex attribs to a non-zero stream.

Also, TF avoids clipping, so no discarding of vertices happens and your results are streamed to the target buffer without interference from the GPU - unless you have some geometry shader which explicitly drops vertices.

Transform feedback is primarily used to retrieve values from vertex-transforming stages of the pipeline.
There are a lot of use cases. The reason in the case you mentioned is performance - using vertex shader to parallelize calculation (instead a single thread calculation on the CPU use tens or hundreds of threads on the GPU).
The second question is not clear. Can you reformulate it?

Thanks your reply

I think Transform feedback mechanism is like below.
Click image for larger version.

Name: Untitled-3.png
Views: 0
Size: 5.1 KB
ID: 1301

Is it right?

And I have one more question. Must I use double buffer (vertex buffer object) when I use TF? Otherwise, Am I able to use triple or more buffer?

Must I use double buffer (vertex buffer object) when I use TF? Otherwise, Am I able to use triple or more buffer?

The output buffer(s) must be distinct from any input buffers; you can't modify vertices in-place. There's no reason why you couldn't use triple-buffering, although I can't think of any situation where that would help.