[Mesa-dev] [PATCH 3/7] glsl: Add user-defined default precision qualifiers to the symbol table

Samuel Iglesias Gonsálvez siglesias at igalia.com
Wed Nov 11 04:27:44 PST 2015


Reviewed-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>

On 05/11/15 12:33, Tapani Pälli wrote:
> From: Iago Toral Quiroga <itoral at igalia.com>
> 
> Notice that the spec requires that a default precision has been set for every
> type used by a shader that can use a precision qualifier and does not have a
> predefined precision, however, at the moment, Mesa only checks this for floats
> in the fragment shader. This is probably because the GLSL ES 1.0 specs mentions
> this case specifically, but GLSL ES 3.0 clarifies that the same applies to
> other types:
> 
> "The fragment language has no default precision qualifier for floating point
>  types. Hence for float, floating point vector and matrix variable
>  declarations, either the declaration must include a precision qualifier or
>  the default float precision must have been previously declared. Similarly,
>  there is no default precision qualifier for the following sampler types in
>  either the vertex or fragment language:
> 
>  sampler3D;
>  samplerCubeShadow;
>  sampler2DShadow;
>  sampler2DArray;
>  sampler2DArrayShadow;
>  isampler2D;
>  isampler3D;
>  isamplerCube;
>  isampler2DArray;
>  usampler2D;
>  usampler3D;
>  usamplerCube;
>  usampler2DArray;"
> 
> we will fix this in a later patch.
> ---
>  src/glsl/ast_to_hir.cpp | 29 ++++++++++-------------------
>  1 file changed, 10 insertions(+), 19 deletions(-)
> 
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> index 0306530..d20be0b 100644
> --- a/src/glsl/ast_to_hir.cpp
> +++ b/src/glsl/ast_to_hir.cpp
> @@ -2184,11 +2184,15 @@ ast_fully_specified_type::glsl_type(const char **name,
>     if (type == NULL)
>        return NULL;
>  
> +   /* The fragment language does not define a default precision value
> +    * for float types, so check that one is defined if the type declaration
> +    * isn't providing one explictly.
> +    */
>     if (type->base_type == GLSL_TYPE_FLOAT
>         && state->es_shader
>         && state->stage == MESA_SHADER_FRAGMENT
>         && this->qualifier.precision == ast_precision_none
> -       && state->symbols->get_variable("#default precision") == NULL) {
> +       && state->symbols->get_default_precision_qualifier("float") == ast_precision_none) {
>        YYLTYPE loc = this->get_location();
>        _mesa_glsl_error(&loc, state,
>                         "no precision specified this scope for type `%s'",
> @@ -5749,20 +5753,10 @@ ast_type_specifier::hir(exec_list *instructions,
>           return NULL;
>        }
>  
> -      if (type->base_type == GLSL_TYPE_FLOAT
> -          && state->es_shader
> -          && state->stage == MESA_SHADER_FRAGMENT) {
> +      if (state->es_shader) {
>           /* Section 4.5.3 (Default Precision Qualifiers) of the GLSL ES 1.00
>            * spec says:
>            *
> -          *     "The fragment language has no default precision qualifier for
> -          *     floating point types."
> -          *
> -          * As a result, we have to track whether or not default precision has
> -          * been specified for float in GLSL ES fragment shaders.
> -          *
> -          * Earlier in that same section, the spec says:
> -          *
>            *     "Non-precision qualified declarations will use the precision
>            *     qualifier specified in the most recent precision statement
>            *     that is still in scope. The precision statement has the same
> @@ -5775,16 +5769,13 @@ ast_type_specifier::hir(exec_list *instructions,
>            *     overriding earlier statements within that scope."
>            *
>            * Default precision specifications follow the same scope rules as
> -          * variables.  So, we can track the state of the default float
> -          * precision in the symbol table, and the rules will just work.  This
> +          * variables.  So, we can track the state of the default precision
> +          * qualifiers in the symbol table, and the rules will just work.  This
>            * is a slight abuse of the symbol table, but it has the semantics
>            * that we want.
>            */
> -         ir_variable *const junk =
> -            new(state) ir_variable(type, "#default precision",
> -                                   ir_var_auto);
> -
> -         state->symbols->add_variable(junk);
> +         state->symbols->add_default_precision_qualifier(this->type_name,
> +                                                         this->default_precision);
>        }
>  
>        /* FINISHME: Translate precision statements into IR. */
> 


More information about the mesa-dev mailing list