尝试从OpenGL创建OpenCL上下文时出现共享组无效错误

h9vpoimq  于 2022-11-04  发布在  其他
关注(0)|答案(1)|浏览(197)

我从我的Windows应用程序中的clCreateContext(...)得到CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR(错误-1000),该应用程序已经初始化了OpenGL窗口。
代码为:

cl_platform_id platforms[4];
cl_uint numOfPlatforms;

clGetPlatformIDs(4, platforms, &numOfPlatforms);

cl_context_properties props[] =
{
    CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
    CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
    CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0]),
    0
};

cl_device_id devices[4];
cl_uint numOfDevices;

clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 4, devices, &numOfDevices);

cl_int createContextError;
auto clContext = clCreateContext(props, 1, devices, &pfn_notify, NULL, &createContextError);

我已经检查了当前设备的扩展,它确实支持cl_khr_gl_sharing
质量标准:

CPU:        AMD ThreadRipper 3960x
GPU:        Nvidia RTX2080s
OpenCL SDK: Khronos
0kjbasz6

0kjbasz61#

这个独立的可执行文件可以在我的笔记本电脑上运行。请在您的环境中检查它的输出。


# include <stdio.h>

# include <Windows.h>

# include <gl/GL.h>

# include <CL/opencl.h>

void CL_CALLBACK pfn_notify(const char *errinfo, const void *private_info, size_t cb, void *user_data) {
    fprintf(stderr, "OpenCL Error (via pfn_notify): %s\n", errinfo);
}

int main() {
    cl_platform_id platforms[4];
    cl_uint numOfPlatforms;
    char device_info[4096];
    char * found;

    clGetPlatformIDs(4, platforms, &numOfPlatforms);

    cl_context_properties props[] = {
        CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
        CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
        CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0]),
        0
    };

    cl_device_id devices[4];
    cl_uint numOfDevices;

    clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 4, devices, &numOfDevices);

    clGetDeviceInfo(devices[0], CL_DEVICE_EXTENSIONS, sizeof(device_info), device_info, NULL);
    found = strstr(device_info, "cl_khr_gl_sharing");

    if (found) fprintf(stdout, "cl_khr_gl_sharing supported\n");

    cl_int createContextError;
    auto clContext = clCreateContext(props, 1, devices, &pfn_notify, NULL, &createContextError);

    fprintf(stdout, "Context: %p\n", clContext);
}

输出量:

cl_khr_gl_sharing supported
Context: 0000022C7B2E5E70

质量标准:

CPU/GPU:    i5
OpenCL SDK: Khronos

相关问题