View Full Version : opengl 4.3 opencl interop small engine

12-14-2016, 06:48 AM
I must create a small opengl 4.3 engine ,where i can find an example or a tutorial for gl files and interop with opencl?
And what version of opencl you advice to me ?
how i can test compatibility with opencl ?
My gpu is a 4.3 opengl nvidia card.

Dark Photon
12-14-2016, 08:06 PM
I must create a small opengl 4.3 engine ... interop with opencl ... My gpu is a 4.3 opengl nvidia card.

You may want to do more reading and research before you go forward with OpenGL + OpenCL on an NVidia GPU. Based on what I know, I'd recommend against this combination.

5+ years ago when I implemented an OpenCL kernel to run in an OpenGL engine (on NVidia GPUs), I ended up having to use sledgehammer synchronization (read expensive) in the form of glFinish() (https://www.opengl.org/sdk/docs/man4/html/glFinish.xhtml) / clFinish() (https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clFinish.html) to swap the pipeline between OpenGL and OpenCL use. As far as I know, you still can't do any better on NVidia drivers.

Why? The Sync Object (https://www.opengl.org/wiki/Sync_Object) extensions defining the efficient alternative to this, namely ARB_cl_event (https://www.opengl.org/registry/specs/ARB/cl_event.txt) / cl_khr_gl_event (https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/gl_event.html), have been defined since 2010. Also, NVidia is typically pretty fast to implement new ARB/KHR extensions. So what's the problem? NVidia appears to be explicitly avoiding implementing these extensions (ARB_cl_event (https://www.opengl.org/registry/specs/ARB/cl_event.txt) is still not supported on recent NV drivers I'm running here). Why? I don't know for sure. But one possibility is that they are trying to discourage folks from using OpenCL in combination with OpenGL, so that (hopefully) they'll use CUDA, NVidia's proprietary compute language, instead.

If you care about cross-GPU vendor portability, my recommendation to you is to implement your compute kernels in OpenGL, either with ordinary GL vertex/geometry/fragment shaders, or GL compute shaders if needed. If you absolutely need to additionally use a separate compute language, consider whether using OpenCL with sledgehammer synchronization on NVidia is sufficient. If not, and if and only if you don't need portability to a non-NVidia GPU, consider using CUDA.

Some related links:

* Sharing textures with OpenCL (avoiding glFinish/clFinish) (https://forums.khronos.org/showthread.php/7392-Sharing-textures-with-OpenCL-(avoiding-glFinish-clFinish)?)
* Does NVidia support OpenCL SPIR? (https://stackoverflow.com/questions/22052832/does-nvidia-support-opencl-spir) (see Damon's comment from 2015)

12-18-2016, 07:17 AM
thanks dark photon for share your experiencing