The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL and OpenCL
mariuszp


Joined: 05 May 2014
Posts: 2
Hello everyone!

As you know, SDL can create OpenGL contexts across various platforms. OpenCL can be a very useful tool when used with OpenGL (context sharing), for example to implement physics engines. I think it would be a good idea to implement OpenCL/OpenGL context sharing in SDL, as it appears to me that no such API exists yet.

The shared context is basically created by passing some properties to clCreateContextFromType(), but the actual properties are platform-specific. Therefore, I think we should add an SDL function like SDL_CreateComputeContext() that would take an OpenGL context and create an OpenCL context derived from it.

I could add this code myself, but I don't know my way around SDL code, so if someone could guide me to the right place, that would be appreciated. I also don't know how to commit this new code (I believe I must be approved first?). We could disable this functionality by default if that's what we need, and we could also create a dummy backend which always fails to create OpenCL contexts.

So what do you think guys?
mariuszp


Joined: 05 May 2014
Posts: 2
bump
SDL and OpenCL
Jonas Kulla
Guest

2014-05-05 21:04 GMT+02:00 mariuszp:
Quote:
Hello everyone!

As you know, SDL can create OpenGL contexts across various platforms. OpenCL can be a very useful tool when used with OpenGL (context sharing), for example to implement physics engines. I think it would be a good idea to implement OpenCL/OpenGL context sharing in SDL, as it appears to me that no such API exists yet.

The shared context is basically created by passing some properties to clCreateContextFromType(), but the actual properties are platform-specific. Therefore, I think we should add an SDL function like SDL_CreateComputeContext() that would take an OpenGL context and create an OpenCL context derived from it.

I could add this code myself, but I don't know my way around SDL code, so if someone could guide me to the right place, that would be appreciated. I also don't know how to commit this new code (I believe I must be approved first?). We could disable this functionality by default if that's what we need, and we could also create a dummy backend which always fails to create OpenCL contexts.

So what do you think guys?



For all three desktop platforms, the SDL_GLContext is just a typecasted native context
(GLXContext, HGLDC, NSOpenGLContext (last one is subclassed it seems)), so there you
have your first parameter almost for free. To get the second parameter on X11/Windows, look at
src/video/x11/SDL_x11video.h and src/video/windows/SDL_windowswindow.h. In Windows' case,
the HDC is directly stored in the window private data; on X11, the window struct has a pointer to
'struct SDL_VideoData' where you'll find the Display handle. On OSX, it seems all you need is
the context handle (and the share group created from it), you'll have to extract the lower level
CGLContextObj handle from the NSOpenGLContext first though.


That's all just from a few minutes of googling and looking through SDL's source code, I'm not
familiar with OpenCL so I'm not sure if this is enough (you'll probably need to check for
a necessary OpenCL extension too or something).