GLSL ES: Nested boolean expressions evaluated incorrectly on PowerVR SGX 540 (Android)?

This topic contains 3 replies, has 2 voices, and was last updated by  Tobias Hector 4 years, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #31428

    pontomedon
    Member

    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
    {
    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.

    #37859

    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

    #37860

    pontomedon
    Member

    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.

    #37861

    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

Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.