clCreateFromGLBuffer崩溃

时间:2018-10-16 17:46:15

标签: c++ opengl opencl sfml vbo

当我尝试将我的vbo与opencl一起使用时,调用clCreateFromGLBuffer时会崩溃

下面是重现此问题的小代码:

opengl上下文的初始化

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

opencl上下文的初始化

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;

创建顶点缓冲区对象

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

opencl缓冲区与opengl顶点缓冲区对象的链接

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

1 个答案:

答案 0 :(得分:0)

当我检查ret_num_devices的值时,得到2。如果更改代码以获取第二个设备的平台ID,则一切正常。因此,我想知道问题是否出在:为第二个平台(我的图形卡)创建了opengl上下文,而我试图访问我的cpu(第一个平台)的gpu。

如果是这样,您能解释一下如何检索与opengl使用的平台相对应的平台吗?