glsl: Modify ir_end_primitive to have a stream.
authorIago Toral Quiroga <itoral@igalia.com>
Fri, 20 Jun 2014 08:38:53 +0000 (10:38 +0200)
committerIago Toral Quiroga <itoral@igalia.com>
Mon, 30 Jun 2014 06:08:50 +0000 (08:08 +0200)
This will be necessary to implement EndStreamPrimitive().
EndPrimitive() will produce an ir_end_primitive with the default stream 0.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
src/glsl/builtin_functions.cpp
src/glsl/ir.h
src/glsl/ir_hierarchical_visitor.cpp
src/glsl/ir_hierarchical_visitor.h
src/glsl/ir_hv_accept.cpp
src/glsl/ir_rvalue_visitor.cpp
src/glsl/ir_rvalue_visitor.h

index 33b8843928ea5236b603c2ae1691cd607e65a5fd..eadc20c6c1d8b7c88d1af08c1f5342b174a711d3 100644 (file)
@@ -3883,7 +3883,8 @@ builtin_builder::_EndPrimitive()
 {
    MAKE_SIG(glsl_type::void_type, gs_only, 0);
 
-   body.emit(new(mem_ctx) ir_end_primitive());
+   ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
+   body.emit(new(mem_ctx) ir_end_primitive(stream));
 
    return sig;
 }
index fa22190d6fa6ca7c8d682ee39c3b8a87d650485b..d5239d4de1bcd0ae7e3d462183716b2533210805 100644 (file)
@@ -2192,9 +2192,11 @@ public:
  */
 class ir_end_primitive : public ir_instruction {
 public:
-   ir_end_primitive()
-      : ir_instruction(ir_type_end_primitive)
+   ir_end_primitive(ir_rvalue *stream)
+      : ir_instruction(ir_type_end_primitive),
+        stream(stream)
    {
+      assert(stream);
    }
 
    virtual void accept(ir_visitor *v)
@@ -2202,12 +2204,19 @@ public:
       v->visit(this);
    }
 
-   virtual ir_end_primitive *clone(void *mem_ctx, struct hash_table *) const
+   virtual ir_end_primitive *clone(void *mem_ctx, struct hash_table *ht) const
    {
-      return new(mem_ctx) ir_end_primitive();
+      return new(mem_ctx) ir_end_primitive(this->stream->clone(mem_ctx, ht));
    }
 
    virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+
+   int stream_id() const
+   {
+      return stream->as_constant()->value.i[0];
+   }
+
+   ir_rvalue *stream;
 };
 
 /*@}*/
index 78ae2df1d3d86ee1bb54b120cb045df5659825ef..d3c00ecdb7676fdff5f7f9628dc2d1b96c3646f4 100644 (file)
@@ -68,15 +68,6 @@ ir_hierarchical_visitor::visit(ir_loop_jump *ir)
    return visit_continue;
 }
 
-ir_visitor_status
-ir_hierarchical_visitor::visit(ir_end_primitive *ir)
-{
-   if (this->callback != NULL)
-      this->callback(ir, this->data);
-
-   return visit_continue;
-}
-
 ir_visitor_status
 ir_hierarchical_visitor::visit(ir_dereference_variable *ir)
 {
@@ -310,6 +301,22 @@ ir_hierarchical_visitor::visit_leave(ir_emit_vertex *ir)
    return visit_continue;
 }
 
