[Mesa-dev] [PATCH 06/12] glsl: Add lowering pass for ir_triop_vector_insert

Eric Anholt eric at anholt.net
Tue Apr 9 10:29:43 PDT 2013


Ian Romanick <idr at freedesktop.org> writes:

> From: Ian Romanick <ian.d.romanick at intel.com>
>
> This will eventually replace do_vec_index_to_cond_assign.  This lowering
> pass is called in all the places where do_vec_index_to_cond_assign or
> do_vec_index_to_swizzle is called.

> +
> +      ir_constant *const cmp_indices =
> +         new(factory.mem_ctx) ir_constant(glsl_type::get_instance(GLSL_TYPE_INT,
> +                                                                  components,
> +                                                                  1),
> +                                          &cmp_indices_data);
> +
> +      ir_variable *const cmp_result =
> +         factory.make_temp(glsl_type::get_instance(GLSL_TYPE_BOOL,
> +                                                   components,
> +                                                   1),
> +                           "index_condition");

I wish we had some helpers like glsl_type::bvec(components) instead of
these verbose getters for sized vectors.

> +      ir_variable *const src_temp =
> +         factory.make_temp(expr->operands[1]->type, "src_temp");
> +
> +      const ir_swizzle_mask m = { 0, 0, 0, 0, components, false };
> +      ir_rvalue *broadcast_index =
> +         new(factory.mem_ctx) ir_swizzle(expr->operands[2], m);

Optionally:

ir_rvalue *broadcast_index =
   swizzle_for_size(swizzle_xxxx(expr->operands[2]), components).

> +      factory.emit(assign(temp, expr->operands[0]));
> +      factory.emit(assign(src_temp, expr->operands[1]));
> +      factory.emit(assign(cmp_result, equal(broadcast_index, cmp_indices)));
> +      factory.emit(if_tree(swizzle_x(cmp_result), assign(temp, src_temp, 1)));
> +      factory.emit(if_tree(swizzle_y(cmp_result), assign(temp, src_temp, 2)));
> +
> +      if (components > 2)
> +         factory.emit(if_tree(swizzle_z(cmp_result), assign(temp, src_temp, 4)));
> +
> +      if (components > 3)
> +         factory.emit(if_tree(swizzle_w(cmp_result), assign(temp, src_temp, 8)));

Please use the WRITEMASK_* defines here.

I know our hardware doesn't like the swizzling of that bvec compare
result and we'd rather just see individual compares as the condition of
each if statement.  (we basically have to emit a compare of the swizzled
bool against 0, after masking its high bits off, when we could have just
compared the index value to a constant).  I imagine other hardware would
prefer the same.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20130409/c259b281/attachment.pgp>


More information about the mesa-dev mailing list