OSDN Git Service

i965/vec4: Allow CSE on uniform-vec4 expansion MOVs.
authorMatt Turner <mattst88@gmail.com>
Fri, 24 Oct 2014 06:22:09 +0000 (23:22 -0700)
committerMatt Turner <mattst88@gmail.com>
Fri, 5 Dec 2014 17:49:42 +0000 (09:49 -0800)
Three source instructions cannot directly source a packed vec4 (<0,4,1>
regioning) like vec4 uniforms, so we emit a MOV that expands the vec4 to
both halves of a register.

If these uniform values are used by multiple three-source instructions,
we'll emit multiple expansion moves, which we cannot combine in CSE
(because CSE emits moves itself).

So emit a virtual instruction that we can CSE.

Sometimes we demote a uniform to to a pull constant after emitting an
expansion move for it. In that case, recognize in opt_algebraic that if
the .file of the new instruction is GRF then it's just a real move that
we can copy propagate and such.

total instructions in shared programs: 5822418 -> 5812335 (-0.17%)
instructions in affected programs:     351841 -> 341758 (-2.87%)

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_defines.h
src/mesa/drivers/dri/i965/brw_shader.cpp
src/mesa/drivers/dri/i965/brw_vec4.cpp
src/mesa/drivers/dri/i965/brw_vec4_cse.cpp
src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp

index 2acd0f8..d421149 100644 (file)
@@ -909,6 +909,7 @@ enum opcode {
    SHADER_OPCODE_GEN7_SCRATCH_READ,
 
    VEC4_OPCODE_PACK_BYTES,
+   VEC4_OPCODE_UNPACK_UNIFORM,
 
    FS_OPCODE_DDX_COARSE,
    FS_OPCODE_DDX_FINE,
index 8528d3e..a53b63a 100644 (file)
@@ -449,6 +449,8 @@ brw_instruction_name(enum opcode op)
 
    case VEC4_OPCODE_PACK_BYTES:
       return "pack_bytes";
+   case VEC4_OPCODE_UNPACK_UNIFORM:
+      return "unpack_uniform";
 
    case FS_OPCODE_DDX_COARSE:
       return "ddx_coarse";
index 18a3369..d026810 100644 (file)
@@ -562,6 +562,13 @@ vec4_visitor::opt_algebraic()
 
    foreach_block_and_inst(block, vec4_instruction, inst, cfg) {
       switch (inst->opcode) {
+      case VEC4_OPCODE_UNPACK_UNIFORM:
+         if (inst->src[0].file != UNIFORM) {
+            inst->opcode = BRW_OPCODE_MOV;
+            progress = true;
+         }
+         break;
+
       case BRW_OPCODE_ADD:
         if (inst->src[1].is_zero()) {
            inst->opcode = BRW_OPCODE_MOV;
index 630d335..7071213 100644 (file)
@@ -69,6 +69,7 @@ is_expression(const vec4_instruction *const inst)
    case BRW_OPCODE_PLN:
    case BRW_OPCODE_MAD:
    case BRW_OPCODE_LRP:
+   case VEC4_OPCODE_UNPACK_UNIFORM:
       return true;
    case SHADER_OPCODE_RCP:
    case SHADER_OPCODE_RSQ:
index b353539..adbb161 100644 (file)
@@ -1183,6 +1183,7 @@ vec4_generator::generate_code(const cfg_t *cfg)
       }
 
       switch (inst->opcode) {
+      case VEC4_OPCODE_UNPACK_UNIFORM:
       case BRW_OPCODE_MOV:
          brw_MOV(p, dst, src[0]);
          break;
index ded7b8c..70ee2c5 100644 (file)
@@ -302,7 +302,7 @@ vec4_visitor::fix_3src_operand(src_reg src)
 
    dst_reg expanded = dst_reg(this, glsl_type::vec4_type);
    expanded.type = src.type;
-   emit(MOV(expanded, src));
+   emit(VEC4_OPCODE_UNPACK_UNIFORM, expanded, src);
    return src_reg(expanded);
 }