[英]Can't create OpenCL context sharing with EGL/OpenGLES context
I'm trying to use OpenCL interop with OpenGL-ES through the use of the cl_khr_gl_sharing extension.我正在尝试通过使用 cl_khr_gl_sharing 扩展将 OpenCL 与 OpenGL-ES 互操作。 But when I try to create an OpenCL context that would share with my OpenGL context, clCreateContext
fails with an error -59 (CL_INVALID_OPERATION).但是当我尝试创建一个与我的 OpenGL 上下文共享的 OpenCL 上下文时, clCreateContext
失败并显示错误 -59 (CL_INVALID_OPERATION)。
From the documentation ( OpenCL Docs ) the only possibility I see is that my "device [...] cannot support OpenCL objects which share the data store of an OpenGL object".从文档( OpenCL Docs )中,我看到的唯一可能性是我的“设备 [...] 无法支持共享 OpenGL 对象数据存储的 OpenCL 对象”。 I checked with clGetDeviceInfo
that the OpenCL device I'm using does support the extension: it does.我使用clGetDeviceInfo
检查我正在使用的 OpenCL 设备是否支持扩展:它支持。 What I'm trying right now is to use an offscreen render, but I tried to use a PBuffer surface, I also tried an onscreen rendering, still the same error.我现在正在尝试的是使用屏幕外渲染,但我尝试使用 PBuffer 表面,我也尝试了屏幕渲染,但仍然出现相同的错误。
I'm using EGL on Ubuntu 18.04.我在 Ubuntu 18.04 上使用 EGL。 Here is the info I get about my GPU when I inquire OpenGL and OpenCL:这是我在查询 OpenGL 和 OpenCL 时获得的有关 GPU 的信息:
OpenGL info ( glGetString
): OpenGL 信息( glGetString
):
Opengl context: NVIDIA Corporation : GeForce GTX 750 Ti/PCIe/SSE2 : OpenGL ES 3.2 NVIDIA 435.21
OpenCL Info ( clGetPlatformInfo
and clGetDeviceInfo
): OpenCL 信息( clGetPlatformInfo
和clGetDeviceInfo
):
CL_PLATFORM_PROFILE FULL_PROFILE
CL_PLATFORM_VERSION OpenCL 1.2 CUDA 10.1.0
CL_PLATFORM_NAME NVIDIA CUDA
CL_PLATFORM_VENDOR NVIDIA Corporation
CL_DEVICE_NAME GeForce GTX 750 Ti
CL_DEVICE_PROFILE FULL_PROFILE
CL_DEVICE_VENDOR NVIDIA Corporation
CL_DEVICE_VERSION OpenCL 1.2 CUDA
CL_DRIVER_VERSION 435.21
Here is the simplified version of the code I'm trying to run:这是我尝试运行的代码的简化版本:
int main()
{
/// OpenGL Setup
EGLDisplay egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(egl_dpy, NULL, NULL);
const EGLint config_attribs[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 16,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE};
EGLConfig cfg;
EGLint count;
eglChooseConfig(egl_dpy, config_attribs, &cfg, 1, &count);
eglBindAPI(EGL_OPENGL_ES_API);
static const EGLint attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
EGLContext core_ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs);
eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, core_ctx);
/// OpenCL setup
cl_platform_id platform_id = NULL;
cl_uint ret_num_platforms;
auto retPlat = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
if (retPlat != CL_SUCCESS)
{
assert(0);
}
cl_device_id device_id = NULL;
auto retDev = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
if (retDev != CL_SUCCESS)
{
assert(0);
}
cl_context_properties props[] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platform_id, CL_GL_CONTEXT_KHR,
(cl_context_properties)eglGetCurrentContext(), CL_EGL_DISPLAY_KHR,
(cl_context_properties)eglGetCurrentDisplay(), 0};
cl_int retContext;
cl_context myContext = clCreateContext(props, 1, &device_id, NULL, NULL, &retContext);
if (retContext != CL_SUCCESS)
{
std::cout << "clCreateContext " << retContext << "\n";
assert(0);
}
}
I found the problem.我发现了问题。 It seems that the Nvidia OpenCL driver does not support OpenGL sharing with EGL contexts.似乎 Nvidia OpenCL 驱动程序不支持与 EGL 上下文的 OpenGL 共享。 I was able to trace in the OpenCL library, and noticed a switch statement that was returning this particular error if the CL_EGL_DISPLAY_KHR
property was used.我能够在 OpenCL 库中进行跟踪,并注意到一个 switch 语句,如果使用了CL_EGL_DISPLAY_KHR
属性,该语句将返回此特定错误。 If I use a GLX OpenGL context instead, everything runs fine.如果我改用 GLX OpenGL 上下文,则一切正常。 I don't know how they could document this fact better, but it would have saved me a week.我不知道他们如何才能更好地记录这一事实,但它可以为我节省一周时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.