From: Ian Romanick Date: Wed, 1 Nov 2017 06:16:38 +0000 (-0700) Subject: glsl: Make the swizzle-swizzle optimization greedy X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c858abb14f8e96fca880d1ae85874f9c084397b7;p=mesa.git glsl: Make the swizzle-swizzle optimization greedy If there is a long sequence of swizzled swizzles, compact all of them down to a single swizzle. Signed-off-by: Ian Romanick Reviewed-by: --- diff --git a/src/compiler/glsl/opt_swizzle_swizzle.cpp b/src/compiler/glsl/opt_swizzle_swizzle.cpp index 7285474b089..40ce268b1a5 100644 --- a/src/compiler/glsl/opt_swizzle_swizzle.cpp +++ b/src/compiler/glsl/opt_swizzle_swizzle.cpp @@ -23,8 +23,7 @@ /** * \file opt_swizzle_swizzle.cpp - * - * Eliminates the second swizzle in a swizzle chain. + * Compact a sequence of swizzled swizzles into a single swizzle. */ #include "ir.h" @@ -51,34 +50,34 @@ public: ir_visitor_status ir_swizzle_swizzle_visitor::visit_enter(ir_swizzle *ir) { - int mask2[4]; - - ir_swizzle *swiz2 = ir->val->as_swizzle(); - if (!swiz2) - return visit_continue; - - memset(&mask2, 0, sizeof(mask2)); - if (swiz2->mask.num_components >= 1) - mask2[0] = swiz2->mask.x; - if (swiz2->mask.num_components >= 2) - mask2[1] = swiz2->mask.y; - if (swiz2->mask.num_components >= 3) - mask2[2] = swiz2->mask.z; - if (swiz2->mask.num_components >= 4) - mask2[3] = swiz2->mask.w; - - if (ir->mask.num_components >= 1) - ir->mask.x = mask2[ir->mask.x]; - if (ir->mask.num_components >= 2) - ir->mask.y = mask2[ir->mask.y]; - if (ir->mask.num_components >= 3) - ir->mask.z = mask2[ir->mask.z]; - if (ir->mask.num_components >= 4) - ir->mask.w = mask2[ir->mask.w]; - - ir->val = swiz2->val; - - this->progress = true; + ir_swizzle *swiz2; + + while ((swiz2 = ir->val->as_swizzle()) != NULL) { + int mask2[4]; + + memset(&mask2, 0, sizeof(mask2)); + if (swiz2->mask.num_components >= 1) + mask2[0] = swiz2->mask.x; + if (swiz2->mask.num_components >= 2) + mask2[1] = swiz2->mask.y; + if (swiz2->mask.num_components >= 3) + mask2[2] = swiz2->mask.z; + if (swiz2->mask.num_components >= 4) + mask2[3] = swiz2->mask.w; + + if (ir->mask.num_components >= 1) + ir->mask.x = mask2[ir->mask.x]; + if (ir->mask.num_components >= 2) + ir->mask.y = mask2[ir->mask.y]; + if (ir->mask.num_components >= 3) + ir->mask.z = mask2[ir->mask.z]; + if (ir->mask.num_components >= 4) + ir->mask.w = mask2[ir->mask.w]; + + ir->val = swiz2->val; + + this->progress = true; + } return visit_continue; }