This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

This very simple shader fails to link on only some Mali GPUs

Some of our shaders fail to 'link' on some specific devices with Mali GPUs. These shaders have not failed on any non Mali GPU in at least last 13 months. On analyzing our debug logs we found that all of our shader failures in last few months are from Mali GPU devices only. Some of these devices report Android 6.0 as their OS, so they are not running very old software.

Some of the GPUs which fail: Mali-T624, Mali-T628, Mali-T720, Mali-T760 and Mali-T860.

Some of the Android devices which fail: Aqua 4G+, SM-J120A, SM-J200M, SM-T800, CP8298_I00, CRR-L09, E5506, F3216, F670S, P1ma40, SM-G903W, SM-G920P, SM-J120A, SM-J200GU, SM-J200M, SM-J700F, SM-J700M, TAB 2 A8-50F, Z820, SM-A510F

It is interesting that shaders work fine on some devices with these same GPUs and fail to link on other devices with same GPUs, I guess it could be due to different GPU driver versions etc...

 

I have tried the offline compiler using different parameters, but that succeeds as expected. Compiling succeeds on actual devices too, it is the linking which fails.

Here is the simplest of our shaders that fails to link. The shader compiler and linker logs are empty.

Here is the shader source, including the 'additions' done to shader code by cocos2dx game engine, We don't really use those extra uniforms added by cocos as we are not attaching these shaders to a cocos2dx object but its part of the final strings sent to GPU to be compiled and linked.

Vertex Shader:

precision highp float;
 precision highp int;
uniform mat4 CC_PMatrix;
uniform mat4 CC_MVMatrix;
uniform mat4 CC_MVPMatrix;
uniform mat3 CC_NormalMatrix;
uniform vec4 CC_Time;
uniform vec4 CC_SinTime;
uniform vec4 CC_CosTime;
uniform vec4 CC_Random01;
uniform sampler2D CC_Texture0;
uniform sampler2D CC_Texture1;
uniform sampler2D CC_Texture2;
uniform sampler2D CC_Texture3;
//CC INCLUDES END


        attribute vec4 a_position;
        attribute vec2 a_texCoord;
        varying vec2 v_texCoord;
        void main() {
            gl_Position = a_position;
            v_texCoord = a_texCoord;
        }

Fragment Shader:

precision mediump float;
 precision mediump int;
uniform mat4 CC_PMatrix;
uniform mat4 CC_MVMatrix;
uniform mat4 CC_MVPMatrix;
uniform mat3 CC_NormalMatrix;
uniform vec4 CC_Time;
uniform vec4 CC_SinTime;
uniform vec4 CC_CosTime;
uniform vec4 CC_Random01;
uniform sampler2D CC_Texture0;
uniform sampler2D CC_Texture1;
uniform sampler2D CC_Texture2;
uniform sampler2D CC_Texture3;
//CC INCLUDES END


        varying vec2 v_texCoord;
        uniform sampler2D texture0;
        void main() {
            vec4 color = texture2D(texture0, v_texCoord);
            color.rgb *= color.w;
            color.a = 1.0;
            gl_FragColor = color;
        }

 

We have already spent more than a week digging into why this could be, but we don't have a device which would fail. Only debug logs from an app published on play store. We can really use some help here.

Parents
  • Well, using the informations provided in the glLinkProgram manual page, I'll split the linking failure problems in two categories :

    Syntax errors

    • A vertex shader and a fragment shader are not both present in the program object.
    • The main function is missing for the vertex shader or the fragment shader.
    • A varying variable actually used in the fragment shader is not declared in the same way (or is not declared at all) in the vertex shader.
    • A reference to a function or variable name is unresolved.
    • A shared global is declared with two different types or two different initial values.
    • One or more of the attached shader objects has not been successfully compiled (via glCompileShader) or loaded with a pre-compiled shader binary (via glShaderBinary).

    GPU resources related errors

    • The number of active attribute variables supported by the implementation has been exceeded.
    • The storage limit for uniform variables has been exceeded.
    • The number of active uniform variables supported by the implementation has been exceeded.
    • Binding a generic attribute matrix caused some rows of the matrix to fall outside the allowed maximum of GL_MAX_VERTEX_ATTRIBS.
    • Not enough contiguous vertex attribute slots could be found to bind attribute matrices.

    The Syntax related problems should provoke a failure, no matter what.

    The GPU resources related can be figured out by running the OpenGL program on a development phone, or on a computer, and analyse it using an OpenGL tracing program like Mali Graphics Debugger or Apitrace . The former might provide more Mali GPU specific informations about the current GPU resources usage.

    You can then add informations about the current GPU GL_MAX_??? limits in the logs when glLinkProgram fails, using glGet, and compare them with the values of working systems.

    Also, don't forget to use glGetString and query the GL_RENDERER, and use Android methods to get the current Android version used, along with the current ROM name. It might be due to the current Android ROM abusing the GPU for some special desktop effects, or misconfiguring the GPU driver and leaving it with almost no system memory.

Reply
  • Well, using the informations provided in the glLinkProgram manual page, I'll split the linking failure problems in two categories :

    Syntax errors

    • A vertex shader and a fragment shader are not both present in the program object.
    • The main function is missing for the vertex shader or the fragment shader.
    • A varying variable actually used in the fragment shader is not declared in the same way (or is not declared at all) in the vertex shader.
    • A reference to a function or variable name is unresolved.
    • A shared global is declared with two different types or two different initial values.
    • One or more of the attached shader objects has not been successfully compiled (via glCompileShader) or loaded with a pre-compiled shader binary (via glShaderBinary).

    GPU resources related errors

    • The number of active attribute variables supported by the implementation has been exceeded.
    • The storage limit for uniform variables has been exceeded.
    • The number of active uniform variables supported by the implementation has been exceeded.
    • Binding a generic attribute matrix caused some rows of the matrix to fall outside the allowed maximum of GL_MAX_VERTEX_ATTRIBS.
    • Not enough contiguous vertex attribute slots could be found to bind attribute matrices.

    The Syntax related problems should provoke a failure, no matter what.

    The GPU resources related can be figured out by running the OpenGL program on a development phone, or on a computer, and analyse it using an OpenGL tracing program like Mali Graphics Debugger or Apitrace . The former might provide more Mali GPU specific informations about the current GPU resources usage.

    You can then add informations about the current GPU GL_MAX_??? limits in the logs when glLinkProgram fails, using glGet, and compare them with the values of working systems.

    Also, don't forget to use glGetString and query the GL_RENDERER, and use Android methods to get the current Android version used, along with the current ROM name. It might be due to the current Android ROM abusing the GPU for some special desktop effects, or misconfiguring the GPU driver and leaving it with almost no system memory.

Children