0

I found some special GLSL writing style will make iPhone 6 Plus crash without any log.

For example, if you write GLSL like code below, it would crash at glLinkProgram.

float testFun(float co) {
    return co;
}

float a = testFun(0.1);

void main()
{
    // your code here
}

But if you move the define of "a" into a function, then it would work correctly.

This wouldn't happen in iPhone5 or 5s.

You could reproduce this bug by download the sample project at

http://www.raywenderlich.com/3664/opengl-tutorial-for-ios-opengl-es-2-0

then replace SimpleFragment.glsl with

varying lowp vec4 DestinationColor;

varying lowp vec2 TexCoordOut; // New
uniform sampler2D Texture; // New

precision highp float;

float testFun(float co) {
    return co;
}

float a = testFun(0.1);

void main()
{
    gl_FragColor = vec4(0.7, 0.5, 0.3, 1.0);
}

and run it on your iPhone 6 Plus. It would crash immediately.

2
  • What's your question? This looks more like a bug report. Which should probably go to Apple. Dec 5, 2014 at 2:06
  • Thankyou very much. Already reported to Apple
    – chenxiao07
    Dec 19, 2014 at 6:00

2 Answers 2

1

At first, these 3 iPhone you mentioned have 3 different GPU:

  • iPhone 5 -> SGX543
  • iPhone 5s -> A7
  • iPhone 6/Plus -> A8

That means it probably have different driver in iOS, and the glsl shader compile implement will also may be different, but no one actually knows that except Apple's guy. On your side, that means you really need to run/debug your App on real device, but not soft simulator.

On the other hand, your iPhone 5/5s/6 Plus are on the same iOS version, right? [I assume yes, ;)]

Turn back to your question, I think your should not use a global variable like c in your glsl shader, since there are no stack/heap storage layout in shader, but most variables are register.

That means your float a; will hold a register place, and that's limited resources in GPU! it's not recommended to use global variable in glsl, or more clear, in most program language, I think.

You can try to check the status about your shader using the function call like below for more detail explain about your shader's compile failure:

glGetProgramiv(program, GL_LINK_STATUS, &link_status);
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
glGetProgramInfoLog(program, length, NULL, &log[0]);

Hope it helps.

0

Your shader code contains an error. This line is invalid:

float a = testFun(0.1);

In the ES 2.0 GLSL spec, section "4.3 Storage Qualifiers" on page 29 says (emphasis added):

Declarations of globals without a storage qualifier, or with just the const qualifier, may include initializers, in which case they will be initialized before the first line of main() is executed. Such initializers must be a constant expression.

Now the question becomes if testFun(0.1) is a constant expression. Section "5.10 Constant Expressions" on page 49 clarifies that:

The following may not be used in constant expressions:

  • User-defined functions

The fact that the shader compiler crashes looks like an Apple bug. File it with them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.