i965: Make shader_time store names/ids instead of referencing shaders.
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 15 Apr 2015 09:16:47 +0000 (02:16 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Fri, 17 Apr 2015 19:07:35 +0000 (12:07 -0700)
Jason noticed that shader_time was bumping the reference count on the
gl_shader_program and gl_program structures, in code called during
compilation.

Not only were these never unreferenced, but it meant fragment shaders
might be referenced twice (SIMD8 and SIMD16)...or only once.

We don't actually need the programs.  We just need their numeric ID and
their language (GLSL/ARB/FF) or KHR_debug label.  If there's a label, we
have to strdup it since the underlying program could be deleted.

To be fair, we're not exactly cleaning that up either, but we at least
ralloc it out of the shader_time arrays, so if we ever bother cleaning
those up, they'll go away properly.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
Acked-by: Anuj Phogat <anuj.phogat@gmail.com>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_program.c

index 0bd0ed1faf82baecd7a6758f2666c869a7cecc2b..a6d67878e7139b9530b9710e44f9745269b8e4a9 100644 (file)
@@ -1454,8 +1454,8 @@ struct brw_context
 
    struct {
       drm_intel_bo *bo;
-      struct gl_shader_program **shader_programs;
-      struct gl_program **programs;
+      const char **names;
+      int *ids;
       enum shader_time_shader_type *types;
       uint64_t *cumulative;
       int num_entries;
index 7ea08e614735dd0ea2dab9981da2145d2c79fc88..81a0c1914206d363ea5106f6b947d9ef1e046941 100644 (file)
@@ -294,10 +294,8 @@ brw_init_shader_time(struct brw_context *brw)
    brw->shader_time.bo = drm_intel_bo_alloc(brw->bufmgr, "shader time",
                                             max_entries * SHADER_TIME_STRIDE,
                                             4096);
-   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.names = rzalloc_array(brw, const char *, max_entries);
+   brw->shader_time.ids = rzalloc_array(brw, int, max_entries);
    brw->shader_time.types = rzalloc_array(brw, enum shader_time_shader_type,
                                           max_entries);
    brw->shader_time.cumulative = rzalloc_array(brw, uint64_t,
@@ -434,36 +432,15 @@ brw_report_shader_time(struct brw_context *brw)
    fprintf(stderr, "\n");
    fprintf(stderr, "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;
-      struct gl_shader_program *prog = brw->shader_time.shader_programs[i];
 
       if (scaled[i] == 0)
          continue;
 
-      int shader_num = 0;
-      if (prog) {
-         shader_num = prog->Name;
-
-         if (prog->Label) {
-            shader_name = prog->Label;
-         } else if (shader_num == 0) {
-            shader_name = "ff";
-         } 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";
-         } else {
-            shader_name = "prog";
-         }
-      } else {
-         shader_name = "other";
-      }
+      int shader_num = brw->shader_time.ids[i];
+      const char *shader_name = brw->shader_time.names[i];
 
       switch (brw->shader_time.types[i]) {
       case ST_VS:
@@ -543,19 +520,24 @@ brw_get_shader_time_index(struct brw_context *brw,
                           struct gl_program *prog,
                           enum shader_time_shader_type type)
 {
-   struct gl_context *ctx = &brw->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);
+   int id = shader_prog ? shader_prog->Name : prog->Id;
+   const char *name;
+   if (id == 0) {
+      name = "ff";
+   } else if (!shader_prog) {
+      name = "prog";
+   } else if (shader_prog->Label) {
+      name = ralloc_strdup(brw->shader_time.names, shader_prog->Label);
+   } else {
+      name = "glsl";
+   }
 
-   _mesa_reference_program(ctx,
-                           &brw->shader_time.programs[shader_time_index],
-                           prog);
+   brw->shader_time.names[shader_time_index] = name;
+   brw->shader_time.ids[shader_time_index] = id;
 
    return shader_time_index;
 }