Mesa (glsl2): glsl2: Define new ir_discard instruction.

Ian Romanick idr at kemper.freedesktop.org
Wed Jun 30 14:59:32 PDT 2010


Module: Mesa
Branch: glsl2
Commit: 16efab1c4dee6e6a827ba5f1c482378159545ae5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=16efab1c4dee6e6a827ba5f1c482378159545ae5

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Jun 30 10:47:34 2010 -0700

glsl2: Define new ir_discard instruction.

---

 src/glsl/ir.h                        |   27 +++++++++++++++++++++++++++
 src/glsl/ir_clone.cpp                |   12 ++++++++++++
 src/glsl/ir_constant_expression.cpp  |    9 +++++++++
 src/glsl/ir_constant_folding.cpp     |    8 ++++++++
 src/glsl/ir_hierarchical_visitor.cpp |   16 ++++++++++++++++
 src/glsl/ir_hierarchical_visitor.h   |    2 ++
 src/glsl/ir_hv_accept.cpp            |   17 +++++++++++++++++
 src/glsl/ir_print_visitor.cpp        |   14 ++++++++++++++
 src/glsl/ir_print_visitor.h          |    1 +
 src/glsl/ir_visitor.h                |    1 +
 src/mesa/shader/ir_to_mesa.cpp       |    8 ++++++++
 11 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 65026ef..00b0076 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -793,6 +793,33 @@ private:
    /** Loop containing this break instruction. */
    ir_loop *loop;
 };
+
+/**
+ * IR instruction representing discard statements.
+ */
+class ir_discard : public ir_jump {
+public:
+   ir_discard()
+   {
+      this->condition = NULL;
+   }
+
+   ir_discard(ir_rvalue *cond)
+   {
+      this->condition = cond;
+   }
+
+   virtual ir_instruction *clone(struct hash_table *ht) const;
+
+   virtual void accept(ir_visitor *v)
+   {
+      v->visit(this);
+   }
+
+   virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+   ir_rvalue *condition;
+};
 /*@}*/
 
 
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index 01a1ce3..74cc858 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -75,6 +75,18 @@ ir_return::clone(struct hash_table *ht) const
 }
 
 ir_instruction *
