Mark some variables as having usage beyond the shader's scope.
authorEric Anholt <eric@anholt.net>
Mon, 19 Apr 2010 18:10:37 +0000 (11:10 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 19 Apr 2010 18:13:20 +0000 (11:13 -0700)
This will be important to optimization passes.  We don't want to
dead-code eliminate writes to out varyings, or propagate uninitialized
values of uniforms.

ast_to_hir.cpp
ir.h
ir_variable.cpp

index 83dac584b2b7ee629301c2ec90dbea95ca315e6a..316bcf7d71c884f9afe6ddbf5e42e66b9526b262 100644 (file)
@@ -1446,6 +1446,15 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
    else
       var->mode = ir_var_auto;
 
+   if (qual->uniform)
+      var->shader_in = true;
+   if (qual->varying) {
+      if (qual->in)
+        var->shader_in = true;
+      if (qual->out)
+        var->shader_out = true;
+   }
+
    if (qual->flat)
       var->interpolation = ir_var_flat;
    else if (qual->noperspective)
diff --git a/ir.h b/ir.h
index 471e19b43d558ff1d779561fd67c56c71a0a4fea..cb153be77de77291b2181d02f048246638f8cf4b 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -151,6 +151,12 @@ public:
    unsigned read_only:1;
    unsigned centroid:1;
    unsigned invariant:1;
+   /** If the variable is initialized outside of the scope of the shader */
+   unsigned shader_in:1;
+   /**
+    * If the variable value is later used outside of the scope of the shader.
+    */
+   unsigned shader_out:1;
 
    unsigned mode:3;
    unsigned interpolation:2;
index 76a528ca2bea49c22b1955230d78ca65db2aa0f9..12992a9b8120098146acb2d68af5329f102c1b83 100644 (file)
@@ -38,9 +38,25 @@ add_variable(const char *name, enum ir_variable_mode mode,
    ir_variable *var = new ir_variable(type, name);
 
    var->mode = mode;
-   if (var->mode != ir_var_out)
+   switch (var->mode) {
+   case ir_var_in:
+      var->shader_in = true;
       var->read_only = true;
-
+      break;
+   case ir_var_inout:
+      var->shader_in = true;
+      var->shader_out = true;
+   case ir_var_out:
+      var->shader_out = true;
+      break;
+   case ir_var_uniform:
+      var->shader_in = true;
+      var->read_only = true;
+      break;
+   default:
+      assert(0);
+      break;
+   }
 
    /* Once the variable is created an initialized, add it to the symbol table
     * and add the declaration to the IR stream.