[Mesa-dev] [PATCH 2/4] linker: Count the number of uniform components used by a shader during linking

Ian Romanick idr at freedesktop.org
Tue Nov 8 14:26:03 PST 2011


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

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/link_uniforms.cpp |   19 +++++++++++++++++--
 src/mesa/main/mtypes.h     |    7 +++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index 11447f3..ca5da30 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -114,7 +114,7 @@ class count_uniform_size : public uniform_field_visitor {
 public:
    count_uniform_size(struct string_to_uint_map *map)
       : num_active_uniforms(0), num_values(0), num_shader_samplers(0),
-	map(map)
+	num_shader_uniforms(0), map(map)
    {
       /* empty */
    }
@@ -122,6 +122,7 @@ public:
    void start_shader()
    {
       this->num_shader_samplers = 0;
+      this->num_shader_uniforms = 0;
    }
 
    /**
@@ -139,6 +140,11 @@ public:
     */
    unsigned num_shader_samplers;
 
+   /**
+    * Number of uniforms used in the current shader
+    */
+   unsigned num_shader_uniforms;
+
 private:
    virtual void visit_field(const glsl_type *type, const char *name)
    {
@@ -150,9 +156,16 @@ private:
        * uniform for multiple shader targets, but in this case we want to
        * count it for each shader target.
        */
+      const unsigned values = values_for_type(type);
       if (type->contains_sampler()) {
 	 this->num_shader_samplers +=
 	    type->is_array() ? type->array_size() : 1;
+      } else {
+	 /* Accumulate the total number of uniform slots used by this shader.
+	  * Note that samplers do not count against this limit because they
+	  * don't use any storage on current hardware.
+	  */
+	 this->num_shader_uniforms += values;
       }
 
       /* If the uniform is already in the map, there's nothing more to do.
@@ -168,7 +181,7 @@ private:
        * uniforms.
        */
       this->num_active_uniforms++;
-      this->num_values += values_for_type(type);
+      this->num_values += values;
    }
 
    struct string_to_uint_map *map;
@@ -307,6 +320,8 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
       }
 
       prog->_LinkedShaders[i]->num_samplers = uniform_size.num_shader_samplers;
+      prog->_LinkedShaders[i]->num_uniform_components =
+	 uniform_size.num_shader_uniforms * 4;
    }
 
    const unsigned num_user_uniforms = uniform_size.num_active_uniforms;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index c5ec752..4acf8ba 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2145,6 +2145,13 @@ struct gl_shader
    unsigned num_samplers;	/**< Number of samplers used by this shader.
 				 * This field is only set post-linking.
 				 */
+   /**
+    * Number of uniform components used by this shader.
+    *
+    * This field is only set post-linking.
+    */
+   unsigned num_uniform_components;
+
    struct exec_list *ir;
    struct glsl_symbol_table *symbols;
 
-- 
1.7.6.4



More information about the mesa-dev mailing list