<div dir="ltr">Doesn't st/mesa have a pass for getting rid if the structs?<br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 2, 2018 at 11:13 AM, Eric Anholt <span dir="ltr"><<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">mesa/st decides whether to update samplers after a program change based on<br>
whether num_textures is nonzero.  By not counting samplers in a uniform<br>
struct, we would segfault in<br>
KHR-GLES3.shaders.struct.<wbr>uniform.sampler_vertex if it was run in the same<br>
context after a non-vertex-shader-uniform testcase (as is the case during<br>
a full conformance run).<br>
---<br>
 src/compiler/nir/nir_gather_<wbr>info.c | 32 ++++++++++++++++++++----------<wbr>--<br>
 1 file changed, 20 insertions(+), 12 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir_gather_<wbr>info.c b/src/compiler/nir/nir_gather_<wbr>info.c<br>
index 5530009255d7..63783f9bc6a2 100644<br>
--- a/src/compiler/nir/nir_gather_<wbr>info.c<br>
+++ b/src/compiler/nir/nir_gather_<wbr>info.c<br>
@@ -350,24 +350,32 @@ gather_info_block(nir_block *block, nir_shader *shader)<br>
    }<br>
 }<br>
<br>
+static void<br>
+nir_gather_uniform_info(nir_<wbr>shader *shader, const struct glsl_type *type,<br>
+                        int count) <br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+{<br>
+   if (glsl_type_is_array(type)) {<br>
+      nir_gather_uniform_info(<wbr>shader, glsl_without_array(type),<br>
+                              count * glsl_get_aoa_size(type));<br>
+   } else if (glsl_type_is_struct(type)) {<br>
+      for (int i = 0; i < glsl_get_length(type); i++) {<br>
+         nir_gather_uniform_info(<wbr>shader, glsl_get_struct_field(type, i),<br>
+                                 count);<br></blockquote><div><br></div><div>The interaction between in and out parameters is a bit weird here.  Why not just have a simpler helper:<br><br></div><div>unsigned<br></div><div>glsl_type_get_image_count(const struct glsl_type *type)<br>{<br></div><div>   if (glsl_type_is_array(type)) {<br></div><div>      return glsl_type_get_image_count(glsl_without_array(type)) * glsl_get_aoa_size(type);<br></div><div>   } else if (glsl_type_is_struct(type)) {<br></div><div>      unsigned count = 0;<br></div><div>      for (int i = 0; i < glsl_get_length(type); i++)<br></div><div>         count += glsl_type_get_image_count(glsl_get_struct_field(type, i));<br></div><div>      return count;<br></div><div>   } else if (glsl_type_is_image(type) {<br></div><div>      return 1;<br></div><div>   } else {<br></div><div>      return 0;   <br></div><div>}<br><br></div><div>and another one for samplers.  Yes, it's a bit more code but the new functions are pure which is nice.<br><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      }<br>
+   } else if (glsl_type_is_image(type)) {<br>
+      shader->info.num_images += count;<br>
+   } else if (glsl_type_is_sampler(type)) {<br>
+      shader->info.num_textures += count;<br>
+   }<br>
+}<br>
+<br>
 void<br>
 nir_shader_gather_info(nir_<wbr>shader *shader, nir_function_impl *entrypoint)<br>
 {<br>
    shader->info.num_textures = 0;<br>
    shader->info.num_images = 0;<br>
    nir_foreach_variable(var, &shader->uniforms) {<br>
-      const struct glsl_type *type = var->type;<br>
-      unsigned count = 1;<br>
-      if (glsl_type_is_array(type)) {<br>
-         count = glsl_get_aoa_size(type);<br>
-         type = glsl_without_array(type);<br>
-      }<br>
-<br>
-      if (glsl_type_is_image(type)) {<br>
-         shader->info.num_images += count;<br>
-      } else if (glsl_type_is_sampler(type)) {<br>
-         shader->info.num_textures += count;<br>
-      }<br>
+      nir_gather_uniform_info(<wbr>shader, var->type, 1);<br>
    }<br>
<br>
    shader->info.inputs_read = 0;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.16.2<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>