diff options
author | Eric Anholt <[email protected]> | 2010-06-03 09:39:54 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2010-06-24 15:05:21 -0700 |
commit | a9b619bb3b96a90d14650771dedaf1db840d70a6 (patch) | |
tree | 7de4ca0009f0155d194959296bb35d77c90375f8 | |
parent | 554dbcce77cc7eb38b786c77eee87a5f391b090b (diff) |
ir_to_mesa: Set up storage for uniform vars.
-rw-r--r-- | ir_to_mesa.cpp | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/ir_to_mesa.cpp b/ir_to_mesa.cpp index 7a1f206cd41..56815ac8e1a 100644 --- a/ir_to_mesa.cpp +++ b/ir_to_mesa.cpp @@ -88,6 +88,9 @@ public: int next_temp; int next_constant; + int next_uniform; + + temp_entry *find_variable_storage(ir_variable *var); ir_to_mesa_src_reg get_temp(int size); @@ -334,13 +337,16 @@ type_size(const struct glsl_type *type) case GLSL_TYPE_INT: case GLSL_TYPE_FLOAT: case GLSL_TYPE_BOOL: - assert(!type->is_matrix()); - /* Regardless of size of vector, it gets a vec4. This is bad - * packing for things like floats, but otherwise arrays become a - * mess. Hopefully a later pass over the code can pack scalars - * down if appropriate. - */ - return 1; + if (type->is_matrix()) { + return 4; /* FINISHME: Not all matrices are 4x4. */ + } else { + /* Regardless of size of vector, it gets a vec4. This is bad + * packing for things like floats, but otherwise arrays become a + * mess. Hopefully a later pass over the code can pack scalars + * down if appropriate. + */ + return 1; + } case GLSL_TYPE_ARRAY: return type_size(type->fields.array) * type->length; case GLSL_TYPE_STRUCT: @@ -354,29 +360,40 @@ type_size(const struct glsl_type *type) } } -ir_to_mesa_src_reg -ir_to_mesa_visitor::get_temp_for_var(ir_variable *var) +temp_entry * +ir_to_mesa_visitor::find_variable_storage(ir_variable *var) { - ir_to_mesa_src_reg src_reg; - + temp_entry *entry; foreach_iter(exec_list_iterator, iter, this->variable_storage) { entry = (temp_entry *)iter.get(); if (entry->var == var) - goto done; + return entry; } - entry = new temp_entry(var, PROGRAM_TEMPORARY, this->next_temp); - this->variable_storage.push_tail(entry); + return NULL; +} - next_temp += type_size(var->type); +ir_to_mesa_src_reg +ir_to_mesa_visitor::get_temp_for_var(ir_variable *var) +{ + temp_entry *entry; + ir_to_mesa_src_reg src_reg; + + entry = find_variable_storage(var); + if (!entry) { + entry = new temp_entry(var, PROGRAM_TEMPORARY, this->next_temp); + this->variable_storage.push_tail(entry); + + next_temp += type_size(var->type); + } -done: src_reg.file = entry->file; src_reg.index = entry->index; src_reg.swizzle = swizzle_for_size(var->type->vector_elements); + src_reg.reladdr = false; return src_reg; } @@ -384,7 +401,16 @@ done: void ir_to_mesa_visitor::visit(ir_variable *ir) { - (void)ir; + if (ir->mode == ir_var_uniform) { + temp_entry *entry = find_variable_storage(ir); + + if (!entry) { + entry = new temp_entry(ir, PROGRAM_UNIFORM, this->next_uniform); + this->variable_storage.push_tail(entry); + + this->next_uniform += type_size(ir->type); + } + } } void @@ -997,6 +1023,7 @@ ir_to_mesa_visitor::ir_to_mesa_visitor() result.file = PROGRAM_UNDEFINED; next_temp = 1; next_constant = 0; + next_uniform = 0; } static struct prog_src_register |