ir_to_mesa: Try to fix up the dereference handling for the visitor rework.
authorEric Anholt <eric@anholt.net>
Tue, 1 Jun 2010 23:23:57 +0000 (16:23 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 24 Jun 2010 22:05:21 +0000 (15:05 -0700)
One of the gstreamer shaders I play with now compiles, but input
mappings are wrong.

ir_to_mesa.cpp

index 59ee3b29f0a4aecf3117d31e3d09a22efe8355ef..8d3f65ffb207f5520a607b2e55c53aa96102b79a 100644 (file)
@@ -659,27 +659,26 @@ ir_to_mesa_visitor::visit(ir_dereference_variable *ir)
       MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z),
       MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W),
    };
-   ir_variable *var = ir->var;
 
    /* By the time we make it to this stage, matrices should be broken down
     * to vectors.
     */
-   assert(!var->type->is_matrix());
+   assert(!ir->var->type->is_matrix());
 
    tree = this->create_tree(MB_TERM_reference_vec4, ir, NULL, NULL);
 
-   if (strncmp(var->name, "gl_", 3) == 0) {
+   if (strncmp(ir->var->name, "gl_", 3) == 0) {
       unsigned int i;
 
       for (i = 0; i < ARRAY_SIZE(builtin_var_to_mesa_reg); i++) {
-        if (strcmp(var->name, builtin_var_to_mesa_reg[i].name) == 0)
+        if (strcmp(ir->var->name, builtin_var_to_mesa_reg[i].name) == 0)
            break;
       }
       assert(i != ARRAY_SIZE(builtin_var_to_mesa_reg));
       ir_to_mesa_set_tree_reg(tree, builtin_var_to_mesa_reg[i].file,
                              builtin_var_to_mesa_reg[i].index);
    } else {
-      this->get_temp_for_var(var, tree);
+      this->get_temp_for_var(ir->var, tree);
    }
 
    /* If the type is smaller than a vec4, replicate the last channel out. */
@@ -698,33 +697,25 @@ ir_to_mesa_visitor::visit(ir_dereference_array *ir)
       MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y),
       MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X),
    };
-   ir_variable *var = ir->variable_referenced();
-   ir_constant *index = ir->array_index->constant_expression_value();
+   ir_constant *index;
+
+   index = ir->array_index->constant_expression_value();
 
    /* By the time we make it to this stage, matrices should be broken down
     * to vectors.
     */
-   assert(!var->type->is_matrix());
-
-   if (strncmp(var->name, "gl_", 3) == 0) {
-      unsigned int i;
-      unsigned int offset = 0;
+   assert(!ir->type->is_matrix());
 
-      tree = this->create_tree(MB_TERM_reference_vec4, ir, NULL, NULL);
+   ir->array->accept(this);
+   tree = this->result;
 
-      offset = index->value.i[0];
+   if (tree->src_reg.file == PROGRAM_INPUT ||
+       tree->src_reg.file == PROGRAM_OUTPUT) {
+      assert(index); /* FINISHME: Handle variable indexing of builtins. */
 
-      for (i = 0; i < ARRAY_SIZE(builtin_var_to_mesa_reg); i++) {
-        if (strcmp(var->name, builtin_var_to_mesa_reg[i].name) == 0)
-           break;
-      }
-      assert(i != ARRAY_SIZE(builtin_var_to_mesa_reg));
-      ir_to_mesa_set_tree_reg(tree, builtin_var_to_mesa_reg[i].file,
-                             builtin_var_to_mesa_reg[i].index + offset);
+      tree->src_reg.index += index->value.i[0];
+      tree->dst_reg.index += index->value.i[0];
    } else {
-      tree = this->create_tree(MB_TERM_reference_vec4, ir, NULL, NULL);
-      this->get_temp_for_var(var, tree);
-
       if (index) {
         tree->src_reg.index += index->value.i[0];
         tree->dst_reg.index += index->value.i[0];