diff options
Diffstat (limited to 'mesalib/src/glsl')
-rw-r--r-- | mesalib/src/glsl/glsl_parser.yy | 1 | ||||
-rwxr-xr-x | mesalib/src/glsl/glsl_symbol_table.cpp | 25 | ||||
-rw-r--r-- | mesalib/src/glsl/glsl_symbol_table.h | 2 | ||||
-rw-r--r-- | mesalib/src/glsl/ir.h | 36 | ||||
-rw-r--r-- | mesalib/src/glsl/ir_clone.cpp | 10 | ||||
-rwxr-xr-x | mesalib/src/glsl/ir_constant_expression.cpp | 205 |
6 files changed, 110 insertions, 169 deletions
diff --git a/mesalib/src/glsl/glsl_parser.yy b/mesalib/src/glsl/glsl_parser.yy index 3798af455..531ae394b 100644 --- a/mesalib/src/glsl/glsl_parser.yy +++ b/mesalib/src/glsl/glsl_parser.yy @@ -1902,7 +1902,6 @@ struct_specifier: $$ = new(ctx) ast_struct_specifier($2, $4); $$->set_location_range(@2, @5); state->symbols->add_type($2, glsl_type::void_type); - state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$)); } | STRUCT '{' struct_declaration_list '}' { diff --git a/mesalib/src/glsl/glsl_symbol_table.cpp b/mesalib/src/glsl/glsl_symbol_table.cpp index 6ec4f534b..d17a5e66f 100755 --- a/mesalib/src/glsl/glsl_symbol_table.cpp +++ b/mesalib/src/glsl/glsl_symbol_table.cpp @@ -166,23 +166,6 @@ bool glsl_symbol_table::add_type(const char *name, const glsl_type *t) return _mesa_symbol_table_add_symbol(table, -1, name, entry) == 0; } -static char *make_ast_name(const char *name) -{ - char *ast_name = new char[strlen("#ast.") + strlen(name) + 1]; - strcpy(ast_name, "#ast."); - strcat(ast_name + strlen("#ast."), name); - return ast_name; -} - -bool glsl_symbol_table::add_type_ast(const char *name, const class ast_type_specifier *a) -{ - symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(a); - char *ast_name = make_ast_name(name); - bool ret = _mesa_symbol_table_add_symbol(table, -1, ast_name, entry) == 0; - delete [] ast_name; - return ret; -} - bool glsl_symbol_table::add_interface(const char *name, const glsl_type *i, enum ir_variable_mode mode) { @@ -234,14 +217,6 @@ const glsl_type *glsl_symbol_table::get_type(const char *name) return entry != NULL ? entry->t : NULL; } -const class ast_type_specifier *glsl_symbol_table::get_type_ast(const char *name) -{ - char *ast_name = make_ast_name(name); - symbol_table_entry *entry = get_entry(ast_name); - delete [] ast_name; - return entry != NULL ? entry->a : NULL; -} - const glsl_type *glsl_symbol_table::get_interface(const char *name, enum ir_variable_mode mode) { diff --git a/mesalib/src/glsl/glsl_symbol_table.h b/mesalib/src/glsl/glsl_symbol_table.h index 89d832125..83d7935d8 100644 --- a/mesalib/src/glsl/glsl_symbol_table.h +++ b/mesalib/src/glsl/glsl_symbol_table.h @@ -103,7 +103,6 @@ public: /*@{*/ bool add_variable(ir_variable *v); bool add_type(const char *name, const glsl_type *t); - bool add_type_ast(const char *name, const class ast_type_specifier *t); bool add_function(ir_function *f); bool add_interface(const char *name, const glsl_type *i, enum ir_variable_mode mode); @@ -120,7 +119,6 @@ public: /*@{*/ ir_variable *get_variable(const char *name); const glsl_type *get_type(const char *name); - const class ast_type_specifier *get_type_ast(const char *name); ir_function *get_function(const char *name); const glsl_type *get_interface(const char *name, enum ir_variable_mode mode); diff --git a/mesalib/src/glsl/ir.h b/mesalib/src/glsl/ir.h index ed3f086ce..8fa3b9ef6 100644 --- a/mesalib/src/glsl/ir.h +++ b/mesalib/src/glsl/ir.h @@ -1914,15 +1914,6 @@ public: * Get the variable that is ultimately referenced by an r-value */ virtual ir_variable *variable_referenced() const = 0; - - /** - * Get the constant that is ultimately referenced by an r-value, - * in a constant expression evaluation context. - * - * The offset is used when the reference is to a specific column of - * a matrix. - */ - virtual void constant_referenced(struct hash_table *variable_context, ir_constant *&store, int &offset) const = 0; }; @@ -1950,15 +1941,6 @@ public: return this->var; } - /** - * Get the constant that is ultimately referenced by an r-value, - * in a constant expression evaluation context. - * - * The offset is used when the reference is to a specific column of - * a matrix. - */ - virtual void constant_referenced(struct hash_table *variable_context, ir_constant *&store, int &offset) const; - virtual ir_variable *whole_variable_referenced() { /* ir_dereference_variable objects always dereference the entire @@ -2010,15 +1992,6 @@ public: return this->array->variable_referenced(); } - /** - * Get the constant that is ultimately referenced by an r-value, - * in a constant expression evaluation context. - * - * The offset is used when the reference is to a specific column of - * a matrix. - */ - virtual void constant_referenced(struct hash_table *variable_context, ir_constant *&store, int &offset) const; - virtual void accept(ir_visitor *v) { v->visit(this); @@ -2058,15 +2031,6 @@ public: return this->record->variable_referenced(); } - /** - * Get the constant that is ultimately referenced by an r-value, - * in a constant expression evaluation context. - * - * The offset is used when the reference is to a specific column of - * a matrix. - */ - virtual void constant_referenced(struct hash_table *variable_context, ir_constant *&store, int &offset) const; - virtual void accept(ir_visitor *v) { v->visit(this); diff --git a/mesalib/src/glsl/ir_clone.cpp b/mesalib/src/glsl/ir_clone.cpp index 311c992be..167b80c9f 100644 --- a/mesalib/src/glsl/ir_clone.cpp +++ b/mesalib/src/glsl/ir_clone.cpp @@ -265,10 +265,12 @@ ir_assignment::clone(void *mem_ctx, struct hash_table *ht) const if (this->condition) new_condition = this->condition->clone(mem_ctx, ht); - return new(mem_ctx) ir_assignment(this->lhs->clone(mem_ctx, ht), - this->rhs->clone(mem_ctx, ht), - new_condition, - this->write_mask); + ir_assignment *cloned = + new(mem_ctx) ir_assignment(this->lhs->clone(mem_ctx, ht), + this->rhs->clone(mem_ctx, ht), + new_condition); + cloned->write_mask = this->write_mask; + return cloned; } ir_function * diff --git a/mesalib/src/glsl/ir_constant_expression.cpp b/mesalib/src/glsl/ir_constant_expression.cpp index 48cf47f53..f5cb12343 100755 --- a/mesalib/src/glsl/ir_constant_expression.cpp +++ b/mesalib/src/glsl/ir_constant_expression.cpp @@ -379,8 +379,104 @@ unpack_half_1x16(uint16_t u) return _mesa_half_to_float(u); } +/** + * Get the constant that is ultimately referenced by an r-value, in a constant + * expression evaluation context. + * + * The offset is used when the reference is to a specific column of a matrix. + */ +static bool +constant_referenced(const ir_dereference *deref, + struct hash_table *variable_context, + ir_constant *&store, int &offset) +{ + store = NULL; + offset = 0; + + if (variable_context == NULL) + return false; + + switch (deref->ir_type) { + case ir_type_dereference_array: { + const ir_dereference_array *const da = + (const ir_dereference_array *) deref; + + ir_constant *const index_c = + da->array_index->constant_expression_value(variable_context); + + if (!index_c || !index_c->type->is_scalar() || !index_c->type->is_integer()) + break; + + const int index = index_c->type->base_type == GLSL_TYPE_INT ? + index_c->get_int_component(0) : + index_c->get_uint_component(0); + + ir_constant *substore; + int suboffset; + + const ir_dereference *const deref = da->array->as_dereference(); + if (!deref) + break; + + if (!constant_referenced(deref, variable_context, substore, suboffset)) + break; + + const glsl_type *const vt = da->array->type; + if (vt->is_array()) { + store = substore->get_array_element(index); + offset = 0; + } else if (vt->is_matrix()) { + store = substore; + offset = index * vt->vector_elements; + } else if (vt->is_vector()) { + store = substore; + offset = suboffset + index; + } + + break; + } + + case ir_type_dereference_record: { + const ir_dereference_record *const dr = + (const ir_dereference_record *) deref; + + const ir_dereference *const deref = dr->record->as_dereference(); + if (!deref) + break; + + ir_constant *substore; + int suboffset; + + if (!constant_referenced(deref, variable_context, substore, suboffset)) + break; + + /* Since we're dropping it on the floor... + */ + assert(suboffset == 0); + + store = substore->get_record_field(dr->field); + break; + } + + case ir_type_dereference_variable: { + const ir_dereference_variable *const dv = + (const ir_dereference_variable *) deref; + + store = (ir_constant *) hash_table_find(variable_context, dv->var); + break; + } + + default: + assert(!"Should not get here."); + break; + } + + return store != NULL; +} + + ir_constant * -ir_rvalue::constant_expression_value(struct hash_table *variable_context) +ir_rvalue::constant_expression_value(struct hash_table *) { assert(this->type->is_error()); return NULL; @@ -1527,7 +1623,7 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) ir_constant * -ir_texture::constant_expression_value(struct hash_table *variable_context) +ir_texture::constant_expression_value(struct hash_table *) { /* texture lookups aren't constant expressions */ return NULL; @@ -1563,19 +1659,6 @@ ir_swizzle::constant_expression_value(struct hash_table *variable_context) } -void -ir_dereference_variable::constant_referenced(struct hash_table *variable_context, - ir_constant *&store, int &offset) const -{ - if (variable_context) { - store = (ir_constant *)hash_table_find(variable_context, var); - offset = 0; - } else { - store = NULL; - offset = 0; - } -} - ir_constant * ir_dereference_variable::constant_expression_value(struct hash_table *variable_context) { @@ -1603,60 +1686,6 @@ ir_dereference_variable::constant_expression_value(struct hash_table *variable_c } -void -ir_dereference_array::constant_referenced(struct hash_table *variable_context, - ir_constant *&store, int &offset) const -{ - ir_constant *index_c = array_index->constant_expression_value(variable_context); - - if (!index_c || !index_c->type->is_scalar() || !index_c->type->is_integer()) { - store = 0; - offset = 0; - return; - } - - int index = index_c->type->base_type == GLSL_TYPE_INT ? - index_c->get_int_component(0) : - index_c->get_uint_component(0); - - ir_constant *substore; - int suboffset; - const ir_dereference *deref = array->as_dereference(); - if (!deref) { - store = 0; - offset = 0; - return; - } - - deref->constant_referenced(variable_context, substore, suboffset); - - if (!substore) { - store = 0; - offset = 0; - return; - } - - const glsl_type *vt = array->type; - if (vt->is_array()) { - store = substore->get_array_element(index); - offset = 0; - return; - } - if (vt->is_matrix()) { - store = substore; - offset = index * vt->vector_elements; - return; - } - if (vt->is_vector()) { - store = substore; - offset = suboffset + index; - return; - } - - store = 0; - offset = 0; -} - ir_constant * ir_dereference_array::constant_expression_value(struct hash_table *variable_context) { @@ -1712,33 +1741,8 @@ ir_dereference_array::constant_expression_value(struct hash_table *variable_cont } -void -ir_dereference_record::constant_referenced(struct hash_table *variable_context, - ir_constant *&store, int &offset) const -{ - ir_constant *substore; - int suboffset; - const ir_dereference *deref = record->as_dereference(); - if (!deref) { - store = 0; - offset = 0; - return; - } - - deref->constant_referenced(variable_context, substore, suboffset); - - if (!substore) { - store = 0; - offset = 0; - return; - } - - store = substore->get_record_field(field); - offset = 0; -} - ir_constant * -ir_dereference_record::constant_expression_value(struct hash_table *variable_context) +ir_dereference_record::constant_expression_value(struct hash_table *) { ir_constant *v = this->record->constant_expression_value(); @@ -1747,7 +1751,7 @@ ir_dereference_record::constant_expression_value(struct hash_table *variable_con ir_constant * -ir_assignment::constant_expression_value(struct hash_table *variable_context) +ir_assignment::constant_expression_value(struct hash_table *) { /* FINISHME: Handle CEs involving assignment (return RHS) */ return NULL; @@ -1755,7 +1759,7 @@ ir_assignment::constant_expression_value(struct hash_table *variable_context) ir_constant * -ir_constant::constant_expression_value(struct hash_table *variable_context) +ir_constant::constant_expression_value(struct hash_table *) { return this; } @@ -1796,9 +1800,8 @@ bool ir_function_signature::constant_expression_evaluate_expression_list(const s ir_constant *store = NULL; int offset = 0; - asg->lhs->constant_referenced(variable_context, store, offset); - if (!store) + if (!constant_referenced(asg->lhs, variable_context, store, offset)) return false; ir_constant *value = asg->rhs->constant_expression_value(variable_context); @@ -1829,9 +1832,9 @@ bool ir_function_signature::constant_expression_evaluate_expression_list(const s ir_constant *store = NULL; int offset = 0; - call->return_deref->constant_referenced(variable_context, store, offset); - if (!store) + if (!constant_referenced(call->return_deref, variable_context, + store, offset)) return false; ir_constant *value = call->constant_expression_value(variable_context); |