[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] GLSL loops and constant expressions



Not having the possibility to use "while" loops or "for" loops with non-constant expressions is very, very sad.
As with some other things, like multiple rendering targets and depth texture formats, I knew the specs say that, but I hoped in some loose validation whenever the underlying GL implementation allows them.
Maybe these features (and others) deserve their extensions?
For example, the gl_FragData[i] is accepted only if i is zero, as the specs say that there is only a COLOR0_ATTACHMENT. But can we actually relax these limitations whenever the system is capable?
Sure, they won't work on all GL|ES 2.0 systems, but, as usual, a developer can ask the capabilities before going on.


Marco.



On 06/12/2010 22:04, Vladimir Vukicevic wrote:
I've noticed a number of demos (even some recent ones) are failing the shader validation/translation step due to using a non-constant expression in a for loop.  This is a limitation imposed by Appendix A of the GLSL ES spec, which WebGL is following, and which ANGLE is now validating.

For loops, as decribed in section 4 of appendix A are allowed with the following limitations:

   - one loop index
   - index has type int or float
   - for statement must have the form:
       for (type_specifier identifier = constant_expression ;
            loop_index op constant_expression ;
            loop_expression )
         statement

      where op is>  >=<  <= == or !=, and loop_expression is of the form
         loop_index++, loop_index--, loop_index += constant_expression, loop_index -= constant_expression

As described in section 5.10 of the GLSL ES spec, a constant expression is:

   - a literal value (e.g., 5 or true)
   - a global or local variable qualified as const excluding function parameters
   - an expression formed by an operator on operands that are constant expressions, including getting an element of a constant vector or a constant matrix, or a field of a constant structure
   - a constructor whose arguments are all constant expressions
   - a built-in function call whose arguments are all constant expressions, with the exception of the
texture lookup functions.

The following are not constant expressions:

   - User-defined functions
   - Uniforms, attributes and varyings.

In particular, a number of shaders are attempting to use a uniform value as a loop expression.  This won't work, and triggers validation failure (and thus a compilation failure at compileShader time).

     - Vlad
-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:


-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email: