cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

zoomzoom
Adept I
Adept I

clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

Hello,

I am struggling with this error for some days already and I just can't figure out what I'm missing, so if any of you has any suggestion, I would be very grateful.

My application uses OpenCL for some data processing and OpenGL to display the results. During the application lifetime, the window displaying the results may be closed, and another window can be opened. In this case a new OpenGL-OpenCL context initialization must be run.

Beginning with the second initialization, clCreateFromGLBuffer fails returning CL_INVALID_GL_OBJECT. This happens on a HD 7850 running OpenCL 1.2 AMD-APP 938.1.

I get no errors if running the same code on NVIDIA GPU (8800GTX or 280 GTX).

Also, I get no errors if the previous OpenGL buffer object is not destroyed before initializing a new context.

Calling glIsBuffer just before clCreateFromGLBuffer always returns TRUE, so the buffer object must be valid.

Using gDEBugger I have noticed the following:

     clCreateContext - creates a new gl context by calling wglCreateContext and sets it to share lists with the input provided gl context by calling wglShareLists

     clCreateFromGLBuffer - works with the context created above (in clCreateContext). It also calls glIsBuffer to validate the input buffer object.

The big problem is that on the second call, clCreateContext does not create a new context anymore. I don't know why.

Moreover, clCreateFromGLBuffer will makeCurrent the context from the previous call (the first context initializations)! This is why I thing glIsBuffer will return FALSE in this situation. But what I don't understand is why the second context initialization uses data from the first one.

Attached is a simplified code showing this strange behavior. Just call SimpleGLCL() and then again SimpleGLCL(), and clCreateFromGLBuffer will throw the -60 error.

If you comment the two lines selecting and deleting the object buffer, there will be no errors.

Thank you!

0 Kudos
Reply
10 Replies
Wenju
Elite
Elite

Re: clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

Hi zoomzoom,

I'll try this. You can have a look at some samples in AMD SDK, some of them used this function.

0 Kudos
Reply
zoomzoom
Adept I
Adept I

Re: clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

Thank you, Wenju, for your quick answer.

Continuing to looking into this problem, I have found that "SimpleGL" sample can also be used to illustrate my problem.

It would need some minor changes; the first one is to add a for loop inside the main function:

int main(int argc, char *argv[])

{

     int run;

     for (run = 0; run < 2; run++)

     {

          // All existing code except for the last line

     }

     return SDK_SUCCESS;

}

Just with these changes everything works just fine. However, I think that the vertexObj buffer destructor is not called where it should. The demo application calls glDeleteBuffers in cleanup(), but after the OpenGL rendering context has been destroyed by wglDeleteContext() function. Why? Does it make any sense to delete an OpenGL object after its OpenGL context has been destroyed?

Moving glBindBuffer, glDeleteBuffers from cleanup() to the beginning of disableGL(HWND hWnd, HDC hDC, HGLRC hRC) will generate the -60 error code for the second call of clCreateFromGLBuffer.

Any idea?

Wenju
Elite
Elite

Re: clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

I think it means nothing. You also can delete an GL  buffer before context. Just speculating.

0 Kudos
Reply
zoomzoom
Adept I
Adept I

Re: clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

Wenju, thank you for your time and attention.

It seems to me something's fishy here. Because clCreateFromGLBuffer behaves differently depending on when glDeleteBuffers is called. Shouldn't it behave the same no matter when glDeleteBuffers is called?

0 Kudos
Reply
Wenju
Elite
Elite

Re: clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

It's my pleasure! I'm not sure about this, but I think it's not a big problem when you know the dependence of all those objects.

0 Kudos
Reply
zoomzoom
Adept I
Adept I

Re: clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

I thought about that myself. But when there are several openGL contexts and/or object buffers not all related to OpenCL, it doesn't work as easy as with the SimpleGL sample.

And I'd rather find what's wrong with my code or with OpenCL implementation on AMD GPUs than wasting time finding strange fixes.

I have filled in a ticket to Amd Service Desk and I'm waiting for an answer. I just hope they will answer even if there's something obvious missing on my side.

Thank you for your support and help.

0 Kudos
Reply
zoomzoom
Adept I
Adept I

Re: clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

Wenju,

You've been so kind to look into this problem that I would dare ask you one more thing.

Would it be possible to try the modified SimpleGL application and tell me if clCreateFromGLBuffer fails on second run for you too?

The two changes to be added to SimpleGL are:

     1. Move glBindBuffer, glDeleteBuffers from cleanup() to the beginning of disableGL(HWND hWnd, HDC hDC, HGLRC hRC)

     2. Add a for loop inside the main function:

int main(int argc, char *argv[])

{

     int run;

     for (run = 0; run < 2; run++)

     {

          // All existing code except for the last line

     }

     return SDK_SUCCESS;

}


Thank you!

0 Kudos
Reply
Wenju
Elite
Elite

Re: clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

Yes, it fails.

zoomzoom
Adept I
Adept I

Re: clCreateFromGLBuffer returns CL_INVALID_GL_OBJECT on the second/third ocl-ogl context

Thank you very much!

0 Kudos
Reply