<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 15, 2015 at 2:24 AM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Jason noticed that shader_time was bumping the reference count on the<br>
gl_shader_program and gl_program structures, in code called during<br>
compilation.<br>
<br>
Not only were these never unreferenced, but it meant fragment shaders<br>
might be referenced twice (SIMD8 and SIMD16)...or only once.<br>
<br>
We don't actually need the programs.  We just need their numeric ID and<br>
their language (GLSL/ARB/FF) or KHR_debug label.  If there's a label, we<br>
have to strdup it since the underlying program could be deleted.<br>
<br>
To be fair, we're not exactly cleaning that up either, but we at least<br>
ralloc it out of the shader_time arrays, so if we ever bother cleaning<br>
those up, they'll go away properly.<br>
<br>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
---<br>
 src/mesa/drivers/dri/i965/brw_context.h |  4 +--<br>
 src/mesa/drivers/dri/i965/brw_program.c | 52 +++++++++++----------------------<br>
 2 files changed, 19 insertions(+), 37 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h<br>
index 0bd0ed1..a6d6787 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_context.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_context.h<br>
@@ -1454,8 +1454,8 @@ struct brw_context<br>
<br>
    struct {<br>
       drm_intel_bo *bo;<br>
-      struct gl_shader_program **shader_programs;<br>
-      struct gl_program **programs;<br>
+      const char **names;<br>
+      int *ids;<br>
       enum shader_time_shader_type *types;<br>
       uint64_t *cumulative;<br>
       int num_entries;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c<br>
index 7ea08e6..81a0c19 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_program.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_program.c<br>
@@ -294,10 +294,8 @@ brw_init_shader_time(struct brw_context *brw)<br>
    brw-><a href="http://shader_time.bo" target="_blank">shader_time.bo</a> = drm_intel_bo_alloc(brw->bufmgr, "shader time",<br>
                                             max_entries * SHADER_TIME_STRIDE,<br>
                                             4096);<br>
-   brw->shader_time.shader_programs = rzalloc_array(brw, struct gl_shader_program *,<br>
-                                                    max_entries);<br>
-   brw->shader_time.programs = rzalloc_array(brw, struct gl_program *,<br>
-                                             max_entries);<br>
+   brw->shader_time.names = rzalloc_array(brw, const char *, max_entries);<br>
+   brw->shader_time.ids = rzalloc_array(brw, int, max_entries);<br>
    brw->shader_time.types = rzalloc_array(brw, enum shader_time_shader_type,<br>
                                           max_entries);<br>
    brw->shader_time.cumulative = rzalloc_array(brw, uint64_t,<br>
@@ -434,36 +432,15 @@ brw_report_shader_time(struct brw_context *brw)<br>
    fprintf(stderr, "\n");<br>
    fprintf(stderr, "type          ID                  cycles spent                   %% of total\n");<br>
    for (int s = 0; s < brw->shader_time.num_entries; s++) {<br>
-      const char *shader_name;<br>
       const char *stage;<br>
       /* Work back from the sorted pointers times to a time to print. */<br>
       int i = sorted[s] - scaled;<br>
-      struct gl_shader_program *prog = brw->shader_time.shader_programs[i];<br>
<br>
       if (scaled[i] == 0)<br>
          continue;<br>
<br>
-      int shader_num = 0;<br>
-      if (prog) {<br>
-         shader_num = prog->Name;<br>
-<br>
-         if (prog->Label) {<br>
-            shader_name = prog->Label;<br>
-         } else if (shader_num == 0) {<br>
-            shader_name = "ff";<br>
-         } else {<br>
-            shader_name = "glsl";<br>
-         }<br>
-      } else if (brw->shader_time.programs[i]) {<br>
-         shader_num = brw->shader_time.programs[i]->Id;<br>
-         if (shader_num == 0) {<br>
-            shader_name = "ff";<br>
-         } else {<br>
-            shader_name = "prog";<br>
-         }<br>
-      } else {<br>
-         shader_name = "other";<br>
-      }<br>
+      int shader_num = brw->shader_time.ids[i];<br>
+      const char *shader_name = brw->shader_time.names[i];<br>
<br>
       switch (brw->shader_time.types[i]) {<br>
       case ST_VS:<br>
@@ -543,19 +520,24 @@ brw_get_shader_time_index(struct brw_context *brw,<br>
                           struct gl_program *prog,<br>
                           enum shader_time_shader_type type)<br>
 {<br>
-   struct gl_context *ctx = &brw->ctx;<br>
-<br>
    int shader_time_index = brw->shader_time.num_entries++;<br>
    assert(shader_time_index < brw->shader_time.max_entries);<br>
    brw->shader_time.types[shader_time_index] = type;<br>
<br>
-   _mesa_reference_shader_program(ctx,<br>
-                                  &brw->shader_time.shader_programs[shader_time_index],<br>
-                                  shader_prog);<br>
+   int id = shader_prog ? shader_prog->Name : prog->Id;<br>
+   const char *name;<br>
+   if (id == 0) {<br>
+      name = "ff";<br>
+   } else if (!shader_prog) {<br>
+      name = "prog";<br>
+   } else if (shader_prog->Label) {<br>
+      name = ralloc_strdup(brw->shader_time.names, shader_prog->Label);<br>
+   } else {<br>
+      name = "glsl";<br>
+   }<br>
<br>
-   _mesa_reference_program(ctx,<br>
-                           &brw->shader_time.programs[shader_time_index],<br>
-                           prog);<br>
+   brw->shader_time.names[shader_time_index] = name;<br>
+   brw->shader_time.ids[shader_time_index] = id;<br>
<br>
    return shader_time_index;<br>
 }<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.3.5<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div><div class="gmail_extra">Acked-by: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>></div></div>