i965: Pull calls to get_shader_time_index out of the visitor
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 19 Jun 2015 22:40:09 +0000 (15:40 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 23 Jun 2015 22:34:59 +0000 (15:34 -0700)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
16 files changed:
src/mesa/drivers/dri/i965/brw_cs.cpp
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
src/mesa/drivers/dri/i965/brw_vec4.cpp
src/mesa/drivers/dri/i965/brw_vec4.h
src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp
src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.h
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
src/mesa/drivers/dri/i965/brw_vec4_vs_visitor.cpp
src/mesa/drivers/dri/i965/brw_vs.h
src/mesa/drivers/dri/i965/gen6_gs_visitor.h
src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp
src/mesa/drivers/dri/i965/test_fs_saturate_propagation.cpp
src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp
src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp

index 0833404d5e5c9bcb37e14d1066e28a5bb79d2bf8..fa8b5c8415d743a49b142810c72f81d61b905147 100644 (file)
@@ -88,10 +88,14 @@ brw_cs_emit(struct brw_context *brw,
    cfg_t *cfg = NULL;
    const char *fail_msg = NULL;
 
+   int st_index = -1;
+   if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+      st_index = brw_get_shader_time_index(brw, prog, &cp->Base, ST_CS);
+
    /* Now the main event: Visit the shader IR and generate our CS IR for it.
     */
    fs_visitor v8(brw, mem_ctx, MESA_SHADER_COMPUTE, key, &prog_data->base, prog,
-                 &cp->Base, 8);
+                 &cp->Base, 8, st_index);
    if (!v8.run_cs()) {
       fail_msg = v8.fail_msg;
    } else if (local_workgroup_size <= 8 * brw->max_cs_threads) {
@@ -100,7 +104,7 @@ brw_cs_emit(struct brw_context *brw,
    }
 
    fs_visitor v16(brw, mem_ctx, MESA_SHADER_COMPUTE, key, &prog_data->base, prog,
-                  &cp->Base, 16);
+                  &cp->Base, 16, st_index);
    if (likely(!(INTEL_DEBUG & DEBUG_NO16)) &&
        !fail_msg && !v8.simd16_unsupported &&
        local_workgroup_size <= 16 * brw->max_cs_threads) {
index 2839b9f7b899b5f9903a5112448727b5536321ea..f6c4169d0be2c749316d638eeb506016928c428c 100644 (file)
@@ -578,31 +578,6 @@ fs_visitor::emit_shader_time_begin()
 void
 fs_visitor::emit_shader_time_end()
 {
-   enum shader_time_shader_type type;
-   switch (stage) {
-   case MESA_SHADER_VERTEX:
-      type = ST_VS;
-      break;
-   case MESA_SHADER_GEOMETRY:
-      type = ST_GS;
-      break;
-   case MESA_SHADER_FRAGMENT:
-      if (dispatch_width == 8) {
-         type = ST_FS8;
-      } else {
-         assert(dispatch_width == 16);
-         type = ST_FS16;
-      }
-      break;
-   case MESA_SHADER_COMPUTE:
-      type = ST_CS;
-      break;
-   default:
-      unreachable("fs_visitor::emit_shader_time_end missing code");
-   }
-   int shader_time_index = brw_get_shader_time_index(brw, shader_prog, prog,
-                                                     type);
-
    /* Insert our code just before the final SEND with EOT. */
    exec_node *end = this->instructions.get_tail();
    assert(end && ((fs_inst *) end)->eot);
@@ -631,16 +606,16 @@ fs_visitor::emit_shader_time_end()
     * trying to determine the time taken for single instructions.
     */
    ibld.ADD(diff, diff, fs_reg(-2u));
-   SHADER_TIME_ADD(ibld, shader_time_index, 0, diff);
-   SHADER_TIME_ADD(ibld, shader_time_index, 1, fs_reg(1u));
+   SHADER_TIME_ADD(ibld, 0, diff);
+   SHADER_TIME_ADD(ibld, 1, fs_reg(1u));
    ibld.emit(BRW_OPCODE_ELSE);
-   SHADER_TIME_ADD(ibld, shader_time_index, 2, fs_reg(1u));
+   SHADER_TIME_ADD(ibld, 2, fs_reg(1u));
    ibld.emit(BRW_OPCODE_ENDIF);
 }
 
 void
 fs_visitor::SHADER_TIME_ADD(const fs_builder &bld,
-                            int shader_time_index, int shader_time_subindex,
+                            int shader_time_subindex,
                             fs_reg value)
 {
    int index = shader_time_index * 3 + shader_time_subindex;
@@ -3835,7 +3810,7 @@ fs_visitor::run_vs()
    assign_common_binding_table_offsets(0);
    setup_vs_payload();
 
-   if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+   if (shader_time_index >= 0)
       emit_shader_time_begin();
 
    emit_nir_code();
@@ -3845,7 +3820,7 @@ fs_visitor::run_vs()
 
    emit_urb_writes();
 
-   if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+   if (shader_time_index >= 0)
       emit_shader_time_end();
 
    calculate_cfg();
@@ -3883,7 +3858,7 @@ fs_visitor::run_fs()
    } else if (brw->use_rep_send && dispatch_width == 16) {
       emit_repclear_shader();
    } else {
-      if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+      if (shader_time_index >= 0)
          emit_shader_time_begin();
 
       calculate_urb_setup();
@@ -3918,7 +3893,7 @@ fs_visitor::run_fs()
 
       emit_fb_writes();
 
-      if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+      if (shader_time_index >= 0)
          emit_shader_time_end();
 
       calculate_cfg();
@@ -3962,7 +3937,7 @@ fs_visitor::run_cs()
 
    setup_cs_payload();
 
-   if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+   if (shader_time_index >= 0)
       emit_shader_time_begin();
 
    emit_nir_code();
@@ -3972,7 +3947,7 @@ fs_visitor::run_cs()
 
    emit_cs_terminate();
 
-   if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+   if (shader_time_index >= 0)
       emit_shader_time_end();
 
    calculate_cfg();
@@ -4022,10 +3997,16 @@ brw_wm_fs_emit(struct brw_context *brw,
    if (unlikely(INTEL_DEBUG & DEBUG_WM))
       brw_dump_ir("fragment", prog, &shader->base, &fp->Base);
 
+   int st_index8 = -1, st_index16 = -1;
+   if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
+      st_index8 = brw_get_shader_time_index(brw, prog, &fp->Base, ST_FS8);
+      st_index16 = brw_get_shader_time_index(brw, prog, &fp->Base, ST_FS16);
+   }
+
    /* Now the main event: Visit the shader IR and generate our FS IR for it.
     */
    fs_visitor v(brw, mem_ctx, MESA_SHADER_FRAGMENT, key, &prog_data->base,
-                prog, &fp->Base, 8);
+                prog, &fp->Base, 8, st_index8);
    if (!v.run_fs()) {
       if (prog) {
          prog->LinkStatus = false;
@@ -4040,7 +4021,7 @@ brw_wm_fs_emit(struct brw_context *brw,
 
    cfg_t *simd16_cfg = NULL;
    fs_visitor v2(brw, mem_ctx, MESA_SHADER_FRAGMENT, key, &prog_data->base,
-                 prog, &fp->Base, 16);
+                 prog, &fp->Base, 16, st_index16);
    if (likely(!(INTEL_DEBUG & DEBUG_NO16) || brw->use_rep_send)) {
       if (!v.simd16_unsupported) {
          /* Try a SIMD16 compile */
index 55a97228bb4c63fb4340001225e89f8603de0986..525be3a4eaf8fb8ac6bef3af959cd592f729aa39 100644 (file)
@@ -77,7 +77,8 @@ public:
               struct brw_stage_prog_data *prog_data,
               struct gl_shader_program *shader_prog,
               struct gl_program *prog,
-              unsigned dispatch_width);
+              unsigned dispatch_width,
+              int shader_time_index);
 
    ~fs_visitor();
 
@@ -278,7 +279,7 @@ public:
    void emit_shader_time_begin();
    void emit_shader_time_end();
    void SHADER_TIME_ADD(const brw::fs_builder &bld,
-                        int shader_time_index, int shader_time_subindex,
+                        int shader_time_subindex,
                         fs_reg value);
 
    void emit_untyped_atomic(unsigned atomic_op, unsigned surf_index,
@@ -387,6 +388,8 @@ public:
 
    const unsigned dispatch_width; /**< 8 or 16 */
 
+   int shader_time_index;
+
    unsigned promoted_constants;
    brw::fs_builder bld;
 };
index 3af9d78598c701cedfefda6b7de5d7270aa33454..bff1169c779f5107f2dd9822c0bedd9c3956e705 100644 (file)
@@ -1983,10 +1983,13 @@ fs_visitor::fs_visitor(struct brw_context *brw,
                        struct brw_stage_prog_data *prog_data,
                        struct gl_shader_program *shader_prog,
                        struct gl_program *prog,
-                       unsigned dispatch_width)
+                       unsigned dispatch_width,
+                       int shader_time_index)
    : backend_shader(brw, mem_ctx, shader_prog, prog, prog_data, stage),
      key(key), prog_data(prog_data),
-     dispatch_width(dispatch_width), promoted_constants(0),
+     dispatch_width(dispatch_width),
+     shader_time_index(shader_time_index),
+     promoted_constants(0),
      bld(fs_builder(this, dispatch_width).at_end())
 {
    switch (stage) {
index 234ee188c2717e16c25a2b27761c5a3dda9d88ab..093802c24d2a9f31915355bc807938362b53855f 100644 (file)
@@ -1676,20 +1676,15 @@ vec4_visitor::emit_shader_time_end()
     */
    emit(ADD(diff, src_reg(diff), src_reg(-2u)));
 
-   int shader_time_index =
-      brw_get_shader_time_index(brw, shader_prog, prog, st_type);
-
-   emit_shader_time_write(shader_time_index, 0, src_reg(diff));
-   emit_shader_time_write(shader_time_index, 1, src_reg(1u));
+   emit_shader_time_write(0, src_reg(diff));
+   emit_shader_time_write(1, src_reg(1u));
    emit(BRW_OPCODE_ELSE);
-   emit_shader_time_write(shader_time_index, 2, src_reg(1u));
+   emit_shader_time_write(2, src_reg(1u));
    emit(BRW_OPCODE_ENDIF);
 }
 
 void
-vec4_visitor::emit_shader_time_write(int shader_time_index,
-                                     int shader_time_subindex,
-                                     src_reg value)
+vec4_visitor::emit_shader_time_write(int shader_time_subindex, src_reg value)
 {
    dst_reg dst =
       dst_reg(this, glsl_type::get_array_instance(glsl_type::vec4_type, 2));
@@ -1715,7 +1710,7 @@ vec4_visitor::run()
 {
    sanity_param_count = prog->Parameters->NumParameters;
 
-   if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+   if (shader_time_index >= 0)
       emit_shader_time_begin();
 
    assign_binding_table_offsets();
@@ -1881,6 +1876,11 @@ brw_vs_emit(struct brw_context *brw,
    if (prog)
       shader = (brw_shader *) prog->_LinkedShaders[MESA_SHADER_VERTEX];
 
+   int st_index = -1;
+   if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+      st_index = brw_get_shader_time_index(brw, prog, &c->vp->program.Base,
+                                           ST_VS);
+
    if (unlikely(INTEL_DEBUG & DEBUG_VS))
       brw_dump_ir("vertex", prog, &shader->base, &c->vp->program.Base);
 
@@ -1899,7 +1899,8 @@ brw_vs_emit(struct brw_context *brw,
       prog_data->base.dispatch_mode = DISPATCH_MODE_SIMD8;
 
       fs_visitor v(brw, mem_ctx, MESA_SHADER_VERTEX, &c->key,
-                   &prog_data->base.base, prog, &c->vp->program.Base, 8);
+                   &prog_data->base.base, prog, &c->vp->program.Base,
+                   8, st_index);
       if (!v.run_vs()) {
          if (prog) {
             prog->LinkStatus = false;
@@ -1937,7 +1938,7 @@ brw_vs_emit(struct brw_context *brw,
    if (!assembly) {
       prog_data->base.dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT;
 
-      vec4_vs_visitor v(brw, c, prog_data, prog, mem_ctx);
+      vec4_vs_visitor v(brw, c, prog_data, prog, mem_ctx, st_index);
       if (!v.run()) {
          if (prog) {
             prog->LinkStatus = false;
index 8d332af17f48b6b9319a6f9b015d614b92a3dfb8..4a3ce62a12eaad18dbce589928ed06f55decd181 100644 (file)
@@ -85,7 +85,7 @@ public:
                 gl_shader_stage stage,
                void *mem_ctx,
                 bool no_spills,
-                shader_time_shader_type st_type);
+                int shader_time_index);
    ~vec4_visitor();
 
    dst_reg dst_null_f()
@@ -343,8 +343,7 @@ public:
 
    void emit_shader_time_begin();
    void emit_shader_time_end();
-   void emit_shader_time_write(int shader_time_index, int shader_time_subindex,
-                               src_reg value);
+   void emit_shader_time_write(int shader_time_subindex, src_reg value);
 
    void emit_untyped_atomic(unsigned atomic_op, unsigned surf_index,
                             dst_reg dst, src_reg offset, src_reg src0,
@@ -411,7 +410,7 @@ private:
     */
    const bool no_spills;
 
-   const shader_time_shader_type st_type;
+   int shader_time_index;
 };
 
 
index d3754de0ca39e130a6b57f67fe0b0a44adc08427..9ba964172592a1b0c7a102b27657a6603c2ecfe2 100644 (file)
@@ -38,10 +38,11 @@ vec4_gs_visitor::vec4_gs_visitor(struct brw_context *brw,
                                  struct brw_gs_compile *c,
                                  struct gl_shader_program *prog,
                                  void *mem_ctx,
-                                 bool no_spills)
+                                 bool no_spills,
+                                 int shader_time_index)
    : vec4_visitor(brw, &c->base, &c->gp->program.Base, &c->key.base,
                   &c->prog_data.base, prog, MESA_SHADER_GEOMETRY, mem_ctx,
-                  no_spills, ST_GS),
+                  no_spills, shader_time_index),
      c(c)
 {
 }
@@ -648,6 +649,10 @@ brw_gs_emit(struct brw_context *brw,
       brw_dump_ir("geometry", prog, &shader->base, NULL);
    }
 
+   int st_index = -1;
+   if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+      st_index = brw_get_shader_time_index(brw, prog, NULL, ST_GS);
+
    if (brw->gen >= 7) {
       /* Compile the geometry shader in DUAL_OBJECT dispatch mode, if we can do
        * so without spilling. If the GS invocations count > 1, then we can't use
@@ -657,7 +662,8 @@ brw_gs_emit(struct brw_context *brw,
           likely(!(INTEL_DEBUG & DEBUG_NO_DUAL_OBJECT_GS))) {
          c->prog_data.base.dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT;
 
-         vec4_gs_visitor v(brw, c, prog, mem_ctx, true /* no_spills */);
+         vec4_gs_visitor v(brw, c, prog, mem_ctx, true /* no_spills */,
+                           st_index);
          if (v.run()) {
             return generate_assembly(brw, prog, &c->gp->program.Base,
                                      &c->prog_data.base, mem_ctx, v.cfg,
@@ -698,9 +704,11 @@ brw_gs_emit(struct brw_context *brw,
    const unsigned *ret = NULL;
 
    if (brw->gen >= 7)
-      gs = new vec4_gs_visitor(brw, c, prog, mem_ctx, false /* no_spills */);
+      gs = new vec4_gs_visitor(brw, c, prog, mem_ctx, false /* no_spills */,
+                               st_index);
    else
-      gs = new gen6_gs_visitor(brw, c, prog, mem_ctx, false /* no_spills */);
+      gs = new gen6_gs_visitor(brw, c, prog, mem_ctx, false /* no_spills */,
+                               st_index);
 
    if (!gs->run()) {
       prog->LinkStatus = false;
index bcb5a2bcfc1a392fc4c8c8f93d49939349a61919..f42311d154fafeba18444fd1e3e542c7c718e28e 100644 (file)
@@ -72,7 +72,8 @@ public:
                    struct brw_gs_compile *c,
                    struct gl_shader_program *prog,
                    void *mem_ctx,
-                   bool no_spills);
+                   bool no_spills,
+                   int shader_time_index);
 
 protected:
    virtual dst_reg *make_reg_for_system_value(ir_variable *ir);
index 5ae572b4c41dfdb3d32145b4d6f0d483cae2711a..4f3fc21724bcb191500f55818b036913bd646aa9 100644 (file)
@@ -3688,7 +3688,7 @@ vec4_visitor::vec4_visitor(struct brw_context *brw,
                            gl_shader_stage stage,
                           void *mem_ctx,
                            bool no_spills,
-                           shader_time_shader_type st_type)
+                           int shader_time_index)
    : backend_shader(brw, mem_ctx, shader_prog, prog, &prog_data->base, stage),
      c(c),
      key(key),
@@ -3698,7 +3698,7 @@ vec4_visitor::vec4_visitor(struct brw_context *brw,
      first_non_payload_grf(0),
      need_all_constants_in_pull_buffer(false),
      no_spills(no_spills),
-     st_type(st_type)
+     shader_time_index(shader_time_index)
 {
    this->failed = false;
 
index 731176afd18917fb209777f4279dd46935eeab89..dc1775527be5af8bcfdd9c88f0facfdfd1e95535 100644 (file)
@@ -216,12 +216,13 @@ vec4_vs_visitor::vec4_vs_visitor(struct brw_context *brw,
                                  struct brw_vs_compile *vs_compile,
                                  struct brw_vs_prog_data *vs_prog_data,
                                  struct gl_shader_program *prog,
-                                 void *mem_ctx)
+                                 void *mem_ctx,
+                                 int shader_time_index)
    : vec4_visitor(brw, &vs_compile->base, &vs_compile->vp->program.Base,
                   &vs_compile->key.base, &vs_prog_data->base, prog,
                   MESA_SHADER_VERTEX,
                   mem_ctx, false /* no_spills */,
-                  ST_VS),
+                  shader_time_index),
      vs_compile(vs_compile),
      vs_prog_data(vs_prog_data)
 {
index 6157ae6ffa9d225136e387777d681f04be1af8fd..6f84179c69485dcd32029c3ed89b1e046e22da24 100644 (file)
@@ -94,7 +94,8 @@ public:
                    struct brw_vs_compile *vs_compile,
                    struct brw_vs_prog_data *vs_prog_data,
                    struct gl_shader_program *prog,
-                   void *mem_ctx);
+                   void *mem_ctx,
+                   int shader_time_index);
 
 protected:
    virtual dst_reg *make_reg_for_system_value(ir_variable *ir);
index 28f23c9e4f7686db8998a65993db030b8efdbf28..863fbd0855212a70f064df67e1528e845d1296ef 100644 (file)
@@ -39,8 +39,9 @@ public:
                    struct brw_gs_compile *c,
                    struct gl_shader_program *prog,
                    void *mem_ctx,
-                   bool no_spills) :
-      vec4_gs_visitor(brw, c, prog, mem_ctx, no_spills) {}
+                   bool no_spills,
+                   int shader_time_index) :
+      vec4_gs_visitor(brw, c, prog, mem_ctx, no_spills, shader_time_index) {}
 
 protected:
    virtual void assign_binding_table_offsets();
index 7bb5c4a2fa27527c2d601cb6e8c514141fc2ab08..f0209abeca909d70e54b5d5bef91e67b78cd1b68 100644 (file)
@@ -48,7 +48,7 @@ public:
                                struct brw_wm_prog_data *prog_data,
                                struct gl_shader_program *shader_prog)
       : fs_visitor(brw, NULL, MESA_SHADER_FRAGMENT, NULL, &prog_data->base,
-                   shader_prog, (struct gl_program *) NULL, 8) {}
+                   shader_prog, (struct gl_program *) NULL, 8, -1) {}
 };
 
 
index d5142f5787248c74d6507a5e65978c389b451af7..b8cf40eace5748d19a1701816153d2554c370bdd 100644 (file)
@@ -48,7 +48,7 @@ public:
                                    struct brw_wm_prog_data *prog_data,
                                    struct gl_shader_program *shader_prog)
       : fs_visitor(brw, NULL, MESA_SHADER_FRAGMENT, NULL, &prog_data->base,
-                   shader_prog, (struct gl_program *) NULL, 8) {}
+                   shader_prog, (struct gl_program *) NULL, 8, -1) {}
 };
 
 
index 8a867366517d713362aaaf2f7ed0df8da873a546..9234b667f014a68c7d5189a53c2d4269ba067423 100644 (file)
@@ -48,7 +48,7 @@ public:
                                   struct gl_shader_program *shader_prog)
       : vec4_visitor(brw, NULL, NULL, NULL, NULL, shader_prog,
                      MESA_SHADER_VERTEX, NULL,
-                     false /* no_spills */, ST_NONE)
+                     false /* no_spills */, -1)
    {
    }
 
index 87ebdfa6e9cde2cdb892bc8b51ed2244ae2fa8a4..7d274ded2f2636a8914a65ced11daf002c6877cc 100644 (file)
@@ -51,7 +51,7 @@ public:
                                   struct gl_shader_program *shader_prog)
       : vec4_visitor(brw, NULL, NULL, NULL, NULL, shader_prog,
                      MESA_SHADER_VERTEX, NULL,
-                     false /* no_spills */, ST_NONE)
+                     false /* no_spills */, -1)
    {
    }