i965/fs: Reference the core GL uniform storage for non-builtin uniforms.
authorEric Anholt <eric@anholt.net>
Wed, 21 Nov 2012 01:43:31 +0000 (17:43 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 28 Dec 2012 18:53:45 +0000 (10:53 -0800)
There's no reason to use an external copy if the relayout in the
external copy isn't serving us.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp

index e157dc2915524a2ce93048bca9c1fe60d1411852..ae26d07e03d71240155a0435473195927e104cc2 100644 (file)
@@ -792,55 +792,41 @@ fs_visitor::import_uniforms(fs_visitor *v)
  * get stored, rather than in some global gl_shader_program uniform
  * store.
  */
-int
-fs_visitor::setup_uniform_values(int loc, const glsl_type *type)
+void
+fs_visitor::setup_uniform_values(ir_variable *ir)
 {
-   unsigned int offset = 0;
-
-   if (type->is_matrix()) {
-      const glsl_type *column = glsl_type::get_instance(GLSL_TYPE_FLOAT,
-                                                       type->vector_elements,
-                                                       1);
-
-      for (unsigned int i = 0; i < type->matrix_columns; i++) {
-        offset += setup_uniform_values(loc + offset, column);
-      }
-
-      return offset;
-   }
+   int namelen = strlen(ir->name);
 
-   switch (type->base_type) {
-   case GLSL_TYPE_FLOAT:
-   case GLSL_TYPE_UINT:
-   case GLSL_TYPE_INT:
-   case GLSL_TYPE_BOOL:
-      for (unsigned int i = 0; i < type->vector_elements; i++) {
-        c->prog_data.param[c->prog_data.nr_params++] =
-            &fp->Base.Parameters->ParameterValues[loc][i].f;
+   /* The data for our (non-builtin) uniforms is stored in a series of
+    * gl_uniform_driver_storage structs for each subcomponent that
+    * glGetUniformLocation() could name.  We know it's been set up in the same
+    * order we'd walk the type, so walk the list of storage and find anything
+    * with our name, or the prefix of a component that starts with our name.
+    */
+   unsigned params_before = c->prog_data.nr_params;
+   for (unsigned u = 0; u < prog->NumUserUniformStorage; u++) {
+      struct gl_uniform_storage *storage = &prog->UniformStorage[u];
+
+      if (strncmp(ir->name, storage->name, namelen) != 0 ||
+          (storage->name[namelen] != 0 &&
+           storage->name[namelen] != '.' &&
+           storage->name[namelen] != '[')) {
+         continue;
       }
-      return 1;
 
-   case GLSL_TYPE_STRUCT:
-      for (unsigned int i = 0; i < type->length; i++) {
-        offset += setup_uniform_values(loc + offset,
-                                       type->fields.structure[i].type);
-      }
-      return offset;
+      unsigned slots = storage->type->component_slots();
+      if (storage->array_elements)
+         slots *= storage->array_elements;
 
-   case GLSL_TYPE_ARRAY:
-      for (unsigned int i = 0; i < type->length; i++) {
-        offset += setup_uniform_values(loc + offset, type->fields.array);
+      for (unsigned i = 0; i < slots; i++) {
+         c->prog_data.param[c->prog_data.nr_params++] =
+            &storage->storage[i].f;
       }
-      return offset;
-
-   case GLSL_TYPE_SAMPLER:
-      /* The sampler takes up a slot, but we don't use any values from it. */
-      return 1;
-
-   default:
-      assert(!"not reached");
-      return 0;
    }
+
+   /* Make sure we actually initialized the right amount of stuff here. */
+   assert(params_before + ir->type->component_slots() ==
+          c->prog_data.nr_params);
 }
 
 
index d80129887bca6aaa2af04593686a317efb377779..bcf38f3cf7994647e2c580c122ba8545e9dfd8d3 100644 (file)
@@ -407,7 +407,7 @@ public:
    fs_reg get_timestamp();
 
    struct brw_reg interp_reg(int location, int channel);
-   int setup_uniform_values(int loc, const glsl_type *type);
+   void setup_uniform_values(ir_variable *ir);
    void setup_builtin_uniform_values(ir_variable *ir);
    int implied_mrf_writes(fs_inst *inst);
 
index d85d48b81beeaaaa453639422f72168cb1a6a68f..e70d6bf89c5b813d1418741aad837e3145c4fe36 100644 (file)
@@ -121,7 +121,7 @@ fs_visitor::visit(ir_variable *ir)
       if (!strncmp(ir->name, "gl_", 3)) {
         setup_builtin_uniform_values(ir);
       } else {
-        setup_uniform_values(ir->location, ir->type);
+        setup_uniform_values(ir);
       }
 
       reg = new(this->mem_ctx) fs_reg(UNIFORM, param_index);