We have some generated shaders which trigger app crashes at link time on Nexus5 / Adreno330, whilst working on all other tested devices & GPUs (no other Adrenos tested though). Simply compiling and linking the shaders is enough to trigger the error, no rendering required.
While we've worked out which exact line in the fragment shader triggers the crash we need to understand a bit more about the underlying reason in order to implement a work-around in our code generator.
Fragment shader (this is where the trigger appears to be):
#ifdef GL_ES
#extension GL_OES_standard_derivatives : enable
# ifdef GL_FRAGMENT_PRECISION_HIGHprecision highp float;# elseprecision mediump float;# endif#endif#define g false#define h true#define i 1#define j 3#define k 3#define l 3#define m 3#define n 3#define o 3#define p 3#define q 3#define r 3#define s 3#define t 3uniform vec3 x[j], A[m], D[p], F[r], L;uniform float y[k], z[l], B[n], C[o], E[q], G[s];uniform int H[t];uniform sampler2D T, U;varying vec2 M;varying vec3 N, O, P, Q, R;varying float S;vec4 V(vec3 W, vec3 X, vec3 Y, vec3 Z, vec4 aa, float ab){vec3 ac = vec3(0.0, 0.0, 0.0);for (int ad = 0; ad < i; ++ad){vec3 ae = normalize(W - x[ad]);// float af = max(y[0], length(x[ad] - W) / z[ad]); // this worksfloat af = max(y[ad], length(x[ad] - W) / z[ad]); // this crashesfloat ag = clamp(float(dot(X, -ae)), 0.0, 1.2);vec3 ah = ((float(ag) * Y) * A[ad]) / pow(af, B[ad]);vec3 ai = normalize(Z + ae);float aj = float(clamp(float(pow(dot(X, ai), C[ad])), 0.0, 2.0));vec3 ak = ((aj * Q) * D[ad]) / pow(af, E[ad]);vec3 al = (Y * F[ad]) / pow(af, G[ad]);ac = ac + (((al + ah) + ak) * float(H[ad]));}return mix(vec4(ac, 1.0), aa, ab);}void main(){gl_FragColor = V(R, mat3(normalize(N), normalize(O), normalize(P)) * (g ? normalize((texture2D(T, M).xyz * 2.0) - 1.0) : vec3(0.0, 0.0, 1.0)), Q * (h ? texture2D(U, M) : vec4(1.0)).xyz, L, vec4(0.0, 0.0, 0.0, 0.0), S);}
Hi Remi - thanks for reporting this problem. At first attempt I'm not able to duplicate the crash using a development Adreno 330 device (no Nexus 5 available at the moment).
Are there any shader logs that are generated?
Do you have the logcat for the crash? (Also let us know the Adreno version that shows up in the log)
Is there a build version and date for the Nexus 5?
Do you an apk that you can share which duplicates the linker crash?
thanks...
Well, I don't seem to be able to attach anything else than .txt's, nor edit any other post than #1. Anyway, here is the repro case: https://www.dropbox.com/s/kddzvjag71v5w0x/LinkerCrash.apk
We picked up a Nexus 7 (2013 edition, obviously) and while the bug did not trigger with Android 4.3 (default install) it *did* show up once the device had been upgraded to 4.4.2
Kernel version 3.4.0-gac9222c, build time: Wed Nov 20 14:50:44 PST 2013. Build number: KOT49H
logcat:
We've been able to duplicate the crash on both Nexus 5 and Nexus 7 with the factory image builds:
N5 build
Android: 4.4.2
Baseband version: M8974A-1.0.25.0.23
Kernel version: 3.4.0-gadb2201 [email protected] #1 Wed Nov 20 14:42:53 PST 2013
Build number: KOT49H
N7 build
Android: 4.4.2
Kernel version: 3.4.0-gac9222c [email protected] #1 Wed Nov 20 14:50:44 PST 2013
Build number: KOT49H
However using a current open source 44 driver (https://developers.google.com/android/nexus/drivers) as well as a current internal driver, the app shows a green flashing screen. Likely the crash has been fixed.
Hi again,
Given that it crashes on the drivers that (presumably) the majority of consumers use it'd be really good to work around this bug on our side. Would it be possible for you to provide some details on what actually triggered the problem? It wouldn't be the first time we implemented workarounds in our code generator. :)
The fix is with our shader compiler doing agressive "optimization" on the indexing. You might try introudcing a temporary variable and copy the indexed variable into it: int temp = y[ad], and then use temp.
Thanks! Just naively replacing it didn't help but we'll see if we can get any further with it once our compiler team has some free time.