Search code examples
openglopenclgrand-central-dispatchgpgpumulti-gpu

glCreateSyncFromCLeventARB alternative?


I would like to save a call to clFinish() in OpenCL before using cl_command_queue result in OpenGL (I have a shared image/texture used in OpenCL/GL).

I found in the book "OpenCL Programming by Example" (p. 243) that creating a GLsync from an OpenCL event using glCreateSyncFromCLeventARB is the way to do this.

The problem is that this function seems to be unsupported on Apple platform.

I'm aware that Apple has their own way to implement OpenGL/OpenCL interoperability using GCD. However, I understand that this would require me to completely change my code and use a non standard OpenCL API for everything, and I want my code to be cross-platform (except minor adaptations where necessary).

Any other alternative to glCreateSyncFromCLEventARGB?


Solution

  • According to the OpenCL 1.1 specification, if an OpenCL platform or device supports the cl_khr_gl_event extension then you can skip the clFinish / glFinish calls.

    Specifically, in section 9.9.1 on p. 332 it says "In addition, this extension modifies the behavior of clEnqueueAcquireGLObjects and clEnqueueReleaseGLObjects to implicitly guarantee synchronization with an OpenGL context bound in the same thread as the OpenCL context." (emphasis mine)

    So you don't actually need to use the clCreateEventFromGLsyncKHR function that this extension enables, nor the rarely-found GL_ARB_cl_event extension unless you need other types of synchronization (other than what clEnqueueAcquireGLObjects and clEnqueueReleaseGLObjects supply).