[Mesa-dev] [PATCH 10/23] mesa: refactor GetActiveAttrib

Ilia Mirkin imirkin at alum.mit.edu
Mon Mar 16 15:28:33 PDT 2015


Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>

One minor note -- not sure if it makes sense to call the
_mesa_program_resource_prop helpers, but it is nicely generic. However
you already have the ir_variable *var, so might as well use it? Your
call.

On Fri, Mar 13, 2015 at 4:37 AM, Tapani Pälli <tapani.palli at intel.com> wrote:
> Instead of iterating IR, retrieve required information through
> the new program resource functions.
>
> Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
> ---
>  src/mesa/main/shader_query.cpp | 58 ++++++++++++++++++++----------------------
>  1 file changed, 27 insertions(+), 31 deletions(-)
>
> diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
> index 749cd32..8134d4b 100644
> --- a/src/mesa/main/shader_query.cpp
> +++ b/src/mesa/main/shader_query.cpp
> @@ -147,45 +147,41 @@ _mesa_GetActiveAttrib(GLhandleARB program, GLuint desired_index,
>        return;
>     }
>
> -   exec_list *const ir = shProg->_LinkedShaders[MESA_SHADER_VERTEX]->ir;
> -   unsigned current_index = 0;
> -
> -   foreach_in_list(ir_instruction, node, ir) {
> -      const ir_variable *const var = node->as_variable();
> -
> -      if (!is_active_attrib(var))
> -         continue;
> +   struct gl_program_resource *res =
> +      _mesa_program_resource_find_index(shProg, GL_PROGRAM_INPUT,
> +                                        desired_index);
>
> -      if (current_index == desired_index) {
> -         const char *var_name = var->name;
> +   /* User asked for index that does not exist. */
> +   if (!res) {
> +      _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveAttrib(index)");
> +      return;
> +   }
>
> -         /* Since gl_VertexID may be lowered to gl_VertexIDMESA, we need to
> -          * consider gl_VertexIDMESA as gl_VertexID for purposes of checking
> -          * active attributes.
> -          */
> -         if (var->data.mode == ir_var_system_value &&
> -             var->data.location == SYSTEM_VALUE_VERTEX_ID_ZERO_BASE) {
> -            var_name = "gl_VertexID";
> -         }
> +   const ir_variable *const var = RESOURCE_VAR(res);
>
> -        _mesa_copy_string(name, maxLength, length, var_name);
> +   if (!is_active_attrib(var))
> +      return;
>
> -        if (size)
> -           *size = (var->type->is_array()) ? var->type->length : 1;
> +   const char *var_name = var->name;
>
> -        if (type)
> -           *type = var->type->gl_type;
> +   /* Since gl_VertexID may be lowered to gl_VertexIDMESA, we need to
> +    * consider gl_VertexIDMESA as gl_VertexID for purposes of checking
> +    * active attributes.
> +    */
> +   if (var->data.mode == ir_var_system_value &&
> +       var->data.location == SYSTEM_VALUE_VERTEX_ID_ZERO_BASE) {
> +      var_name = "gl_VertexID";
> +   }
>
> -        return;
> -      }
> +   _mesa_copy_string(name, maxLength, length, var_name);
>
> -      current_index++;
> -   }
> +   if (size)
> +      _mesa_program_resource_prop(shProg, res, desired_index, GL_ARRAY_SIZE,
> +                                  size, "glGetActiveAttrib");
>
> -   /* If the loop did not return early, the caller must have asked for
> -    * an index that did not exit.  Set an error.
> -    */
> -   _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveAttrib(index)");
> +   if (type)
> +      _mesa_program_resource_prop(shProg, res, desired_index, GL_TYPE,
> +                                  (GLint *) type, "glGetActiveAttrib");
>  }
>
>  /* Locations associated with shader variables (array or non-array) can be
> --
> 2.1.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list