Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Problem with boolean expressions

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    7

    Unhappy 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:
    Code :
    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
    Last edited by danielkr; 11-30-2012 at 02:56 AM.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Mar 2009
    Posts
    153
    This seems like a compiler bug. I would try changing from do/while to simple while loop.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    7
    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).

  4. #4
    Junior Member Regular Contributor
    Join Date
    Mar 2009
    Posts
    153
    After looking at the code I think that you are missing the parenthesis. For example variant 2 should be like this:

    Code :
     
    continueLoop = (data.x - dimension) < 0 && (data.y - dimension) < 0 && (data.z - dimension) < 0;
    Last edited by randall; 11-30-2012 at 10:27 AM.

  5. #5
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    783
    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.

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    7
    Quote Originally Posted by arekkusu View Post
    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 :/
    Last edited by danielkr; 12-01-2012 at 09:15 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •