I have code similar to the following in one of my vertex shaders:
#define NUM_ITERATIONS /* some value /
bool found = false;
float value;
float limit = / some value /;
for(int i=0; i<NUM_ITERATIONS; i++)
{
float v = / calculated /;
if(!found && (v < limit || i == (NUM_ITERATIONS-1))
{
value = v;
found = true;
}
/ some more code /
}
This code, compiled on a Samsung Nexus S (Android 4.1.2, GL_RENDERER=“PowerVR SGX 540”, GL_VERSION=“OpenGL ES 2.0 build 1.8.GOOGLENEXUS.ED945322@2112805”) doesn’t work, the code inside the if seems to be executed always (at least) in the last run of the for loop, not (only) in the first iteration where (v < limit || i == (NUM_ITERATIONS-1) is true (it seems to ignore the bool found). If i change the code to
/ … /
if(!found)
{
if(v < limit || i == (NUM_ITERATIONS-1)
{
/ … /
}
}
/ … */
everything works as expected. The same (incorrect) behaviour also happens on a Kindle Fire HD (Android 4.0.3, GL_RENDERER=“PowerVR SGX 540”, GL_VERSION=“OpenGL ES 2.0 build 1.8@785978”), but not on an Apple iPad 1 (IOS 5.0, GL_RENDERER=“PowerVR SGX 535”, GL_VERSION=“OpenGL ES 2.0 IMGSGX535-63.14.2”)
I am able to (privately) share the full shaders, if it helps with debugging.
Edit: I forgot to mention that the first version of the shader works fine on (at least) an Adreno 320, a Mali-400 MP and an Nvidia Tegra 3.
Hi Pontomedon,
Sorry for the delay in getting back to you - I’ve investigated this and you’re right, it seems to be a weird compiler bug. I will submit a bug report for this - thanks for letting us know! Unfortunately there’s not much we can do in terms of actually fixing the compiler in devices out in the wild, but at least you’ve got a work around. Please let me know if you have any questions.
Regards,
Tobias
Hi Tobias!
Thanks for your response! I know there’s nothing you can do about the existing devices, but my shaders are so full of workarounds for bugs in other compilers/linkers that this little issue doesn’t matter at all, and it’s the only bug in the PowerVR driver that i’ve noticed so far
By the way, I don’t know if it helps, but i think the first version of the shader (with the combined boolean expression) worked fine on an iPad 1 (ios 5.0), which is an SGX 535 iirc, so it may be an Android specific issue.
Hi Pontomedon,
Glad to hear that ours are usually not too bad! Less glad about the number of workarounds though - that’s unfortunate
As for iOS, Apple writes their own shader compiler, using ours only as reference so it’s not surprising to hear that there are differences. It points to a bug in our reference code regardless, so hopefully we’ll get this fixed asap
Thanks,
Tobias