Mesa (master): linker: Count the number of samplers used by a shader during linking

Ian Romanick idr at kemper.freedesktop.org
Mon Nov 14 11:09:33 PST 2011


Module: Mesa
Branch: master
Commit: 812aa8839388042609f65ed00ae4fbfdb60a11d6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=812aa8839388042609f65ed00ae4fbfdb60a11d6

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Nov  8 11:58:47 2011 -0800

linker: Count the number of samplers used by a shader during linking

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/glsl/link_uniforms.cpp |   29 ++++++++++++++++++++++++++++-
 src/mesa/main/mtypes.h     |    3 +++
 2 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index b9d5361..11447f3 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -113,11 +113,17 @@ uniform_field_visitor::recursion(const glsl_type *t, char **name,
 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), map(map)
+      : num_active_uniforms(0), num_values(0), num_shader_samplers(0),
+	map(map)
    {
       /* empty */
    }
 
+   void start_shader()
+   {
+      this->num_shader_samplers = 0;
+   }
+
    /**
     * Total number of active uniforms counted
     */
@@ -128,12 +134,27 @@ public:
     */
    unsigned num_values;
 
+   /**
+    * Number of samplers used
+    */
+   unsigned num_shader_samplers;
+
 private:
    virtual void visit_field(const glsl_type *type, const char *name)
    {
       assert(!type->is_record());
       assert(!(type->is_array() && type->fields.array->is_record()));
 
+      /* Count the number of samplers regardless of whether the uniform is
+       * already in the hash table.  The hash table prevents adding the same
+       * uniform for multiple shader targets, but in this case we want to
+       * count it for each shader target.
+       */
+      if (type->contains_sampler()) {
+	 this->num_shader_samplers +=
+	    type->is_array() ? type->array_size() : 1;
+      }
+
       /* If the uniform is already in the map, there's nothing more to do.
        */
       unsigned id;
@@ -267,6 +288,10 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
       if (prog->_LinkedShaders[i] == NULL)
 	 continue;
 
+      /* Reset various per-shader target counts.
+       */
+      uniform_size.start_shader();
+
       foreach_list(node, prog->_LinkedShaders[i]->ir) {
 	 ir_variable *const var = ((ir_instruction *) node)->as_variable();
 
@@ -280,6 +305,8 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
 
 	 uniform_size.process(var);
       }
+
+      prog->_LinkedShaders[i]->num_samplers = uniform_size.num_shader_samplers;
    }
 
    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 deab97d..47282c0 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2158,6 +2158,9 @@ struct gl_shader
 
    unsigned Version;       /**< GLSL version used for linking */
 
+   unsigned num_samplers;	/**< Number of samplers used by this shader.
+				 * This field is only set post-linking.
+				 */
    struct exec_list *ir;
    struct glsl_symbol_table *symbols;
 



More information about the mesa-commit mailing list