[Mesa-dev] [PATCH 10/12] glsl: Use vector-insert and vector-extract on elements of gl_ClipDistanceMESA

Paul Berry stereotype441 at gmail.com
Tue May 7 10:07:39 PDT 2013


On 3 May 2013 16:07, Ian Romanick <idr at freedesktop.org> wrote:

> From: Ian Romanick <ian.d.romanick at intel.com>
>
> Variable indexing into vectors using ir_dereference_array is being
> removed, so this lowering pass has to generate something different.
>
> v2: Convert tabs to spaces.  Suggested by Eric.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> Cc: Paul Berry <stereotype441 at gmail.com>
> ---
>  src/glsl/lower_clip_distance.cpp | 36 ++++++++++++++++++++++++++++++++++--
>  1 file changed, 34 insertions(+), 2 deletions(-)
>
> diff --git a/src/glsl/lower_clip_distance.cpp
> b/src/glsl/lower_clip_distance.cpp
> index 19068fb..c93c821e 100644
> --- a/src/glsl/lower_clip_distance.cpp
> +++ b/src/glsl/lower_clip_distance.cpp
> @@ -197,10 +197,17 @@ lower_clip_distance_visitor::handle_rvalue(ir_rvalue
> **rv)
>           ir_rvalue *swizzle_index;
>           this->create_indices(array->array_index, array_index,
> swizzle_index);
>           void *mem_ctx = ralloc_parent(array);
> -         array->array =
> +
> +         ir_dereference_array *const ClipDistanceMESA_deref =
>              new(mem_ctx) ir_dereference_array(this->new_clip_distance_var,
>                                                array_index);
> -         array->array_index = swizzle_index;
> +
> +         ir_expression *const expr =
> +            new(mem_ctx) ir_expression(ir_binop_vector_extract,
> +                                       ClipDistanceMESA_deref,
> +                                       swizzle_index);
> +
> +         *rv = expr;
>        }
>     }
>  }
> @@ -280,7 +287,32 @@
> lower_clip_distance_visitor::visit_leave(ir_assignment *ir)
>        return visit_continue;
>     }
>
> +   /* Handle the LHS as if it were an r-value.  This may cause the LHS to
> get
> +    * replaced with an ir_expression or ir_binop_vector_extract.  If this
> +    * occurs, replace it with a dereference of the vector, and replace
> the RHS
> +    * with an ir_triop_vector_insert.
> +    */
>     handle_rvalue((ir_rvalue **)&ir->lhs);
> +   if (ir->lhs->ir_type == ir_type_expression) {
> +      ir_expression *const expr = (ir_expression *) ir->lhs;
> +
> +      /* The expression must be of the form:
> +       *
> +       *     (vector_extract gl_ClipDistanceMESA[i], j).
> +       */
> +      assert(expr->operation == ir_binop_vector_extract);
> +      assert(expr->operands[0]->ir_type == ir_type_dereference_array);
> +
> +      ir_dereference *const new_lhs = (ir_dereference *)
> expr->operands[0];
> +      ir->rhs = new(ctx) ir_expression(ir_triop_vector_insert,
> +                                       new_lhs->type,
> +                                       new_lhs->clone(ctx, NULL),
> +                                       ir->rhs,
> +                                       expr->operands[1]);
> +      ir->set_lhs(new_lhs);
> +      ir->write_mask = (1U << new_lhs->type->vector_elements) - 1;
>

We know that the LHS is always a vec4, so I think it would be clearer to
just say:

ir->write_mask = 0xf;

But I don't feel terribly strongly about it.

Regardless of whether you decide to make this change, the patch is:

Reviewed-by: Paul Berry <stereotype441 at gmail.com>


> +   }
> +
>     return rvalue_visit(ir);
>  }
>
> --
> 1.8.1.4
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20130507/301e5f92/attachment.html>


More information about the mesa-dev mailing list