
OpenTK and Cloo - OpenCL/GL Interop
Posted Thursday, 22 April, 2010 - 01:51 by douglas125 inHi, I'm trying to get OpenCL/GL interop using Cloo and OpenTK, but I keep getting a Cloo.ComputeErrorCode.CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR error.
I'm using ATI Stream SDK 2.01 so I think I *should* be able to create a Context from OpenGL but...
I get the error just as I try to create the ComputeContext Ctx.
This is the code I try to run:
OpenTK.Graphics.IGraphicsContextInternal ctx = (OpenTK.Graphics.IGraphicsContextInternal)OpenTK.Graphics.GraphicsContext.CurrentContext; IntPtr raw_context_handle = ctx.Context.Handle; ComputeContextProperty p1 = new ComputeContextProperty(ComputeContextPropertyName.CL_GL_CONTEXT_KHR, raw_context_handle); ComputeContextProperty p2 = new ComputeContextProperty(ComputeContextPropertyName.Platform, ComputePlatform.Platforms[0].Handle); List<ComputeContextProperty> props = new List<ComputeContextProperty>() { p1, p2 }; ComputeContextPropertyList Properties = new ComputeContextPropertyList(props); try { ComputeContext Ctx = new ComputeContext(ComputeDeviceTypes.Gpu, Properties, null, IntPtr.Zero); ComputeErrorCode Error; unsafe { Cloo.Bindings.CL10.CreateFromGLBuffer(Ctx.Handle, ComputeMemoryFlags.CopyHostPointer | ComputeMemoryFlags.ReadWrite, bufs[0], &Error); } } catch { int i = 0; }
Any help is appreciated.
Thanks


Comments
Re: OpenTK and Cloo - OpenCL/GL Interop
This post looks familiar :)
As for the OpenTK part of the question I'm not really sure which OpenGL version we should use for interop. I've been trying 3.x contexts but the drivers might have had no such support back then.
I'm downloading the most recent CUDA release as we speak. I'll let you know, if I can put together a working CL/GL environment.
Re: OpenTK and Cloo - OpenCL/GL Interop
Thanks nythrix
I'm really looking forward to putting CL/GL together I hope it becomes possible soon.
Re: OpenTK and Cloo - OpenCL/GL Interop
Assuming you're running Windows you also need specify
ComputeContextProperty p3 = new ComputeContextProperty(ComputeContextPropertyName.CL_WGL_HDC_KHR, wglHandle);but I'm not sure where we can find the WGL handle.
Does anyone know if this handle is stored somewhere near GraphicsContext? Or do we have to
wglGetCurrentDC()?Re: OpenTK and Cloo - OpenCL/GL Interop
Good news! I managed to create a CL GL context. Add these to your code and you should be good to go:
Re: OpenTK and Cloo - OpenCL/GL Interop
Hey it looks like it worked!
Wow your solution is much better, thanks!
EDIT:
Awesome, it works!!!
You just can't forget the Finish instructions:
Re: OpenTK and Cloo - OpenCL/GL Interop
Hi all, using the examples from
http://www.cmsoft.com.br/index.php?option=com_content&view=category&layo...
It seems that the following code works on ATI cards
but it does not work on my Nvidia 9 series card using the latest Cuda 3.01 driver and cloo.dll (0.72)and the OpenTK (1.0rc1). (FYI: this card passes the c++ sdk examples on openGL-OpenCL interop).
after some trial and error, the following works.
Anyone else has similar experience?
Re: OpenTK and Cloo - OpenCL/GL Interop
Hi, you cannot use CopyHostPointer in this case because that is a flag related to memory allocation. Here you're not allocating memory but sharing it between OpenGL and OpenCL. NVidia's implementation/behaviour is correct (http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clCreateFromGL... see flags argument).
Re: OpenTK and Cloo - OpenCL/GL Interop
This is correct. Maybe AMD OpenCL drivers just ignore the CopyHostPointer whereas NVidia's (correctly) don't. Thanks for pointing it. Tutorial is now fixed too.
Re: OpenTK and Cloo - OpenCL/GL Interop
hi there! i want to run the tutorial source of the cmsoft site, too (same link as LikeTK has given).
it gives me an nullpointerexception:
my notebook runs ubuntu 10.04 64bit, mono 2.63, stream sdk 2.2.
i dont have a opencl capable graphic card installed (old ati 2600 in this notebook).
i want to run it as cpu device.
what i tried: svn co'ed opentk and recompiled, replaced the opentk.dll and glcontrol.dll by the fresh compiled ones.
what i want to know is, is the error message related to opencl or is it a opengl-only error?
and is it actually possible to do opengl/cl interop runnig in cpu mode? in that case the cpu would
manipulate the vbo data directly, right?
thx for any advice,
boogi
Re: OpenTK and Cloo - OpenCL/GL Interop
This doesn't look like an OpenCL error. On the other hand, I'm not that good in recognizing OpenGL errors so it could be anything else. There's more experienced people around here that can tell why would GL.MatrixMode fail with the null reference thingy.
As for the second part of your question the answer would be no. CL/GL interop is restricted to GPUs. Otherwise the ComputeContext creation will fail with an InvalidOperationComputeException.