Mesa (master): mesa: Determine GL_ACTIVE_ATTRIBUTE_MAX_LENGTH by walking the GLSL IR.

Ian Romanick idr at kemper.freedesktop.org
Tue Oct 4 13:18:50 PDT 2011


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Aug 18 15:27:18 2011 -0700

mesa: Determine GL_ACTIVE_ATTRIBUTE_MAX_LENGTH by walking the GLSL IR.

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

---

 src/mesa/main/shader_query.cpp    |   29 +++++++++++++++++++++++++++++
 src/mesa/main/shaderapi.c         |    8 +-------
 src/mesa/main/shaderapi.h         |    2 ++
 src/mesa/program/prog_parameter.c |   22 ----------------------
 src/mesa/program/prog_parameter.h |    4 ----
 5 files changed, 32 insertions(+), 33 deletions(-)

diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index e9e6dbf..e532a29 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -212,3 +212,32 @@ _mesa_count_active_attribs(struct gl_shader_program *shProg)
 
    return i;
 }
+
+
+size_t
+_mesa_longest_attribute_name_length(struct gl_shader_program *shProg)
+{
+   if (!shProg->LinkStatus
+       || shProg->_LinkedShaders[MESA_SHADER_VERTEX] == NULL) {
+      return 0;
+   }
+
+   exec_list *const ir = shProg->_LinkedShaders[MESA_SHADER_VERTEX]->ir;
+   size_t longest = 0;
+
+   foreach_list(node, ir) {
+      const ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+      if (var == NULL
+	  || var->mode != ir_var_in
+	  || var->location == -1
+	  || var->location < VERT_ATTRIB_GENERIC0)
+	 continue;
+
+      const size_t len = strlen(var->name);
+      if (len >= longest)
+	 longest = len + 1;
+   }
+
+   return longest;
+}
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 657de66..9e0ed9c 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -538,7 +538,6 @@ get_handle(struct gl_context *ctx, GLenum pname)
 static void
 get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, GLint *params)
 {
-   const struct gl_program_parameter_list *attribs;
    struct gl_shader_program *shProg
       = _mesa_lookup_shader_program(ctx, program);
 
@@ -547,11 +546,6 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, GLint *param
       return;
    }
 
-   if (shProg->VertexProgram)
-      attribs = shProg->VertexProgram->Base.Attributes;
-   else
-      attribs = NULL;
-
    switch (pname) {
    case GL_DELETE_STATUS:
       *params = shProg->DeletePending;
@@ -572,7 +566,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, GLint *param
       *params = _mesa_count_active_attribs(shProg);
       break;
    case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
-      *params = _mesa_longest_parameter_name(attribs, PROGRAM_INPUT) + 1;
+      *params = _mesa_longest_attribute_name_length(shProg);
       break;
    case GL_ACTIVE_UNIFORMS:
       *params = shProg->Uniforms ? shProg->Uniforms->NumUniforms : 0;
diff --git a/src/mesa/main/shaderapi.h b/src/mesa/main/shaderapi.h
index 9674724..bec448d 100644
--- a/src/mesa/main/shaderapi.h
+++ b/src/mesa/main/shaderapi.h
@@ -53,6 +53,8 @@ _mesa_init_shader_dispatch(struct _glapi_table *exec);
 extern unsigned
 _mesa_count_active_attribs(struct gl_shader_program *shProg);
 
+extern size_t
+_mesa_longest_attribute_name_length(struct gl_shader_program *shProg);
 
 extern void GLAPIENTRY
 _mesa_AttachObjectARB(GLhandleARB, GLhandleARB);
diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c
index 49b3ffb..2018fa5 100644
--- a/src/mesa/program/prog_parameter.c
+++ b/src/mesa/program/prog_parameter.c
@@ -640,28 +640,6 @@ _mesa_combine_parameter_lists(const struct gl_program_parameter_list *listA,
 }
 
 
-
-/**
- * Find longest name of all uniform parameters in list.
- */
-GLuint
-_mesa_longest_parameter_name(const struct gl_program_parameter_list *list,
-                             gl_register_file type)
-{
-   GLuint i, maxLen = 0;
-   if (!list)
-      return 0;
-   for (i = 0; i < list->NumParameters; i++) {
-      if (list->Parameters[i].Type == type) {
-         GLuint len = strlen(list->Parameters[i].Name);
-         if (len > maxLen)
-            maxLen = len;
-      }
-   }
-   return maxLen;
-}
-
-
 /**
  * Count the number of parameters in the last that match the given type.
  */
diff --git a/src/mesa/program/prog_parameter.h b/src/mesa/program/prog_parameter.h
index 8811c46..a6793d0 100644
--- a/src/mesa/program/prog_parameter.h
+++ b/src/mesa/program/prog_parameter.h
@@ -174,10 +174,6 @@ _mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
                                 GLint *posOut, GLuint *swizzleOut);
 
 extern GLuint
-_mesa_longest_parameter_name(const struct gl_program_parameter_list *list,
-                             gl_register_file type);
-
-extern GLuint
 _mesa_num_parameters_of_type(const struct gl_program_parameter_list *list,
                              gl_register_file type);
 



More information about the mesa-commit mailing list