+ir_visitor_status
+ir_hierarchical_visitor::visit_enter(ir_end_primitive *ir)
+{
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
+   return visit_continue;
+}
+
+ir_visitor_status
+ir_hierarchical_visitor::visit_leave(ir_end_primitive *ir)
+{
+   (void) ir;
+   return visit_continue;
+}
+
 void
 ir_hierarchical_visitor::run(exec_list *instructions)
 {
index 1679e0a0822def4b273b28685dbf3ec772eb1bfd..bc89a04d8c95079e64a49fe96feb50febdab58dc 100644 (file)
@@ -87,7 +87,6 @@ public:
    virtual ir_visitor_status visit(class ir_variable *);
    virtual ir_visitor_status visit(class ir_constant *);
    virtual ir_visitor_status visit(class ir_loop_jump *);
-   virtual ir_visitor_status visit(class ir_end_primitive *);
 
    /**
     * ir_dereference_variable isn't technically a leaf, but it is treated as a
@@ -138,6 +137,8 @@ public:
    virtual ir_visitor_status visit_leave(class ir_if *);
    virtual ir_visitor_status visit_enter(class ir_emit_vertex *);
    virtual ir_visitor_status visit_leave(class ir_emit_vertex *);
+   virtual ir_visitor_status visit_enter(class ir_end_primitive *);
+   virtual ir_visitor_status visit_leave(class ir_end_primitive *);
    /*@}*/
 
 
index f6332836b1c91f641259f51a8d3968ae5d30cca2..3ca7a58871a02aaa5d0e3f4696a5aa6bb987f506 100644 (file)
@@ -420,5 +420,13 @@ ir_emit_vertex::accept(ir_hierarchical_visitor *v)
 ir_visitor_status
 ir_end_primitive::accept(ir_hierarchical_visitor *v)
 {
-   return v->visit(this);
+   ir_visitor_status s = v->visit_enter(this);
+   if (s != visit_continue)
+      return (s == visit_continue_with_parent) ? visit_continue : s;
+
+   s = this->stream->accept(v);
+   if (s != visit_continue)
+      return (s == visit_continue_with_parent) ? visit_continue : s;
+
+   return (s == visit_stop) ? s : v->visit_leave(this);
 }
index eb6691ea1d978e37ff7f1484465552f690af1136..0370170b3bfcfaa8bba06ac2e8bd6c2e33281dc3 100644 (file)
@@ -156,6 +156,13 @@ ir_rvalue_base_visitor::rvalue_visit(ir_emit_vertex *ir)
    return visit_continue;
 }
 
+ir_visitor_status
+ir_rvalue_base_visitor::rvalue_visit(ir_end_primitive *ir)
+{
+   handle_rvalue(&ir->stream);
+   return visit_continue;
+}
+
 ir_visitor_status
 ir_rvalue_visitor::visit_leave(ir_expression *ir)
 {
@@ -216,6 +223,12 @@ ir_rvalue_visitor::visit_leave(ir_emit_vertex *ir)
    return rvalue_visit(ir);
 }
 
+ir_visitor_status
+ir_rvalue_visitor::visit_leave(ir_end_primitive *ir)
+{
+   return rvalue_visit(ir);
+}
+
 ir_visitor_status
 ir_rvalue_enter_visitor::visit_enter(ir_expression *ir)
 {
@@ -275,3 +288,9 @@ ir_rvalue_enter_visitor::visit_enter(ir_emit_vertex *ir)
 {
    return rvalue_visit(ir);
 }
+
+ir_visitor_status
+ir_rvalue_enter_visitor::visit_enter(ir_end_primitive *ir)
+{
+   return rvalue_visit(ir);
+}
index ad1694168a0ff318a50cad14ab0a2fbfb50e8f14..04ec0fa398ce37c28e699f1959dd2a69bb1aa305 100644 (file)
@@ -42,6 +42,7 @@ public:
    ir_visitor_status rvalue_visit(ir_swizzle *);
    ir_visitor_status rvalue_visit(ir_texture *);
    ir_visitor_status rvalue_visit(ir_emit_vertex *);
+   ir_visitor_status rvalue_visit(ir_end_primitive *);
 
    virtual void handle_rvalue(ir_rvalue **rvalue) = 0;
 };
@@ -59,6 +60,7 @@ public:
    virtual ir_visitor_status visit_leave(ir_swizzle *);
    virtual ir_visitor_status visit_leave(ir_texture *);
    virtual ir_visitor_status visit_leave(ir_emit_vertex *);
+   virtual ir_visitor_status visit_leave(ir_end_primitive *);
 };
 
 class ir_rvalue_enter_visitor : public ir_rvalue_base_visitor {
@@ -74,4 +76,5 @@ public:
    virtual ir_visitor_status visit_enter(ir_swizzle *);
    virtual ir_visitor_status visit_enter(ir_texture *);
    virtual ir_visitor_status visit_enter(ir_emit_vertex *);
+   virtual ir_visitor_status visit_enter(ir_end_primitive *);
 };