CUDA doesn't perceive VBO data's modification with glMapBuffer() ?


From my code I have just found a problem with vbo and cuda,

  1. I change the data in VBO with opengl commands:

glBindBuffer( GL_ARRAY_BUFFER, _vbo_id );
GLfloat* unitdata = static_cast<GLfloat*>( glMapBuffer( GL_ARRAY_BUFFER, GL_READ_WRITE ) );
xxxx; /* change this VBO with pointer unitdata at host side */
glUnmapBuffer( GL_ARRAY_BUFFER );
glBindBuffer( GL_ARRAY_BUFFER, 0 );

  1. Then I wanna read this VBO from cuda:

cudaGraphicsMapResources( 1, &cgr, 0 ); /* cgr has already been initialized( registered with the corresponding VBO ID ) at the initialization phase /
cudaGraphicsResourceGetMappedPointer( &pdata, &datasizeinbyte, cgr );
xxxx; /
using this vbo’s data in cuda(kernel) throught this mapped pointer */
cudaGraphicsUnmapResources( 1, &cgr, 0 );

But by my program, every time after I have changed the data in VBO with opengl, the data read from cuda remains unchanged. I am really confused about that, I have printed the data (coppied first to host memory side) every time I use the mapped pointer in kernel.

Please help me, thanks very much!


If I register( not only map it ) this VBO to CUDA everytime after call of glMapBuffer, the cuda can notice the modification of VBO.

The question is, why must man register it again? after glMapBuffer, will the location of device memory of this VBO be changed?

I vaguely remember that resources have to unregistered if you want to modify them from OpenGL, but I can’t find any reference to this in the documentation. It may be a bug, please file one.

Note you could also initialize the contents of the VBO from CUDA using cudaMemcpy.