Mesa (glsl-to-tgsi): glsl_to_tgsi: improve assignment handling

Bryan Cain bryanc at kemper.freedesktop.org
Mon Jun 27 22:28:19 UTC 2011


Module: Mesa
Branch: glsl-to-tgsi
Commit: 5033622c729e5d70d8e900358fbcce474a26b38c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5033622c729e5d70d8e900358fbcce474a26b38c

Author: Bryan Cain <bryancain3 at gmail.com>
Date:   Mon Jun 27 17:11:07 2011 -0500

glsl_to_tgsi: improve assignment handling

This is a hack, but it's better than emitting an unnecessary MOV instruction
and hoping the optimization passes clean it up.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 15a1a3c..e38617a 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -695,13 +695,13 @@ glsl_to_tgsi_visitor::emit_arl(ir_instruction *ir,
    st_src_reg tmp = get_temp(glsl_type::float_type);
 
    if (src0.type == GLSL_TYPE_INT)
-      emit(ir, TGSI_OPCODE_I2F, st_dst_reg(tmp), src0);
+      emit(NULL, TGSI_OPCODE_I2F, st_dst_reg(tmp), src0);
    else if (src0.type == GLSL_TYPE_UINT)
-      emit(ir, TGSI_OPCODE_U2F, st_dst_reg(tmp), src0);
+      emit(NULL, TGSI_OPCODE_U2F, st_dst_reg(tmp), src0);
    else
       tmp = src0;
    
-   emit(ir, TGSI_OPCODE_ARL, dst, tmp);
+   emit(NULL, TGSI_OPCODE_ARL, dst, tmp);
 }
 
 /**
@@ -1902,6 +1902,17 @@ glsl_to_tgsi_visitor::visit(ir_assignment *ir)
          l.index++;
          r.index++;
       }
+   } else if (ir->rhs->as_expression() &&
+              this->instructions.get_tail() &&
+              ir->rhs == ((glsl_to_tgsi_instruction *)this->instructions.get_tail())->ir &&
+              type_size(ir->lhs->type) == 1) {
+      /* To avoid emitting an extra MOV when assigning an expression to a 
+       * variable, change the destination register of the last instruction 
+       * emitted as part of the expression to the assignment variable.
+       */
+      glsl_to_tgsi_instruction *inst;
+      inst = (glsl_to_tgsi_instruction *)this->instructions.get_tail();
+      inst->dst = l;
    } else {
       for (i = 0; i < type_size(ir->lhs->type); i++) {
          emit(ir, TGSI_OPCODE_MOV, l, r);




More information about the mesa-commit mailing list