[Mesa-dev] [PATCH 2/4] glsl: Rename uniform_field_visitor to program_resource_visitor.

Paul Berry stereotype441 at gmail.com
Thu Jan 31 16:34:41 PST 2013


There's actually nothing uniform-specific in uniform_field_visitor.
It is potentially useful for all kinds of program resources (in
particular, future patches will use it for transform feedback
varyings).

This patch renames it to program_resource_visitor, and clarifies
several comments, to reflect the fact that it is useful for more than
just uniforms.

NOTE: This is a candidate for the 9.1 branch.
---
 src/glsl/link_uniform_blocks.cpp |  6 +++---
 src/glsl/link_uniforms.cpp       | 24 ++++++++++++------------
 src/glsl/linker.h                | 33 +++++++++++++++++----------------
 src/mesa/program/ir_to_mesa.cpp  |  4 ++--
 4 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/src/glsl/link_uniform_blocks.cpp b/src/glsl/link_uniform_blocks.cpp
index 74fe1e2..c72d1d8 100644
--- a/src/glsl/link_uniform_blocks.cpp
+++ b/src/glsl/link_uniform_blocks.cpp
@@ -29,7 +29,7 @@
 #include "main/hash_table.h"
 #include "program.h"
 
-class ubo_visitor : public uniform_field_visitor {
+class ubo_visitor : public program_resource_visitor {
 public:
    ubo_visitor(void *mem_ctx, gl_uniform_buffer_variable *variables,
                unsigned num_variables)
@@ -44,7 +44,7 @@ public:
       this->offset = 0;
       this->buffer_size = 0;
       this->is_array_instance = strchr(name, ']') != NULL;
-      this->uniform_field_visitor::process(type, name);
+      this->program_resource_visitor::process(type, name);
    }
 
    unsigned index;
@@ -112,7 +112,7 @@ private:
    }
 };
 
-class count_block_size : public uniform_field_visitor {
+class count_block_size : public program_resource_visitor {
 public:
    count_block_size() : num_active_uniforms(0)
    {
diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index f1284ad..d457e4d 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -52,7 +52,7 @@ values_for_type(const glsl_type *type)
 }
 
 void
-uniform_field_visitor::process(const glsl_type *type, const char *name)
+program_resource_visitor::process(const glsl_type *type, const char *name)
 {
    assert(type->is_record()
           || (type->is_array() && type->fields.array->is_record())
@@ -65,7 +65,7 @@ uniform_field_visitor::process(const glsl_type *type, const char *name)
 }
 
 void
-uniform_field_visitor::process(ir_variable *var)
+program_resource_visitor::process(ir_variable *var)
 {
    const glsl_type *t = var->type;
 
@@ -93,8 +93,8 @@ uniform_field_visitor::process(ir_variable *var)
 }
 
 void
-uniform_field_visitor::recursion(const glsl_type *t, char **name,
-                                 size_t name_length, bool row_major)
+program_resource_visitor::recursion(const glsl_type *t, char **name,
+                                    size_t name_length, bool row_major)
 {
    /* Records need to have each field processed individually.
     *
@@ -110,7 +110,7 @@ uniform_field_visitor::recursion(const glsl_type *t, char **name,
          if (t->fields.structure[i].type->is_record())
             this->visit_field(&t->fields.structure[i]);
 
-         /* Append '.field' to the current uniform name. */
+         /* Append '.field' to the current variable name. */
          if (name_length == 0) {
             ralloc_asprintf_rewrite_tail(name, &new_length, "%s", field);
          } else {
@@ -125,7 +125,7 @@ uniform_field_visitor::recursion(const glsl_type *t, char **name,
       for (unsigned i = 0; i < t->length; i++) {
 	 size_t new_length = name_length;
 
-	 /* Append the subscript to the current uniform name */
+	 /* Append the subscript to the current variable name */
 	 ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]", i);
 
          recursion(t->fields.array, name, new_length,
@@ -137,7 +137,7 @@ uniform_field_visitor::recursion(const glsl_type *t, char **name,
 }
 
 void
-uniform_field_visitor::visit_field(const glsl_struct_field *field)
+program_resource_visitor::visit_field(const glsl_struct_field *field)
 {
    (void) field;
    /* empty */
@@ -153,7 +153,7 @@ uniform_field_visitor::visit_field(const glsl_struct_field *field)
  * If the same uniform is added multiple times (i.e., once for each shader
  * target), it will only be accounted once.
  */
-class count_uniform_size : public uniform_field_visitor {
+class count_uniform_size : public program_resource_visitor {
 public:
    count_uniform_size(struct string_to_uint_map *map)
       : num_active_uniforms(0), num_values(0), num_shader_samplers(0),
@@ -171,10 +171,10 @@ public:
    void process(ir_variable *var)
    {
       if (var->is_interface_instance())
-         uniform_field_visitor::process(var->interface_type,
-                                        var->interface_type->name);
+         program_resource_visitor::process(var->interface_type,
+                                           var->interface_type->name);
       else
-         uniform_field_visitor::process(var);
+         program_resource_visitor::process(var);
    }
 
    /**
@@ -258,7 +258,7 @@ private:
  * the \c gl_uniform_storage and \c gl_constant_value arrays are "big
  * enough."
  */
-class parcel_out_uniform_storage : public uniform_field_visitor {
+class parcel_out_uniform_storage : public program_resource_visitor {
 public:
    parcel_out_uniform_storage(struct string_to_uint_map *map,
 			      struct gl_uniform_storage *uniforms,
diff --git a/src/glsl/linker.h b/src/glsl/linker.h
index 14eb9c1..f1ce50a 100644
--- a/src/glsl/linker.h
+++ b/src/glsl/linker.h
@@ -61,38 +61,39 @@ link_uniform_blocks(void *mem_ctx,
                     struct gl_uniform_block **blocks_ret);
 
 /**
- * Class for processing all of the leaf fields of an uniform
+ * Class for processing all of the leaf fields of a variable that corresponds
+ * to a program resource.
  *
- * Leaves are, roughly speaking, the parts of the uniform that the application
- * could query with \c glGetUniformLocation (or that could be returned by
- * \c glGetActiveUniforms).
+ * The leaf fields are all the parts of the variable that the application
+ * could query using \c glGetProgramResourceIndex (or that could be returned
+ * by \c glGetProgramResourceName).
  *
  * Classes my derive from this class to implement specific functionality.
  * This class only provides the mechanism to iterate over the leaves.  Derived
  * classes must implement \c ::visit_field and may override \c ::process.
  */
-class uniform_field_visitor {
+class program_resource_visitor {
 public:
    /**
-    * Begin processing a uniform
+    * Begin processing a variable
     *
     * Classes that overload this function should call \c ::process from the
-    * base class to start the recursive processing of the uniform.
+    * base class to start the recursive processing of the variable.
     *
-    * \param var  The uniform variable that is to be processed
+    * \param var  The variable that is to be processed
     *
-    * Calls \c ::visit_field for each leaf of the uniform.
+    * Calls \c ::visit_field for each leaf of the variable.
     *
     * \warning
-    * This entry should only be used with uniform blocks in cases where the
-    * row / column ordering of matrices in the block does not matter.  For
-    * example, enumerating the names of members of the block, but not for
-    * determining the offsets of members.
+    * When processing a uniform block, this entry should only be used in cases
+    * where the row / column ordering of matrices in the block does not
+    * matter.  For example, enumerating the names of members of the block, but
+    * not for determining the offsets of members.
     */
    void process(ir_variable *var);
 
    /**
-    * Begin processing a uniform of a structured type.
+    * Begin processing a variable of a structured type.
     *
     * This flavor of \c process should be used to handle structured types
     * (i.e., structures, interfaces, or arrays there of) that need special
@@ -100,7 +101,7 @@ public:
     * (instead of the instance name) is used for an interface block.
     *
     * \param type  Type that is to be processed, associated with \c name
-    * \param name  Base name of the structured uniform being processed
+    * \param name  Base name of the structured variable being processed
     *
     * \note
     * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
@@ -110,7 +111,7 @@ public:
 
 protected:
    /**
-    * Method invoked for each leaf of the uniform
+    * Method invoked for each leaf of the variable
     *
     * \param type  Type of the field.
     * \param name  Fully qualified name of the field.
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index cd89171..ce409ec 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2375,7 +2375,7 @@ print_program(struct prog_instruction *mesa_instructions,
    }
 }
 
-class add_uniform_to_shader : public uniform_field_visitor {
+class add_uniform_to_shader : public program_resource_visitor {
 public:
    add_uniform_to_shader(struct gl_shader_program *shader_program,
 			 struct gl_program_parameter_list *params)
@@ -2387,7 +2387,7 @@ public:
    void process(ir_variable *var)
    {
       this->idx = -1;
-      this->uniform_field_visitor::process(var);
+      this->program_resource_visitor::process(var);
 
       var->location = this->idx;
    }
-- 
1.8.1.2



More information about the mesa-dev mailing list