【问题标题】:how to create CL GL interop context?如何创建 CL GL 互操作上下文?
【发布时间】:2018-09-04 03:07:37
【问题描述】:

对于 openGL,我使用 lwjgl,对于 openCL,我使用 jocl。

我的显卡 rx550。

操作系统 win10pro。

这是我的 GL Init 方法,我先运行它。

static long window;

static void initGL(){
    if(glfwInit()!=true){
        System.err.println("INIT_GLFW_FAILED");
        System.exit(1);
    }

    window=glfwCreateWindow( w, h, "test", 0, 0);
    glfwShowWindow(window);
    glfwMakeContextCurrent(window);
    GL.createCapabilities();

    glViewport(0, 0, w, h);
    glOrtho(0, w, h, 0, -1, 1);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_TEXTURE_3D);

}

这是我的 CL 初始化方法,我第二次运行它。

static void initCL(){
    CL.setExceptionsEnabled(true);

    int numPlatformsArray[] = new int[1];
    clGetPlatformIDs(0, null, numPlatformsArray);
    numPlatforms=numPlatformsArray[0];

    cl_platform_id platforms[] = new cl_platform_id[numPlatforms];
    clGetPlatformIDs(platforms.length, platforms, null);
    cl_platform_id platform = platforms[platformIndex];

    int numDevicesArray[] = new int[1];
    clGetDeviceIDs(platform, deviceType, 0, null, numDevicesArray);
    numDevices = numDevicesArray[0];

    cl_device_id devices[] = new cl_device_id[numDevices];
    clGetDeviceIDs(platform, deviceType, numDevices, devices, null);
    device = devices[deviceIndex];


    cl_context_properties contextProperties = new cl_context_properties();
    contextProperties.addProperty(CL_GL_CONTEXT_KHR, 
    glfwGetCurrentContext());//wglGetCurrentContext()
    contextProperties.addProperty(CL_WGL_HDC_KHR, wglGetCurrentDC());
    contextProperties.addProperty(CL_CONTEXT_PLATFORM, platform);

    context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU, 
    null, null, null);

    commandQueue = clCreateCommandQueue(context, device, 0, null);

    mprogram = clCreateProgramWithSource(context,1, new String[]{ program }, null, null);

    clBuildProgram(mprogram, numDevices, devices, null, null, null);

    mkernel = clCreateKernel(mprogram, "sampleKernel", null);

    System.out.println("CLinit done");
}

在这部分他说 CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR。

context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU, null, null, null);

我尝试将 glfwGetCurrentContext() 更改为 wglGetCurrentContext() 并更改为 window 但他又说了一遍。

但如果我删除这一行

contextProperties.addProperty(CL_WGL_HDC_KHR, wglGetCurrentDC());

他跑得很好,但如果我尝试把 texture3d 放

clCreateFromGLTexture3D(context, CL_MEM_READ_ONLY, GL_TEXTURE_3D, 0, GL_TEXTURE_3D, null);

他说 CL_INVALID_CONTEXT。

【问题讨论】:

    标签: java opengl opencl lwjgl jocl


    【解决方案1】:

    由于您使用 GLFW 来创建窗口/WGL 上下文,因此您应该确保使用 GLFW 的本机包装器来处理您的 WGL 上下文:

    http://www.glfw.org/docs/latest/group__native.html

    尝试设置

    contextProperties.addProperty(CL_WGL_HDC_KHR, wglGetCurrentDC());
    

    contextProperties.addProperty(CL_WGL_HDC_KHR, glfwGetWGLContext(window));
    

    还要确保上下文在使用时始终是最新的。

    glfwGetWGLContext 属于 GLFWNativeWGL 类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-08
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      相关资源
      最近更新 更多