Mesa (master): glsl: Check that interpolation qualifiers do not precede ' varying'

Chad Versace chadversary at kemper.freedesktop.org
Mon Jan 17 18:21:19 UTC 2011


Module: Mesa
Branch: master
Commit: 605aacc67d73db0926e0046a90a07fcd93a2d613
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=605aacc67d73db0926e0046a90a07fcd93a2d613

Author: Chad Versace <chad.versace at intel.com>
Date:   Tue Jan 11 17:21:18 2011 -0800

glsl: Check that interpolation qualifiers do not precede 'varying'

... and 'centroid varying'. The check is performed only in GLSL
versions >= 1.30.

>From page 29 (page 35 of the PDF) of the GLSL 1.30 spec:
   "interpolation qualifiers may only precede the qualifiers in, centroid
    in, out, or centroid out in a declaration. They do not apply to the
    deprecated storage qualifiers varying or centroid varying."

Fixes Piglit test
spec/glsl-1.30/compiler/interpolation-qualifiers/smooth-varying-01.frag.

---

 src/glsl/ast.h          |    5 +++++
 src/glsl/ast_to_hir.cpp |   26 ++++++++++++++++++++++++++
 src/glsl/ast_type.cpp   |    7 +++++++
 3 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/glsl/ast.h b/src/glsl/ast.h
index c096f9a..523a389 100644
--- a/src/glsl/ast.h
+++ b/src/glsl/ast.h
@@ -366,6 +366,11 @@ struct ast_type_qualifier {
    unsigned location;
 
    /**
+    * Return true if and only if an interpolation qualifier is present.
+    */
+   bool has_interpolation() const;
+
+   /**
     * \brief Return string representation of interpolation qualifier.
     *
     * If an interpolation qualifier is present, then return that qualifier's
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 365a6e2..a2edb6a 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2277,6 +2277,32 @@ ast_declarator_list::hir(exec_list *instructions,
       }
 
 
+      /* Interpolation qualifiers cannot be applied to 'centroid' and
+       * 'centroid varying'.
+       *
+       * From page 29 (page 35 of the PDF) of the GLSL 1.30 spec:
+       *    "interpolation qualifiers may only precede the qualifiers in,
+       *    centroid in, out, or centroid out in a declaration. They do not apply
+       *    to the deprecated storage qualifiers varying or centroid varying."
+       */
+      if (state->language_version >= 130
+          && this->type->qualifier.has_interpolation()
+          && this->type->qualifier.flags.q.varying) {
+
+         const char *i = this->type->qualifier.interpolation_string();
+         assert(i != NULL);
+         const char *s;
+         if (this->type->qualifier.flags.q.centroid)
+            s = "centroid varying";
+         else
+            s = "varying";
+
+         _mesa_glsl_error(&loc, state,
+                          "qualifier '%s' cannot be applied to the "
+                          "deprecated storage qualifier '%s'", i, s);
+      }
+
+
       /* Process the initializer and add its instructions to a temporary
        * list.  This list will be added to the instruction stream (below) after
        * the declaration is added.  This is done because in some cases (such as
diff --git a/src/glsl/ast_type.cpp b/src/glsl/ast_type.cpp
index a876161..f23e545 100644
--- a/src/glsl/ast_type.cpp
+++ b/src/glsl/ast_type.cpp
@@ -117,6 +117,13 @@ ast_fully_specified_type::has_qualifiers() const
    return this->qualifier.flags.i != 0;
 }
 
+bool ast_type_qualifier::has_interpolation() const
+{
+   return this->flags.q.smooth
+          || this->flags.q.flat
+          || this->flags.q.noperspective;
+}
+
 const char*
 ast_type_qualifier::interpolation_string() const
 {




More information about the mesa-commit mailing list