husker-dev / openglfx

OpenGL implementation for JavaFX
Apache License 2.0
80 stars 10 forks source link

Intel Iris Xe compatibility issues #35

Closed yetyman closed 1 year ago

yetyman commented 1 year ago

Hello,

This is likely not an issue with your library, I would like to bring it to your attention on the off chance you might see something that I do not as I am fairly new to graphics programming.

When I set NVidia Control Panel to give my application the embedded graphics chip(Intel Iris Xe) on my laptop instead of its bigger embedded GPU(RTX 3050 laptop) I start getting issues. I recognize that this is a hardware issue however nothing I look up indicates any lack of support on the Intel Iris Xe and glView is indicating full support for everything.

for reference here's the simplified set of code in init() that leads the an Access_Violation_Exception everytime with the Intel Iris Xe but runs well with the 3050. Its a pretty basic shader program, I'm not aware of anything here being particularly advanced.


public void init(GLInitializeEvent event) {
        GLUtil.setupDebugMessageCallback(System.out);
        log.info("initializing");

        String gfxVendor = glGetString(GL_VENDOR);
        String gfxRenderer = glGetString(GL_RENDERER);
        String glLangLevel = glGetString(GL_VERSION);
        String slLangLevel = glGetString(GL_SHADING_LANGUAGE_VERSION);
        log.info("rendering via " + gfxRenderer + " with vendor " + gfxVendor + " with gl: "+glLangLevel + "  sl:"+slLangLevel);

        //region shader code
        String vertexShaderStr = loadFileStr("shader.vert");
        String fragShaderStr = loadFileStr("shader.frag");
        //endregion

        shaderPrgHandle = createShaderProgram(vertexShaderStr, fragShaderStr);
}

    private int createShaderProgram(String vertexShaderStr, String fragShaderStr) {
        int shaderHandle;
        int vertexShader = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource(vertexShader, vertexShaderStr);
        int fragShader = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource(fragShader,fragShaderStr);

        glCompileShader(vertexShader);

        String infoLogVert = getShaderLog(vertexShader);
        if (!infoLogVert.isBlank())
            log.info(infoLogVert);

        glCompileShader(fragShader);

        String infoLogFrag = getShaderLog(fragShader);
        if (!infoLogFrag.isBlank())
            log.info(infoLogFrag);

        //create a program pointer
        shaderHandle = glCreateProgram();

        CheckGPUErrors("error creating shader program");
        //slot in the shaders for this program
        glAttachShader(shaderHandle, vertexShader);
        glAttachShader(shaderHandle, fragShader);

        CheckGPUErrors("error attaching shaders to program");
        //compile a program with these settings at this pointer
        glLinkProgram(shaderHandle);

        CheckGPUErrors("error linking shader program");
        //remove the settings, the program is already compiled
        glDetachShader(shaderHandle, vertexShader);
        glDetachShader(shaderHandle, fragShader);
        glDeleteShader(fragShader);
        glDeleteShader(vertexShader);

        CheckGPUErrors("Error detaching and deleting shaders from program: ");

        return shaderHandle;
    }

The Access Violation occurs within org.lwjgl.opengl.GL20C.glLinkProgram(I)V+0 as you can see from this dump

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffe67ca9a58, pid=17416, tid=29688
#
# JRE version: OpenJDK Runtime Environment Corretto-17.0.5.8.1 (17.0.5+8) (build 17.0.5+8-LTS)
# Java VM: OpenJDK 64-Bit Server VM Corretto-17.0.5.8.1 (17.0.5+8-LTS, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# C  [igc64.dll+0x2129a58]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   https://github.com/corretto/corretto-17/issues/
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  S U M M A R Y ------------

Command Line: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:55199,suspend=y,server=n -javaagent:C:\Users\someone\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\223.8836.41\plugins\java\lib\rt\debugger-agent.jar -Dfile.encoding=UTF-8 com.mycompany.viewer.Main

Host: 12th Gen Intel(R) Core(TM) i7-12700H, 20 cores, 63G,  Windows 11 , 64 bit Build 22621 (10.0.22621.1635)
Time: Fri May 12 15:53:07 2023 Eastern Daylight Time elapsed time: 9.445569 seconds (0d 0h 0m 9s)

---------------  T H R E A D  ---------------

Current thread (0x00000214fb4e94f0):  JavaThread "QuantumRenderer-0" daemon [_thread_in_native, id=29688, stack(0x000000a8ef000000,0x000000a8ef100000)]

Stack: [0x000000a8ef000000,0x000000a8ef100000],  sp=0x000000a8ef0fa9c0,  free space=1002k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [igc64.dll+0x2129a58]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.lwjgl.opengl.GL20C.glLinkProgram(I)V+0
j  org.lwjgl.opengl.GL20.glLinkProgram(I)V+1
j  com.mycompany.jfx.rendering.canvas3d.opengl.GLPipelineManager.createShaderProgram(Ljava/lang/String;Ljava/lang/String;)I+123
j  com.mycompany.jfx.rendering.canvas3d.opengl.GLPipelineManager.init(Lcom/huskerdev/openglfx/events/GLInitializeEvent;)V+78
j  com.mycompany.jfx.rendering.canvas3d.opengl.OpenGLPartScanCanvas$$Lambda$295+0x0000000800f097c8.accept(Ljava/lang/Object;)V+8
j  com.huskerdev.openglfx.OpenGLCanvas.checkInitialization()V+84
j  com.huskerdev.openglfx.OpenGLCanvas.fireReshapeEvent(II)V+1
j  com.huskerdev.openglfx.core.implementations.InteropImpl.onNGRender(Lcom/sun/prism/Graphics;)V+273
j  com.huskerdev.openglfx.OpenGLCanvas$NGOpenGLCanvas.renderContent(Lcom/sun/prism/Graphics;)V+11
j  com.sun.javafx.sg.prism.NGNode.doRender(Lcom/sun/prism/Graphics;)V+330
j  com.sun.javafx.sg.prism.NGNode.render(Lcom/sun/prism/Graphics;)V+35
j  com.sun.javafx.sg.prism.NGGroup.renderContent(Lcom/sun/prism/Graphics;)V+151
j  com.sun.javafx.sg.prism.NGRegion.renderContent(Lcom/sun/prism/Graphics;)V+111
j  com.sun.javafx.sg.prism.NGNode.doRender(Lcom/sun/prism/Graphics;)V+330
j  com.sun.javafx.sg.prism.NGNode.render(Lcom/sun/prism/Graphics;)V+35
j  com.sun.javafx.sg.prism.NGGroup.renderContent(Lcom/sun/prism/Graphics;)V+151
j  com.sun.javafx.sg.prism.NGRegion.renderContent(Lcom/sun/prism/Graphics;)V+111
j  com.sun.javafx.sg.prism.NGNode.doRender(Lcom/sun/prism/Graphics;)V+330
j  com.sun.javafx.sg.prism.NGNode.render(Lcom/sun/prism/Graphics;)V+35
j  com.sun.javafx.sg.prism.NGGroup.renderContent(Lcom/sun/prism/Graphics;)V+151
j  com.sun.javafx.sg.prism.NGRegion.renderContent(Lcom/sun/prism/Graphics;)V+111
j  com.sun.javafx.sg.prism.NGNode.doRender(Lcom/sun/prism/Graphics;)V+330
j  com.sun.javafx.sg.prism.NGNode.render(Lcom/sun/prism/Graphics;)V+35
j  com.sun.javafx.sg.prism.NGGroup.renderContent(Lcom/sun/prism/Graphics;)V+151
j  com.sun.javafx.sg.prism.NGRegion.renderContent(Lcom/sun/prism/Graphics;)V+111
j  com.sun.javafx.sg.prism.NGNode.doRender(Lcom/sun/prism/Graphics;)V+330
j  com.sun.javafx.sg.prism.NGNode.render(Lcom/sun/prism/Graphics;)V+35
j  com.sun.javafx.tk.quantum.ViewPainter.doPaint(Lcom/sun/prism/Graphics;Lcom/sun/javafx/sg/prism/NodePath;)V+202
j  com.sun.javafx.tk.quantum.ViewPainter.paintImpl(Lcom/sun/prism/Graphics;)V+970
j  com.sun.javafx.tk.quantum.PresentingPainter.run()V+331
j  java.util.concurrent.Executors$RunnableAdapter.call()Ljava/lang/Object;+4 java.base@17.0.5
j  java.util.concurrent.FutureTask.runAndReset$$$capture()Z+44 java.base@17.0.5
j  java.util.concurrent.FutureTask.runAndReset()Z+5 java.base@17.0.5
j  com.sun.javafx.tk.RenderJob.run()V+1
j  java.util.concurrent.ThreadPoolExecutor.runWorker(Ljava/util/concurrent/ThreadPoolExecutor$Worker;)V+92 java.base@17.0.5
j  java.util.concurrent.ThreadPoolExecutor$Worker.run()V+5 java.base@17.0.5
j  com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run()V+8
j  java.lang.Thread.run()V+11 java.base@17.0.5
v  ~StubRoutines::call_stub

