1
votes

I am trying to find the OpenCL device closest to the current OpenGL context to do OpenCL/OpenGL Interop. Via the OpenCL extension clGetGLContextInfoKHR() and the CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR parameter I can ask for this device for a specific OpenCL platform and a specific (current) OpenGL context.

I have two OpenCL platforms on my MacBook Pro (OpenCL 1.1 (NVIDIA) and OpenCL 1.2 (Intel)). The strange thing is that for both platforms clGetGLContextInfoKHR() returns a result even if the OpenGL context is running on NVIDIA. Am I doing something wrong or doesn't clGetGLContextInfoKHR() always produce a unique result?

1

1 Answers

1
votes

To get your current context according to the current graphic card on a recent MBP, you can use :

CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(cgl_ctx);
cl_context_properties props[] =
{
    CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup,
    CL_CONTEXT_PLATFORM, (cl_context_properties)_platform,
    0
};

_context = clCreateContext(props, 0, NULL, NULL, NULL, &err);
err = clGetGLContextInfoAPPLE(_context, cgl_ctx, CL_CGL_DEVICE_FOR_CURRENT_VIRTUAL_SCREEN_APPLE, sizeof(_deviceID), &_deviceID, NULL);

where cgl_ctx is your CGLContextObj, _platform the platform you get with

unsigned int platformCount;
err = clGetPlatformIDs(1, &_platform, &platformCount);

and _context is your cl_context.