i965/vs: Add VS program key dumping to INTEL_DEBUG=perf.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vs.c
index be82177f40d5b3162192640ad0f44e5aceb412a0..21204372c0de4a84d0e80e438f2cb84e0aab07ec 100644 (file)
@@ -57,13 +57,13 @@ static inline void assign_vue_slot(struct brw_vue_map *vue_map,
  * prog_data->userclip and prog_data->outputs_written in their key
  * (generated by CACHE_NEW_VS_PROG).
  */
-void
-brw_compute_vue_map(struct brw_vue_map *vue_map,
-                    const struct intel_context *intel,
-                   const struct brw_vs_prog_data *prog_data)
+static void
+brw_compute_vue_map(struct brw_vs_compile *c)
 {
-   bool userclip_active = prog_data->userclip;
-   GLbitfield64 outputs_written = prog_data->outputs_written;
+   struct brw_context *brw = c->func.brw;
+   const struct intel_context *intel = &brw->intel;
+   struct brw_vue_map *vue_map = &c->prog_data.vue_map;
+   GLbitfield64 outputs_written = c->prog_data.outputs_written;
    int i;
 
    vue_map->num_slots = 0;
@@ -118,7 +118,7 @@ brw_compute_vue_map(struct brw_vue_map *vue_map,
        */
       assign_vue_slot(vue_map, VERT_RESULT_PSIZ);
       assign_vue_slot(vue_map, VERT_RESULT_HPOS);
-      if (userclip_active) {
+      if (c->key.userclip_active) {
          assign_vue_slot(vue_map, VERT_RESULT_CLIP_DIST0);
          assign_vue_slot(vue_map, VERT_RESULT_CLIP_DIST1);
       }
@@ -229,6 +229,8 @@ do_vs_prog(struct brw_context *brw,
         c.prog_data.outputs_written |= BITFIELD64_BIT(VERT_RESULT_TEX0 + i);
    }
 
+   brw_compute_vue_map(&c);
+
    if (0) {
       _mesa_fprint_program_opt(stdout, &c.vp->program.Base, PROG_PRINT_DEBUG,
                               true);
@@ -245,8 +247,22 @@ do_vs_prog(struct brw_context *brw,
       brw_old_vs_emit(&c);
    }
 
+   if (c.prog_data.nr_pull_params)
+      c.prog_data.num_surfaces = 1;
+   if (c.vp->program.Base.SamplersUsed)
+      c.prog_data.num_surfaces = SURF_INDEX_VS_TEXTURE(BRW_MAX_TEX_UNIT);
+   if (prog &&
+       prog->_LinkedShaders[MESA_SHADER_VERTEX]->NumUniformBlocks) {
+      c.prog_data.num_surfaces =
+        SURF_INDEX_VS_UBO(prog->_LinkedShaders[MESA_SHADER_VERTEX]->NumUniformBlocks);
+   }
+
    /* Scratch space is used for register spilling */
    if (c.last_scratch) {
+      perf_debug("Vertex shader triggered register spilling.  "
+                 "Try reducing the number of live vec4 values to "
+                 "improve performance.\n");
+
       c.prog_data.total_scratch = brw_get_scratch_size(c.last_scratch);
 
       brw_get_scratch_bo(intel, &brw->vs.scratch_bo,
@@ -281,6 +297,77 @@ do_vs_prog(struct brw_context *brw,
    return true;
 }
 
+static bool
+key_debug(const char *name, int a, int b)
+{
+   if (a != b) {
+      perf_debug("  %s %d->%d\n", name, a, b);
+      return true;
+   }
+   return false;
+}
+
+void
+brw_vs_debug_recompile(struct brw_context *brw,
+                       struct gl_shader_program *prog,
+                       const struct brw_vs_prog_key *key)
+{
+   struct brw_cache_item *c = NULL;
+   const struct brw_vs_prog_key *old_key = NULL;
+   bool found = false;
+
+   perf_debug("Recompiling vertex shader for program %d\n", prog->Name);
+
+   for (unsigned int i = 0; i < brw->cache.size; i++) {
+      for (c = brw->cache.items[i]; c; c = c->next) {
+         if (c->cache_id == BRW_VS_PROG) {
+            old_key = c->key;
+
+            if (old_key->program_string_id == key->program_string_id)
+               break;
+         }
+      }
+      if (c)
+         break;
+   }
+
+   if (!c) {
+      perf_debug("  Didn't find previous compile in the shader cache for "
+                 "debug\n");
+      return;
+   }
+
+   for (unsigned int i = 0; i < VERT_ATTRIB_MAX; i++) {
+      found |= key_debug("GL_FIXED rescaling",
+                         old_key->gl_fixed_input_size[i],
+                         key->gl_fixed_input_size[i]);
+   }
+
+   found |= key_debug("user clip flags",
+                      old_key->userclip_active, key->userclip_active);
+
+   found |= key_debug("user clipping planes as push constants",
+                      old_key->nr_userclip_plane_consts,
+                      key->nr_userclip_plane_consts);
+
+   found |= key_debug("clip distance enable",
+                      old_key->uses_clip_distance, key->uses_clip_distance);
+   found |= key_debug("clip plane enable bitfield",
+                      old_key->userclip_planes_enabled_gen_4_5,
+                      key->userclip_planes_enabled_gen_4_5);
+   found |= key_debug("copy edgeflag",
+                      old_key->copy_edgeflag, key->copy_edgeflag);
+   found |= key_debug("PointCoord replace",
+                      old_key->point_coord_replace, key->point_coord_replace);
+   found |= key_debug("vertex color clamping",
+                      old_key->clamp_vertex_color, key->clamp_vertex_color);
+
+   found |= brw_debug_recompile_sampler_key(&old_key->tex, &key->tex);
+
+   if (!found) {
+      perf_debug("  Something else\n");
+   }
+}
 
 static void brw_upload_vs_prog(struct brw_context *brw)
 {
@@ -312,8 +399,12 @@ static void brw_upload_vs_prog(struct brw_context *brw)
             = _mesa_logbase2(ctx->Transform.ClipPlanesEnabled) + 1;
       }
    }
-   key.copy_edgeflag = (ctx->Polygon.FrontMode != GL_FILL ||
-                       ctx->Polygon.BackMode != GL_FILL);
+
+   /* _NEW_POLYGON */
+   if (intel->gen < 6) {
+      key.copy_edgeflag = (ctx->Polygon.FrontMode != GL_FILL ||
+                           ctx->Polygon.BackMode != GL_FILL);
+   }
 
    /* _NEW_LIGHT | _NEW_BUFFERS */
    key.clamp_vertex_color = ctx->Light._ClampVertexColor;
@@ -327,10 +418,7 @@ static void brw_upload_vs_prog(struct brw_context *brw)
    }
 
    /* _NEW_TEXTURE */
-   for (i = 0; i < BRW_MAX_TEX_UNIT; i++) {
-      if (prog->TexturesUsed[i])
-        brw_populate_sampler_prog_key_data(ctx, &key.tex, i);
-   }
+   brw_populate_sampler_prog_key_data(ctx, prog, &key.tex);
 
    /* BRW_NEW_VERTICES */
    for (i = 0; i < VERT_ATTRIB_MAX; i++) {