[Mesa-dev] [PATCH V2 2/3] i965: Generalize coord+offset lowering pass for ir_txf

Kenneth Graunke kenneth at whitecape.org
Sat Oct 26 10:27:22 CEST 2013


On 10/14/2013 01:36 AM, Chris Forbes wrote:
> ir_txf expects an ivec* coordinate, and may be larger than ivec2;
> shuffle things around so that this will work.
> 
> Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
> ---
>  .../dri/i965/brw_lower_unnormalized_offset.cpp     | 51 ++++++++++++++++++----
>  1 file changed, 42 insertions(+), 9 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_lower_unnormalized_offset.cpp b/src/mesa/drivers/dri/i965/brw_lower_unnormalized_offset.cpp
> index 733c289..9106726 100644
> --- a/src/mesa/drivers/dri/i965/brw_lower_unnormalized_offset.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_lower_unnormalized_offset.cpp
> @@ -50,20 +50,53 @@ public:
>  ir_visitor_status
>  brw_lower_unnormalized_offset_visitor::visit_leave(ir_texture *ir)
>  {
> -   if (ir->sampler->type->sampler_dimensionality != GLSL_SAMPLER_DIM_RECT ||
> -       !ir->offset || ir->op != ir_tg4)
> +   if (!ir->offset)
>        return visit_continue;
>  
> +   if (ir->op == ir_tg4) {
> +      if (ir->sampler->type->sampler_dimensionality != GLSL_SAMPLER_DIM_RECT)
> +         return visit_continue;
> +   }
> +   else if (ir->op != ir_txf) {

Style nit:

} else if (ir->op != ir_txf) {

> +      return visit_continue;
> +   }
> +
>     void *mem_ctx = ralloc_parent(ir);
>  
> -   ir->coordinate = new (mem_ctx) ir_expression(
> -         ir_binop_add,
> -         ir->coordinate,
> -         new (mem_ctx) ir_expression(
> -            ir_unop_i2f,
> -            ir->offset));
> -   ir->offset = NULL;
> +   if (ir->op == ir_txf) {
> +      ir_variable *var = new (mem_ctx) ir_variable(
> +            ir->coordinate->type, "coordinate", ir_var_auto);
> +      base_ir->insert_before(var);
>  
> +      ir_assignment *assign = new (mem_ctx) ir_assignment(
> +            new (mem_ctx) ir_dereference_variable(var),
> +            ir->coordinate,
> +            NULL);
> +      base_ir->insert_before(assign);
> +
> +      assign = new (mem_ctx) ir_assignment(
> +            new (mem_ctx) ir_dereference_variable(var),
> +            new (mem_ctx) ir_expression(
> +               ir_binop_add,
> +               new (mem_ctx) ir_swizzle(
> +                  new (mem_ctx) ir_dereference_variable(var),
> +                  0, 1, 2, 3, ir->offset->type->vector_elements),
> +               ir->offset),
> +            NULL);
> +      assign->write_mask = (1 << ir->offset->type->vector_elements) - 1;
> +      base_ir->insert_before(assign);
> +
> +      ir->coordinate = new (mem_ctx) ir_dereference_variable(var);
> +   } else {
> +      ir->coordinate = new (mem_ctx) ir_expression(
> +            ir_binop_add,
> +            ir->coordinate,
> +            new (mem_ctx) ir_expression(
> +               ir_unop_i2f,
> +               ir->offset));
> +   }

if (ir->op == ir_txf) {
   ir_variable *var = new(mem_ctx) ir_variable(ir->coordinate->type,
                                               "coordinate",
                                               ir_var_temporary);
   base_ir->insert_before(var);
   ir_assignment *assign = assign(var, ir->coordinate);
   base_ir->insert_before(assign);
   assign = assign(var, add(swizzle_for_size(var, ir->offset->type->vector_elements), ir->offset));
   base_ir->insert_before(assign);

   ir->coordinate = new(mem_ctx) ir_dereference_variable(var);
} else {
   ir->coordinate = add(ir->coordinate, i2f(ir->offset));
}

So much easier :)

With that changed, this series is:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

> +
> +   ir->offset = NULL;
>  
>     progress = true;
>     return visit_continue;
> 



More information about the mesa-dev mailing list