[Mesa-dev] [PATCH 02/14] glsl: Add type predicate to check whether a type contains any opaque types.

Ian Romanick idr at freedesktop.org
Fri Oct 25 10:52:16 PDT 2013


Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

On 10/01/2013 07:15 PM, Francisco Jerez wrote:
> And use it to forbid comparisons of opaque operands.  According to the
> GL 4.2 specification:
> 
>> Except for array indexing, structure member selection, and
>> parentheses, opaque variables are not allowed to be operands in
>> expressions.
> ---
>  src/glsl/ast_to_hir.cpp |  4 ++++
>  src/glsl/glsl_types.cpp | 18 ++++++++++++++++++
>  src/glsl/glsl_types.h   |  5 +++++
>  3 files changed, 27 insertions(+)
> 
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> index 99159dc..db59d0a 100644
> --- a/src/glsl/ast_to_hir.cpp
> +++ b/src/glsl/ast_to_hir.cpp
> @@ -1197,6 +1197,10 @@ ast_expression::hir(exec_list *instructions,
>                   !state->check_version(120, 300, &loc,
>                                         "array comparisons forbidden")) {
>  	 error_emitted = true;
> +      } else if ((op[0]->type->contains_opaque() ||
> +                  op[1]->type->contains_opaque())) {
> +         _mesa_glsl_error(&loc, state, "opaque type comparisons forbidden");
> +         error_emitted = true;
>        }
>  
>        if (error_emitted) {
> diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
> index e1fe153..a9b7eb3 100644
> --- a/src/glsl/glsl_types.cpp
> +++ b/src/glsl/glsl_types.cpp
> @@ -162,6 +162,24 @@ glsl_type::contains_integer() const
>     }
>  }
>  
> +bool
> +glsl_type::contains_opaque() const {
> +   switch (base_type) {
> +   case GLSL_TYPE_SAMPLER:
> +   case GLSL_TYPE_ATOMIC_UINT:
> +      return true;
> +   case GLSL_TYPE_ARRAY:
> +      return element_type()->contains_opaque();
> +   case GLSL_TYPE_STRUCT:
> +      for (unsigned int i = 0; i < length; i++) {
> +         if (fields.structure[i].type->contains_opaque())
> +            return true;
> +      }
> +      return false;
> +   default:
> +      return false;
> +   }
> +}
>  
>  gl_texture_index
>  glsl_type::sampler_index() const
> diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
> index d00b9e7..133b0af 100644
> --- a/src/glsl/glsl_types.h
> +++ b/src/glsl/glsl_types.h
> @@ -463,6 +463,11 @@ struct glsl_type {
>     }
>  
>     /**
> +    * Return whether a type contains any opaque types.
> +    */
> +   bool contains_opaque() const;
> +
> +   /**
>      * Query the full type of a matrix row
>      *
>      * \return
> 



More information about the mesa-dev mailing list