+ir_discard::clone(struct hash_table *ht) const
+{
+   void *ctx = talloc_parent(this);
+   ir_rvalue *new_condition = NULL;
+
+   if (this->condition != NULL)
+      new_condition = (ir_rvalue *) this->condition->clone(ht);
+
+   return new(ctx) ir_discard(new_condition);
+}
+
+ir_instruction *
 ir_loop_jump::clone(struct hash_table *ht) const
 {
    void *ctx = talloc_parent(this);
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index 3408f52..c6348ac 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -75,6 +75,7 @@ public:
    virtual void visit(ir_constant *);
    virtual void visit(ir_call *);
    virtual void visit(ir_return *);
+   virtual void visit(ir_discard *);
    virtual void visit(ir_if *);
    virtual void visit(ir_loop *);
    virtual void visit(ir_loop_jump *);
@@ -648,6 +649,14 @@ ir_constant_visitor::visit(ir_return *ir)
 
 
 void
+ir_constant_visitor::visit(ir_discard *ir)
+{
+   (void) ir;
+   value = NULL;
+}
+
+
+void
 ir_constant_visitor::visit(ir_if *ir)
 {
    (void) ir;
diff --git a/src/glsl/ir_constant_folding.cpp b/src/glsl/ir_constant_folding.cpp
index 342d027..2daa6fd 100644
--- a/src/glsl/ir_constant_folding.cpp
+++ b/src/glsl/ir_constant_folding.cpp
@@ -68,6 +68,7 @@ public:
    virtual void visit(ir_constant *);
    virtual void visit(ir_call *);
    virtual void visit(ir_return *);
+   virtual void visit(ir_discard *);
    virtual void visit(ir_if *);
    virtual void visit(ir_loop *);
    virtual void visit(ir_loop_jump *);
@@ -191,6 +192,13 @@ ir_constant_folding_visitor::visit(ir_return *ir)
 
 
 void
+ir_constant_folding_visitor::visit(ir_discard *ir)
+{
+   (void) ir;
+}
+
+
+void
 ir_constant_folding_visitor::visit(ir_if *ir)
 {
    ir_constant *const_val = ir->condition->constant_expression_value();
diff --git a/src/glsl/ir_hierarchical_visitor.cpp b/src/glsl/ir_hierarchical_visitor.cpp
index 0d520b1..9afb12a 100644
--- a/src/glsl/ir_hierarchical_visitor.cpp
+++ b/src/glsl/ir_hierarchical_visitor.cpp
@@ -243,6 +243,22 @@ ir_hierarchical_visitor::visit_leave(ir_return *ir)
 }
 
 ir_visitor_status
+ir_hierarchical_visitor::visit_enter(ir_discard *ir)
+{
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
+   return visit_continue;
+}
+
+ir_visitor_status
+ir_hierarchical_visitor::visit_leave(ir_discard *ir)
+{
+   (void) ir;
+   return visit_continue;
+}
+
+ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_if *ir)
 {
    if (this->callback != NULL)
diff --git a/src/glsl/ir_hierarchical_visitor.h b/src/glsl/ir_hierarchical_visitor.h
index 8b9e49d..2c4590d 100644
--- a/src/glsl/ir_hierarchical_visitor.h
+++ b/src/glsl/ir_hierarchical_visitor.h
@@ -129,6 +129,8 @@ public:
    virtual ir_visitor_status visit_leave(class ir_call *);
    virtual ir_visitor_status visit_enter(class ir_return *);
    virtual ir_visitor_status visit_leave(class ir_return *);
+   virtual ir_visitor_status visit_enter(class ir_discard *);
+   virtual ir_visitor_status visit_leave(class ir_discard *);
    virtual ir_visitor_status visit_enter(class ir_if *);
    virtual ir_visitor_status visit_leave(class ir_if *);
    /*@}*/
diff --git a/src/glsl/ir_hv_accept.cpp b/src/glsl/ir_hv_accept.cpp
index f936b35..7b5cc52 100644
--- a/src/glsl/ir_hv_accept.cpp
+++ b/src/glsl/ir_hv_accept.cpp
@@ -322,6 +322,23 @@ ir_return::accept(ir_hierarchical_visitor *v)
 
 
 ir_visitor_status
+ir_discard::accept(ir_hierarchical_visitor *v)
+{
+   ir_visitor_status s = v->visit_enter(this);
+   if (s != visit_continue)
+      return (s == visit_continue_with_parent) ? visit_continue : s;
+
+   if (this->condition != NULL) {
+      s = this->condition->accept(v);
+      if (s != visit_continue)
+	 return (s == visit_continue_with_parent) ? visit_continue : s;
+   }
+
+   return v->visit_leave(this);
+}
+
+
+ir_visitor_status
 ir_if::accept(ir_hierarchical_visitor *v)
 {
    ir_visitor_status s = v->visit_enter(this);
diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp
index be5a843..6f867e3 100644
--- a/src/glsl/ir_print_visitor.cpp
+++ b/src/glsl/ir_print_visitor.cpp
@@ -315,6 +315,20 @@ ir_print_visitor::visit(ir_return *ir)
 
 
 void
+ir_print_visitor::visit(ir_discard *ir)
+{
+   printf("(discard ");
+
+   if (ir->condition != NULL) {
+      printf(" ");
+      ir->condition->accept(this);
+   }
+
+   printf(")");
+}
+
+
+void
 ir_print_visitor::visit(ir_if *ir)
 {
    printf("(if ");
diff --git a/src/glsl/ir_print_visitor.h b/src/glsl/ir_print_visitor.h
index e97b823..3db42e2 100644
--- a/src/glsl/ir_print_visitor.h
+++ b/src/glsl/ir_print_visitor.h
@@ -69,6 +69,7 @@ public:
    virtual void visit(ir_constant *);
    virtual void visit(ir_call *);
    virtual void visit(ir_return *);
+   virtual void visit(ir_discard *);
    virtual void visit(ir_if *);
    virtual void visit(ir_loop *);
    virtual void visit(ir_loop_jump *);
diff --git a/src/glsl/ir_visitor.h b/src/glsl/ir_visitor.h
index a6f9d2b..b87d737 100644
--- a/src/glsl/ir_visitor.h
+++ b/src/glsl/ir_visitor.h
@@ -57,6 +57,7 @@ public:
    virtual void visit(class ir_constant *) = 0;
    virtual void visit(class ir_call *) = 0;
    virtual void visit(class ir_return *) = 0;
+   virtual void visit(class ir_discard *) = 0;
    virtual void visit(class ir_if *) = 0;
    virtual void visit(class ir_loop *) = 0;
    virtual void visit(class ir_loop_jump *) = 0;
diff --git a/src/mesa/shader/ir_to_mesa.cpp b/src/mesa/shader/ir_to_mesa.cpp
index ef9a96e..8c074a8 100644
--- a/src/mesa/shader/ir_to_mesa.cpp
+++ b/src/mesa/shader/ir_to_mesa.cpp
@@ -134,6 +134,7 @@ public:
    virtual void visit(ir_constant *);
    virtual void visit(ir_call *);
    virtual void visit(ir_return *);
+   virtual void visit(ir_discard *);
    virtual void visit(ir_texture *);
    virtual void visit(ir_if *);
    /*@}*/
@@ -1321,6 +1322,13 @@ ir_to_mesa_visitor::visit(ir_return *ir)
    ir->get_value()->accept(this);
 }
 
+void
+ir_to_mesa_visitor::visit(ir_discard *ir)
+{
+   assert(0);
+
+   ir->condition->accept(this);
+}
 
 void
 ir_to_mesa_visitor::visit(ir_if *ir)



More information about the mesa-commit mailing list