CL GL Interop:CL 上下文创建参数
CL GL Interop: CL context creation parameters
我一直在尝试创建一个绑定到 OpenGL 上下文的 OpenCL 上下文。我未能找到 KHRGLSharing.clGetGLContextInfoKHR
方法查询可用设备所需的 properties
参数的适当值。 OpenGL 上下文是使用 GLFW 创建的,我想要使用的 window 是当前上下文(使用 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:代码有效,但我不确定这是否是正确的方法。
Apple:我没有机器可以测试它,但如果我也知道那里的正确参数,我将不胜感激。
Intel 的 Linux 驱动程序不支持 CL-GL 互操作(它缺少 cl_khr_gl_sharing
扩展)。
如果驱动程序支持 CL-GL 互操作
,则代码片段应该适用于 Linux
我一直在尝试创建一个绑定到 OpenGL 上下文的 OpenCL 上下文。我未能找到 KHRGLSharing.clGetGLContextInfoKHR
方法查询可用设备所需的 properties
参数的适当值。 OpenGL 上下文是使用 GLFW 创建的,我想要使用的 window 是当前上下文(使用 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
.
Windows:代码有效,但我不确定这是否是正确的方法。
Apple:我没有机器可以测试它,但如果我也知道那里的正确参数,我将不胜感激。
Intel 的 Linux 驱动程序不支持 CL-GL 互操作(它缺少 cl_khr_gl_sharing
扩展)。
如果驱动程序支持 CL-GL 互操作