[Mesa-dev] [PATCH] st/mesa: cache tgsi opcode info in the instruction

Marek Olšák maraeo at gmail.com
Thu Aug 27 04:28:25 PDT 2015


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

Marek

On Thu, Aug 27, 2015 at 2:02 AM, Dave Airlie <airlied at gmail.com> wrote:
> From: Dave Airlie <airlied at redhat.com>
>
> Instead of looking this up lots, lets just cache it in the instruction
> translation up front. I just noticed this function what high in a profile
> of shader-db on radeonsi.
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 39 ++++++++++++------------------
>  1 file changed, 16 insertions(+), 23 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index cba9881..65aae40 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -262,6 +262,7 @@ public:
>     int dead_mask; /**< Used in dead code elimination */
>
>     class function_entry *function; /* Set on TGSI_OPCODE_CAL or TGSI_OPCODE_BGNSUB */
> +   const struct tgsi_opcode_info *info;
>  };
>
>  class variable_storage : public exec_node {
> @@ -530,25 +531,16 @@ swizzle_for_size(int size)
>     return size_swizzles[size - 1];
>  }
>
> -static bool
> -is_tex_instruction(unsigned opcode)
> -{
> -   const tgsi_opcode_info* info = tgsi_get_opcode_info(opcode);
> -   return info->is_tex;
> -}
> -
>  static unsigned
> -num_inst_dst_regs(unsigned opcode)
> +num_inst_dst_regs(const glsl_to_tgsi_instruction *op)
>  {
> -   const tgsi_opcode_info* info = tgsi_get_opcode_info(opcode);
> -   return info->num_dst;
> +   return op->info->num_dst;
>  }
>
>  static unsigned
> -num_inst_src_regs(unsigned opcode)
> +num_inst_src_regs(const glsl_to_tgsi_instruction *op)
>  {
> -   const tgsi_opcode_info* info = tgsi_get_opcode_info(opcode);
> -   return info->is_tex ? info->num_src - 1 : info->num_src;
> +   return op->info->is_tex ? op->info->num_src - 1 : op->info->num_src;
>  }
>
>  glsl_to_tgsi_instruction *
> @@ -592,6 +584,7 @@ glsl_to_tgsi_visitor::emit_asm(ir_instruction *ir, unsigned op,
>     assert(num_reladdr == 0);
>
>     inst->op = op;
> +   inst->info = tgsi_get_opcode_info(op);
>     inst->dst[0] = dst;
>     inst->dst[1] = dst1;
>     inst->src[0] = src0;
> @@ -3538,7 +3531,7 @@ count_resources(glsl_to_tgsi_visitor *v, gl_program *prog)
>     v->samplers_used = 0;
>
>     foreach_in_list(glsl_to_tgsi_instruction, inst, &v->instructions) {
> -      if (is_tex_instruction(inst->op)) {
> +      if (inst->info->is_tex) {
>           for (int i = 0; i < inst->sampler_array_size; i++) {
>              unsigned idx = inst->sampler.index + i;
>              v->samplers_used |= 1 << idx;
> @@ -3673,7 +3666,7 @@ glsl_to_tgsi_visitor::rename_temp_register(int index, int new_index)
>     foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
>        unsigned j;
>
> -      for (j = 0; j < num_inst_src_regs(inst->op); j++) {
> +      for (j = 0; j < num_inst_src_regs(inst); j++) {
>           if (inst->src[j].file == PROGRAM_TEMPORARY &&
>               inst->src[j].index == index) {
>              inst->src[j].index = new_index;
> @@ -3687,7 +3680,7 @@ glsl_to_tgsi_visitor::rename_temp_register(int index, int new_index)
>           }
>        }
>
> -      for (j = 0; j < num_inst_dst_regs(inst->op); j++) {
> +      for (j = 0; j < num_inst_dst_regs(inst); j++) {
>           if (inst->dst[j].file == PROGRAM_TEMPORARY && inst->dst[j].index == index) {
>              inst->dst[j].index = new_index;
>           }
> @@ -3703,7 +3696,7 @@ glsl_to_tgsi_visitor::get_first_temp_read(int index)
>     unsigned i = 0, j;
>
>     foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
> -      for (j = 0; j < num_inst_src_regs(inst->op); j++) {
> +      for (j = 0; j < num_inst_src_regs(inst); j++) {
>           if (inst->src[j].file == PROGRAM_TEMPORARY &&
>               inst->src[j].index == index) {
>              return (depth == 0) ? i : loop_start;
> @@ -3737,7 +3730,7 @@ glsl_to_tgsi_visitor::get_first_temp_write(int index)
>     unsigned j;
>
>     foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
> -      for (j = 0; j < num_inst_dst_regs(inst->op); j++) {
> +      for (j = 0; j < num_inst_dst_regs(inst); j++) {
>           if (inst->dst[j].file == PROGRAM_TEMPORARY && inst->dst[j].index == index) {
>              return (depth == 0) ? i : loop_start;
>           }
> @@ -3763,7 +3756,7 @@ glsl_to_tgsi_visitor::get_last_temp_read(int index)
>     unsigned i = 0, j;
>
>     foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
> -      for (j = 0; j < num_inst_src_regs(inst->op); j++) {
> +      for (j = 0; j < num_inst_src_regs(inst); j++) {
>           if (inst->src[j].file == PROGRAM_TEMPORARY &&
>               inst->src[j].index == index) {
>              last = (depth == 0) ? i : -2;
> @@ -3795,7 +3788,7 @@ glsl_to_tgsi_visitor::get_last_temp_write(int index)
>     unsigned j;
>
>     foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
> -      for (j = 0; j < num_inst_dst_regs(inst->op); j++) {
> +      for (j = 0; j < num_inst_dst_regs(inst); j++) {
>           if (inst->dst[j].file == PROGRAM_TEMPORARY && inst->dst[j].index == index)
>              last = (depth == 0) ? i : -2;
>        }
> @@ -4193,7 +4186,7 @@ glsl_to_tgsi_visitor::merge_two_dsts(void)
>     foreach_in_list_safe(glsl_to_tgsi_instruction, inst, &this->instructions) {
>        glsl_to_tgsi_instruction *inst2;
>        bool merged;
> -      if (num_inst_dst_regs(inst->op) != 2)
> +      if (num_inst_dst_regs(inst) != 2)
>           continue;
>
>        if (inst->dst[0].file != PROGRAM_UNDEFINED &&
> @@ -4969,8 +4962,8 @@ compile_tgsi_instruction(struct st_translate *t,
>     unsigned num_src;
>     unsigned tex_target;
>
> -   num_dst = num_inst_dst_regs(inst->op);
> -   num_src = num_inst_src_regs(inst->op);
> +   num_dst = num_inst_dst_regs(inst);
> +   num_src = num_inst_src_regs(inst);
>
>     for (i = 0; i < num_dst; i++)
>        dst[i] = translate_dst(t,
> --
> 2.4.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list