[Mesa-dev] [PATCH v2] st/mesa: swizzle argument when there's a vector size mismatch

Marek Olšák maraeo at gmail.com
Tue Dec 5 18:43:08 UTC 2017


Reviewed-by: Marek Olšák <marek.olsak at amd.com>

Marek

On Tue, Dec 5, 2017 at 5:26 AM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
> GLSL IR operation arguments can sometimes have an implicit swizzle as a
> result of a vector arg and a scalar arg, where the scalar argument is
> implicitly expanded to the size of the vector argument.
>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103955
> Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
> ---
>
> v1 -> v2:
>  - fix typo that caused compilation failure
>  - remove ir_binop_interpolate_at_* from getting the resizing treatment
>
> I went through all the ir_binops and ir_triops, and those two seem like the
> only ones with weird arguments. I think.
>
>  src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index 8eeae86dabb..740c197c74b 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -1341,10 +1341,33 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op)
>     st_dst_reg result_dst;
>
>     int vector_elements = ir->operands[0]->type->vector_elements;
> -   if (ir->operands[1]) {
> +   if (ir->operands[1] &&
> +       ir->operation != ir_binop_interpolate_at_offset &&
> +       ir->operation != ir_binop_interpolate_at_sample) {
> +      st_src_reg *swz_op = NULL;
> +      if (vector_elements > ir->operands[1]->type->vector_elements) {
> +         assert(ir->operands[1]->type->vector_elements == 1);
> +         swz_op = &op[1];
> +      } else if (vector_elements < ir->operands[1]->type->vector_elements) {
> +         assert(ir->operands[0]->type->vector_elements == 1);
> +         swz_op = &op[0];
> +      }
> +      if (swz_op) {
> +         uint16_t swizzle_x = GET_SWZ(swz_op->swizzle, 0);
> +         swz_op->swizzle = MAKE_SWIZZLE4(swizzle_x, swizzle_x,
> +                                         swizzle_x, swizzle_x);
> +      }
>        vector_elements = MAX2(vector_elements,
>                               ir->operands[1]->type->vector_elements);
>     }
> +   if (ir->operands[2] &&
> +       ir->operands[2]->type->vector_elements != vector_elements) {
> +      /* This can happen with ir_triop_lrp, i.e. glsl mix */
> +      assert(ir->operands[2]->type->vector_elements == 1);
> +      uint16_t swizzle_x = GET_SWZ(op[2].swizzle, 0);
> +      op[2].swizzle = MAKE_SWIZZLE4(swizzle_x, swizzle_x,
> +                                    swizzle_x, swizzle_x);
> +   }
>
>     this->result.file = PROGRAM_UNDEFINED;
>
> --
> 2.13.6
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list