[Mesa-dev] [PATCH 8/8] i965: remove now unused GLSL IR optimisations

tournier.elie tournier.elie at gmail.com
Wed Apr 19 15:32:36 UTC 2017


On 18 April 2017 at 06:52, Timothy Arceri <tarceri at itsqueeze.com> wrote:
> These are no longer used since the previous commit.

Patches 4 - 8 are:
Acked-by: Elie Tournier <elie.tournier at collabora.com>

> ---
>  src/mesa/drivers/dri/i965/Makefile.sources         |   2 -
>  .../dri/i965/brw_fs_channel_expressions.cpp        | 483 ---------------------
>  .../drivers/dri/i965/brw_fs_vector_splitting.cpp   | 400 -----------------
>  src/mesa/drivers/dri/i965/brw_program.h            |   3 -
>  4 files changed, 888 deletions(-)
>  delete mode 100644 src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp
>  delete mode 100644 src/mesa/drivers/dri/i965/brw_fs_vector_splitting.cpp
>
> diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources
> index 02dbb55..aef1a7a 100644
> --- a/src/mesa/drivers/dri/i965/Makefile.sources
> +++ b/src/mesa/drivers/dri/i965/Makefile.sources
> @@ -21,22 +21,20 @@ i965_FILES = \
>         brw_cs.c \
>         brw_cs.h \
>         brw_curbe.c \
>         brw_defines.h \
>         brw_draw.c \
>         brw_draw.h \
>         brw_draw_upload.c \
>         brw_ff_gs.c \
>         brw_ff_gs_emit.c \
>         brw_ff_gs.h \
> -       brw_fs_channel_expressions.cpp \
> -       brw_fs_vector_splitting.cpp \
>         brw_formatquery.c \
>         brw_gs.c \
>         brw_gs.h \
>         brw_gs_state.c \
>         brw_gs_surface_state.c \
>         brw_link.cpp \
>         brw_meta_util.c \
>         brw_meta_util.h \
>         brw_misc_state.c \
>         brw_multisample_state.h \
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp b/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp
> deleted file mode 100644
> index 58fa207..0000000
> --- a/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp
> +++ /dev/null
> @@ -1,483 +0,0 @@
> -/*
> - * Copyright © 2010 Intel Corporation
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining a
> - * copy of this software and associated documentation files (the "Software"),
> - * to deal in the Software without restriction, including without limitation
> - * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> - * and/or sell copies of the Software, and to permit persons to whom the
> - * Software is furnished to do so, subject to the following conditions:
> - *
> - * The above copyright notice and this permission notice (including the next
> - * paragraph) shall be included in all copies or substantial portions of the
> - * Software.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> - * DEALINGS IN THE SOFTWARE.
> - */
> -
> -/**
> - * \file brw_wm_channel_expressions.cpp
> - *
> - * Breaks vector operations down into operations on each component.
> - *
> - * The 965 fragment shader receives 8 or 16 pixels at a time, so each
> - * channel of a vector is laid out as 1 or 2 8-float registers.  Each
> - * ALU operation operates on one of those channel registers.  As a
> - * result, there is no value to the 965 fragment shader in tracking
> - * "vector" expressions in the sense of GLSL fragment shaders, when
> - * doing a channel at a time may help in constant folding, algebraic
> - * simplification, and reducing the liveness of channel registers.
> - *
> - * The exception to the desire to break everything down to floats is
> - * texturing.  The texture sampler returns a writemasked masked
> - * 4/8-register sequence containing the texture values.  We don't want
> - * to dispatch to the sampler separately for each channel we need, so
> - * we do retain the vector types in that case.
> - */
> -
> -#include "brw_program.h"
> -#include "compiler/glsl/ir.h"
> -#include "compiler/glsl/ir_expression_flattening.h"
> -#include "compiler/glsl_types.h"
> -
> -class ir_channel_expressions_visitor : public ir_hierarchical_visitor {
> -public:
> -   ir_channel_expressions_visitor()
> -   {
> -      this->progress = false;
> -      this->mem_ctx = NULL;
> -   }
> -
> -   ir_visitor_status visit_leave(ir_assignment *);
> -
> -   ir_rvalue *get_element(ir_variable *var, unsigned int element);
> -   void assign(ir_assignment *ir, int elem, ir_rvalue *val);
> -
> -   bool progress;
> -   void *mem_ctx;
> -};
> -
> -static bool
> -channel_expressions_predicate(ir_instruction *ir)
> -{
> -   ir_expression *expr = ir->as_expression();
> -   unsigned int i;
> -
> -   if (!expr)
> -      return false;
> -
> -   switch (expr->operation) {
> -      case ir_unop_pack_half_2x16:
> -      case ir_unop_pack_snorm_2x16:
> -      case ir_unop_pack_snorm_4x8:
> -      case ir_unop_pack_unorm_2x16:
> -      case ir_unop_pack_unorm_4x8:
> -         return false;
> -
> -      /* these opcodes need to act on the whole vector,
> -       * just like texturing.
> -       */
> -      case ir_unop_interpolate_at_centroid:
> -      case ir_binop_interpolate_at_offset:
> -      case ir_binop_interpolate_at_sample:
> -      case ir_unop_pack_double_2x32:
> -      case ir_unop_pack_int_2x32:
> -      case ir_unop_pack_uint_2x32:
> -         return false;
> -      default:
> -         break;
> -   }
> -
> -   for (i = 0; i < expr->get_num_operands(); i++) {
> -      if (expr->operands[i]->type->is_vector())
> -        return true;
> -   }
> -
> -   return false;
> -}
> -
> -bool
> -brw_do_channel_expressions(exec_list *instructions)
> -{
> -   ir_channel_expressions_visitor v;
> -
> -   /* Pull out any matrix expression to a separate assignment to a
> -    * temp.  This will make our handling of the breakdown to
> -    * operations on the matrix's vector components much easier.
> -    */
> -   do_expression_flattening(instructions, channel_expressions_predicate);
> -
> -   visit_list_elements(&v, instructions);
> -
> -   return v.progress;
> -}
> -
> -ir_rvalue *
> -ir_channel_expressions_visitor::get_element(ir_variable *var, unsigned int elem)
> -{
> -   ir_dereference *deref;
> -
> -   if (var->type->is_scalar())
> -      return new(mem_ctx) ir_dereference_variable(var);
> -
> -   assert(elem < var->type->components());
> -   deref = new(mem_ctx) ir_dereference_variable(var);
> -   return new(mem_ctx) ir_swizzle(deref, elem, 0, 0, 0, 1);
> -}
> -
> -void
> -ir_channel_expressions_visitor::assign(ir_assignment *ir, int elem, ir_rvalue *val)
> -{
> -   ir_dereference *lhs = ir->lhs->clone(mem_ctx, NULL);
> -   ir_assignment *assign;
> -
> -   /* This assign-of-expression should have been generated by the
> -    * expression flattening visitor (since we never short circit to
> -    * not flatten, even for plain assignments of variables), so the
> -    * writemask is always full.
> -    */
> -   assert(ir->write_mask == (1 << ir->lhs->type->components()) - 1);
> -
> -   assign = new(mem_ctx) ir_assignment(lhs, val, NULL, (1 << elem));
> -   ir->insert_before(assign);
> -}
> -
> -ir_visitor_status
> -ir_channel_expressions_visitor::visit_leave(ir_assignment *ir)
> -{
> -   ir_expression *expr = ir->rhs->as_expression();
> -   bool found_vector = false;
> -   unsigned int i, vector_elements = 1;
> -   ir_variable *op_var[4];
> -
> -   if (!expr)
> -      return visit_continue;
> -
> -   if (!this->mem_ctx)
> -      this->mem_ctx = ralloc_parent(ir);
> -
> -   for (i = 0; i < expr->get_num_operands(); i++) {
> -      if (expr->operands[i]->type->is_vector()) {
> -        found_vector = true;
> -        vector_elements = expr->operands[i]->type->vector_elements;
> -        break;
> -      }
> -   }
> -   if (!found_vector)
> -      return visit_continue;
> -
> -   switch (expr->operation) {
> -      case ir_unop_pack_half_2x16:
> -      case ir_unop_pack_snorm_2x16:
> -      case ir_unop_pack_snorm_4x8:
> -      case ir_unop_pack_unorm_2x16:
> -      case ir_unop_pack_unorm_4x8:
> -      case ir_unop_interpolate_at_centroid:
> -      case ir_binop_interpolate_at_offset:
> -      case ir_binop_interpolate_at_sample:
> -      /* We scalarize these in NIR, so no need to do it here */
> -      case ir_unop_pack_double_2x32:
> -      case ir_unop_pack_int_2x32:
> -      case ir_unop_pack_uint_2x32:
> -         return visit_continue;
> -
> -      default:
> -         break;
> -   }
> -
> -   /* Store the expression operands in temps so we can use them
> -    * multiple times.
> -    */
> -   for (i = 0; i < expr->get_num_operands(); i++) {
> -      ir_assignment *assign;
> -      ir_dereference *deref;
> -
> -      assert(!expr->operands[i]->type->is_matrix());
> -
> -      op_var[i] = new(mem_ctx) ir_variable(expr->operands[i]->type,
> -                                          "channel_expressions",
> -                                          ir_var_temporary);
> -      ir->insert_before(op_var[i]);
> -
> -      deref = new(mem_ctx) ir_dereference_variable(op_var[i]);
> -      assign = new(mem_ctx) ir_assignment(deref,
> -                                         expr->operands[i],
> -                                         NULL);
> -      ir->insert_before(assign);
> -   }
> -
> -   const glsl_type *element_type = glsl_type::get_instance(ir->lhs->type->base_type,
> -                                                          1, 1);
> -
> -   /* OK, time to break down this vector operation. */
> -   switch (expr->operation) {
> -   case ir_unop_bit_not:
> -   case ir_unop_logic_not:
> -   case ir_unop_neg:
> -   case ir_unop_abs:
> -   case ir_unop_sign:
> -   case ir_unop_rcp:
> -   case ir_unop_rsq:
> -   case ir_unop_sqrt:
> -   case ir_unop_exp:
> -   case ir_unop_log:
> -   case ir_unop_exp2:
> -   case ir_unop_log2:
> -   case ir_unop_bitcast_i2f:
> -   case ir_unop_bitcast_f2i:
> -   case ir_unop_bitcast_f2u:
> -   case ir_unop_bitcast_u2f:
> -   case ir_unop_bitcast_u642d:
> -   case ir_unop_bitcast_i642d:
> -   case ir_unop_bitcast_d2u64:
> -   case ir_unop_bitcast_d2i64:
> -   case ir_unop_i2u:
> -   case ir_unop_u2i:
> -   case ir_unop_f2i:
> -   case ir_unop_f2u:
> -   case ir_unop_i2f:
> -   case ir_unop_f2b:
> -   case ir_unop_b2f:
> -   case ir_unop_i2b:
> -   case ir_unop_b2i:
> -   case ir_unop_u2f:
> -   case ir_unop_d2f:
> -   case ir_unop_f2d:
> -   case ir_unop_d2i:
> -   case ir_unop_i2d:
> -   case ir_unop_d2u:
> -   case ir_unop_u2d:
> -   case ir_unop_d2b:
> -   case ir_unop_i642i:
> -   case ir_unop_u642i:
> -   case ir_unop_i642u:
> -   case ir_unop_u642u:
> -   case ir_unop_i642b:
> -   case ir_unop_i642f:
> -   case ir_unop_u642f:
> -   case ir_unop_i642d:
> -   case ir_unop_u642d:
> -   case ir_unop_i2i64:
> -   case ir_unop_u2i64:
> -   case ir_unop_b2i64:
> -   case ir_unop_f2i64:
> -   case ir_unop_d2i64:
> -   case ir_unop_i2u64:
> -   case ir_unop_u2u64:
> -   case ir_unop_f2u64:
> -   case ir_unop_d2u64:
> -   case ir_unop_u642i64:
> -   case ir_unop_i642u64:
> -   case ir_unop_trunc:
> -   case ir_unop_ceil:
> -   case ir_unop_floor:
> -   case ir_unop_fract:
> -   case ir_unop_round_even:
> -   case ir_unop_sin:
> -   case ir_unop_cos:
> -   case ir_unop_dFdx:
> -   case ir_unop_dFdx_coarse:
> -   case ir_unop_dFdx_fine:
> -   case ir_unop_dFdy:
> -   case ir_unop_dFdy_coarse:
> -   case ir_unop_dFdy_fine:
> -   case ir_unop_bitfield_reverse:
> -   case ir_unop_bit_count:
> -   case ir_unop_find_msb:
> -   case ir_unop_find_lsb:
> -   case ir_unop_saturate:
> -   case ir_unop_subroutine_to_int:
> -      for (i = 0; i < vector_elements; i++) {
> -        ir_rvalue *op0 = get_element(op_var[0], i);
> -
> -        assign(ir, i, new(mem_ctx) ir_expression(expr->operation,
> -                                                 element_type,
> -                                                 op0,
> -                                                 NULL));
> -      }
> -      break;
> -
> -   case ir_binop_add:
> -   case ir_binop_sub:
> -   case ir_binop_mul:
> -   case ir_binop_imul_high:
> -   case ir_binop_div:
> -   case ir_binop_carry:
> -   case ir_binop_borrow:
> -   case ir_binop_mod:
> -   case ir_binop_min:
> -   case ir_binop_max:
> -   case ir_binop_pow:
> -   case ir_binop_lshift:
> -   case ir_binop_rshift:
> -   case ir_binop_bit_and:
> -   case ir_binop_bit_xor:
> -   case ir_binop_bit_or:
> -   case ir_binop_logic_and:
> -   case ir_binop_logic_xor:
> -   case ir_binop_logic_or:
> -   case ir_binop_less:
> -   case ir_binop_greater:
> -   case ir_binop_lequal:
> -   case ir_binop_gequal:
> -   case ir_binop_equal:
> -   case ir_binop_nequal:
> -   case ir_binop_ldexp:
> -      for (i = 0; i < vector_elements; i++) {
> -        ir_rvalue *op0 = get_element(op_var[0], i);
> -        ir_rvalue *op1 = get_element(op_var[1], i);
> -
> -        assign(ir, i, new(mem_ctx) ir_expression(expr->operation,
> -                                                 element_type,
> -                                                 op0,
> -                                                 op1));
> -      }
> -      break;
> -
> -   case ir_binop_dot: {
> -      ir_expression *last = NULL;
> -      for (i = 0; i < vector_elements; i++) {
> -        ir_rvalue *op0 = get_element(op_var[0], i);
> -        ir_rvalue *op1 = get_element(op_var[1], i);
> -        ir_expression *temp;
> -
> -        temp = new(mem_ctx) ir_expression(ir_binop_mul,
> -                                          element_type,
> -                                          op0,
> -                                          op1);
> -        if (last) {
> -           last = new(mem_ctx) ir_expression(ir_binop_add,
> -                                             element_type,
> -                                             temp,
> -                                             last);
> -        } else {
> -           last = temp;
> -        }
> -      }
> -      assign(ir, 0, last);
> -      break;
> -   }
> -
> -   case ir_binop_all_equal:
> -   case ir_binop_any_nequal: {
> -      ir_expression *last = NULL;
> -      for (i = 0; i < vector_elements; i++) {
> -        ir_rvalue *op0 = get_element(op_var[0], i);
> -        ir_rvalue *op1 = get_element(op_var[1], i);
> -        ir_expression *temp;
> -        ir_expression_operation join;
> -
> -        if (expr->operation == ir_binop_all_equal)
> -           join = ir_binop_logic_and;
> -        else
> -           join = ir_binop_logic_or;
> -
> -        temp = new(mem_ctx) ir_expression(expr->operation,
> -                                          element_type,
> -                                          op0,
> -                                          op1);
> -        if (last) {
> -           last = new(mem_ctx) ir_expression(join,
> -                                             element_type,
> -                                             temp,
> -                                             last);
> -        } else {
> -           last = temp;
> -        }
> -      }
> -      assign(ir, 0, last);
> -      break;
> -   }
> -   case ir_unop_noise:
> -      unreachable("noise should have been broken down to function call");
> -
> -   case ir_binop_ubo_load:
> -   case ir_unop_get_buffer_size:
> -      unreachable("not yet supported");
> -
> -   case ir_triop_fma:
> -   case ir_triop_lrp:
> -   case ir_triop_csel:
> -   case ir_triop_bitfield_extract:
> -      for (i = 0; i < vector_elements; i++) {
> -        ir_rvalue *op0 = get_element(op_var[0], i);
> -        ir_rvalue *op1 = get_element(op_var[1], i);
> -        ir_rvalue *op2 = get_element(op_var[2], i);
> -
> -        assign(ir, i, new(mem_ctx) ir_expression(expr->operation,
> -                                                 element_type,
> -                                                 op0,
> -                                                 op1,
> -                                                 op2));
> -      }
> -      break;
> -
> -   case ir_quadop_bitfield_insert:
> -      for (i = 0; i < vector_elements; i++) {
> -         ir_rvalue *op0 = get_element(op_var[0], i);
> -         ir_rvalue *op1 = get_element(op_var[1], i);
> -         ir_rvalue *op2 = get_element(op_var[2], i);
> -         ir_rvalue *op3 = get_element(op_var[3], i);
> -
> -         assign(ir, i, new(mem_ctx) ir_expression(expr->operation,
> -                                                  element_type,
> -                                                  op0,
> -                                                  op1,
> -                                                  op2,
> -                                                  op3));
> -      }
> -      break;
> -
> -   case ir_unop_pack_snorm_2x16:
> -   case ir_unop_pack_snorm_4x8:
> -   case ir_unop_pack_unorm_2x16:
> -   case ir_unop_pack_unorm_4x8:
> -   case ir_unop_pack_half_2x16:
> -   case ir_unop_unpack_snorm_2x16:
> -   case ir_unop_unpack_snorm_4x8:
> -   case ir_unop_unpack_unorm_2x16:
> -   case ir_unop_unpack_unorm_4x8:
> -   case ir_unop_unpack_half_2x16:
> -   case ir_binop_vector_extract:
> -   case ir_triop_vector_insert:
> -   case ir_quadop_vector:
> -   case ir_unop_ssbo_unsized_array_length:
> -      unreachable("should have been lowered");
> -
> -   case ir_unop_interpolate_at_centroid:
> -   case ir_binop_interpolate_at_offset:
> -   case ir_binop_interpolate_at_sample:
> -   case ir_unop_unpack_double_2x32:
> -      unreachable("not reached: expression operates on scalars only");
> -
> -   case ir_unop_pack_double_2x32:
> -   case ir_unop_pack_int_2x32:
> -   case ir_unop_pack_uint_2x32:
> -      unreachable("not reached: to be lowered in NIR, should've been skipped");
> -
> -   case ir_unop_frexp_sig:
> -   case ir_unop_frexp_exp:
> -      unreachable("should have been lowered by lower_instructions");
> -
> -   case ir_unop_vote_any:
> -   case ir_unop_vote_all:
> -   case ir_unop_vote_eq:
> -   case ir_unop_unpack_int_2x32:
> -   case ir_unop_unpack_uint_2x32:
> -   case ir_unop_ballot:
> -   case ir_unop_read_first_invocation:
> -   case ir_binop_read_invocation:
> -      unreachable("unsupported");
> -   }
> -
> -   ir->remove();
> -   this->progress = true;
> -
> -   return visit_continue;
> -}
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_vector_splitting.cpp b/src/mesa/drivers/dri/i965/brw_fs_vector_splitting.cpp
> deleted file mode 100644
> index ce64dc6..0000000
> --- a/src/mesa/drivers/dri/i965/brw_fs_vector_splitting.cpp
> +++ /dev/null
> @@ -1,400 +0,0 @@
> -/*
> - * Copyright © 2010 Intel Corporation
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining a
> - * copy of this software and associated documentation files (the "Software"),
> - * to deal in the Software without restriction, including without limitation
> - * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> - * and/or sell copies of the Software, and to permit persons to whom the
> - * Software is furnished to do so, subject to the following conditions:
> - *
> - * The above copyright notice and this permission notice (including the next
> - * paragraph) shall be included in all copies or substantial portions of the
> - * Software.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> - * DEALINGS IN THE SOFTWARE.
> - */
> -
> -/**
> - * \file brw_wm_vector_splitting.cpp
> - *
> - * If a vector is only ever referenced by its components, then
> - * split those components out to individual variables so they can be
> - * handled normally by other optimization passes.
> - *
> - * This skips vectors in uniforms and varyings, which need to be
> - * accessible as vectors for their access by the GL.  Also, vector
> - * results of non-variable-derefs in assignments aren't handled
> - * because to do so we would have to store the vector result to a
> - * temporary in order to unload each channel, and to do so would just
> - * loop us back to where we started.  For the 965, this is exactly the
> - * behavior we want for the results of texture lookups, but probably not for
> - */
> -
> -#include "brw_program.h"
> -#include "main/imports.h"
> -#include "compiler/glsl/ir.h"
> -#include "compiler/glsl/ir_rvalue_visitor.h"
> -#include "compiler/glsl_types.h"
> -#include "util/hash_table.h"
> -
> -static bool debug = false;
> -
> -class variable_entry : public exec_node
> -{
> -public:
> -   variable_entry(ir_variable *var)
> -   {
> -      this->var = var;
> -      this->whole_vector_access = 0;
> -      this->mem_ctx = NULL;
> -   }
> -
> -   ir_variable *var; /* The key: the variable's pointer. */
> -
> -   /** Number of times the variable is referenced, including assignments. */
> -   unsigned whole_vector_access;
> -
> -   ir_variable *components[4];
> -
> -   /** ralloc_parent(this->var) -- the shader's ralloc context. */
> -   void *mem_ctx;
> -};
> -
> -class ir_vector_reference_visitor : public ir_hierarchical_visitor {
> -public:
> -   ir_vector_reference_visitor(void)
> -   {
> -      this->mem_ctx = ralloc_context(NULL);
> -      this->ht = _mesa_hash_table_create(mem_ctx, _mesa_hash_pointer,
> -                                         _mesa_key_pointer_equal);
> -   }
> -
> -   ~ir_vector_reference_visitor(void)
> -   {
> -      ralloc_free(mem_ctx);
> -   }
> -
> -   virtual ir_visitor_status visit(ir_variable *);
> -   virtual ir_visitor_status visit(ir_dereference_variable *);
> -   virtual ir_visitor_status visit_enter(ir_swizzle *);
> -   virtual ir_visitor_status visit_enter(ir_assignment *);
> -   virtual ir_visitor_status visit_enter(ir_function_signature *);
> -
> -   variable_entry *get_variable_entry(ir_variable *var);
> -
> -   /* List of variable_entry */
> -   struct hash_table *ht;
> -
> -   void *mem_ctx;
> -};
> -
> -variable_entry *
> -ir_vector_reference_visitor::get_variable_entry(ir_variable *var)
> -{
> -   assert(var);
> -
> -   if (!var->type->is_vector())
> -      return NULL;
> -
> -   switch (var->data.mode) {
> -   case ir_var_uniform:
> -   case ir_var_shader_storage:
> -   case ir_var_shader_shared:
> -   case ir_var_shader_in:
> -   case ir_var_shader_out:
> -   case ir_var_system_value:
> -   case ir_var_function_in:
> -   case ir_var_function_out:
> -   case ir_var_function_inout:
> -      /* Can't split varyings or uniforms.  Function in/outs won't get split
> -       * either.
> -       */
> -      return NULL;
> -   case ir_var_auto:
> -   case ir_var_temporary:
> -      break;
> -   }
> -
> -   struct hash_entry *hte = _mesa_hash_table_search(ht, var);
> -   if (hte)
> -      return (struct variable_entry *) hte->data;
> -
> -   variable_entry *entry = new(mem_ctx) variable_entry(var);
> -   _mesa_hash_table_insert(ht, var, entry);
> -   return entry;
> -}
> -
> -
> -ir_visitor_status
> -ir_vector_reference_visitor::visit(ir_variable *ir)
> -{
> -   /* Make sure splitting looks at splitting this variable */
> -   (void)this->get_variable_entry(ir);
> -
> -   return visit_continue;
> -}
> -
> -ir_visitor_status
> -ir_vector_reference_visitor::visit(ir_dereference_variable *ir)
> -{
> -   ir_variable *const var = ir->var;
> -   variable_entry *entry = this->get_variable_entry(var);
> -
> -   if (entry)
> -      entry->whole_vector_access++;
> -
> -   return visit_continue;
> -}
> -
> -ir_visitor_status
> -ir_vector_reference_visitor::visit_enter(ir_swizzle *ir)
> -{
> -   /* Don't descend into a vector ir_dereference_variable below. */
> -   if (ir->val->as_dereference_variable() && ir->type->is_scalar())
> -      return visit_continue_with_parent;
> -
> -   return visit_continue;
> -}
> -
> -ir_visitor_status
> -ir_vector_reference_visitor::visit_enter(ir_assignment *ir)
> -{
> -   if (ir->lhs->as_dereference_variable() &&
> -       ir->rhs->as_dereference_variable() &&
> -       !ir->condition) {
> -      /* We'll split copies of a vector to copies of channels, so don't
> -       * descend to the ir_dereference_variables.
> -       */
> -      return visit_continue_with_parent;
> -   }
> -   if (ir->lhs->as_dereference_variable() &&
> -       _mesa_is_pow_two(ir->write_mask) &&
> -       !ir->condition) {
> -      /* If we're writing just a channel, then channel-splitting the LHS is OK.
> -       */
> -      ir->rhs->accept(this);
> -      return visit_continue_with_parent;
> -   }
> -   return visit_continue;
> -}
> -
> -ir_visitor_status
> -ir_vector_reference_visitor::visit_enter(ir_function_signature *ir)
> -{
> -   /* We don't want to descend into the function parameters and
> -    * split them, so just accept the body here.
> -    */
> -   visit_list_elements(this, &ir->body);
> -   return visit_continue_with_parent;
> -}
> -
> -class ir_vector_splitting_visitor : public ir_rvalue_visitor {
> -public:
> -   ir_vector_splitting_visitor(struct hash_table *vars)
> -   {
> -      this->ht = vars;
> -   }
> -
> -   virtual ir_visitor_status visit_leave(ir_assignment *);
> -
> -   void handle_rvalue(ir_rvalue **rvalue);
> -   variable_entry *get_splitting_entry(ir_variable *var);
> -
> -   struct hash_table *ht;
> -};
> -
> -variable_entry *
> -ir_vector_splitting_visitor::get_splitting_entry(ir_variable *var)
> -{
> -   assert(var);
> -
> -   if (!var->type->is_vector())
> -      return NULL;
> -
> -   struct hash_entry *hte = _mesa_hash_table_search(ht, var);
> -   return hte ? (struct variable_entry *) hte->data : NULL;
> -}
> -
> -void
> -ir_vector_splitting_visitor::handle_rvalue(ir_rvalue **rvalue)
> -{
> -   if (!*rvalue)
> -      return;
> -
> -   ir_swizzle *swiz = (*rvalue)->as_swizzle();
> -   if (!swiz || !swiz->type->is_scalar())
> -      return;
> -
> -   ir_dereference_variable *deref_var = swiz->val->as_dereference_variable();
> -   if (!deref_var)
> -      return;
> -
> -   variable_entry *entry = get_splitting_entry(deref_var->var);
> -   if (!entry)
> -      return;
> -
> -   ir_variable *var = entry->components[swiz->mask.x];
> -   *rvalue = new(entry->mem_ctx) ir_dereference_variable(var);
> -}
> -
> -ir_visitor_status
> -ir_vector_splitting_visitor::visit_leave(ir_assignment *ir)
> -{
> -   ir_dereference_variable *lhs_deref = ir->lhs->as_dereference_variable();
> -   ir_dereference_variable *rhs_deref = ir->rhs->as_dereference_variable();
> -   variable_entry *lhs = lhs_deref ? get_splitting_entry(lhs_deref->var) : NULL;
> -   variable_entry *rhs = rhs_deref ? get_splitting_entry(rhs_deref->var) : NULL;
> -
> -   if (lhs_deref && rhs_deref && (lhs || rhs) && !ir->condition) {
> -      unsigned int rhs_chan = 0;
> -
> -      /* Straight assignment of vector variables. */
> -      for (unsigned int i = 0; i < ir->lhs->type->vector_elements; i++) {
> -        ir_dereference *new_lhs;
> -        ir_rvalue *new_rhs;
> -        void *mem_ctx = lhs ? lhs->mem_ctx : rhs->mem_ctx;
> -        unsigned int writemask;
> -
> -        if (!(ir->write_mask & (1 << i)))
> -           continue;
> -
> -        if (lhs) {
> -           new_lhs = new(mem_ctx) ir_dereference_variable(lhs->components[i]);
> -           writemask = 1;
> -        } else {
> -           new_lhs = ir->lhs->clone(mem_ctx, NULL);
> -           writemask = 1 << i;
> -        }
> -
> -        if (rhs) {
> -           new_rhs =
> -              new(mem_ctx) ir_dereference_variable(rhs->components[rhs_chan]);
> -        } else {
> -           new_rhs = new(mem_ctx) ir_swizzle(ir->rhs->clone(mem_ctx, NULL),
> -                                             rhs_chan, 0, 0, 0, 1);
> -        }
> -
> -        ir->insert_before(new(mem_ctx) ir_assignment(new_lhs,
> -                                                     new_rhs,
> -                                                     NULL, writemask));
> -
> -        rhs_chan++;
> -      }
> -      ir->remove();
> -   } else if (lhs) {
> -      void *mem_ctx = lhs->mem_ctx;
> -      int elem = -1;
> -
> -      switch (ir->write_mask) {
> -      case (1 << 0):
> -        elem = 0;
> -        break;
> -      case (1 << 1):
> -        elem = 1;
> -        break;
> -      case (1 << 2):
> -        elem = 2;
> -        break;
> -      case (1 << 3):
> -        elem = 3;
> -        break;
> -      default:
> -        ir->fprint(stderr);
> -        unreachable("not reached: non-channelwise dereference of LHS.");
> -      }
> -
> -      ir->lhs = new(mem_ctx) ir_dereference_variable(lhs->components[elem]);
> -      ir->write_mask = (1 << 0);
> -
> -      handle_rvalue(&ir->rhs);
> -   } else {
> -      handle_rvalue(&ir->rhs);
> -   }
> -
> -   handle_rvalue(&ir->condition);
> -
> -   return visit_continue;
> -}
> -
> -bool
> -brw_do_vector_splitting(exec_list *instructions)
> -{
> -   struct hash_entry *hte;
> -
> -   ir_vector_reference_visitor refs;
> -
> -   visit_list_elements(&refs, instructions);
> -
> -   /* Trim out variables we can't split. */
> -   hash_table_foreach(refs.ht, hte) {
> -      struct variable_entry *entry = (struct variable_entry *) hte->data;
> -      if (debug) {
> -        fprintf(stderr, "vector %s@%p: whole_access %d\n",
> -                 entry->var->name, (void *) entry->var,
> -                 entry->whole_vector_access);
> -      }
> -
> -      if (entry->whole_vector_access) {
> -         _mesa_hash_table_remove(refs.ht, hte);
> -      }
> -   }
> -
> -   if (refs.ht->entries == 0)
> -      return false;
> -
> -   void *mem_ctx = ralloc_context(NULL);
> -
> -   /* Replace the decls of the vectors to be split with their split
> -    * components.
> -    */
> -   hash_table_foreach(refs.ht, hte) {
> -      struct variable_entry *entry = (struct variable_entry *) hte->data;
> -      const struct glsl_type *type;
> -      type = glsl_type::get_instance(entry->var->type->base_type, 1, 1);
> -
> -      entry->mem_ctx = ralloc_parent(entry->var);
> -
> -      for (unsigned int i = 0; i < entry->var->type->vector_elements; i++) {
> -         char *const name = ir_variable::temporaries_allocate_names
> -            ? ralloc_asprintf(mem_ctx, "%s_%c",
> -                              entry->var->name,
> -                              "xyzw"[i])
> -            : NULL;
> -
> -        entry->components[i] = new(entry->mem_ctx) ir_variable(type, name,
> -                                                               ir_var_temporary);
> -
> -         ralloc_free(name);
> -
> -         if (entry->var->constant_initializer) {
> -            ir_constant_data data = {0};
> -            assert(entry->var->data.has_initializer);
> -            if (entry->var->type->is_double()) {
> -               data.d[0] = entry->var->constant_initializer->value.d[i];
> -            } else {
> -               data.u[0] = entry->var->constant_initializer->value.u[i];
> -            }
> -            entry->components[i]->data.has_initializer = true;
> -            entry->components[i]->constant_initializer = new(entry->components[i]) ir_constant(type, &data);
> -         }
> -
> -        entry->var->insert_before(entry->components[i]);
> -      }
> -
> -      entry->var->remove();
> -   }
> -
> -   ir_vector_splitting_visitor split(refs.ht);
> -   visit_list_elements(&split, instructions);
> -
> -   ralloc_free(mem_ctx);
> -
> -   return true;
> -}
> diff --git a/src/mesa/drivers/dri/i965/brw_program.h b/src/mesa/drivers/dri/i965/brw_program.h
> index 2e9f121..e62b7d36 100644
> --- a/src/mesa/drivers/dri/i965/brw_program.h
> +++ b/src/mesa/drivers/dri/i965/brw_program.h
> @@ -25,23 +25,20 @@
>  #define BRW_PROGRAM_H
>
>  #include "compiler/brw_compiler.h"
>
>  #ifdef __cplusplus
>  extern "C" {
>  #endif
>
>  struct brw_context;
>
> -bool brw_do_channel_expressions(struct exec_list *instructions);
> -bool brw_do_vector_splitting(struct exec_list *instructions);
> -
>  struct nir_shader *brw_create_nir(struct brw_context *brw,
>                                    const struct gl_shader_program *shader_prog,
>                                    struct gl_program *prog,
>                                    gl_shader_stage stage,
>                                    bool is_scalar);
>
>  void brw_setup_tex_for_precompile(struct brw_context *brw,
>                                    struct brw_sampler_prog_key_data *tex,
>                                    struct gl_program *prog);
>
> --
> 2.9.3
>
> _______________________________________________
> 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