clCreateFromGLBuffer上的分段错误

时间:2018-11-29 10:30:56

标签: c++ opengl interop opencl

我正在使用C ++。我正在使用OpenCL 2.1,gcc版本6.3.0 20170516(Debian 6.3.0-18)。我正在通过《 OpenCL编程指南》这本书学习OpenCL。我尝试互操作OpenCl / OpenGL。

GLuint initVBO(int vbolen)
{
    GLint bsize;
    GLuint vbo_buffer;
    glGenBuffers(1, &vbo_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, vbo_buffer);
    glBufferData(GL_ARRAY_BUFFER, vbolen*sizeof(float)* 4, NULL, GL_STREAM_DRAW);
    glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &bsize);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    return vbo_buffer;
}

cl_context CreateContext()
{
    cl_uint numPlatforms;
    cl_platform_id firstPlatformId;
    cl_context context = NULL;
    clGetPlatformIDs(1, &firstPlatformId, &numPlatforms);
    cl_context_properties contextProperties[] =
    {
        CL_CONTEXT_PLATFORM, (cl_context_properties)firstPlatformId,
        CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
        CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
        0
    };
    cl_uint uiDevCount;
    cl_device_id* cdDevices;
    clGetDeviceIDs(firstPlatformId, CL_DEVICE_TYPE_GPU, 0, NULL, &uiDevCount);
    cdDevices = new cl_device_id[uiDevCount];
    clGetDeviceIDs(firstPlatformId, CL_DEVICE_TYPE_GPU, uiDevCount, cdDevices, NULL);
    auto clDev = &cdDevices[0];
    context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
                                      NULL, NULL, &errNum);
    return context;
}

void CreateMemObjects(cl_context& context, GLuint texture, GLuint vbo, cl_mem *p_cl_vbo_mem, cl_mem *p_cl_tex_mem)
{
    cl_int errNum;
    cl_vbo_mem = clCreateFromGLBuffer(context, CL_MEM_READ_WRITE, vbo, &errNum);
    return true;
}

int main()
{
    vbo = initVBO(vbolen);
.......
    // Create an OpenCL context on first available platform
    context = CreateContext();
......
    CreateMemObjects(context, tex, vbo, &cl_vbo_mem, &cl_tex_mem);
......
}

当我创建Memory对象时,我遇到了分段错误。细分错误位于此api clCreateFromGLBuffer的函数CreateMemObjects()中。任何想法为什么我会出现此错误。

0 个答案:

没有答案