[Mesa-dev] [PATCH 1/8] i965: Track ARB program state along with GLSL state for shader_time.

Eric Anholt eric at anholt.net
Tue Mar 19 17:05:56 PDT 2013


This will let us do much better printouts for non-GLSL programs.
---
 src/mesa/drivers/dri/i965/brw_context.h |    7 +++++-
 src/mesa/drivers/dri/i965/brw_fs.cpp    |   14 ++----------
 src/mesa/drivers/dri/i965/brw_fs.h      |    2 +-
 src/mesa/drivers/dri/i965/brw_program.c |   38 ++++++++++++++++++++++++++++---
 src/mesa/drivers/dri/i965/brw_vec4.cpp  |   13 ++---------
 src/mesa/drivers/dri/i965/brw_vec4.h    |    2 +-
 6 files changed, 47 insertions(+), 29 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 0f1d451..61f3bb7 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1105,7 +1105,8 @@ struct brw_context
 
    struct {
       drm_intel_bo *bo;
-      struct gl_shader_program **programs;
+      struct gl_shader_program **shader_programs;
+      struct gl_program **programs;
       enum shader_time_shader_type *types;
       uint64_t *cumulative;
       int num_entries;
@@ -1168,6 +1169,10 @@ int brw_get_scratch_size(int size);
 void brw_get_scratch_bo(struct intel_context *intel,
 			drm_intel_bo **scratch_bo, int size);
 void brw_init_shader_time(struct brw_context *brw);
+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);
 void brw_collect_and_report_shader_time(struct brw_context *brw);
 void brw_destroy_shader_time(struct brw_context *brw);
 
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 1b57af0..7817655 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -605,18 +605,8 @@ void
 fs_visitor::emit_shader_time_write(enum shader_time_shader_type type,
                                    fs_reg value)
 {
-   /* Choose an index in the buffer and set up tracking information for our
-    * printouts.
-    */
-   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;
-   if (prog) {
-      _mesa_reference_shader_program(ctx,
-                                     &brw->shader_time.programs[shader_time_index],
-                                     prog);
-   }
-
+   int shader_time_index = brw_get_shader_time_index(brw, prog, &fp->Base,
+                                                     type);
    int base_mrf = 6;
 
    fs_reg offset_mrf = fs_reg(MRF, base_mrf);
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 254a534..1fabec4 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -424,7 +424,7 @@ public:
    void dump_instructions();
    void dump_instruction(fs_inst *inst);
 
-   const struct gl_fragment_program *fp;
+   struct gl_fragment_program *fp;
    struct brw_wm_compile *c;
    unsigned int sanity_param_count;
 
diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c
index 62954d3..7a1b3f2 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -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);
@@ -369,8 +371,8 @@ 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;
       }
 
       switch (brw->shader_time.types[i]) {
@@ -431,6 +433,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)
 {
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp
index 2fd981e..3e628c8 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp
@@ -1204,17 +1204,8 @@ void
 vec4_visitor::emit_shader_time_write(enum shader_time_shader_type type,
                                      src_reg value)
 {
-   /* Choose an index in the buffer and set up tracking information for our
-    * printouts.
-    */
-   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;
-   if (prog) {
-      _mesa_reference_shader_program(ctx,
-                                     &brw->shader_time.programs[shader_time_index],
-                                     prog);
-   }
+   int shader_time_index = brw_get_shader_time_index(brw, prog, &vp->Base,
+                                                     type);
 
    int base_mrf = 6;
 
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
index 88a3e3b..9e700a9 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -224,7 +224,7 @@ public:
       return dst_reg(retype(brw_null_reg(), BRW_REGISTER_TYPE_D));
    }
 
-   const struct gl_vertex_program *vp;
+   struct gl_vertex_program *vp;
    struct brw_vs_compile *c;
    struct brw_vs_prog_data *prog_data;
    unsigned int sanity_param_count;
-- 
1.7.10.4



More information about the mesa-dev mailing list