Hello Guest

[SOLVED] clCreateFromGLTexture2D/clCreateFromGLTexture access violation

  • 4 Replies
  • 4422 Views
Hi I'm trying to share a GLTexture with OpenCL (I have LWJGL debug mode on), I'm following this: https://software.intel.com/en-us/articles/opencl-and-opengl-interoperability-tutorial (Method 1:  Texture Sharing via clCreateFromGLTexture) I added the JVM log file

This line crashes the JVM:
Code: [Select]
long mem = CL10GL.clCreateFromGLTexture2D(context, flags, GL11.GL_TEXTURE_2D, 0, texture, errorBuffer);
It's the same with this:
Code: [Select]
long mem = CL12GL.clCreateFromGLTexture(context, flags, GL11.GL_TEXTURE_2D, 0, texture, errorBuffer);
This is the console output:
Code: [Select]
11:39:48 PM: Executing external task 'debug -Plwjgl.debug=true'...
:debugSetup UP-TO-DATE
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:run
23:39:48.958 [main] INFO  c.b.m.Hatch - 3.0.0b SNAPSHOT
[LWJGL] Version: 3.0.0b SNAPSHOT
[LWJGL] OS: Windows 8.1 v6.3
[LWJGL] JRE: 1.8.0_31 amd64
[LWJGL] JVM: Java HotSpot(TM) 64-Bit Server VM v25.31-b07 by Oracle Corporation
[LWJGL] Loaded library from org.lwjgl.librarypath: lwjgl
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL] Loaded native library: D:\Development\Projects\gamy\Java\JGame\natives\jemalloc.dll
[LWJGL] MemoryUtil allocator: JEmallocAllocator
[LWJGL] Loaded native library: D:\Development\Projects\gamy\Java\JGame\natives\glfw.dll
23:39:49.021 [main] INFO  c.b.m.u.OpenGLHandler - Using display: DELL S2340L(Hdmi) 1920x1080 R8 G8 B8 Hz60
[LWJGL] Loaded native library: C:\Windows\system32\opengl32.dll
[LWJGL] Failed to locate address for GL function glNamedBufferPageCommitmentARB
[LWJGL] Failed to locate address for GL function glVertexWeighthNV
[LWJGL] Failed to locate address for GL function glVertexWeighthvNV
[LWJGL] Failed to locate address for GL function wglCopyImageSubDataNV
[LWJGL] [GL] WGL_NV_copy_image was reported as available but an entry point is missing.
[LWJGL] Loaded native library: C:\Windows\system32\OpenCL.dll
23:39:50.235 [main] INFO  c.b.m.u.OpenCLHandler - There are 1 OpenCL platforms available
23:39:50.237 [main] INFO  c.b.m.u.OpenCLHandler - Sharing is caring ^^
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffcc13e814e, pid=13988, tid=8876
#
# JRE version: Java(TM) SE Runtime Environment (8.0_31-b13) (build 1.8.0_31-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.31-b07 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [nvopencl.dll+0x814e]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\Development\Projects\gamy\Java\JGame\hs_err_pid13988.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
:run FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with non-zero exit value -805306369

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 8.819 secs
Process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with non-zero exit value -805306369
11:39:57 PM: External task execution finished 'debug -Plwjgl.debug=true'.

this is what I'm using to generate the texture:
Code: [Select]
public int genTexture(final int width, final int height) {
        int textureId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);

        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)null);
        return textureId;
    }

This is how I'm initializing OpenCL (prints the sharing is caring message):
Code: [Select]
public void init() {
        logger.info("There are {} OpenCL platforms available", CLPlatform.getPlatforms().size());
        platform = CLPlatform.getPlatforms(new Filter<CLPlatform>() {
            @Override
            public boolean accept(CLPlatform object) {
                return object.getCapabilities().cl_khr_gl_sharing;
            }
        }).get(GameData.getSetting("clPlatform", 0));
        ArrayList<CLDevice> devices = (ArrayList<CLDevice>) platform.getDevices(CL10.CL_DEVICE_TYPE_GPU);
        if (devices.size() < 1) {
            devices = (ArrayList<CLDevice>) platform.getDevices(CL10.CL_DEVICE_TYPE_DEFAULT);
            if (devices.size() < 1) {
                devices = (ArrayList<CLDevice>) platform.getDevices(CL10.CL_DEVICE_TYPE_ALL);
            }
        }

        int dev = GameData.getSetting("clDevice", -1);
        if (dev > 0) {
            device = devices.get(dev);
            if(device != null) {
                if (supportsSharing()) {
                    logger.info("Sharing is caring ^^");
                } else {
                    logger.info("We're just a little shellfish");
                }
            }
        } else {
            for (int i = 0; i < devices.size(); i++) {
                if (devices.get(i).getCapabilities().cl_khr_gl_sharing || devices.get(i).getCapabilities().cl_APPLE_gl_sharing) {
                    logger.info("Sharing is caring ^^");
                    device = devices.get(i);
                    break;
                }
            }
        }

        if(device == null) {
            devices.get(0);
        }

        PointerBuffer buffer = BufferUtils.createPointerBuffer(3);
        buffer.put(CL10.CL_CONTEXT_PLATFORM).put(platform).put(0).flip();

        context = CL10.clCreateContext(buffer, device.address(), CREATE_CONTEXT_CALLBACK, MemoryUtil.NULL, errorBuffer);
        CLUtil.checkCLError(errorBuffer.get(0));

        queue = CL10.clCreateCommandQueue(context, device.address(), CL10.CL_QUEUE_PROFILING_ENABLE, errorBuffer);
        CLUtil.checkCLError(errorBuffer.get(0));
    }
« Last Edit: November 27, 2015, 08:24:14 by Max9403 »

*

Online spasi

  • *****
  • 2140
    • WebHotelier
Re: [BUG] clCreateFromGLTexture2D/clCreateFromGLTexture access violation
« Reply #1 on: November 26, 2015, 23:19:56 »
You must specify the OpenGL context to the properties list you pass to clCreateContext. This requires platform-specific code, but you can copy this example. For more details, see the information on cl_khr_gl_sharing in the OpenCL Extension Specification.

Re: [BUG] clCreateFromGLTexture2D/clCreateFromGLTexture access violation
« Reply #2 on: November 27, 2015, 08:23:58 »
Ahhh.... thank you, let me now repeatedly slam my face into my desk.

Any chance this could raise an exception instead of crashing the JVM?

*

Online spasi

  • *****
  • 2140
    • WebHotelier
I'm afraid not. According to the spec you should be getting a CL_INVALID_CONTEXT error. The access violation occurs inside the Nvidia driver, so it's a bug in their implementation.

Sounds like Nvidias new approach to their drivers -_-, still remember being locked out of opengl earlier this year.