[Mesa-dev] [PATCH v2] glsl: Copy propagate in array index function parameters

Ilia Mirkin imirkin at alum.mit.edu
Fri May 6 16:23:07 UTC 2016


Could you add something to piglit which tries this with AoA to make
sure that your logic is right?

On Fri, May 6, 2016 at 11:54 AM, Juan A. Suarez Romero
<jasuarez at igalia.com> wrote:
> Copy propagate is not applied in function parameters when they are out
> or inout.
>
> But if the parameter is an array, we can copy propagate the index array.
>
> This also fixes shaders at out-parameter-indexing piglit tests, that
> exposes a wrong handling of inout function parameters in Mesa.
>
> This commit does not produce any piglit regression, nor any change in
> shader-db results.
>
> v2:
>   - Deal with swizzles (jasuarez)
>   - Use a loop top peel off all array dereferences (Ilia)
> ---
>  src/compiler/glsl/opt_copy_propagation.cpp | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/src/compiler/glsl/opt_copy_propagation.cpp b/src/compiler/glsl/opt_copy_propagation.cpp
> index ae62921..e464de3 100644
> --- a/src/compiler/glsl/opt_copy_propagation.cpp
> +++ b/src/compiler/glsl/opt_copy_propagation.cpp
> @@ -193,6 +193,24 @@ ir_copy_propagation_visitor::visit_enter(ir_call *ir)
>        if (sig_param->data.mode != ir_var_function_out
>            && sig_param->data.mode != ir_var_function_inout) {
>           ir->accept(this);
> +      } else {
> +         /* Peeling of all array dereferences / swizzles */
> +         ir_dereference_array *ir_array;
> +         ir_swizzle *ir_swizzle;
> +         do {
> +            ir_array = ir->as_dereference_array();
> +            if (ir_array) {
> +               ir_array->array_index->accept(this);
> +               ir = ir_array->array;
> +               continue;
> +            }
> +            ir_swizzle = ir->as_swizzle();
> +            if (ir_swizzle) {
> +               ir = ir_swizzle->val;
> +               continue;
> +            }
> +            ir = NULL;
> +         } while (ir);

How about

while (true) {
  if ((ir_array = ir->as_dereference_array()) {

  } else if ((ir_swizzle = ir->as_swizzle()) {

  } else {
    break;
  }
}

IMHO that better expresses what you're trying to do. Or something else
like that.

Also, are vector extracts still a thing at this point, or are they
already lowered? Like vec4[1] instead of vec4.y.

  -ilia


More information about the mesa-dev mailing list