1

对于 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() 和窗口,但他又说了一遍。

但是如果我删除这条线

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。

4

1 回答 1

0

由于您使用 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 类。

于 2018-03-26T16:45:21.753 回答