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

[Public WebGL] GLSL loops and constant expressions

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 )

     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: