Problem with boolean expressions

Dear OpenGL-community,

I have the following problem with the OpenGL 4.3 Shader Language, NVIDIA GTX 680, driver 310.64 (driver 310.61 had the same issue).
A simplyfied code example is:


uniform uint dimension; // fixed at 512
void main()
{
    bool continueLoop = true;
    do
    {
        ivec3 data = // compute data, range of [0...512]
        
        // variant 1:
        continueLoop = data.x < dimension && data.y < dimension && data.z < dimension;

        // variant 2:
	continueLoop = data.x - dimension < 0 && data.y - dimension < 0 && data.z - dimension < 0;    

        // variant 3:
	continueLoop = data.x - dimension + 1 <= 0 && data.y - dimension + 1 <= 0 && data.z - dimension + 1 <= 0;    

        // variant 4:
	continueLoop = all(lessThanEqual(data - ivec3(dimension), ivec(0)));
    }
    while(continueLoop);
}

The problem is, that only for variant 1, the code executes correctly.
I cannot see any fault here, can someone give me a hint? Or is it a bug?

In my opinion, every variant is the same in terms of boolean algebra, right?
I even tried a lot of parenthesis and int-casting so the -dimension does not underflow or something.

Kind regards,
Daniel

This seems like a compiler bug. I would try changing from do/while to simple while loop.

Thanks for your answer.
I already have some workarounds for the problem, but using variant 4 would simplify the code when writing and reading (actutally, the expression is a lot more complex than above).

After looking at the code I think that you are missing the parenthesis. For example variant 2 should be like this:



continueLoop = (data.x - dimension) < 0 && (data.y - dimension) < 0 && (data.z - dimension) < 0; 

Read the “Implicit Conversions” section of the GLSL spec and it should be clear why variant 2 and 3 don’t work – a uint will never be less than zero.

Thank you for your answers.
I also tried explicit conversions with int(dimension), too. This did not work, either :confused:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.