<div dir="ltr">On 17 December 2013 10:51, Brian Paul <span dir="ltr"><<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</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">
<div class=""><div class="h5">On 12/17/2013 11:23 AM, Paul Berry wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
We already have a function for converting a shader type index to a<br>
string: _mesa_glsl_shader_target_name(<u></u>).<br>
---<br>
  src/glsl/link_atomics.cpp |  8 +++-----<br>
  src/glsl/linker.cpp       | 16 ++++++----------<br>
  2 files changed, 9 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/src/glsl/link_atomics.cpp b/src/glsl/link_atomics.cpp<br>
index 33903ad..cac5615 100644<br>
--- a/src/glsl/link_atomics.cpp<br>
+++ b/src/glsl/link_atomics.cpp<br>
@@ -21,6 +21,7 @@<br>
   * DEALINGS IN THE SOFTWARE.<br>
   */<br>
<br>
+#include "glsl_parser_extras.h"<br>
  #include "ir.h"<br>
  #include "ir_uniform.h"<br>
  #include "linker.h"<br>
@@ -214,9 +215,6 @@ link_check_atomic_counter_<u></u>resources(struct gl_context *ctx,<br>
                                      struct gl_shader_program *prog)<br>
  {<br>
     STATIC_ASSERT(MESA_SHADER_<u></u>TYPES == 3);<br>
-   static const char *shader_names[MESA_SHADER_<u></u>TYPES] = {<br>
-      "vertex", "geometry", "fragment"<br>
-   };<br>
     const unsigned max_atomic_counters[MESA_<u></u>SHADER_TYPES] = {<br>
        ctx->Const.VertexProgram.<u></u>MaxAtomicCounters,<br>
        ctx->Const.GeometryProgram.<u></u>MaxAtomicCounters,<br>
@@ -260,11 +258,11 @@ link_check_atomic_counter_<u></u>resources(struct gl_context *ctx,<br>
     for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {<br>
        if (atomic_counters[i] > max_atomic_counters[i])<br>
           linker_error(prog, "Too many %s shader atomic counters",<br>
-                      shader_names[i]);<br>
+                      _mesa_glsl_shader_target_name(<u></u>(gl_shader_type) i));<br>
<br>
        if (atomic_buffers[i] > max_atomic_buffers[i])<br>
           linker_error(prog, "Too many %s shader atomic counter buffers",<br>
-                      shader_names[i]);<br>
+                      _mesa_glsl_shader_target_name(<u></u>(gl_shader_type) i));<br>
     }<br>
<br>
     if (total_atomic_counters > ctx->Const.<u></u>MaxCombinedAtomicCounters)<br>
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp<br>
index a6133ea..1406f13 100644<br>
--- a/src/glsl/linker.cpp<br>
+++ b/src/glsl/linker.cpp<br>
@@ -1893,10 +1893,6 @@ store_fragdepth_layout(struct gl_shader_program *prog)<br>
  static void<br>
  check_resources(struct gl_context *ctx, struct gl_shader_program *prog)<br>
  {<br>
-   static const char *const shader_names[MESA_SHADER_<u></u>TYPES] = {<br>
-      "vertex", "geometry", "fragment"<br>
-   };<br>
-<br>
     const unsigned max_samplers[MESA_SHADER_<u></u>TYPES] = {<br>
        ctx->Const.VertexProgram.<u></u>MaxTextureImageUnits,<br>
        ctx->Const.GeometryProgram.<u></u>MaxTextureImageUnits,<br>
@@ -1929,7 +1925,7 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)<br>
<br>
        if (sh->num_samplers > max_samplers[i]) {<br>
         linker_error(prog, "Too many %s shader texture samplers",<br>
-                     shader_names[i]);<br>
+                     _mesa_glsl_shader_target_name(<u></u>(gl_shader_type) i));<br>
        }<br>
<br>
        if (sh->num_uniform_components > max_default_uniform_<u></u>components[i]) {<br>
@@ -1938,11 +1934,11 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)<br>
                             "components, but the driver will try to optimize "<br>
                             "them out; this is non-portable out-of-spec "<br>
                           "behavior\n",<br>
-                           shader_names[i]);<br>
+                           _mesa_glsl_shader_target_name(<u></u>(gl_shader_type) i));<br>
           } else {<br>
              linker_error(prog, "Too many %s shader default uniform block "<br>
                         "components",<br>
-                         shader_names[i]);<br>
+                         _mesa_glsl_shader_target_name(<u></u>(gl_shader_type) i));<br>
           }<br>
        }<br>
<br>
@@ -1952,10 +1948,10 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)<br>
              linker_warning(prog, "Too many %s shader uniform components, "<br>
                             "but the driver will try to optimize them out; "<br>
                             "this is non-portable out-of-spec behavior\n",<br>
-                           shader_names[i]);<br>
+                           _mesa_glsl_shader_target_name(<u></u>(gl_shader_type) i));<br>
           } else {<br>
              linker_error(prog, "Too many %s shader uniform components",<br>
-                         shader_names[i]);<br>
+                         _mesa_glsl_shader_target_name(<u></u>(gl_shader_type) i));<br>
           }<br>
        }<br>
     }<br>
@@ -1979,7 +1975,7 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)<br>
         for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {<br>
            if (blocks[i] > max_uniform_blocks[i]) {<br>
               linker_error(prog, "Too many %s uniform blocks (%d/%d)",<br>
-                           shader_names[i],<br>
+                           _mesa_glsl_shader_target_name(<u></u>(gl_shader_type) i),<br>
                            blocks[i],<br>
                            max_uniform_blocks[i]);<br>
               break;<br>
<br>
</blockquote>
<br></div></div>
Could the variable 'i' be declared as gl_shader_type to avoid all the casting?<br>
<br>
-Brian<br></blockquote><div><br></div><div>I'm not thrilled about the casting either.  I'm worried that some time in the future someone will try removing one of the casts, see that there is no compiler error, and come to the wrong conclusion that the cast does nothing.  (In reality, the cast is necessary because it's selecting between two overloads of _mesa_glsl_shader_target_name(), one which takes a GLenum and one which takes a gl_shader_type).<br>
</div><div><br><br>Unfortunatly, declaring i as gl_shader_type isn't a great fix because it forces casting to be added elsewhere.  The top of the "for" loop would have to change to something like:<br><br>   for (gl_shader_type i = (gl_shader_type) 0; i < MESA_SHADER_TYPES;<br>
        i = (gl_shader_type) (i + 1)) {<br><br></div><div>which seems pretty ugly.<br><br><br></div><div>How about this idea instead: rather than use function overloading to distinguish between the two meanings of _mesa_glsl_shader_target_name(), have two functions with separate names, e.g.:<br>
<br></div><div>const char *_mesa_gl_shader_type_to_string(unsigned): converts MESA_SHADER_VERTEX -> "vertex", etc.<br><br></div><div>const char *_mesa_shader_target_enum_to_string(GLenum): converts GL_VERTEX_SHADER -> "vertex", etc. <br>
</div><div><br></div><div>That would eliminate the need for typecasts, and it would reduce the danger of someone calling the wrong function by mistake.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<br>
______________________________<u></u>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/<u></u>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div></div>