Hello Guest

OpenCL

  • 69 Replies
  • 64443 Views
OpenCL
« on: February 10, 2010, 14:46:50 »
Hi,

a feature request.. maybe LWJGL could provide OpenCL wrappers too? It seems available on many platforms now..

Re: OpenCL
« Reply #1 on: February 10, 2010, 22:50:04 »
it will be nice, i'm agree too.

*

Offline Matzon

  • *****
  • 2242
Re: OpenCL
« Reply #2 on: February 11, 2010, 07:06:50 »
I am not sure what gain games will have for this? - but at any rate, I think that a patch would be more likely than someone from the existing contributors to work on this

*

Offline spasi

  • *****
  • 2160
    • WebHotelier
Re: OpenCL
« Reply #3 on: February 11, 2010, 10:41:16 »
LWJGL isn't used for games only and even games have a lot to gain out of OpenCL. Getting it in LWJGL is in my plans, but unfortunately I won't have time to work on it for the next 3 months (at least). So unless someone else decides to contribute, it's going to take a while.

*

Offline Momoko_Fan

  • *
  • 38
  • jME3 lead developer
Re: OpenCL
« Reply #4 on: February 20, 2010, 19:25:13 »
OpenCL is useful in games, two uses I can come up with is software skinning and particle updates. OpenCL is the only way to fully take advantage of SSE instructions in java.
Then again, you can already do that, with this project: http://www.jocl.org/. Surely a LWJGL integrated solution would be useful. Perhaps the two projects can work together or something.

*

Offline VeAr

  • *
  • 18
Re: OpenCL
« Reply #5 on: February 20, 2010, 22:05:15 »
Another argument for having OpenCL integrated with OpenGL in LWJGL, is that OpenCL can share data with OpenGL. OpenCL can work with OpenGL textures and buffers directly. For example it would be possible to generate geometry (vertex data) using OpenCL into a buffer, then to use that buffer for rendering the geometry using OpenGL. Performance wise this is optimal, because no copying is occurring, and it all can happen on the GPU.

*

Offline Matzon

  • *****
  • 2242
Re: OpenCL
« Reply #6 on: February 20, 2010, 22:33:01 »
From a brief glance at the site - it appears to not be tied to any API as such. You should be able to use it with LWJGL too?
I do not expect that the two API's can work together, without jocl doing a license change (currently L/GPL).

*

Offline princec

  • *****
  • 1931
    • Puppygames
Re: OpenCL
« Reply #7 on: February 21, 2010, 10:30:39 »
I don't think mixed licenses will hurt anyone's ability to use JOCL with LWJGL.
But at any rate: JOCL's there, it does the job, doesn't need any competition from an alternative implementation for now (especially considering its extremely niche interest).
An SSE/assembler library might be nice though...

Cas :)

Re: OpenCL
« Reply #8 on: February 28, 2010, 11:29:22 »
Another argument for having OpenCL integrated with OpenGL in LWJGL, is that OpenCL can share data with OpenGL. OpenCL can work with OpenGL textures and buffers directly.
That is proposed but not implemented afaik. Neither Nvidia nor ATI drivers seems support that, pretty poor.

*

Offline basil

  • **
  • 81
Re: OpenCL
« Reply #9 on: April 03, 2010, 14:35:18 »
afaik thats right. you cannot share a texture properly yet. works ok with buffertype stuff like PBO's and map unmap buffer but thats not realy helping yet.

anyway. you can create an opencl image from a gl texture but you cannot (probably) write or read it ... still, I managed to create such texture and at least read out the order, format and dimensions correctly.

one thing that would be realy helpful with lwjgl is a bit support with opencl context creation. the way I did it atm is something like this:

Code: [Select]
cl_context = clCreateContextFromType ( contextProperties, CL_DEVICE_TYPE_GPU, null, null, null );
where the properties are :

Code: [Select]
[... setup platforms ...]

cl_context_properties contextProperties = new cl_context_properties ();
contextProperties.addProperty ( CL_CONTEXT_PLATFORM, platforms [ 0 ] );

but then :

Code: [Select]
Class< org.lwjgl.opengl.Display > display = org.lwjgl.opengl.Display.class;

Field display_impl = display.getDeclaredField ( "display_impl" );
Field ctx          = display.getDeclaredField ( "context" );

display_impl.setAccessible ( true );
ctx.setAccessible ( true );

Method getHdc    = display_impl.get ( display ).getClass ().getDeclaredMethod ( "getHdc" );
Method getHandle = ctx.get ( display ).getClass ().getDeclaredMethod ( "getHandle" );

