首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CL GL Interop: CL上下文创建参数

CL GL Interop: CL上下文创建参数
EN

Stack Overflow用户
提问于 2020-12-10 01:46:34
回答 1查看 45关注 0票数 0

我一直在尝试创建一个绑定到OpenGL上下文的OpenCL上下文。我找不到KHRGLSharing.clGetGLContextInfoKHR方法查询可用设备所需的properties参数的相应值。OpenGL上下文是使用GLFW创建的,我想使用的窗口是当前上下文(使用glfwMakeContextCurrent设置)

下面的代码片段展示了我到目前为止想出的东西:

代码语言:javascript
复制
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:代码可以工作,但我不确定这是不是正确的方法。

苹果:我没有机器来测试它,但如果我也知道正确的参数,我会很感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-03 06:06:07

英特尔的Linux驱动程序不支持CL-GL互操作(它缺少cl_khr_gl_sharing扩展)。如果驱动程序支持CL-GL互操作,则代码片段应在Linux上工作

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

https://stackoverflow.com/questions/65222179

复制
相关文章

相似问题

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