cdyken
February 22, 2007, 3:43pm
1
Hi,
I’ve encountered some strange behaviour trying to set up a OpenGL VBO for rendering of cuda output. The following code:
// ...
glGenBuffers(1, &m_vbo );
glBindBuffer( GL_ARRAY_BUFFER, m_vbo );
glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat)*256*256, NULL, GL_DYNAMIC_DRAW );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
CHECK_GL;
CUDA_SAFE_CALL( cudaGLRegisterBufferObject( m_vbo ) );
// ...
gives a segmentation fault at the call to RegisterBufferObject-call. After playing around with buffer type, usage type, etc. to no avail, I saw that the simpleGL-example in the SDK did the following
float* foo = (float*)malloc(sizeof(GLfloat)*256*256);
glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat)*256*256, foo, GL_DYNAMIC_DRAW );
free(foo);
thus actually defining the contents of the buffer to be something. And if I do this, my code works…
I guess since the code in the SDK does the extra malloc-gymnastics, maybe it is a known bug?
Chris
Hi Chris,
This is a known bug and we have a fix in progress. It was missed for the release notes – sorry for the inconvenience.
The workaround, is as you saw in the example, to allocate a dummy array to pass to glBufferData.
Mark
cdyken
February 23, 2007, 6:24am
3
Hi Mark,
Thanks for your reply !
By the way, the cudaGLMapBufferObject definition in the 0.8 programming guide on p.34 lacks the “GL”-bit in the name and has different arguments than the definition in the header-file.
Chris
ohh
April 1, 2008, 9:40pm
4
I discovered that if size is less than 65536 this works as expected.
glBufferData( GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW );
But once i tried with 65536 or more, I got a memory pointer far off from the usual value with
float4 *ptr = (float4*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
.
The same behaviour was observed with device emulation too.
cdyken
April 2, 2008, 9:59am
5
I discovered that if size is less than 65536 this works as expected.
glBufferData( GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW );
But once i tried with 65536 or more, I got a memory pointer far off from the usual value with
float4 *ptr = (float4*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
.
The same behaviour was observed with device emulation too.
[snapback]355018[/snapback]
Is the pointer illegal? (i.e., do you get a segfault if you try to use it?)
And if so, have you registered the buffer with CUDA, or is it plain GL?
Chris