clEnqueueWriteBuffer fails for OpenGL buffer (OpenGL/OpenCL interop)

Hi,

i have an application that uses OpenGl/Cl interop. I’m creating a OpenGL VBO, mapping it to an OpenCL buffer and later try to read the buffer data to the host using clEnqueueReadBuffer.

This fails with an error code -30 (CL_INVALID_VALUE).

clEnqueueWriteBuffer works fine if i do not use gl/cl interop (i.e. the buffer was created with clCreateBuffer).

And, the same code with cl/gl interop works on AMD and Intel GPUs.

So, could this be a limitation of the Nvidia driver? If so, is there a workaround?

Hardware is Quadro K4000, driver is NVIDIA-Linux-x86_64-352.55.run, OS is CentOS 7.

Thanks.

Code to create/map the buffer:
glGenBuffers(1, &b->vbo);
glBindBuffer(GL_ARRAY_BUFFER, b->vbo);
glBufferData(GL_ARRAY_BUFFER, hostDataSize, hostData, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
b->clBuffer = clCreateFromGLBuffer (context, CL_MEM_READ_WRITE, b->vbo, &status);

Sorry, copy/paste error: The issue should read “clEnqueueREADBuffer” (not sure yet about write)!

Did you call clEnqueueAcquireGLObjects() before clEnqueueReadBuffer()?

Yes, i generally do that.
But i forgot to do it right after creating the vbo and mapping it to the cl buffer … thanks!

Interesting that it worked at all for other OpenCL implementations.