cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

adams
Journeyman III

OpenGL interop on CPU device type

Jump to solution

This might be a silly question, but is it possible to write to GPU texture with OpenCL context created from device type CL_DEVICE_TYPE_CPU? The version I am targetting is 1.2.

If the answer is no, is there any fast way I can copy image from OpenCL memeory to OpenGL texture in this scenario? Or am I forced to use clEnqueueReadImage and then glTexImage2D every frame?

Tags (3)
0 Likes
1 Solution

Accepted Solutions
dipak
Staff
Staff

Re: OpenGL interop on CPU device type

Jump to solution

I think, it should work as long as the CPU device supports cl_khr_gl_sharing extension and its in the list of all CL devices which may be associated with the specified OpenGL context queried using clGetGLContextInfoKHR . You may try following workflow:

// Say, you have declared the context property as below:

cl_context_properties props[] =

{

//OpenCL platform

  CL_CONTEXT_PLATFORM, (cl_context_properties)   platform,

//OpenGL context

      CL_GL_CONTEXT_KHR,   (cl_context_properties)   hRC,

//HDC used to create the OpenGL context

      CL_WGL_HDC_KHR,     (cl_context_properties)   hDC,

      0

    };

...

// Get the list of all CL devices which may be associated with the specified OpenGL context.

clGetGLContextInfoKHR(props, CL_DEVICES_FOR_GL_CONTEXT_KHR, listSize, deviceList, NULL));

// Check if the "deviceList" contains the CPU device and if so, find the CPU device from the "deviceList" using clGetDeviceInfo(..,CL_DEVICE_TYPE, …)

// Say, cpu device id is cpuDeviceId

// Then create a context only for CPU device

context = clCreateContext(props, 1, &cpuDeviceId, 0, 0, NULL);

// Now, its possible to share the GL texture or buffer

Regards,

View solution in original post

2 Replies
dipak
Staff
Staff

Re: OpenGL interop on CPU device type

Jump to solution

I think, it should work as long as the CPU device supports cl_khr_gl_sharing extension and its in the list of all CL devices which may be associated with the specified OpenGL context queried using clGetGLContextInfoKHR . You may try following workflow:

// Say, you have declared the context property as below:

cl_context_properties props[] =

{

//OpenCL platform

  CL_CONTEXT_PLATFORM, (cl_context_properties)   platform,

//OpenGL context

      CL_GL_CONTEXT_KHR,   (cl_context_properties)   hRC,

//HDC used to create the OpenGL context

      CL_WGL_HDC_KHR,     (cl_context_properties)   hDC,

      0

    };

...

// Get the list of all CL devices which may be associated with the specified OpenGL context.

clGetGLContextInfoKHR(props, CL_DEVICES_FOR_GL_CONTEXT_KHR, listSize, deviceList, NULL));

// Check if the "deviceList" contains the CPU device and if so, find the CPU device from the "deviceList" using clGetDeviceInfo(..,CL_DEVICE_TYPE, …)

// Say, cpu device id is cpuDeviceId

// Then create a context only for CPU device

context = clCreateContext(props, 1, &cpuDeviceId, 0, 0, NULL);

// Now, its possible to share the GL texture or buffer

Regards,

View solution in original post

adams
Journeyman III

Re: OpenGL interop on CPU device type

Jump to solution

Thank you for reply. I had some problems but the main reason why I couldn't use CPU device is that I didn't use clEnqueueAcquireGLObjects and clEnqueueReleaseGLObjects. For some reason I didn't need to do this while executing my kernels on AMD GPU device.

0 Likes