clCreateFromGLBuffer crash

Hello every one,

When I tried to use my vbo with opencl I get a crash when calling clCreateFromGLBuffer

Below a small code that reproduce the issue:


sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 2;
sf::Window window(sf::VideoMode(2048, 1024), "GAME",
        sf::Style::Fullscreen, settings);
glewInit();

cl_platform_id platform_id = NULL;
cl_device_id device_id = NULL;
cl_uint ret_num_devices;
cl_uint ret_num_platforms;
cl_int ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);

ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id,
        &ret_num_devices);

cl_context_properties props[] = { CL_GL_CONTEXT_KHR,
        (cl_context_properties) wglGetCurrentContext(), CL_WGL_HDC_KHR,
        (cl_context_properties) wglGetCurrentDC(), CL_CONTEXT_PLATFORM,
        (cl_context_properties) platform_id, 0 };

cl_context context = clCreateContext(props, 1, &device_id, NULL, NULL,
        &ret);

GLuint vboID_m = 0;
Creation of the vertex buffer object

glGenBuffers(1, &vboID_m);
glBindBuffer(GL_ARRAY_BUFFER, vboID_m);
{

    std::vector<float> tmp = { 0., 0., 0., 0., 0., 0., 0., 0., 0. };

    glBufferData(GL_ARRAY_BUFFER, (tmp.size()) * sizeof(float), 0,
    GL_STATIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER, 0, tmp.size() * sizeof(float),
            tmp.data());
}
glBindBuffer(GL_ARRAY_BUFFER, 0);

glFlush();

cl_int status;
clCreateFromGLBuffer(context, CL_MEM_READ_WRITE, vboID_m, &status);
return 0;

Thanks for your help!

Try glFinish() instad of glFlush()

Thanks for your reply, unfortunatly it doesn’t do the trick :frowning:

When I check the value of ret_num_devices, I get 2. If I change the code to get the platform id for the second device, every things works fine. So I am wondering if the problem is : The opengl context is created for the second platform (my graphic card) and I was trying to access the gpu of my cpu (first platform).

If this is true, Can you explain me how to retrieve the platform that correspond to the one used by opengl ?