i965: Go back to using the kernel SOL reset feature.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_fs_vector_splitting.cpp
index 83b4af05bcbb6c9c7c5409216ee473eaabac5e28..b9487532c59f5bbc89a1b8491b07a0d0756d5047 100644 (file)
@@ -41,11 +41,11 @@ extern "C" {
 #include "main/core.h"
 #include "intel_context.h"
 }
-#include "../glsl/ir.h"
-#include "../glsl/ir_visitor.h"
-#include "../glsl/ir_print_visitor.h"
-#include "../glsl/ir_rvalue_visitor.h"
-#include "../glsl/glsl_types.h"
+#include "glsl/ir.h"
+#include "glsl/ir_visitor.h"
+#include "glsl/ir_print_visitor.h"
+#include "glsl/ir_rvalue_visitor.h"
+#include "glsl/glsl_types.h"
 
 static bool debug = false;
 
@@ -69,7 +69,7 @@ public:
 
    ir_variable *components[4];
 
-   /** talloc_parent(this->var) -- the shader's talloc context. */
+   /** ralloc_parent(this->var) -- the shader's ralloc context. */
    void *mem_ctx;
 };
 
@@ -77,13 +77,13 @@ class ir_vector_reference_visitor : public ir_hierarchical_visitor {
 public:
    ir_vector_reference_visitor(void)
    {
-      this->mem_ctx = talloc_new(NULL);
+      this->mem_ctx = ralloc_context(NULL);
       this->variable_list.make_empty();
    }
 
    ~ir_vector_reference_visitor(void)
    {
-      talloc_free(mem_ctx);
+      ralloc_free(mem_ctx);
    }
 
    virtual ir_visitor_status visit(ir_variable *);
@@ -110,11 +110,13 @@ ir_vector_reference_visitor::get_variable_entry(ir_variable *var)
 
    switch (var->mode) {
    case ir_var_uniform:
-   case ir_var_in:
-   case ir_var_out:
-   case ir_var_inout:
+   case ir_var_shader_in:
+   case ir_var_shader_out:
+   case ir_var_function_in:
+   case ir_var_function_out:
+   case ir_var_function_inout:
       /* Can't split varyings or uniforms.  Function in/outs won't get split
-       * either, so don't care about the ambiguity.
+       * either.
        */
       return NULL;
    case ir_var_auto:
@@ -122,8 +124,8 @@ ir_vector_reference_visitor::get_variable_entry(ir_variable *var)
       break;
    }
 
-   foreach_iter(exec_list_iterator, iter, this->variable_list) {
-      variable_entry *entry = (variable_entry *)iter.get();
+   foreach_list(node, &this->variable_list) {
+      variable_entry *entry = (variable_entry *)node;
       if (entry->var == var)
         return entry;
    }
@@ -209,13 +211,12 @@ public:
    virtual ir_visitor_status visit_leave(ir_assignment *);
 
    void handle_rvalue(ir_rvalue **rvalue);
-   struct variable_entry *get_splitting_entry(ir_variable *var);
+   variable_entry *get_splitting_entry(ir_variable *var);
 
    exec_list *variable_list;
-   void *mem_ctx;
 };
 
-struct variable_entry *
+variable_entry *
 ir_vector_splitting_visitor::get_splitting_entry(ir_variable *var)
 {
    assert(var);
@@ -223,8 +224,8 @@ ir_vector_splitting_visitor::get_splitting_entry(ir_variable *var)
    if (!var->type->is_vector())
       return NULL;
 
-   foreach_iter(exec_list_iterator, iter, *this->variable_list) {
-      variable_entry *entry = (variable_entry *)iter.get();
+   foreach_list(node, &*this->variable_list) {
+      variable_entry *entry = (variable_entry *)node;
       if (entry->var == var) {
         return entry;
       }
@@ -264,8 +265,10 @@ ir_vector_splitting_visitor::visit_leave(ir_assignment *ir)
    variable_entry *rhs = rhs_deref ? get_splitting_entry(rhs_deref->var) : NULL;
 
    if (lhs_deref && rhs_deref && (lhs || rhs) && !ir->condition) {
+      unsigned int rhs_chan = 0;
+
       /* Straight assignment of vector variables. */
-      for (unsigned int i = 0; i < ir->rhs->type->vector_elements; i++) {
+      for (unsigned int i = 0; i < ir->lhs->type->vector_elements; i++) {
         ir_dereference *new_lhs;
         ir_rvalue *new_rhs;
         void *mem_ctx = lhs ? lhs->mem_ctx : rhs->mem_ctx;
@@ -283,18 +286,22 @@ ir_vector_splitting_visitor::visit_leave(ir_assignment *ir)
         }
 
         if (rhs) {
-           new_rhs = new(mem_ctx) ir_dereference_variable(rhs->components[i]);
+           new_rhs =
+              new(mem_ctx) ir_dereference_variable(rhs->components[rhs_chan]);
         } else {
            new_rhs = new(mem_ctx) ir_swizzle(ir->rhs->clone(mem_ctx, NULL),
-                                             i, i, i, i, 1);
+                                             rhs_chan, 0, 0, 0, 1);
         }
 
         ir->insert_before(new(mem_ctx) ir_assignment(new_lhs,
                                                      new_rhs,
                                                      NULL, writemask));
+
+        rhs_chan++;
       }
       ir->remove();
    } else if (lhs) {
+      void *mem_ctx = lhs->mem_ctx;
       int elem = -1;
 
       switch (ir->write_mask) {
@@ -328,7 +335,6 @@ ir_vector_splitting_visitor::visit_leave(ir_assignment *ir)
    return visit_continue;
 }
 
-extern "C" {
 bool
 brw_do_vector_splitting(exec_list *instructions)
 {
@@ -337,8 +343,8 @@ brw_do_vector_splitting(exec_list *instructions)
    visit_list_elements(&refs, instructions);
 
    /* Trim out variables we can't split. */
-   foreach_iter(exec_list_iterator, iter, refs.variable_list) {
-      variable_entry *entry = (variable_entry *)iter.get();
+   foreach_list_safe(node, &refs.variable_list) {
+      variable_entry *entry = (variable_entry *)node;
 
       if (debug) {
         printf("vector %s@%p: decl %d, whole_access %d\n",
@@ -354,20 +360,20 @@ brw_do_vector_splitting(exec_list *instructions)
    if (refs.variable_list.is_empty())
       return false;
 
-   void *mem_ctx = talloc_new(NULL);
+   void *mem_ctx = ralloc_context(NULL);
 
    /* Replace the decls of the vectors to be split with their split
     * components.
     */
-   foreach_iter(exec_list_iterator, iter, refs.variable_list) {
-      variable_entry *entry = (variable_entry *)iter.get();
+   foreach_list(node, &refs.variable_list) {
+      variable_entry *entry = (variable_entry *)node;
       const struct glsl_type *type;
       type = glsl_type::get_instance(entry->var->type->base_type, 1, 1);
 
-      entry->mem_ctx = talloc_parent(entry->var);
+      entry->mem_ctx = ralloc_parent(entry->var);
 
       for (unsigned int i = 0; i < entry->var->type->vector_elements; i++) {
-        const char *name = talloc_asprintf(mem_ctx, "%s_%c",
+        const char *name = ralloc_asprintf(mem_ctx, "%s_%c",
                                            entry->var->name,
                                            "xyzw"[i]);
 
@@ -382,8 +388,7 @@ brw_do_vector_splitting(exec_list *instructions)
    ir_vector_splitting_visitor split(&refs.variable_list);
    visit_list_elements(&split, instructions);
 
-   talloc_free(mem_ctx);
+   ralloc_free(mem_ctx);
 
    return true;
 }
-}