Mesa (9.1): glsl: Allow default precision qualifiers to be set for sampler types.

Paul Berry stereotype441 at kemper.freedesktop.org
Fri Feb 15 21:43:53 UTC 2013


Module: Mesa
Branch: 9.1
Commit: 2cd4824fbcbe7739601e784b527f7d130d289d19
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2cd4824fbcbe7739601e784b527f7d130d289d19

Author: Paul Berry <stereotype441 at gmail.com>
Date:   Tue Feb 12 12:36:41 2013 -0800

glsl: Allow default precision qualifiers to be set for sampler types.

>From GLSL ES 3.00 section 4.5.4 ("Default Precision Qualifiers"):

    "The precision statement

        precision precision-qualifier type;

    can be used to establish a default precision qualifier. The type
    field can be either int or float or any of the sampler types, and
    the precision-qualifier can be lowp, mediump, or highp."

GLSL ES 1.00 has similar language.  GLSL 1.30 doesn't allow precision
qualifiers on sampler types, but this seems like an oversight (since
the intention of including these in GLSL 1.30 is to allow
compatibility with ES shaders).

Previously, Mesa followed GLSL 1.30 and only allowed default precision
qualifiers to be set for float and int.  This patch makes it follow
GLSL ES rules in all cases.

Fixes Piglit tests default-precision-sampler.{vert,frag}.

Partially addresses https://bugs.freedesktop.org/show_bug.cgi?id=60737.

NOTE: This is a candidate for stable branches.

Reviewed-by: Eric Anholt <eric at anholt.net>
(cherry picked from commit d5948f2f5e37d1abc0d433ddf43407d87b2d1227)

---

 src/glsl/ast_to_hir.cpp |   46 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 49093d8..668973d 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3967,6 +3967,47 @@ ast_iteration_statement::hir(exec_list *instructions,
 }
 
 
+/**
+ * Determine if the given type is valid for establishing a default precision
+ * qualifier.
+ *
+ * From GLSL ES 3.00 section 4.5.4 ("Default Precision Qualifiers"):
+ *
+ *     "The precision statement
+ *
+ *         precision precision-qualifier type;
+ *
+ *     can be used to establish a default precision qualifier. The type field
+ *     can be either int or float or any of the sampler types, and the
+ *     precision-qualifier can be lowp, mediump, or highp."
+ *
+ * GLSL ES 1.00 has similar language.  GLSL 1.30 doesn't allow precision
+ * qualifiers on sampler types, but this seems like an oversight (since the
+ * intention of including these in GLSL 1.30 is to allow compatibility with ES
+ * shaders).  So we allow int, float, and all sampler types regardless of GLSL
+ * version.
+ */
+static bool
+is_valid_default_precision_type(const struct _mesa_glsl_parse_state *state,
+                                const char *type_name)
+{
+   const struct glsl_type *type = state->symbols->get_type(type_name);
+   if (type == NULL)
+      return false;
+
+   switch (type->base_type) {
+   case GLSL_TYPE_INT:
+   case GLSL_TYPE_FLOAT:
+      /* "int" and "float" are valid, but vectors and matrices are not. */
+      return type->vector_elements == 1 && type->matrix_columns == 1;
+   case GLSL_TYPE_SAMPLER:
+      return true;
+   default:
+      return false;
+   }
+}
+
+
 ir_rvalue *
 ast_type_specifier::hir(exec_list *instructions,
 			  struct _mesa_glsl_parse_state *state)
@@ -4007,11 +4048,10 @@ ast_type_specifier::hir(exec_list *instructions,
                           "arrays");
          return NULL;
       }
-      if (strcmp(this->type_name, "float") != 0 &&
-	  strcmp(this->type_name, "int") != 0) {
+      if (!is_valid_default_precision_type(state, this->type_name)) {
          _mesa_glsl_error(&loc, state,
                           "default precision statements apply only to types "
-                          "float and int");
+                          "float, int, and sampler types");
          return NULL;
       }
 




More information about the mesa-commit mailing list