我的计算机上有两个GPU,一个来自我的CPU,另一个来自我的图形卡。
我正在尝试使用opengl / opencl互操作功能。但是我被困在opencl上下文的创建中,我不知道如何识别opengl使用的两个平台/设备。
在上面的代码中,我应该在测试“ DEVICE MATCHING OPENGL ONE”中使用哪种功能来测试设备是否为OpenGL使用的设备,或者我应该怎么做来测试platform_id是否是好的?
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 2;
sf::Window window(sf::VideoMode(2048, 1024), "GAME",
sf::Style::Fullscreen, settings);
glewInit();
cl_platform_id platform_ids[16] = { NULL };
cl_device_id device_id = NULL;
cl_uint ret_num_devices;
cl_uint ret_num_platforms;
cl_platform_id platform_id = 0;
cl_int ret = clGetPlatformIDs(_countof(platform_ids), platform_ids,
&ret_num_platforms);
size_t n = 0;
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) platform_id, 0 };
for (size_t i = 0; i < ret_num_platforms; ++i) {
platform_id = platform_ids[i];
cl_device_id curDevices_id[16];
ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU,
_countof(curDevices_id), curDevices_id, &ret_num_devices);
for (cl_uint nDevices = 0; nDevices < ret_num_devices; ++nDevices) {
cl_device_id curDevice_id = curDevices_id[nDevices];
clGetGLContextInfoKHR_fn clGetGLContextInfo =
reinterpret_cast<clGetGLContextInfoKHR_fn>
(clGetExtensionFunctionAddressForPlatform(
platform_id, "clGetGLContextInfoKHR"));
if (clGetGLContextInfo) {
cl_device_id clGLDevice = 0;
props[5] =
reinterpret_cast<cl_context_properties>(platform_id);
clGetGLContextInfo(props,
CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,
sizeof(clGLDevice), &clGLDevice, &n);
if (DEVICE MATCHING OPENGL ONE) {
device_id = clGLDevice;
}
}
}
if (device_id) {
break;
}
}
cl_context context = clCreateContext(props, 1, &device_id, NULL, NULL,
&ret);
答案 0 :(得分:0)
使用Kronos认可的扩展名“ cl_khr_gl_sharing”。将使用clGetDeviceInfo返回CL_DEVICE_EXTENSIONS。
https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/cl_khr_gl_sharing.html