Login  Register

Troubles with CL/GL interoperability

Posted by Andrew on May 04, 2017; 3:37pm
URL: https://forum.jogamp.org/Troubles-with-CL-GL-interoperability-tp4037954.html

I am trying to write very basic program using CL/GL interop, but problem appears -- JVM crashes with access violation exception while creating CLGLContext. Here is the code:

=====
    public static void main(String[] args) {
        JFrame window = new JFrame("test");
        GLCanvas c = new GLCanvas();
        c.addGLEventListener(new GLEventListener() {

            @Override
            public void init(GLAutoDrawable drawable) {
                GLContext context = drawable.getContext();
                CLGLContext clglContext = CLGLContext.create(context, CLDevice.Type.GPU); // access violation here
                System.out.println(clglContext);
            }

            @Override
            public void dispose(GLAutoDrawable drawable) {}
            @Override
            public void display(GLAutoDrawable drawable) {}
            @Override
            public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
        });
        c.setSize(300, 300);
        window.add(c);
        window.setSize(300, 300);
        window.pack();
        window.setVisible(true);
    }
=====

Any ideas/suggestions how to fix that?

UPD: Just realized that there is an official JogAmp GL/CL interop example, but it doesn't help much -- when I run it, the problem remains.
My platforms/GPU devices:
CLPlatform [name: Intel(R) OpenCL, vendor: Intel(R) Corporation, profile: FULL_PROFILE, version: OpenCL 1.2 ]
        CLDevice [id: 468205296 name: Intel(R) HD Graphics 4000 type: GPU profile: FULL_PROFILE]
CLPlatform [name: AMD Accelerated Parallel Processing, vendor: Advanced Micro Devices, Inc., profile: FULL_PROFILE, version: OpenCL 2.0 AMD-APP (2117.14)]
        CLDevice [id: 468587040 name: Capeverde type: GPU profile: FULL_PROFILE]
AMD platform is the one where the error arises. Intel one works perfectly.

UPD2: It seems like the cause is that Intel device is being selected as default device in JOGL, but in JOCL the default device is AMD device, and interoperability obviously isn't going to work. I can easily select which CL device to use, but cannot find a way to do it in JOGL (except for changing the default device globally for OS, but I'm not really comfortable with that).
The question now is: how can I select specific GL device to work with in JOGL?