Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Adept I

ocl-ogl interop - clCreateContext returns -1000 if the specified OpenGL context is not current


According to the OpenCL specification version 1.0 (page 276), if a context is specified during a opengl-opencl interop initialization, the context does not need to be the current context of the thread calling clCreateFunction.

However, calling clCreateFunction to create an OpenCL context that will be associated with an OpenGL context, returns error code -1000 (CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR) if the OpenGL context is not the current context of the calling thread.

My GPU is an HD 7850 running OpenCL 1.2 AMD-APP 938.1

To get the error above, you can take any AMD OpenCL samples (for example, SimpleGL) and add a wglMakeCurrent(NULL, NULL) call just before clCreateContext function call.

I get no such error on NVIDIA GPUs.

Has anyone else encountered this problem? Or have I misread the documentation?

Thank you.

10 Replies

I think GaussianNoiseGL is much better.


The problem is still there also for GaussianNoiseGL sample.

Add wglMakeCurrent(NULL, NULL) before clCreateContext and the -1000 error will be returned.

Why does clCreateContext return -1000 if the OpenGL context is not the current active context?


The -1000 error means that the OpenGL context or share group object handle is specified in properties is invalid. In sample SimpleGL, you can try this(about line 420): 

cl_context_properties cps[3] =







  wglMakeCurrent(NULL, NULL);

        // Create OpenCL context from device's id

  context = clCreateContext(cps,






CHECK_OPENCL_ERROR(status, "clCreateContext failed!!");


I did find the explanation on the -1000 error code in the OpenCL documentation. And indeed your sample code should and does generate the -1000 error code.

But.... take the SimpleGL sample without any changes. It works, right? No errors.

Ok, so it means that the OpenGL context handle is valid. Great! Now go to where clCreateContext is called and add

wglMakeCurrent(NULL, NULL) before clCreateContext. => clCreateContext will fail with the -1000 error code.

Why this error? The context properties array contains a valid opengl context handle. wglMakeCurrent(NULL, NULL) should just make the current context of the current thread not current.


Download opencl-1.2-extension.pdf, about chapter 9.6.3. If your code like this:

wglMakeCurrent(NULL, NULL);


and you get -1000. Why? If hglrc is NULL, the function makes the calling thread's current rendering context no longer current, and releases the device context that is used by the rendering context. In this case, hdc is ignored. And I think the context properties will be invalid. And if you set this array as the first argument for clCreateContext, you'll get -1000. So the code I gave you will not get -1000, but I'm not sure whether it's what you want.


According to the OpenCL specification version 1.0 (page 276), if a context is specified during a opengl-opencl interop initialization, the context does not need to be the current context of the thread calling clCreateContext.

wglMakeCurrent(NULL, NULL) makes hglrc no longer current for the current thread and releases the hdc, but releasing does not mean destroying. At least as far as I understand it.

Also wglMakeCurrent(NULL, NULL) is frequently used to switch rendering contexts. It can be usedby a certain thread to switch between rendering contexts or to allow different (sync) threads to use the same rendering context. Again, at least as I understand these things.

And one last thing, there's no -1000 error code on NVIDIA.

Since the effort to make sure the openGL context is current when calling clCreateContext is acceptable, I will take this approach. However, it still seems to me the AMD implementation of the OpenCL is not according to the specifications.


Attachment is the opencl-1.2-extension. Page39 ~


Your attachment contains a description of the error CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR

But I still don't get it, why is this error returned? The OpenGL context is very much valid.

wglMakeCurrent(NULL, NULL) doesn't destroy it and wglDeleteContext is not called. To prove this once again add wglMakeCurrent(hDC, hRC) just after wglMakeCurrent(NULL, NULL) and you'll see that clCreateContext works without any error.

I have attached myself a page from the OpenCL documentation I was referring to early in my first post.


As the extension said: "If no OpenGL or OpenGL ES context or share group is specified in the attribute list, then memory objects may not be shared, and calling any of the commands in  section 9.7 will result in a CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR error." And now, it returns -1000. Besides, when I changed the attribute list, the error gone. And when you added wglMakeCurrent(hDC, hRC), the error gone too. So in this way, we can draw a conclusion: wglMakeCurrent(NULL, NULL) maybe has an effect on OpenGL or OpenGL ES context. But what's the detail, I don't know, I haven't seen any specification about this yet.


I already experienced the -1000 return value. I had 2 graphics cards on my computer (one AMD, one NVIDIA) and I was trying to create a context from AMD platform with my main screen plugged on the NVIDIA cards, It resulted in a -1000 return error.

I fixed it by properelly  querying and selecting the right platforms for the main screen.