我一直在尝试创建绑定到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_PLATFORM
、CL_GL_CONTEXT_KHR
和CL_GLX_DISPLAY_KHR
要传递什么值。当前的SIGSEGV
会导致JVM崩溃。
Windows:代码工作正常,但我不确定这是否是正确的方法。
苹果:我没有机器来测试这个,但如果我也知道正确的参数,我会很感激。
2条答案
按热度按时间acruukt91#
Intel的Linux驱动程序不支持CL-GL interop(它缺少
cl_khr_gl_sharing
扩展)。如果驱动程序支持CL-GL interop,则代码片段应该可以在Linux上运行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
回来了!