From 71df19f5ef6e78beb5160801f81468184b75447e Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 19 Apr 2010 11:10:37 -0700 Subject: [PATCH] Mark some variables as having usage beyond the shader's scope. 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 | 9 +++++++++ ir.h | 6 ++++++ ir_variable.cpp | 20 ++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index 83dac584b2b..316bcf7d71c 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -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 471e19b43d5..cb153be77de 100644 --- 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; diff --git a/ir_variable.cpp b/ir_variable.cpp index 76a528ca2be..12992a9b812 100644 --- a/ir_variable.cpp +++ b/ir_variable.cpp @@ -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. -- 2.30.2