For other platforms (OSs) seems that is getting more time than hoped but finally the promising OpenGL interop is coming soon..
as in the last week the cl_gl_khr_sharing was published in Khronos registry and was also added to the specification document now at revision 48..
Right now seems that the support of OpenGL OpenCL in Snow is not source code stable as per the new release as the property for context creation changes from CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE to CL_CGL_SHAREGROUP_KHR and also requires to pass
in addition the current GL context CL_GL_CONTEXT_KHR..
Note that seems that OpenGL interop cannot created on contexts having CPU devices attached on this platform..
On all platforms this interop requires first creating an OpenGL context and then creating a OpenCL context passing info about the OpenGL context with is windowing system dependant (and also some info about the drawable associated to the OpenGL context in non Apple platforms).
On Apple platform a context with OpenGL interop is created by getting the CGL share group associated to the wished OpenGL context, and passing that to clCreateContext via the property (in first parameter) CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE.
See the following code snippet from Procedural Grass demo in compute_engine.cpp:
if(bUseOpenGLContext)
{
printf(SEPARATOR);
printf("Compute Engine: Using active OpenGL context...\n");
CGLContextObj kCGLContext = CGLGetCurrentContext();
CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
cl_context_properties akProperties[] = {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
(cl_context_properties)kCGLShareGroup, 0
};
// Create a context from a CGL share group
//
m_kContext = clCreateContext(akProperties, 0, 0, clLogMessagesToStdoutAPPLE, 0, 0);
}
else
{
uint uiAvailableDeviceCount = 0;
iError = clGetDeviceIDs(NULL, kRequestedDeviceType, uiCount, akAvailableDeviceIds, &uiAvailableDeviceCount);
if (iError != CL_SUCCESS)
{
printf("Error: Failed to locate compute device!\n");
return false;
}
m_kContext = clCreateContext(0, uiAvailableDeviceCount, akAvailableDeviceIds, NULL, NULL, &iError);
}
Also note that per new spec code below (defining cl_context_properties akProperties[]) should be changed to:
cl_context_properties akProperties[] = {
CL_GL_CONTEXT_KHR,
(cl_context_properties)wglGetCurrentContext(),
CL_WGL_HDC_KHR,
(cl_context_properties)wglGetCurrentDC(), 0
};
cl_context_properties akProperties[] = {
CL_GL_CONTEXT_KHR,
kCGLContext
CL_CGL_SHAREGROUP_KHR,
(cl_context_properties)kCGLShareGroup, 0
};
Some Apple demos use it as Nbody, Displacament mapping, Grass..
all you have to do to enable disable the support in it is via defining USE_GL_ATTACHMENT to 1 or 0.
If I remember correctly in Apple also there is a flag when creating a OpenGL context for specifying that we want that device where is created it supports OpenCL contexts also..
(for other OSes is similar functionality provided by the extension..)
I will try to update it with more info and perhaps provide samples for every OSs..
For more info see (perhaps you have to login in ADC): "Using OpenCL with OpenGL” section of "OpenCL Programming Guide for Mac OS X"
which is currently no avaiable.. (PDF)
Also seems that for AMD cards 10.6.2 update will make them finally robust and stable in OpenCL..
Also I have found bits in AMD SDK 2.0beta4 showing cl_gl_amd_sharing and also CAL GL interop..
The case of CAL GL interop is at least for smiling since it's reported as supported by the CAL API extensions reporting function since at least a year (see Everest builds in Windows which provide CAL information..) But noneless is in the Catalyst 9.11 (fglrx 8.67 in Linux )release
where finally we can find bits of calGLAssociate function and others as this.. Still not working as they aren't exported by CAL libraries..
Also the GL header (cl_gl.h) in AMD OpenCL SDK includes the bits of the extension..
The Nvidia OpenCL library shows no signs of OpenGL interop but you have to remind that the latest version released in late September 2009 was the same as released by 10 September to registered developers and the driver is dated 28 August 2009 so almost two months old now..
Also Nvidia is aware that this is a current limitation as it list with the release notes
This no precludes Nvidia SDK demos from having support for it/ making use of it..
You have to use #define GL_INTEROP in the source code or compile with -DGL_INTEROP..
Anyway this won't fully enable the demos as the context must be created with OpenGL interop,
basically:
(windows)
cl_context_properties akProperties[] = {
CL_GL_CONTEXT_KHR,
HGLRC handle,
CL_WGL_HDC_KHR,
(cl_context_properties)HDC handle, 0
};
(linux)
cl_context_properties akProperties[] = {
CL_GL_CONTEXT_KHR,
GLXContext handle,
CL_WGL_HDC_KHR,
(cl_context_properties)Display handle, 0
};
(windows&linux)
m_kContext = clCreateContext(akProperties, 0, 0, 0, 0, 0);
Interesting is how this will mix with say frameworks as GLUT, SDL, specific window creation code for OpenGL 3.0 contexts, etc..
If I had a cristall ball and made money predicting the future :-) I will say OpenGL interop is coming in Nvidia 195.xx series.. Yes that are supposed (by me) to have also CUDA 3.0 support and also Fermi support.. so is I think dependent on Fermi release but say before of the year
and perhaps in very late November/early December..
Note that I expect OpenGL interop improving in CUDA also with that release namely that CUDA supports texture interop (texture buffer object support) in addition to existing VBO, PBO to direct interop also (right now I think the interop is get copying buffers in GPU memory which is anyway fast (but reduces memory with buffer duplication))..
Note that this support was by error saying as supported by CUDA 2.2 beta release for registered develeopers back in March 2009 with first Nvidia 185.xx drivers..
For AMD I will be surprised if they have before end of the year (as they have much work left see my post on OpenCL exntesinos) and I will be happy if they have by late February or March 2009..
In the meantime I will try to provide OpenGL emulation in my OpenCL wrapper library for SDKs with image support..
I will update the post to show how to modify demos from AMD, Nvidia and Apple OpenCL SDKs to use
this extension..
Also the coming soon Windows demos of the Apple demos will have this enabled..
0 comments:
Post a Comment