i915: Remove most of the code under gen >= 4 checks.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_program.c
index 62954d3cf7863f2eaa6225e5d02d11bcf95cc21f..87986a952f35a144f6141478d81bf19416c95d3c 100644 (file)
@@ -230,7 +230,9 @@ brw_init_shader_time(struct brw_context *brw)
    brw->shader_time.bo = drm_intel_bo_alloc(intel->bufmgr, "shader time",
                                             max_entries * SHADER_TIME_STRIDE,
                                             4096);
-   brw->shader_time.programs = rzalloc_array(brw, struct gl_shader_program *,
+   brw->shader_time.shader_programs = rzalloc_array(brw, struct gl_shader_program *,
+                                                    max_entries);
+   brw->shader_time.programs = rzalloc_array(brw, struct gl_program *,
                                              max_entries);
    brw->shader_time.types = rzalloc_array(brw, enum shader_time_shader_type,
                                           max_entries);
@@ -275,13 +277,15 @@ get_written_and_reset(struct brw_context *brw, int i,
 }
 
 static void
-print_shader_time_line(const char *name, int shader_num,
-                       uint64_t time, uint64_t total)
+print_shader_time_line(const char *stage, const char *name,
+                       int shader_num, uint64_t time, uint64_t total)
 {
-   printf("%s", name);
-   for (int i = strlen(name); i < 10; i++)
-      printf(" ");
-   printf("%4d: ", shader_num);
+   printf("%-6s%-6s", stage, name);
+
+   if (shader_num != -1)
+      printf("%4d: ", shader_num);
+   else
+      printf("    : ");
 
    printf("%16lld (%7.2f Gcycles)      %4.1f%%\n",
           (long long)time,
@@ -360,8 +364,10 @@ brw_report_shader_time(struct brw_context *brw)
    qsort(sorted, brw->shader_time.num_entries, sizeof(sorted[0]), compare_time);
 
    printf("\n");
-   printf("type   ID      cycles spent                   %% of total\n");
+   printf("type          ID      cycles spent                   %% of total\n");
    for (int s = 0; s < brw->shader_time.num_entries; s++) {
+      const char *shader_name;
+      const char *stage;
       /* Work back from the sorted pointers times to a time to print. */
       int i = sorted[s] - scaled;
 
@@ -369,30 +375,55 @@ brw_report_shader_time(struct brw_context *brw)
          continue;
 
       int shader_num = -1;
-      if (brw->shader_time.programs[i]) {
-         shader_num = brw->shader_time.programs[i]->Name;
+      if (brw->shader_time.shader_programs[i]) {
+         shader_num = brw->shader_time.shader_programs[i]->Name;
+
+         /* The fixed function fragment shader generates GLSL IR with a Name
+          * of 0, and nothing else does.
+          */
+         if (shader_num == 0 &&
+             (brw->shader_time.types[i] == ST_FS8 ||
+              brw->shader_time.types[i] == ST_FS16)) {
+            shader_name = "ff";
+            shader_num = -1;
+         } else {
+            shader_name = "glsl";
+         }
+      } else if (brw->shader_time.programs[i]) {
+         shader_num = brw->shader_time.programs[i]->Id;
+         if (shader_num == 0) {
+            shader_name = "ff";
+            shader_num = -1;
+         } else {
+            shader_name = "prog";
+         }
+      } else {
+         shader_name = "other";
       }
 
       switch (brw->shader_time.types[i]) {
       case ST_VS:
-         print_shader_time_line("vs", shader_num, scaled[i], total);
+         stage = "vs";
          break;
       case ST_FS8:
-         print_shader_time_line("fs8", shader_num, scaled[i], total);
+         stage = "fs8";
          break;
       case ST_FS16:
-         print_shader_time_line("fs16", shader_num, scaled[i], total);
+         stage = "fs16";
          break;
       default:
-         print_shader_time_line("other", shader_num, scaled[i], total);
+         stage = "other";
          break;
       }
+
+      print_shader_time_line(stage, shader_name, shader_num,
+                             scaled[i], total);
    }
 
    printf("\n");
-   print_shader_time_line("total vs", -1, total_by_type[ST_VS], total);
-   print_shader_time_line("total fs8", -1, total_by_type[ST_FS8], total);
-   print_shader_time_line("total fs16", -1, total_by_type[ST_FS16], total);
+   print_shader_time_line("total", "vs", -1, total_by_type[ST_VS], total);
+   print_shader_time_line("total", "fs8", -1, total_by_type[ST_FS8], total);
+   print_shader_time_line("total", "fs16", -1, total_by_type[ST_FS16], total);
 }
 
 static void
@@ -431,6 +462,36 @@ brw_collect_and_report_shader_time(struct brw_context *brw)
    }
 }
 
+/**
+ * Chooses an index in the shader_time buffer and sets up tracking information
+ * for our printouts.
+ *
+ * Note that this holds on to references to the underlying programs, which may
+ * change their lifetimes compared to normal operation.
+ */
+int
+brw_get_shader_time_index(struct brw_context *brw,
+                          struct gl_shader_program *shader_prog,
+                          struct gl_program *prog,
+                          enum shader_time_shader_type type)
+{
+   struct gl_context *ctx = &brw->intel.ctx;
+
+   int shader_time_index = brw->shader_time.num_entries++;
+   assert(shader_time_index < brw->shader_time.max_entries);
+   brw->shader_time.types[shader_time_index] = type;
+
+   _mesa_reference_shader_program(ctx,
+                                  &brw->shader_time.shader_programs[shader_time_index],
+                                  shader_prog);
+
+   _mesa_reference_program(ctx,
+                           &brw->shader_time.programs[shader_time_index],
+                           prog);
+
+   return shader_time_index;
+}
+
 void
 brw_destroy_shader_time(struct brw_context *brw)
 {