glsl: Modify ir_emit_vertex to have a stream.
authorIago Toral Quiroga <itoral@igalia.com>
Fri, 20 Jun 2014 08:26:29 +0000 (10:26 +0200)
committerIago Toral Quiroga <itoral@igalia.com>
Mon, 30 Jun 2014 06:08:50 +0000 (08:08 +0200)
This will be necessary to implement EmitStreamVertex().
EmitVertex() will produce an ir_emit_vertex 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
src/glsl/lower_output_reads.cpp
src/glsl/lower_packed_varyings.cpp
src/glsl/opt_dead_code_local.cpp

index f9f06862e4427ed81ff03d377ea1ac4b563a21b3..33b8843928ea5236b603c2ae1691cd607e65a5fd 100644 (file)
@@ -3872,7 +3872,8 @@ builtin_builder::_EmitVertex()
 {
    MAKE_SIG(glsl_type::void_type, gs_only, 0);
 
-   body.emit(new(mem_ctx) ir_emit_vertex());
+   ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
+   body.emit(new(mem_ctx) ir_emit_vertex(stream));
 
    return sig;
 }
index 2e422ddac4adde0b2bbd39c6e43f0bccb04ed35d..fa22190d6fa6ca7c8d682ee39c3b8a87d650485b 100644 (file)
@@ -2159,9 +2159,11 @@ private:
  */
 class ir_emit_vertex : public ir_instruction {
 public:
-   ir_emit_vertex()
-      : ir_instruction(ir_type_emit_vertex)
+   ir_emit_vertex(ir_rvalue *stream)
+      : ir_instruction(ir_type_emit_vertex),
+        stream(stream)
    {
+      assert(stream);
    }
 
    virtual void accept(ir_visitor *v)
@@ -2169,12 +2171,19 @@ public:
       v->visit(this);
    }
 
-   virtual ir_emit_vertex *clone(void *mem_ctx, struct hash_table *) const
+   virtual ir_emit_vertex *clone(void *mem_ctx, struct hash_table *ht) const
    {
-      return new(mem_ctx) ir_emit_vertex();
+      return new(mem_ctx) ir_emit_vertex(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 2e606dda4bef26500c08cdf7f0b8a73fb2bb5108..78ae2df1d3d86ee1bb54b120cb045df5659825ef 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_emit_vertex *ir)
-{
-   if (this->callback != NULL)
-      this->callback(ir, this->data);
-
-   return visit_continue;
-}
-
 ir_visitor_status
 ir_hierarchical_visitor::visit(ir_end_primitive *ir)
 {
@@ -303,6 +294,22 @@ ir_hierarchical_visitor::visit_leave(ir_if *ir)
    return visit_continue;
 }
 
+ir_visitor_status
+ir_hierarchical_visitor::visit_enter(ir_emit_vertex *ir)
+{
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
+   return visit_continue;
+}
+
+ir_visitor_status
+ir_hierarchical_visitor::visit_leave(ir_emit_vertex *ir)
+{
+   (void) ir;
+   return visit_continue;
+}
+
 void
 ir_hierarchical_visitor::run(exec_list *instructions)
 {
index 647d2e002e522f4eb9c02b468fcdd88c9080aa3b..1679e0a0822def4b273b28685dbf3ec772eb1bfd 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_emit_vertex *);
    virtual ir_visitor_status visit(class ir_end_primitive *);
 
    /**
@@ -137,6 +136,8 @@ public:
    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 *);
+   virtual ir_visitor_status visit_enter(class ir_emit_vertex *);
+   virtual ir_visitor_status visit_leave(class ir_emit_vertex *);
    /*@}*/
 
 
index 2a1f70e5baa12d18f4d223df67084a5f9b44fc99..f6332836b1c91f641259f51a8d3968ae5d30cca2 100644 (file)
@@ -405,7 +405,15 @@ ir_if::accept(ir_hierarchical_visitor *v)
 ir_visitor_status
 ir_emit_vertex::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 fcbe9448d9c313d77cfb23be7d06e48d4328c066..eb6691ea1d978e37ff7f1484465552f690af1136 100644 (file)
@@ -149,6 +149,12 @@ ir_rvalue_base_visitor::rvalue_visit(ir_if *ir)
    return visit_continue;
 }
 
