opengl - CL GL Interop:CL 上下文创建参数
问题描述
我一直在尝试创建一个绑定到 OpenGL 上下文的 OpenCL 上下文。我未能找到查询可用设备的方法properties
所需的参数的适当值。KHRGLSharing.clGetGLContextInfoKHR
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
。当前使 JVM 崩溃并带有SIGSEGV
.
Windows:代码有效,但我不确定这是否是正确的方法。
Apple:我没有机器可以对此进行测试,但如果我也知道那里的正确参数,我将不胜感激。
解决方案
英特尔的 Linux 驱动程序不支持 CL-GL 互操作(它缺少cl_khr_gl_sharing
扩展)。如果驱动程序支持 CL-GL 互操作,则代码片段应该可以在 Linux 上运行
推荐阅读
- html - 我已将带有拉丁字符和字形的字体导入到我的 css 样式表中,如何使字形而不是拉丁字符出现?
- ios - 子视图通过滚动从集合视图单元中消失
- python - Matplotlib:具有从主轴映射的值的辅助轴
- android - Firebase android 应用程序设置永远不会完成“与我们的服务器通信”步骤
- xamarin.forms - 如何在后台服务执行时保持跟踪
- c++ - OpenGL:在帧中回收帧缓冲区会损害性能吗?
- influxdb - 将多个值插入到 influxdb
- python - 减少 matplotlib 中的 y 刻度,字符串错误
- node.js - anagrams 数组程序和数组组结果
- swift - 为什么我存档的 Swift 应用程序看起来路径错误?