首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >glFinish永远挂在clEnqueueReleaseGLObjects之后

glFinish永远挂在clEnqueueReleaseGLObjects之后
EN

Stack Overflow用户
提问于 2016-04-02 11:19:54
回答 1查看 485关注 0票数 4

下面的代码运行良好(Windows7,NvidiaGTX750Ti)与Nvidia驱动程序361.91 (及更早),但挂起更新版本,如364.72和368.69。现在,glFinish只在调用clEnqueueReleaseGLObjects之后才阻止程序的执行。在指责驱动程序之前,我怀疑我的OpenCL/OpenGL互操作有什么问题,下面是一个小程序的代码,它复制了这个问题,问题就在最后:

代码语言:javascript
运行
复制
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include <SDL.h>
#include <gl/glew.h>
#include <SDL_opengl.h>
#include <gl/glut.h>

#pragma comment (lib, "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v7.5\\lib\\x64\\OpenCL.lib")
#include <CL/cl.h>
#include <CL/cl_gl.h>

cl_int init_cl_context(cl_context *context, cl_command_queue *command_queue)
{
    cl_int i, ret, pf_index=-1;
    cl_platform_id  platform_id[16];
    cl_device_id    device_id[16];
    cl_uint     ret_num_platforms;
    cl_uint     ret_num_devices;

    ret = clGetPlatformIDs(sizeof(platform_id)/sizeof(*platform_id), platform_id, &ret_num_platforms);  // get all the platforms

    for (i=0; i<ret_num_platforms; i++)     // go through all the platforms
    {
        ret = clGetDeviceIDs(platform_id[i], CL_DEVICE_TYPE_GPU, sizeof(device_id)/sizeof(*device_id), device_id, &ret_num_devices);    // get all the suitable GPU devices

        if (ret_num_devices > 0)        // stop trying platforms when a suitable device is found
        {
            pf_index = i;
            break;
        }
    }

    cl_context_properties properties[] = { CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(), CL_CONTEXT_PLATFORM, (cl_context_properties)platform_id[pf_index], 0 };
    *context = clCreateContextFromType(properties, CL_DEVICE_TYPE_GPU, NULL, NULL, &ret);
    *command_queue = clCreateCommandQueue(*context, device_id[0], 0*CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | 0*CL_QUEUE_PROFILING_ENABLE, &ret);

    return ret;
}

int main(int argc, char *argv[])
{
    cl_int ret=0;
    int w = 800, h = 600;
    SDL_Window *window;
    SDL_Renderer *renderer;
    cl_context context;
    cl_command_queue command_queue;
    cl_mem cltex;           // CL buffer of type image_2d_t pointing to the GL texture
    uint32_t gltex;         // ID of the GL texture for cltex

    //**** Init SDL, OpenGL/glew ****
    SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_AUDIO);

    window = SDL_CreateWindow ("Title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_OPENGL);
    SDL_GetWindowSize(window, &w, &h);

    SDL_GL_CreateContext(window);
    glewExperimental = 1; 
    glewInit();

    renderer = SDL_CreateRenderer(window, -1, 0*SDL_RENDERER_PRESENTVSYNC);
    //-------------------------------

    ret = init_cl_context(&context, &command_queue);    // initialise the CL context to match GL as to make the interop possible

    // create an OpenGL 2D texture normally
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &gltex);                                   // generate the texture ID
    glBindTexture(GL_TEXTURE_2D, gltex);                                // binding the texture
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);        // specify texture dimensions, format etc

    cltex = clCreateFromGLTexture(context, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, gltex, &ret);   // Creating the OpenCL image corresponding to the texture (once)

    ret = clFinish(command_queue);
    //glFinish();                  // this works fine
    ret = clEnqueueReleaseGLObjects(command_queue, 1, &cltex, 0, 0, NULL);          // release the ownership from CL back to GL
    clFinish(command_queue);
    glFlush();

    printf("This blocks the execution forever:\n");
    glFinish();                   // this blocks everything
    printf("This never gets printed\n");

    return 0;
}

在我的大得多的程序中(它有完全相同的问题),在驱动程序更新之前,一切都运行得很完美,现在甚至在更新之前编译的二进制文件都显示了上面演示的相同的冻结。为了提高可读性,我删除了返回代码的检查,但是无论是在这个小程序中,还是在更大的程序中,都完全没有报告的问题。我看不出有什么明显的错误.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-14 12:09:53

很明显,我的问题来自于向后做事情,因为在我排队之前,我试图从前面的框架中获得结果。

如果在第一个框架中,我跳过了这个部分,然后直接对第一个任务进行排队,那么它就不再阻塞了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36372561

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档