opengl CL GL互操作性:CL上下文创建参数

nhhxz33t  于 2022-11-04  发布在  其他
关注(0)|答案(2)|浏览(193)

我一直在尝试创建绑定到OpenGL上下文的OpenCL上下文。我找不到KHRGLSharing.clGetGLContextInfoKHR方法查询可用设备所需的properties参数的适当值。OpenGL上下文是使用GLFW创建的,我要使用的窗口是当前上下文(使用glfwMakeContextCurrent设置)
下面的代码显示了我到目前为止所做的工作:

public static List<Long> queryDevicesForPlatform(long platform) {
        stack.push(); // MemoryStack defined elsewhere
        //Create properties
        //Problematic piece of code
        long[] properties =  switch (Platform.get()) {
            //These parameters let the JVM crash when clGetGLContextInfoKHR is called
            case LINUX -> new long[]{
                    CL_CONTEXT_PLATFORM, platform,
                    CL_GL_CONTEXT_KHR, GLX14.glXGetCurrentContext(),
                    CL_GLX_DISPLAY_KHR, GLX14.glXGetCurrentDisplay(),
                    0
            };
            //Not yet tested
            case MACOSX -> new long[]{
                    CL_CONTEXT_PLATFORM, platform,
                    CL_CGL_SHAREGROUP_KHR, CGL.CGLGetShareGroup(CGL.CGLGetCurrentContext()),
                    0
            };
            //This one works
            case WINDOWS -> new long[]{
                    CL_CONTEXT_PLATFORM, platform,
                    CL_GL_CONTEXT_KHR, glfwGetCurrentContext(),
                    CL_WGL_HDC_KHR, wglGetCurrentDC(),
                    0
            };
        };

        //Copy properties to a buffer
        ByteBuffer byteProp = stack.malloc(properties.length * Long.BYTES);
        byteProp.asLongBuffer().put(properties);
        ByteBuffer bytes = stack.malloc(Long.BYTES);

        //JVM crashes here
        int error = KHRGLSharing.clGetGLContextInfoKHR(PointerBuffer.create(byteProp),
                CL_DEVICES_FOR_GL_CONTEXT_KHR, (ByteBuffer) null, PointerBuffer.create(bytes));
        assert error == CL22.CL_SUCCESS: error;

        ByteBuffer value = stack.malloc((int) bytes.asLongBuffer().get(0));
        error = KHRGLSharing.clGetGLContextInfoKHR(PointerBuffer.create(byteProp), CL_DEVICES_FOR_GL_CONTEXT_KHR, value, null);
        assert error == CL22.CL_SUCCESS: error;
        LongBuffer devices = value.asLongBuffer();

        ArrayList<Long> ret = new ArrayList<>();
        while(devices.hasRemaining()) {
            ret.add(devices.get());
        }

        stack.pop();
        return ret;
    }

Linux:我不知道CL_CONTEXT_PLATFORMCL_GL_CONTEXT_KHRCL_GLX_DISPLAY_KHR要传递什么值。当前的SIGSEGV会导致JVM崩溃。
Windows:代码工作正常,但我不确定这是否是正确的方法。
苹果:我没有机器来测试这个,但如果我也知道正确的参数,我会很感激。

acruukt9

acruukt91#

Intel的Linux驱动程序不支持CL-GL interop(它缺少cl_khr_gl_sharing扩展)。如果驱动程序支持CL-GL interop,则代码片段应该可以在Linux上运行

3vpjnl9f

3vpjnl9f2#

使用我的非官方分支重试您的代码:https://github.com/kallaballa/compute-runtime/tree/clgl-fork。它与英特尔官方计算运行时的22.42.24548发布标签(https://github.com/intel/compute-runtime/releases/tag/22.42.24548)兼容。
cl_khr_gl_sharing回来了!

相关问题