summaryrefslogtreecommitdiffstats
path: root/src/glsl/ir_constant_variable.cpp
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2010-07-29 14:54:01 -0700
committerEric Anholt <[email protected]>2010-07-29 15:09:28 -0700
commitee4b4bab682ca64740b78d99d421e3d676eec447 (patch)
tree235e42e8c5ee0e141b1de8e80d166873ec7a9229 /src/glsl/ir_constant_variable.cpp
parentbf496862be1ba863285aa2c1a2262b2d764c3e53 (diff)
ir_constant_variable: Don't mark variable from outside our scope as constant.
Fixes (with software, except for alpha): glsl1-function with early return(3)
Diffstat (limited to 'src/glsl/ir_constant_variable.cpp')
-rw-r--r--src/glsl/ir_constant_variable.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/glsl/ir_constant_variable.cpp b/src/glsl/ir_constant_variable.cpp
index c5ccd52e5db..749e2cf809f 100644
--- a/src/glsl/ir_constant_variable.cpp
+++ b/src/glsl/ir_constant_variable.cpp
@@ -42,10 +42,13 @@ struct assignment_entry {
int assignment_count;
ir_variable *var;
ir_constant *constval;
+ bool our_scope;
};
class ir_constant_variable_visitor : public ir_hierarchical_visitor {
public:
+ virtual ir_visitor_status visit_enter(ir_dereference_variable *);
+ virtual ir_visitor_status visit(ir_variable *);
virtual ir_visitor_status visit_enter(ir_assignment *);
virtual ir_visitor_status visit_enter(ir_call *);
@@ -69,6 +72,22 @@ get_assignment_entry(ir_variable *var, exec_list *list)
}
ir_visitor_status
+ir_constant_variable_visitor::visit(ir_variable *ir)
+{
+ struct assignment_entry *entry = get_assignment_entry(ir, &this->list);
+ entry->our_scope = true;
+ return visit_continue;
+}
+
+/* Skip derefs of variables so that we can detect declarations. */
+ir_visitor_status
+ir_constant_variable_visitor::visit_enter(ir_dereference_variable *ir)
+{
+ (void)ir;
+ return visit_continue_with_parent;
+}
+
+ir_visitor_status
ir_constant_variable_visitor::visit_enter(ir_assignment *ir)
{
ir_constant *constval;
@@ -146,7 +165,7 @@ do_constant_variable(exec_list *instructions)
struct assignment_entry *entry;
entry = exec_node_data(struct assignment_entry, v.list.head, link);
- if (entry->assignment_count == 1 && entry->constval) {
+ if (entry->assignment_count == 1 && entry->constval && entry->our_scope) {
entry->var->constant_value = entry->constval;
progress = true;
}