Skip to content

Instantly share code, notes, and snippets.

@aras-p
Created May 18, 2011 16:16
Show Gist options
  • Save aras-p/978908 to your computer and use it in GitHub Desktop.
Save aras-p/978908 to your computer and use it in GitHub Desktop.
Shader crashes on iPad 2
/* Both vertex & fragment shaders (define VERTEX or FRAGMENT before loading each).
Looks like crash caused by indexing into uniform array. Crash goes away if:
1) replacing array indices [i] with actual constants (0 & 1) and removing index math, OR
2) removing unrelated ALU ops (' - viewpos'), OR
3) rewriting shader to not be unrolled; using for (int i = 0; i < 2; ++i) loop.
Shader by itself does not make any practical sense, I just simplified a more complex shader to smallest that still crashes.
Crashes inside PVR driver on iPad 2, iOS 4.3:
#0 0x30efeb92 in UpdateShaderParams
#1 0x30eff5f2 in glrUpdateCtxSysVertexProgram
#2 0x30ef7b16 in glrUpdateVertexProgramInline
#3 0x30ef7cd8 in glrLoadCurrentPipelinePrograms
#4 0x30f00552 in gldUpdateDispatch
#5 0x35f77bb2 in gleDoDrawDispatchCore
#6 0x35efe5d2 in glDrawArrays_IMM_Exec
#7 0x30ea8ee2 in glDrawArrays
Does NOT crash on iPhone 3Gs (iOS 4.3).
*/
#ifdef VERTEX
uniform mat4 glstate_matrix_mvp;
uniform mat4 glstate_matrix_modelview0;
attribute vec4 _glesVertex;
uniform vec4 uniformPositions[4];
uniform vec4 uniformColors[4];
varying lowp vec4 varColor;
void main ()
{
highp vec3 viewpos = (glstate_matrix_modelview0 * _glesVertex).xyz;
highp vec3 col = vec3(0.0);
int i = 0;
col += uniformColors[i].xyz * length(uniformPositions[i].xyz - viewpos);
++i;
col += uniformColors[i].xyz * length(uniformPositions[i].xyz - viewpos);
++i;
gl_Position = glstate_matrix_mvp * _glesVertex;
varColor = vec4(col, 1.0);
}
#endif
#ifdef FRAGMENT
varying lowp vec4 varColor;
void main ()
{
gl_FragColor = varColor + vec4(0.7,0.2,0.1,0.0);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment