Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Interop problem......

Help
Anonymous
2011-12-11
2012-12-21

  • Anonymous
    2011-12-11

    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……

    // Context Creation

    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();

     
  • nythrix
    nythrix
    2011-12-12

    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