Pablitinho's picture

Interop OpenCL/OpenGL problem...... :(

Hi,

I am porting the Volume rendering example of NVIDIA to Cloo making use of OpenTK. The issue is that when I acquire the GL object, the buffer size of the variable pbo_cl still 0. Seems that there is not a right Binding..... I am lost and I dont know why this doesn't work. I tested also with textures and the same issue...... Thx in advance....

 
// Context Creation
 
[DllImport("opengl32.dll")]
extern static IntPtr wglGetCurrentDC();
//...
IntPtr glHandle = (GraphicsContext.CurrentContext as IGraphicsContextInternal).Context.Handle;
IntPtr wglHandle = wglGetCurrentDC();
ComputePlatform platform = ComputePlatform.GetByName("NVIDIA CUDA");
ComputeContextProperty p1 = new ComputeContextProperty(ComputeContextPropertyName.Platform, platform.Handle);
ComputeContextProperty p2 = new ComputeContextProperty(ComputeContextPropertyName.CL_GL_CONTEXT_KHR, glHandle);
ComputeContextProperty p3 = new ComputeContextProperty(ComputeContextPropertyName.CL_WGL_HDC_KHR, wglHandle);
ComputeContextPropertyList cpl = new ComputeContextPropertyList(new ComputeContextProperty[] { p1, p2, p3 });
ComputeContext context = new ComputeContext(ComputeDeviceTypes.Gpu, cpl, null, IntPtr.Zero);
CL.ComputeBuffer<uint> pbo_cl;
ComputeEventList ev = new ComputeEventList();
 
GL.Arb.GenBuffers(1, out pbo);
GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, pbo);
GL.Arb.MapBuffer(BufferTargetArb.ArrayBuffer, ArbVertexBufferObject.StreamDrawArb);
GL.Arb.BufferData(BufferTargetArb.ArrayBuffer, (IntPtr)(512* 512* 4*sizeof(byte)), IntPtr.Zero, BufferUsageArb.StreamDraw);
GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, 0);
 
 
pbo_cl = ComputeBuffer<uint>.CreateFromGLBuffer<uint>(oclContext, ComputeMemoryFlags.WriteOnly, (int)pbo);
 
List<ComputeMemory> PBO_CL = new List<ComputeMemory>() {  pbo_cl };
 
GL.Flush();
GL.Finish();
oclCQ.AcquireGLObjects(PBO_CL, ev); 
// After this... pbo_cl size continue to 0.
 
//OPENCL Calls.....
 
 
oclCQ.ReleaseGLObjects(PBO_CL, ev); 
oclCQ.Finish();
 

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nythrix's picture

This is a piece of code from one of my testing programs. And it does work:

GL.ClearColor(new Color4());                
GL.GenBuffers(1, out vbo);
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
GCHandle vboHandle = GCHandle.Alloc(position, GCHandleType.Pinned);
GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(Vector4.SizeInBytes * globalSize), vboHandle.AddrOfPinnedObject(), BufferUsageHint.StaticDraw);
vboHandle.Free();
GL.EnableClientState(ArrayCap.VertexArray);
clVboPos = ComputeBuffer<Vector4>.CreateFromGLBuffer<Vector4>(clContext, ComputeMemoryFlags.ReadWrite, vbo);

I use the GCHandle because VBO is not just plain numbers. Other than that I have no special code around.

Try a couple of things:
1) driver sanity check
2) see that opengl is properly initialized
3) check pbo initialization

Pablitinho's picture

Thx Nythrix,

Now it's working ok. It was a PICNIC.

Regards,

Pablo.