mesa: Determine GL_ACTIVE_ATTRIBUTE_MAX_LENGTH by walking the GLSL IR.
authorIan Romanick <ian.d.romanick@intel.com>
Thu, 18 Aug 2011 22:27:18 +0000 (15:27 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Tue, 4 Oct 2011 20:17:48 +0000 (13:17 -0700)
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/main/shader_query.cpp
src/mesa/main/shaderapi.c
src/mesa/main/shaderapi.h
src/mesa/program/prog_parameter.c
src/mesa/program/prog_parameter.h

index e9e6dbf7122269d3f02c9e44f92ca13e7b1d07ed..e532a29e1cf96d811ed991965211e7433157ad9c 100644 (file)
@@ -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;
+}
index 657de66e9a14d4e22cdbc0f57ed01fe7e66b3239..9e0ed9c69772e9d02bdd61ca94beadcc0a3b5577 100644 (file)
@@ -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;
index 967472472044084ce3f0e83cf4bf5ad23fbf218d..bec448dee47a7c41041b160b3d90b844f65f3bb1 100644 (file)
@@ -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);
index 49b3ffbdd5c9970ca9dd74ec95af9b3312e8316c..2018fa520710fb3ec3afa0e2e178d41f54c6d9ed 100644 (file)
@@ -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.
  */
index 8811c462252e4a26f952e9e0e0f1396040768be9..a6793d0d866642ef66040ecada25a46c6121e345 100644 (file)
@@ -173,10 +173,6 @@ _mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
                                 const gl_constant_value v[], GLuint vSize,
                                 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);