[Mesa-dev] [PATCH v2 2/8] glsl: Distinguish between no interpolation qualifier and 'smooth'

Paul Berry stereotype441 at gmail.com
Tue Oct 25 20:38:20 PDT 2011


Previously, we treated the 'smooth' qualifier as equivalent to no
qualifier at all.  However, this is incorrect for the built-in color
variables (gl_FrontColor, gl_BackColor, gl_FrontSecondaryColor, and
gl_BackSecondaryColor).  For those variables, if there is no qualifier
at all, interpolation should be flat if the shade model is GL_FLAT,
and smooth if the shade model is GL_SMOOTH.

To make this possible, I added a new value to the
glsl_interp_qualifier enum, INTERP_QUALIFIER_NONE.
---
 src/glsl/ast_to_hir.cpp |    4 +++-
 src/glsl/ir.cpp         |    3 ++-
 src/glsl/ir.h           |    4 ++++
 src/mesa/main/mtypes.h  |    6 +++++-
 4 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index d090d31..fa6206e 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1965,8 +1965,10 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
       var->interpolation = INTERP_QUALIFIER_FLAT;
    else if (qual->flags.q.noperspective)
       var->interpolation = INTERP_QUALIFIER_NOPERSPECTIVE;
-   else
+   else if (qual->flags.q.smooth)
       var->interpolation = INTERP_QUALIFIER_SMOOTH;
+   else
+      var->interpolation = INTERP_QUALIFIER_NONE;
 
    var->pixel_center_integer = qual->flags.q.pixel_center_integer;
    var->origin_upper_left = qual->flags.q.origin_upper_left;
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 046ce25..9aad0fc 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1320,7 +1320,7 @@ ir_swizzle::variable_referenced() const
 ir_variable::ir_variable(const struct glsl_type *type, const char *name,
 			 ir_variable_mode mode)
    : max_array_access(0), read_only(false), centroid(false), invariant(false),
-     mode(mode), interpolation(INTERP_QUALIFIER_SMOOTH)
+     mode(mode), interpolation(INTERP_QUALIFIER_NONE)
 {
    this->ir_type = ir_type_variable;
    this->type = type;
@@ -1343,6 +1343,7 @@ const char *
 ir_variable::interpolation_string() const
 {
    switch (this->interpolation) {
+   case INTERP_QUALIFIER_NONE:          return "no";
    case INTERP_QUALIFIER_SMOOTH:        return "smooth";
    case INTERP_QUALIFIER_FLAT:          return "flat";
    case INTERP_QUALIFIER_NOPERSPECTIVE: return "noperspective";
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 4ea8764..0c0cccb 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -283,6 +283,10 @@ public:
     * \return The string that would be used in a shader to specify \c
     * mode will be returned.
     *
+    * This function is used to generate error messages of the form "shader
+    * uses %s interpolation qualifier", so in the case where there is no
+    * interpolation qualifier, it returns "no".
+    *
     * This function should only be used on a shader input or output variable.
     */
    const char *interpolation_string() const;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index bd5e020..47d8a96 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1793,9 +1793,13 @@ typedef enum
 /**
  * The possible interpolation qualifiers that can be applied to a fragment
  * shader input in GLSL.
+ *
+ * Note: INTERP_QUALIFIER_NONE must be 0 so that memsetting the
+ * gl_fragment_program data structure to 0 causes the default behavior.
  */
 enum glsl_interp_qualifier
 {
+   INTERP_QUALIFIER_NONE = 0,
    INTERP_QUALIFIER_SMOOTH,
    INTERP_QUALIFIER_FLAT,
    INTERP_QUALIFIER_NOPERSPECTIVE
@@ -1906,7 +1910,7 @@ struct gl_fragment_program
    /**
     * GLSL interpolation qualifier associated with each fragment shader input.
     * For inputs that do not have an interpolation qualifier specified in
-    * GLSL, the value is INTERP_QUALIFIER_SMOOTH.
+    * GLSL, the value is INTERP_QUALIFIER_NONE.
     */
    enum glsl_interp_qualifier InterpQualifier[FRAG_ATTRIB_MAX];
 };
-- 
1.7.6.4



More information about the mesa-dev mailing list