[Mesa-dev] [PATCH RESEND v4] glsl: enforce invariant conditions for built-in variables

Lars Hamre chemecse at gmail.com
Tue Jun 21 17:37:44 UTC 2016


Gentle ping. I would appreciate feedbaçk on what (if anything) I
should do to get this patch into shape.

Regards,
Lars Hamre

On Mon, Jun 6, 2016 at 9:00 AM, Lars Hamre <chemecse at gmail.com> wrote:
> v2:
>  - ES version check (Tapani Pälli)
> v3/v4:
>  - compare varying slot locations rather than names (Ilia Mirkin)
>
> The conditions for which certain built-in special variables
> can be declared invariant were not being checked.
>
> GLSL ES 1.00 specification, Section "Invariance and linkage" says:
>
> For the built-in special variables, gl_FragCoord can
> only be declared invariant if and only if gl_Position is
> declared invariant. Similarly gl_PointCoord can only be
> declared invariant if and only if gl_PointSize is declared
> invariant. It is an error to declare gl_FrontFacing as invariant.
>
> This fixes the following piglit tests in spec/glsl-es-1.00/linker:
> glsl-fcoord-invariant
> glsl-fface-invariant
> glsl-pcoord-invariant
>
> Signed-off-by: Lars Hamre <chemecse at gmail.com>
>
> ---
>
> NOTE: Someone with access will need to commit this after the
>       review process
>
>  src/compiler/glsl/link_varyings.cpp | 39 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
>
> diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
> index 34c8906..755000e 100644
> --- a/src/compiler/glsl/link_varyings.cpp
> +++ b/src/compiler/glsl/link_varyings.cpp
> @@ -336,6 +336,9 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
>     ir_variable *explicit_locations[MAX_VARYINGS_INCL_PATCH][4] =
>        { {NULL, NULL} };
>
> +   bool is_gl_position_invariant = false;
> +   bool is_gl_point_size_invariant = false;
> +
>     /* Find all shader outputs in the "producer" stage.
>      */
>     foreach_in_list(ir_instruction, node, producer->ir) {
> @@ -344,6 +347,13 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
>        if (var == NULL || var->data.mode != ir_var_shader_out)
>           continue;
>
> +      if (prog->IsES && prog->Version < 300) {
> +         if (var->data.location == VARYING_SLOT_POS)
> +            is_gl_position_invariant = var->data.invariant;
> +         if (var->data.location == VARYING_SLOT_PSIZ)
> +            is_gl_point_size_invariant = var->data.invariant;
> +      }
> +
>        if (!var->data.explicit_location
>            || var->data.location < VARYING_SLOT_VAR0)
>           parameters.add_variable(var);
> @@ -430,6 +440,35 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
>        if (input == NULL || input->data.mode != ir_var_shader_in)
>           continue;
>
> +      /*
> +       * GLSL ES 1.00 specification, Section "Invariance and linkage" says:
> +       *
> +       *  "For the built-in special variables, gl_FragCoord can
> +       *  only be declared invariant if and only if gl_Position is
> +       *  declared invariant. Similarly gl_PointCoord can only be
> +       *  declared invariant if and only if gl_PointSize is declared
> +       *  invariant. It is an error to declare gl_FrontFacing as invariant."
> +       */
> +      if (prog->IsES && prog->Version < 300 && input->data.invariant) {
> +         if (input->data.location == VARYING_SLOT_FACE) {
> +            linker_error(prog,
> +                         "gl_FrontFacing cannot be declared invariant");
> +            return;
> +         } else if (!is_gl_position_invariant &&
> +                    input->data.location == VARYING_SLOT_POS) {
> +            linker_error(prog,
> +                         "gl_FragCoord cannot be declared invariant "
> +                         "unless gl_Position is also invariant");
> +            return;
> +         } else if (!is_gl_point_size_invariant &&
> +                    input->data.location == VARYING_SLOT_PNTC) {
> +            linker_error(prog,
> +                         "gl_PointCoord cannot be declared invariant "
> +                         "unless gl_PointSize is also invariant");
> +            return;
> +         }
> +      }
> +
>        if (strcmp(input->name, "gl_Color") == 0 && input->data.used) {
>           const ir_variable *const front_color =
>              parameters.get_variable("gl_FrontColor");
> --
> 2.5.5
>


More information about the mesa-dev mailing list