[Mesa-dev] [PATCH 21/32] glsl: Add new uniform_field_visitor::process variant

Ian Romanick idr at freedesktop.org
Tue Jan 22 00:52:12 PST 2013


From: Ian Romanick <ian.d.romanick at intel.com>

This flavor takes a type and a base name.  It will be used to handle
cases where the block name (instead of the instance name) is used for an
interface block.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/link_uniforms.cpp | 22 ++++++++++++++++++++++
 src/glsl/linker.h          | 17 +++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index 57793ba..5edb69d 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -58,6 +58,19 @@ values_for_type(const glsl_type *type)
 }
 
 void
+uniform_field_visitor::process(const glsl_type *type, const char *name)
+{
+   assert(type->is_record()
+          || (type->is_array() && type->fields.array->is_record())
+          || type->is_interface()
+          || (type->is_array() && type->fields.array->is_interface()));
+
+   char *name_copy = ralloc_strdup(NULL, name);
+   recursion(type, &name_copy, strlen(name), false);
+   ralloc_free(name_copy);
+}
+
+void
 uniform_field_visitor::process(ir_variable *var)
 {
    const glsl_type *t = var->type;
@@ -156,6 +169,15 @@ public:
       this->num_shader_uniform_components = 0;
    }
 
+   void process(ir_variable *var)
+   {
+      if (var->is_interface_instance())
+         uniform_field_visitor::process(var->interface_type,
+                                        var->interface_type->name);
+      else
+         uniform_field_visitor::process(var);
+   }
+
    /**
     * Total number of active uniforms counted
     */
diff --git a/src/glsl/linker.h b/src/glsl/linker.h
index 856b263..71586d0 100644
--- a/src/glsl/linker.h
+++ b/src/glsl/linker.h
@@ -78,6 +78,23 @@ public:
     */
    void process(ir_variable *var);
 
+   /**
+    * Begin processing a uniform 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
+    * name handling.  A common usage is to handle cases where the block name
+    * (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
+    *
+    * \note
+    * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
+    * there of.
+    */
+   void process(const glsl_type *type, const char *name);
+
 protected:
    /**
     * Method invoked for each leaf of the uniform
-- 
1.7.11.7



More information about the mesa-dev mailing list