<p dir="ltr">Perhaps I'm blind, but I don't see where that array var is used beyond just being incremented. Mind pointing it out?</p>
<div class="gmail_quote">On Mar 21, 2015 11:31 PM, "Timothy Arceri" <<a href="mailto:t_arceri@yahoo.com.au">t_arceri@yahoo.com.au</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sat, 2015-03-21 at 19:46 -0400, Ilia Mirkin wrote:<br>
> On Sat, Mar 21, 2015 at 5:49 AM, Timothy Arceri <<a href="mailto:t_arceri@yahoo.com.au">t_arceri@yahoo.com.au</a>> wrote:<br>
> > ---<br>
> > src/glsl/link_uniform_initializers.cpp | 51 ++++++++++++++++++++++++----------<br>
> > src/glsl/link_uniforms.cpp | 28 +++++++++++--------<br>
> > 2 files changed, 52 insertions(+), 27 deletions(-)<br>
> ><br>
> > diff --git a/src/glsl/link_uniform_initializers.cpp b/src/glsl/link_uniform_initializers.cpp<br>
> > index 6907384..7817314 100644<br>
> > --- a/src/glsl/link_uniform_initializers.cpp<br>
> > +++ b/src/glsl/link_uniform_initializers.cpp<br>
> > @@ -100,6 +100,38 @@ copy_constant_to_storage(union gl_constant_value *storage,<br>
> > }<br>
> ><br>
> > void<br>
> > +copy_constant_array_to_storage(struct gl_uniform_storage *const storage,<br>
> > + const ir_constant *val,<br>
> > + unsigned int *idx,<br>
> > + unsigned int *array_elements,<br>
> > + unsigned int boolean_true)<br>
> > +{<br>
> > + if (val->type->fields.array->is_array()) {<br>
> > + for (unsigned int i = 0; i < val->type->length; i++) {<br>
> > + copy_constant_array_to_storage(storage, val->array_elements[i],<br>
> > + idx, array_elements, boolean_true);<br>
> > + }<br>
> > + } else {<br>
> > + const enum glsl_base_type base_type =<br>
> > + val->array_elements[0]->type->base_type;<br>
> > + const unsigned int elements = val->array_elements[0]->type->components();<br>
> > + unsigned dmul = (base_type == GLSL_TYPE_DOUBLE) ? 2 : 1;<br>
> > + unsigned int length = MIN2(val->type->length,<br>
> > + (storage->array_elements - *array_elements));<br>
> > +<br>
> > + for (unsigned int i = 0; i < length; i++) {<br>
> > + copy_constant_to_storage(& storage->storage[*idx],<br>
> > + val->array_elements[i],<br>
> > + base_type,<br>
> > + elements,<br>
> > + boolean_true);<br>
> > + *idx += elements * dmul;<br>
> > + *array_elements = *array_elements + 1;<br>
> > + }<br>
> > + }<br>
> > +}<br>
> > +<br>
> > +void<br>
> > set_sampler_binding(gl_shader_program *prog, const char *name, int binding)<br>
> > {<br>
> > struct gl_uniform_storage *const storage =<br>
> > @@ -178,7 +210,7 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,<br>
> > field_constant = (ir_constant *)field_constant->next;<br>
> > }<br>
> > return;<br>
> > - } else if (type->is_array() && type->fields.array->is_record()) {<br>
> > + } else if (type->without_array()->is_record()) {<br>
><br>
> That's not what the old code looked for... it looked for array &&<br>
> array-of-record. You changed it to record ||-array-of-record ||<br>
> array-of-array-of-record || ... . You've done this several times<br>
> throughout this change. Are all of these changes safe?<br>
<br>
Yeah it's safe. In each case you will see that the non array version<br>
would be found in a preceding if statement so all we are really checking<br>
for is<br>
array-of-record || array-of-array-of-record || ...<br>
<br>
><br>
> > const glsl_type *const element_type = type->fields.array;<br>
> ><br>
> > for (unsigned int i = 0; i < type->length; i++) {<br>
> > @@ -201,22 +233,11 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,<br>
> > }<br>
> ><br>
> > if (val->type->is_array()) {<br>
> > - const enum glsl_base_type base_type =<br>
> > - val->array_elements[0]->type->base_type;<br>
> > - const unsigned int elements = val->array_elements[0]->type->components();<br>
> > unsigned int idx = 0;<br>
> > - unsigned dmul = (base_type == GLSL_TYPE_DOUBLE) ? 2 : 1;<br>
> > + unsigned int array_elements = 0;<br>
><br>
> What is this used for? I don't see it used here or in the function (as<br>
> temp shared storage).<br>
<br>
It's used in the function to calculate the amount of room left in<br>
storage so we don't overflow if the array is to big. Maybe it should be<br>
renamed to something better storage_count? used_storage_elements?<br>
total_array_elements?<br>
Or maybe I could just add a comment to the function:<br>
/* Used to calculate the space left in storage so we don't<br>
* overflow if the array is to big.<br>
*/<br>
<br>
><br>
> ><br>
> > - assert(val->type->length >= storage->array_elements);<br>
> > - for (unsigned int i = 0; i < storage->array_elements; i++) {<br>
> > - copy_constant_to_storage(& storage->storage[idx],<br>
> > - val->array_elements[i],<br>
> > - base_type,<br>
> > - elements,<br>
> > - boolean_true);<br>
> > -<br>
> > - idx += elements * dmul;<br>
> > - }<br>
> > + copy_constant_array_to_storage(storage, val, &idx,<br>
> > + &array_elements, boolean_true);<br>
> > } else {<br>
> > copy_constant_to_storage(storage->storage,<br>
> > val,<br>
> > diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp<br>
> > index 799c74b..654a1ca 100644<br>
> > --- a/src/glsl/link_uniforms.cpp<br>
> > +++ b/src/glsl/link_uniforms.cpp<br>
> > @@ -49,8 +49,8 @@ values_for_type(const glsl_type *type)<br>
> > {<br>
> > if (type->is_sampler()) {<br>
> > return 1;<br>
> > - } else if (type->is_array() && type->fields.array->is_sampler()) {<br>
> > - return type->array_size();<br>
> > + } else if (type->is_array()) {<br>
> > + return type->array_size() * values_for_type(type->fields.array);<br>
> > } else {<br>
> > return type->component_slots();<br>
> > }<br>
> > @@ -71,6 +71,7 @@ void<br>
> > program_resource_visitor::process(ir_variable *var)<br>
> > {<br>
> > const glsl_type *t = var->type;<br>
> > + const glsl_type *t_without_array = var->type->without_array();<br>
> > const bool row_major =<br>
> > var->data.matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR;<br>
> ><br>
> > @@ -136,7 +137,7 @@ program_resource_visitor::process(ir_variable *var)<br>
> > */<br>
> > recursion(var->type, &name, strlen(name), row_major, NULL, false);<br>
> > ralloc_free(name);<br>
> > - } else if (t->without_array()->is_record()) {<br>
> > + } else if (t_without_array->is_record()) {<br>
> > char *name = ralloc_strdup(NULL, var->name);<br>
> > recursion(var->type, &name, strlen(name), row_major, NULL, false);<br>
> > ralloc_free(name);<br>
> > @@ -144,8 +145,8 @@ program_resource_visitor::process(ir_variable *var)<br>
> > char *name = ralloc_strdup(NULL, var->type->name);<br>
> > recursion(var->type, &name, strlen(name), row_major, NULL, false);<br>
> > ralloc_free(name);<br>
> > - } else if (t->is_array() && t->fields.array->is_interface()) {<br>
> > - char *name = ralloc_strdup(NULL, var->type->fields.array->name);<br>
> > + } else if (t_without_array->is_interface()) {<br>
> > + char *name = ralloc_strdup(NULL, t_without_array->name);<br>
> > recursion(var->type, &name, strlen(name), row_major, NULL, false);<br>
> > ralloc_free(name);<br>
> > } else {<br>
> > @@ -216,8 +217,8 @@ program_resource_visitor::recursion(const glsl_type *t, char **name,<br>
> > (*name)[name_length] = '\0';<br>
> > this->leave_record(t, *name, row_major);<br>
> > }<br>
> > - } else if (t->is_array() && (t->fields.array->is_record()<br>
> > - || t->fields.array->is_interface())) {<br>
> > + } else if (t->without_array()->is_record()<br>
> > + || t->without_array()->is_interface()) {<br>
> > if (record_type == NULL && t->fields.array->is_record())<br>
> > record_type = t->fields.array;<br>
> ><br>
> > @@ -574,8 +575,12 @@ private:<br>
> ><br>
> > const glsl_type *base_type;<br>
> > if (type->is_array()) {<br>
> > - this->uniforms[id].array_elements = type->length;<br>
> > - base_type = type->fields.array;<br>
> > + this->uniforms[id].array_elements = type->length;<br>
> > + base_type = type->fields.array;<br>
> > + while (base_type->is_array()) {<br>
> > + this->uniforms[id].array_elements *= base_type->length;<br>
> > + base_type = base_type->fields.array;<br>
> > + }<br>
> > } else {<br>
> > this->uniforms[id].array_elements = 0;<br>
> > base_type = type;<br>
> > @@ -629,7 +634,7 @@ private:<br>
> ><br>
> > if (type->is_array()) {<br>
> > this->uniforms[id].array_stride =<br>
> > - glsl_align(type->fields.array->std140_size(row_major), 16);<br>
> > + glsl_align(type->without_array()->std140_size(row_major), 16);<br>
> > } else {<br>
> > this->uniforms[id].array_stride = 0;<br>
> > }<br>
> > @@ -768,8 +773,7 @@ link_update_uniform_buffer_variables(struct gl_shader *shader)<br>
> ><br>
> > if (var->type->is_record()) {<br>
> > sentinel = '.';<br>
> > - } else if (var->type->is_array()<br>
> > - && var->type->fields.array->is_record()) {<br>
> > + } else if (var->type->without_array()->is_record()) {<br>
> > sentinel = '[';<br>
> > }<br>
> ><br>
> > --<br>
> > 2.1.0<br>
> ><br>
> > _______________________________________________<br>
> > mesa-dev mailing list<br>
> > <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> > <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
<br>
<br>
</blockquote></div>