retrieve opencl platform that match the opengl one

Hello !

I have two gpu on my computer, one from my cpu and another one from my graphic card.

I am trying to use the opengl/opencl interop capabilities. But I am stuck at the creation of the opencl context, I don’t know how to identify which platform / device of the two one is used by opengl.

In the above code, which fonction should I use in the test “DEVICE MATCHING OPENGL ONE” to test if the device is the one used by OpenGL, or what should I do to test if the platform_id is the good one ?

sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 2;
sf::Window window(sf::VideoMode(2048, 1024), "GAME",
		sf::Style::Fullscreen, settings);

glewInit();

cl_platform_id platform_ids[16] = { NULL };
cl_device_id device_id = NULL;
cl_uint ret_num_devices;
cl_uint ret_num_platforms;
	
cl_platform_id platform_id = 0;
cl_int ret = clGetPlatformIDs(_countof(platform_ids), platform_ids,
			&ret_num_platforms);

size_t n = 0;

cl_context_properties props[] = { CL_GL_CONTEXT_KHR,
	(cl_context_properties) wglGetCurrentContext(), CL_WGL_HDC_KHR,
	(cl_context_properties) wglGetCurrentDC(), CL_CONTEXT_PLATFORM,
	(cl_context_properties) platform_id, 0 };

for (size_t i = 0; i < ret_num_platforms; ++i) {
	platform_id = platform_ids[i];
	cl_device_id curDevices_id[16];

    	ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU,
				_countof(curDevices_id), curDevices_id, &ret_num_devices);

	for (cl_uint nDevices = 0; nDevices < ret_num_devices; ++nDevices) {
		cl_device_id curDevice_id = curDevices_id[nDevices];

		clGetGLContextInfoKHR_fn clGetGLContextInfo =
				reinterpret_cast<clGetGLContextInfoKHR_fn> 
                   (clGetExtensionFunctionAddressForPlatform(
							platform_id, "clGetGLContextInfoKHR"));

		if (clGetGLContextInfo) {
			cl_device_id clGLDevice = 0;
			props[5] =
					reinterpret_cast<cl_context_properties>(platform_id);
			clGetGLContextInfo(props,
					CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,
					sizeof(clGLDevice), &clGLDevice, &n);

			if (DEVICE MATCHING OPENGL ONE) {
				device_id = clGLDevice;
			}
		}
	}
	if (device_id) {
		break;
	}
}

cl_context context = clCreateContext(props, 1, &device_id, NULL, NULL,
		&ret);

Thanks for your future help!

If you don’t get any leads here, you might try the OpenCL Forum on khronos.org.

This may be what you need: cl_khr_gl_sharing (see also clGetGLContextInfoKHR).

Unfortunatly this doesn’t help, both of the two device support cl_khr_gl_sharing