OpenGL transform feedback alongside CUDA

Hi all,
I have an application which does some sort of simulation and the resulting vertex modification are rerendered using transform feedback. The performance is fairly good I get approx. 1000 fps on a 1024x768 screen with about 2500 particles each modifiable in realtime by mouse interaction.
Now I want to know

  1. if it is possible to use transform feedback along side a CUDA kernel? If so how do i do the synchronization of my vbos btw the opengl device and the cuda device? Would this synchronization of vbos cause delays? Any reference on this would be appreciated.
  2. Lets say I want to try the same calculations that I m currently doing in my vertex shader with transform feedback in CUDA would i give me the same performance? Does cuda have a mechanism like transform feedback or do i need to manually handle the vbos myself. Again any reference would be appreciated.

It is not very clear what you want to achieve. What does it mean “use transform feedback along side a CUDA kernel”? It is possible to share buffers between CUDA and GL. To achieve that you have to:

  1. Enable GL interoperability (cudaGLSetGLDevice)
  2. Register buffers (cudaGraphicsGLRegisterBuffer)
  3. Whenever you want to access buffer from within CUDA - Map buffer (cudaGraphicsMapResources), and grab the pointer to it (cudaGraphicsResourceGetMappedPointer)
  4. When finished unmap it (cudaGraphicsUnmapResources)

Synchronization is done through map/unmap, and it is expensive, since all calls must be finished before another API takes control.

Thanks for your reply Aleksandar. I have noted the steps u have mentioned.

Ok. currently I am doing a simulation in a vertex shader + transform feedback to modify vbos. If i write the current appraoch in plain language it would be something like this,


vertex shader deforms vertices 
transform feedback handles vbos using update vaos
deformed points are read from render vao and then rendered 

Now I want to do the same thing using CUDA. So i wanted to know if there is anything like transform feedback in CUDA so that I could simply change my vertex shader with a CUDA kernel. So again putting it in plain language i want to do this


CUDA kernel deforms vertices 
CUDA (transform feedback ???) handles vbos using update vaos
deformed points are read from render vao and then rendered 

Is this possible? Does CUDA have any construct like transform feedback. If not how do I handle the vaos?

One more question. I have got two vbos which are handled through a single vao. Can I pass my vao to CUDA and then access the appropriate vbo or I can only pass the vbo?

Is this possible? Does CUDA have any construct like transform feedback. If not how do I handle the vaos?

This is a very confused question.

First, VAOs are just collections of buffer object references and state needed for rendering. They define the vertex format and which buffers to pull from for a rendering operation. CUDA has no need to talk to such objects, and they almost certainly don’t live on the GPU anyway. They’re for user convenience; they don’t really mean anything.

Second, transform feedback is a mechanism that allows the saving of outputs from a vertex shader. CUDA doesn’t have shaders of any kind; it is an API for doing arbitrary computations. So no, it does not do “transform feedback.”

However, it can write arbitrary data to GPU memory buffers. Memory buffers like buffer objects.

So if you’re asking, “Can CUDA write to OpenGL buffer objects, so that I can use those buffer objects as attributes for a later OpenGL rendering call?” the answer is yes.

Thanks Alfonse for the wonderful insights. I get it now.