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

Paul Berry stereotype441 at gmail.com
Mon Oct 24 14:38:39 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
ir_variable_interpolation enum, ir_var_interp_unspecified.  I also
took the liberty of renaming all of the enum elements to begin with
ir_var_interp for clarity.
---
 src/glsl/ast_to_hir.cpp |   10 ++++++----
 src/glsl/ir.cpp         |    9 +++++----
 src/glsl/ir.h           |   11 ++++++++---
 src/glsl/ir_reader.cpp  |    6 +++---
 4 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 70afb67..c7d5107 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1962,11 +1962,13 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
    }
 
    if (qual->flags.q.flat)
-      var->interpolation = ir_var_flat;
+      var->interpolation = ir_var_interp_flat;
    else if (qual->flags.q.noperspective)
-      var->interpolation = ir_var_noperspective;
+      var->interpolation = ir_var_interp_noperspective;
+   else if (qual->flags.q.smooth)
+      var->interpolation = ir_var_interp_smooth;
    else
-      var->interpolation = ir_var_smooth;
+      var->interpolation = ir_var_interp_unspecified;
 
    var->pixel_center_integer = qual->flags.q.pixel_center_integer;
    var->origin_upper_left = qual->flags.q.origin_upper_left;
@@ -2630,7 +2632,7 @@ ast_declarator_list::hir(exec_list *instructions,
           && state->current_function == NULL
           && var->type->is_integer()
           && var->mode == ir_var_out
-          && var->interpolation != ir_var_flat) {
+          && var->interpolation != ir_var_interp_flat) {
 
          _mesa_glsl_error(&loc, state, "If a vertex output is an integer, "
                           "then it must be qualified with 'flat'");
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index d968890..a833c80 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(ir_var_smooth)
+     mode(mode), interpolation(ir_var_interp_unspecified)
 {
    this->ir_type = ir_type_variable;
    this->type = type;
@@ -1343,9 +1343,10 @@ const char *
 ir_variable::interpolation_string() const
 {
    switch (this->interpolation) {
-   case ir_var_smooth:        return "smooth";
-   case ir_var_flat:          return "flat";
-   case ir_var_noperspective: return "noperspective";
+   case ir_var_interp_unspecified:   return "no";
+   case ir_var_interp_smooth:        return "smooth";
+   case ir_var_interp_flat:          return "flat";
+   case ir_var_interp_noperspective: return "noperspective";
    }
 
    assert(!"Should not get here.");
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index b707634..e8ce28d 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -228,9 +228,10 @@ enum ir_variable_mode {
 };
 
 enum ir_variable_interpolation {
-   ir_var_smooth = 0,
-   ir_var_flat,
-   ir_var_noperspective
+   ir_var_interp_unspecified = 0,
+   ir_var_interp_smooth,
+   ir_var_interp_flat,
+   ir_var_interp_noperspective
 };
 
 /**
@@ -288,6 +289,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/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp
index afb06b3..bf76fc8 100644
--- a/src/glsl/ir_reader.cpp
+++ b/src/glsl/ir_reader.cpp
@@ -405,11 +405,11 @@ ir_reader::read_declaration(s_expression *expr)
       } else if (strcmp(qualifier->value(), "inout") == 0) {
 	 var->mode = ir_var_inout;
       } else if (strcmp(qualifier->value(), "smooth") == 0) {
-	 var->interpolation = ir_var_smooth;
+	 var->interpolation = ir_var_interp_smooth;
       } else if (strcmp(qualifier->value(), "flat") == 0) {
-	 var->interpolation = ir_var_flat;
+	 var->interpolation = ir_var_interp_flat;
       } else if (strcmp(qualifier->value(), "noperspective") == 0) {
-	 var->interpolation = ir_var_noperspective;
+	 var->interpolation = ir_var_interp_noperspective;
       } else {
 	 ir_read_error(expr, "unknown qualifier: %s", qualifier->value());
 	 return NULL;
-- 
1.7.6.4



More information about the mesa-dev mailing list