1 Reply Latest reply on Sep 3, 2012 1:45 AM by Wenju

    Weird OpenCL-GL sharing problem

    torandi

      Hi!

      I have a weird problem with opencl - gl context sharing. My program works in linux, but porting it to windows I have run into this problem:

       

      I create my cl context like this:

       

          cl_context_properties properties[] = {
                  CL_CONTEXT_PLATFORM, (cl_context_properties)platform_(),
              CL_WGL_HDC_KHR, (intptr_t) wglGetCurrentDC(),
              CL_GL_CONTEXT_KHR, (intptr_t) wglGetCurrentContext(),
              0
          };
      
      platform_.getDevices(CL_DEVICE_TYPE_GPU, &devices_);
      
      context_ = cl::Context(devices_, properties, &CL::cl_error_callback, nullptr, &err);
      
      err = clGetGLContextInfoKHR(properties, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof(device_id), &device_id, NULL);
      
      context_device_ = cl::Device(device_id);
      
      queue_ = cl::CommandQueue(context_, context_device_, 0, &err);
      

      And I get no errors. Creating shared buffers also works fine. Except they don't work. The memory is not actually shared, but is individual to cl/gl.

       

      Then I noticed that if i hardcoded the opencl contex to be created on the cpu instead the sharing worked. Really weird since I have verified that the opengl context is on the gpu, and CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR also proposes the GPU.

       

      The only difference I can find between my code and the SimpleGL sample is that I use SDL, while that code uses wglCreateWindow directly.

       

      Could anyone help? I'm really lost at this one.

       

      I would almost be happy with a way to detect this and use the cpu, it gives good enough performance.

       

      Update: I have found what makes it work/not work. If the shared buffer is slightly above 1 MB the sharing works, but if it is below, it doesn't work.