Main Menu

SWT and OpenCL

Started by Kai, October 21, 2014, 11:07:35

Previous topic - Next topic

Kai

Hi,

I want to use SWT as windowing framework and can successfully create an OpenGL GLCanvas and use it.
Now, I want to use OpenCL with OpenGL sharing.

I saw that I can give CLContext.create a LWJGL Drawable instance and it takes care of the rest.

Now, while I am using SWT, I currently have no idea how to create such a Drawable from a GLCanvas.
Delving a little bit more into the LWJGL code it shows that I need to create a ContextGL, which I couldn't, since it is package-private.

Basically, I can obtain all information necessary to create an OpenCL sharing context from the GLCanvas: I have the underlying window system handle and I am sure I could get a hold on the GL context handle.

Now I just need to somehow deliver those handles to OpenCL initialization routines. But how?  :-\

Thanks for any help!

spasi

Would you consider using LWJGL 3.0 instead? It should be easier to figure out a solution.

Kai

I would have to git-clone it from https://github.com/LWJGL/lwjgl3.git and build it?
Or is it already in a Maven repository? According to the sources, it does not seem to be mavenized, so this would be a no? :-)

Kai

Okay, I have cloned it and tried to "ant" it inside a Visual Studio 2012 prompt, and the following errors were reported:

-link:
   [Linker]    Bibliothek "lwjgl64.lib" und Objekt "lwjgl64.exp" werden erstellt.
   [Linker] org_lwjgl_system_glfw_GLFW.obj : error LNK2019: Verweis auf nicht aufgel÷stes externes Symbol "_glfwInit" in Funktion "_Java_org_lwjgl_system_glfw_GLFW_nglfwInit@8".
   [Linker] org_lwjgl_system_glfw_GLFW.obj : error LNK2019: Verweis auf nicht aufgel÷stes externes Symbol "_glfwTerminate" in Funktion "_Java_org_lwjgl_system_glfw_GLFW_nglfwTerminate@8".
   [Linker] org_lwjgl_system_glfw_GLFW.obj : error LNK2019: Verweis auf nicht aufgel÷stes externes Symbol "_glfwGetVersion" in Funktion "_Java_org_lwjgl_system_glfw_GLFW_nglfwGetVersion@32".
   [Linker] org_lwjgl_system_glfw_GLFW.obj : error LNK2019: Verweis auf nicht aufgel÷stes externes Symbol "_glfwGetVersionString" in Funktion "_Java_org_lwjgl_system_glfw_GLFW_nglfwGetVersionString@8"
...


Any hints? I am using Windows 7 64-bit.

spasi

That's odd. Could you check if glfw3.lib exists in libs/windows/amd64? I could also use the full build log (do an "ant clean" first).

Kai

Oh, my bad!
Apparently, I was using somehow the wrong VS12 environment shell. There was (translated) "Developer prompt for VS2013", but I should have used "VS2013 x64 Cross Tools prompt".

Anywho, it compiled successfully.  :)

Thanks so far!

I will now have a look at the new lwjgl3 and how I would go about using SWT with OpenGL and OpenCL.

spasi

See src/tests/org/lwjgl/demo/opencl/Mandelbrot.java, line 188, where the OpenCL context properties are being initialized. Unlike LWJGL 2, you'll find that you have access to everything you need to make CL/GL interop work, assuming the SWT managed context is current in the current thread.

Kai

Thank you!

That is awesome. LWJGL is again just what I needed: A very thin enabling technology for OpenCL/OpenGL without any unnecessery object-oriented layer on top of it.

Right now, I have refactored my existing simple OpenCL code. Now, I get an exception when querying the platform for a list of devices of type CL_DEVICE_TYPE_GPU. Previously, in lwjgl 2.9 I did not get an exception but just a null List.
The exception now says: Error Code: 0xFFFFFFFF
which translates to: CL_DEVICE_NOT_FOUND
which is okay, because that platform only has a CPU type device.

But, the OpenCLException class has no way of querying the specific OpenCL exception (error code) in order to decide how to handle that exceptional case.
Could you please provide a getter in the OpenCLException class to query it for the OpenCL error code?

Thanks.

spasi

You're right, that's an unnecessary exception. I'll probably remove it, but in the meantime, you may use clGetDeviceIDs directly (the CLDevice constructors are public).