siginfo: EXCEPTION_ACCESS_VIOLATION (0xc0000005), writing address 0x00000000000004d6

if it is relevant, here are my shaders though I don't think I'm doing anything interesting here.

#version 330
in vec3 aPosition;
in int aColorIndex;
in vec2 aCorner;
uniform vec4 colorOptions[5];
uniform float sizeMultiplier;
uniform mat4 modelMats[5];
uniform mat4 invCameraPerspective;
uniform mat4 invCameraMats[2];
uniform float partRadius;
uniform vec3 perspectiveSpacePartCenter;
uniform float viewPortScale;
uniform vec2 viewPortSize;

out float opacity;
out vec2 texPos;
out vec4 pointColor;
void main()
{
    vec2 aspectRatioCorr = viewPortSize.yx * viewPortScale;
    vec3 pos = aPosition;
    vec4 pos4 = vec4(pos, 1.);
    for(int i = 0; i < modelMats.length; i++)
    {
        pos4 = modelMats[i] * pos4;
    }
    for(int i = int(invCameraMats.length-1); i >= 0; i--)
    {
        pos4 = invCameraMats[i] * pos4;
    }
    pos4 = invCameraPerspective * pos4;
    pos = vec3(pos4.xy/pos4.w, (pos4.z)/pos4.w);
    float centerZ = perspectiveSpacePartCenter.z;
    float zScale = 1.-clamp((pos.z-centerZ),-.25,.25);
    float size = viewPortScale * 2. * sizeMultiplier * zScale;
    opacity = zScale-.25;
    if(aColorIndex == int(20)){
      size = size*3.;
      pointColor = vec4(1.,0.,0.,1.);
    }else
      pointColor = colorOptions[aColorIndex];
    texPos = aCorner+vec2(.5,.5);
    vec3 perspectivePos = vec3(pos.xy + aCorner*size/aspectRatioCorr.yx, pos.z);
    gl_Position = vec4(perspectivePos.xyz, 1.0);
}
#version 330
out vec4 FragColor;
in vec4 pointColor;
in float opacity;
in vec2 texPos;

uniform float viewPortScale;
uniform vec2 viewPortSize;
uniform sampler2D pointSprite;
void main()
{
    vec4 tex = texture(pointSprite, texPos).rgba;
    if(tex.a < .75) discard;
    FragColor = vec4(pointColor.rgb * opacity * tex.rgb,1.);
}
husker-dev commented 1 year ago

Have you tried to use this code separately in default lwjgl with glfw?

yetyman commented 1 year ago

I have not. But I was able to figure out through trial and error that the Iris Xe chip is failing to support the Mat4[] parameters of my shader. It compiles, but the access violation is thrown inside the intel driver during the linkProgram call. if i replace the mat4[] uniform with individual mat4 uniforms the access violation no longer occurs. Strange stuff.