From: Iago Toral Quiroga Date: Thu, 26 Feb 2015 11:15:18 +0000 (+0100) Subject: glsl: Add user-defined default precision qualifiers to the symbol table X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e6629d814f9a860b3a5390684be06370b270be14;p=mesa.git glsl: Add user-defined default precision qualifiers to the symbol table 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. Reviewed-by: Tapani Pälli Reviewed-by: Samuel Iglesias Gonsálvez --- diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index 9d341e8cf92..a701753d959 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -2141,11 +2141,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'", @@ -5714,20 +5718,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 @@ -5740,16 +5734,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. */