<div dir="ltr">On 26 November 2013 00:02, Francisco Jerez <span dir="ltr"><<a href="mailto:currojerez@riseup.net" target="_blank">currojerez@riseup.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">---<br>
 src/glsl/link_uniforms.cpp | 13 +++++++++++-<br>
 src/glsl/linker.cpp        | 50 ++++++++++++++++++++++++++++++++++++++++++++++<br>
 2 files changed, 62 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp<br>
index 0a15739..c75a38c 100644<br>
--- a/src/glsl/link_uniforms.cpp<br>
+++ b/src/glsl/link_uniforms.cpp<br>
@@ -240,7 +240,8 @@ class count_uniform_size : public program_resource_visitor {<br>
 public:<br>
    count_uniform_size(struct string_to_uint_map *map)<br>
       : num_active_uniforms(0), num_values(0), num_shader_samplers(0),<br>
-       num_shader_uniform_components(0), is_ubo_var(false), map(map)<br>
+        num_shader_images(0), num_shader_uniform_components(0),<br>
+        is_ubo_var(false), map(map)<br>
    {<br>
       /* empty */<br>
    }<br>
@@ -248,6 +249,7 @@ public:<br>
    void start_shader()<br>
    {<br>
       this->num_shader_samplers = 0;<br>
+      this->num_shader_images = 0;<br>
       this->num_shader_uniform_components = 0;<br>
    }<br>
<br>
@@ -277,6 +279,11 @@ public:<br>
    unsigned num_shader_samplers;<br>
<br>
    /**<br>
+    * Number of images used<br>
+    */<br>
+   unsigned num_shader_images;<br>
+<br>
+   /**<br>
     * Number of uniforms used in the current shader<br>
     */<br>
    unsigned num_shader_uniform_components;<br>
@@ -303,6 +310,9 @@ private:<br>
       if (type->contains_sampler()) {<br>
         this->num_shader_samplers +=<br>
            type->is_array() ? type->array_size() : 1;<br>
+      } else if (type->contains_image()) {<br>
+         this->num_shader_images += values;<br>
+         this->num_shader_uniform_components += values;<br></blockquote><div><br>How come images contribute to num_shader_uniform_components but samplers don't?  There should be a comment explaining this difference.<br>
 </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
       } else {<br>
         /* Accumulate the total number of uniform slots used by this shader.<br>
          * Note that samplers do not count against this limit because they<br>
@@ -782,6 +792,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog)<br>
       }<br>
<br>
       sh->num_samplers = uniform_size.num_shader_samplers;<br>
+      sh->NumImages = uniform_size.num_shader_images;<br>
       sh->num_uniform_components = uniform_size.num_shader_uniform_components;<br>
<br>
       sh->num_combined_uniform_components = sh->num_uniform_components;<br>
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp<br>
index fac186a..86a0cae 100644<br>
--- a/src/glsl/linker.cpp<br>
+++ b/src/glsl/linker.cpp<br>
@@ -1980,6 +1980,55 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)<br>
    }<br>
 }<br>
<br>
+/**<br>
+ * Validate shader image resources.<br>
+ */<br>
+static void<br>
+check_image_resources(struct gl_context *ctx, struct gl_shader_program *prog)<br>
+{<br>
+   STATIC_ASSERT(MESA_SHADER_TYPES == 3);<br>
+   static const char *const shader_names[MESA_SHADER_TYPES] = {<br>
+      "vertex", "geometry", "fragment"<br>
+   };<br></blockquote><div><br>Use _mesa_glsl_shader_target_name() instead of hardcoding this array.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

+   const unsigned max_images[MESA_SHADER_TYPES] = {<br>
+      ctx->Const.VertexProgram.MaxImageUniforms,<br>
+      ctx->Const.GeometryProgram.MaxImageUniforms,<br>
+      ctx->Const.FragmentProgram.MaxImageUniforms<br>
+   };<br></blockquote><div><br></div><div>Rather than doing STATIC_ASSERT(MESA_SHADER_TYPES == 3), I think this would be slightly cleaner, since it will be more obvious what needs fixing if the assertion ever fires:<br>
<br>   const unsigned max_images[] = {<br>      ctx->Const.VertexProgram.MaxImageUniforms,<br>      ctx->Const.GeometryProgram.MaxImageUniforms,<br>      ctx->Const.FragmentProgram.MaxImageUniforms<br>   };<br>   STATIC_ASSERT(Elements(max_images) == MESA_SHADER_TYPES);<br>
<br><br></div><div>With those changes, the patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br></div></div></div></div>