i965: Rename brw_disasm to brw_disassemble_inst.
[mesa.git] / src / glsl / link_uniforms.cpp
index 1c451e7f51c3bf22738bfbfe973603bfd79bae0b..c7147e0ee8eaf4e926a7bdf2876ebc954061fac7 100644 (file)
@@ -212,7 +212,7 @@ program_resource_visitor::recursion(const glsl_type *t, char **name,
 void
 program_resource_visitor::visit_field(const glsl_type *type, const char *name,
                                       bool row_major,
-                                      const glsl_type *record_type)
+                                      const glsl_type *)
 {
    visit_field(type, name, row_major);
 }
@@ -308,8 +308,7 @@ private:
        */
       const unsigned values = values_for_type(type);
       if (type->contains_sampler()) {
-        this->num_shader_samplers +=
-           type->is_array() ? type->array_size() : 1;
+         this->num_shader_samplers += values;
       } else if (type->contains_image()) {
          this->num_shader_images += values;
 
@@ -799,6 +798,10 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
    prog->UniformStorage = NULL;
    prog->NumUserUniformStorage = 0;
 
+   ralloc_free(prog->UniformRemapTable);
+   prog->UniformRemapTable = NULL;
+   prog->NumUniformRemapTable = 0;
+
    if (prog->UniformHash != NULL) {
       prog->UniformHash->clear();
    } else {
@@ -911,19 +914,28 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
              sizeof(prog->_LinkedShaders[i]->SamplerTargets));
    }
 
-   /* Determine the size of the largest uniform array queryable via
-    * glGetUniformLocation.  Using this as the location scale guarantees that
-    * there is enough "room" for the array index to be stored in the low order
-    * part of the uniform location.  It also makes the locations be more
-    * tightly packed.
-    */
-   unsigned max_array_size = 1;
+   /* Build the uniform remap table that is used to set/get uniform locations */
    for (unsigned i = 0; i < num_user_uniforms; i++) {
-      if (uniforms[i].array_elements > max_array_size)
-         max_array_size = uniforms[i].array_elements;
-   }
 
-   prog->UniformLocationBaseScale = max_array_size;
+      /* how many new entries for this uniform? */
+      const unsigned entries = MAX2(1, uniforms[i].array_elements);
+
+      /* resize remap table to fit new entries */
+      prog->UniformRemapTable =
+         reralloc(prog,
+                  prog->UniformRemapTable,
+                  gl_uniform_storage *,
+                  prog->NumUniformRemapTable + entries);
+
+      /* set pointers for this uniform */
+      for (unsigned j = 0; j < entries; j++)
+         prog->UniformRemapTable[prog->NumUniformRemapTable+j] = &uniforms[i];
+
+      /* set the base location in remap table for the uniform */
+      uniforms[i].remap_location = prog->NumUniformRemapTable;
+
+      prog->NumUniformRemapTable += entries;
+   }
 
 #ifndef NDEBUG
    for (unsigned i = 0; i < num_user_uniforms; i++) {