[Mesa-dev] [PATCH 2/2] glsl: Update expression types after rebalancing the tree.

Kenneth Graunke kenneth at whitecape.org
Mon Jul 14 15:28:58 PDT 2014


On Thursday, July 10, 2014 11:26:52 AM Matt Turner wrote:
> If we saw a tree that looked like
> 
>             vec3
>            /   \
>          vec3 float
>         /   \
>       vec3 float
>      /   \
>    vec3 float
> 
> We would see that all of the expression types were vec3, and then
> rebalance to
> 
>            vec3
>         /        \
>       vec3       vec3 <-- should be float
>      /   \      /    \
>    vec3 float float float
> 
> This patch adds code to visit the rebalanced tree and update the
> expression types from the bottom up.
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=80880
> ---
>  src/glsl/opt_rebalance_tree.cpp | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/src/glsl/opt_rebalance_tree.cpp 
b/src/glsl/opt_rebalance_tree.cpp
> index 773aab3..daabdc9 100644
> --- a/src/glsl/opt_rebalance_tree.cpp
> +++ b/src/glsl/opt_rebalance_tree.cpp
> @@ -60,6 +60,7 @@
>  #include "ir_visitor.h"
>  #include "ir_rvalue_visitor.h"
>  #include "ir_optimization.h"
> +#include "main/macros.h" /* for MAX2 */
>  
>  /* The DSW algorithm generates a degenerate tree (really, a linked list) in
>   * tree_to_vine(). We'd rather not leave a binary expression with only one
> @@ -261,6 +262,20 @@ handle_expression(ir_expression *expr)
>     return expr;
>  }
>  
> +static void
> +update_types(ir_instruction *ir, void *)
> +{
> +   ir_expression *expr = ir->as_expression();
> +   if (!expr)
> +      return;
> +
> +   expr->type =
> +      glsl_type::get_instance(expr->type->base_type,
> +                              MAX2(expr->operands[0]->type->components(),
> +                                   expr->operands[1]->type->components()),
> +                              1);
> +}
> +
>  void
>  ir_rebalance_visitor::handle_rvalue(ir_rvalue **rvalue)
>  {
> @@ -285,6 +300,8 @@ ir_rebalance_visitor::handle_rvalue(ir_rvalue **rvalue)
>     if (new_rvalue == *rvalue)
>        return;
>  
> +   visit_tree(new_rvalue, NULL, NULL, update_types);
> +
>     *rvalue = new_rvalue;
>     this->progress = true;
>  }
> 

Thanks for fixing this!

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140714/a9b34f30/attachment.sig>


More information about the mesa-dev mailing list