[Mesa-dev] [PATCH 11/13] mesa: Determine GL_ACTIVE_ATTRIBUTES by walking the GLSL IR.

Ian Romanick idr at freedesktop.org
Fri Sep 30 16:44:55 PDT 2011


From: Ian Romanick <ian.d.romanick at intel.com>

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 |   27 +++++++++++++++++++++++++++
 src/mesa/main/shaderapi.c      |    2 +-
 src/mesa/main/shaderapi.h      |    2 ++
 3 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 636ab0f..e9e6dbf 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -185,3 +185,30 @@ _mesa_GetAttribLocationARB(GLhandleARB program, const GLcharARB * name)
 
    return -1;
 }
+
+
+unsigned
+_mesa_count_active_attribs(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;
+   unsigned i = 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;
+
+      i++;
+   }
+
+   return i;
+}
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index b13ec45..657de66 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -569,7 +569,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, GLint *param
       *params = shProg->NumShaders;
       break;
    case GL_ACTIVE_ATTRIBUTES:
-      *params = attribs ? attribs->NumParameters : 0;
+      *params = _mesa_count_active_attribs(shProg);
       break;
    case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
       *params = _mesa_longest_parameter_name(attribs, PROGRAM_INPUT) + 1;
diff --git a/src/mesa/main/shaderapi.h b/src/mesa/main/shaderapi.h
index e4b4776..9674724 100644
--- a/src/mesa/main/shaderapi.h
+++ b/src/mesa/main/shaderapi.h
@@ -50,6 +50,8 @@ _mesa_active_program(struct gl_context *ctx, struct gl_shader_program *shProg,
 extern void
 _mesa_init_shader_dispatch(struct _glapi_table *exec);
 
+extern unsigned
+_mesa_count_active_attribs(struct gl_shader_program *shProg);
 
 
 extern void GLAPIENTRY
-- 
1.7.6



More information about the mesa-dev mailing list