getHdc.setAccessible ( true );
getHandle.setAccessible ( true );

long       getHdcValue = ( Long ) getHdc.invoke ( display_impl.get ( display ));
ByteBuffer glHandle    = ( ByteBuffer ) getHandle.invoke ( ctx.get ( display ));

glHandle.rewind ();

contextProperties.addProperty ( CL_GL_CONTEXT_KHR, glHandle.getInt ( 0 ));
contextProperties.addProperty ( CL_WGL_HDC_KHR, getHdcValue );

works for windows and JOCL. clCreateFromGLTexture2D does not return with CL_INVALID_CONTEXT anymore.

very ugly, you may see my point :)
« Last Edit: April 03, 2010, 14:37:24 by basil »

*

Kai

Re: OpenCL
« Reply #10 on: April 26, 2010, 10:47:18 »
Quote
very ugly, you may see my point
Yeah, reflection is such a nice tool!

I currently want to integrate OpenCL into my OpenGL render framework, too, for some offscreen heightfield/normalmap generation computations for generated terrains. I currently do it via shaders but at some point this is becoming a real mess. Especially the fact that coordinates need to remap from pixel centroid positions to [0.0, 1.0] again for the whole viewport and things like that. OpenCL integration into LWJGL here would be REALLY nice.
And by "OpenCL integration" I merely mean the possibility to get low-level information, such as the context and drawable handles, out of LWJGL. JOGL does a fine job with that, according to the sample applications on the JOCL http://www.jocl.org/samples/samples.html site!

So for the meantime, doing it with reflection is the way I will go.

*

Offline basil

  • **
  • 81
Re: OpenCL
« Reply #11 on: April 26, 2010, 11:23:59 »
[...] JOGL does a fine job with that, according to the sample applications on the JOCL http://www.jocl.org/samples/samples.html site!

So for the meantime, doing it with reflection is the way I will go.
aye! the new version shows us a realy nice way to handle that stuff.

look up the initContextProperties function in JOCLSimpleGL3.java. CL_WGL_HDC_KHR, CL_GLX_DISPLAY_KHR, CL_CGL_SHAREGROUP_KHR .. all that stuff.

*

Offline basil

  • **
  • 81
Re: OpenCL
« Reply #12 on: September 09, 2010, 22:08:56 »
just to keep it complete .. with lwjgl v.2.5 we need to do something like that. notice how the way to access the context class changed :

Code: [Select]
Class< org.lwjgl.opengl.Display > display = org.lwjgl.opengl.Display.class;

Field display_impl = display.getDeclaredField ( "display_impl" );

display_impl.setAccessible ( true );

Drawable d          = org.lwjgl.opengl.Display.getDrawable ();
Method   getcontext = d.getClass ().getSuperclass ().getDeclaredMethod ( "getContext" );

getcontext.setAccessible ( true );

Object ctx       = getcontext.invoke ( d );

Method getHdc    = display_impl.get ( display ).getClass ().getDeclaredMethod ( "getHdc" );
Method getHandle = ctx.getClass ().getDeclaredMethod ( "getHandle" );

getHdc.setAccessible ( true );
getHandle.setAccessible ( true );

long       getHdcValue = ( Long ) getHdc.invoke ( display_impl.get ( display ));

ByteBuffer glHandle    = ( ByteBuffer ) getHandle.invoke ( ctx );

glHandle.rewind ();

contextProperties.addProperty ( CL_GL_CONTEXT_KHR, glHandle.getInt ( 0 ));
contextProperties.addProperty ( CL_WGL_HDC_KHR, getHdcValue );

... so we can use

Code: [Select]
Drawable d          = org.lwjgl.opengl.Display.getDrawable ();
Method   getcontext = d.getClass ().getSuperclass ().getDeclaredMethod ( "getContext" );

.. some good news about opencl v.1.1 :

http://gpgpu.org/2010/06/18/opencl-1-1-released

maybe now, if new drivers follow, we can do proper integration into opengl. :)
« Last Edit: September 11, 2010, 09:02:25 by basil »

*

Offline spasi

  • *****
  • 2160
    • WebHotelier
Re: OpenCL
« Reply #13 on: September 10, 2010, 00:38:39 »
Hey, just letting you know that I've started working on OpenCL support. It's been only a couple of days, so I'm still in the process of reading the specification and figuring out the best way to integrate this in LWJGL. I haven't used OpenCL before and I've no clue how long this is going to take, I'll try to give you an estimate early next week.

*

Offline basil

  • **
  • 81
Re: OpenCL
« Reply #14 on: September 11, 2010, 09:01:09 »
no hurry :) .. good news tho'!