+ir_visitor_status
+ir_rvalue_base_visitor::rvalue_visit(ir_emit_vertex *ir)
+{
+   handle_rvalue(&ir->stream);
+   return visit_continue;
+}
 
 ir_visitor_status
 ir_rvalue_visitor::visit_leave(ir_expression *ir)
@@ -204,6 +210,12 @@ ir_rvalue_visitor::visit_leave(ir_if *ir)
    return rvalue_visit(ir);
 }
 
+ir_visitor_status
+ir_rvalue_visitor::visit_leave(ir_emit_vertex *ir)
+{
+   return rvalue_visit(ir);
+}
+
 ir_visitor_status
 ir_rvalue_enter_visitor::visit_enter(ir_expression *ir)
 {
@@ -257,3 +269,9 @@ ir_rvalue_enter_visitor::visit_enter(ir_if *ir)
 {
    return rvalue_visit(ir);
 }
+
+ir_visitor_status
+ir_rvalue_enter_visitor::visit_enter(ir_emit_vertex *ir)
+{
+   return rvalue_visit(ir);
+}
index 2179fa5a8f739b8c2e4de6db008d0a15ce7ce03d..ad1694168a0ff318a50cad14ab0a2fbfb50e8f14 100644 (file)
@@ -41,6 +41,7 @@ public:
    ir_visitor_status rvalue_visit(ir_return *);
    ir_visitor_status rvalue_visit(ir_swizzle *);
    ir_visitor_status rvalue_visit(ir_texture *);
+   ir_visitor_status rvalue_visit(ir_emit_vertex *);
 
    virtual void handle_rvalue(ir_rvalue **rvalue) = 0;
 };
@@ -57,6 +58,7 @@ public:
    virtual ir_visitor_status visit_leave(ir_return *);
    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 *);
 };
 
 class ir_rvalue_enter_visitor : public ir_rvalue_base_visitor {
@@ -71,4 +73,5 @@ public:
    virtual ir_visitor_status visit_enter(ir_return *);
    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 *);
 };
index afe17766beb17982824a36141d77777c2f13b005..1ee815d5eceb35d21e32b9f392044b7453f15fa3 100644 (file)
@@ -52,7 +52,7 @@ public:
    output_read_remover();
    ~output_read_remover();
    virtual ir_visitor_status visit(class ir_dereference_variable *);
-   virtual ir_visitor_status visit(class ir_emit_vertex *);
+   virtual ir_visitor_status visit_leave(class ir_emit_vertex *);
    virtual ir_visitor_status visit_leave(class ir_return *);
    virtual ir_visitor_status visit_leave(class ir_function_signature *);
 };
@@ -148,7 +148,7 @@ output_read_remover::visit_leave(ir_return *ir)
 }
 
 ir_visitor_status
-output_read_remover::visit(ir_emit_vertex *ir)
+output_read_remover::visit_leave(ir_emit_vertex *ir)
 {
    hash_table_call_foreach(replacements, emit_return_copy, ir);
    hash_table_clear(replacements);
index e8654748f5b5bce95c8418ee17524784bcc0329e..eda56a97b14b512c8b714b5ee59d5cf58660fbfe 100644 (file)
@@ -613,7 +613,7 @@ public:
    explicit lower_packed_varyings_gs_splicer(void *mem_ctx,
                                              const exec_list *instructions);
 
-   virtual ir_visitor_status visit(ir_emit_vertex *ev);
+   virtual ir_visitor_status visit_leave(ir_emit_vertex *ev);
 
 private:
    /**
@@ -637,7 +637,7 @@ lower_packed_varyings_gs_splicer::lower_packed_varyings_gs_splicer(
 
 
 ir_visitor_status
-lower_packed_varyings_gs_splicer::visit(ir_emit_vertex *ev)
+lower_packed_varyings_gs_splicer::visit_leave(ir_emit_vertex *ev)
 {
    foreach_list(node, this->instructions) {
       ir_instruction *ir = (ir_instruction *) node;
index c27c526f9f94c821dec8e36f61e06338d4149671..88895fb0e8767eb04bbd95cfa83cf86ff75badcf 100644 (file)
@@ -114,7 +114,7 @@ public:
       return visit_continue_with_parent;
    }
 
-   virtual ir_visitor_status visit(ir_emit_vertex *)
+   virtual ir_visitor_status visit_leave(ir_emit_vertex *)
    {
       /* For the purpose of dead code elimination, emitting a vertex counts as
        * "reading" all of the currently assigned output variables.